Commit 6643a930 authored by David C. Lonie's avatar David C. Lonie

Restore ability to scale gl2ps linewidth/pointsize.

The functions:

static void vtkGL2PSExporter::SetGlobalLineWidthFactor(float);
static void vtkGL2PSExporter::SetGlobalPointSizeFactor(float);

were removed during the GL2PS rewrite. This patch restores the
functionality by adding LineWidthFactor and PointSizeFactor ivars to
vtkGL2PSExporter and the associated setters:

void vtkGL2PSExporter::SetLineWidthFactor(float)
void vtkGL2PSExporter::SetPointSizeFactor(float)

These attributes are specific to the vtkGL2PSExporter instances, while
the old implementation stored them in global variables.

A vtkOpenGLGL2PSHelper is added to RenderingOpenGL that fakes the
GL2PS function calls needed to update line width, point size, and
stipple state. The public static methods are called from the rendering
code when the GL state is changed to inform GL2PS of the change. The
vtkOpenGLGL2PSHelper class is used to update GL2PS without introducing
a dependency on vtkgl2ps to vtkRenderingOpenGL.

The TestContextGL2PS unit test is modified to ensure that 1.0 scaling
factors are used.

The vtkGL2PSContextDevice::StippleOn was not used, and is removed in
this commit.

