reading a 1DTexture1x1 in CPU after rendering to it in pipeline

Started by
4 comments, last by lomateron 11 years, 7 months ago
So I know that a texture that has been created with D3D11_CPU_ACCESS_READ cant be put in the pipeline.
What i wanna do is render to a 1DTexture1x1 and then read the pixel in the CPU, how can i do that?
Advertisement
Render it to a D3D11_USAGE_DEFAULT texture and then copy it to a D3D11_USAGE_STAGING texture, which can be created with CPU read access and be read back.
Use CopyResource for the copy.
I have a stupidly hard problem, look at the fourth parameter of the method map()
[source lang="java"]HRESULT Map(
[in] UINT Subresource,
[in] D3D10_MAP MapType,
[in] UINT MapFlags,
[out] void **ppData
)[/source]
so the data is in a single pixel, so i have:

D3DXVECTOR4 pix;

how do i put that pixel info in pix, i mean pix=.......?;

My brain gets stuck and ends in pure confusion when i think about pointers that point to other pointer and equals to another pointer that points anotherwacko.png ... Have read again all about pointers and have tried but i cant still do it.
void *pData;
Map(subres, D3D10_MAP_READ, 0, &pData);
D3DXVECTOR4 *pPix = reinterpret_cast<D3DXVECTOR4*>(pData);
D3DXVECTOR4 pix = *pPix;

This requires that your 1x1 texture is in a 128-bit float format ofcourse, as D3DXVECTOR4 is 4 floats.
Otherwise you need to convert it. For example if you have a normal R8G8B8A8 resource you can use pData as an unsigned char[4] to get the R G B A components from 0 to 255.
now its correct thanks
wait i don't know, but does this works too?

D3DXVECTOR4 pix;
collTime2->Map(0, D3D10_MAP_READ, 0, (void**)&pix);

This topic is closed to new replies.

Advertisement