Commit c358a6a8 authored by Ken Martin's avatar Ken Martin Committed by Kitware Robot

Merge topic 'clean_supports_ogl'

50bc89e4 New Win32 approach to SupportsOpenGL
e83bf68e Try to make the OpenGLSupport process better
8f2cea5c try a different approach
78fd576e better testing for opengl support
6d6cc259 fix so that it only frees the display when it created it
f5076346 try something to see if it fixes a pv issue
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1021
parents 9a95cea8 50bc89e4
Pipeline #2787 running with stage
......@@ -121,6 +121,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
......@@ -247,12 +248,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();
......
......@@ -20,6 +20,7 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkRendererCollection.h"
#include "vtkWin32RenderWindowInteractor.h"
......@@ -412,43 +413,63 @@ void vtkWin32OpenGLRenderWindow::VTKRegisterClass()
int vtkWin32OpenGLRenderWindow::SupportsOpenGL()
{
#ifdef GLEW_OK
this->InitializeApplication();
this->VTKRegisterClass();
// Create a dummy window, needed for calling wglGetProcAddress.
#ifdef UNICODE
HWND tempId = CreateWindow(L"vtkOpenGL", 0, 0, 0, 0, 1, 1, 0, 0, this->ApplicationInstance, 0);
#else
HWND tempId = CreateWindow("vtkOpenGL", 0, 0, 0, 0, 1, 1, 0, 0, this->ApplicationInstance, 0);
#endif
HDC tempDC = GetDC(tempId);
PIXELFORMATDESCRIPTOR tempPfd;
memset(&tempPfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
tempPfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
tempPfd.nVersion = 1;
tempPfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
tempPfd.iPixelType = PFD_TYPE_RGBA;
int tempPixelFormat = ChoosePixelFormat(tempDC, &tempPfd);
SetPixelFormat(tempDC, tempPixelFormat, &tempPfd);
HGLRC tempContext = wglCreateContext(tempDC);
wglMakeCurrent(tempDC, tempContext);
if (this->OpenGLSupportTested)
{
return this->OpenGLSupportResult;
}
GLenum result = glewInit();
bool m_valid = (result == GLEW_OK);
if (!m_valid)
vtkWin32OpenGLRenderWindow *rw = vtkWin32OpenGLRenderWindow::New();
rw->SetOffScreenRendering(1);
rw->Initialize();
if (rw->GetContextSupportsOpenGL32())
{
return 0;
this->OpenGLSupportResult = 1;
this->OpenGLSupportMessage =
"The system appears to support OpenGL 3.2";
}
if (GLEW_VERSION_3_2 || (GLEW_VERSION_2_1 && GLEW_EXT_gpu_shader4))
#ifdef GLEW_OK
else if (GLEW_VERSION_3_2 || (GLEW_VERSION_2_1 && GLEW_EXT_gpu_shader4))
{
return 1;
this->OpenGLSupportResult = 1;
this->OpenGLSupportMessage =
"The system appears to support OpenGL 3.2 or has 2.1 with the required extension";
}
#endif
return 0;
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->OpenGLSupportTested = true;
return this->OpenGLSupportResult;
}
......
......@@ -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"
......@@ -728,12 +729,7 @@ void vtkXOpenGLRenderWindow::DestroyWindow()
this->WindowId = static_cast<Window>(NULL);
}
// if we create the display, we'll delete it
if (this->OwnDisplay && this->DisplayId)
{
XCloseDisplay(this->DisplayId);
this->DisplayId = NULL;
}
this->CloseDisplay();
delete[] this->Capabilities;
this->Capabilities = 0;
......@@ -1640,117 +1636,77 @@ const char* vtkXOpenGLRenderWindow::ReportCapabilities()
return this->Capabilities;
}
int vtkXOpenGLRenderWindow::SupportsOpenGL()
void vtkXOpenGLRenderWindow::CloseDisplay()
{
#ifdef GLEW_OK
if(!this->OffScreenRendering)
// if we create the display, we'll delete it
if (this->OwnDisplay && this->DisplayId)
{
// get the default display connection
if (!this->DisplayId)
{
this->DisplayId = XOpenDisplay(static_cast<char *>(NULL));
if (this->DisplayId == NULL)
{
vtkErrorMacro(<< "bad X server connection. DISPLAY="
<< vtksys::SystemTools::GetEnv("DISPLAY") << ". Aborting.\n");
return 0;
}
this->OwnDisplay = 1;
}
int value = 0;
XVisualInfo *v = this->GetDesiredVisualInfo();
if (!v)
{
return 0;
}
else
{
glXGetConfig(this->DisplayId, v, GLX_USE_GL, &value);
XFree(v);
}
// try for 32 context
if (this->Internal->FBConfig)
{
// NOTE: It is not necessary to create or make current to a context before
// calling glXGetProcAddressARB
glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0;
glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)
glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" );
int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 2,
//GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
0
};
XCloseDisplay(this->DisplayId);
this->DisplayId = NULL;
this->OwnDisplay = 0;
}
}
if (glXCreateContextAttribsARB)
{
this->Internal->ContextId =
glXCreateContextAttribsARB( this->DisplayId,
this->Internal->FBConfig, 0,
GL_TRUE, context_attribs );
// Sync to ensure any errors generated are processed.
XSync( this->DisplayId, False );
if ( this->Internal->ContextId )
{
this->SetContextSupportsOpenGL32(true);
}
}
}
int vtkXOpenGLRenderWindow::SupportsOpenGL()
{
if (this->OpenGLSupportTested)
{
return this->OpenGLSupportResult;
}
// old failsafe
if (this->Internal->ContextId == NULL)
{
this->Internal->ContextId =
glXCreateContext(this->DisplayId, v, 0, GL_TRUE);
}
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";
}
if(!this->Internal->ContextId)
{
return 0;
}
#ifdef GLEW_OK
int pbufferAttribs[] =
{
GLX_PBUFFER_WIDTH, 32,
GLX_PBUFFER_HEIGHT, 32,
None
};
GLXPbuffer pbuffer = glXCreatePbuffer(
this->DisplayId, this->Internal->FBConfig, pbufferAttribs);
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";
}
XSync( this->DisplayId, False );
#endif
if ( !glXMakeContextCurrent( this->DisplayId, pbuffer, pbuffer, this->Internal->ContextId) )
{
return 0;
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";
}
}
GLenum result = glewInit();
glFinish();
glXDestroyContext(this->DisplayId, this->Internal->ContextId);
glXDestroyPbuffer(this->DisplayId, pbuffer);
this->Internal->ContextId = 0;
bool m_valid = (result == GLEW_OK);
if (!m_valid)
{
return 0;
}
rw->Delete();
if (GLEW_VERSION_3_2 || (GLEW_VERSION_2_1 && GLEW_EXT_gpu_shader4))
{
return 1;
}
}
this->OpenGLSupportTested = true;
#endif
return 0;
return this->OpenGLSupportResult;
}
int vtkXOpenGLRenderWindow::IsDirect()
......
......@@ -270,6 +270,7 @@ protected:
void CreateOffScreenWindow(int width, int height);
void DestroyOffScreenWindow();
void ResizeOffScreenWindow(int width, int height);
void CloseDisplay();
private:
......
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