minor cleanup

This commit is contained in:
rdb 2011-03-02 11:33:23 +00:00
parent 926f4e5b30
commit 730a278372

View File

@ -95,7 +95,7 @@ CLP(GraphicsBuffer)(GraphicsEngine *engine, GraphicsPipe *pipe,
CLP(GraphicsBuffer):: CLP(GraphicsBuffer)::
~CLP(GraphicsBuffer)() { ~CLP(GraphicsBuffer)() {
// unshare shared depth buffer if any // unshare shared depth buffer if any
this -> unshare_depth_buffer(); this->unshare_depth_buffer();
// unshare all buffers that are sharing this object's depth buffer // unshare all buffers that are sharing this object's depth buffer
{ {
@ -105,15 +105,15 @@ CLP(GraphicsBuffer)::
graphics_buffer_iterator = _shared_depth_buffer_list.begin( ); graphics_buffer_iterator = _shared_depth_buffer_list.begin( );
while (graphics_buffer_iterator != _shared_depth_buffer_list.end( )) { while (graphics_buffer_iterator != _shared_depth_buffer_list.end( )) {
graphics_buffer = (*graphics_buffer_iterator); graphics_buffer = (*graphics_buffer_iterator);
if (graphics_buffer) { if (graphics_buffer) {
// this call removes the entry from the list // this call removes the entry from the list
graphics_buffer -> unshare_depth_buffer(); graphics_buffer -> unshare_depth_buffer();
} }
graphics_buffer_iterator = _shared_depth_buffer_list.begin( ); graphics_buffer_iterator = _shared_depth_buffer_list.begin( );
} }
} }
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: glGraphicsBuffer::begin_frame // Function: glGraphicsBuffer::begin_frame
// Access: Public, Virtual // Access: Public, Virtual
@ -128,7 +128,7 @@ begin_frame(FrameMode mode, Thread *current_thread) {
begin_frame_spam(mode); begin_frame_spam(mode);
check_host_valid(); check_host_valid();
if (!_is_valid) { if (!_is_valid) {
if (GLCAT.is_debug()) { if (GLCAT.is_debug()) {
GLCAT.debug() GLCAT.debug()
@ -144,7 +144,7 @@ begin_frame(FrameMode mode, Thread *current_thread) {
} }
return false; return false;
} }
// Figure out the desired size of the buffer. // Figure out the desired size of the buffer.
if (mode == FM_render) { if (mode == FM_render) {
rebuild_bitplanes(); rebuild_bitplanes();
@ -166,7 +166,7 @@ begin_frame(FrameMode mode, Thread *current_thread) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: glGraphicsBuffer::check_fbo // Function: glGraphicsBuffer::check_fbo
// Access: Private // Access: Private
// Description: Calls 'glCheckFramebufferStatus'. On error, // Description: Calls 'glCheckFramebufferStatus'. On error,
// prints out an appropriate error message and unbinds // prints out an appropriate error message and unbinds
// the fbo. Returns true for OK or false for error. // the fbo. Returns true for OK or false for error.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -203,7 +203,7 @@ check_fbo() {
GLCAT.error() << "UNKNOWN PROBLEM " << status; break; GLCAT.error() << "UNKNOWN PROBLEM " << status; break;
} }
GLCAT.error(false) << " for " << get_name() << "\n"; GLCAT.error(false) << " for " << get_name() << "\n";
glgsg->bind_fbo(0); glgsg->bind_fbo(0);
report_my_gl_errors(); report_my_gl_errors();
return false; return false;
@ -225,7 +225,7 @@ rebuild_bitplanes() {
if (_gsg == 0) { if (_gsg == 0) {
return; return;
} }
CLP(GraphicsStateGuardian) *glgsg; CLP(GraphicsStateGuardian) *glgsg;
DCAST_INTO_V(glgsg, _gsg); DCAST_INTO_V(glgsg, _gsg);
@ -235,7 +235,7 @@ rebuild_bitplanes() {
if (tex == 0) { if (tex == 0) {
return; return;
} }
if (tex->get_texture_type() != Texture::TT_cube_map) { if (tex->get_texture_type() != Texture::TT_cube_map) {
if (_fbo == 0) { if (_fbo == 0) {
glgsg->_glGenFramebuffers(1, &_fbo); glgsg->_glGenFramebuffers(1, &_fbo);
@ -302,7 +302,7 @@ rebuild_bitplanes() {
} }
// If I can't find an appropriate slot, or if there's // If I can't find an appropriate slot, or if there's
// already a texture bound to this slot, then punt // already a texture bound to this slot, then punt
// this texture. // this texture.
if (attach[plane]) { if (attach[plane]) {
_textures[i]._rtm_mode = RTM_copy_texture; _textures[i]._rtm_mode = RTM_copy_texture;
@ -367,7 +367,7 @@ rebuild_bitplanes() {
} else { } else {
// make an FBO for each cubemap face // make an FBO for each cubemap face
int update; int update;
update = false; update = false;
for (int f = 0; f < 6; f++) { for (int f = 0; f < 6; f++) {
if (_cubemap_fbo [f] == 0) { if (_cubemap_fbo [f] == 0) {
@ -376,10 +376,10 @@ rebuild_bitplanes() {
if (_cubemap_fbo [f] == 0) { if (_cubemap_fbo [f] == 0) {
report_my_gl_errors(); report_my_gl_errors();
return; return;
} }
} }
} }
if (update) { if (update) {
int color_attachment = GL_COLOR_ATTACHMENT0_EXT; int color_attachment = GL_COLOR_ATTACHMENT0_EXT;
@ -398,11 +398,10 @@ rebuild_bitplanes() {
RenderTexturePlane plane = get_texture_plane(i); RenderTexturePlane plane = get_texture_plane(i);
switch (plane) switch (plane) {
{
case RTP_depth: case RTP_depth:
case RTP_depth_stencil: case RTP_depth_stencil:
for (int f = 0; f < 6; f++) { for (int f = 0; f < 6; f++) {
glgsg->bind_fbo(_cubemap_fbo [f]); glgsg->bind_fbo(_cubemap_fbo [f]);
glgsg->_glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, glgsg->_glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_TEXTURE_CUBE_MAP_POSITIVE_X + f, GL_TEXTURE_CUBE_MAP_POSITIVE_X + f,
@ -431,13 +430,13 @@ rebuild_bitplanes() {
} }
color_attachment++; color_attachment++;
break; break;
default: default:
break; break;
} }
} }
} }
glgsg->bind_fbo(_cubemap_fbo [0]); glgsg->bind_fbo(_cubemap_fbo [0]);
} }
@ -445,7 +444,7 @@ rebuild_bitplanes() {
if (_initial_clear) { if (_initial_clear) {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
_initial_clear = false; _initial_clear = false;
} }
#ifndef OPENGLES #ifndef OPENGLES
@ -504,7 +503,7 @@ bind_slot(bool rb_resize, Texture **attach, RenderTexturePlane slot, GLenum atta
tex->set_pad_size(_rb_size_x - _x_size, _rb_size_y - _y_size); tex->set_pad_size(_rb_size_x - _x_size, _rb_size_y - _y_size);
return; return;
} }
// Bind the texture to the slot. // Bind the texture to the slot.
tex->set_x_size(_rb_size_x); tex->set_x_size(_rb_size_x);
tex->set_y_size(_rb_size_y); tex->set_y_size(_rb_size_y);
@ -520,8 +519,8 @@ bind_slot(bool rb_resize, Texture **attach, RenderTexturePlane slot, GLenum atta
CLP(TextureContext) *gtc = DCAST(CLP(TextureContext), tc); CLP(TextureContext) *gtc = DCAST(CLP(TextureContext), tc);
glgsg->update_texture(tc, true); glgsg->update_texture(tc, true);
#ifndef OPENGLES #ifndef OPENGLES
GLclampf priority = 1.0f; GLclampf priority = 1.0f;
glPrioritizeTextures(1, &gtc->_index, &priority); glPrioritizeTextures(1, &gtc->_index, &priority);
#endif #endif
if (tex->get_texture_type() == Texture::TT_2d_texture) { if (tex->get_texture_type() == Texture::TT_2d_texture) {
glgsg->_glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, glgsg->_glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
@ -556,8 +555,8 @@ bind_slot(bool rb_resize, Texture **attach, RenderTexturePlane slot, GLenum atta
nassertv(tc != (TextureContext *)NULL); nassertv(tc != (TextureContext *)NULL);
CLP(TextureContext) *gtc = DCAST(CLP(TextureContext), tc); CLP(TextureContext) *gtc = DCAST(CLP(TextureContext), tc);
#ifndef OPENGLES #ifndef OPENGLES
GLclampf priority = 1.0f; GLclampf priority = 1.0f;
glPrioritizeTextures(1, &gtc->_index, &priority); glPrioritizeTextures(1, &gtc->_index, &priority);
#endif #endif
glgsg->update_texture(tc, true); glgsg->update_texture(tc, true);
if (tex->get_texture_type() == Texture::TT_2d_texture) { if (tex->get_texture_type() == Texture::TT_2d_texture) {
@ -569,26 +568,26 @@ bind_slot(bool rb_resize, Texture **attach, RenderTexturePlane slot, GLenum atta
gtc->_index, 0); gtc->_index, 0);
} }
} }
_tex[slot] = tex; _tex[slot] = tex;
// If there was a renderbuffer bound to this slot, delete it. // If there was a renderbuffer bound to this slot, delete it.
if (_rb[slot] != 0) { if (_rb[slot] != 0) {
glgsg->_glDeleteRenderbuffers(1, &(_rb[slot])); glgsg->_glDeleteRenderbuffers(1, &(_rb[slot]));
_rb[slot] = 0; _rb[slot] = 0;
} }
} else { } else {
// Disconnect from any texture that was previously bound to this slot. // Disconnect from any texture that was previously bound to this slot.
_tex[slot] = 0; _tex[slot] = 0;
// If a renderbuffer is already attached to the slot, and it's // If a renderbuffer is already attached to the slot, and it's
// the right size, then no update of this slot is needed. // the right size, then no update of this slot is needed.
if (_shared_depth_buffer == 0 && (_rb[slot] != 0)&&(!rb_resize)) { if (_shared_depth_buffer == 0 && (_rb[slot] != 0)&&(!rb_resize)) {
return; return;
} }
#ifndef OPENGLES_2 #ifndef OPENGLES_2
// Check for the tricky case of a depth_stencil buffer: // Check for the tricky case of a depth_stencil buffer:
// If we think we need one, but we have a texture bound in the depth slot, // If we think we need one, but we have a texture bound in the depth slot,
@ -604,7 +603,7 @@ bind_slot(bool rb_resize, Texture **attach, RenderTexturePlane slot, GLenum atta
if (_rb[slot] == 0) { if (_rb[slot] == 0) {
glgsg->_glGenRenderbuffers(1, &(_rb[slot])); glgsg->_glGenRenderbuffers(1, &(_rb[slot]));
} }
// Allocate and bind the renderbuffer. // Allocate and bind the renderbuffer.
glgsg->_glBindRenderbuffer(GL_RENDERBUFFER_EXT, _rb[slot]); glgsg->_glBindRenderbuffer(GL_RENDERBUFFER_EXT, _rb[slot]);
if (attachpoint == GL_DEPTH_ATTACHMENT_EXT) { if (attachpoint == GL_DEPTH_ATTACHMENT_EXT) {
@ -614,17 +613,17 @@ bind_slot(bool rb_resize, Texture **attach, RenderTexturePlane slot, GLenum atta
glgsg->_glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, glgsg->_glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT,
_rb_size_x, _rb_size_y); _rb_size_x, _rb_size_y);
glgsg->_glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0); glgsg->_glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
GLuint rb; GLuint rb;
rb = _rb[slot]; rb = _rb[slot];
if (_shared_depth_buffer) { if (_shared_depth_buffer) {
rb = _shared_depth_buffer -> _rb[slot]; rb = _shared_depth_buffer -> _rb[slot];
} }
glgsg->_glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, glgsg->_glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, rb); GL_RENDERBUFFER_EXT, rb);
glgsg->_glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, glgsg->_glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, rb); GL_RENDERBUFFER_EXT, rb);
@ -643,7 +642,7 @@ bind_slot(bool rb_resize, Texture **attach, RenderTexturePlane slot, GLenum atta
// We'll bail out before here if we set a depth_stencil buffer, or figure out that we're // We'll bail out before here if we set a depth_stencil buffer, or figure out that we're
// GOING to set a depth_stencil buffer. // GOING to set a depth_stencil buffer.
// //
// If we get here, we're using the simple fallback case. // If we get here, we're using the simple fallback case.
#endif #endif
#ifdef OPENGLES #ifdef OPENGLES
@ -673,11 +672,11 @@ bind_slot(bool rb_resize, Texture **attach, RenderTexturePlane slot, GLenum atta
} }
} }
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: glGraphicsBuffer::bind_slot_multisample // Function: glGraphicsBuffer::bind_slot_multisample
// Access: Private // Access: Private
// Description: Attaches incoming Texture or renderbuffer to the // Description: Attaches incoming Texture or renderbuffer to the
// required bitplanes for the 2 FBOs comprising a // required bitplanes for the 2 FBOs comprising a
// multisample graphics buffer. // multisample graphics buffer.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -791,7 +790,7 @@ bind_slot_multisample(bool rb_resize, Texture **attach, RenderTexturePlane slot,
// Function: glGraphicsBuffer::generate_mipmaps // Function: glGraphicsBuffer::generate_mipmaps
// Access: Private // Access: Private
// Description: This function will be called within the draw thread // Description: This function will be called within the draw thread
// after rendering is completed for a given frame. // after rendering is completed for a given frame.
// If we've just rendered into level zero of a mipmapped // If we've just rendered into level zero of a mipmapped
// texture, then all subsequent mipmap levels will now // texture, then all subsequent mipmap levels will now
// be calculated. // be calculated.
@ -836,7 +835,7 @@ void CLP(GraphicsBuffer)::end_frame(FrameMode mode, Thread *current_thread) {
// Unbind the FBO // Unbind the FBO
CLP(GraphicsStateGuardian) *glgsg; CLP(GraphicsStateGuardian) *glgsg;
DCAST_INTO_V(glgsg, _gsg); DCAST_INTO_V(glgsg, _gsg);
// Resolve Multisample rendering if using it. // Resolve Multisample rendering if using it.
if (_requested_multisamples && _fbo_multisample) { if (_requested_multisamples && _fbo_multisample) {
glgsg->report_my_gl_errors(); glgsg->report_my_gl_errors();
@ -855,13 +854,13 @@ void CLP(GraphicsBuffer)::end_frame(FrameMode mode, Thread *current_thread) {
graphics_buffer_iterator != _shared_depth_buffer_list.end(); graphics_buffer_iterator != _shared_depth_buffer_list.end();
graphics_buffer_iterator++) { graphics_buffer_iterator++) {
graphics_buffer = (*graphics_buffer_iterator); graphics_buffer = (*graphics_buffer_iterator);
if (graphics_buffer) { if (graphics_buffer) {
// this call removes the entry from the list // this call removes the entry from the list
if ( graphics_buffer->get_sort() >= max_sort_order ) { if ( graphics_buffer->get_sort() >= max_sort_order ) {
max_sort_order = graphics_buffer->get_sort(); max_sort_order = graphics_buffer->get_sort();
highest_sort_graphics_buffer = graphics_buffer; highest_sort_graphics_buffer = graphics_buffer;
} }
} }
} }
if (max_sort_order == this->get_sort()) { if (max_sort_order == this->get_sort()) {
do_depth_blit = 1; do_depth_blit = 1;
@ -870,12 +869,12 @@ void CLP(GraphicsBuffer)::end_frame(FrameMode mode, Thread *current_thread) {
do_depth_blit = 1; do_depth_blit = 1;
} }
if (do_depth_blit) { if (do_depth_blit) {
glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y, glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y,
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
GL_NEAREST); GL_NEAREST);
} else { } else {
glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y, glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y,
GL_COLOR_BUFFER_BIT, GL_COLOR_BUFFER_BIT,
GL_NEAREST); GL_NEAREST);
} }
#ifndef OPENGLES #ifndef OPENGLES
@ -884,25 +883,25 @@ void CLP(GraphicsBuffer)::end_frame(FrameMode mode, Thread *current_thread) {
for (int i=0; i<_fb_properties.get_aux_rgba(); i++) { for (int i=0; i<_fb_properties.get_aux_rgba(); i++) {
glReadBuffer( next ); glReadBuffer( next );
glDrawBuffer( next ); glDrawBuffer( next );
glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y, glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y,
GL_COLOR_BUFFER_BIT, GL_NEAREST); GL_COLOR_BUFFER_BIT, GL_NEAREST);
next += 1; next += 1;
} }
for (int i=0; i<_fb_properties.get_aux_hrgba(); i++) { for (int i=0; i<_fb_properties.get_aux_hrgba(); i++) {
glReadBuffer( next ); glReadBuffer( next );
glDrawBuffer( next ); glDrawBuffer( next );
glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y, glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y,
GL_COLOR_BUFFER_BIT, GL_NEAREST); GL_COLOR_BUFFER_BIT, GL_NEAREST);
next += 1; next += 1;
} }
for (int i=0; i<_fb_properties.get_aux_float(); i++) { for (int i=0; i<_fb_properties.get_aux_float(); i++) {
glReadBuffer( next ); glReadBuffer( next );
glDrawBuffer( next ); glDrawBuffer( next );
glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y, glgsg->_glBlitFramebuffer(0, 0, _rb_size_x, _rb_size_y, 0, 0, _rb_size_x, _rb_size_y,
GL_COLOR_BUFFER_BIT, GL_NEAREST); GL_COLOR_BUFFER_BIT, GL_NEAREST);
next += 1; next += 1;
} }
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
#endif #endif
@ -945,7 +944,7 @@ select_cube_map(int cube_map_index) {
CLP(GraphicsStateGuardian) *glgsg; CLP(GraphicsStateGuardian) *glgsg;
DCAST_INTO_V(glgsg, _gsg); DCAST_INTO_V(glgsg, _gsg);
glgsg->bind_fbo(_cubemap_fbo [cube_map_index]); glgsg->bind_fbo(_cubemap_fbo [cube_map_index]);
report_my_gl_errors(); report_my_gl_errors();
} }
@ -976,9 +975,9 @@ open_buffer() {
if (!glgsg->_supports_framebuffer_object) { if (!glgsg->_supports_framebuffer_object) {
return false; return false;
} }
// Describe the framebuffer properties of the FBO. // Describe the framebuffer properties of the FBO.
// //
// The rule is that the properties should be as close // The rule is that the properties should be as close
// as possible to those requested, subject to the limits // as possible to those requested, subject to the limits
// of the implementation. This particular implementation // of the implementation. This particular implementation
@ -1002,7 +1001,7 @@ open_buffer() {
_fb_properties.set_stereo(0); _fb_properties.set_stereo(0);
_fb_properties.set_force_hardware(_host->get_fb_properties().get_force_hardware()); _fb_properties.set_force_hardware(_host->get_fb_properties().get_force_hardware());
_fb_properties.set_force_software(_host->get_fb_properties().get_force_software()); _fb_properties.set_force_software(_host->get_fb_properties().get_force_software());
_is_valid = true; _is_valid = true;
report_my_gl_errors(); report_my_gl_errors();
return true; return true;
@ -1019,12 +1018,12 @@ close_buffer() {
check_host_valid(); check_host_valid();
report_my_gl_errors(); report_my_gl_errors();
_active = false; _active = false;
if (_gsg == 0) { if (_gsg == 0) {
return; return;
} }
// Get the glgsg. // Get the glgsg.
CLP(GraphicsStateGuardian) *glgsg; CLP(GraphicsStateGuardian) *glgsg;
DCAST_INTO_V(glgsg, _gsg); DCAST_INTO_V(glgsg, _gsg);
@ -1049,7 +1048,7 @@ close_buffer() {
_rb_size_x = 0; _rb_size_x = 0;
_rb_size_y = 0; _rb_size_y = 0;
report_my_gl_errors(); report_my_gl_errors();
// Delete the FBO itself. // Delete the FBO itself.
if (_fbo != 0) { if (_fbo != 0) {
glgsg->_glDeleteFramebuffers(1, &_fbo); glgsg->_glDeleteFramebuffers(1, &_fbo);
@ -1064,7 +1063,7 @@ close_buffer() {
report_my_gl_errors(); report_my_gl_errors();
} }
} }
// Release the Gsg // Release the Gsg
_gsg.clear(); _gsg.clear();
@ -1073,49 +1072,49 @@ close_buffer() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: glGraphicsBuffer::share_depth_buffer // Function: glGraphicsBuffer::share_depth_buffer
// Access: Published // Access: Published
// Description: Will attempt to use the depth buffer of the input // Description: Will attempt to use the depth buffer of the input
// graphics_output. The buffer sizes must be exactly // graphics_output. The buffer sizes must be exactly
// the same. // the same.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool CLP(GraphicsBuffer):: bool CLP(GraphicsBuffer)::
share_depth_buffer(GraphicsOutput *graphics_output) { share_depth_buffer(GraphicsOutput *graphics_output) {
bool state; bool state;
CLP(GraphicsBuffer) *input_graphics_output; CLP(GraphicsBuffer) *input_graphics_output;
state = false; state = false;
input_graphics_output = DCAST (CLP(GraphicsBuffer), graphics_output); input_graphics_output = DCAST (CLP(GraphicsBuffer), graphics_output);
if (this != input_graphics_output && input_graphics_output) { if (this != input_graphics_output && input_graphics_output) {
state = true; state = true;
this -> unshare_depth_buffer(); this -> unshare_depth_buffer();
// check buffer sizes // check buffer sizes
if (this -> get_x_size() != input_graphics_output -> get_x_size()) { if (this -> get_x_size() != input_graphics_output -> get_x_size()) {
GLCAT.error() << "share_depth_buffer: non matching width \n"; GLCAT.error() << "share_depth_buffer: non matching width \n";
state = false; state = false;
} }
if (this -> get_y_size() != input_graphics_output -> get_y_size()) { if (this -> get_y_size() != input_graphics_output -> get_y_size()) {
GLCAT.error() << "share_depth_buffer: non matching height \n"; GLCAT.error() << "share_depth_buffer: non matching height \n";
state = false; state = false;
} }
// Check multisample compatibility. // Check multisample compatibility.
if ( this->get_multisample_count() != input_graphics_output->get_multisample_count() ) { if ( this->get_multisample_count() != input_graphics_output->get_multisample_count() ) {
GLCAT.error() << "share_depth_buffer: non matching multisamples \n"; GLCAT.error() << "share_depth_buffer: non matching multisamples \n";
state = false; state = false;
} }
if ( this->get_coverage_sample_count() != input_graphics_output->get_coverage_sample_count() ) { if ( this->get_coverage_sample_count() != input_graphics_output->get_coverage_sample_count() ) {
GLCAT.error() << "share_depth_buffer: non matching multisamples \n"; GLCAT.error() << "share_depth_buffer: non matching multisamples \n";
state = false; state = false;
} }
if (state) { if (state) {
// let the input GraphicsOutput know that there is an object // let the input GraphicsOutput know that there is an object
// sharing its depth buffer // sharing its depth buffer
input_graphics_output -> register_shared_depth_buffer(this); input_graphics_output -> register_shared_depth_buffer(this);
_shared_depth_buffer = input_graphics_output; _shared_depth_buffer = input_graphics_output;
state = true; state = true;
@ -1127,7 +1126,7 @@ share_depth_buffer(GraphicsOutput *graphics_output) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: glGraphicsBuffer::unshare_depth_buffer // Function: glGraphicsBuffer::unshare_depth_buffer
// Access: Published // Access: Published
// Description: Discontinue sharing the depth buffer. // Description: Discontinue sharing the depth buffer.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void CLP(GraphicsBuffer):: void CLP(GraphicsBuffer)::
@ -1135,7 +1134,7 @@ unshare_depth_buffer() {
if (_shared_depth_buffer) { if (_shared_depth_buffer) {
// let the GraphicsOutput know that this object is no longer // let the GraphicsOutput know that this object is no longer
// sharing its depth buffer // sharing its depth buffer
_shared_depth_buffer -> unregister_shared_depth_buffer(this); _shared_depth_buffer -> unregister_shared_depth_buffer(this);
_shared_depth_buffer = 0; _shared_depth_buffer = 0;
} }
} }
@ -1148,10 +1147,10 @@ unshare_depth_buffer() {
void CLP(GraphicsBuffer):: void CLP(GraphicsBuffer)::
register_shared_depth_buffer(GraphicsOutput *graphics_output) { register_shared_depth_buffer(GraphicsOutput *graphics_output) {
CLP(GraphicsBuffer) *input_graphics_output; CLP(GraphicsBuffer) *input_graphics_output;
input_graphics_output = DCAST (CLP(GraphicsBuffer), graphics_output); input_graphics_output = DCAST (CLP(GraphicsBuffer), graphics_output);
if (input_graphics_output) { if (input_graphics_output) {
// add to list // add to list
_shared_depth_buffer_list.push_back(input_graphics_output); _shared_depth_buffer_list.push_back(input_graphics_output);
} }
} }
@ -1164,10 +1163,10 @@ register_shared_depth_buffer(GraphicsOutput *graphics_output) {
void CLP(GraphicsBuffer):: void CLP(GraphicsBuffer)::
unregister_shared_depth_buffer(GraphicsOutput *graphics_output) { unregister_shared_depth_buffer(GraphicsOutput *graphics_output) {
CLP(GraphicsBuffer) *input_graphics_output; CLP(GraphicsBuffer) *input_graphics_output;
input_graphics_output = DCAST (CLP(GraphicsBuffer), graphics_output); input_graphics_output = DCAST (CLP(GraphicsBuffer), graphics_output);
if (input_graphics_output) { if (input_graphics_output) {
// remove from list // remove from list
_shared_depth_buffer_list.remove(input_graphics_output); _shared_depth_buffer_list.remove(input_graphics_output);
} }
} }