HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImathGL.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
4 //
5 
6 //
7 // Convenience functions that call GL with Imath types
8 //
9 
10 #ifndef INCLUDED_IMATHGL_H
11 #define INCLUDED_IMATHGL_H
12 
13 #include <GL/gl.h>
14 
15 #include "ImathFun.h"
16 #include "ImathMatrix.h"
17 #include "ImathNamespace.h"
18 #include "ImathVec.h"
19 
20 /// Call glVertex3f
21 inline void
23 {
24  glVertex3f (v.x, v.y, v.z);
25 }
26 
27 /// Call glVertex2f
28 inline void
30 {
31  glVertex2f (v.x, v.y);
32 }
33 
34 /// Call glNormal3f
35 inline void
37 {
38  glNormal3f (n.x, n.y, n.z);
39 }
40 
41 /// Call glColor3f
42 inline void
44 {
45  glColor3f (c.x, c.y, c.z);
46 }
47 
48 /// Call glTranslatef
49 inline void
51 {
52  glTranslatef (t.x, t.y, t.z);
53 }
54 
55 /// Call glTexCoord2f
56 inline void
58 {
59  glTexCoord2f (t.x, t.y);
60 }
61 
62 /// Disable GL textures
63 inline void
65 {
69 
71 }
72 
73 namespace
74 {
75 
76 const float GL_FLOAT_MAX = 1.8e+19; // sqrt (FLT_MAX)
77 
78 inline bool
79 badFloat (float f)
80 {
81  return !IMATH_INTERNAL_NAMESPACE::finitef (f) || f < -GL_FLOAT_MAX || f > GL_FLOAT_MAX;
82 }
83 
84 } // namespace
85 
86 /// Throw an exception if m is not a valid matrix for GL
87 inline void
89 {
90  if (badFloat (m[0][0]) || badFloat (m[0][1]) || badFloat (m[0][2]) || badFloat (m[0][3]) ||
91  badFloat (m[1][0]) || badFloat (m[1][1]) || badFloat (m[1][2]) || badFloat (m[1][3]) ||
92  badFloat (m[2][0]) || badFloat (m[2][1]) || badFloat (m[2][2]) || badFloat (m[2][3]) ||
93  badFloat (m[3][0]) || badFloat (m[3][1]) || badFloat (m[3][2]) || badFloat (m[3][3]))
94  throw std::invalid_argument ("GL matrix overflow");
95 }
96 
97 /// Call glMultmatrixf. Throw an exception if m is not a valid matrix for GL.
98 inline void
100 {
101  throwBadMatrix (m);
102  glMultMatrixf ((GLfloat*) m[0]);
103 }
104 
105 /// Call glMultmatrixf. Throw an exception if m is not a valid matrix for GL.
106 inline void
108 {
109  throwBadMatrix (*m);
110  glMultMatrixf ((GLfloat*) (*m)[0]);
111 }
112 
113 /// Call glLoadmatrixf. Throw an exception if m is not a valid matrix for GL.
114 inline void
116 {
117  throwBadMatrix (m);
118  glLoadMatrixf ((GLfloat*) m[0]);
119 }
120 
121 /// Call glLoadmatrixf. Throw an exception if m is not a valid matrix for GL.
122 inline void
124 {
125  throwBadMatrix (*m);
126  glLoadMatrixf ((GLfloat*) (*m)[0]);
127 }
128 
129 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
130 
131 ///
132 /// A class object that pushes/pops the GL matrix. This object assists with
133 /// proper cleanup of the state when exceptions are thrown.
134 ///
135 
137 {
138  public:
141 };
142 
143 ///
144 /// A class object that pushes/pops the current GL attribute state. This object assists with
145 /// proper cleanup of the state when exceptions are thrown.
146 ///
147 
149 {
150  public:
151  /// call glPushAttrib()
153 
154  /// call glPopAttrib()
156 };
157 
158 ///
159 /// A class object that wraps glBegin/glEnd. The constructor calls
160 /// glBegin(). The destructor calls glEnd().
161 ///
162 
163 class GLBegin
164 {
165  public:
166 
167  /// Call glBegin()
168  GLBegin (GLenum mode) { glBegin (mode); }
169 
170  /// Call glEnd()
171  ~GLBegin() { glEnd(); }
172 };
173 
174 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
175 
176 #endif
#define glEnd
Definition: glad.h:2222
GLPushMatrix()
Definition: ImathGL.h:139
GLPushAttrib(GLbitfield mask)
call glPushAttrib()
Definition: ImathGL.h:152
~GLPushMatrix()
Definition: ImathGL.h:140
float GLfloat
Definition: glcorearb.h:89
#define glPopAttrib
Definition: glad.h:2672
#define GL_TEXTURE_2D
Definition: glcorearb.h:309
Matrix44< float > M44f
4x4 matrix of float
Definition: ImathMatrix.h:1137
void glColor(const IMATH_INTERNAL_NAMESPACE::V3f &c)
Call glColor3f.
Definition: ImathGL.h:43
const GLdouble * v
Definition: glcorearb.h:837
#define GL_TEXTURE0
Definition: glcorearb.h:489
GLAPI void GL_APIENTRY glDisable(GLenum cap)
unsigned int GLenum
Definition: cl.hpp:166
#define glNormal3f
Definition: glad.h:2261
void glTranslate(const IMATH_INTERNAL_NAMESPACE::V3f &t)
Call glTranslatef.
Definition: ImathGL.h:50
GLAPI void GL_APIENTRY glBindTexture(GLenum target, GLuint texture)
#define glTranslatef
Definition: glad.h:2864
#define glPushAttrib
Definition: glad.h:2675
~GLPushAttrib()
call glPopAttrib()
Definition: ImathGL.h:155
void throwBadMatrix(const IMATH_INTERNAL_NAMESPACE::M44f &m)
Throw an exception if m is not a valid matrix for GL.
Definition: ImathGL.h:88
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
GLint GLuint mask
Definition: glcorearb.h:124
void glTexCoord(const IMATH_INTERNAL_NAMESPACE::V2f &t)
Call glTexCoord2f.
Definition: ImathGL.h:57
#define glBegin
Definition: glad.h:2114
#define glLoadMatrixf
Definition: glad.h:2825
GLdouble t
Definition: glad.h:2397
GLenum mode
Definition: glcorearb.h:99
Vec2< float > V2f
Vec2 of float.
Definition: ImathVec.h:834
Vec3< float > V3f
Vec3 of float.
Definition: ImathVec.h:849
void glNormal(const IMATH_INTERNAL_NAMESPACE::V3f &n)
Call glNormal3f.
Definition: ImathGL.h:36
void glMultMatrix(const IMATH_INTERNAL_NAMESPACE::M44f &m)
Call glMultmatrixf. Throw an exception if m is not a valid matrix for GL.
Definition: ImathGL.h:99
#define glPopMatrix
Definition: glad.h:2843
void glLoadMatrix(const IMATH_INTERNAL_NAMESPACE::M44f &m)
Call glLoadmatrixf. Throw an exception if m is not a valid matrix for GL.
Definition: ImathGL.h:115
#define GL_TEXTURE1
Definition: glcorearb.h:490
void glDisableTexture()
Disable GL textures.
Definition: ImathGL.h:64
#define glVertex2f
Definition: glad.h:2477
GLBegin(GLenum mode)
Call glBegin()
Definition: ImathGL.h:168
#define glMultMatrixf
Definition: glad.h:2834
#define glTexCoord2f
Definition: glad.h:2405
void glVertex(const IMATH_INTERNAL_NAMESPACE::V3f &v)
Call glVertex3f.
Definition: ImathGL.h:22
#define glVertex3f
Definition: glad.h:2501
~GLBegin()
Call glEnd()
Definition: ImathGL.h:171
unsigned int GLbitfield
Definition: glcorearb.h:92
#define glColor3f
Definition: glad.h:2132
#define glActiveTexture
Definition: glad.h:2981
#define glPushMatrix
Definition: glad.h:2846
IMATH_HOSTDEVICE bool finitef(float f) IMATH_NOEXCEPT
Definition: ImathFun.h:204