Commit 503d68d2 authored by Burlen Loring's avatar Burlen Loring
Browse files

refactor vtkHardwareSelector device state management

This patch refactors device dependent OpenGL state
management code used only by the vtkHardwareSelector
out of vtkOpenGLPainterDeviceAdaptor and into the
new vtkOpenGLHardwareSelector class and decorates the
old vtkOpenGLPainterDeviceAdaptor API with VTK_LEGACY.
In vtkOpenGLHardwareSelector added a check for and
load of the GL_ARB_multisample extension before using
it. This fixes failing tests in ParaView with MS GDI
OpenGL 1.1 driver which doesn't support multisampling.

Change-Id: I450802a58d346be801fe0bc74841619cccb17075
parent c9c23706
......@@ -155,6 +155,7 @@ set_source_files_properties(
vtkAbstractPicker
vtkAbstractPropPicker
vtkCuller
vtkHardwareSelector
vtkImageMapper3D
vtkInteractorObserver
vtkMapper
......
......@@ -73,11 +73,10 @@ public:
// Ids for props that were hit.
std::set<int> HitProps;
std::map<int, vtkSmartPointer<vtkProp> > Props;
// state that's managed through the renderer
double OriginalBackground[3];
bool OriginalGradient;
int OriginalMultisample;
int OriginalLighting;
int OriginalBlending;
typedef std::map<PixelInformation, std::set<vtkIdType>,
PixelInformationComparator> MapOfAttributeIds;
......@@ -177,8 +176,12 @@ public:
};
vtkStandardNewMacro(vtkHardwareSelector);
//----------------------------------------------------------------------------
vtkAbstractObjectFactoryNewMacro(vtkHardwareSelector);
//----------------------------------------------------------------------------
vtkCxxSetObjectMacro(vtkHardwareSelector, Renderer, vtkRenderer);
//----------------------------------------------------------------------------
vtkHardwareSelector::vtkHardwareSelector()
{
......@@ -365,16 +368,11 @@ void vtkHardwareSelector::BeginRenderProp()
{
return;
}
// Ensure that blending/lighting/multisampling is off.
vtkPainterDeviceAdapter* device = this->Renderer->GetRenderWindow()->
GetPainterDeviceAdapter();
this->Internals->OriginalMultisample = device->QueryMultisampling();
this->Internals->OriginalLighting = device->QueryLighting();
this->Internals->OriginalBlending = device->QueryBlending();
device->MakeMultisampling(0);
device->MakeLighting(0);
device->MakeBlending(0);
// device specific prep
vtkRenderWindow *renWin = this->Renderer->GetRenderWindow();
this->BeginRenderProp(renWin);
//cout << "In BeginRenderProp" << endl;
//glFinish();
if (this->CurrentPass == ACTOR_PASS)
......@@ -390,7 +388,7 @@ void vtkHardwareSelector::BeginRenderProp()
// Since 0 is reserved for nothing selected, we offset propid by 1.
propid = propid + 1;
vtkHardwareSelector::Convert(propid, color);
this->Renderer->GetRenderWindow()->GetPainterDeviceAdapter()->SendAttribute(
renWin->GetPainterDeviceAdapter()->SendAttribute(
vtkDataSetAttributes::SCALARS, 3, VTK_FLOAT, color);
}
else if (this->CurrentPass == PROCESS_PASS)
......@@ -398,13 +396,13 @@ void vtkHardwareSelector::BeginRenderProp()
float color[3];
// Since 0 is reserved for nothing selected, we offset propid by 1.
vtkHardwareSelector::Convert(this->ProcessID + 1, color);
this->Renderer->GetRenderWindow()->GetPainterDeviceAdapter()->SendAttribute(
renWin->GetPainterDeviceAdapter()->SendAttribute(
vtkDataSetAttributes::SCALARS, 3, VTK_FLOAT, color);
}
else
{
float color[3] = {0, 0, 0};
this->Renderer->GetRenderWindow()->GetPainterDeviceAdapter()->SendAttribute(
renWin->GetPainterDeviceAdapter()->SendAttribute(
vtkDataSetAttributes::SCALARS, 3, VTK_FLOAT, color);
}
}
......@@ -415,15 +413,15 @@ void vtkHardwareSelector::EndRenderProp()
if (this->InPropRender)
{
this->InPropRender--;
if (this->InPropRender != 0)
{
return;
}
vtkPainterDeviceAdapter* device = this->Renderer->GetRenderWindow()->
GetPainterDeviceAdapter();
device->MakeMultisampling(this->Internals->OriginalMultisample);
device->MakeLighting(this->Internals->OriginalLighting);
device->MakeBlending(this->Internals->OriginalBlending);
// device specific cleanup
vtkRenderWindow *renWin = this->Renderer->GetRenderWindow();
this->EndRenderProp(renWin);
}
}
......
......@@ -62,6 +62,7 @@
#include "vtkObject.h"
class vtkRenderer;
class vtkRenderWindow;
class vtkSelection;
class vtkProp;
class vtkTextureObject;
......@@ -94,7 +95,7 @@ public:
// Description:
// Get/Set the renderer to perform the selection on.
void SetRenderer(vtkRenderer*);
virtual void SetRenderer(vtkRenderer*);
vtkGetObjectMacro(Renderer, vtkRenderer);
// Description:
......@@ -176,8 +177,8 @@ public:
// Description:
// Called by the mapper (vtkHardwareSelectionPolyDataPainter) before and after
// rendering each prop.
void BeginRenderProp();
void EndRenderProp();
virtual void BeginRenderProp();
virtual void EndRenderProp();
// Description:
// Get/Set the process id. If process id < 0 (default -1), then the
......@@ -233,11 +234,16 @@ protected:
vtkHardwareSelector();
~vtkHardwareSelector();
// Called internally before and after each prop is rendered
// for device specific configuration/preparation etc.
virtual void BeginRenderProp(vtkRenderWindow *) = 0;
virtual void EndRenderProp(vtkRenderWindow *) = 0;
static void Convert(int id, float tcoord[3])
{
tcoord[0] = static_cast<float>((id & 0xff)/255.0);
tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
tcoord[0] = static_cast<float>((id & 0xff)/255.0);
tcoord[1] = static_cast<float>(((id & 0xff00) >> 8)/255.0);
tcoord[2] = static_cast<float>(((id & 0xff0000) >> 16)/255.0);
}
int Convert(unsigned long offset, unsigned char* pb)
......@@ -246,7 +252,6 @@ protected:
{
return 0;
}
offset = offset * 3;
unsigned char rgb[3];
rgb[0] = pb[offset];
......
......@@ -158,29 +158,43 @@ public:
// vtkRenderer.
virtual int Compatible(vtkRenderer *renderer) = 0;
#ifndef VTK_LEGACY_REMOVE
// Description:
// @deprecated code that needs access directly to OpenGL state should
// manage it locally.
// Turns lighting on and off.
virtual void MakeLighting(int mode) = 0;
// Description:
// @deprecated code that needs access directly to OpenGL state should
// manage it locally.
// Returns current lighting setting.
virtual int QueryLighting() = 0;
// Description:
// @deprecated code that needs access directly to OpenGL state should
// manage it locally.
// Turns antialiasing on and off.
virtual void MakeMultisampling(int mode) = 0;
// Description:
// @deprecated code that needs access directly to OpenGL state should
// manage it locally.
// Returns current antialiasing setting.
virtual int QueryMultisampling() = 0;
// Description:
// @deprecated code that needs access directly to OpenGL state should
// manage it locally.
// Turns blending on and off.
virtual void MakeBlending(int mode) = 0;
// Description:
// @deprecated code that needs access directly to OpenGL state should
// manage it locally.
// Returns current blending setting.
virtual int QueryBlending() = 0;
#endif
// Description:
// Turns emphasis of vertices on or off for vertex selection.
......
......@@ -64,6 +64,7 @@ set(Module_SRCS
vtkOpenGLExtensionManager.cxx
vtkOpenGLGL2PSHelper.cxx
vtkOpenGLGlyph3DMapper.cxx
vtkOpenGLHardwareSelector.cxx
vtkOpenGLHardwareSupport.cxx
vtkOpenGLImageMapper.cxx
vtkOpenGLImageSliceMapper.cxx
......@@ -277,6 +278,7 @@ set(opengl_overrides
CompositePainter
DisplayListPainter
Glyph3DMapper
HardwareSelector
ImageSliceMapper
Light
LightingPainter
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGLHardwareSelector.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 "vtkOpenGLHardwareSelector.h"
#include "vtkObjectFactory.h"
#include "vtkRenderWindow.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLExtensionManager.h"
#include "vtkgl.h"
#include "vtkOpenGLError.h"
// Description:
// Internal state and helper methods.
class vtkOpenGLHardwareSelector::vtkInternals
{
public:
vtkOpenGLRenderWindow *Context;
bool MultisampleSupport;
bool OriginalMultisample;
bool OriginalLighting;
bool OriginalBlending;
vtkInternals() :
Context(NULL),
MultisampleSupport(false),
OriginalMultisample(false),
OriginalLighting(false),
OriginalBlending(false)
{}
// Description:
// Set the rendering context and load the required
// extensions.
void SetContext(vtkRenderWindow *context)
{
if (this->Context != context)
{
this->MultisampleSupport = false;
this->Context = vtkOpenGLRenderWindow::SafeDownCast(context);
if (this->Context)
{
vtkOpenGLExtensionManager *manager
= this->Context->GetExtensionManager();
// don't need any of the functions so don't bother
// to load the extension, but do make sure enums are
// defined.
this->MultisampleSupport
= manager->ExtensionSupported("GL_ARB_multisample")==1;
}
}
}
// Description:
// Enable/disable lighting
void EnableLighting(bool mode)
{
if (mode)
{
glEnable(GL_LIGHTING);
}
else
{
glDisable(GL_LIGHTING);
}
}
// Description:
// Check if lighting is enabled.
bool QueryLighting()
{
if (glIsEnabled(GL_LIGHTING))
{
return true;
}
else
{
return false;
}
}
// Description:
// Enable/disable multisampling.
void EnableMultisampling(bool mode)
{
if (this->MultisampleSupport)
{
if (mode)
{
glEnable(vtkgl::MULTISAMPLE);
}
else
{
glDisable(vtkgl::MULTISAMPLE);
}
}
}
// Description:
// Check if multisample is enabled.
bool QueryMultisampling()
{
if (this->MultisampleSupport && glIsEnabled(vtkgl::MULTISAMPLE))
{
return true;
}
else
{
return false;
}
}
// Description:
// Enable/Disable blending
void EnableBlending(bool mode)
{
if (mode)
{
glEnable(GL_BLEND);
}
else
{
glDisable(GL_BLEND);
}
}
// Description:
// Check if blending is enabled.
bool QueryBlending()
{
if (glIsEnabled(GL_BLEND))
{
return true;
}
else
{
return false;
}
}
};
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkOpenGLHardwareSelector);
//----------------------------------------------------------------------------
vtkOpenGLHardwareSelector::vtkOpenGLHardwareSelector()
{
#ifdef vtkOpenGLHardwareSelectorDEBUG
cerr << "=====vtkOpenGLHardwareSelector::vtkOpenGLHardwareSelector" << endl;
#endif
this->Internals = new vtkInternals;
}
//----------------------------------------------------------------------------
vtkOpenGLHardwareSelector::~vtkOpenGLHardwareSelector()
{
#ifdef vtkOpenGLHardwareSelectorDEBUG
cerr << "=====vtkOpenGLHardwareSelector::~vtkOpenGLHardwareSelector" << endl;
#endif
delete this->Internals;
}
//----------------------------------------------------------------------------
void vtkOpenGLHardwareSelector::BeginRenderProp(vtkRenderWindow *context)
{
#ifdef vtkOpenGLHardwareSelectorDEBUG
cerr << "=====vtkOpenGLHardwareSelector::BeginRenderProp" << endl;
#endif
this->Internals->SetContext(context);
// Disable multisample, lighting, and blending.
this->Internals->OriginalMultisample = this->Internals->QueryMultisampling();
this->Internals->EnableMultisampling(false);
this->Internals->OriginalLighting = this->Internals->QueryLighting();
this->Internals->EnableLighting(false);
this->Internals->OriginalBlending = this->Internals->QueryBlending();
this->Internals->EnableBlending(false);
}
//----------------------------------------------------------------------------
void vtkOpenGLHardwareSelector::EndRenderProp(vtkRenderWindow *)
{
#ifdef vtkOpenGLHardwareSelectorDEBUG
cerr << "=====vtkOpenGLHardwareSelector::EndRenderProp" << endl;
#endif
// Restore multisample, lighting, and blending.
this->Internals->EnableMultisampling(this->Internals->OriginalMultisample);
this->Internals->EnableLighting(this->Internals->OriginalLighting);
this->Internals->EnableBlending(this->Internals->OriginalBlending);
}
//----------------------------------------------------------------------------
void vtkOpenGLHardwareSelector::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os
<< indent << "MultisampleSupport: "
<< this->Internals->MultisampleSupport
<< endl;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenGLHardwareSelector.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 vtkOpenGLHardwareSelector - implements the device specific code of
// vtkOpenGLHardwareSelector.
//
// .SECTION Description
// Implements the device specific code of vtkOpenGLHardwareSelector.
//
// .SECTION See Also
// vtkHardwareSelector
#ifndef __vtkOpenGLHardwareSelector_h
#define __vtkOpenGLHardwareSelector_h
#include "vtkRenderingOpenGLModule.h" // For export macro
#include "vtkHardwareSelector.h"
class VTKRENDERINGOPENGL_EXPORT vtkOpenGLHardwareSelector : public vtkHardwareSelector
{
public:
static vtkOpenGLHardwareSelector* New();
vtkTypeMacro(vtkOpenGLHardwareSelector, vtkHardwareSelector);
void PrintSelf(ostream& os, vtkIndent indent);
protected:
vtkOpenGLHardwareSelector();
virtual ~vtkOpenGLHardwareSelector();
// Called internally before and after each prop is rendered
// for device specific configuration/preparation etc.
virtual void BeginRenderProp(vtkRenderWindow *);
virtual void EndRenderProp(vtkRenderWindow *);
// for internal state
class vtkInternals;
vtkInternals* Internals;
private:
vtkOpenGLHardwareSelector(const vtkOpenGLHardwareSelector&); // Not implemented.
void operator=(const vtkOpenGLHardwareSelector&); // Not implemented.
};
#endif
......@@ -27,7 +27,10 @@
#include "vtkDataSetAttributes.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLGL2PSHelper.h"
#include "vtkOpenGLRenderWindow.h"
#ifndef VTK_LEGACY_REMOVE
#include "vtkOpenGLExtensionManager.h"
#endif
#include "vtkRenderer.h"
#include "vtkgl.h"
......@@ -845,15 +848,29 @@ void vtkOpenGLPainterDeviceAdapter::DrawElements(int mode, vtkIdType count,
}
//-----------------------------------------------------------------------------
int vtkOpenGLPainterDeviceAdapter::Compatible(vtkRenderer *renderer)
{
return renderer->IsA("vtkOpenGLRenderer");
vtkOpenGLRenderWindow *context
= vtkOpenGLRenderWindow::SafeDownCast(renderer->GetRenderWindow());
if (!context)
{
return false;
}
#ifndef VTK_LEGACY_REMOVE
vtkOpenGLExtensionManager *manager = context->GetExtensionManager();
if (!manager->ExtensionSupported("GL_ARB_multisample"))
{
return false;
}
#endif
return true;
}
#ifndef VTK_LEGACY_REMOVE
//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::MakeLighting(int mode)
{
VTK_LEGACY_BODY(vtkOpenGLPainterDeviceAdapter::MakeLighting, "VTK 6.1");
if (mode)
{
glEnable(GL_LIGHTING);
......@@ -867,6 +884,7 @@ void vtkOpenGLPainterDeviceAdapter::MakeLighting(int mode)
//-----------------------------------------------------------------------------
int vtkOpenGLPainterDeviceAdapter::QueryLighting()
{
VTK_LEGACY_BODY(vtkOpenGLPainterDeviceAdapter::QueryLighting, "VTK 6.1");
if (glIsEnabled(GL_LIGHTING))
{
return 1;
......@@ -880,6 +898,7 @@ int vtkOpenGLPainterDeviceAdapter::QueryLighting()
//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::MakeMultisampling(int mode)
{
VTK_LEGACY_BODY(vtkOpenGLPainterDeviceAdapter::MakeMultisampling, "VTK 6.1");
if (mode)
{
glEnable(vtkgl::MULTISAMPLE);
......@@ -893,6 +912,7 @@ void vtkOpenGLPainterDeviceAdapter::MakeMultisampling(int mode)
//-----------------------------------------------------------------------------
int vtkOpenGLPainterDeviceAdapter::QueryMultisampling()
{
VTK_LEGACY_BODY(vtkOpenGLPainterDeviceAdapter::QueryMultisampling, "VTK 6.1");
if (glIsEnabled(vtkgl::MULTISAMPLE))
{
return 1;
......@@ -906,6 +926,7 @@ int vtkOpenGLPainterDeviceAdapter::QueryMultisampling()
//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::MakeBlending(int mode)
{
VTK_LEGACY_BODY(vtkOpenGLPainterDeviceAdapter::MakeBlending, "VTK 6.1");
if (mode)
{
glEnable(GL_BLEND);
......@@ -919,6 +940,7 @@ void vtkOpenGLPainterDeviceAdapter::MakeBlending(int mode)
//-----------------------------------------------------------------------------
int vtkOpenGLPainterDeviceAdapter::QueryBlending()
{
VTK_LEGACY_BODY(vtkOpenGLPainterDeviceAdapter::QueryBlending, "VTK 6.1");
if (glIsEnabled(GL_BLEND))
{
return 1;
......@@ -928,6 +950,7 @@ int vtkOpenGLPainterDeviceAdapter::QueryBlending()
return 0;
}
}
#endif
//-----------------------------------------------------------------------------
void vtkOpenGLPainterDeviceAdapter::MakeVertexEmphasis(bool mode)
......
......@@ -105,28 +105,40 @@ public:
virtual int Compatible(vtkRenderer *renderer);
// Description:
// @deprecated code that needs access directly to OpenGL state should
// manage it locally.
// Turns lighting on and off.
virtual void MakeLighting(int mode);
VTK_LEGACY(virtual void MakeLighting(int mode));
// Description:
// @deprecated code that needs access directly to OpenGL state should
// manage it locally.
// Returns current lighting setting.
virtual int QueryLighting();
VTK_LEGACY(virtual int QueryLighting());
// Description:
// @deprecated code that needs access directly to OpenGL state should
// manage it locally.
// Turns antialiasing on and off.
virtual void MakeMultisampling(int mode);
VTK_LEGACY(virtual void MakeMultisampling(int mode));
// Description:
// @deprecated code that needs access directly to OpenGL state should
// manage it locally.
// Returns current antialiasing setting.
virtual int QueryMultisampling();
VTK_LEGACY(virtual int QueryMultisampling());
// Description:
// @deprecated code that needs access directly to OpenGL state should
// manage it locally.
// Turns blending on and off.
virtual void MakeBlending(int mode);
VTK_LEGACY(virtual void MakeBlending(int mode));