• Advertisement
Sign in to follow this  

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

This topic is 1969 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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. Edited by Erik Rufelt

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. Edited by Erik Rufelt

Share this post


Link to post
Share on other sites
wait i don't know, but does this works too?

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement