Commit e83bf68e authored by Ken Martin's avatar Ken Martin

Try to make the OpenGLSupport process better

Cache the result provide an API for a string message
Verify that a shader program compiles
parent 8f2cea5c
Pipeline #2682 passed with stage
......@@ -116,6 +116,10 @@ vtkOpenGLRenderWindow::vtkOpenGLRenderWindow()
this->OwnContext = 1;
this->MaximumHardwareLineWidth = 1.0;
this->OpenGLSupportTested = false;
this->OpenGLSupportResult = 0;
this->OpenGLSupportMessage = "Not tested yet";
}
// free up memory & close the window
......
......@@ -24,6 +24,7 @@
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkRenderWindow.h"
#include <string> // for ivar
#include <map> // for ivar
#include "vtkType.h" // for ivar
......@@ -243,12 +244,27 @@ public:
int vtktype, int numComponents,
bool needInteger, bool needFloat);
// Description:
// Return a message profiding additional details about the
// results of calling SupportsOpenGL() This can be used
// to retrieve more specifics about what failed
std::string GetOpenGLSupportMessage()
{
return this->OpenGLSupportMessage;
}
protected:
vtkOpenGLRenderWindow();
~vtkOpenGLRenderWindow();
vtkOpenGLShaderCache *ShaderCache;
// used in testing for opengl support
// in the SupportsOpenGL() method
bool OpenGLSupportTested;
int OpenGLSupportResult;
std::string OpenGLSupportMessage;
int TextureInternalFormats[VTK_UNICODE_STRING][3][5];
void InitializeTextureInternalFormats();
......
......@@ -39,6 +39,7 @@ typedef ptrdiff_t GLsizeiptr;
#include "vtkCommand.h"
#include "vtkIdList.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkRendererCollection.h"
#include "vtkRenderWindowInteractor.h"
......@@ -1648,7 +1649,10 @@ void vtkXOpenGLRenderWindow::CloseDisplay()
int vtkXOpenGLRenderWindow::SupportsOpenGL()
{
int result = 0;
if (this->OpenGLSupportTested)
{
return this->OpenGLSupportResult;
}
vtkXOpenGLRenderWindow *rw = vtkXOpenGLRenderWindow::New();
rw->SetDisplayId(this->DisplayId);
......@@ -1656,20 +1660,53 @@ int vtkXOpenGLRenderWindow::SupportsOpenGL()
rw->Initialize();
if (rw->GetContextSupportsOpenGL32())
{
result = 1;
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))
{
result = 1;
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();
return result;
this->OpenGLSupportTested = true;
return this->OpenGLSupportResult;
}
int vtkXOpenGLRenderWindow::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