Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top