Skip to content
Snippets Groups Projects
Commit 6c386da4 authored by David C. Lonie's avatar David C. Lonie
Browse files

Move PreserveColorBuffer to vtkRenderer.

This way we can defer to the superclass to "do the right thing"
in vtkExternalOpenGLRenderer::Clear.
parent ca58fe77
No related branches found
No related tags found
No related merge requests found
......@@ -87,6 +87,7 @@ vtkRenderer::vtkRenderer()
this->PathArrayCount = 0;
this->Layer = 0;
this->PreserveColorBuffer = 0;
this->PreserveDepthBuffer = 0;
this->ComputedVisiblePropBounds[0] = VTK_DOUBLE_MAX;
......@@ -619,6 +620,19 @@ vtkWindow *vtkRenderer::GetVTKWindow()
return this->RenderWindow;
}
// ----------------------------------------------------------------------------
void vtkRenderer::SetLayer(int layer)
{
vtkDebugMacro(<< this->GetClassName() << " (" << this
<< "): setting Layer to " << layer);
if (this->Layer != layer)
{
this->Layer = layer;
this->Modified();
}
this->SetPreserveColorBuffer(layer == 0 ? 0 : 1);
}
// Specify the camera to use for this renderer.
void vtkRenderer::SetActiveCamera(vtkCamera *cam)
{
......@@ -1819,8 +1833,7 @@ void vtkRenderer::ExpandBounds(double bounds[6], vtkMatrix4x4 *matrix)
int vtkRenderer::Transparent()
{
// If our layer is the 0th layer, then we are not transparent, else we are.
return (this->Layer == 0 ? 0 : 1);
return this->PreserveColorBuffer;
}
double vtkRenderer::GetTiledAspectRatio()
......
......@@ -339,12 +339,32 @@ public:
// Description:
// Set/Get the layer that this renderer belongs to. This is only used if
// there are layered renderers.
vtkSetMacro(Layer, int);
//
// Note: Changing the layer will update the PreserveColorBuffer setting. If
// the layer is 0, PreserveColorBuffer will be set to false, making the
// bottom renderer opaque. If the layer is non-zero, PreserveColorBuffer will
// be set to true, giving the renderer a transparent background. If other
// PreserveColorBuffer configurations are desired, they must be adjusted after
// the layer is set.
virtual void SetLayer(int layer);
vtkGetMacro(Layer, int);
// Description:
// Normally a renderer is treated as transparent if Layer > 0. To treat a
// renderer at Layer 0 as transparent, set this flag to true.
// By default, the renderer at layer 0 is opaque, and all non-zero layer
// renderers are transparent. This flag allows this behavior to be overridden.
// If true, this setting will force the renderer to preserve the existing
// color buffer regardless of layer. If false, it will always be cleared at
// the start of rendering.
//
// This flag influences the Transparent() method, and is updated by calls to
// SetLayer(). For this reason it should only be set after changing the layer.
vtkGetMacro(PreserveColorBuffer, int);
vtkSetMacro(PreserveColorBuffer, int);
vtkBooleanMacro(PreserveColorBuffer, int);
// Description:
// By default, the depth buffer is reset for each renderer. If this flag is
// true, this renderer will use the existing depth buffer for its rendering.
vtkSetMacro(PreserveDepthBuffer, int);
vtkGetMacro(PreserveDepthBuffer, int);
vtkBooleanMacro(PreserveDepthBuffer, int);
......@@ -549,6 +569,7 @@ protected:
// Shows what layer this renderer belongs to. Only of interested when
// there are layered renderers.
int Layer;
int PreserveColorBuffer;
int PreserveDepthBuffer;
// Holds the result of ComputeVisiblePropBounds so that it is visible from
......
......@@ -45,111 +45,6 @@ vtkExternalOpenGLRenderer::~vtkExternalOpenGLRenderer()
{
}
//----------------------------------------------------------------------------
void vtkExternalOpenGLRenderer::Clear()
{
vtkOpenGLClearErrorMacro();
GLbitfield clear_mask = 0;
if (!this->Transparent() && !this->GetPreserveColorBuffer())
{
glClearColor( static_cast<GLclampf>(this->Background[0]),
static_cast<GLclampf>(this->Background[1]),
static_cast<GLclampf>(this->Background[2]),
static_cast<GLclampf>(0.0));
clear_mask |= GL_COLOR_BUFFER_BIT;
}
if (!this->GetPreserveDepthBuffer())
{
glClearDepth(static_cast<GLclampf>(1.0));
clear_mask |= GL_DEPTH_BUFFER_BIT;
}
vtkDebugMacro(<< "glClear\n");
glClear(clear_mask);
// If gradient background is turned on, draw it now.
if (!this->Transparent() &&
(this->GradientBackground || this->TexturedBackground))
{
double tile_viewport[4];
this->GetRenderWindow()->GetTileViewport(tile_viewport);
glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT);
glDisable(GL_ALPHA_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_1D);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glShadeModel(GL_SMOOTH); // color interpolation
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
{
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
{
glLoadIdentity();
glOrtho(
tile_viewport[0],
tile_viewport[2],
tile_viewport[1],
tile_viewport[3],
-1.0, 1.0);
//top vertices
if (this->TexturedBackground && this->BackgroundTexture)
{
glEnable(GL_TEXTURE_2D);
this->BackgroundTexture->Render(this);
// NOTE: By default the mode is GL_MODULATE. Since the user
// cannot set the mode, the default is set to replace.
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// NOTE: vtkTexture Render enables the alpha test
// so that no buffer is affected if alpha of incoming fragment is
// below the threshold. Here we have to enable it so that it won't
// rejects the fragments of the quad as the alpha is set to 0 on it.
glDisable(GL_ALPHA_TEST);
}
glBegin(GL_QUADS);
glColor4d(this->Background[0],this->Background[1],this->Background[2],
0.0);
glTexCoord2f(0.0, 0.0);
glVertex2f(0.0, 0.0);
glTexCoord2f(1.0, 0.0);
glVertex2f(1.0, 0);
//bottom vertices
glColor4d(this->Background2[0],this->Background2[1],
this->Background2[2],0.0);
glTexCoord2f(1.0, 1.0);
glVertex2f(1.0, 1.0);
glTexCoord2f(0.0, 1.0);
glVertex2f(0.0, 1.0);
glEnd();
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
}
vtkOpenGLCheckErrorMacro("failed after Clear");
}
//----------------------------------------------------------------------------
void vtkExternalOpenGLRenderer::Render(void)
{
......
......@@ -41,23 +41,10 @@ public:
vtkTypeMacro(vtkExternalOpenGLRenderer, vtkOpenGLRenderer);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Implementation for the Clear method that clears the buffer if requested
void Clear(void);
// Description:
// Synchronize camera and light parameters
void Render(void);
// Description:
// Normally the vtkOpenGLRenderer clears the color buffer before rendering a
// new frame. When this flag is true, the color buffer is not cleared. This
// can be helpful when there are multiple visualization systems
// sharing the same context. Default value is 1.
vtkGetMacro(PreserveColorBuffer, int);
vtkSetMacro(PreserveColorBuffer, int);
vtkBooleanMacro(PreserveColorBuffer, int);
// Description:
// Create a new Camera sutible for use with this type of Renderer.
// This function creates the vtkExternalOpenGLCamera.
......@@ -67,8 +54,6 @@ protected:
vtkExternalOpenGLRenderer();
~vtkExternalOpenGLRenderer();
int PreserveColorBuffer;
private:
vtkExternalOpenGLRenderer(const vtkExternalOpenGLRenderer&); // Not implemented.
void operator=(const vtkExternalOpenGLRenderer&); // Not implemented.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment