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 ||
82  f > GL_FLOAT_MAX;
83 }
84 
85 } // namespace
86 
87 /// Throw an exception if m is not a valid matrix for GL
88 inline void
90 {
91  if (badFloat (m[0][0]) || badFloat (m[0][1]) || badFloat (m[0][2]) ||
92  badFloat (m[0][3]) || badFloat (m[1][0]) || badFloat (m[1][1]) ||
93  badFloat (m[1][2]) || badFloat (m[1][3]) || badFloat (m[2][0]) ||
94  badFloat (m[2][1]) || badFloat (m[2][2]) || badFloat (m[2][3]) ||
95  badFloat (m[3][0]) || badFloat (m[3][1]) || badFloat (m[3][2]) ||
96  badFloat (m[3][3]))
97  throw std::invalid_argument ("GL matrix overflow");
98 }
99 
100 /// Call glMultmatrixf. Throw an exception if m is not a valid matrix for GL.
101 inline void
103 {
104  throwBadMatrix (m);
105  glMultMatrixf ((GLfloat*) m[0]);
106 }
107 
108 /// Call glMultmatrixf. Throw an exception if m is not a valid matrix for GL.
109 inline void
111 {
112  throwBadMatrix (*m);
113  glMultMatrixf ((GLfloat*) (*m)[0]);
114 }
115 
116 /// Call glLoadmatrixf. Throw an exception if m is not a valid matrix for GL.
117 inline void
119 {
120  throwBadMatrix (m);
121  glLoadMatrixf ((GLfloat*) m[0]);
122 }
123 
124 /// Call glLoadmatrixf. Throw an exception if m is not a valid matrix for GL.
125 inline void
127 {
128  throwBadMatrix (*m);
129  glLoadMatrixf ((GLfloat*) (*m)[0]);
130 }
131 
132 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
133 
134 ///
135 /// A class object that pushes/pops the GL matrix. This object assists with
136 /// proper cleanup of the state when exceptions are thrown.
137 ///
138 
140 {
141 public:
144 };
145 
146 ///
147 /// A class object that pushes/pops the current GL attribute state. This object assists with
148 /// proper cleanup of the state when exceptions are thrown.
149 ///
150 
152 {
153 public:
154  /// call glPushAttrib()
156 
157  /// call glPopAttrib()
159 };
160 
161 ///
162 /// A class object that wraps glBegin/glEnd. The constructor calls
163 /// glBegin(). The destructor calls glEnd().
164 ///
165 
166 class GLBegin
167 {
168 public:
169  /// Call glBegin()
170  GLBegin (GLenum mode) { glBegin (mode); }
171 
172  /// Call glEnd()
173  ~GLBegin () { glEnd (); }
174 };
175 
176 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
177 
178 #endif
#define glEnd
Definition: glad.h:2222
GLPushMatrix()
Definition: ImathGL.h:142
GLPushAttrib(GLbitfield mask)
call glPushAttrib()
Definition: ImathGL.h:155
~GLPushMatrix()
Definition: ImathGL.h:143
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:1401
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:158
void throwBadMatrix(const IMATH_INTERNAL_NAMESPACE::M44f &m)
Throw an exception if m is not a valid matrix for GL.
Definition: ImathGL.h:89
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:1046
Vec3< float > V3f
Vec3 of float.
Definition: ImathVec.h:1064
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:102
#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:118
#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:170
#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:173
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:206