Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GL.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2022 Inria
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of the ALICE Project-Team nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Contact: Bruno Levy
30  *
31  * https://www.inria.fr/fr/bruno-levy
32  *
33  * Inria,
34  * Domaine de Voluceau,
35  * 78150 Le Chesnay - Rocquencourt
36  * FRANCE
37  *
38  */
39 
40 #ifndef GEOGRAM_GFX_BASIC_GL
41 #define GEOGRAM_GFX_BASIC_GL
42 
43 #ifdef GEO_DEBUG
44 #define GEO_DEBUG_GL
45 #endif
46 
48 #include <geogram_gfx/api/defs.h>
49 
50 
51 #if defined(GEO_OS_EMSCRIPTEN)
52 # define GLFW_INCLUDE_ES2
53 # include <GLFW/glfw3.h>
54 # define GL_GLEXT_PROTOTYPES
55 # include <GLES2/gl2ext.h>
56 # define GL_INVALID_INDEX GLuint(-1)
57 typedef double GLdouble;
58 # define glGenVertexArrays glGenVertexArraysOES
59 # define glBindVertexArray glBindVertexArrayOES
60 # define glDeleteVertexArrays glDeleteVertexArraysOES
61 # define GEO_GL_ES2
62 # define GEO_GL_NO_DOUBLES
63 #elif defined(GEO_OS_ANDROID)
64 # include <GLES3/gl3.h>
65 # include <GLES3/gl31.h>
66 # include <GLES3/gl32.h>
67 # define GEO_GL_TEXTURE_3D
68 # define GEO_GL_ES2
69 # define GEO_GL_150
70 # define GEO_GL_NO_DOUBLES
71 #else
72 # include <geogram_gfx/third_party/glad/glad.h>
73 # define GEO_GL_TEXTURE_3D
74 # define GEO_GL_150
75 # define GEO_GL_440
76 # define GEO_GL_ES2
77 #endif
78 
79 #include <geogram_gfx/GLUP/GLUP.h>
80 #include <geogram/basic/geometry.h>
81 
82 // Some defines missing in Emscripten GL headers
83 #if defined(GEO_OS_EMSCRIPTEN) || defined(GEO_OS_ANDROID)
84 # ifndef GL_RGB8
85 # define GL_RGB8 0x8051
86 # endif
87 
88 # ifndef GL_RGBA8
89 # define GL_RGBA8 0x8058
90 # endif
91 
92 # ifndef GL_R16F
93 # define GL_R16F 0x822D
94 # endif
95 
96 # ifndef GL_R32F
97 # define GL_R32F 0x822E
98 # endif
99 
100 # ifndef GL_RED
101 # define GL_RED 0x1903
102 # endif
103 
104 # ifndef GL_R8
105 # define GL_R8 0x8229
106 # endif
107 
108 # ifndef GL_R16
109 # define GL_R16 0x822A
110 # endif
111 
112 # ifndef GL_DEPTH_COMPONENT24
113 # define GL_DEPTH_COMPONENT24 0x81A6
114 # endif
115 
116 #endif
117 
123 namespace GEO {
124 
125  namespace GL {
131 
137  }
138 
139 
144  inline void glupVertex(const vec2& v) {
145  glupVertex2dv(v.data());
146  }
147 
152  inline void glupVertex(const vec3& v) {
153  glupVertex3dv(v.data());
154  }
155 
161  inline void glupVertex(const vec4& v) {
162  glupVertex4dv(v.data());
163  }
164 
169  inline void glupColor(const vec3& v) {
170  glupColor3dv(v.data());
171  }
172 
177  inline void glupColor(const vec4& v) {
178  glupColor4dv(v.data());
179  }
180 
181 
186  inline void glupTexCoord(const vec2& v) {
187  glupTexCoord2dv(v.data());
188  }
189 
194  inline void glupTexCoord(const vec3& v) {
195  glupTexCoord3dv(v.data());
196  }
197 
202  inline void glupTexCoord(const vec4& v) {
203  glupTexCoord4dv(v.data());
204  }
205 
210  inline void glupTranslate(const vec3& v) {
211  glupTranslated(v.x, v.y, v.z);
212  }
213 
224  double minval, double maxval, index_t mult=1
225  );
226 
237 
248 
258 
273  GLuint& buffer_id, GLenum target, size_t new_size, const void* data
274  );
275 
294  GLuint& buffer_id, GLenum target, size_t new_size, const void* data
295  );
296 
297 
318  GLuint& buffer_id, GLenum target, size_t new_size, const void* data,
319  bool update
320  );
321 
330  const char* file, int line, bool warning_only=false
331  );
332 
342  void GEOGRAM_GFX_API clear_gl_error_flags(const char* file, int line);
343 
356 
362 #ifdef GEO_DEBUG_GL
363 # define GEO_CHECK_GL() ::GEO::check_gl(__FILE__,__LINE__)
364 #else
365 # define GEO_CHECK_GL()
366 #endif
367 
368  /***********************************************************/
369 
370  void GEOGRAM_GFX_API glTexImage2Dxpm(char const* const* xpm_data);
371 
372 }
373 
374 #endif
GLUP: GL Useful Primitives.
T * data()
Gets modifiable vector data.
Definition: vecg.h:161
Geometric functions in 2d and 3d.
Basic definitions for the Geogram C API.
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
Definition: defs.h:55
Common include file, providing basic definitions. Should be included before anything else by all head...
Global Vorpaline namespace.
Definition: basic.h:55
void GEOGRAM_GFX_API update_or_check_buffer_object(GLuint &buffer_id, GLenum target, size_t new_size, const void *data, bool update)
Updates the content of an OpenGL buffer object, and resizes it if need be, or tests whether it has th...
void GEOGRAM_GFX_API glupMultMatrix(const mat4 &m)
Multiplies the current GLUP matrix with another one.
void terminate()
Cleans up Geogram.
void GEOGRAM_GFX_API glupMapTexCoords1d(double minval, double maxval, index_t mult=1)
Maps texture coordinates from a specified interval to the unit interval.
void GEOGRAM_GFX_API update_buffer_object(GLuint &buffer_id, GLenum target, size_t new_size, const void *data)
Updates the content of an OpenGL buffer object, and resizes it if need be.
GLint64 GEOGRAM_GFX_API get_size_of_bound_buffer_object(GLenum target)
Gets the size (in bytes) of the OpenGL buffer bound to a specified target.
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
Definition: geometry.h:65
void GEOGRAM_GFX_API stream_buffer_object(GLuint &buffer_id, GLenum target, size_t new_size, const void *data)
Updates the content of an OpenGL buffer object in streaming mode.
void glupVertex(const vec2 &v)
Sends a vertex to OpenGL.
Definition: GL.h:144
void GEOGRAM_GFX_API clear_gl_error_flags(const char *file, int line)
Clears all error flags set by previous OpenGL calls.
void GEOGRAM_GFX_API glupLoadMatrix(const mat4 &m)
Replaces the current GLUP matrix with a user defined one.
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
vecng< 4, Numeric::float64 > vec4
Represents points and vectors in 4d.
Definition: geometry.h:71
void GEOGRAM_GFX_API draw_unit_textured_quad(bool BW=false)
Draws a textured quad.
void glupTexCoord(const vec2 &v)
Sends 2d texture coordinates to OpenGL.
Definition: GL.h:186
void initialize(int flags=GEOGRAM_INSTALL_NONE)
Initialize Geogram.
void glupTranslate(const vec3 &v)
Applies a translation.
Definition: GL.h:210
void glupColor(const vec3 &v)
Sends a RGB color to OpenGL.
Definition: GL.h:169
void GEOGRAM_GFX_API check_gl(const char *file, int line, bool warning_only=false)
Tests for OpenGL errors and displays a message if OpenGL errors were encountered.