Advertisement Jump to content
Sign in to follow this  
gfxCahd

Get texel RGBA from texture2d

This topic is 1826 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

I want to read the RGBA values for each texel in a texture2D I've loaded.

 

So, I load my image, with the following imageloadinfo:

dataLoadInfo = new ImageLoadInformation()
{
  BindFlags = BindFlags.None,
  CpuAccessFlags = CpuAccessFlags.Read,
  Usage = ResourceUsage.Staging,
  Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm,
  MipLevels = 1
};

Then, I Map the data:

DataRectangle dataRectangle = texture2D.Map(0, MapMode.Read, MapFlags.None);

Cool. But how do I loop over the dataRectangle?

I guess I could just deal with the actual pointer as described here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205319%28v=vs.85%29.aspx

 

but is there really no way to do this without resorting to unsafe code?

Edited by gfxCahd

Share this post


Link to post
Share on other sites
Advertisement

maybe this can help :

DataStream mStream;


GraphicsRenderer.contex.MapSubresource(texture, 0, 0, MapMode.Read, MapFlags.None, out mStream);

Color4[] colors=new Color4[mStream.Length/Marshal.SizeOf(typeof(Color4))];

int i = 0;

 while (mStream.RemainingLength > 0)
{
          colors[i] = mStream.ReadColor4();
           i++;
 }

GraphicsRenderer.contex is my DeviceContext .

Edited by BlackBrain

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!