Commit 52d32544 authored by Ken Martin's avatar Ken Martin

try fix for offscreen rendering on Windows

The context was getting cleaned too often maybe.
This fix reverts one line from commit
https://gitlab.kitware.com/vtk/vtk/commit/
3a8e4497

This commit fixes issue

#16876

and adds a test for that condition as well as
a few other cases that should work but could
cause problems.

This change could introduce other issues limited
to windows as the code is fairly complex and
the use cases vary widely. At some point the whole
process of creating windows and handling offscreen
drawing needs to be reworked. It is a mishmash of 20
years of code and overdue for a real workover for all
platforms. But this topic is intended to fix this one
case until we have time to really look at it and rework
it.

Currently the new test is only active for OpenGL2 and
Windows. OpenGL1 and other platforms has issues with
it that need to be fixed in the future. But for now this
change fixes the reported Windows issues and adds a
test to maintain that fix.
parent 9922afd4
......@@ -13,6 +13,7 @@ if(VTK_RENDERING_BACKEND STREQUAL "OpenGL2")
TestTranslucentLUTTextureAlphaBlending.cxx
TestAreaSelections.cxx
TestValuePassFloatingPoint.cxx
TestToggleOSWithInteractor.cxx,NO_DATA
)
else()
set(extra_opengl2_tests
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestOSConeCxx.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.
=========================================================================*/
// This test covers offscreen rendering.
//
// The command line arguments are:
// -I => run in interactive mode; unless this is used, the program will
// not allow interaction and exit
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
// test works on Windows, in the future we need to
// make sure it works for OSX and Linux/EGL
#ifdef WIN32
int TestToggleOSWithInteractor(int argc, char* argv[])
{
// run through a couple cases
vtkNew<vtkSphereSource> sphere;
sphere->SetRadius( 10.0 );
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection( sphere->GetOutputPort() );
vtkNew<vtkActor> actor;
actor->SetMapper( mapper.Get() );
vtkNew<vtkRenderer> renderer;
renderer->AddActor( actor.Get() );
{
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer( renderer.Get() );
// 1) Try calling SupportsOpenGL to make sure that
// doesn't crash
renderWindow->SupportsOpenGL();
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow( renderWindow.Get() );
interactor->Initialize();
// 2) try toggling offscreen rendering on and off
renderWindow->OffScreenRenderingOn();
renderWindow->Render();
renderWindow->OffScreenRenderingOff();
renderWindow->Render();
}
{
// 3) try doing it again with a new window
// but using existing old actor/rederer
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer( renderer.Get() );
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow( renderWindow.Get() );
interactor->Initialize();
renderWindow->OffScreenRenderingOn();
renderWindow->Render();
renderWindow->OffScreenRenderingOff();
renderWindow->Render();
// 4) try doing it again with offscreenbuffers
renderWindow->SetUseOffScreenBuffers(true);
renderWindow->OffScreenRenderingOn();
renderWindow->Render();
renderWindow->OffScreenRenderingOff();
renderWindow->Render();
}
int retVal = 0;
{
// 5) try doing it again with a new everything
vtkNew<vtkActor> actor2;
actor2->SetMapper( mapper.Get() );
actor2->GetProperty()->SetAmbient(1.0);
actor2->GetProperty()->SetDiffuse(0.0);
vtkNew<vtkRenderer> renderer2;
renderer2->AddActor( actor2.Get() );
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer( renderer2.Get() );
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow( renderWindow.Get() );
interactor->Initialize();
renderWindow->OffScreenRenderingOn();
renderWindow->SupportsOpenGL();
renderWindow->Render();
renderWindow->OffScreenRenderingOff();
renderWindow->Render();
retVal = vtkRegressionTestImage( renderWindow.Get() );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
interactor->Start();
}
}
return !retVal;
#else
int TestToggleOSWithInteractor(int, char* [])
{
return 0;
#endif
}
......@@ -1063,12 +1063,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);
......
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