-1

I am a novice user of DirectX technologies.

How can I scroll a contents of ID3D10Texture2D? using bitblt. Something like BitBlt on GDI device context where src and dst hdc are the same.

I have ID3D10Texture2D from IDXGISurface which scrolling is my real goal, but could not find anything in the dxgi api.

Roman
  • 999
  • 3
  • 12
  • 23

1 Answers1

0

Scrolling is fairly easy. To draw an entire texture you texture from 0, 0 to 1,1. Now instead add 0.5 to each x coordinate so you get the following:

0.5, 0.0----------------1.5, 0.0
   |                       |
   |                       |
   |                       |
   |                       |
   |                       |
0.5, 1.0----------------1.5, 1.0

You will now find the texture has srolled by half its width to the right.

Hope that helps!

Edit: If you can't do the above then you may be slightly stuck as you can't read and write from the same texture (well on some drivers you can but its undefined behaviour). So you have 2 options.

1) Create a render-target texture and then render (as above) the original texture to the new render target with your offset. Then texture with the render target texture.

2) Lock (Map) the texture and copy individual bytes around to the new positions (This will be very slow due to the PCIe bus copy).

So ideally you'd do as I suggest in 1. For best performance however you'd set up a "scrolling texture vertex shader" where you set the scroll amount as a constant and then offset the texture coords per-vertex as originally described. This would be by far the most performant method.

Goz
  • 61,365
  • 24
  • 124
  • 204
  • I have asked how to scroll the texture contents, not how to draw it in another position. – Roman Apr 17 '12 at 11:34
  • @Roman ... what exactly do you mean then? The above description will scroll the texture half of its width to the right? Setting the texture to wrap mode will also mean that the data "falling off" the right will "wrap" round to the left ... If you want to scroll the actual texture data then I have to advise you against it. It will create a horrific pipeline bubble as you will need to copy data from and to the graphics card over the PCIe bus. – Goz Apr 17 '12 at 11:36
  • @Roman: Well I've updated my answer but you'll find the best methods are still, pretty much, as I originally described. – Goz Apr 17 '12 at 11:46
  • Thanks, you answered it is not possible to read and write from the same texture. So it seems it is not possible to scroll the contents and then, using it as a render target redraw missing parts. – Roman Apr 20 '12 at 12:36
  • @Roman: Ther eare always ways to do what you want to do ... don't get sucked in by the way "you" want do it. There are many alternative solutions. You may find that if you explain your use case better people will be able to give you solutions to your problem :) – Goz Apr 20 '12 at 19:15
  • You are right, the question is not really clear :( I was just trying to scroll a window with Direct2D, I should ask(and maybe I will) a question about it, and not only about one of the tryouts. – Roman Apr 23 '12 at 10:22