Commit aae43de7 authored by Ken Martin's avatar Ken Martin

Better handling of thick lines in a couple places

Have the actor2D and context3d only use/warn about thick lines
if the hardware does not support them
parent edfcf35d
......@@ -359,6 +359,21 @@ void vtkOpenGLContextDevice3D::ReadyVCBOProgram()
}
}
bool vtkOpenGLContextDevice3D::HaveWideLines()
{
if (this->Pen->GetWidth() > 1.0
&& vtkOpenGLRenderWindow::GetContextSupportsOpenGL32())
{
// we have wide lines, but the OpenGL implementation may
// actually support them, check the range to see if we
// really need have to implement our own wide lines
return !(this->RenderWindow &&
this->RenderWindow->GetMaximumHardwareLineWidth() >= this->Pen->GetWidth());
}
return false;
}
void vtkOpenGLContextDevice3D::DrawPoly(const float *verts, int n,
const unsigned char *colors, int nc)
{
......@@ -376,12 +391,6 @@ void vtkOpenGLContextDevice3D::DrawPoly(const float *verts, int n,
this->Storage->SetLineType(this->Pen->GetLineType());
if (this->Pen->GetWidth() > 1.0)
{
vtkErrorMacro(<< "lines wider than 1.0 are not supported\n");
}
glLineWidth(this->Pen->GetWidth());
vtkOpenGLHelper *cbo = 0;
if (colors)
{
......@@ -392,6 +401,14 @@ void vtkOpenGLContextDevice3D::DrawPoly(const float *verts, int n,
{
this->ReadyVBOProgram();
cbo = this->VBO;
if (this->HaveWideLines())
{
vtkWarningMacro(<< "a line width has been requested that is larger than your system supports");
}
else
{
glLineWidth(this->Pen->GetWidth());
}
cbo->Program->SetUniform4uc("vertexColor",
this->Pen->GetColor());
}
......
......@@ -145,6 +145,9 @@ protected:
float *tcoords);
void CoreDrawTriangles(std::vector<float> &tverts);
// do we have wide lines that require special handling
virtual bool HaveWideLines();
vtkTransform *ModelMatrix;
// Description:
......
......@@ -133,13 +133,11 @@ bool vtkOpenGLPolyDataMapper2D::GetNeedToRebuildShaders(
//-----------------------------------------------------------------------------
void vtkOpenGLPolyDataMapper2D::BuildShaders(
std::string &VSSource, std::string &FSSource, std::string &GSSource,
vtkViewport* vtkNotUsed(viewport), vtkActor2D *actor)
vtkViewport* viewport, vtkActor2D *actor)
{
VSSource = vtkPolyData2DVS;
FSSource = vtkPolyData2DFS;
if (this->LastBoundBO == &this->Lines
&& actor->GetProperty()->GetLineWidth() > 1.0
&& vtkOpenGLRenderWindow::GetContextSupportsOpenGL32())
if (this->HaveWideLines(viewport, actor))
{
GSSource = vtkPolyDataWideLineGS;
}
......@@ -316,7 +314,7 @@ void vtkOpenGLPolyDataMapper2D::UpdateShaders(vtkOpenGLHelper &cellBO,
//-----------------------------------------------------------------------------
void vtkOpenGLPolyDataMapper2D::SetMapperShaderParameters(
vtkOpenGLHelper &cellBO, vtkViewport *vtkNotUsed(viewport), vtkActor2D *actor)
vtkOpenGLHelper &cellBO, vtkViewport *viewport, vtkActor2D *actor)
{
// Now to update the VAO too, if necessary.
if (this->VBOUpdateTime > cellBO.AttributeUpdateTime ||
......@@ -381,9 +379,7 @@ void vtkOpenGLPolyDataMapper2D::SetMapperShaderParameters(
}
// handle wide lines
if (this->LastBoundBO == &this->Lines
&& actor->GetProperty()->GetLineWidth() > 1.0
&& vtkOpenGLRenderWindow::GetContextSupportsOpenGL32())
if (this->HaveWideLines(viewport,actor))
{
int vp[4];
glGetIntegerv(GL_VIEWPORT, vp);
......@@ -678,6 +674,24 @@ void vtkOpenGLPolyDataMapper2D::UpdateVBO(vtkActor2D *act, vtkViewport *viewport
}
}
bool vtkOpenGLPolyDataMapper2D::HaveWideLines(
vtkViewport *ren,
vtkActor2D *actor)
{
if (this->LastBoundBO == &this->Lines
&& actor->GetProperty()->GetLineWidth() > 1.0
&& vtkOpenGLRenderWindow::GetContextSupportsOpenGL32())
{
// we have wide lines, but the OpenGL implementation may
// actually support them, check the range to see if we
// really need have to implement our own wide lines
vtkOpenGLRenderWindow *renWin =
vtkOpenGLRenderWindow::SafeDownCast(ren->GetVTKWindow());
return !(renWin &&
renWin->GetMaximumHardwareLineWidth() >= actor->GetProperty()->GetLineWidth());
}
return false;
}
void vtkOpenGLPolyDataMapper2D::RenderOverlay(vtkViewport* viewport,
vtkActor2D* actor)
......@@ -759,8 +773,7 @@ void vtkOpenGLPolyDataMapper2D::RenderOverlay(vtkViewport* viewport,
this->UpdateShaders(this->Lines, viewport, actor);
this->Lines.Program->SetUniformi("PrimitiveIDOffset",
this->PrimitiveIDOffset);
if (!vtkOpenGLRenderWindow::GetContextSupportsOpenGL32() ||
actor->GetProperty()->GetLineWidth() <= 1.0)
if (!this->HaveWideLines(viewport,actor))
{
glLineWidth(actor->GetProperty()->GetLineWidth());
}
......
......@@ -118,6 +118,9 @@ protected:
vtkTimeStamp VBOUpdateTime; // When was the VBO updated?
vtkPoints *TransformedPoints;
// do we have wide lines that require special handling
virtual bool HaveWideLines(vtkViewport *, vtkActor2D *);
private:
vtkOpenGLPolyDataMapper2D(const vtkOpenGLPolyDataMapper2D&); // Not implemented.
void operator=(const vtkOpenGLPolyDataMapper2D&); // Not implemented.
......
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