Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VTKViewer_OpenGLHelper.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef VTKVIEWER_OPENGLHELPER_H
21 #define VTKVIEWER_OPENGLHELPER_H
22 
23 #include <vtkObject.h>
24 #include <vtkMatrix4x4.h>
25 #include "VTKViewer.h"
26 
27 #ifdef WIN32
28 #include <windows.h>
29 #endif
30 
31 #include <GL/gl.h>
32 
33 
34 #ifndef GL_ARB_shader_objects
35 typedef GLuint GLhandleARB;
36 #endif
37 
38 #ifndef APIENTRY
39 #define APIENTRY
40 #endif
41 #ifndef APIENTRYP
42 #define APIENTRYP APIENTRY *
43 #endif
44 
45 #ifndef GL_ARB_shader_objects
46 typedef char GLcharARB;
47 #endif
48 
49 #ifndef GL_VERTEX_PROGRAM_POINT_SIZE_ARB
50 #define GL_VERTEX_PROGRAM_POINT_SIZE_ARB 0x8642
51 #endif
52 
53 #ifndef GL_VERTEX_SHADER_ARB
54 #define GL_VERTEX_SHADER_ARB 0x8B31
55 #endif
56 
57 #ifndef GL_FRAGMENT_SHADER_ARB
58 #define GL_FRAGMENT_SHADER_ARB 0x8B30
59 #endif
60 
61 #ifndef GL_ARB_point_sprite
62 #define GL_POINT_SPRITE_ARB 0x8861
63 #define GL_COORD_REPLACE_ARB 0x8862
64 #endif
65 
66 #ifndef GL_ARB_vertex_buffer_object
67 typedef ptrdiff_t GLsizeiptrARB;
68 
69 #define GL_ARRAY_BUFFER_ARB 0x8892
70 #define GL_STATIC_DRAW_ARB 0x88E4
71 #endif
72 
73 
74 namespace GUI_OPENGL {
75 char* readFromFile( std::string fileName );
76 }
77 
79 {
80 public:
83 
84  void Init();
85 
86  bool IsInitialized() const { return mIsInitialized; }
87 
88 public:
89  bool CreateShaderProgram (const std::string& theFilePath,
90  GLhandleARB& theProgram,
91  GLhandleARB& theVertexShader,
92  GLhandleARB& theFragmentShader) const;
93 
94  void DestroyShaderProgram (GLhandleARB theProgram,
95  GLhandleARB theVertexShader,
96  GLhandleARB theFragmentShader) const;
97 #ifdef VTK_OPENGL2
98  void SetUniformMatrix (const GLint theLocation,
99  const vtkMatrix4x4* theMatrix) const;
100 #endif
101 
102 protected:
103  typedef void (APIENTRYP PFNGLSHADERSOURCEARBPROC) (GLhandleARB shaderObj, GLsizei count, const GLcharARB* *string, const GLint *length);
104  typedef GLhandleARB (APIENTRYP PFNGLCREATESHADEROBJECTARBPROC) (GLenum shaderType);
105  typedef void (APIENTRYP PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
106  typedef void (APIENTRYP PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
107  typedef void (APIENTRYP PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
108  typedef void (APIENTRYP PFNGLBUFFERDATAARBPROC) (GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage);
109  typedef void (APIENTRYP PFNGLCOMPILESHADERARBPROC) (GLhandleARB shaderObj);
110  typedef GLhandleARB (APIENTRYP PFNGLCREATEPROGRAMOBJECTARBPROC) (void);
111  typedef void (APIENTRYP PFNGLATTACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj);
112  typedef void (APIENTRYP PFNGLLINKPROGRAMARBPROC) (GLhandleARB programObj);
113  typedef void (APIENTRYP PFNGLUSEPROGRAMOBJECTARBPROC) (GLhandleARB programObj);
114  typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONARBPROC) (GLhandleARB programObj, const GLcharARB *name);
115  typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERARBPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
116  typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYARBPROC) (GLuint index);
117  typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) (GLuint index);
118 
119 #ifdef VTK_OPENGL2
120  typedef void (APIENTRYP PFNGLDETACHOBJECTARBPROC) (GLhandleARB containerObj, GLhandleARB obj);
121  typedef void (APIENTRYP PFNGLDELETEOBJECTARBPROC) (GLhandleARB obj);
122  typedef void (APIENTRYP PFNGLVALIDATEPROGRAMARBPROC) (GLhandleARB program);
123  typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONARBPROC) (GLhandleARB program, const GLcharARB *name );
124  typedef void (APIENTRYP PFNGLGETSHADERIVARBPROC) (GLuint shader, GLenum pname, GLint *params);
125  typedef void (APIENTRYP PFNGLGETPROGRAMIVARBPROC) (GLuint program, GLenum pname, GLint *params);
126  typedef void (APIENTRYP PFNGLGETSHADERINFOLOGARBPROC) (GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog);
127  typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVARBPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
128  typedef void (APIENTRYP PFNGLGENVERTEXARRAYSARBPROC) (GLsizei n, GLuint *arrays);
129  typedef void (APIENTRYP PFNGLBINDVERTEXARRAYARBPROC) (GLuint array);
130  typedef void (APIENTRYP PFNGLUNIFORM1IARBPROC) (GLint location, GLint v0);
131 #endif
132 
133 public:
134  PFNGLSHADERSOURCEARBPROC vglShaderSourceARB;
135  PFNGLCREATESHADEROBJECTARBPROC vglCreateShaderObjectARB;
136  PFNGLCOMPILESHADERARBPROC vglCompileShaderARB;
137  PFNGLCREATEPROGRAMOBJECTARBPROC vglCreateProgramObjectARB;
138  PFNGLATTACHOBJECTARBPROC vglAttachObjectARB;
139  PFNGLLINKPROGRAMARBPROC vglLinkProgramARB;
140  PFNGLUSEPROGRAMOBJECTARBPROC vglUseProgramObjectARB;
141 
142  PFNGLGENBUFFERSARBPROC vglGenBuffersARB;
143  PFNGLBINDBUFFERARBPROC vglBindBufferARB;
144  PFNGLBUFFERDATAARBPROC vglBufferDataARB;
145  PFNGLDELETEBUFFERSARBPROC vglDeleteBuffersARB;
146  PFNGLGETATTRIBLOCATIONARBPROC vglGetAttribLocationARB;
147  PFNGLVERTEXATTRIBPOINTERARBPROC vglVertexAttribPointerARB;
148  PFNGLENABLEVERTEXATTRIBARRAYARBPROC vglEnableVertexAttribArrayARB;
149  PFNGLDISABLEVERTEXATTRIBARRAYARBPROC vglDisableVertexAttribArrayARB;
150 
151 #ifdef VTK_OPENGL2
152  PFNGLDETACHOBJECTARBPROC vglDetachObjectARB;
153  PFNGLDELETEOBJECTARBPROC vglDeleteObjectARB;
154  PFNGLVALIDATEPROGRAMARBPROC vglValidateProgramARB;
155  PFNGLGETSHADERIVARBPROC vglGetShaderivARB;
156  PFNGLGETPROGRAMIVARBPROC vglGetProgramivARB;
157  PFNGLGETSHADERINFOLOGARBPROC vglGetShaderInfoLogARB;
158 
159  PFNGLUNIFORMMATRIX4FVARBPROC vglUniformMatrix4fvARB;
160  PFNGLGENVERTEXARRAYSARBPROC vglGenVertexArraysARB;
161  PFNGLBINDVERTEXARRAYARBPROC vglBindVertexArrayARB;
162  PFNGLUNIFORM1IARBPROC vglUniform1iARB;
163  PFNGLGETUNIFORMLOCATIONARBPROC vglGetUniformLocationARB;
164 #endif
165 
166 protected:
168 };
169 
170 #endif