From 559366c37b5e545efa53261dd5d6efaf04132957 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 19 Feb 2004 02:36:21 +0000 Subject: [PATCH] support new interface from panda --- panda/src/wgldisplay/config_wgldisplay.cxx | 7 -- panda/src/wgldisplay/config_wgldisplay.h | 1 - panda/src/wgldisplay/wglGraphicsBuffer.cxx | 77 +++++++++++++--------- panda/src/wgldisplay/wglGraphicsBuffer.h | 2 + 4 files changed, 48 insertions(+), 39 deletions(-) diff --git a/panda/src/wgldisplay/config_wgldisplay.cxx b/panda/src/wgldisplay/config_wgldisplay.cxx index d6aacf0d5c..ee69014093 100644 --- a/panda/src/wgldisplay/config_wgldisplay.cxx +++ b/panda/src/wgldisplay/config_wgldisplay.cxx @@ -66,10 +66,3 @@ bool gl_force_invalid = config_wgldisplay.GetBool("gl-force-invalid", false); // fullscreen windows, no matter what resolution of window was // requested. It only affects fullscreen windows. bool gl_do_vidmemsize_check = config_wgldisplay.GetBool("gl-do-vidmemsize-check", true); - -// For now, we fake offscreen rendering without using the -// poorly-supported pbuffer extension; we simply render into an -// invisible window. Some drivers don't like that, so for these -// drivers set show-pbuffers to true to force the window to be visible -// so you can at least get some work done. -bool show_pbuffers = config_wgldisplay.GetBool("show-pbuffers", false); diff --git a/panda/src/wgldisplay/config_wgldisplay.h b/panda/src/wgldisplay/config_wgldisplay.h index 5afea2de05..c1f9205cf1 100644 --- a/panda/src/wgldisplay/config_wgldisplay.h +++ b/panda/src/wgldisplay/config_wgldisplay.h @@ -29,6 +29,5 @@ extern EXPCL_PANDAGL void init_libwgldisplay(); extern int gl_force_pixfmt; extern bool gl_force_invalid; extern bool gl_do_vidmemsize_check; -extern bool show_pbuffers; #endif diff --git a/panda/src/wgldisplay/wglGraphicsBuffer.cxx b/panda/src/wgldisplay/wglGraphicsBuffer.cxx index 9eb5f3dc0b..a5734f77f0 100644 --- a/panda/src/wgldisplay/wglGraphicsBuffer.cxx +++ b/panda/src/wgldisplay/wglGraphicsBuffer.cxx @@ -84,6 +84,47 @@ begin_frame() { return GraphicsBuffer::begin_frame(); } +//////////////////////////////////////////////////////////////////// +// Function: wglGraphicsBuffer::end_frame +// Access: Public, Virtual +// Description: This function will be called within the draw thread +// after rendering is completed for a given frame. It +// should do whatever finalization is required. +//////////////////////////////////////////////////////////////////// +void wglGraphicsBuffer:: +end_frame() { + nassertv(_gsg != (GraphicsStateGuardian *)NULL); + _gsg->end_frame(); + + if (_copy_texture) { + 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 copy it to the texture, 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; + } + } + + // For now, we copy the framebuffer to the texture every frame. + // Eventually we can take advantage of the render_texture + // extension, if it is available, to render directly into a + // texture in the first place (but I don't have a card that + // supports that right now). + PT(DisplayRegion) dr = make_scratch_display_region(_x_size, _y_size); + get_texture()->copy(_gsg, dr, _gsg->get_render_buffer(RenderBuffer::T_back)); + } +} + //////////////////////////////////////////////////////////////////// // Function: wglGraphicsBuffer::make_current // Access: Public, Virtual @@ -137,37 +178,14 @@ release_gsg() { //////////////////////////////////////////////////////////////////// void wglGraphicsBuffer:: begin_flip() { + // In principle, we shouldn't need to flip the pbuffer. But it + // seems that if we don't, at least on my nVidia driver, it won't + // copy to texture properly somehow. + if (_gsg != (GraphicsStateGuardian *)NULL) { make_current(); 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()) { - // Use glCopyTexImage2D to copy the framebuffer to the texture. - // This appears to be the only way to "render to a texture" in - // OpenGL; there's no interface to make the offscreen buffer - // itself be a texture. - PT(DisplayRegion) dr = make_scratch_display_region(_x_size, _y_size); - get_texture()->copy(_gsg, dr, _gsg->get_render_buffer(RenderBuffer::T_back)); - } - if (_pbuffer_dc) { SwapBuffers(_pbuffer_dc); } else { @@ -323,10 +341,7 @@ make_window() { return false; } - ShowWindow(_window, SW_SHOWNORMAL); - if (!show_pbuffers) { - ShowWindow(_window, SW_HIDE); - } + ShowWindow(_window, SW_HIDE); _window_dc = GetDC(_window); diff --git a/panda/src/wgldisplay/wglGraphicsBuffer.h b/panda/src/wgldisplay/wglGraphicsBuffer.h index 8f1a40dc02..2a81ba272f 100644 --- a/panda/src/wgldisplay/wglGraphicsBuffer.h +++ b/panda/src/wgldisplay/wglGraphicsBuffer.h @@ -47,11 +47,13 @@ public: virtual ~wglGraphicsBuffer(); virtual bool begin_frame(); + virtual void end_frame(); virtual void make_current(); virtual void release_gsg(); virtual void begin_flip(); + virtual void process_events(); protected: