소스 검색

fix stereo mode

David Rose 20 년 전
부모
커밋
544e8dbc90

+ 0 - 43
panda/src/display/displayRegion.cxx

@@ -349,20 +349,6 @@ set_stereo_channel(Lens::StereoChannel stereo_channel) {
 
   CDWriter cdata(_cycler);
   cdata->_stereo_channel = stereo_channel;
-  switch (stereo_channel) {
-  case Lens::SC_left:
-    cdata->_draw_buffer_mask = ~(RenderBuffer::T_front_right | RenderBuffer::T_back_right);
-    break;
-
-  case Lens::SC_right:
-    cdata->_draw_buffer_mask = ~(RenderBuffer::T_front_left | RenderBuffer::T_back_left);
-    break;
-
-  case Lens::SC_mono:
-  case Lens::SC_stereo:
-    cdata->_draw_buffer_mask = ~0;
-    break;
-  }
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -673,33 +659,6 @@ get_screenshot(PNMImage &image) {
   return true;
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: DisplayRegion::get_screenshot_buffer_type
-//       Access: Public, Virtual
-//  Description: Returns the RenderBuffer that should be used for
-//               capturing screenshots from this particular
-//               DrawableRegion.
-////////////////////////////////////////////////////////////////////
-int DisplayRegion::
-get_screenshot_buffer_type() const {
-  CDReader cdata(_cycler);
-  return _screenshot_buffer_type & cdata->_draw_buffer_mask;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DisplayRegion::get_draw_buffer_type
-//       Access: Public, Virtual
-//  Description: Returns the RenderBuffer into which the GSG should
-//               issue draw commands.  Normally, this is the back
-//               buffer for double-buffered windows, and the front
-//               buffer for single-buffered windows.
-////////////////////////////////////////////////////////////////////
-int DisplayRegion::
-get_draw_buffer_type() const {
-  CDReader cdata(_cycler);
-  return _draw_buffer_type & cdata->_draw_buffer_mask;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: DisplayRegion::win_display_regions_changed
 //       Access: Private
@@ -763,7 +722,6 @@ CData() :
   _active(true),
   _sort(0),
   _stereo_channel(Lens::SC_mono),
-  _draw_buffer_mask(~0),
   _cube_map_index(-1)
 {
 }
@@ -790,7 +748,6 @@ CData(const DisplayRegion::CData &copy) :
   _active(copy._active),
   _sort(copy._sort),
   _stereo_channel(copy._stereo_channel),
-  _draw_buffer_mask(copy._draw_buffer_mask),
   _cube_map_index(copy._cube_map_index)
 {
 }

+ 0 - 4
panda/src/display/displayRegion.h

@@ -121,9 +121,6 @@ public:
   INLINE CullResult *get_cull_result() const;
   INLINE SceneSetup *get_scene_setup() const;
 
-  virtual int get_screenshot_buffer_type() const;
-  virtual int get_draw_buffer_type() const;
-
 private:
   class CData;
 
@@ -167,7 +164,6 @@ private:
     bool _active;
     int _sort;
     Lens::StereoChannel _stereo_channel;
-    int _draw_buffer_mask;
     int _cube_map_index;
   };
 

+ 25 - 0
panda/src/display/drawableRegion.I

@@ -202,3 +202,28 @@ INLINE bool DrawableRegion::
 is_any_clear_active() const {
   return (_flags & F_clear_all) != 0;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: DrawableRegion::get_screenshot_buffer_type
+//       Access: Public
+//  Description: Returns the RenderBuffer that should be used for
+//               capturing screenshots from this particular
+//               DrawableRegion.
+////////////////////////////////////////////////////////////////////
+INLINE int DrawableRegion::
+get_screenshot_buffer_type() const {
+  return _screenshot_buffer_type;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: DrawableRegion::get_draw_buffer_type
+//       Access: Public
+//  Description: Returns the RenderBuffer into which the GSG should
+//               issue draw commands.  Normally, this is the back
+//               buffer for double-buffered windows, and the front
+//               buffer for single-buffered windows.
+////////////////////////////////////////////////////////////////////
+INLINE int DrawableRegion::
+get_draw_buffer_type() const {
+  return _draw_buffer_type;
+}

+ 0 - 25
panda/src/display/drawableRegion.cxx

@@ -27,28 +27,3 @@
 DrawableRegion::
 ~DrawableRegion() {
 }
-
-////////////////////////////////////////////////////////////////////
-//     Function: DrawableRegion::get_screenshot_buffer_type
-//       Access: Public, Virtual
-//  Description: Returns the RenderBuffer that should be used for
-//               capturing screenshots from this particular
-//               DrawableRegion.
-////////////////////////////////////////////////////////////////////
-int DrawableRegion::
-get_screenshot_buffer_type() const {
-  return _screenshot_buffer_type;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: DrawableRegion::get_draw_buffer_type
-//       Access: Public, Virtual
-//  Description: Returns the RenderBuffer into which the GSG should
-//               issue draw commands.  Normally, this is the back
-//               buffer for double-buffered windows, and the front
-//               buffer for single-buffered windows.
-////////////////////////////////////////////////////////////////////
-int DrawableRegion::
-get_draw_buffer_type() const {
-  return _draw_buffer_type;
-}

+ 2 - 2
panda/src/display/drawableRegion.h

@@ -58,8 +58,8 @@ PUBLISHED:
   INLINE bool is_any_clear_active() const;
 
 public:
-  virtual int get_screenshot_buffer_type() const;
-  virtual int get_draw_buffer_type() const;
+  INLINE int get_screenshot_buffer_type() const;
+  INLINE int get_draw_buffer_type() const;
 
 protected:
   int _screenshot_buffer_type;

+ 10 - 1
panda/src/display/graphicsStateGuardian.cxx

@@ -281,6 +281,7 @@ reset() {
   _scene_setup = _scene_null;
   
   _buffer_mask = 0;
+  _stereo_buffer_mask = ~0;
   _color_write_mask = ColorWriteAttrib::C_all;
   _color_clear_value.set(0.0f, 0.0f, 0.0f, 0.0f);
   _depth_clear_value = 1.0f;
@@ -342,7 +343,7 @@ set_state_and_transform(const RenderState *state,
 ////////////////////////////////////////////////////////////////////
 RenderBuffer GraphicsStateGuardian::
 get_render_buffer(int buffer_type) {
-  return RenderBuffer(this, buffer_type & _buffer_mask);
+  return RenderBuffer(this, buffer_type & _buffer_mask & _stereo_buffer_mask);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -651,13 +652,21 @@ prepare_display_region(DisplayRegion *dr, Lens::StereoChannel stereo_channel) {
   _current_display_region = dr;
   _current_stereo_channel = stereo_channel;
 
+  _stereo_buffer_mask = ~0;
+
   switch (stereo_channel) {
   case Lens::SC_left:
     _color_write_mask = dr->get_window()->get_left_eye_color_mask();
+    if (_is_stereo) {
+      _stereo_buffer_mask = ~(RenderBuffer::T_front_right | RenderBuffer::T_back_right);
+    }
     break;
 
   case Lens::SC_right:
     _color_write_mask = dr->get_window()->get_right_eye_color_mask();
+    if (_is_stereo) {
+      _stereo_buffer_mask = ~(RenderBuffer::T_front_left | RenderBuffer::T_back_left);
+    }
     break;
 
   case Lens::SC_mono:

+ 1 - 0
panda/src/display/graphicsStateGuardian.h

@@ -277,6 +277,7 @@ protected:
   CPT(GeomVertexData) _vertex_data;
 
   int _buffer_mask;
+  int _stereo_buffer_mask;
   unsigned int _color_write_mask;
   Colorf _color_clear_value;
   float _depth_clear_value;

+ 6 - 3
panda/src/dxgsg8/wdxGraphicsPipe8.cxx

@@ -784,9 +784,12 @@ make_gsg(const FrameBufferProperties &properties,
     return NULL;
   }
 
-  // FrameBufferProperties really belongs as part of the window/renderbuffer specification
-  // put here because of GLX multithreading requirement
-  PT(DXGraphicsStateGuardian8) gsg = new DXGraphicsStateGuardian8(properties);
+  // DX never supports stereo.  We should also remove other properties
+  // we don't have, but we don't know enough right now.
+  FrameBufferProperties new_properties = properties;
+  new_properties.set_frame_buffer_mode(properties.get_frame_buffer_mode() & ~FrameBufferProperties::FM_stereo);
+
+  PT(DXGraphicsStateGuardian8) gsg = new DXGraphicsStateGuardian8(new_properties);
   return gsg.p();
 }
 

+ 6 - 3
panda/src/dxgsg9/wdxGraphicsPipe9.cxx

@@ -793,9 +793,12 @@ make_gsg(const FrameBufferProperties &properties,
     return NULL;
   }
 
-  // FrameBufferProperties really belongs as part of the window/renderbuffer specification
-  // put here because of GLX multithreading requirement
-  PT(DXGraphicsStateGuardian9) gsg = new DXGraphicsStateGuardian9(properties);
+  // DX never supports stereo.  We should also remove other properties
+  // we don't have, but we don't know enough right now.
+  FrameBufferProperties new_properties = properties;
+  new_properties.set_frame_buffer_mode(properties.get_frame_buffer_mode() & ~FrameBufferProperties::FM_stereo);
+
+  PT(DXGraphicsStateGuardian9) gsg = new DXGraphicsStateGuardian9(new_properties);
   return gsg.p();
 }
 

+ 9 - 21
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -973,7 +973,7 @@ prepare_display_region(DisplayRegion *dr, Lens::StereoChannel stereo_channel) {
   GLint y = GLint(b);
   GLsizei width = GLsizei(w);
   GLsizei height = GLsizei(h);
-  
+
   set_draw_buffer(get_render_buffer(_current_display_region->get_draw_buffer_type()));
   enable_scissor(true);
   GLP(Scissor)(x, y, width, height);
@@ -3721,35 +3721,23 @@ set_draw_buffer(const RenderBuffer &rb) {
     break;
 
   case RenderBuffer::T_front_right:
-    if (_is_stereo) {
-      GLP(DrawBuffer)(GL_FRONT_RIGHT);
-    } else {
-      GLP(DrawBuffer)(GL_FRONT);
-    }
+    nassertv(_is_stereo);
+    GLP(DrawBuffer)(GL_FRONT_RIGHT);
     break;
 
   case RenderBuffer::T_front_left:
-    if (_is_stereo) {
-      GLP(DrawBuffer)(GL_FRONT_LEFT);
-    } else {
-      GLP(DrawBuffer)(GL_FRONT);
-    }
+    nassertv(_is_stereo);
+    GLP(DrawBuffer)(GL_FRONT_LEFT);
     break;
 
   case RenderBuffer::T_back_right:
-    if (_is_stereo) {
-      GLP(DrawBuffer)(GL_BACK_RIGHT);
-    } else {
-      GLP(DrawBuffer)(GL_BACK);
-    }
+    nassertv(_is_stereo);
+    GLP(DrawBuffer)(GL_BACK_RIGHT);
     break;
 
   case RenderBuffer::T_back_left:
-    if (_is_stereo) {
-      GLP(DrawBuffer)(GL_BACK_LEFT);
-    } else {
-      GLP(DrawBuffer)(GL_BACK);
-    }
+    nassertv(_is_stereo);
+    GLP(DrawBuffer)(GL_BACK_LEFT);
     break;
 
   default: