From: isk Date: Tue, 16 Aug 2016 11:19:25 +0000 (+0300) Subject: Fix background troubles. X-Git-Tag: V8_1_0rc1~8^2~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=65e02990cc881c70c156195c160921009e4a5f87;p=modules%2Fgui.git Fix background troubles. --- diff --git a/src/VTKViewer/CMakeLists.txt b/src/VTKViewer/CMakeLists.txt index d0095af7c..7d0d468e2 100755 --- a/src/VTKViewer/CMakeLists.txt +++ b/src/VTKViewer/CMakeLists.txt @@ -69,6 +69,7 @@ SET(_other_HEADERS VTKViewer_InteractorStyle.h VTKViewer_MarkerDef.h VTKViewer_MarkerUtils.h + VTKViewer_OpenGLHelper.h VTKViewer_OpenGLRenderer.h VTKViewer_PolyDataMapper.h VTKViewer_ShrinkFilter.h @@ -152,6 +153,7 @@ SET(_other_SOURCES VTKViewer_MarkerDlg.cxx VTKViewer_MarkerUtils.cxx VTKViewer_MarkerWidget.cxx + VTKViewer_OpenGLHelper.cxx VTKViewer_OpenGLRenderer.cxx VTKViewer_PolyDataMapper.cxx VTKViewer_RenderWindow.cxx diff --git a/src/VTKViewer/VTKViewer_OpenGLHelper.cxx b/src/VTKViewer/VTKViewer_OpenGLHelper.cxx new file mode 100644 index 000000000..b92c14dc9 --- /dev/null +++ b/src/VTKViewer/VTKViewer_OpenGLHelper.cxx @@ -0,0 +1,362 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + +#include "VTKViewer_OpenGLHelper.h" + +#ifndef WIN32 +# ifndef GLX_GLXEXT_LEGACY +# define GLX_GLXEXT_LEGACY +# endif +# include +# include +#else +# include +#endif + +#ifndef WIN32 +#define GL_GetProcAddress( x ) glXGetProcAddressARB( (const GLubyte*)x ) +#else +#define GL_GetProcAddress( x ) wglGetProcAddress( (const LPCSTR)x ) +#endif + +// ============================================================================ +// function : VTKViewer_OpenGLHelper +// purpose : +// ============================================================================ +VTKViewer_OpenGLHelper::VTKViewer_OpenGLHelper() +: vglShaderSourceARB (NULL), + vglCreateShaderObjectARB (NULL), + vglCompileShaderARB (NULL), + vglCreateProgramObjectARB (NULL), + vglAttachObjectARB (NULL), + vglLinkProgramARB (NULL), + vglUseProgramObjectARB (NULL), + vglGenBuffersARB (NULL), + vglBindBufferARB (NULL), + vglBufferDataARB (NULL), + vglDeleteBuffersARB (NULL), + vglGetAttribLocationARB (NULL), + vglVertexAttribPointerARB (NULL), + vglEnableVertexAttribArrayARB (NULL), + vglDisableVertexAttribArrayARB (NULL), +#ifdef VTK_OPENGL2 + vglDetachObjectARB (NULL), + vglDeleteObjectARB (NULL), + vglValidateProgramARB (NULL), + vglGetShaderivARB (NULL), + vglGetProgramivARB (NULL), + vglGetShaderInfoLogARB (NULL), + vglUniformMatrix4fvARB (NULL), + vglGenVertexArraysARB (NULL), + vglBindVertexArrayARB (NULL), + vglUniform1iARB (NULL), + vglGetUniformLocationARB (NULL), +#endif + mIsInitialized (false) +{ + Init(); +} + +// ============================================================================ +// function : ~VTKViewer_OpenGLHelper +// purpose : +// ============================================================================ +VTKViewer_OpenGLHelper::~VTKViewer_OpenGLHelper() +{ + // +} + +// ============================================================================ +// function : Init +// purpose : +// ============================================================================ +void VTKViewer_OpenGLHelper::Init() +{ + if (mIsInitialized) + return; + + vglShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)GL_GetProcAddress( "glShaderSourceARB" ); + if( !vglShaderSourceARB ) + return; + + vglCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)GL_GetProcAddress( "glCreateShaderObjectARB" ); + if( !vglCreateShaderObjectARB ) + return; + + vglCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)GL_GetProcAddress( "glCompileShaderARB" ); + if( !vglCompileShaderARB ) + return; + + vglCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)GL_GetProcAddress( "glCreateProgramObjectARB" ); + if( !vglCreateProgramObjectARB ) + return; + + vglAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)GL_GetProcAddress( "glAttachObjectARB" ); + if( !vglAttachObjectARB ) + return; + + vglLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)GL_GetProcAddress( "glLinkProgramARB" ); + if( !vglLinkProgramARB ) + return; + + vglUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)GL_GetProcAddress( "glUseProgramObjectARB" ); + if( !vglUseProgramObjectARB ) + return; + + vglGenBuffersARB = (PFNGLGENBUFFERSARBPROC)GL_GetProcAddress( "glGenBuffersARB" ); + if( !vglGenBuffersARB ) + return; + + vglBindBufferARB = (PFNGLBINDBUFFERARBPROC)GL_GetProcAddress( "glBindBufferARB" ); + if( !vglBindBufferARB ) + return; + + vglBufferDataARB = (PFNGLBUFFERDATAARBPROC)GL_GetProcAddress( "glBufferDataARB" ); + if( !vglBufferDataARB ) + return; + + vglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)GL_GetProcAddress( "glDeleteBuffersARB" ); + if( !vglDeleteBuffersARB ) + return; + + vglGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC)GL_GetProcAddress( "glGetAttribLocation" ); + if( !vglGetAttribLocationARB ) + return; + + vglVertexAttribPointerARB = (PFNGLVERTEXATTRIBPOINTERARBPROC)GL_GetProcAddress( "glVertexAttribPointer" ); + if( !vglVertexAttribPointerARB ) + return; + + vglEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)GL_GetProcAddress( "glEnableVertexAttribArray" ); + if(!vglEnableVertexAttribArrayARB) + return; + + vglDisableVertexAttribArrayARB = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)GL_GetProcAddress( "glDisableVertexAttribArray" ); + if(!vglDisableVertexAttribArrayARB) + return; + +#ifdef VTK_OPENGL2 + vglDetachObjectARB = (PFNGLDETACHOBJECTARBPROC)GL_GetProcAddress( "glDetachObjectARB" ); + if( !vglDetachObjectARB ) + return; + + vglDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)GL_GetProcAddress( "glDeleteObjectARB" ); + if( !vglDeleteObjectARB ) + return; + + vglValidateProgramARB = (PFNGLVALIDATEPROGRAMARBPROC)GL_GetProcAddress( "glValidateProgramARB" ); + if ( !vglValidateProgramARB ) + return; + + vglGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)GL_GetProcAddress( "glGetUniformLocationARB" ); + if( !vglGetUniformLocationARB ) + return; + + vglGetShaderivARB = (PFNGLGETSHADERIVPROC)GL_GetProcAddress( "glGetShaderiv" ); + if( !vglGetShaderivARB ) + return; + + vglGetProgramivARB = (PFNGLGETPROGRAMIVPROC)GL_GetProcAddress( "glGetProgramiv" ); + if( !vglGetProgramivARB ) + return; + + vglGetShaderInfoLogARB = (PFNGLGETSHADERINFOLOGPROC)GL_GetProcAddress( "glGetShaderInfoLog" ); + if( !vglGetShaderInfoLogARB ) + return; + + vglUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC)GL_GetProcAddress( "glUniformMatrix4fv" ); + if( !vglUniformMatrix4fvARB ) + return; + + vglGenVertexArraysARB = (PFNGLGENVERTEXARRAYSARBPROC)GL_GetProcAddress( "glGenVertexArrays" ); + if( !vglGenVertexArraysARB ) + return; + + vglBindVertexArrayARB = (PFNGLBINDVERTEXARRAYARBPROC)GL_GetProcAddress( "glBindVertexArray" ); + if( !vglBindVertexArrayARB ) + return; + + vglUniform1iARB = (PFNGLUNIFORM1IARBPROC)GL_GetProcAddress( "glUniform1i" ); + if( !vglUniform1iARB ) + return; +#endif + + mIsInitialized = true; + return; +} + +namespace +{ + char* readFromFile( std::string fileName ) + { + FILE* file = fopen( fileName.c_str(), "r" ); + + char* content = NULL; + int count = 0; + + if( file != NULL ) + { + fseek( file, 0, SEEK_END ); + count = ftell( file ); + rewind( file ); + + if( count > 0 ) + { + content = ( char* )malloc( sizeof( char ) * ( count + 1 ) ); + count = fread( content, sizeof( char ), count, file ); + content[ count ] = '\0'; + } + fclose( file ); + } + + return content; + } +} +// ============================================================================ +// function : CreateShaderProgram +// purpose : +// ============================================================================ +bool VTKViewer_OpenGLHelper::CreateShaderProgram (const std::string& theFilePath, + GLhandleARB& theProgram, + GLhandleARB& theVertexShader, + GLhandleARB& theFragmentShader) const +{ +#ifdef VTK_OPENGL2 + // Create program. + theProgram = vglCreateProgramObjectARB(); + if (theProgram == 0) + { + std::cerr << "Can't create opengl program." << std::endl; + return false; + } + + std::string fileName; + char* shaderContent; + GLint linked, compileStatus, validateStatus; + + // Create vertex shader. + fileName = theFilePath + ".vs.glsl"; + + shaderContent = readFromFile (fileName); + + theVertexShader = vglCreateShaderObjectARB (GL_VERTEX_SHADER_ARB); + vglShaderSourceARB (theVertexShader, 1, (const GLcharARB**)&shaderContent, NULL); + vglCompileShaderARB (theVertexShader); + + free( shaderContent ); + + vglGetShaderivARB (theVertexShader, GL_COMPILE_STATUS, &compileStatus); + if (compileStatus != GL_TRUE) + { + GLint size; + GLchar info[1024]; + + vglGetShaderInfoLogARB (theVertexShader, 1024, &size, info); + std::cerr << "Can't compile vertex shader." << std::endl; + std::cerr << info << std::endl; + + return false; + } + + // Create fragment shader. + fileName = theFilePath + ".fs.glsl"; + + shaderContent = readFromFile (fileName); + + theFragmentShader = vglCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB); + vglShaderSourceARB (theFragmentShader, 1, (const GLcharARB**)&shaderContent, NULL); + vglCompileShaderARB (theFragmentShader); + + free (shaderContent); + + vglGetShaderivARB (theFragmentShader, GL_COMPILE_STATUS, &compileStatus); + if (compileStatus != GL_TRUE) + { + GLint size; + GLchar info[1024]; + + vglGetShaderInfoLogARB (theVertexShader, 1024, &size, info); + std::cerr << "Can't compile fragment shader." << std::endl; + std::cerr << info << std::endl; + return false; + } + + // Attach shaders. + vglAttachObjectARB (theProgram, theVertexShader); + vglAttachObjectARB (theProgram, theFragmentShader); + vglLinkProgramARB (theProgram); + + vglGetProgramivARB (theProgram, GL_LINK_STATUS, &linked); + if (!linked) + { + std::cerr << "Can't link program." << std::endl; + return false; + } + + vglValidateProgramARB (theProgram); + vglGetProgramivARB (theProgram, GL_VALIDATE_STATUS, &validateStatus); + + if (validateStatus != GL_TRUE) + { + std::cerr << "Shader program is not validate." << std::endl; + return false; + } + + return true; +#else + return false; +#endif +} + +// ============================================================================ +// function : DestroyShaderProgram +// purpose : +// ============================================================================ +void VTKViewer_OpenGLHelper::DestroyShaderProgram (GLhandleARB theProgram, + GLhandleARB theVertexShader, + GLhandleARB theFragmentShader) const +{ +#ifdef VTK_OPENGL2 + vglDetachObjectARB (theProgram, theVertexShader); + vglDetachObjectARB (theProgram, theFragmentShader); + + vglDeleteObjectARB (theVertexShader); + vglDeleteObjectARB (theFragmentShader); +#endif +} + +// ============================================================================ +// function : SetUniformMatrix +// purpose : +// ============================================================================ +void VTKViewer_OpenGLHelper::SetUniformMatrix (const GLint theLocation, + const vtkMatrix4x4* theMatrix) const +{ + float data[16]; + for (int i = 0; i < 16; ++i) + { + data[i] = theMatrix->Element[i / 4][i % 4]; + } + + this->vglUniformMatrix4fvARB (theLocation, 1, GL_FALSE, data); +} diff --git a/src/VTKViewer/VTKViewer_OpenGLHelper.h b/src/VTKViewer/VTKViewer_OpenGLHelper.h new file mode 100644 index 000000000..26333be2d --- /dev/null +++ b/src/VTKViewer/VTKViewer_OpenGLHelper.h @@ -0,0 +1,160 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef VTKVIEWER_OPENGLHELPER_H +#define VTKVIEWER_OPENGLHELPER_H + +#include +#include +#include "VTKViewer.h" + +#include + + +#ifndef GL_ARB_shader_objects +typedef GLuint GLhandleARB; +#endif + +#ifndef APIENTRY +#define APIENTRY +#endif +#ifndef APIENTRYP +#define APIENTRYP APIENTRY * +#endif + +#ifndef GL_ARB_shader_objects +typedef char GLcharARB; +#endif + +#ifndef GL_VERTEX_PROGRAM_POINT_SIZE_ARB +#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 +#endif + +#ifndef GL_VERTEX_SHADER_ARB +#define GL_VERTEX_SHADER_ARB 0x8B31 +#endif + +#ifndef GL_FRAGMENT_SHADER_ARB +#define GL_FRAGMENT_SHADER_ARB 0x8B30 +#endif + +#ifndef GL_ARB_point_sprite +#define GL_POINT_SPRITE_ARB 0x8861 +#define GL_COORD_REPLACE_ARB 0x8862 +#endif + +#ifndef GL_ARB_vertex_buffer_object +typedef ptrdiff_t GLsizeiptrARB; + +#define GL_ARRAY_BUFFER_ARB 0x8892 +#define GL_STATIC_DRAW_ARB 0x88E4 +#endif + +class VTKVIEWER_EXPORT VTKViewer_OpenGLHelper +{ +public: + VTKViewer_OpenGLHelper(); + ~VTKViewer_OpenGLHelper(); + + void Init(); + + bool IsInitialized() const { return mIsInitialized; } + +public: + bool CreateShaderProgram (const std::string& theFilePath, + GLhandleARB& theProgram, + GLhandleARB& theVertexShader, + GLhandleARB& theFragmentShader) const; + + void DestroyShaderProgram (GLhandleARB theProgram, + GLhandleARB theVertexShader, + GLhandleARB theFragmentShader) const; + + void SetUniformMatrix (const GLint theLocation, + const vtkMatrix4x4* theMatrix) const; + +protected: + typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); + typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); + typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); + typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); + typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); + typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); + typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); + typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); + typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); + typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); + typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); + typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); + typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); + typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); + typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); + +#ifdef VTK_OPENGL2 + typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); + typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); + typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB program); + typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB program, const GLcharARB *name ); + typedef void (APIENTRYP PFNGLGETSHADERIVARBPROC) (GLuint shader, GLenum pname, GLint *params); + typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLuint program, GLenum pname, GLint *params); + typedef void (APIENTRYP PFNGLGETSHADERINFOLOGARBPROC) (GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog); + typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); + typedef void (APIENTRYP PFNGLGENVERTEXARRAYSARBPROC) (GLsizei n, GLuint *arrays); + typedef void (APIENTRYP PFNGLBINDVERTEXARRAYARBPROC) (GLuint array); + typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); +#endif + +public: + PFNGLSHADERSOURCEARBPROC vglShaderSourceARB; + PFNGLCREATESHADEROBJECTARBPROC vglCreateShaderObjectARB; + PFNGLCOMPILESHADERARBPROC vglCompileShaderARB; + PFNGLCREATEPROGRAMOBJECTARBPROC vglCreateProgramObjectARB; + PFNGLATTACHOBJECTARBPROC vglAttachObjectARB; + PFNGLLINKPROGRAMARBPROC vglLinkProgramARB; + PFNGLUSEPROGRAMOBJECTARBPROC vglUseProgramObjectARB; + + PFNGLGENBUFFERSARBPROC vglGenBuffersARB; + PFNGLBINDBUFFERARBPROC vglBindBufferARB; + PFNGLBUFFERDATAARBPROC vglBufferDataARB; + PFNGLDELETEBUFFERSARBPROC vglDeleteBuffersARB; + PFNGLGETATTRIBLOCATIONARBPROC vglGetAttribLocationARB; + PFNGLVERTEXATTRIBPOINTERARBPROC vglVertexAttribPointerARB; + PFNGLENABLEVERTEXATTRIBARRAYARBPROC vglEnableVertexAttribArrayARB; + PFNGLDISABLEVERTEXATTRIBARRAYARBPROC vglDisableVertexAttribArrayARB; + +#ifdef VTK_OPENGL2 + PFNGLDETACHOBJECTARBPROC vglDetachObjectARB; + PFNGLDELETEOBJECTARBPROC vglDeleteObjectARB; + PFNGLVALIDATEPROGRAMARBPROC vglValidateProgramARB; + PFNGLGETSHADERIVARBPROC vglGetShaderivARB; + PFNGLGETPROGRAMIVARBPROC vglGetProgramivARB; + PFNGLGETSHADERINFOLOGARBPROC vglGetShaderInfoLogARB; + + PFNGLUNIFORMMATRIX4FVARBPROC vglUniformMatrix4fvARB; + PFNGLGENVERTEXARRAYSARBPROC vglGenVertexArraysARB; + PFNGLBINDVERTEXARRAYARBPROC vglBindVertexArrayARB; + PFNGLUNIFORM1IARBPROC vglUniform1iARB; + PFNGLGETUNIFORMLOCATIONARBPROC vglGetUniformLocationARB; +#endif + +protected: + bool mIsInitialized; +}; + +#endif diff --git a/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx b/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx index 117a2939b..64bb2e4f3 100644 --- a/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx +++ b/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx @@ -46,6 +46,15 @@ vtkStandardNewMacro(VTKViewer_OpenGLRenderer); VTKViewer_OpenGLRenderer::VTKViewer_OpenGLRenderer() { this->GradientType = HorizontalGradient; + +#ifdef VTK_OPENGL2 + this->BackgroundProgram = 0; + this->BackgroundVertexShader = 0; + this->BackgroundFragmentShader = 0; + this->VertexArrayObject = 0; + + this->OpenGLHelper.Init(); +#endif } VTKViewer_OpenGLRenderer::~VTKViewer_OpenGLRenderer() @@ -59,6 +68,30 @@ void VTKViewer_OpenGLRenderer::SetGradientType( const int theGradientType ) void VTKViewer_OpenGLRenderer::Clear(void) { +#ifdef VTK_OPENGL2 + if (this->OpenGLHelper.IsInitialized()) + { + if (this->BackgroundProgram == 0) + { + std::string filePath = std::string( getenv( "GUI_ROOT_DIR") ) + "/share/salome/resources/gui/Background"; + if (!this->OpenGLHelper.CreateShaderProgram (filePath, + this->BackgroundProgram, + this->BackgroundVertexShader, + this->BackgroundFragmentShader)) + { + return; + } + // Get uniform locations. + this->OpenGLHelper.vglUseProgramObjectARB (this->BackgroundProgram); + + this->myLocations.UseTexture = this->OpenGLHelper.vglGetUniformLocationARB (this->BackgroundProgram, "uUseTexture"); + this->myLocations.BackgroundTexture = this->OpenGLHelper.vglGetUniformLocationARB (this->BackgroundProgram, "uBackgroundTexture"); + + this->OpenGLHelper.vglUseProgramObjectARB (0); + } + } +#endif + GLbitfield clear_mask = 0; if( !this->Transparent() ) @@ -92,6 +125,9 @@ void VTKViewer_OpenGLRenderer::Clear(void) glDisable( GL_TEXTURE_1D ); glDisable( GL_TEXTURE_2D ); glDisable( GL_BLEND ); + + GLint oldShadeModel; + glGetIntegerv(GL_SHADE_MODEL, &oldShadeModel); glShadeModel( GL_SMOOTH ); // color interpolation glMatrixMode( GL_PROJECTION ); @@ -176,6 +212,62 @@ void VTKViewer_OpenGLRenderer::Clear(void) break; } +#ifdef VTK_OPENGL2 + if (this->OpenGLHelper.IsInitialized()) + { + if (this->VertexArrayObject == 0) + { + this->OpenGLHelper.vglGenVertexArraysARB (1, &this->VertexArrayObject); + } + + this->OpenGLHelper.vglUseProgramObjectARB (this->BackgroundProgram); + this->OpenGLHelper.vglBindVertexArrayARB (this->VertexArrayObject); + + GLfloat data[7 * 4]; + if( this->GradientType != FirstCornerGradient && this->GradientType != ThirdCornerGradient ) + { + const float tmpData[] = { (float)corner1[0], (float)corner1[1], (float)corner1[2], 1.0f, -1.0f, 1.0f, 0.0f, + (float)corner2[0], (float)corner2[1], (float)corner2[2], 1.0f, -1.0f, -1.0f, 0.0f, + (float)corner3[0], (float)corner3[1], (float)corner3[2], 1.0f, 1.0f, -1.0f, 0.0f, + (float)corner4[0], (float)corner4[1], (float)corner4[2], 1.0f, 1.0f, 1.0f, 0.0f }; + memcpy (data, tmpData, sizeof(float) * 7 * 4); + } + else //if( this->GradientType == FirstCornerGradient || this->GradientType == ThirdCornerGradient ) + { + const float tmpData[] = { (float)corner2[0], (float)corner2[1], (float)corner2[2], 1.0f, -1.0f, -1.0f, 0.0f, + (float)corner3[0], (float)corner3[1], (float)corner3[2], 1.0f, -1.0f, 1.0f, 0.0f, + (float)corner4[0], (float)corner4[1], (float)corner4[2], 1.0f, 1.0f, 1.0f, 0.0f, + (float)corner1[0], (float)corner1[1], (float)corner1[2], 1.0f, 1.0f, -1.0f, 0.0f }; + memcpy (data, tmpData, sizeof(float) * 7 * 4); + } + + GLuint vertexBuffer; + this->OpenGLHelper.vglGenBuffersARB (1, &vertexBuffer); + this->OpenGLHelper.vglBindBufferARB (GL_ARRAY_BUFFER_ARB, vertexBuffer); + this->OpenGLHelper.vglBufferDataARB (GL_ARRAY_BUFFER_ARB, sizeof(data), data, GL_STATIC_DRAW_ARB); + + GLint colorAttrib = this->OpenGLHelper.vglGetAttribLocationARB (this->BackgroundProgram, "Color"); + GLint vertexAttrib = this->OpenGLHelper.vglGetAttribLocationARB (this->BackgroundProgram, "Vertex"); + GLsizei vertexSize = sizeof(GLfloat) * 7; + + this->OpenGLHelper.vglVertexAttribPointerARB (colorAttrib, 4, GL_FLOAT, GL_FALSE, vertexSize, (const GLvoid*)0); + this->OpenGLHelper.vglEnableVertexAttribArrayARB (colorAttrib); + + this->OpenGLHelper.vglVertexAttribPointerARB (vertexAttrib, 3, GL_FLOAT, GL_FALSE, vertexSize, (const GLvoid*)(sizeof(GLfloat) * 4)); + this->OpenGLHelper.vglEnableVertexAttribArrayARB (vertexAttrib); + + this->OpenGLHelper.vglUniform1iARB (this->myLocations.UseTexture, 0); + + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + this->OpenGLHelper.vglDisableVertexAttribArrayARB (0); + this->OpenGLHelper.vglBindBufferARB (GL_ARRAY_BUFFER_ARB, 0); + this->OpenGLHelper.vglDeleteBuffersARB (1, &vertexBuffer); + this->OpenGLHelper.vglBindVertexArrayARB (0); + this->OpenGLHelper.vglUseProgramObjectARB (0); + } +#else + glBegin( GL_TRIANGLE_FAN ); if( this->GradientType != FirstCornerGradient && this->GradientType != ThirdCornerGradient ) { @@ -192,6 +284,7 @@ void VTKViewer_OpenGLRenderer::Clear(void) glColor3f( corner1[0], corner1[1], corner1[2] ); glVertex2f( 0.F, 0.F ); } glEnd(); +#endif } if( this->TexturedBackground && this->BackgroundTexture ) @@ -213,7 +306,50 @@ void VTKViewer_OpenGLRenderer::Clear(void) // below the threshold. Here we have to enable it so that it won't // rejects the fragments of the quad as the alpha is set to 0 on it. glDisable( GL_ALPHA_TEST ); +#ifdef VTK_OPENGL2 + if (this->OpenGLHelper.IsInitialized()) + { + if (this->VertexArrayObject == 0) + { + this->OpenGLHelper.vglGenVertexArraysARB (1, &this->VertexArrayObject); + } + + this->OpenGLHelper.vglUseProgramObjectARB (this->BackgroundProgram); + this->OpenGLHelper.vglBindVertexArrayARB (this->VertexArrayObject); + + // First 4 components of Vertex is TexCoords now. + GLfloat data[7 * 4] = { 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, + 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f }; + GLuint vertexBuffer; + this->OpenGLHelper.vglGenBuffersARB (1, &vertexBuffer); + this->OpenGLHelper.vglBindBufferARB (GL_ARRAY_BUFFER_ARB, vertexBuffer); + this->OpenGLHelper.vglBufferDataARB (GL_ARRAY_BUFFER_ARB, sizeof(data), data, GL_STATIC_DRAW_ARB); + + GLint colorAttrib = this->OpenGLHelper.vglGetAttribLocationARB (this->BackgroundProgram, "Color"); + GLint vertexAttrib = this->OpenGLHelper.vglGetAttribLocationARB (this->BackgroundProgram, "Vertex"); + GLsizei vertexSize = sizeof(GLfloat) * 7; + + this->OpenGLHelper.vglVertexAttribPointerARB (colorAttrib, 4, GL_FLOAT, GL_FALSE, vertexSize, (const GLvoid*)0); + this->OpenGLHelper.vglEnableVertexAttribArrayARB (colorAttrib); + + this->OpenGLHelper.vglVertexAttribPointerARB (vertexAttrib, 3, GL_FLOAT, GL_FALSE, vertexSize, (const GLvoid*)(sizeof(GLfloat) * 4)); + this->OpenGLHelper.vglEnableVertexAttribArrayARB (vertexAttrib); + + this->OpenGLHelper.vglUniform1iARB (this->myLocations.UseTexture, 1); + this->OpenGLHelper.vglUniform1iARB (this->myLocations.BackgroundTexture, GL_TEXTURE0); + + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + this->OpenGLHelper.vglDisableVertexAttribArrayARB (0); + this->OpenGLHelper.vglBindBufferARB (GL_ARRAY_BUFFER_ARB, 0); + this->OpenGLHelper.vglDeleteBuffersARB (1, &vertexBuffer); + this->OpenGLHelper.vglBindVertexArrayARB (0); + this->OpenGLHelper.vglUseProgramObjectARB (0); + } +#else GLfloat texX = 1.F; // texture coordinate GLfloat texY = 1.F; // texture coordinate GLfloat x_offset = 0.5, y_offset = 0.5; @@ -251,9 +387,22 @@ void VTKViewer_OpenGLRenderer::Clear(void) glTexCoord2f( texX, aCoef * texY ); glVertex2f( x_offset + coeff, aCoef * y_offset + coeff ); glTexCoord2f( 0.F, aCoef * texY ); glVertex2f( -x_offset + coeff, aCoef * y_offset + coeff ); glEnd(); +#endif } } + // Restore settings. + { + glEnable( GL_ALPHA_TEST ); + glEnable( GL_DEPTH_TEST ); + glEnable( GL_LIGHTING ); + glEnable( GL_TEXTURE_1D ); + glEnable( GL_TEXTURE_2D ); + glEnable( GL_BLEND ); + + glShadeModel( oldShadeModel ); // color interpolation + } + glPopMatrix(); glMatrixMode( GL_PROJECTION ); glPopMatrix(); diff --git a/src/VTKViewer/VTKViewer_OpenGLRenderer.h b/src/VTKViewer/VTKViewer_OpenGLRenderer.h index e6b662614..81ec8a98b 100644 --- a/src/VTKViewer/VTKViewer_OpenGLRenderer.h +++ b/src/VTKViewer/VTKViewer_OpenGLRenderer.h @@ -25,6 +25,7 @@ #include "VTKViewer.h" #include "vtkOpenGLRenderer.h" +#include "VTKViewer_OpenGLHelper.h" class VTKVIEWER_EXPORT VTKViewer_OpenGLRenderer : public vtkOpenGLRenderer { @@ -55,6 +56,31 @@ protected: private: int GradientType; +#ifdef VTK_OPENGL2 + VTKViewer_OpenGLHelper OpenGLHelper; + GLhandleARB BackgroundProgram; + GLhandleARB BackgroundVertexShader; + GLhandleARB BackgroundFragmentShader; + GLuint VertexArrayObject; + + struct Locations + { + static const GLint INVALID_LOCATION = -1; + + GLint UseTexture; + GLint BackgroundTexture; + + Locations() + : UseTexture (INVALID_LOCATION), + BackgroundTexture (INVALID_LOCATION) + { + // + } + + } myLocations; +#endif + + private: VTKViewer_OpenGLRenderer(const VTKViewer_OpenGLRenderer&); // Not implemented. void operator=(const VTKViewer_OpenGLRenderer&); // Not implemented. diff --git a/src/VTKViewer/VTKViewer_PolyDataMapper.cxx b/src/VTKViewer/VTKViewer_PolyDataMapper.cxx index 5b3178269..f61d2af21 100644 --- a/src/VTKViewer/VTKViewer_PolyDataMapper.cxx +++ b/src/VTKViewer/VTKViewer_PolyDataMapper.cxx @@ -65,111 +65,8 @@ vtkStandardNewMacro(VTKViewer_PolyDataMapper); #define VTK_PDPSM_NORMAL_TYPE_DOUBLE 0x0020 #define VTK_PDPSM_OPAQUE_COLORS 0x0040 -#ifndef APIENTRY -#define APIENTRY -#endif -#ifndef APIENTRYP -#define APIENTRYP APIENTRY * -#endif - -#ifndef GL_ARB_shader_objects -typedef char GLcharARB; -#endif - -#ifndef GL_VERTEX_PROGRAM_POINT_SIZE_ARB -#define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642 -#endif - -#ifndef GL_VERTEX_SHADER_ARB -#define GL_VERTEX_SHADER_ARB 0x8B31 -#endif - -#ifndef GL_FRAGMENT_SHADER_ARB -#define GL_FRAGMENT_SHADER_ARB 0x8B30 -#endif - -#ifndef GL_ARB_point_sprite -#define GL_POINT_SPRITE_ARB 0x8861 -#define GL_COORD_REPLACE_ARB 0x8862 -#endif - -#ifndef GL_ARB_vertex_buffer_object -typedef ptrdiff_t GLsizeiptrARB; - -#define GL_ARRAY_BUFFER_ARB 0x8892 -#define GL_STATIC_DRAW_ARB 0x88E4 -#endif -typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length); -typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType); -typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer); -typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers); -typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers); -typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage); -typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj); -typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void); -typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); -typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj); -typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj); -typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name); -typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); -typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); -typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index); - -#ifdef VTK_OPENGL2 -typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj); -typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj); -typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB program); -typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) ( GLhandleARB program, const GLcharARB *name ); -typedef void (APIENTRYP PFNGLGETSHADERIVARBPROC) (GLuint shader, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLuint program, GLenum pname, GLint *params); -typedef void (APIENTRYP PFNGLGETSHADERINFOLOGARBPROC) (GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog); -typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); -typedef void (APIENTRYP PFNGLGENVERTEXARRAYSARBPROC) (GLsizei n, GLuint *arrays); -typedef void (APIENTRYP PFNGLBINDVERTEXARRAYARBPROC) (GLuint array); -typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0); -#endif - typedef GLfloat TBall; - -static PFNGLSHADERSOURCEARBPROC vglShaderSourceARB = NULL; -static PFNGLCREATESHADEROBJECTARBPROC vglCreateShaderObjectARB = NULL; -static PFNGLCOMPILESHADERARBPROC vglCompileShaderARB = NULL; -static PFNGLCREATEPROGRAMOBJECTARBPROC vglCreateProgramObjectARB = NULL; -static PFNGLATTACHOBJECTARBPROC vglAttachObjectARB = NULL; -static PFNGLLINKPROGRAMARBPROC vglLinkProgramARB = NULL; -static PFNGLUSEPROGRAMOBJECTARBPROC vglUseProgramObjectARB = NULL; - -static PFNGLGENBUFFERSARBPROC vglGenBuffersARB = NULL; -static PFNGLBINDBUFFERARBPROC vglBindBufferARB = NULL; -static PFNGLBUFFERDATAARBPROC vglBufferDataARB = NULL; -static PFNGLDELETEBUFFERSARBPROC vglDeleteBuffersARB = NULL; -static PFNGLGETATTRIBLOCATIONARBPROC vglGetAttribLocationARB = NULL; -static PFNGLVERTEXATTRIBPOINTERARBPROC vglVertexAttribPointerARB = NULL; -static PFNGLENABLEVERTEXATTRIBARRAYARBPROC vglEnableVertexAttribArrayARB = NULL; -static PFNGLDISABLEVERTEXATTRIBARRAYARBPROC vglDisableVertexAttribArrayARB = NULL; - -#ifdef VTK_OPENGL2 -static PFNGLDETACHOBJECTARBPROC vglDetachObjectARB = NULL; -static PFNGLDELETEOBJECTARBPROC vglDeleteObjectARB = NULL; -static PFNGLVALIDATEPROGRAMARBPROC vglValidateProgramARB = NULL; -static PFNGLGETSHADERIVARBPROC vglGetShaderivARB = NULL; -static PFNGLGETPROGRAMIVARBPROC vglGetProgramivARB = NULL; -static PFNGLGETSHADERINFOLOGARBPROC vglGetShaderInfoLogARB = NULL; - -static PFNGLUNIFORMMATRIX4FVARBPROC vglUniformMatrix4fvARB = NULL; -static PFNGLGENVERTEXARRAYSARBPROC vglGenVertexArraysARB = NULL; -static PFNGLBINDVERTEXARRAYARBPROC vglBindVertexArrayARB = NULL; -static PFNGLUNIFORM1IARBPROC vglUniform1iARB = NULL; -static PFNGLGETUNIFORMLOCATIONARBPROC vglGetUniformLocationARB = NULL; -#endif - -#ifndef WIN32 -#define GL_GetProcAddress( x ) glXGetProcAddressARB( (const GLubyte*)x ) -#else -#define GL_GetProcAddress( x ) wglGetProcAddress( (const LPCSTR)x ) -#endif - #ifdef WIN32 #ifdef max #undef max @@ -180,145 +77,6 @@ static PFNGLGETUNIFORMLOCATIONARBPROC vglGetUniformLocationARB = NUL // texture id for balls drawing #define BallTextureId 0 -bool InitializeBufferExtensions() -{ - vglShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)GL_GetProcAddress( "glShaderSourceARB" ); - if( !vglShaderSourceARB ) - return false; - - vglCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)GL_GetProcAddress( "glCreateShaderObjectARB" ); - if( !vglCreateShaderObjectARB ) - return false; - - vglCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)GL_GetProcAddress( "glCompileShaderARB" ); - if( !vglCompileShaderARB ) - return false; - - vglCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)GL_GetProcAddress( "glCreateProgramObjectARB" ); - if( !vglCreateProgramObjectARB ) - return false; - - vglAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)GL_GetProcAddress( "glAttachObjectARB" ); - if( !vglAttachObjectARB ) - return false; - - vglLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)GL_GetProcAddress( "glLinkProgramARB" ); - if( !vglLinkProgramARB ) - return false; - - vglUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)GL_GetProcAddress( "glUseProgramObjectARB" ); - if( !vglUseProgramObjectARB ) - return false; - - vglGenBuffersARB = (PFNGLGENBUFFERSARBPROC)GL_GetProcAddress( "glGenBuffersARB" ); - if( !vglGenBuffersARB ) - return false; - - vglBindBufferARB = (PFNGLBINDBUFFERARBPROC)GL_GetProcAddress( "glBindBufferARB" ); - if( !vglBindBufferARB ) - return false; - - vglBufferDataARB = (PFNGLBUFFERDATAARBPROC)GL_GetProcAddress( "glBufferDataARB" ); - if( !vglBufferDataARB ) - return false; - - vglDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)GL_GetProcAddress( "glDeleteBuffersARB" ); - if( !vglDeleteBuffersARB ) - return false; - - vglGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC)GL_GetProcAddress( "glGetAttribLocation" ); - if( !vglGetAttribLocationARB ) - return false; - - vglVertexAttribPointerARB = (PFNGLVERTEXATTRIBPOINTERARBPROC)GL_GetProcAddress( "glVertexAttribPointer" ); - if( !vglVertexAttribPointerARB ) - return false; - - vglEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)GL_GetProcAddress( "glEnableVertexAttribArray" ); - if(!vglEnableVertexAttribArrayARB) - return false; - - vglDisableVertexAttribArrayARB = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)GL_GetProcAddress( "glDisableVertexAttribArray" ); - - if(!vglDisableVertexAttribArrayARB) - return false; - -#ifdef VTK_OPENGL2 - vglDetachObjectARB = (PFNGLDETACHOBJECTARBPROC)GL_GetProcAddress( "glDetachObjectARB" ); - if( !vglDetachObjectARB ) - return false; - - vglDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)GL_GetProcAddress( "glDeleteObjectARB" ); - if( !vglDeleteObjectARB ) - return false; - - vglValidateProgramARB = (PFNGLVALIDATEPROGRAMARBPROC)GL_GetProcAddress( "glValidateProgramARB" ); - if ( !vglValidateProgramARB ) - return false; - - vglGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)GL_GetProcAddress( "glGetUniformLocationARB" ); - if( !vglGetUniformLocationARB ) - return false; - - vglGetShaderivARB = (PFNGLGETSHADERIVPROC)GL_GetProcAddress( "glGetShaderiv" ); - if( !vglGetShaderivARB ) - return false; - - vglGetProgramivARB = (PFNGLGETPROGRAMIVPROC)GL_GetProcAddress( "glGetProgramiv" ); - if( !vglGetProgramivARB ) - return false; - - vglGetShaderInfoLogARB = (PFNGLGETSHADERINFOLOGPROC)GL_GetProcAddress( "glGetShaderInfoLog" ); - if( !vglGetShaderInfoLogARB ) - return false; - - vglUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC)GL_GetProcAddress( "glUniformMatrix4fv" ); - if( !vglUniformMatrix4fvARB ) - return false; - - vglGenVertexArraysARB = (PFNGLGENVERTEXARRAYSARBPROC)GL_GetProcAddress( "glGenVertexArrays" ); - if( !vglGenVertexArraysARB ) - return false; - - vglBindVertexArrayARB = (PFNGLBINDVERTEXARRAYARBPROC)GL_GetProcAddress( "glBindVertexArray" ); - if( !vglBindVertexArrayARB ) - return false; - - vglUniform1iARB = (PFNGLUNIFORM1IARBPROC)GL_GetProcAddress( "glUniform1i" ); - if( !vglUniform1iARB ) - return false; -#endif - - return true; -}; - -//----------------------------------------------------------------------------- -char* readFromFile( std::string fileName ) -{ - FILE* file = fopen( fileName.c_str(), "r" ); - - char* content = NULL; - int count = 0; - - if( file != NULL ) - { - fseek( file, 0, SEEK_END ); - count = ftell( file ); - rewind( file ); - - if( count > 0 ) - { - content = ( char* )malloc( sizeof( char ) * ( count + 1 ) ); - count = fread( content, sizeof( char ), count, file ); - content[ count ] = '\0'; - } - fclose( file ); - } - - return content; -} - -static bool IsBufferExtensionsInitialized = InitializeBufferExtensions(); //----------------------------------------------------------------------------- VTKViewer_PolyDataMapper::VTKViewer_PolyDataMapper() @@ -340,6 +98,8 @@ VTKViewer_PolyDataMapper::VTKViewer_PolyDataMapper() this->VertexShader = 0; this->FragmentShader = 0; #endif + + this->OpenGLHelper.Init(); } //----------------------------------------------------------------------------- @@ -349,11 +109,7 @@ VTKViewer_PolyDataMapper::~VTKViewer_PolyDataMapper() glDeleteTextures( 1, &PointSpriteTexture ); #ifdef VTK_OPENGL2 - vglDetachObjectARB( this->PointProgram, this->VertexShader ); - vglDetachObjectARB( this->PointProgram, this->FragmentShader ); - - vglDeleteObjectARB( this->VertexShader ); - vglDeleteObjectARB( this->FragmentShader ); + this->OpenGLHelper.DestroyShaderProgram( this->PointProgram, this->VertexShader, this->FragmentShader); #endif } @@ -361,109 +117,34 @@ VTKViewer_PolyDataMapper::~VTKViewer_PolyDataMapper() int VTKViewer_PolyDataMapper::InitShader() { #ifdef VTK_OPENGL2 - const GLubyte *version = glGetString(GL_VERSION); - MESSAGE(version); - // Create program. - this->PointProgram = vglCreateProgramObjectARB(); - if (this->PointProgram == 0) - { - MESSAGE("Can't create opengl program."); - return ES_Error; - } - - std::string fileName; - char* shaderContent; - GLint linked, compileStatus, validateStatus; - - // Create vertex shader. - fileName = std::string( getenv( "GUI_ROOT_DIR") ) + - "/share/salome/resources/gui/Vertex_Shader_ARB.glsl"; - - shaderContent = readFromFile( fileName ); - - this->VertexShader = vglCreateShaderObjectARB( GL_VERTEX_SHADER_ARB ); - vglShaderSourceARB( this->VertexShader, 1, (const GLcharARB**)&shaderContent, NULL ); - vglCompileShaderARB( this->VertexShader ); - - free( shaderContent ); - - vglGetShaderivARB( this->VertexShader, GL_COMPILE_STATUS, &compileStatus ); - if (compileStatus != GL_TRUE) - { - GLint size; - GLchar info[1024]; - - vglGetShaderInfoLogARB( this->VertexShader, 1024, &size, info ); - std::cout << info << std::endl; - - MESSAGE( "Can't compile vertex shader." ); - return ES_Error; - } - - // Create fragment shader. - fileName = std::string( getenv( "GUI_ROOT_DIR") ) + - "/share/salome/resources/gui/Fragment_Shader_ARB.glsl"; - - shaderContent = readFromFile( fileName ); - - this->FragmentShader = vglCreateShaderObjectARB( GL_FRAGMENT_SHADER_ARB ); - vglShaderSourceARB( this->FragmentShader, 1, (const GLcharARB**)&shaderContent, NULL ); - vglCompileShaderARB( this->FragmentShader ); - - free( shaderContent ); - - vglGetShaderivARB( this->FragmentShader, GL_COMPILE_STATUS, &compileStatus ); - if (compileStatus != GL_TRUE) - { - MESSAGE( "Can't compile fragment shader." ); - return ES_Error; - } - - // Attach shaders. - vglAttachObjectARB( this->PointProgram, this->VertexShader ); - vglAttachObjectARB( this->PointProgram, this->FragmentShader ); - vglLinkProgramARB( this->PointProgram ); - - vglGetProgramivARB( this->PointProgram, GL_LINK_STATUS, &linked ); - if (!linked) - { - MESSAGE("Can't link program."); - return ES_Error; - } - - vglValidateProgramARB( this->PointProgram ); - vglGetProgramivARB( this->PointProgram, GL_VALIDATE_STATUS, &validateStatus ); - - if (validateStatus != GL_TRUE) - { - MESSAGE( "Shader program is not validate." ); - return ES_Error; - } + std::string filePath = std::string( getenv( "GUI_ROOT_DIR") ) + "/share/salome/resources/gui/Point"; + if( !this->OpenGLHelper.CreateShaderProgram(filePath, this->PointProgram, this->VertexShader, this->FragmentShader) ) + return false; // Get uniform locations. - vglUseProgramObjectARB( this->PointProgram ); + this->OpenGLHelper.vglUseProgramObjectARB( this->PointProgram ); - this->myLocations.ModelViewProjection = vglGetUniformLocationARB( this->PointProgram, "uModelViewProjectionMatrix" ); - this->myLocations.GeneralPointSize = vglGetUniformLocationARB( this->PointProgram, "uGeneralPointSize" ); - this->myLocations.PointSprite = vglGetUniformLocationARB( this->PointProgram, "uPointSprite" ); + this->myLocations.ModelViewProjection = this->OpenGLHelper.vglGetUniformLocationARB( this->PointProgram, "uModelViewProjectionMatrix" ); + this->myLocations.GeneralPointSize = this->OpenGLHelper.vglGetUniformLocationARB( this->PointProgram, "uGeneralPointSize" ); + this->myLocations.PointSprite = this->OpenGLHelper.vglGetUniformLocationARB( this->PointProgram, "uPointSprite" ); - vglUseProgramObjectARB( 0 ); + this->OpenGLHelper.vglUseProgramObjectARB( 0 ); - vglGenVertexArraysARB(1, &this->VertexArrayObject); + this->OpenGLHelper.vglGenVertexArraysARB(1, &this->VertexArrayObject); #else std::string fileName = std::string( getenv( "GUI_ROOT_DIR") ) + "/share/salome/resources/gui/Vertex_Program_ARB.txt"; char* shader = readFromFile( fileName ); - GLhandleARB VertexShader = vglCreateShaderObjectARB( GL_VERTEX_SHADER_ARB ); - vglShaderSourceARB( VertexShader, 1, (const GLcharARB**)&shader, NULL ); - vglCompileShaderARB( VertexShader ); + GLhandleARB VertexShader = this->OpenGLHelper.vglCreateShaderObjectARB( GL_VERTEX_SHADER_ARB ); + this->OpenGLHelper.vglShaderSourceARB( VertexShader, 1, (const GLcharARB**)&shader, NULL ); + this->OpenGLHelper.vglCompileShaderARB( VertexShader ); - this->PointProgram = vglCreateProgramObjectARB(); - vglAttachObjectARB( this->PointProgram, VertexShader ); + this->PointProgram = this->OpenGLHelper.vglCreateProgramObjectARB(); + this->OpenGLHelper.vglAttachObjectARB( this->PointProgram, VertexShader ); - vglLinkProgramARB( this->PointProgram ); + this->OpenGLHelper.vglLinkProgramARB( this->PointProgram ); free( shader ); #endif @@ -666,8 +347,8 @@ int VTKViewer_PolyDataMapper::InitExtensions() const char* ext = s.c_str(); #else const char* ext = (const char*)glGetString( GL_EXTENSIONS ); -#endif - if( !IsBufferExtensionsInitialized || !ext || +#endif + if( !this->OpenGLHelper.IsInitialized() || !ext || strstr( ext, "GL_ARB_point_sprite" ) == NULL || strstr( ext, "GL_ARB_vertex_buffer_object" ) == NULL || strstr( ext, "GL_ARB_shader_objects") == NULL ) @@ -745,7 +426,7 @@ void VTKViewer_PolyDataMapper::InitTextures() #ifdef VTK_OPENGL2 // Set sampler. - vglUniform1iARB( this->myLocations.PointSprite, GL_TEXTURE0 ); + this->OpenGLHelper.vglUniform1iARB( this->myLocations.PointSprite, GL_TEXTURE0 ); #endif } @@ -800,7 +481,7 @@ void VTKViewer_PolyDataMapper::RenderPiece( vtkRenderer* ren, vtkActor* act ) ren->GetRenderWindow()->MakeCurrent(); - vglUseProgramObjectARB( this->PointProgram ); + this->OpenGLHelper.vglUseProgramObjectARB( this->PointProgram ); #ifndef VTK_OPENGL2 // @@ -881,7 +562,7 @@ void VTKViewer_PolyDataMapper::RenderPiece( vtkRenderer* ren, vtkActor* act ) // this->RenderEdges(ren,act); //this->RenderPieceFinish(ren, act); #endif - vglUseProgramObjectARB( 0 ); + this->OpenGLHelper.vglUseProgramObjectARB( 0 ); this->CleanupPointSprites(); glBindTexture( GL_TEXTURE_2D, 0 ); } @@ -1101,18 +782,6 @@ void VTKViewer_PolyDataMapper::RenderPieceDraw( vtkRenderer* ren, vtkActor* act #include #include #include -#include -void SetUniformMatrix (const GLint theLocation, - vtkMatrix4x4* theMatrix) -{ - float data[16]; - for (int i = 0; i < 16; ++i) - { - data[i] = theMatrix->Element[i / 4][i % 4]; - } - - vglUniformMatrix4fvARB(theLocation, 1, GL_FALSE, data); -} #endif void VTKViewer_PolyDataMapper::InternalDraw(vtkRenderer* ren, vtkActor* act ) { @@ -1193,7 +862,7 @@ void VTKViewer_PolyDataMapper::InternalDraw(vtkRenderer* ren, vtkActor* act ) { if( this->ExtensionsInitialized == ES_Ok ) { #ifdef VTK_OPENGL2 - vglUseProgramObjectARB( this->PointProgram ); + this->OpenGLHelper.vglUseProgramObjectARB( this->PointProgram ); vtkOpenGLCamera *cam = (vtkOpenGLCamera *)(ren->GetActiveCamera()); vtkMatrix4x4 *wcdc; @@ -1207,83 +876,84 @@ void VTKViewer_PolyDataMapper::InternalDraw(vtkRenderer* ren, vtkActor* act ) { vtkMatrix3x3 *anorms; ((vtkOpenGLActor *)act)->GetKeyMatrices( mcwc, anorms ); vtkMatrix4x4::Multiply4x4( mcwc, wcdc, this->TempMatrix4 ); - SetUniformMatrix( this->myLocations.ModelViewProjection, this->TempMatrix4 ); + + this->OpenGLHelper.SetUniformMatrix( this->myLocations.ModelViewProjection, this->TempMatrix4 ); } else { - SetUniformMatrix( this->myLocations.ModelViewProjection, wcdc ); + this->OpenGLHelper.SetUniformMatrix( this->myLocations.ModelViewProjection, wcdc ); } - vglUniform1iARB( this->myLocations.GeneralPointSize, std::max( aSize[0], aSize[1] ) ); + this->OpenGLHelper.vglUniform1iARB( this->myLocations.GeneralPointSize, std::max( aSize[0], aSize[1] ) ); GLuint aBufferObjectID, aDiamsID = 0; - vglBindVertexArrayARB( this->VertexArrayObject ); - vglGenBuffersARB( 1, &aBufferObjectID ); - vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); + this->OpenGLHelper.vglBindVertexArrayARB( this->VertexArrayObject ); + this->OpenGLHelper.vglGenBuffersARB( 1, &aBufferObjectID ); + this->OpenGLHelper.vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); int anArrayObjectSize = sizeof( VTK::TVertex ) * aTotalConnectivitySize; - vglBufferDataARB( GL_ARRAY_BUFFER_ARB, anArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB ); + this->OpenGLHelper.vglBufferDataARB( GL_ARRAY_BUFFER_ARB, anArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB ); delete [] aVertexArr; - GLint colorAttrib = vglGetAttribLocationARB( this->PointProgram, "Color" ); - GLint vertexAttrib = vglGetAttribLocationARB( this->PointProgram, "Vertex" ); - GLint diamAttrib = vglGetAttribLocationARB( this->PointProgram, "Diameter" ); + GLint colorAttrib = this->OpenGLHelper.vglGetAttribLocationARB( this->PointProgram, "Color" ); + GLint vertexAttrib = this->OpenGLHelper.vglGetAttribLocationARB( this->PointProgram, "Vertex" ); + GLint diamAttrib = this->OpenGLHelper.vglGetAttribLocationARB( this->PointProgram, "Diameter" ); GLsizei vertexSize = sizeof(VTK::TVertex); - vglVertexAttribPointerARB( colorAttrib, 4, GL_FLOAT, GL_FALSE, vertexSize, (const GLvoid*)0 ); - vglEnableVertexAttribArrayARB( colorAttrib ); + this->OpenGLHelper.vglVertexAttribPointerARB( colorAttrib, 4, GL_FLOAT, GL_FALSE, vertexSize, (const GLvoid*)0 ); + this->OpenGLHelper.vglEnableVertexAttribArrayARB( colorAttrib ); - vglVertexAttribPointerARB( vertexAttrib, 3, GL_FLOAT, GL_FALSE, vertexSize, (const GLvoid*)(sizeof(GLfloat) * 4) ); - vglEnableVertexAttribArrayARB( vertexAttrib ); + this->OpenGLHelper.vglVertexAttribPointerARB( vertexAttrib, 3, GL_FLOAT, GL_FALSE, vertexSize, (const GLvoid*)(sizeof(GLfloat) * 4) ); + this->OpenGLHelper.vglEnableVertexAttribArrayARB( vertexAttrib ); if(this->BallEnabled) { // Don't use uniform variable. - vglUniform1iARB( this->myLocations.GeneralPointSize, -1 ); - vglGenBuffersARB( 1, &aDiamsID); - vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aDiamsID); + this->OpenGLHelper.vglUniform1iARB( this->myLocations.GeneralPointSize, -1 ); + this->OpenGLHelper.vglGenBuffersARB( 1, &aDiamsID); + this->OpenGLHelper.vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aDiamsID); int aDiamsSize = sizeof(TBall)*aNbCells; - vglBufferDataARB( GL_ARRAY_BUFFER_ARB, aDiamsSize, aBallArray, GL_STATIC_DRAW_ARB); + this->OpenGLHelper.vglBufferDataARB( GL_ARRAY_BUFFER_ARB, aDiamsSize, aBallArray, GL_STATIC_DRAW_ARB); delete [] aBallArray; - vglVertexAttribPointerARB( diamAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0 ); - vglEnableVertexAttribArrayARB( diamAttrib ); + this->OpenGLHelper.vglVertexAttribPointerARB( diamAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0 ); + this->OpenGLHelper.vglEnableVertexAttribArrayARB( diamAttrib ); } glDrawArrays( GL_POINTS, 0, aTotalConnectivitySize ); if( this->BallEnabled ) { - vglDisableVertexAttribArrayARB( diamAttrib ); - vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); - vglDeleteBuffersARB( 1, &aDiamsID ); + this->OpenGLHelper.vglDisableVertexAttribArrayARB( diamAttrib ); + this->OpenGLHelper.vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); + this->OpenGLHelper.vglDeleteBuffersARB( 1, &aDiamsID ); } - vglDisableVertexAttribArrayARB( colorAttrib ); - vglDisableVertexAttribArrayARB( vertexAttrib ); - vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); - vglDeleteBuffersARB( 1, &aBufferObjectID ); - vglBindVertexArrayARB( 0 ); + this->OpenGLHelper.vglDisableVertexAttribArrayARB( colorAttrib ); + this->OpenGLHelper.vglDisableVertexAttribArrayARB( vertexAttrib ); + this->OpenGLHelper.vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); + this->OpenGLHelper.vglDeleteBuffersARB( 1, &aBufferObjectID ); + this->OpenGLHelper.vglBindVertexArrayARB( 0 ); - vglUseProgramObjectARB( 0 ); + this->OpenGLHelper.vglUseProgramObjectARB( 0 ); #else GLuint aBufferObjectID, aDiamsID = 0; GLint attribute_diams = -1; - vglGenBuffersARB( 1, &aBufferObjectID ); - vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); + this->OpenGLHelper.vglGenBuffersARB( 1, &aBufferObjectID ); + this->OpenGLHelper.vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); int anArrayObjectSize = sizeof( VTK::TVertex ) * aTotalConnectivitySize; - vglBufferDataARB( GL_ARRAY_BUFFER_ARB, anArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB ); + this->OpenGLHelper.vglBufferDataARB( GL_ARRAY_BUFFER_ARB, anArrayObjectSize, aVertexArr, GL_STATIC_DRAW_ARB ); delete [] aVertexArr; - vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); - vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); + this->OpenGLHelper.vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); + this->OpenGLHelper.vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aBufferObjectID ); glColorPointer( 4, GL_FLOAT, sizeof(VTK::TVertex), (void*)0 ); glVertexPointer( 3, GL_FLOAT, sizeof(VTK::TVertex), (void*)(4*sizeof(GLfloat)) ); @@ -1292,20 +962,20 @@ void VTKViewer_PolyDataMapper::InternalDraw(vtkRenderer* ren, vtkActor* act ) { glEnableClientState( GL_COLOR_ARRAY ); if(this->BallEnabled) { - vglGenBuffersARB( 2, &aDiamsID); - vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aDiamsID); + this->OpenGLHelper.vglGenBuffersARB( 1, &aDiamsID); + this->OpenGLHelper.vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aDiamsID); int aDiamsSize = sizeof(TBall)*aNbCells; - vglBufferDataARB( GL_ARRAY_BUFFER_ARB, aDiamsSize, aBallArray, GL_STATIC_DRAW_ARB); + this->OpenGLHelper.vglBufferDataARB( GL_ARRAY_BUFFER_ARB, aDiamsSize, aBallArray, GL_STATIC_DRAW_ARB); delete [] aBallArray; - vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); - vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aDiamsID ); + this->OpenGLHelper.vglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); + this->OpenGLHelper.vglBindBufferARB( GL_ARRAY_BUFFER_ARB, aDiamsID ); attribute_diams = vglGetAttribLocationARB(this->PointProgram, "diameter"); - vglEnableVertexAttribArrayARB(attribute_diams); - vglBindBufferARB(GL_ARRAY_BUFFER_ARB, aDiamsID); - vglVertexAttribPointerARB( + this->OpenGLHelper.vglEnableVertexAttribArrayARB(attribute_diams); + this->OpenGLHelper.vglBindBufferARB(GL_ARRAY_BUFFER_ARB, aDiamsID); + this->OpenGLHelper.vglVertexAttribPointerARB( attribute_diams, // attribute 1, // number of elements per vertex, here (diameter) GL_FLOAT, // the type of each element @@ -1319,11 +989,11 @@ void VTKViewer_PolyDataMapper::InternalDraw(vtkRenderer* ren, vtkActor* act ) { glDisableClientState( GL_COLOR_ARRAY ); glDisableClientState( GL_VERTEX_ARRAY ); - vglDeleteBuffersARB( 1, &aBufferObjectID ); + this->OpenGLHelper.vglDeleteBuffersARB( 1, &aBufferObjectID ); if(this->BallEnabled) { - vglDisableVertexAttribArrayARB(attribute_diams); - vglDeleteBuffersARB( 2, &aDiamsID ); + this->OpenGLHelper.vglDisableVertexAttribArrayARB(attribute_diams); + this->OpenGLHelper.vglDeleteBuffersARB( 1, &aDiamsID ); } #endif diff --git a/src/VTKViewer/VTKViewer_PolyDataMapper.h b/src/VTKViewer/VTKViewer_PolyDataMapper.h index 8f8349520..0413ae665 100644 --- a/src/VTKViewer/VTKViewer_PolyDataMapper.h +++ b/src/VTKViewer/VTKViewer_PolyDataMapper.h @@ -43,10 +43,7 @@ class vtkImageData; #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper #endif -#ifndef GL_ARB_shader_objects -typedef GLuint GLhandleARB; -#endif - +#include "VTKViewer_OpenGLHelper.h" //---------------------------------------------------------------------------- //! OpenGL Point Sprites PolyData Mapper. @@ -132,6 +129,7 @@ private: vtkSmartPointer ImageData; + VTKViewer_OpenGLHelper OpenGLHelper; GLhandleARB PointProgram; #ifdef VTK_OPENGL2 GLhandleARB VertexShader; diff --git a/src/VTKViewer/resources/Background.fs.glsl b/src/VTKViewer/resources/Background.fs.glsl new file mode 100644 index 000000000..2c68fe90a --- /dev/null +++ b/src/VTKViewer/resources/Background.fs.glsl @@ -0,0 +1,21 @@ +#version 130 + +#if (__VERSION__ >= 130) + out vec4 outColor; + #define Texture2D texture +#else + #define outColor gl_FragColor + #define Texture2D texture2D +#endif + +uniform int uUseTexture; +uniform sampler2D uBackgroundTexture; + +in vec4 VSColor; +void main() +{ + if (uUseTexture == 1) + outColor = Texture2D(uBackgroundTexture, VSColor.xy); + else + outColor = VSColor; +} diff --git a/src/VTKViewer/resources/Background.vs.glsl b/src/VTKViewer/resources/Background.vs.glsl new file mode 100644 index 000000000..da9d1c700 --- /dev/null +++ b/src/VTKViewer/resources/Background.vs.glsl @@ -0,0 +1,15 @@ +#version 330 core +#if (__VERSION__ >= 130) + in vec4 Color; + in vec3 Vertex; +#else + #define Vertex gl_Vertex + #define Color gl_Color; +#endif + +out vec4 VSColor; +void main() +{ + gl_Position = vec4 (Vertex.xyz, 1.0); + VSColor = Color; +} diff --git a/src/VTKViewer/resources/Fragment_Shader_ARB.glsl b/src/VTKViewer/resources/Fragment_Shader_ARB.glsl deleted file mode 100644 index 1c7cbb020..000000000 --- a/src/VTKViewer/resources/Fragment_Shader_ARB.glsl +++ /dev/null @@ -1,22 +0,0 @@ -#version 130 - -#if (__VERSION__ >= 130) - out vec4 outColor; - #define Texture2D texture -#else - #define outColor gl_FragColor - #define Texture2D texture2D -#endif - -uniform sampler2D uPointSprite; - -in vec4 VSColor; -void main() -{ - outColor = VSColor; - vec4 testColor = Texture2D(uPointSprite, gl_PointCoord); - if (testColor.r > 0.1) - outColor = testColor * outColor; - else - discard; -} diff --git a/src/VTKViewer/resources/Point.fs.glsl b/src/VTKViewer/resources/Point.fs.glsl new file mode 100644 index 000000000..1c7cbb020 --- /dev/null +++ b/src/VTKViewer/resources/Point.fs.glsl @@ -0,0 +1,22 @@ +#version 130 + +#if (__VERSION__ >= 130) + out vec4 outColor; + #define Texture2D texture +#else + #define outColor gl_FragColor + #define Texture2D texture2D +#endif + +uniform sampler2D uPointSprite; + +in vec4 VSColor; +void main() +{ + outColor = VSColor; + vec4 testColor = Texture2D(uPointSprite, gl_PointCoord); + if (testColor.r > 0.1) + outColor = testColor * outColor; + else + discard; +} diff --git a/src/VTKViewer/resources/Point.vs.glsl b/src/VTKViewer/resources/Point.vs.glsl new file mode 100644 index 000000000..c73f7eb18 --- /dev/null +++ b/src/VTKViewer/resources/Point.vs.glsl @@ -0,0 +1,26 @@ +#version 130 +#if (__VERSION__ >= 130) + in vec4 Color; + in vec3 Vertex; + in float Diameter; +#else + #define Vertex gl_Vertex + #define Color gl_Color; + attribute float Diameter; +#endif + +uniform mat4 uModelViewProjectionMatrix; +uniform int uGeneralPointSize; + +out vec4 VSColor; +void main() +{ + gl_Position = uModelViewProjectionMatrix * vec4 (Vertex.xyz, 1.0); + + if (uGeneralPointSize == -1) + gl_PointSize = Diameter; + else + gl_PointSize = uGeneralPointSize; + + VSColor = Color; +} diff --git a/src/VTKViewer/resources/Vertex_Shader_ARB.glsl b/src/VTKViewer/resources/Vertex_Shader_ARB.glsl deleted file mode 100644 index 6982a6453..000000000 --- a/src/VTKViewer/resources/Vertex_Shader_ARB.glsl +++ /dev/null @@ -1,26 +0,0 @@ -#version 330 core -#if (__VERSION__ >= 130) - in vec4 Color; - in vec3 Vertex; - in float Diameter; -#else - #define Vertex gl_Vertex - #define Color gl_Color; - attribute float Diameter; -#endif - -uniform mat4 uModelViewProjectionMatrix; -uniform int uGeneralPointSize; - -out vec4 VSColor; -void main() -{ - gl_Position = uModelViewProjectionMatrix * vec4 (Vertex.xyz, 1.0); - - if (uGeneralPointSize == -1) - gl_PointSize = Diameter; - else - gl_PointSize = uGeneralPointSize; - - VSColor = Color; -}