// Draw screenshot.
public void drawFrameInThread()
   {
      if (frameBuffer == null)
      {
         return; // Framebuffer is not up yet
      }
      // Select gpuToVram PBO an read pixels from GPU to VRAM
      glBindBuffer(GL_PIXEL_PACK_BUFFER, gpuToVram);
      glReadPixels(0, 0, frameBuffer.getWidth(), frameBuffer.getHeight(), GL_BGRA, GL_UNSIGNED_BYTE, 0);
      // Select vramToSys PBO, bind it to systemRam and copy the data over
      glBindBuffer(GL_PIXEL_PACK_BUFFER, vramToSys);
      ByteBuffer byteBuf = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY, null);
      // Swap indices
      int previousGpuToVram = gpuToVram;
      gpuToVram = vramToSys;
      vramToSys = previousGpuToVram;
      if (byteBuf == null)
      {
         return;
      }
      convertScreenShot2(byteBuf.asIntBuffer(), bufferedImage);
      // Unmap buffer
      glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
      // Unbind PBO
      glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
      synchronized (lock)
      {
         // All operations on strategy should be synchronized (?)
         if (strategy == null)
         {
            try
            {
               createBufferStrategy(1,
                                    new BufferCapabilities(new ImageCapabilities(true),
                                                           new ImageCapabilities(true),
                                                           BufferCapabilities.FlipContents.UNDEFINED));
            }
            catch (AWTException ex)
            {
               ex.printStackTrace();
            }
            strategy = getBufferStrategy();
            printIfDebug(getClass().getSimpleName() + ": Visible. Create strategy.");
         }
         // Draw screenshot.
         do
         {
            do
            {
               Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
               if (g2d == null)
               {
                  printIfDebug(getClass().getSimpleName() + ": DrawGraphics was null.");
                  return;
               }
               g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
               //             g2d.drawImage(img, transformOp, 0, 0);
               g2d.drawImage(bufferedImage, 0, 0, null);
               g2d.dispose();
               strategy.show();
            }
            while (strategy.contentsRestored());
         }
         while (strategy.contentsLost());
      }
   }
printIfDebug(getClass().getSimpleName() + ": Visible. Create strategy.");
}
// Draw screenshot.
do
{
new ImageCapabilities(true),
BufferCapabilities.FlipContents.UNDEFINED));
}
catch (AWTException ex)
{
ex.printStackTrace();
}
strategy = getBufferStrategy();
printIfDebug(getClass().getSimpleName() + ": Visible. Create strategy.");
}
// Draw screenshot.
do
{
do
{
Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
if (g2d == null)
{
printIfDebug(getClass().getSimpleName() + ": DrawGraphics was null.");
return;
}
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
synchronized (lock)
{
// All operations on strategy should be synchronized (?)
if (strategy == null)
{
try
{
createBufferStrategy(1,
new BufferCapabilities(new ImageCapabilities(true),
new ImageCapabilities(true),
BufferCapabilities.FlipContents.UNDEFINED));
}
catch (AWTException ex)
{
ex.printStackTrace();
}
strategy = getBufferStrategy();
printIfDebug(getClass().getSimpleName() + ": Visible. Create strategy.");
}
// Draw screenshot.
do
{
do
{
Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
if (g2d == null)
{
printIfDebug(getClass().getSimpleName() + ": DrawGraphics was null.");
return;
}
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
// g2d.drawImage(img, transformOp, 0, 0);
g2d.drawImage(bufferedImage, 0, 0, null);
g2d.dispose();
strategy.show();
}
while (strategy.contentsRestored());
}
while (strategy.contentsLost());
}