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()
count++;
}
this->Context->GetState()->vtkDrawBuffers(count, buffers);
this->Context->GetState()->vtkDrawBuffers(count, buffers, this);
delete[] buffers;
}
......@@ -620,7 +620,7 @@ void vtkOpenGLFramebufferObject::ActivateReadBuffer(
unsigned int colorAtt)
{
colorAtt += GL_COLOR_ATTACHMENT0;
this->Context->GetState()->vtkReadBuffer((GLenum)colorAtt);
this->Context->GetState()->vtkReadBuffer((GLenum)colorAtt, this);
this->ActiveReadBuffer = colorAtt;
}
......@@ -639,7 +639,7 @@ void vtkOpenGLFramebufferObject::ActivateDrawBuffers(unsigned int num)
count++;
}
this->Context->GetState()->vtkDrawBuffers(count, buffers);
this->Context->GetState()->vtkDrawBuffers(count, buffers, this);
delete[] buffers;
this->ActiveBuffers.clear();
......@@ -674,7 +674,7 @@ void vtkOpenGLFramebufferObject::ActivateDrawBuffers(unsigned int *ids, int num)
count++;
}
this->Context->GetState()->vtkDrawBuffers(count, buffers);
this->Context->GetState()->vtkDrawBuffers(count, buffers, this);
delete[] buffers;
this->ActiveBuffers.clear();
......@@ -689,14 +689,14 @@ void vtkOpenGLFramebufferObject::ActivateDrawBuffers(unsigned int *ids, int num)
void vtkOpenGLFramebufferObject::DeactivateDrawBuffers()
{
GLenum att = GL_NONE;
this->Context->GetState()->vtkDrawBuffers(1, &att);
this->Context->GetState()->vtkDrawBuffers(1, &att, this);
this->ActiveBuffers.clear();
}
//----------------------------------------------------------------------------
void vtkOpenGLFramebufferObject::DeactivateReadBuffer()
{
this->Context->GetState()->vtkReadBuffer(GL_NONE);
this->Context->GetState()->vtkReadBuffer(GL_NONE, this);
this->ActiveReadBuffer = GL_NONE;
}
......
......@@ -570,7 +570,9 @@ void vtkOpenGLState::vtkglDrawBuffer(unsigned int val)
{
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
vtkGenericWarningMacro(
......@@ -607,7 +609,9 @@ void vtkOpenGLState::vtkglDrawBuffers(unsigned int count, unsigned int *vals)
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
vtkGenericWarningMacro(
......@@ -653,7 +657,10 @@ void vtkOpenGLState::vtkglDrawBuffers(unsigned int count, unsigned int *vals)
vtkCheckOpenGLErrorsWithStack("glDrawBuffers");
}
void vtkOpenGLState::vtkDrawBuffers(unsigned int count, unsigned int *vals)
void vtkOpenGLState::vtkDrawBuffers(
unsigned int count,
unsigned int *vals,
vtkOpenGLFramebufferObject *fo)
{
vtkOpenGLCheckStateMacro();
......@@ -670,6 +677,12 @@ void vtkOpenGLState::vtkDrawBuffers(unsigned int count, unsigned int *vals)
" 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
bool changed = false;
for (int i = 0; i < static_cast<int>(count) && i < 10; ++i)
......@@ -696,7 +709,9 @@ void vtkOpenGLState::vtkglReadBuffer(unsigned int val)
{
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(
"A vtkOpenGLFramebufferObject is currently bound but a hardware draw bufer was requested.");
......@@ -723,7 +738,7 @@ void vtkOpenGLState::vtkglReadBuffer(unsigned int val)
vtkCheckOpenGLErrorsWithStack("glReadBuffer");
}
void vtkOpenGLState::vtkReadBuffer(unsigned int val)
void vtkOpenGLState::vtkReadBuffer(unsigned int val, vtkOpenGLFramebufferObject *fo)
{
vtkOpenGLCheckStateMacro();
......@@ -735,6 +750,12 @@ void vtkOpenGLState::vtkReadBuffer(unsigned int val)
" 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
if (this->CurrentState.ReadBinding.ReadBuffer != val)
#endif
......
......@@ -106,8 +106,8 @@ public:
void vtkglReadBuffer(unsigned int);
void vtkBindFramebuffer(unsigned int target, vtkOpenGLFramebufferObject *fo);
void vtkDrawBuffers(unsigned int n, unsigned int *);
void vtkReadBuffer(unsigned int);
void vtkDrawBuffers(unsigned int n, unsigned int *, vtkOpenGLFramebufferObject *);
void vtkReadBuffer(unsigned int, vtkOpenGLFramebufferObject *);
//@}
//@{
......
......@@ -1735,13 +1735,13 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::EndImageSample(
if (this->Parent->ImageSampleDistance != 1.f)
{
this->ImageSampleFBO->DeactivateDrawBuffers();
this->ImageSampleFBO->RestorePreviousBindingsAndBuffers(
GL_DRAW_FRAMEBUFFER);
if (this->RenderPassAttached)
{
this->ImageSampleFBO->ActivateDrawBuffers(
static_cast<unsigned int>(this->NumImageSampleDrawBuffers));
}
this->ImageSampleFBO->RestorePreviousBindingsAndBuffers(
GL_DRAW_FRAMEBUFFER);
// Render the contents of ImageSampleFBO as a quad to intermix with the
// 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