Commit ec4014d4 authored by Andrew Bauer's avatar Andrew Bauer

Moving the SupportsOpenGL call to parent class to avoid code duplication.

parent 16120cba
......@@ -550,21 +550,6 @@ void vtkEGLRenderWindow::SetPosition(int x, int y)
this->Position[1] = y;
}
int vtkEGLRenderWindow::SupportsOpenGL()
{
if(!this->Initialized)
{
this->Initialize();
}
vtkInternals* impl = this->Internals;
this->MakeCurrent();
if(impl->Display == EGL_NO_DISPLAY && this->OwnWindow)
{
return false;
}
return true;
}
// Set this RenderWindow to a pre-existing window.
void vtkEGLRenderWindow::SetWindowInfo(char *)
{
......@@ -572,7 +557,6 @@ void vtkEGLRenderWindow::SetWindowInfo(char *)
this->Mapped = 1;
}
void vtkEGLRenderWindow::SetWindowName(const char *name)
{
vtkOpenGLRenderWindow::SetWindowName( name );
......
......@@ -92,10 +92,6 @@ public:
// Tells if this window is the current OpenGL context for the calling thread.
virtual bool IsCurrent();
// Description:
// Does this render window support OpenGL? 0-false, 1-true
int SupportsOpenGL();
// Description:
// Is this render window using hardware acceleration? 0-false, 1-true
int IsDirect() { return 1;};
......
......@@ -31,9 +31,11 @@
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkOpenGLVertexArrayObject.h"
#include "vtkOutputWindow.h"
#include "vtkRendererCollection.h"
#include "vtkShaderProgram.h"
#include "vtkStdString.h"
#include "vtkStringOutputWindow.h"
#include "vtkTextureObject.h"
#include "vtkTextureUnitManager.h"
#include "vtkUnsignedCharArray.h"
......@@ -2247,3 +2249,77 @@ bool vtkOpenGLRenderWindow::GetUseOffScreenBuffers()
{
return this->HardwareOffScreenBuffersBind || this->OffScreenRendering;
}
// ----------------------------------------------------------------------------
int vtkOpenGLRenderWindow::SupportsOpenGL()
{
if (this->OpenGLSupportTested)
{
return this->OpenGLSupportResult;
}
vtkOutputWindow *oldOW = vtkOutputWindow::GetInstance();
oldOW->Register(this);
vtkNew<vtkStringOutputWindow> sow;
vtkOutputWindow::SetInstance(sow.Get());
vtkOpenGLRenderWindow *rw = this->NewInstance();
rw->SetDisplayId(this->GetGenericDisplayId());
rw->SetOffScreenRendering(1);
rw->Initialize();
if (rw->GetContextSupportsOpenGL32())
{
this->OpenGLSupportResult = 1;
this->OpenGLSupportMessage =
"The system appears to support OpenGL 3.2";
}
#ifdef GLEW_OK
else if (GLEW_VERSION_3_2 || (GLEW_VERSION_2_1 && GLEW_EXT_gpu_shader4))
{
this->OpenGLSupportResult = 1;
this->OpenGLSupportMessage =
"The system appears to support OpenGL 3.2 or has 2.1 with the required extension";
}
#endif
if (this->OpenGLSupportResult)
{
// even if glew thinks we have support we should actually try linking a
// shader program to make sure
vtkShaderProgram *newShader =
rw->GetShaderCache()->ReadyShaderProgram(
// simple vert shader
"//VTK::System::Dec\n"
"attribute vec4 vertexMC;\n"
"void main() { gl_Position = vertexMC; }\n",
// frag shader that used gl_PrimitiveId
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"void main(void) {\n"
" gl_FragData[0] = vec4(float(gl_PrimitiveID)/100.0,1.0,1.0,1.0);\n"
"}\n",
// no geom shader
"");
if (newShader == NULL)
{
this->OpenGLSupportResult = 0;
this->OpenGLSupportMessage =
"The system appeared to have OpenGL Support but a test shader program failed to compile and link";
}
}
rw->Delete();
this->OpenGLSupportMessage +=
"vtkOutputWindow Text Folows:\n\n" +
sow->GetOutput();
vtkOutputWindow::SetInstance(oldOW);
oldOW->Delete();
this->OpenGLSupportTested = true;
return this->OpenGLSupportResult;
}
......@@ -277,6 +277,17 @@ public:
virtual int SetUseOffScreenBuffers(bool offScreen);
virtual bool GetUseOffScreenBuffers();
// Description:
// Does this render window support OpenGL? 0-false, 1-true
virtual int SupportsOpenGL();
// Description:
// Initialize the rendering window. This will setup all system-specific
// resources. This method and Finalize() must be symmetric and it
// should be possible to call them multiple times, even changing WindowId
// in-between. This is what WindowRemap does.
virtual void Initialize(void) {};
protected:
vtkOpenGLRenderWindow();
~vtkOpenGLRenderWindow();
......
......@@ -402,79 +402,6 @@ void vtkWin32OpenGLRenderWindow::VTKRegisterClass()
}
}
int vtkWin32OpenGLRenderWindow::SupportsOpenGL()
{
if (this->OpenGLSupportTested)
{
return this->OpenGLSupportResult;
}
vtkOutputWindow *oldOW = vtkOutputWindow::GetInstance();
oldOW->Register(this);
vtkNew<vtkStringOutputWindow> sow;
vtkOutputWindow::SetInstance(sow.Get());
vtkWin32OpenGLRenderWindow *rw = vtkWin32OpenGLRenderWindow::New();
rw->SetOffScreenRendering(1);
rw->Initialize();
if (rw->GetContextSupportsOpenGL32())
{
this->OpenGLSupportResult = 1;
this->OpenGLSupportMessage =
"The system appears to support OpenGL 3.2";
}
#ifdef GLEW_OK
else if (GLEW_VERSION_3_2 || (GLEW_VERSION_2_1 && GLEW_EXT_gpu_shader4))
{
this->OpenGLSupportResult = 1;
this->OpenGLSupportMessage =
"The system appears to support OpenGL 3.2 or has 2.1 with the required extension";
}
#endif
if (this->OpenGLSupportResult)
{
// even if glew thinks we have support we should actually try linking a
// shader program to make sure
vtkShaderProgram *newShader =
rw->GetShaderCache()->ReadyShaderProgram(
// simple vert shader
"//VTK::System::Dec\n"
"attribute vec4 vertexMC;\n"
"void main() { gl_Position = vertexMC; }\n",
// frag shader that used gl_PrimitiveId
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"void main(void) {\n"
" gl_FragData[0] = vec4(float(gl_PrimitiveID)/100.0,1.0,1.0,1.0);\n"
"}\n",
// no geom shader
"");
if (newShader == NULL)
{
this->OpenGLSupportResult = 0;
this->OpenGLSupportMessage =
"The system appeared to have OpenGL Support but a test shader program failed to compile and link";
}
}
rw->Delete();
this->OpenGLSupportMessage +=
"vtkOutputWindow Text Folows:\n\n" +
sow->GetOutput();
vtkOutputWindow::SetInstance(oldOW);
oldOW->Delete();
this->OpenGLSupportTested = true;
return this->OpenGLSupportResult;
}
int vtkWin32OpenGLRenderWindow::IsDirect()
{
this->MakeCurrent();
......
......@@ -169,10 +169,6 @@ public:
// Get report of capabilities for the render window
const char *ReportCapabilities();
// Description:
// Does this render window support OpenGL? 0-false, 1-true
int SupportsOpenGL();
// Description:
// Is this render window using hardware acceleration? 0-false, 1-true
int IsDirect();
......
......@@ -1641,79 +1641,6 @@ void vtkXOpenGLRenderWindow::CloseDisplay()
}
}
int vtkXOpenGLRenderWindow::SupportsOpenGL()
{
if (this->OpenGLSupportTested)
{
return this->OpenGLSupportResult;
}
vtkOutputWindow *oldOW = vtkOutputWindow::GetInstance();
oldOW->Register(this);
vtkNew<vtkStringOutputWindow> sow;
vtkOutputWindow::SetInstance(sow.Get());
vtkXOpenGLRenderWindow *rw = vtkXOpenGLRenderWindow::New();
rw->SetDisplayId(this->DisplayId);
rw->SetOffScreenRendering(1);
rw->Initialize();
if (rw->GetContextSupportsOpenGL32())
{
this->OpenGLSupportResult = 1;
this->OpenGLSupportMessage =
"The system appears to support OpenGL 3.2";
}
#ifdef GLEW_OK
else if (GLEW_VERSION_3_2 || (GLEW_VERSION_2_1 && GLEW_EXT_gpu_shader4))
{
this->OpenGLSupportResult = 1;
this->OpenGLSupportMessage =
"The system appears to support OpenGL 3.2 or has 2.1 with the required extension";
}
#endif
if (this->OpenGLSupportResult)
{
// even if glew thinks we have support we should actually try linking a
// shader program to make sure
vtkShaderProgram *newShader =
rw->GetShaderCache()->ReadyShaderProgram(
// simple vert shader
"//VTK::System::Dec\n"
"attribute vec4 vertexMC;\n"
"void main() { gl_Position = vertexMC; }\n",
// frag shader that used gl_PrimitiveId
"//VTK::System::Dec\n"
"//VTK::Output::Dec\n"
"void main(void) {\n"
" gl_FragData[0] = vec4(float(gl_PrimitiveID)/100.0,1.0,1.0,1.0);\n"
"}\n",
// no geom shader
"");
if (newShader == NULL)
{
this->OpenGLSupportResult = 0;
this->OpenGLSupportMessage =
"The system appeared to have OpenGL Support but a test shader program failed to compile and link";
}
}
rw->Delete();
this->OpenGLSupportMessage +=
"vtkOutputWindow Text Folows:\n\n" +
sow->GetOutput();
vtkOutputWindow::SetInstance(oldOW);
oldOW->Delete();
this->OpenGLSupportTested = true;
return this->OpenGLSupportResult;
}
int vtkXOpenGLRenderWindow::IsDirect()
{
this->MakeCurrent();
......
......@@ -111,10 +111,6 @@ public:
// Get report of capabilities for the render window
const char *ReportCapabilities();
// Description:
// Does this render window support OpenGL? 0-false, 1-true
int SupportsOpenGL();
// Description:
// Is this render window using hardware acceleration? 0-false, 1-true
int IsDirect();
......
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