Commit 3a8e4497 authored by Ken Martin's avatar Ken Martin

Try to cleanup the release graphcis resources some

An issue with OS windows lead to this. But it needs to done
and it will not be working in the commit.
parent 804902b1
Pipeline #217 passed with stage
......@@ -163,6 +163,23 @@ vtkRenderer::~vtkRenderer()
}
}
void vtkRenderer::ReleaseGraphicsResources(vtkWindow *renWin)
{
if(this->BackgroundTexture != 0)
{
this->BackgroundTexture->ReleaseGraphicsResources(renWin);
}
vtkProp *aProp;
vtkCollectionSimpleIterator pit;
this->Props->InitTraversal(pit);
for ( aProp = this->Props->GetNextProp(pit);
aProp != NULL;
aProp = this->Props->GetNextProp(pit) )
{
aProp->ReleaseGraphicsResources(renWin);
}
}
// Concrete render method.
void vtkRenderer::Render(void)
{
......
......@@ -505,7 +505,7 @@ public:
vtkBooleanMacro(TexturedBackground,bool);
// method to release graphics resources in any derived renderers.
virtual void ReleaseGraphicsResources(vtkWindow *) { }
virtual void ReleaseGraphicsResources(vtkWindow *);
// Description:
// Turn on/off rendering of shadows if supported
......
......@@ -277,20 +277,8 @@ void vtkCocoaRenderWindow::DestroyWindow()
if (this->OwnContext && this->GetContextId())
{
this->MakeCurrent();
// tell each of the renderers that this render window/graphics context
// is being removed (the RendererCollection is removed by vtkRenderWindow's
// destructor)
vtkCollectionSimpleIterator rsit;
vtkRenderer *ren;
for ( this->Renderers->InitTraversal(rsit);
(ren = this->Renderers->GetNextRenderer(rsit));)
{
ren->SetRenderWindow(NULL);
ren->SetRenderWindow(this);
}
this->ReleaseGraphicsResources();
}
this->ReleaseGraphicsResources(this);
}
this->SetContextId(NULL);
this->SetPixelFormat(NULL);
......
......@@ -368,7 +368,7 @@ void vtkEGLRenderWindow::ResizeWindow(int width, int height)
void vtkEGLRenderWindow::DestroyWindow()
{
vtkInternals* impl = this->Internals;
this->ReleaseGraphicsResources();
this->ReleaseGraphicsResources(this);
if (this->OwnWindow && this->Mapped && impl->Display != EGL_NO_DISPLAY)
{
// make sure all other code knows we're not mapped anymore
......
......@@ -83,15 +83,7 @@ void vtkGenericOpenGLRenderWindow::Finalize()
// tell each of the renderers that this render window/graphics context
// is being removed (the RendererCollection is removed by vtkRenderWindow's
// destructor)
vtkRenderer* ren;
this->Renderers->InitTraversal();
for ( ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject());
ren != NULL;
ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject()) )
{
ren->SetRenderWindow(NULL);
ren->SetRenderWindow(this);
}
this->ReleaseGraphicsResources(this);
}
void vtkGenericOpenGLRenderWindow::Frame()
......
......@@ -92,19 +92,8 @@ void vtkIOSRenderWindow::DestroyWindow()
if (this->OwnContext && this->GetContextId())
{
this->MakeCurrent();
// tell each of the renderers that this render window/graphics context
// is being removed (the RendererCollection is removed by vtkRenderWindow's
// destructor)
vtkCollectionSimpleIterator rsit;
vtkRenderer *ren;
for ( this->Renderers->InitTraversal(rsit);
(ren = this->Renderers->GetNextRenderer(rsit));)
{
ren->SetRenderWindow(NULL);
ren->SetRenderWindow(this);
}
}
this->ReleaseGraphicsResources(this);
}
this->SetContextId(NULL);
this->SetPixelFormat(NULL);
......
......@@ -153,20 +153,7 @@ void vtkOSOpenGLRenderWindow::CreateAWindow()
void vtkOSOpenGLRenderWindow::DestroyWindow()
{
this->MakeCurrent();
// tell each of the renderers that this render window/graphics context
// is being removed (the RendererCollection is removed by vtkRenderWindow's
// destructor)
vtkRenderer* ren;
this->Renderers->InitTraversal();
for ( ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject());
ren != NULL;
ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject()) )
{
ren->SetRenderWindow(NULL);
ren->SetRenderWindow(this);
}
this->ReleaseGraphicsResources(this);
delete[] this->Capabilities;
this->Capabilities = 0;
......@@ -224,17 +211,7 @@ void vtkOSOpenGLRenderWindow::DestroyOffScreenWindow()
// this call invokes Renderer's ReleaseGraphicsResources
// method which only invokes ReleaseGraphicsResources on
// rendering passes.
this->ReleaseGraphicsResources();
vtkRenderer *ren;
vtkCollectionSimpleIterator rit;
this->Renderers->InitTraversal(rit);
while ( (ren = this->Renderers->GetNextRenderer(rit)) )
{
ren->SetRenderWindow(NULL);
ren->SetRenderWindow(this);
}
this->ReleaseGraphicsResources(this);
if (this->Internal->OffScreenContextId)
{
......
......@@ -141,7 +141,7 @@ vtkOpenGLRenderWindow::~vtkOpenGLRenderWindow()
}
// ----------------------------------------------------------------------------
void vtkOpenGLRenderWindow::ReleaseGraphicsResources()
void vtkOpenGLRenderWindow::ReleaseGraphicsResources(vtkRenderWindow *renWin)
{
vtkCollectionSimpleIterator rsit;
this->Renderers->InitTraversal(rsit);
......@@ -150,16 +150,16 @@ void vtkOpenGLRenderWindow::ReleaseGraphicsResources()
{
if (aren->GetRenderWindow() == this)
{
aren->ReleaseGraphicsResources(this);
aren->ReleaseGraphicsResources(renWin);
}
}
if(this->DrawPixelsTextureObject != 0)
{
this->DrawPixelsTextureObject->ReleaseGraphicsResources(this);
this->DrawPixelsTextureObject->ReleaseGraphicsResources(renWin);
}
this->ShaderCache->ReleaseGraphicsResources(this);
this->ShaderCache->ReleaseGraphicsResources(renWin);
if (this->TextureResourceIds.size())
{
......
......@@ -298,7 +298,8 @@ protected:
// Description:
// Free up any graphics resources associated with this window
virtual void ReleaseGraphicsResources();
// a value of NULL means the context may already be destroyed
virtual void ReleaseGraphicsResources(vtkRenderWindow *);
// Description:
// Set the texture unit manager.
......
......@@ -516,6 +516,7 @@ void vtkOpenGLRenderer::ReleaseGraphicsResources(vtkWindow *w)
{
this->ShadowMapPass->ReleaseGraphicsResources(w);
}
this->Superclass::ReleaseGraphicsResources(w);
}
void vtkOpenGLRenderer::UpdatePickId()
......
......@@ -115,14 +115,7 @@ void vtkWin32OpenGLRenderWindow::CleanUpRenderers()
// tell each of the renderers that this render window/graphics context
// is being removed (the RendererCollection is removed by vtkRenderWindow's
// destructor)
vtkRenderer *ren;
vtkCollectionSimpleIterator rsit;
for (this->Renderers->InitTraversal(rsit);
(ren = this->Renderers->GetNextRenderer(rsit));)
{
ren->SetRenderWindow(NULL);
}
this->ReleaseGraphicsResources();
this->ReleaseGraphicsResources(this);
}
LRESULT APIENTRY vtkWin32OpenGLRenderWindow::WndProc(HWND hWnd, UINT message,
......@@ -595,9 +588,7 @@ void vtkWin32OpenGLRenderWindow::SetupPixelFormatPaletteAndContext(
// features like multisamples.
PIXELFORMATDESCRIPTOR pfd;
int pixelFormat = 0;
wglChoosePixelFormatARBType wglChoosePixelFormatARB =
reinterpret_cast<wglChoosePixelFormatARBType>(wglGetProcAddress("wglChoosePixelFormatARB"));
if ((dwFlags & PFD_DRAW_TO_WINDOW) && wglChoosePixelFormatARB)
if (wglChoosePixelFormatARB)
{
int attrib[] = {
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
......@@ -668,6 +659,10 @@ void vtkWin32OpenGLRenderWindow::SetupPixelFormatPaletteAndContext(
}
}
}
else
{
vtkErrorMacro("failed to get wglChoosePixelFormatARB");
}
// see if we can get a 3.2 context
if (pixelFormat)
......@@ -716,7 +711,7 @@ void vtkWin32OpenGLRenderWindow::SetupPixelFormatPaletteAndContext(
// Otherwise fail as the OpenGL does not support even 2.1
if (!pixelFormat)
{
vtkErrorMacro("wglChoosePixelFormatARB not defined. OpenGL not supported.");
vtkErrorMacro("failed to get valid pixel format.");
}
return;
......@@ -984,7 +979,7 @@ void vtkWin32OpenGLRenderWindow::CreateAWindow()
this->MakeCurrent();
// wipe out any existing display lists
this->ReleaseGraphicsResources();
this->ReleaseGraphicsResources(this);
this->OpenGLInit();
this->Mapped = 1;
this->WindowIdReferenceCount = 1;
......@@ -1049,12 +1044,12 @@ void vtkWin32OpenGLRenderWindow::Finalize (void)
void vtkWin32OpenGLRenderWindow::DestroyWindow()
{
this->Clean();
if(this->WindowIdReferenceCount > 0)
{
--this->WindowIdReferenceCount;
if(this->WindowIdReferenceCount == 0)
{
this->Clean();
if (this->WindowId)
{
ReleaseDC(this->WindowId, this->DeviceContext);
......@@ -1445,6 +1440,9 @@ void vtkWin32OpenGLRenderWindow::CreateOffScreenDC(int xsize, int ysize,
void vtkWin32OpenGLRenderWindow::CreateOffScreenDC(HBITMAP hbmp, HDC aHdc)
{
this->InitializeApplication();
this->VTKRegisterClass();
BITMAP bm;
GetObject(hbmp, sizeof(BITMAP), &bm);
......@@ -1456,15 +1454,7 @@ void vtkWin32OpenGLRenderWindow::CreateOffScreenDC(HBITMAP hbmp, HDC aHdc)
// Put the bitmap into the device context
SelectObject(this->MemoryHdc, this->MemoryBuffer);
// Renderers will need to redraw anything cached in display lists
vtkRenderer *ren;
vtkCollectionSimpleIterator rsit;
for (this->Renderers->InitTraversal(rsit);
(ren = this->Renderers->GetNextRenderer(rsit));)
{
ren->SetRenderWindow(NULL);
ren->SetRenderWindow(this);
}
this->ReleaseGraphicsResources(this);
// adjust settings for renderwindow
this->Mapped =0;
......@@ -1552,16 +1542,8 @@ void vtkWin32OpenGLRenderWindow::ResumeScreenRendering(void)
// release OpenGL graphics resources before switch back to on-screen.
if(this->ContextId!=0)
{
this->MakeCurrent();
// Renderers will need to redraw anything cached in display lists
vtkRenderer *ren;
vtkCollectionSimpleIterator rsit;
for (this->Renderers->InitTraversal(rsit);
(ren = this->Renderers->GetNextRenderer(rsit));)
{
ren->SetRenderWindow(NULL);
ren->SetRenderWindow(this);
}
this->MakeCurrent();
this->ReleaseGraphicsResources(this);
}
this->Mapped = this->ScreenMapped;
......
......@@ -711,19 +711,7 @@ void vtkXOpenGLRenderWindow::DestroyWindow()
if (this->OwnContext && this->Internal->ContextId)
{
this->MakeCurrent();
// tell each of the renderers that this render window/graphics context
// is being removed (the RendererCollection is removed by vtkRenderWindow's
// destructor)
vtkRenderer* ren;
this->Renderers->InitTraversal();
for ( ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject());
ren != NULL;
ren = vtkOpenGLRenderer::SafeDownCast(this->Renderers->GetNextItemAsObject()) )
{
ren->SetRenderWindow(NULL);
ren->SetRenderWindow(this);
}
this->ReleaseGraphicsResources();
this->ReleaseGraphicsResources(this);
if (this->Internal->ContextId)
{
......@@ -890,17 +878,8 @@ void vtkXOpenGLRenderWindow::CreateOffScreenWindow(int width, int height)
void vtkXOpenGLRenderWindow::DestroyOffScreenWindow()
{
// release graphic resources.
vtkRenderer *ren;
vtkCollectionSimpleIterator rit;
this->Renderers->InitTraversal(rit);
while ( (ren = this->Renderers->GetNextRenderer(rit)) )
{
ren->SetRenderWindow(NULL);
ren->SetRenderWindow(this);
}
this->ReleaseGraphicsResources(this);
#ifdef VTK_USE_OSMESA
if (this->Internal->OffScreenContextId)
......
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