Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This problem is actually common (apparently) in game code and the like. One interesting solution is the following: <a href="https://stackoverflow.com/questions/2944290/efficient-pixel-shader-sum-of-all-pixels">Efficient pixel shader sum of all pixels</a>. This is particularly relevant to your exact situation, since you can use a larger mimmap texture to sum smaller segments of the display. </p> <p><a href="https://stackoverflow.com/questions/10819951/how-to-copy-frontbuffer-data-to-texture-directx-9">Get the screen into a texture</a></p> <pre><code>IDirect3DTexture9* texture; // needs to be created, of course IDirect3DSurface9* dest = NULL; // to be our level0 surface of the texture texture-&gt;GetSurfaceLevel(0, &amp;dest); pD3DDevice-&gt;StretchRect(pSurface, NULL, dest, NULL, D3DTEXF_LINEAR); </code></pre> <p>And then create a mipmap chain as <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb206251%28v=vs.85%29.aspx" rel="nofollow noreferrer">here</a></p> <pre><code>// This code example assumes that m_d3dDevice is a // valid pointer to a IDirect3DDevice9 interface IDirect3DTexture9 * pMipMap; m_pD3DDevice-&gt;CreateTexture(256, 256, 5, 0, D3DFMT_R8G8B8, D3DPOOL_MANAGED, &amp;pMipMap); </code></pre> <p>Of course you don't have to access the bottom mipmap (which is the average). You could access a few levels higher to get averages of sections. Also this is quick because texture mipmapping is important in games and graphics in general. Other filtering options may be available too.</p> <p>For the second edit try <a href="https://stackoverflow.com/questions/120066/doing-readback-from-direct3d-textures-and-surfaces">here</a> - something about textures in gpu mem are read differently, and can't be locked, you'll need to use getrendertargetdata or some such. <a href="http://msdn.microsoft.com/en-us/library/bb174405%28VS.85%29.aspx" rel="nofollow noreferrer">This</a> can be used to copy your stretchrect surface to a texture created cpu side in the system pool. As far as I know gpu side textures/surfaces can't be memcpy'ed directly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload