SpiderPig Posted November 4, 2023 Share Posted November 4, 2023 How can I access the pixel data from a pixmap generated with TextureBuffer::Capture()? I want to access the pixel data directly like this: auto captures = texture_buffer->GetCaptures(); if (captures.size() != 0) { auto pixmap = captures[0]; auto data = pixmap->pixels->Data(); int x = 0, y = 0, stride = 4; auto i = ((y * pixmap->size.x) + x) * stride; auto r = data[0]; auto g = data[1]; auto b = data[2]; auto a = data[3]; } I've also tried this but it shows an error saying it "Bytes per block must be four or less" auto pix = pixmap->ReadPixel(x, y); auto r = Red(pix); auto g = Green(pix); auto b = Blue(pix); auto a = Alpha(pix); I can convert the pixmap from TEXTURE_RGB16 to TEXTURE_RGBA and both code will work but it's far too slow for my situation (I'm doing it once per frame). Quote Link to comment Share on other sites More sharing options...
Josh Posted November 4, 2023 Share Posted November 4, 2023 Pixmap::Sample(). You can input an iVec2 to get a single pixel without bilinear filtering. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted November 4, 2023 Author Share Posted November 4, 2023 Thanks. It's actually 3 times slower to do that per pixel than to convert the whole pixmap and access the pixel data directly. I am I correct in saying that for an RGBA16 format, the data here 2 bytes per channel? char* data = pixmap->pixels->Data(); I need a value between 0 and 255 but I'm not positive if bit shifting like this is the right way. And then I'm not positive how to get back the 0 - 255 range. auto r = (data[index] << 8) | data[index + 1]; auto g = (data[index + 2] << 8) | data[index + 3]; auto b = (data[index + 4] << 8) | data[index + 5]; auto a = (data[index + 6] << 8) | data[index + 7]; index += 8; Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted November 4, 2023 Solution Share Posted November 4, 2023 Do it like this: unsigned short* data = (unsigned short*)pixmap->pixels->Data(); Each channel will be a half float. Use halfToFloat() to convert that to a floating point number. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted November 4, 2023 Author Share Posted November 4, 2023 Thanks that worked a treat. Should we be able to change the format of a texturebuffer, like to RGBA or is RGBA16 the only one that will work for camera targets? Quote Link to comment Share on other sites More sharing options...
Josh Posted November 4, 2023 Share Posted November 4, 2023 RGBA16 is used because it supports values outside the range of 0-1. This is important if post-processing effects are used, and it also important for environment probes. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.