瀏覽代碼

query for pbuffer getting lost

David Rose 22 年之前
父節點
當前提交
31cc2f4d8f
共有 2 個文件被更改,包括 53 次插入0 次删除
  1. 51 0
      panda/src/wgldisplay/wglGraphicsBuffer.cxx
  2. 2 0
      panda/src/wgldisplay/wglGraphicsBuffer.h

+ 51 - 0
panda/src/wgldisplay/wglGraphicsBuffer.cxx

@@ -52,6 +52,37 @@ wglGraphicsBuffer(GraphicsPipe *pipe, GraphicsStateGuardian *gsg,
 wglGraphicsBuffer::
 wglGraphicsBuffer::
 ~wglGraphicsBuffer() {
 ~wglGraphicsBuffer() {
 }
 }
+ 
+////////////////////////////////////////////////////////////////////
+//     Function: wglGraphicsBuffer::begin_frame
+//       Access: Public, Virtual
+//  Description: This function will be called within the draw thread
+//               before beginning rendering for a given frame.  It
+//               should do whatever setup is required, and return true
+//               if the frame should be rendered, or false if it
+//               should be skipped.
+////////////////////////////////////////////////////////////////////
+bool wglGraphicsBuffer::
+begin_frame() {
+  if (_gsg == (GraphicsStateGuardian *)NULL) {
+    return false;
+  }
+
+  wglGraphicsStateGuardian *wglgsg;
+  DCAST_INTO_R(wglgsg, _gsg, false);
+
+  if (_pbuffer_dc) {
+    int flag = 0;
+    wglgsg->_wglQueryPbufferARB(_pbuffer, WGL_PBUFFER_LOST_ARB, &flag);
+    if (flag != 0) {
+      wgldisplay_cat.info()
+        << "Pbuffer contents lost.\n";
+      return false;
+    }
+  }
+
+  return GraphicsBuffer::begin_frame();
+}
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: wglGraphicsBuffer::make_current
 //     Function: wglGraphicsBuffer::make_current
@@ -108,6 +139,24 @@ begin_flip() {
     make_current();
     make_current();
     glFinish();
     glFinish();
 
 
+    wglGraphicsStateGuardian *wglgsg;
+    DCAST_INTO_V(wglgsg, _gsg);
+
+    // If we've lost the pbuffer image (due to a mode-switch, for
+    // instance), don't attempt to flip the buffers, since the frame
+    // is invalid.  For excruciating correctness, we should force the
+    // frame to be re-rendered, but we'll just discard the frame
+    // instead.
+    if (_pbuffer_dc) {
+      int flag = 0;
+      wglgsg->_wglQueryPbufferARB(_pbuffer, WGL_PBUFFER_LOST_ARB, &flag);
+      if (flag != 0) {
+        wgldisplay_cat.info()
+          << "Pbuffer contents lost.\n";
+        return;
+      }
+    }
+
     if (has_texture()) {
     if (has_texture()) {
       // Use glCopyTexImage2D to copy the framebuffer to the texture.
       // Use glCopyTexImage2D to copy the framebuffer to the texture.
       // This appears to be the only way to "render to a texture" in
       // This appears to be the only way to "render to a texture" in
@@ -332,6 +381,8 @@ make_pbuffer() {
     // request (and subsequently use) must be "pbuffer capable".
     // request (and subsequently use) must be "pbuffer capable".
     iattrib_list[ni++] = WGL_DRAW_TO_PBUFFER_ARB;
     iattrib_list[ni++] = WGL_DRAW_TO_PBUFFER_ARB;
     iattrib_list[ni++] = true;
     iattrib_list[ni++] = true;
+    iattrib_list[ni++] = WGL_SUPPORT_OPENGL_ARB;
+    iattrib_list[ni++] = true;
 
 
     // Match up the framebuffer bits.
     // Match up the framebuffer bits.
     iattrib_list[ni++] = WGL_RED_BITS_ARB;
     iattrib_list[ni++] = WGL_RED_BITS_ARB;

+ 2 - 0
panda/src/wgldisplay/wglGraphicsBuffer.h

@@ -45,6 +45,8 @@ public:
                     int x_size, int y_size, bool want_texture);
                     int x_size, int y_size, bool want_texture);
   virtual ~wglGraphicsBuffer();
   virtual ~wglGraphicsBuffer();
 
 
+  virtual bool begin_frame();
+
   virtual void make_current();
   virtual void make_current();
   virtual void release_gsg();
   virtual void release_gsg();