Commit 1e6e44cb authored by Ken Martin's avatar Ken Martin

Introduce opengl state management

This commit adds a vtkOpenGLState class that is used
to save, restore and cache opengl state. In this commit
the caching is disabled to ease rollout. Likewise only
a few methods are being cached which can be expanded
on later as desired.
parent f21d1c1c
......@@ -21,6 +21,7 @@
#include "vtkOpenGLTexture.h"
#include "vtkTextureObject.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLState.h"
#include "vtkOpenGLError.h"
vtkStandardNewMacro(vtkOpenGLContextBufferId);
......@@ -137,35 +138,24 @@ vtkIdType vtkOpenGLContextBufferId::GetPickedItem(int x, int y)
else
{
this->Context->MakeCurrent();
vtkOpenGLState *ostate = this->Context->GetState();
// Render texture to current write buffer. Texel x,y is rendered at
// pixel x,y (instead of pixel 0,0 to work around pixel ownership test).
GLint savedDrawBuffer;
glGetIntegerv(GL_DRAW_BUFFER,&savedDrawBuffer);
bool savedDepthTest=glIsEnabled(GL_DEPTH_TEST)==GL_TRUE;
bool savedAlphaTest=glIsEnabled(GL_ALPHA_TEST)==GL_TRUE;
bool savedStencilTest=glIsEnabled(GL_STENCIL_TEST)==GL_TRUE;
bool savedBlend=glIsEnabled(GL_BLEND)==GL_TRUE;
vtkOpenGLState::ScopedglEnableDisable dsaver(ostate,GL_DEPTH_TEST);
vtkOpenGLState::ScopedglEnableDisable ssaver(ostate,GL_STENCIL_TEST);
vtkOpenGLState::ScopedglEnableDisable bsaver(ostate,GL_BLEND);
if(savedDrawBuffer!=GL_BACK_LEFT)
{
glDrawBuffer(GL_BACK_LEFT);
}
if(savedDepthTest)
{
glDisable(GL_DEPTH_TEST);
}
if(savedAlphaTest)
{
glDisable(GL_ALPHA_TEST);
}
if(savedStencilTest)
{
glDisable(GL_STENCIL_TEST);
}
if(savedBlend)
{
glDisable(GL_BLEND);
}
ostate->glDisable(GL_DEPTH_TEST);
ostate->glDisable(GL_STENCIL_TEST);
ostate->glDisable(GL_BLEND);
this->Texture->CopyToFrameBuffer(x,y,x,y,x,y,
this->Context->GetSize()[0],
......@@ -193,22 +183,6 @@ vtkIdType vtkOpenGLContextBufferId::GetPickedItem(int x, int y)
{
glDrawBuffer(static_cast<GLenum>(savedDrawBuffer));
}
if(savedDepthTest)
{
glEnable(GL_DEPTH_TEST);
}
if(savedAlphaTest)
{
glEnable(GL_ALPHA_TEST);
}
if(savedStencilTest)
{
glEnable(GL_STENCIL_TEST);
}
if(savedBlend)
{
glEnable(GL_BLEND);
}
int value=(static_cast<int>(rgb[0])<<16)|(static_cast<int>(rgb[1])<<8)
|static_cast<int>(rgb[2]);
......
......@@ -31,6 +31,7 @@
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkOpenGLState.h"
#include "vtkOpenGLTexture.h"
#include "vtkOpenGLVertexArrayObject.h"
#include "vtkOpenGLVertexBufferObject.h"
......@@ -324,13 +325,14 @@ void vtkOpenGLContextDevice2D::Begin(vtkViewport* viewport)
this->ProjectionMatrix->SetMatrix(*matrix);
// Store the previous state before changing it
this->Storage->SaveGLState();
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
this->Renderer = vtkRenderer::SafeDownCast(viewport);
this->RenderWindow = vtkOpenGLRenderWindow::SafeDownCast(this->Renderer->GetRenderWindow());
vtkOpenGLState *ostate = this->RenderWindow->GetState();
this->Storage->SaveGLState(ostate);
ostate->glDisable(GL_DEPTH_TEST);
ostate->glEnable(GL_BLEND);
this->RenderWindow->GetShaderCache()->ReleaseCurrentShader();
// Enable simple line smoothing if multisampling is on.
......@@ -357,7 +359,8 @@ void vtkOpenGLContextDevice2D::End()
vtkOpenGLClearErrorMacro();
// Restore the GL state that we changed
this->Storage->RestoreGLState();
vtkOpenGLState *ostate = this->RenderWindow->GetState();
this->Storage->RestoreGLState(ostate);
// Disable simple line smoothing if multisampling is on.
if (this->Renderer->GetRenderWindow()->GetMultiSamples())
......@@ -383,7 +386,8 @@ void vtkOpenGLContextDevice2D::BufferIdModeBegin(
this->BufferId=bufferId;
// Save OpenGL state.
this->Storage->SaveGLState(true);
vtkOpenGLState *ostate = this->RenderWindow->GetState();
this->Storage->SaveGLState(ostate, true);
int lowerLeft[2];
int usize, vsize;
......@@ -416,12 +420,11 @@ void vtkOpenGLContextDevice2D::BufferIdModeBegin(
this->ProjectionMatrix->SetMatrix(*matrix);
glDrawBuffer(GL_BACK_LEFT);
glClearColor(0.0,0.0,0.0,0.0); // id=0 means no hit, just background
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_ALPHA_TEST);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
ostate->glClearColor(0.0,0.0,0.0,0.0); // id=0 means no hit, just background
ostate->glClear(GL_COLOR_BUFFER_BIT);
ostate->glDisable(GL_STENCIL_TEST);
ostate->glDisable(GL_DEPTH_TEST);
ostate->glDisable(GL_BLEND);
vtkOpenGLCheckErrorMacro("failed after BufferIdModeBegin");
......@@ -444,7 +447,7 @@ void vtkOpenGLContextDevice2D::BufferIdModeEnd()
this->ProjectionMatrix->Pop();
this->PopMatrix();
this->Storage->RestoreGLState(true);
this->Storage->RestoreGLState(this->RenderWindow->GetState(), true);
this->BufferId=nullptr;
......@@ -2151,20 +2154,13 @@ void vtkOpenGLContextDevice2D::SetClipping(int *dim)
vp[3] = dim[3];
}
glScissor(vp[0], vp[1], vp[2], vp[3]);
this->RenderWindow->GetState()->glScissor(vp[0], vp[1], vp[2], vp[3]);
}
//-----------------------------------------------------------------------------
void vtkOpenGLContextDevice2D::EnableClipping(bool enable)
{
if (enable)
{
glEnable(GL_SCISSOR_TEST);
}
else
{
glDisable(GL_SCISSOR_TEST);
}
this->RenderWindow->GetState()->SetEnumState(GL_SCISSOR_TEST, enable);
}
//-----------------------------------------------------------------------------
......
......@@ -276,7 +276,6 @@ public:
vtkContextDevice2D::Stretch;
this->SpriteTexture = nullptr;
this->SavedDepthTest = GL_TRUE;
this->SavedAlphaTest = GL_TRUE;
this->SavedStencilTest = GL_TRUE;
this->SavedBlend = GL_TRUE;
this->SavedDrawBuffer = 0;
......@@ -303,60 +302,37 @@ public:
}
}
void SaveGLState(bool colorBuffer = false)
void SaveGLState(vtkOpenGLState *ostate, bool colorBuffer = false)
{
this->SavedDepthTest = glIsEnabled(GL_DEPTH_TEST);
this->SavedDepthTest = ostate->GetEnumState(GL_DEPTH_TEST);
if (colorBuffer)
{
this->SavedAlphaTest = glIsEnabled(GL_ALPHA_TEST);
this->SavedStencilTest = glIsEnabled(GL_STENCIL_TEST);
this->SavedBlend = glIsEnabled(GL_BLEND);
glGetFloatv(GL_COLOR_CLEAR_VALUE, this->SavedClearColor);
this->SavedStencilTest = ostate->GetEnumState(GL_STENCIL_TEST);
this->SavedBlend = ostate->GetEnumState(GL_BLEND);
ostate->GetClearColor(this->SavedClearColor);
glGetIntegerv(GL_DRAW_BUFFER, &this->SavedDrawBuffer);
}
}
void RestoreGLState(bool colorBuffer = false)
void RestoreGLState(vtkOpenGLState *ostate, bool colorBuffer = false)
{
this->SetGLCapability(GL_DEPTH_TEST, this->SavedDepthTest);
ostate->SetEnumState(GL_DEPTH_TEST, this->SavedDepthTest);
if (colorBuffer)
{
this->SetGLCapability(GL_ALPHA_TEST, this->SavedAlphaTest);
this->SetGLCapability(GL_STENCIL_TEST, this->SavedStencilTest);
this->SetGLCapability(GL_BLEND, this->SavedBlend);
ostate->SetEnumState(GL_STENCIL_TEST, this->SavedStencilTest);
ostate->SetEnumState(GL_BLEND, this->SavedBlend);
if(this->SavedDrawBuffer != GL_BACK_LEFT)
{
glDrawBuffer(this->SavedDrawBuffer);
}
int i = 0;
bool colorDiffer = false;
while(!colorDiffer && i < 4)
{
colorDiffer=this->SavedClearColor[i++] != 0.0;
}
if(colorDiffer)
{
glClearColor(this->SavedClearColor[0],
ostate->glClearColor(this->SavedClearColor[0],
this->SavedClearColor[1],
this->SavedClearColor[2],
this->SavedClearColor[3]);
}
}
}
void SetGLCapability(GLenum capability, GLboolean state)
{
if (state)
{
glEnable(capability);
}
else
{
glDisable(capability);
}
}
......@@ -516,10 +492,9 @@ public:
unsigned int TextureProperties;
vtkTexture *SpriteTexture;
// Store the previous GL state so that we can restore it when complete
GLboolean SavedDepthTest;
GLboolean SavedAlphaTest;
GLboolean SavedStencilTest;
GLboolean SavedBlend;
bool SavedDepthTest;
bool SavedStencilTest;
bool SavedBlend;
GLint SavedDrawBuffer;
GLfloat SavedClearColor[4];
......
......@@ -26,6 +26,7 @@
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkOpenGLState.h"
#include "vtkOpenGLVertexArrayObject.h"
#include "vtkOpenGLVertexBufferObject.h"
#include "vtkPen.h"
......@@ -37,38 +38,12 @@ class vtkOpenGLContextDevice3D::Private
public:
Private()
{
this->SavedDepthTest = GL_TRUE;
}
~Private()
{
}
void SaveGLState()
{
this->SavedDepthTest = glIsEnabled(GL_DEPTH_TEST);
this->SavedBlending = glIsEnabled(GL_BLEND);
}
void RestoreGLState()
{
this->SetGLCapability(GL_DEPTH_TEST, this->SavedDepthTest);
this->SetGLCapability(GL_BLEND, this->SavedBlending);
}
void SetGLCapability(GLenum capability, GLboolean state)
{
if (state)
{
glEnable(capability);
}
else
{
glDisable(capability);
}
vtkOpenGLStaticCheckErrorMacro("failed after SetGLCapability");
}
void Transpose(double *in, double *transposed)
{
transposed[0] = in[0];
......@@ -101,11 +76,6 @@ public:
vtkGenericWarningMacro(<< "Line Stipples are no longer supported");
}
// Store the previous GL state so that we can restore it when complete
GLboolean SavedLighting;
GLboolean SavedDepthTest;
GLboolean SavedBlending;
vtkVector2i Dim;
vtkVector2i Offset;
};
......@@ -153,8 +123,8 @@ void vtkOpenGLContextDevice3D::Begin(vtkViewport* vtkNotUsed(viewport))
void vtkOpenGLContextDevice3D::SetMatrices(vtkShaderProgram *prog)
{
glDisable(GL_SCISSOR_TEST);
vtkOpenGLState *ostate = this->RenderWindow->GetState();
ostate->glDisable(GL_SCISSOR_TEST);
prog->SetUniformMatrix("WCDCMatrix",
this->Device2D->GetProjectionMatrix());
......@@ -649,19 +619,14 @@ void vtkOpenGLContextDevice3D::SetClipping(const vtkRecti &rect)
vp[3] = rect.GetHeight();
}
glScissor(vp[0], vp[1], vp[2], vp[3]);
vtkOpenGLState *ostate = this->RenderWindow->GetState();
ostate->glScissor(vp[0], vp[1], vp[2], vp[3]);
}
void vtkOpenGLContextDevice3D::EnableClipping(bool enable)
{
if (enable)
{
glEnable(GL_SCISSOR_TEST);
}
else
{
glDisable(GL_SCISSOR_TEST);
}
vtkOpenGLState *ostate = this->RenderWindow->GetState();
ostate->SetEnumState(GL_SCISSOR_TEST, enable);
}
void vtkOpenGLContextDevice3D::EnableClippingPlane(int i, double *planeEquation)
......@@ -690,12 +655,14 @@ void vtkOpenGLContextDevice3D::DisableClippingPlane(int i)
void vtkOpenGLContextDevice3D::EnableDepthBuffer()
{
glEnable(GL_DEPTH_TEST);
vtkOpenGLState *ostate = this->RenderWindow->GetState();
ostate->glEnable(GL_DEPTH_TEST);
}
void vtkOpenGLContextDevice3D::DisableDepthBuffer()
{
glDisable(GL_DEPTH_TEST);
vtkOpenGLState *ostate = this->RenderWindow->GetState();
ostate->glDisable(GL_DEPTH_TEST);
}
void vtkOpenGLContextDevice3D::PrintSelf(ostream &os, vtkIndent indent)
......
......@@ -307,11 +307,11 @@ void vtkLabeledContourMapper::Render(vtkRenderer *ren, vtkActor *act)
if (!this->RenderPolyData(ren, act))
{
this->RemoveStencil();
this->RemoveStencil(ren);
return;
}
if (!this->RemoveStencil())
if (!this->RemoveStencil(ren))
{
return;
}
......@@ -869,7 +869,7 @@ bool vtkLabeledContourMapper::RenderPolyData(vtkRenderer *ren, vtkActor *act)
}
//------------------------------------------------------------------------------
bool vtkLabeledContourMapper::RemoveStencil()
bool vtkLabeledContourMapper::RemoveStencil(vtkRenderer *)
{
// Handled in backend override.
return true;
......
......@@ -158,7 +158,7 @@ protected:
bool BuildStencilQuads();
virtual bool ApplyStencil(vtkRenderer *ren, vtkActor *act);
bool RenderPolyData(vtkRenderer *ren, vtkActor *act);
virtual bool RemoveStencil();
virtual bool RemoveStencil(vtkRenderer *ren);
bool RenderLabels(vtkRenderer *ren, vtkActor *act);
bool AllocateTextActors(vtkIdType num);
......
......@@ -19,6 +19,7 @@
#include "vtkOpenGLError.h"
#include "vtkOpenGL.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLState.h"
#include "vtkOutputWindow.h"
#include "vtkPerspectiveTransform.h"
#include "vtkRenderer.h"
......@@ -44,6 +45,7 @@ void vtkExternalOpenGLCamera::Render(vtkRenderer *ren)
int usize, vsize;
vtkOpenGLRenderWindow *win = vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow());
vtkOpenGLState *ostate = win->GetState();
// find out if we should stereo render
this->Stereo = (ren->GetRenderWindow())->GetStereoRender();
......@@ -120,9 +122,9 @@ void vtkExternalOpenGLCamera::Render(vtkRenderer *ren)
}
}
glViewport(lowerLeft[0], lowerLeft[1], usize, vsize);
glEnable(GL_SCISSOR_TEST);
glScissor(lowerLeft[0], lowerLeft[1], usize, vsize);
ostate->glViewport(lowerLeft[0], lowerLeft[1], usize, vsize);
ostate->glEnable(GL_SCISSOR_TEST);
ostate->glScissor(lowerLeft[0], lowerLeft[1], usize, vsize);
if ((ren->GetRenderWindow())->GetErase() && ren->GetErase()
&& !ren->GetIsPicking())
......
......@@ -14,27 +14,6 @@
=========================================================================*/
#include "vtkCompositeSurfaceLICMapper.h"
// #include "vtkBoundingBox.h"
// #include "vtkCommand.h"
// #include "vtkCompositeDataIterator.h"
// #include "vtkCompositeDataPipeline.h"
//#include "vtkCompositeDataSet.h"
// #include "vtkCompositeDataDisplayAttributes.h"
// #include "vtkGarbageCollector.h"
//#include "vtkHardwareSelector.h"
// #include "vtkInformation.h"
// #include "vtkMath.h"
//#include "vtkObjectFactory.h"
// #include "vtkPolyData.h"
// #include "vtkProperty.h"
// #include "vtkRenderer.h"
// #include "vtkRenderWindow.h"
// #include "vtkScalarsToColors.h"
// #include "vtkShaderProgram.h"
// #include "vtkUnsignedCharArray.h"
// #include "vtkMultiBlockDataSet.h"
// #include "vtkMultiPieceDataSet.h"
#include "vtk_glew.h"
#include "vtkCellData.h"
......@@ -56,6 +35,7 @@
#include "vtkOpenGLIndexBufferObject.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLState.h"
#include "vtkOpenGLTexture.h"
#include "vtkOpenGLVertexArrayObject.h"
#include "vtkOpenGLVertexBufferObject.h"
......@@ -315,7 +295,9 @@ void vtkCompositeSurfaceLICMapper::Render(
// Before start rendering LIC, capture some essential state so we can restore
// it.
bool blendEnabled = (glIsEnabled(GL_BLEND) == GL_TRUE);
vtkOpenGLRenderWindow *rw = vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow());
vtkOpenGLState *ostate = rw->GetState();
vtkOpenGLState::ScopedglEnableDisable bsaver(ostate, GL_BLEND);
vtkNew<vtkOpenGLFramebufferObject> fbo;
fbo->SetContext(vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow()));
......@@ -345,13 +327,4 @@ void vtkCompositeSurfaceLICMapper::Render(
this->LICInterface->CopyToScreen();
fbo->RestorePreviousBindingsAndBuffers();
if (blendEnabled)
{
glEnable(GL_BLEND);
}
else
{
glDisable(GL_BLEND);
}
}
......@@ -28,6 +28,7 @@
#include "vtkObjectFactory.h"
#include "vtkLineIntegralConvolution2D.h"
#include "vtkOpenGLFramebufferObject.h"
#include "vtkOpenGLState.h"
#include "vtkRenderbuffer.h"
#include "vtkPixelBufferObject.h"
#include "vtkTextureObject.h"
......@@ -454,8 +455,8 @@ int vtkImageDataLIC2D::RequestData(
drawFbo->CheckFrameBufferStatus(GL_FRAMEBUFFER);
drawFbo->InitializeViewport(magVectorSize[0], magVectorSize[1]);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
this->Context->GetState()->glClearColor(0.0, 0.0, 0.0, 0.0);
this->Context->GetState()->glClear(GL_COLOR_BUFFER_BIT);
float tcoords[] = {
0.0f, 0.0f,
......
......@@ -28,6 +28,7 @@
#include "vtkOpenGLRenderUtilities.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkOpenGLState.h"
#include "vtkOpenGLVertexArrayObject.h"
#include "vtkPainterCommunicator.h"
#include "vtkPixelBufferObject.h"
......@@ -271,6 +272,8 @@ public:
const deque<vtkPixelExtent> &extents,
int clearEETex = 0)
{
vtkOpenGLState *ostate = fbo->GetContext()->GetState();
//attach
fbo->AddColorAttachment(GL_DRAW_FRAMEBUFFER, 0U, this->LICTexture0);
fbo->AddColorAttachment(GL_DRAW_FRAMEBUFFER, 1U, this->SeedTexture0);
......@@ -287,11 +290,8 @@ public:
// clear the parts of the screen which we will modify
// initially mask all fragments
glClearColor(0.0, 1.0, 0.0, 0.0);
#if 0
glClear(GL_COLOR_BUFFER_BIT);
#else
glEnable(GL_SCISSOR_TEST);
ostate->glClearColor(0.0, 1.0, 0.0, 0.0);
ostate->glEnable(GL_SCISSOR_TEST);
size_t nBlocks = extents.size();
for (size_t e=0; e<nBlocks; ++e)
{
......@@ -307,11 +307,10 @@ public:
unsigned int extSize[2];
ext.Size(extSize);
glScissor(ext[0], ext[2], extSize[0], extSize[1]);
glClear(GL_COLOR_BUFFER_BIT);
ostate->glScissor(ext[0], ext[2], extSize[0], extSize[1]);
ostate->glClear(GL_COLOR_BUFFER_BIT);
}
glDisable(GL_SCISSOR_TEST);
#endif
ostate->glDisable(GL_SCISSOR_TEST);
// detach
// detach
fbo->RemoveTexColorAttachments(GL_DRAW_FRAMEBUFFER, num);
......@@ -326,6 +325,8 @@ public:
const vtkPixelExtent &viewExt,
const deque<vtkPixelExtent> &extents)
{
vtkOpenGLState *ostate = fbo->GetContext()->GetState();
//attach
fbo->AddColorAttachment(GL_DRAW_FRAMEBUFFER, 0U, tex);
fbo->ActivateDrawBuffers(1);
......@@ -333,11 +334,8 @@ public:
// clear the parts of the screen which we will modify
// initially mask all fragments
glClearColor(0.0, 1.0, 0.0, 0.0);
#if 0
glClear(GL_COLOR_BUFFER_BIT);
#else
glEnable(GL_SCISSOR_TEST);
ostate->glClearColor(0.0, 1.0, 0.0, 0.0);
ostate->glEnable(GL_SCISSOR_TEST);
size_t nBlocks = extents.size();
for (size_t e=0; e<nBlocks; ++e)
{
......@@ -353,11 +351,10 @@ public:
unsigned int extSize[2];
ext.Size(extSize);
glScissor(ext[0], ext[2], extSize[0], extSize[1]);
glClear(GL_COLOR_BUFFER_BIT);
ostate->glScissor(ext[0], ext[2], extSize[0], extSize[1]);
ostate->glClear(GL_COLOR_BUFFER_BIT);
}
glDisable(GL_SCISSOR_TEST);
#endif
ostate->glDisable(GL_SCISSOR_TEST);
// detach
fbo->RemoveTexColorAttachments(GL_DRAW_FRAMEBUFFER, 1);
fbo->DeactivateDrawBuffers();
......@@ -1411,6 +1408,8 @@ vtkTextureObject *vtkLineIntegralConvolution2D::Execute(
vtkErrorMacro("invalid this->Context");
return nullptr;
}
vtkOpenGLState *ostate = this->Context->GetState();
if (this->NumberOfSteps < 0)
{
vtkErrorMacro("Number of integration steps should be positive.");
......@@ -1549,9 +1548,9 @@ vtkTextureObject *vtkLineIntegralConvolution2D::Execute(
this->VTShader->Program->SetUniformi("texVectors", bufs.GetVectorTextureUnit());
vtkOpenGLCheckErrorMacro("failed");
// essential to initialize the entire buffer
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
ostate->glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
vtkOpenGLCheckErrorMacro("failed");
glClear(GL_COLOR_BUFFER_BIT);
ostate->glClear(GL_COLOR_BUFFER_BIT);
vtkOpenGLCheckErrorMacro("failed");
size_t nVectorExtents = vectorExtents.size();
for (size_t q=0; q<nVectorExtents; ++q)
......
......@@ -21,6 +21,7 @@
#include "vtkOpenGLError.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkOpenGLState.h"
#include "vtkPainterCommunicator.h"
#include "vtkPixelBufferObject.h"
#include "vtkPointData.h"
......@@ -180,6 +181,8 @@ void vtkSurfaceLICInterface::UpdateCommunicator(
void vtkSurfaceLICInterface::PrepareForGeometry()
{
vtkOpenGLState *ostate = this->Internals->Context->GetState();
// save the active fbo and its draw buffer
this->PrevDrawBuf = 0;
glGetIntegerv(GL_DRAW_BUFFER, &this->PrevDrawBuf);
......@@ -202,11 +205,11 @@ void vtkSurfaceLICInterface::PrepareForGeometry()
// clear internal color and depth buffers
// the LIC'er requires *all* fragments in the vector
// texture to be initialized to 0
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
ostate->glDisable(GL_BLEND);
ostate->glEnable(GL_DEPTH_TEST);
ostate->glDisable(GL_SCISSOR_TEST);
ostate->glClearColor(0.0, 0.0, 0.0, 0.0);
ostate->glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
}
void vtkSurfaceLICInterface::CompletedGeometry()
......@@ -493,6 +496,7 @@ void vtkSurfaceLICInterface::ApplyLIC()
void vtkSurfaceLICInterface::CombineColorsAndLIC()
{
vtkOpenGLRenderWindow *renWin = this->Internals->Context;
vtkOpenGLState *ostate = renWin->GetState();
vtkPainterCommunicator *comm = this->GetCommunicator();
......@@ -510,8 +514,8 @@ void vtkSurfaceLICInterface::CombineColorsAndLIC()
vtkCheckFrameBufferStatusMacro(GL_FRAMEBUFFER);
// clear the parts of the screen which we will modify
glEnable(GL_SCISSOR_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);
ostate->glEnable(GL_SCISSOR_TEST);
ostate->glClearColor(0.0, 0.0, 0.0, 0.0);
size_t nBlocks = this->Internals->BlockExts.size();
for (size_t e=0; e<nBlocks; ++e)
{
......@@ -522,10 +526,10 @@ void vtkSurfaceLICInterface::CombineColorsAndLIC()
unsigned int extSize[2];
ext.Size(extSize);
glScissor(ext[0], ext[2], extSize[0], extSize[1]);
glClear(GL_COLOR_BUFFER_BIT);
ostate->glScissor(ext[0], ext[2], extSize[0], extSize[1]);
ostate->glClear(GL_COLOR_BUFFER_BIT);
}
glDisable(GL_SCISSOR_TEST);
ostate->glDisable(GL_SCISSOR_TEST);
this->Internals->VectorImage->Activate();
this->Internals->GeometryImage->Activate();
......@@ -665,6 +669,7 @@ void vtkSurfaceLICInterface::CombineColorsAndLIC()
void vtkSurfaceLICInterface::CopyToScreen()
{
vtkOpenGLRenderWindow *renWin = this->Internals->Context;
vtkOpenGLState *ostate = renWin->GetState();
vtkPixelExtent viewExt(