Пример #1
0
/*---------------------------------------------------------------------------
   Captures the contents of the frame buffer object for streaming purposes.
   Returns true if the frame was successfully captured. If the Wait flag is
   set, the function with use a blocking mutex lock on the Frame texture.
  ---------------------------------------------------------------------------*/
bool Filter::Capture(Texture &Frame, bool Wait)
   {
   if (!Ready()) {return false;}

   MutexControl Mutex(Frame.GetMutexHandle());
   if (!Wait && !Mutex.LockRequest()) {return false;}
   else {Mutex.Lock();}
   
   vector2u Res = Frame.Resolution();
   if (Res.U != ViewPort.C2 || Res.V != ViewPort.C3 || Frame.DataType() != Texture::TypeRGB) 
      {
      Res.Set(ViewPort.C2, ViewPort.C3);
      Frame.Create(Res, Texture::TypeRGB);
      }

   glBindFramebuffer(GL_READ_FRAMEBUFFER, FBOID);
   glReadPixels(0, 0, Res.U, Res.V, Frame.DataFormat(), Frame.DataCompType(), Frame.Pointer());
   glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);

   #if defined (DEBUG)
      GLenum Error = glGetError();
      if (Error != GL_NO_ERROR) {throw dexception("OpenGL generated an error: %s", Debug::ErrorGL(Error));}
   #endif
   
   return true;
   }