Jump to content
Rastar

[C++] Texture::GetPixels() for buffer texture

Recommended Posts

When I try to get the pixels of a Buffer's color texture, I get an exception. The texture is fine and can e.g. be set to a texture slot, so I guess the data isn't actually retrieved from the GPU? Is there a way to do this?

Share this post


Link to post

Yes, that works. But I am trying to get the content of a render buffer

 

Texture* tex = Texture::Create(width, height);
Buffer* buffer = Buffer::Create(width, height, 1, 0);
buffer->SetColorTexture(tex);
buffer->Enable();
buffer->Clear();
world->Render();
buffer->Disable();
Context::SetCurrent(context);
tex = buffer->GetColorTexture();
const char* pixelBuf = new char[tex->GetMipmapSize(0)];
tex->GetPixels(pixelBuf);

 

A call to mat->SetTexture(tex) works, probably because the texture handle is being passed, but the above call to GetPixels() doesn't. As I said, I assume the texture isn't actually retrieved from the GPU to the main memory.

Share this post


Link to post

Forgive me if I'm wrong, but I think your problem may be the const

const char* pixelBuf = new char[tex->GetMipmapSize(0)];
tex->GetPixels(pixelBuf);

When I did this, I had to cast it

GLubyte* tPixels = new GLubyte[tex->GetMipmapSize(0)];
tex->GetPixels(reinterpret_cast<const char*>(tPixels));

 

I have no idea why it's passed as a const char* since it's obviously modified; if anything, it should be passed as a char* const.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...