Change-Id: Ia367211848f69ffdb093fceeb9baa029435a20d0
parent 22a3aa7b
......@@ -66,6 +66,8 @@ int TestContextGL2PS( int, char *[] )
exp->CompressOff();
exp->SetSortToOff();
exp->DrawBackgroundOn();
exp->SetLineWidthFactor(1.0);
exp->SetPointSizeFactor(1.0);
std::string fileprefix = vtkTestingInteractor::TempDirectory +
std::string("/TestContextGL2PS");
......
......@@ -79,6 +79,8 @@ vtkGL2PSExporter::vtkGL2PSExporter()
this->OcclusionCull = 1;
this->Write3DPropsAsRasterImage = 0;
this->TextAsPath = false;
this->PointSizeFactor = 5.f / 7.f;
this->LineWidthFactor = 5.f / 7.f;
}
vtkGL2PSExporter::~vtkGL2PSExporter()
......@@ -144,6 +146,9 @@ void vtkGL2PSExporter::WriteData()
// Setup the helper class.
vtkGL2PSUtilities::SetRenderWindow(this->RenderWindow);
vtkGL2PSUtilities::SetTextAsPath(this->TextAsPath != 0);
vtkGL2PSUtilities::SetPointSizeFactor(this->PointSizeFactor);
vtkGL2PSUtilities::SetLineWidthFactor(this->LineWidthFactor);
vtkGL2PSUtilities::StartExport();
// Store the "properly" rendered image's pixel data for special actors that
// need to copy bitmaps into the output (e.g. paraview's scalar bar actor)
......@@ -291,6 +296,7 @@ void vtkGL2PSExporter::WriteData()
delete[] fName;
vtkDebugMacro(<<"Finished writing file using GL2PS");
vtkGL2PSUtilities::FinishExport();
}
int vtkGL2PSExporter::GetGL2PSOptions()
......
......@@ -268,6 +268,16 @@ public:
void SetRasterExclusions(vtkPropCollection*);
vtkGetObjectMacro(RasterExclusions, vtkPropCollection);
// Description:
// Set the ratio between the OpenGL PointSize and that used by GL2PS
// to generate PostScript. Defaults to a ratio of 5/7.
vtkSetNGetMacro(PointSizeFactor, float)
// Description:
// Set the ratio between the OpenGL LineWidth and that used by GL2PS
// to generate PostScript. Defaults to a ratio of 5/7.
vtkSetNGetMacro(LineWidthFactor, float)
protected:
vtkGL2PSExporter();
~vtkGL2PSExporter();
......@@ -333,6 +343,8 @@ protected:
int OcclusionCull;
int Write3DPropsAsRasterImage;
bool TextAsPath;
float PointSizeFactor;
float LineWidthFactor;
vtkNew<vtkImageData> PixelData;
......
......@@ -98,7 +98,7 @@ void vtkOpenGL2ContextDevice2D::DrawPointSprites(vtkImageData *sprite,
{
if (points && n > 0)
{
glPointSize(this->Pen->GetWidth());
this->SetPointSize(this->Pen->GetWidth());
if (sprite)
{
if (!this->Storage->SpriteTexture)
......
......@@ -300,7 +300,7 @@ void vtkOpenGLContextDevice2D::DrawPointSprites(vtkImageData *sprite,
{
if (points && n > 0)
{
glPointSize(this->Pen->GetWidth());
this->SetPointSize(this->Pen->GetWidth());
if (sprite)
{
if (!this->Storage->SpriteTexture)
......@@ -588,7 +588,7 @@ void vtkOpenGLContextDevice2D::DrawEllipticArc(float x, float y, float rX,
}
this->SetLineType(this->Pen->GetLineType());
glLineWidth(this->Pen->GetWidth());
this->SetLineWidth(this->Pen->GetWidth());
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, p);
glColor4ubv(this->Brush->GetColor());
......
......@@ -2,6 +2,7 @@ vtk_module(vtkRenderingGL2PS
TCL_NAME vtkRenderingGLtoPS
DEPENDS
vtkRenderingContext2D
vtkRenderingOpenGL
vtkgl2ps
TEST_DEPENDS
vtkTestingRendering
......
......@@ -20,6 +20,7 @@
#include "vtkMathTextUtilities.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLGL2PSHelper.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkPath.h"
#include "vtkPen.h"
......@@ -35,7 +36,6 @@ vtkStandardNewMacro(vtkGL2PSContextDevice2D)
//-----------------------------------------------------------------------------
vtkGL2PSContextDevice2D::vtkGL2PSContextDevice2D()
{
this->StippleOn = false;
}
//-----------------------------------------------------------------------------
......@@ -268,13 +268,15 @@ void vtkGL2PSContextDevice2D::ApplyPen(vtkPen *pen)
//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::SetPointSize(float size)
{
gl2psPointSize(size);
glPointSize(size);
vtkOpenGLGL2PSHelper::SetPointSize(size);
}
//-----------------------------------------------------------------------------
void vtkGL2PSContextDevice2D::SetLineWidth(float width)
{
gl2psLineWidth(width);
glLineWidth(width);
vtkOpenGLGL2PSHelper::SetLineWidth(width);
}
//-----------------------------------------------------------------------------
......@@ -283,13 +285,13 @@ void vtkGL2PSContextDevice2D::SetLineType(int type)
// Must call gl2psEnable(GL_LINE_STIPPLE) after glLineStipple. Let the
// superclass handle setting the stipple type:
this->Superclass::SetLineType(type);
if (type == vtkPen::SOLID_LINE && this->StippleOn)
if (type == vtkPen::SOLID_LINE)
{
gl2psDisable(GL2PS_LINE_STIPPLE);
vtkOpenGLGL2PSHelper::DisableStipple();
}
else if (!this->StippleOn)
else
{
gl2psEnable(GL2PS_LINE_STIPPLE);
vtkOpenGLGL2PSHelper::EnableStipple();
}
}
......@@ -664,6 +666,4 @@ void vtkGL2PSContextDevice2D::TransformPath(vtkPath *path)
void vtkGL2PSContextDevice2D::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "StippleOn: " << this->StippleOn << endl;
}
......@@ -144,7 +144,6 @@ public:
virtual void SetLineType(int type);
protected:
bool StippleOn;
vtkGL2PSContextDevice2D();
virtual ~vtkGL2PSContextDevice2D();
......
......@@ -15,13 +15,13 @@
#include "vtkGL2PSUtilities.h"
#include "vtkImageData.h"
#include "vtkIntArray.h"
#include "vtkFloatArray.h"
#include "vtkMath.h"
#include "vtkMatrix4x4.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLGL2PSHelper.h"
#include "vtkPath.h"
#include "vtkRenderWindow.h"
#include "vtkTextProperty.h"
......@@ -34,8 +34,12 @@
#include <string>
vtkStandardNewMacro(vtkGL2PSUtilities)
bool vtkGL2PSUtilities::TextAsPath = false;
// Initialize static members
vtkRenderWindow *vtkGL2PSUtilities::RenderWindow = NULL;
bool vtkGL2PSUtilities::TextAsPath = false;
float vtkGL2PSUtilities::PointSizeFactor = 5.f / 7.f;
float vtkGL2PSUtilities::LineWidthFactor = 5.f / 7.f;
void vtkGL2PSUtilities::DrawString(const char *str,
vtkTextProperty *tprop, double pos[])
......@@ -267,6 +271,34 @@ void vtkGL2PSUtilities::DrawPath(vtkPath *path, double rasterPos[3],
}
}
void vtkGL2PSUtilities::StartExport()
{
// This is nasty -- the tokens are used in the feedback buffer to tell GL2PS
// about stippling or when the linewidth/pointsize changes. These are the
// values defined in gl2ps.c as of v1.3.8. If these values change (doubtful)
// we'll need to detect the gl2ps version and set the values per version.
//
// We set these in the helper class to fake the GL2PS functions that inject
// the tokens into the feedback buffer to avoid making vtkRenderingOpenGL
// depend on gl2ps.
vtkOpenGLGL2PSHelper::StippleBeginToken = 5.f; // GL2PS_BEGIN_STIPPLE_TOKEN
vtkOpenGLGL2PSHelper::StippleEndToken = 6.f; // GL2PS_END_STIPPLE_TOKEN
vtkOpenGLGL2PSHelper::PointSizeToken = 7.f; // GL2PS_POINT_SIZE_TOKEN
vtkOpenGLGL2PSHelper::LineWidthToken = 8.f; // GL2PS_LINE_WIDTH_TOKEN
// These are used to scale the points and lines:
vtkOpenGLGL2PSHelper::PointSizeFactor = vtkGL2PSUtilities::PointSizeFactor;
vtkOpenGLGL2PSHelper::LineWidthFactor = vtkGL2PSUtilities::LineWidthFactor;
// Enable the code paths that interact with the feedback buffer:
vtkOpenGLGL2PSHelper::InGL2PSRender = true;
}
void vtkGL2PSUtilities::FinishExport()
{
vtkOpenGLGL2PSHelper::InGL2PSRender = false;
}
void vtkGL2PSUtilities::DrawPathPS(vtkPath *path, double rasterPos[3],
double windowPos[2], unsigned char rgba[4],
double scale[2], double rotateAngle,
......
......@@ -55,11 +55,7 @@ public:
static int TextPropertyToGL2PSAlignment(vtkTextProperty *tprop);
// Description:
// Set/Get the current RenderWindow that is being exported
static void SetRenderWindow(vtkRenderWindow *renWin)
{
vtkGL2PSUtilities::RenderWindow = renWin;
}
// Get the current RenderWindow that is being exported
static vtkRenderWindow *GetRenderWindow()
{
return vtkGL2PSUtilities::RenderWindow;
......@@ -82,17 +78,43 @@ public:
unsigned char rgba[4], double scale[2] = NULL,
double rotateAngle = 0.0, float strokeWidth = -1);
// Set/Get whether all text will be exported as paths.
// Description:
// Get whether all text will be exported as paths.
static bool GetTextAsPath()
{
return vtkGL2PSUtilities::TextAsPath;
}
// Description:
// Get a scaling factor for the point size or line width used by GL2PS.
// Default value: 5/7.
static float GetPointSizeFactor()
{ return vtkGL2PSUtilities::PointSizeFactor; }
static float GetLineWidthFactor()
{ return vtkGL2PSUtilities::LineWidthFactor; }
protected:
friend class vtkGL2PSExporter;
static void StartExport();
static void FinishExport();
static void SetPointSizeFactor(float f)
{ vtkGL2PSUtilities::PointSizeFactor = f; }
static void SetLineWidthFactor(float f)
{ vtkGL2PSUtilities::LineWidthFactor = f; }
static void SetTextAsPath(bool b)
{
vtkGL2PSUtilities::TextAsPath = b;
}
static bool GetTextAsPath()
static void SetRenderWindow(vtkRenderWindow *renWin)
{
return vtkGL2PSUtilities::TextAsPath;
vtkGL2PSUtilities::RenderWindow = renWin;
}
protected:
static void DrawPathPS(vtkPath *path, double rasterPos[3],
double windowPos[2], unsigned char rgba[4],
double scale[2] = NULL, double rotateAngle = 0.0,
......@@ -115,6 +137,8 @@ private:
static vtkRenderWindow *RenderWindow;
static bool TextAsPath;
static float PointSizeFactor;
static float LineWidthFactor;
// Description:
// Project the point from world coordinates into device coordinates.
......
......@@ -60,6 +60,7 @@ set(Module_SRCS
vtkOpenGLCoincidentTopologyResolutionPainter.cxx
vtkOpenGLDisplayListPainter.cxx
vtkOpenGLExtensionManager.cxx
vtkOpenGLGL2PSHelper.cxx
vtkOpenGLGlyph3DMapper.cxx
vtkOpenGLHardwareSupport.cxx
vtkOpenGLImageMapper.cxx
......@@ -122,6 +123,7 @@ set_source_files_properties(
vtkLightingHelper
vtkRenderState
vtkOpenGLState
vtkOpenGLGL2PSHelper
vtkShader2
vtkShader2Collection
vtkShaderProgram2
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGLGL2PSHelper.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 "vtkOpenGLGL2PSHelper.h"
bool vtkOpenGLGL2PSHelper::InGL2PSRender = false;
GLfloat vtkOpenGLGL2PSHelper::PointSizeFactor = 0.f;
GLfloat vtkOpenGLGL2PSHelper::LineWidthFactor = 0.f;
GLfloat vtkOpenGLGL2PSHelper::PointSizeToken = 0;
GLfloat vtkOpenGLGL2PSHelper::LineWidthToken = 0;
GLfloat vtkOpenGLGL2PSHelper::StippleBeginToken = 0;
GLfloat vtkOpenGLGL2PSHelper::StippleEndToken = 0;
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGLGL2PSHelper.h
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.
=========================================================================*/
// .NAME vtkOpenGLGL2PSHelper - Helper functionality for GL2PS exporting.
//
// .SECTION Description
// vtkOpenGLGL2PSHelper provides a number of static variables and methods that
// are used during GL2PS exporting. The rational behind this class is that GL
// does not include all of the information that GL2PS needs into its feedback
// buffer, and in certain situations GL2PS function calls need to be made
// alongside their GL equivalents, notably glLineWidth and glPointSize.
//
// The static variables in this class are set by vtkGL2PSUtilities at the
// beginning of a GL2PS export render. This class fakes GL2PS calls like
// gl2psLineWidth in order to keep GL2PS from being a module dependency for
// vtkRenderingOpenGL.
#ifndef __vtkOpenGLGL2PSHelper_h
#define __vtkOpenGLGL2PSHelper_h
#include "vtkRenderingOpenGLModule.h" // For export macro
#include "vtkOpenGL.h" // for GL defines.
class VTKRENDERINGOPENGL_EXPORT vtkOpenGLGL2PSHelper
{
public:
// Description:
// Call alongside glLineWidth(lineWidth) to inform GL2PS of the change.
static void SetLineWidth(float lineWidth)
{
if (vtkOpenGLGL2PSHelper::InGL2PSRender)
{
glPassThrough(vtkOpenGLGL2PSHelper::LineWidthToken);
glPassThrough(vtkOpenGLGL2PSHelper::LineWidthFactor * lineWidth);
}
}
// Description:
// Call alongside glPointSize(pointSize) to inform GL2PS of the change.
static void SetPointSize(float pointSize)
{
if (vtkOpenGLGL2PSHelper::InGL2PSRender)
{
glPassThrough(vtkOpenGLGL2PSHelper::PointSizeToken);
glPassThrough(vtkOpenGLGL2PSHelper::PointSizeFactor * pointSize);
}
}
// Description:
// Call alongside glEnable(GL_LINE_STIPPLE) to inform GL2PS of the change.
// This must be called *after* calling glLineStipple(factor, pattern).
static void EnableStipple()
{
if (vtkOpenGLGL2PSHelper::InGL2PSRender)
{
GLint tmp;
glPassThrough(vtkOpenGLGL2PSHelper::StippleBeginToken);
glGetIntegerv(GL_LINE_STIPPLE_PATTERN, &tmp);
glPassThrough(static_cast<GLfloat>(tmp));
glGetIntegerv(GL_LINE_STIPPLE_REPEAT, &tmp);
glPassThrough(static_cast<GLfloat>(tmp));
}
}
// Description:
// Call alongside glDisable(GL_LINE_STIPPLE) to inform GL2PS of the change.
static void DisableStipple()
{
if (vtkOpenGLGL2PSHelper::InGL2PSRender)
{
glPassThrough(vtkOpenGLGL2PSHelper::StippleEndToken);
}
}
protected:
friend class vtkGL2PSUtilities;
static bool InGL2PSRender;
static GLfloat PointSizeFactor;
static GLfloat LineWidthFactor;
static GLfloat PointSizeToken;
static GLfloat LineWidthToken;
static GLfloat StippleBeginToken;
static GLfloat StippleEndToken;
private:
// static-only class -- no need to construct/destroy.
vtkOpenGLGL2PSHelper();
~vtkOpenGLGL2PSHelper();
vtkOpenGLGL2PSHelper(const vtkOpenGLGL2PSHelper &); // Not implemented.
void operator=(const vtkOpenGLGL2PSHelper &); // Not implemented.
};
#endif //__vtkOpenGLGL2PSHelper_h
// VTK-HeaderTest-Exclude: vtkOpenGLGL2PSHelper.h
......@@ -26,6 +26,7 @@
#include "vtkDataArray.h"
#include "vtkDataSetAttributes.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLGL2PSHelper.h"
#include "vtkOpenGLExtensionManager.h"
#include "vtkRenderer.h"
#include "vtkgl.h"
......@@ -1059,6 +1060,7 @@ void vtkOpenGLPainterDeviceAdapter::MakeVertexEmphasis(bool mode)
glGetFloatv(GL_POINT_SIZE, &s);
this->PointSize = s;
glPointSize(4.0); //make verts large enough to be sure to overlap cell
vtkOpenGLGL2PSHelper::SetPointSize(4.0);
float nf[2]; //put verts just in front of associated cells
glGetFloatv(GL_DEPTH_RANGE, nf);
......@@ -1070,6 +1072,7 @@ void vtkOpenGLPainterDeviceAdapter::MakeVertexEmphasis(bool mode)
else
{
glPointSize(static_cast<GLfloat>(this->PointSize));
vtkOpenGLGL2PSHelper::SetPointSize(static_cast<GLfloat>(this->PointSize));
glDepthRange(this->RangeNear, this->RangeFar);
glDepthMask(GL_TRUE);
}
......
......@@ -17,6 +17,7 @@
#include "vtkActor2D.h"
#include "vtkCellArray.h"
#include "vtkMath.h"
#include "vtkOpenGLGL2PSHelper.h"
#include "vtkObjectFactory.h"
#include "vtkPlane.h"
#include "vtkPlaneCollection.h"
......@@ -260,6 +261,7 @@ void vtkOpenGLPolyDataMapper2D::RenderOverlay(vtkViewport* viewport,
// Set the PointSize
glPointSize(actor->GetProperty()->GetPointSize());
vtkOpenGLGL2PSHelper::SetPointSize(actor->GetProperty()->GetPointSize());
double *dptr;
aPrim = input->GetVerts();
......@@ -294,6 +296,7 @@ void vtkOpenGLPolyDataMapper2D::RenderOverlay(vtkViewport* viewport,
// Set the LineWidth
glLineWidth(actor->GetProperty()->GetLineWidth());
vtkOpenGLGL2PSHelper::SetLineWidth(actor->GetProperty()->GetLineWidth());
// Set the LineStipple
if (actor->GetProperty()->GetLineStipplePattern() != 0xFFFF)
......@@ -301,10 +304,12 @@ void vtkOpenGLPolyDataMapper2D::RenderOverlay(vtkViewport* viewport,
glEnable(GL_LINE_STIPPLE);
glLineStipple(actor->GetProperty()->GetLineStippleRepeatFactor(),
actor->GetProperty()->GetLineStipplePattern());
vtkOpenGLGL2PSHelper::EnableStipple();
}
else
{
glDisable(GL_LINE_STIPPLE);
vtkOpenGLGL2PSHelper::DisableStipple();
}
aPrim = input->GetLines();
......
......@@ -19,6 +19,7 @@
#include "vtkObjectFactory.h"
#include "vtkOpenGLExtensionManager.h"
#include "vtkOpenGLGL2PSHelper.h"
#include "vtkOpenGLTexture.h"
#include "vtkTexture.h"
......@@ -484,9 +485,11 @@ void vtkOpenGLProperty::Render(vtkActor *anActor,
// Set the PointSize
glPointSize(this->PointSize);
vtkOpenGLGL2PSHelper::SetPointSize(this->PointSize);
// Set the LineWidth
glLineWidth(this->LineWidth);
vtkOpenGLGL2PSHelper::SetLineWidth(this->LineWidth);
// Set the LineStipple
if (this->LineStipplePattern != 0xFFFF)
......@@ -494,6 +497,7 @@ void vtkOpenGLProperty::Render(vtkActor *anActor,
glEnable(GL_LINE_STIPPLE);
glLineStipple(this->LineStippleRepeatFactor,
static_cast<GLushort>(this->LineStipplePattern));
vtkOpenGLGL2PSHelper::EnableStipple(); // must be called after glLineStipple
}
else
{
......@@ -502,6 +506,7 @@ void vtkOpenGLProperty::Render(vtkActor *anActor,
glLineStipple(this->LineStippleRepeatFactor,
static_cast<GLushort>(this->LineStipplePattern));
glDisable(GL_LINE_STIPPLE);
vtkOpenGLGL2PSHelper::DisableStipple();
}
if (this->Lighting) // fixed-pipeline
......
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