gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
OpenGLUtilities.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2017, Dr Franck P. Vidal (franck.p.vidal@fpvidal.net),
4 http://www.fpvidal.net/
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16 
17 3. Neither the name of the Bangor University nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 */
33 
34 
35 #ifndef __OpenGLUtilities_h
36 #define __OpenGLUtilities_h
37 
38 
67 //******************************************************************************
68 // Include
69 //******************************************************************************
70 #ifndef __gVirtualXRayConfig_h
72 #endif
73 
74 #include <vector>
75 
76 #ifndef __Matrix4x4_h
77 #include "gVirtualXRay/Matrix4x4.h"
78 #endif
79 
80 #ifndef __Types_h
81 #include "gVirtualXRay/Types.h"
82 #endif
83 
84 #ifndef __VBO_h
85 #include "gVirtualXRay/VBO.h"
86 #endif
87 
88 #ifndef __OpenGL2VBO_h
90 #endif
91 
92 #ifndef __OpenGL3VBO_h
94 #endif
95 
96 
97 //******************************************************************************
98 // namespace
99 //******************************************************************************
100 namespace gVirtualXRay {
101 
102  class OpenGL2VBO;
103  class OpenGL3VBO;
104 
105 
106 //------------------------------------------------------------------------------
108 //------------------------------------------------------------------------------
109 void initialiseGLAD(const std::string& anAPI);
110 
111 
112 //------------------------------------------------------------------------------
114 //------------------------------------------------------------------------------
115 void initializeGLAD(const std::string& anAPI);
116 
117 
118 //------------------------------------------------------------------------------
120 //------------------------------------------------------------------------------
121 void initialiseGLEW();
122 
123 
124 //------------------------------------------------------------------------------
126 //------------------------------------------------------------------------------
127 void initializeGLEW();
128 
129 
130 //------------------------------------------------------------------------------
132 
137 //------------------------------------------------------------------------------
138 void checkOpenGLErrorStatus(const char* aFileName,
139  const char* aFunctionName,
140  int aLineNumber);
141 
142 
143 //------------------------------------------------------------------------------
145 
150 //------------------------------------------------------------------------------
151 void checkFBOErrorStatus(const char* aFileName,
152  const char* aFunctionName,
153  int aLineNumber);
154 
155 
156 //------------------------------------------------------------------------------
158 //------------------------------------------------------------------------------
159 void pushProjectionMatrix();
160 
161 
162 //------------------------------------------------------------------------------
164 //------------------------------------------------------------------------------
165 void pushModelViewMatrix();
166 
167 
168 //------------------------------------------------------------------------------
170 //------------------------------------------------------------------------------
171 void pushFBO();
172 
173 
174 //------------------------------------------------------------------------------
176 //------------------------------------------------------------------------------
177 void pushTexture1D();
178 
179 
180 //------------------------------------------------------------------------------
182 //------------------------------------------------------------------------------
183 void pushTexture2D();
184 
185 
186 //------------------------------------------------------------------------------
188 //------------------------------------------------------------------------------
189 void pushTextureRectangle();
190 
191 
192 //------------------------------------------------------------------------------
194 //------------------------------------------------------------------------------
195 void pushTexture3D();
196 
197 
198 //------------------------------------------------------------------------------
200 
203 //------------------------------------------------------------------------------
204 void pushEnableDisableState(int aParameter);
205 
206 
207 //------------------------------------------------------------------------------
209 //------------------------------------------------------------------------------
210 void pushShaderProgram();
211 
212 
213 //------------------------------------------------------------------------------
216 //------------------------------------------------------------------------------
217 void popProjectionMatrix();
218 
219 
220 //------------------------------------------------------------------------------
223 //------------------------------------------------------------------------------
224 void popModelViewMatrix();
225 
226 
227 //------------------------------------------------------------------------------
230 //------------------------------------------------------------------------------
231 void popFBO();
232 
233 
234 //------------------------------------------------------------------------------
237 //------------------------------------------------------------------------------
238 void popTexture();
239 
240 
241 //------------------------------------------------------------------------------
244 //------------------------------------------------------------------------------
245 void popEnableDisableState();
246 
247 
248 //------------------------------------------------------------------------------
251 //------------------------------------------------------------------------------
252 void popShaderProgram();
253 
254 
255 //--------------------------------------------------------------------------
257 
260 //--------------------------------------------------------------------------
262 
263 
264 //------------------------------------------------------------------------------
266 //------------------------------------------------------------------------------
268 
269 
270 //------------------------------------------------------------------------------
272 //------------------------------------------------------------------------------
274 
275 
276 //------------------------------------------------------------------------------
278 
291 //------------------------------------------------------------------------------
292 void loadFrustumProjectionMatrix(double left,
293  double right,
294  double bottom,
295  double top,
296  double near,
297  double far);
298 
299 
300 //------------------------------------------------------------------------------
302 
313 //------------------------------------------------------------------------------
314 void loadPerspectiveProjectionMatrix(double fovy,
315  double aspect,
316  double zNear,
317  double zFar);
318 
319 
320 //------------------------------------------------------------------------------
322 
335 //------------------------------------------------------------------------------
336 void loadOrthoProjectionMatrix(double left,
337  double right,
338  double bottom,
339  double top,
340  double near,
341  double far);
342 
343 
344 //------------------------------------------------------------------------------
346 
360 //------------------------------------------------------------------------------
362  double right,
363  double bottom,
364  double top,
365  double near,
366  double far);
367 
368 
369 //------------------------------------------------------------------------------
371 
385 //------------------------------------------------------------------------------
387  double right,
388  double bottom,
389  double top,
390  double near,
391  double far);
392 
393 
394 //------------------------------------------------------------------------------
396 
408 //------------------------------------------------------------------------------
410  double aspect,
411  double zNear,
412  double zFar);
413 
414 
415 //------------------------------------------------------------------------------
417 
422 //------------------------------------------------------------------------------
423 void loadLookAtModelViewMatrix(const VEC3& eye,
424  const VEC3& centre,
425  const VEC3& up);
426 
427 
428 //------------------------------------------------------------------------------
430 
447 //------------------------------------------------------------------------------
448 void loadLookAtModelViewMatrix(double eyeX,
449  double eyeY,
450  double eyeZ,
451  double centreX,
452  double centreY,
453  double centreZ,
454  double upX,
455  double upY,
456  double upZ);
457 
458 
459 //------------------------------------------------------------------------------
461 
467 //------------------------------------------------------------------------------
469  const VEC3& centre,
470  const VEC3& up);
471 
472 
473 //------------------------------------------------------------------------------
475 
493 //------------------------------------------------------------------------------
495  double eyeY,
496  double eyeZ,
497  double centreX,
498  double centreY,
499  double centreZ,
500  double upX,
501  double upY,
502  double upZ);
503 
504 
505 //------------------------------------------------------------------------------
507 //------------------------------------------------------------------------------
509 
510 
511 //------------------------------------------------------------------------------
513 //------------------------------------------------------------------------------
515 
516 
517 //------------------------------------------------------------------------------
520 //------------------------------------------------------------------------------
521 void applyModelViewMatrix();
522 
523 
524 //------------------------------------------------------------------------------
526 /*
527 * @return true if the current OpenGL context supports OpenGL 4.5,
528 * false otherwise
529 */
530 //------------------------------------------------------------------------------
531 bool useOpenGL45();
532 
533 
534 //------------------------------------------------------------------------------
536 /*
537 * @return true if the current OpenGL context supports OpenGL 3.2,
538 * false otherwise
539 */
540 //------------------------------------------------------------------------------
541 bool useOpenGL32();
542 
543 
544 //------------------------------------------------------------------------------
546 /*
547 * @return true if the current OpenGL context supports Compute Shaders,
548 * false otherwise
549 */
550 //------------------------------------------------------------------------------
551 bool useOpenGLCompute();
552 
553 
554 //------------------------------------------------------------------------------
556 /*
557 * @return the new OpenGL VBO
558 */
559 //------------------------------------------------------------------------------
560 VBO* createVBO();
561 
562 
563 //------------------------------------------------------------------------------
565 /*
566 * @return the new OpenGL VBO
567 */
568 //------------------------------------------------------------------------------
569 OpenGL2VBO* createOpenGL2VBO();
570 
571 
572 //------------------------------------------------------------------------------
574 /*
575 * @return the new OpenGL VBO
576 */
577 //------------------------------------------------------------------------------
578 OpenGL3VBO* createOpenGL3VBO();
579 
580 
581 std::string getShaderTypeID(const std::type_info& aTypeID);
582 std::string getShaderImageType(const std::type_info& aTypeID);
583 std::string getShaderPixelType(const std::type_info& aTypeID);
584 std::string getShaderRGBAPixelType(const std::type_info& aTypeID);
585 
587 extern std::vector<MATRIX4> g_p_modelview_matrix_stack;
588 
589 
591 extern std::vector<MATRIX4> g_p_projection_matrix_stack;
592 
593 
596 
597 
600 
601 
603 extern std::vector<int> g_frame_buffer_object_stack;
604 
605 
607 extern std::vector<std::pair<int, int> > g_texture_stack;
608 
609 
611 extern std::vector<std::pair<int, bool> > g_enable_disable_state_stack;
612 
613 
615 extern std::vector<int> g_shader_program_stack;
616 
617 
618 } // namespace gVirtualXRay
619 
620 
621 //******************************************************************************
622 #include "OpenGLUtilities.inl"
623 
624 
625 #endif // __OpenGLUtilities_h
Class to handle vertex buffer objects (VBOs) in OpenGL 3.x or 4.x.
void pushProjectionMatrix()
Add the current matrix to the projection matrix stack.
void checkFBOErrorStatus(const char *aFileName, const char *aFunctionName, int aLineNumber)
Check the current FBO&#39;s error status.
void popEnableDisableState()
void loadModelViewMatrixFromOpenGL()
Replace the modelling-viewing matrix by OpenGL&#39;s modelling-viewing matrix.
void initializeGLEW()
Initialize GLEW.
Type declarations.
void pushModelViewMatrix()
Add the current matrix to the model/view matrix stack.
void applyModelViewMatrix()
bool useOpenGL32()
Check if OpenGL 3.2 is supported by the current OpenGL context.
MATRIX4 buildOrthoProjectionMatrix(double left, double right, double bottom, double top, double near, double far)
Create a orthographic projection matrix.
void checkOpenGLErrorStatus(const char *aFileName, const char *aFunctionName, int aLineNumber)
Check OpenGL&#39;s error status.
Class to handle vertex buffer objects (VBOs).
VBO * createVBO()
Create an OpenGL VBO suitable for the current OpenGL context.
void initialiseGLAD(const std::string &anAPI)
Initialise GLAD.
void loadPerspectiveProjectionMatrix(double fovy, double aspect, double zNear, double zFar)
Replace the projection matrix by a perspective projection matrix.
void pushShaderProgram()
Add the current shader program to the corresponding stack.
OpenGL2VBO * createOpenGL2VBO()
Create an OpenGL 2.x VBO.
bool useOpenGL45()
Check if OpenGL 4.5 is supported by the current OpenGL context.
std::vector< std::pair< int, bool > > g_enable_disable_state_stack
The stack of enable/disable states.
std::string getShaderPixelType(const std::type_info &aTypeID)
void pushEnableDisableState(int aParameter)
Add the enable/disable state to the corresponding stack.
Matrix4x4< RATIONAL_NUMBER > MATRIX4
Type of data used to store 4x4 matrices.
Definition: Types.h:119
void loadProjectionMatrixFromOpenGL()
Replace the projection matrix by OpenGL&#39;s projection matrix.
void pushTexture3D()
Add the current 3D texture binding to the texture stack.
std::string getShaderRGBAPixelType(const std::type_info &aTypeID)
Template class to handle a 4x4 matrixs.
std::string getShaderImageType(const std::type_info &aTypeID)
void initializeGLAD(const std::string &anAPI)
Initialize GLAD.
void loadIdentityModelViewMatrix()
Replace the model/view matrix by the identity matrix.
void initialiseGLEW()
Initialise GLEW.
Vec3< RATIONAL_NUMBER > VEC3
Type of data used to store 3D vectors.
Definition: Types.h:115
void pushTexture2D()
Add the current 2D texture binding to the texture stack.
gVirtualXRay::Matrix4x4< float > getCurrentOpenGLMatrix()
Load the current OpenGL matrix.
MATRIX4 g_current_projection_matrix
The projection matrix.
std::vector< int > g_shader_program_stack
The stack of shader programs.
MATRIX4 buildFrustumProjectionMatrix(double left, double right, double bottom, double top, double near, double far)
Create a perspective projection matrix.
void loadOrthoProjectionMatrix(double left, double right, double bottom, double top, double near, double far)
Replace the projection matrix by a orthographic projection matrix.
Some utility functions about OpenGL. Now supports GLSL450 and OpenGL 4.5.
void pushTexture1D()
Add the current 1D texture binding to the texture stack.
std::vector< int > g_frame_buffer_object_stack
The stack of FBO binding.
void popProjectionMatrix()
std::vector< MATRIX4 > g_p_projection_matrix_stack
The stack of projection matrix.
void popShaderProgram()
void loadIdentityProjectionMatrix()
Replace the projection matrix by the identity matrix.
std::vector< MATRIX4 > g_p_modelview_matrix_stack
The stack of model/view matrices.
std::string getShaderTypeID(const std::type_info &aTypeID)
MATRIX4 buildLookAtModelViewMatrix(const VEC3 &eye, const VEC3 &centre, const VEC3 &up)
Create a modelling-viewing matrix.
void loadFrustumProjectionMatrix(double left, double right, double bottom, double top, double near, double far)
Replace the projection matrix by a perspective projection matrix.
MATRIX4 g_current_modelview_matrix
The model/view matrices.
MATRIX4 buildPerspectiveProjectionMatrix(double fovy, double aspect, double zNear, double zFar)
Create a perspective projection matrix.
Matrix4x4 is a template class to handle a 4 by 4 matrix.
Definition: Matrix4x4.h:89
void pushTextureRectangle()
Add the current rectangle texture binding to the texture stack.
Class to handle vertex buffer objects (VBOs) in OpenGL 2.x.
void popModelViewMatrix()
void pushFBO()
Add the current FBO binding to the FBO stack.
void popTexture()
bool useOpenGLCompute()
Check if OpenGL Compute Shaders are supported by the current OpenGL context.
std::vector< std::pair< int, int > > g_texture_stack
The stack of texture binding.
void loadLookAtModelViewMatrix(const VEC3 &eye, const VEC3 &centre, const VEC3 &up)
Replace the modelling-viewing matrix by a viewing transformation matrix.
OpenGL3VBO * createOpenGL3VBO()
Create an OpenGL 3.x or 4.x VBO.