Commit a9fa6d3b authored by Ken Martin's avatar Ken Martin

add opengl resource management to polydatamapper2d

In some cases it could attempt to free opengl resources
when it was not the current context or after the context
was destroyed. Add the new resource management logic
via vtkOpenGLResourceFreeCallback the class to prevent
this.
parent 9f2759cf
......@@ -29,6 +29,7 @@
#include "vtkOpenGLPolyDataMapper.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLResourceFreeCallback.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkOpenGLTexture.h"
#include "vtkOpenGLVertexArrayObject.h"
......@@ -64,11 +65,20 @@ vtkOpenGLPolyDataMapper2D::vtkOpenGLPolyDataMapper2D()
this->HaveCellScalars = false;
this->PrimitiveIDOffset = 0;
this->LastPickState = 0;
this->ResourceCallback = new vtkOpenGLResourceFreeCallback<vtkOpenGLPolyDataMapper2D>(this,
&vtkOpenGLPolyDataMapper2D::ReleaseGraphicsResources);
}
//-----------------------------------------------------------------------------
vtkOpenGLPolyDataMapper2D::~vtkOpenGLPolyDataMapper2D()
{
if (this->ResourceCallback)
{
this->ResourceCallback->Release();
delete this->ResourceCallback;
this->ResourceCallback = NULL;
}
if (this->TransformedPoints)
{
this->TransformedPoints->UnRegister(this);
......@@ -96,6 +106,12 @@ vtkOpenGLPolyDataMapper2D::~vtkOpenGLPolyDataMapper2D()
//-----------------------------------------------------------------------------
void vtkOpenGLPolyDataMapper2D::ReleaseGraphicsResources(vtkWindow* win)
{
if (!this->ResourceCallback->IsReleasing())
{
this->ResourceCallback->Release();
return;
}
this->VBO->ReleaseGraphicsResources();
this->Points.ReleaseGraphicsResources(win);
this->Lines.ReleaseGraphicsResources(win);
......@@ -788,6 +804,10 @@ void vtkOpenGLPolyDataMapper2D::RenderOverlay(vtkViewport* viewport,
}
vtkRenderWindow *renWin = vtkRenderWindow::SafeDownCast(viewport->GetVTKWindow());
this->ResourceCallback->RegisterGraphicsResources(
static_cast<vtkOpenGLRenderWindow *>(renWin));
int picking = renWin->GetIsPicking();
if (picking != this->LastPickState)
{
......
......@@ -35,6 +35,7 @@
#include <vector> //for ivars
class vtkActor2D;
class vtkGenericOpenGLResourceFreeCallback;
class vtkMatrix4x4;
class vtkOpenGLBufferObject;
class vtkOpenGLHelper;
......@@ -70,6 +71,8 @@ protected:
vtkOpenGLPolyDataMapper2D();
~vtkOpenGLPolyDataMapper2D();
vtkGenericOpenGLResourceFreeCallback *ResourceCallback;
// the following is all extra stuff to work around the
// fact that gl_PrimitiveID does not work correctly on
// Apple devices with AMD graphics hardware. See apple
......
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