Commit 616685f9 authored by Ken Martin's avatar Ken Martin

Fix bug in vol ren, better opengl error checking

Fix an error in the volume rendering where draw buffers
were being set after the frambuffer was unbound

Improve state error checking to catch a couple more
issues and catch them earlier in the execution.
parent d444f01d
...@@ -605,7 +605,7 @@ void vtkOpenGLFramebufferObject::ActivateBuffers() ...@@ -605,7 +605,7 @@ void vtkOpenGLFramebufferObject::ActivateBuffers()
count++; count++;
} }
this->Context->GetState()->vtkDrawBuffers(count, buffers); this->Context->GetState()->vtkDrawBuffers(count, buffers, this);
delete[] buffers; delete[] buffers;
} }
...@@ -620,7 +620,7 @@ void vtkOpenGLFramebufferObject::ActivateReadBuffer( ...@@ -620,7 +620,7 @@ void vtkOpenGLFramebufferObject::ActivateReadBuffer(
unsigned int colorAtt) unsigned int colorAtt)
{ {
colorAtt += GL_COLOR_ATTACHMENT0; colorAtt += GL_COLOR_ATTACHMENT0;
this->Context->GetState()->vtkReadBuffer((GLenum)colorAtt); this->Context->GetState()->vtkReadBuffer((GLenum)colorAtt, this);
this->ActiveReadBuffer = colorAtt; this->ActiveReadBuffer = colorAtt;
} }
...@@ -639,7 +639,7 @@ void vtkOpenGLFramebufferObject::ActivateDrawBuffers(unsigned int num) ...@@ -639,7 +639,7 @@ void vtkOpenGLFramebufferObject::ActivateDrawBuffers(unsigned int num)
count++; count++;
} }
this->Context->GetState()->vtkDrawBuffers(count, buffers); this->Context->GetState()->vtkDrawBuffers(count, buffers, this);
delete[] buffers; delete[] buffers;
this->ActiveBuffers.clear(); this->ActiveBuffers.clear();
...@@ -674,7 +674,7 @@ void vtkOpenGLFramebufferObject::ActivateDrawBuffers(unsigned int *ids, int num) ...@@ -674,7 +674,7 @@ void vtkOpenGLFramebufferObject::ActivateDrawBuffers(unsigned int *ids, int num)
count++; count++;
} }
this->Context->GetState()->vtkDrawBuffers(count, buffers); this->Context->GetState()->vtkDrawBuffers(count, buffers, this);
delete[] buffers; delete[] buffers;
this->ActiveBuffers.clear(); this->ActiveBuffers.clear();
...@@ -689,14 +689,14 @@ void vtkOpenGLFramebufferObject::ActivateDrawBuffers(unsigned int *ids, int num) ...@@ -689,14 +689,14 @@ void vtkOpenGLFramebufferObject::ActivateDrawBuffers(unsigned int *ids, int num)
void vtkOpenGLFramebufferObject::DeactivateDrawBuffers() void vtkOpenGLFramebufferObject::DeactivateDrawBuffers()
{ {
GLenum att = GL_NONE; GLenum att = GL_NONE;
this->Context->GetState()->vtkDrawBuffers(1, &att); this->Context->GetState()->vtkDrawBuffers(1, &att, this);
this->ActiveBuffers.clear(); this->ActiveBuffers.clear();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void vtkOpenGLFramebufferObject::DeactivateReadBuffer() void vtkOpenGLFramebufferObject::DeactivateReadBuffer()
{ {
this->Context->GetState()->vtkReadBuffer(GL_NONE); this->Context->GetState()->vtkReadBuffer(GL_NONE, this);
this->ActiveReadBuffer = GL_NONE; this->ActiveReadBuffer = GL_NONE;
} }
......
...@@ -570,7 +570,9 @@ void vtkOpenGLState::vtkglDrawBuffer(unsigned int val) ...@@ -570,7 +570,9 @@ void vtkOpenGLState::vtkglDrawBuffer(unsigned int val)
{ {
vtkOpenGLCheckStateMacro(); vtkOpenGLCheckStateMacro();
if (this->CurrentState.DrawBinding.Framebuffer && val < GL_COLOR_ATTACHMENT0) if ((this->CurrentState.DrawBinding.Framebuffer ||
this->CurrentState.DrawBinding.Binding) && val < GL_COLOR_ATTACHMENT0
&& val != GL_NONE)
{ {
// todo get rid of the && and make this always an error if FO is set // todo get rid of the && and make this always an error if FO is set
vtkGenericWarningMacro( vtkGenericWarningMacro(
...@@ -607,7 +609,9 @@ void vtkOpenGLState::vtkglDrawBuffers(unsigned int count, unsigned int *vals) ...@@ -607,7 +609,9 @@ void vtkOpenGLState::vtkglDrawBuffers(unsigned int count, unsigned int *vals)
return; return;
} }
if (this->CurrentState.DrawBinding.Framebuffer && vals[0] < GL_COLOR_ATTACHMENT0) if ((this->CurrentState.DrawBinding.Framebuffer ||
this->CurrentState.DrawBinding.Binding) && vals[0] < GL_COLOR_ATTACHMENT0
&& vals[0] != GL_NONE)
{ {
// todo get rid of the && and make this always an error if FO is set // todo get rid of the && and make this always an error if FO is set
vtkGenericWarningMacro( vtkGenericWarningMacro(
...@@ -653,7 +657,10 @@ void vtkOpenGLState::vtkglDrawBuffers(unsigned int count, unsigned int *vals) ...@@ -653,7 +657,10 @@ void vtkOpenGLState::vtkglDrawBuffers(unsigned int count, unsigned int *vals)
vtkCheckOpenGLErrorsWithStack("glDrawBuffers"); vtkCheckOpenGLErrorsWithStack("glDrawBuffers");
} }
void vtkOpenGLState::vtkDrawBuffers(unsigned int count, unsigned int *vals) void vtkOpenGLState::vtkDrawBuffers(
unsigned int count,
unsigned int *vals,
vtkOpenGLFramebufferObject *fo)
{ {
vtkOpenGLCheckStateMacro(); vtkOpenGLCheckStateMacro();
...@@ -670,6 +677,12 @@ void vtkOpenGLState::vtkDrawBuffers(unsigned int count, unsigned int *vals) ...@@ -670,6 +677,12 @@ void vtkOpenGLState::vtkDrawBuffers(unsigned int count, unsigned int *vals)
" be called from vtkOpenGLFramebufferObject."); " be called from vtkOpenGLFramebufferObject.");
} }
if (fo != this->CurrentState.DrawBinding.Framebuffer)
{
vtkGenericWarningMacro(
"Attempt to set draw buffers from a Framebuffer Object that is not bound.");
}
#ifndef NO_CACHE #ifndef NO_CACHE
bool changed = false; bool changed = false;
for (int i = 0; i < static_cast<int>(count) && i < 10; ++i) for (int i = 0; i < static_cast<int>(count) && i < 10; ++i)
...@@ -696,7 +709,9 @@ void vtkOpenGLState::vtkglReadBuffer(unsigned int val) ...@@ -696,7 +709,9 @@ void vtkOpenGLState::vtkglReadBuffer(unsigned int val)
{ {
vtkOpenGLCheckStateMacro(); vtkOpenGLCheckStateMacro();
if (this->CurrentState.ReadBinding.Framebuffer && val < GL_COLOR_ATTACHMENT0) if ((this->CurrentState.ReadBinding.Framebuffer ||
this->CurrentState.ReadBinding.Binding) && val < GL_COLOR_ATTACHMENT0
&& val != GL_NONE)
{ {
vtkGenericWarningMacro( vtkGenericWarningMacro(
"A vtkOpenGLFramebufferObject is currently bound but a hardware draw bufer was requested."); "A vtkOpenGLFramebufferObject is currently bound but a hardware draw bufer was requested.");
...@@ -723,7 +738,7 @@ void vtkOpenGLState::vtkglReadBuffer(unsigned int val) ...@@ -723,7 +738,7 @@ void vtkOpenGLState::vtkglReadBuffer(unsigned int val)
vtkCheckOpenGLErrorsWithStack("glReadBuffer"); vtkCheckOpenGLErrorsWithStack("glReadBuffer");
} }
void vtkOpenGLState::vtkReadBuffer(unsigned int val) void vtkOpenGLState::vtkReadBuffer(unsigned int val, vtkOpenGLFramebufferObject *fo)
{ {
vtkOpenGLCheckStateMacro(); vtkOpenGLCheckStateMacro();
...@@ -735,6 +750,12 @@ void vtkOpenGLState::vtkReadBuffer(unsigned int val) ...@@ -735,6 +750,12 @@ void vtkOpenGLState::vtkReadBuffer(unsigned int val)
" be called from vtkOpenGLFramebufferObject."); " be called from vtkOpenGLFramebufferObject.");
} }
if (fo != this->CurrentState.ReadBinding.Framebuffer)
{
vtkGenericWarningMacro(
"Attempt to set read buffer from a Framebuffer Object that is not bound.");
}
#ifndef NO_CACHE #ifndef NO_CACHE
if (this->CurrentState.ReadBinding.ReadBuffer != val) if (this->CurrentState.ReadBinding.ReadBuffer != val)
#endif #endif
......
...@@ -106,8 +106,8 @@ public: ...@@ -106,8 +106,8 @@ public:
void vtkglReadBuffer(unsigned int); void vtkglReadBuffer(unsigned int);
void vtkBindFramebuffer(unsigned int target, vtkOpenGLFramebufferObject *fo); void vtkBindFramebuffer(unsigned int target, vtkOpenGLFramebufferObject *fo);
void vtkDrawBuffers(unsigned int n, unsigned int *); void vtkDrawBuffers(unsigned int n, unsigned int *, vtkOpenGLFramebufferObject *);
void vtkReadBuffer(unsigned int); void vtkReadBuffer(unsigned int, vtkOpenGLFramebufferObject *);
//@} //@}
//@{ //@{
......
...@@ -1735,13 +1735,13 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::EndImageSample( ...@@ -1735,13 +1735,13 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::EndImageSample(
if (this->Parent->ImageSampleDistance != 1.f) if (this->Parent->ImageSampleDistance != 1.f)
{ {
this->ImageSampleFBO->DeactivateDrawBuffers(); this->ImageSampleFBO->DeactivateDrawBuffers();
this->ImageSampleFBO->RestorePreviousBindingsAndBuffers(
GL_DRAW_FRAMEBUFFER);
if (this->RenderPassAttached) if (this->RenderPassAttached)
{ {
this->ImageSampleFBO->ActivateDrawBuffers( this->ImageSampleFBO->ActivateDrawBuffers(
static_cast<unsigned int>(this->NumImageSampleDrawBuffers)); static_cast<unsigned int>(this->NumImageSampleDrawBuffers));
} }
this->ImageSampleFBO->RestorePreviousBindingsAndBuffers(
GL_DRAW_FRAMEBUFFER);
// Render the contents of ImageSampleFBO as a quad to intermix with the // Render the contents of ImageSampleFBO as a quad to intermix with the
// rest of the scene. // rest of the scene.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment