1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGLCoincidentTopologyResolutionPainter.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkOpenGLCoincidentTopologyResolutionPainter.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkMapper.h" // for VTK_RESOLVE_*
#include "vtkObjectFactory.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkOpenGL.h"
#include "vtkOpenGLError.h"
vtkStandardNewMacro(vtkOpenGLCoincidentTopologyResolutionPainter);
//-----------------------------------------------------------------------------
vtkOpenGLCoincidentTopologyResolutionPainter::
vtkOpenGLCoincidentTopologyResolutionPainter()
{
}
//-----------------------------------------------------------------------------
vtkOpenGLCoincidentTopologyResolutionPainter::
~vtkOpenGLCoincidentTopologyResolutionPainter()
{
}
//-----------------------------------------------------------------------------
void vtkOpenGLCoincidentTopologyResolutionPainter::RenderInternal(
vtkRenderer *renderer, vtkActor *actor, unsigned long typeflags,
bool forceCompileOnly)
{
vtkProperty* prop = actor->GetProperty();
bool draw_surface_with_edges =
(prop->GetEdgeVisibility() && prop->GetRepresentation() == VTK_SURFACE);
int rct = draw_surface_with_edges? VTK_RESOLVE_OFF: this->ResolveCoincidentTopology;
switch (rct)
{
case VTK_RESOLVE_OFF:
this->Superclass::RenderInternal(renderer, actor,
typeflags, forceCompileOnly);
break;
case VTK_RESOLVE_POLYGON_OFFSET:
this->RenderPolygonOffset(renderer, actor, typeflags, forceCompileOnly);
break;
case VTK_RESOLVE_SHIFT_ZBUFFER:
this->RenderShiftZBuffer(renderer, actor, typeflags, forceCompileOnly);
break;
}
}
//-----------------------------------------------------------------------------
void vtkOpenGLCoincidentTopologyResolutionPainter::RenderPolygonOffset(
vtkRenderer *renderer, vtkActor *actor, unsigned long typeflags,
bool forceCompileOnly)
{
#ifdef GL_VERSION_1_1
vtkOpenGLClearErrorMacro();
if (this->OffsetFaces)
{
glEnable(GL_POLYGON_OFFSET_FILL);
}
else
{
glEnable(GL_POLYGON_OFFSET_LINE);
glEnable(GL_POLYGON_OFFSET_POINT);
}
glPolygonOffset(this->PolygonOffsetFactor, this->PolygonOffsetUnits);
#endif
this->Superclass::RenderInternal(renderer, actor, typeflags,
forceCompileOnly);
#ifdef GL_VERSION_1_1
if (this->OffsetFaces)
{
glDisable(GL_POLYGON_OFFSET_FILL);
}
else
{
glDisable(GL_POLYGON_OFFSET_LINE);
glDisable(GL_POLYGON_OFFSET_POINT);
}
vtkOpenGLCheckErrorMacro("failed after RenderPolygonOffset");
#endif
}
//-----------------------------------------------------------------------------
void vtkOpenGLCoincidentTopologyResolutionPainter::RenderShiftZBuffer(
vtkRenderer *renderer, vtkActor *actor, unsigned long typeflags,
bool forceCompileOnly)
{
vtkOpenGLClearErrorMacro();
// Get the flags for each type of primitive. Polygons can be drawn
// as vertices or lines rather than filled, so check the property and
// OpenGL flags to try to determine which one we are doing.
unsigned long vertFlags = typeflags & vtkPainter::VERTS;
unsigned long lineFlags = typeflags & vtkPainter::LINES;
unsigned long polyFlags = 0;
int actorRep = actor->GetProperty()->GetRepresentation();
GLint oglPolyMode[2];
glGetIntegerv(GL_POLYGON_MODE, oglPolyMode);
if ((actorRep == VTK_POINTS) || (oglPolyMode[0] == GL_POINT))
{
vertFlags |= typeflags & (vtkPainter::POLYS | vtkPainter::STRIPS);
}
else if ((actorRep == VTK_WIREFRAME) || (oglPolyMode[0] == GL_LINE))
{
lineFlags |= typeflags & (vtkPainter::POLYS | vtkPainter::STRIPS);
}
else
{
polyFlags |= typeflags & (vtkPainter::POLYS | vtkPainter::STRIPS);
}
GLint stackDepth, maxStackDepth;
glGetIntegerv(GL_PROJECTION_STACK_DEPTH, &stackDepth);
glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH, &maxStackDepth);
// We need to push the projection matrix on the stack. Unfortunately, the
// projection matrix stack can be small, so we check to make sure that we
// can do it.
if (stackDepth < maxStackDepth)
{
double range[2];
renderer->GetActiveCamera()->GetClippingRange(range);
if (vertFlags)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glTranslated(0.0, 0.0, 2.0*this->ZShift*(range[1]-range[0]));
vtkOpenGLCheckErrorMacro("failed after setup");
this->Superclass::RenderInternal(renderer, actor, vertFlags,
forceCompileOnly);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
if (lineFlags)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glTranslated(0.0, 0.0, this->ZShift*(range[1]-range[0]));
vtkOpenGLCheckErrorMacro("failed after setup");
this->Superclass::RenderInternal(renderer, actor, lineFlags,
forceCompileOnly);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
if (polyFlags)
{
this->Superclass::RenderInternal(renderer, actor, polyFlags,
forceCompileOnly);
}
}
else
{
this->Superclass::RenderInternal(renderer, actor, typeflags,
forceCompileOnly);
}
vtkOpenGLCheckErrorMacro("failed after RenderShiftZBuffer");
}
//-----------------------------------------------------------------------------
void vtkOpenGLCoincidentTopologyResolutionPainter::PrintSelf(
ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
|