Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the actual framebuffer content? #138

Open
ichlubna opened this issue Dec 11, 2024 · 2 comments
Open

How to get the actual framebuffer content? #138

ichlubna opened this issue Dec 11, 2024 · 2 comments

Comments

@ichlubna
Copy link

Hi @aap. Thanks for this library! I use it for some scientific experiments and I am struggling getting the content of a framebuffer. Would you please explain to me how your pipeline works? I have tried off-screen rendering where I bound a new framebuffer instead of the default one at all places where glDraw... is used. Having issues with that, I tried to go to the very end of the drawing and did this simple thing in glDevice.cpp in showRaster function:

std::vector<uint8> data(raster->width*raster->height*4);
glReadBuffer(GL_BACK);
glReadPixels(0,0,raster->width,raster->height,GL_BGRA,GL_UNSIGNED_BYTE,data.data());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->width, image->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);

I tried to render the texture but it does not contain the same content as I would see in the game. Please would you kindly tell me how to obtain the image as it is viewed when the game plays?

I am trying to render the scene in several views, similarly to VR mods. My plan is to add a loop somewhere around the glDraw commands, edit the matrices and render only to a portion of the framebuffer. Or maybe an easier solution would be to force the engine to render everything several times and call the showRaster only once at the end while storing the framebuffer in each iteration (would be again related to the issue above)? Then I need to do something with the views as described above. Any suggestions regarding my approach are welcomed.
Thank you!

@aap
Copy link
Owner

aap commented Dec 11, 2024

scientific experiments? woah. anyway, if you want to get the pixel values into main memory for something like a screenshot i think what should work is camera->frameBuffer->toImage(). locking that raster should read out the pixels similar to how you tried to do it. but i'm not entirely sure i understand what you want to do, reading the pixel values to main memory may not be the right solution. perhaps the subrast example is more like what you need?

@ichlubna
Copy link
Author

ichlubna commented Dec 11, 2024

Thank you for the quick reply @aap. Imagine my problem as producing a VR-like side-by-side views and some post-process. So what I need is:

  1. Render the scene several times with different camera settings
  2. Get the views in one shader and process them

I tried to start with the second point by trying to get the framebuffer to a texture and render in a new draw call on a fullscreen quad. I don't need it in the main memory, just desperately tried the simplest solution. The optimal solution for me would be to render everything into different parts of an off-screen framebuffer and then project it on a fullscreen quad.

EDIT:
I am looking at the subrast example, as you suggested, which seems to be very similar to my use case indeed. I went too low-level before. I am working with the re3 repo so I understand that I just need to use the cameras as in the subrast example, right? Do I do the trick in your raster.cpp? I need to take the original game camera coordinates, transform them and create a similar loop to the subrast one, not sure where would be the best place for the injection. Do you think I can do this solely in librw or do I need to edit the re3? Would be great if I could just clone the camera used by re3, move it and render all in librw.
Another question is if I can somehow do the post processing in librw or do I need to get the framebuffer by the toImage() and upload it back to GPU? Or maybe I can just attach a color texture to your framebuffer and use it it then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants