2

I am trying to take screenshots in the most efficient way. I thing using a FrameBuffer is the most efficient way of taking screenshots because i can process the data in different thread than rendering thread. How can i get the information from FrameBUffer and transfer it to a file?

FrameBuffer m_fbo;

render(){
   m_fbo = new FrameBuffer(Format.RGB565, (int)(w * m_fboScaler), (int)(h * m_fboScaler), false);
   m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture());
   m_fboRegion.flip(false, true);
   m_fbo.begin();
   ...rendering...
   m_fbo.end();
   writeTextureRegionToFile(); - i need some lines of code for the implementation of this method
}
Duna
  • 1,564
  • 1
  • 16
  • 36

1 Answers1

2

The FrameBuffer contents reside in memory managed by OpenGL, so you will (as far as I understand things) still need to fetch those bytes using OpenGL APIs on the render thread. Specifically, you want the ScreenUtils class to get a byte[] containing the RGBA8888 contents of your FrameBuffer.

Once you get the raw bytes, you can do any compression/conversion/output on a different thread, of course. There is a forum post that has a quick and dirty PNG writer. The Libgdx-specific (?) CIM format is also an option (see the PixmapIO class), but you'll have to convert the bytes into a Pixmap first.

P.T.
  • 24,557
  • 7
  • 64
  • 95
  • "still need to fetch those bytes using OpenGL APIs on the render thread" - by doing that fps drops to 6. If this could be done in separate thread would be usefull. – Duna Jun 26 '13 at 13:09
  • Libgdx (and LWJGL underneath) only allow a single thread to do OpenGL calls, so there isn't much hope of getting it off the render thread. – P.T. Jun 26 '13 at 16:27