Atoms Crowd  7.0.0
ImathGL.h
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_ATOMSMATHGL_H
11 #define INCLUDED_ATOMSMATHGL_H
12 
13 #include <GL/gl.h>
14 
15 #include <AtomsMath/ImathFun.h>
16 #include <AtomsMath/ImathMatrix.h>
17 #include <AtomsMath/ImathNamespace.h>
18 #include <AtomsMath/ImathVec.h>
19 
21 inline void
22 glVertex (const ATOMSMATH_INTERNAL_NAMESPACE::V3f& v)
23 {
24  glVertex3f (v.x, v.y, v.z);
25 }
26 
28 inline void
29 glVertex (const ATOMSMATH_INTERNAL_NAMESPACE::V2f& v)
30 {
31  glVertex2f (v.x, v.y);
32 }
33 
35 inline void
36 glNormal (const ATOMSMATH_INTERNAL_NAMESPACE::V3f& n)
37 {
38  glNormal3f (n.x, n.y, n.z);
39 }
40 
42 inline void
43 glColor (const ATOMSMATH_INTERNAL_NAMESPACE::V3f& c)
44 {
45  glColor3f (c.x, c.y, c.z);
46 }
47 
49 inline void
50 glTranslate (const ATOMSMATH_INTERNAL_NAMESPACE::V3f& t)
51 {
52  glTranslatef (t.x, t.y, t.z);
53 }
54 
56 inline void
57 glTexCoord (const ATOMSMATH_INTERNAL_NAMESPACE::V2f& t)
58 {
59  glTexCoord2f (t.x, t.y);
60 }
61 
63 inline void
64 glDisableTexture()
65 {
66  glActiveTexture (GL_TEXTURE1);
67  glBindTexture (GL_TEXTURE_2D, 0);
68  glDisable (GL_TEXTURE_2D);
69 
70  glActiveTexture (GL_TEXTURE0);
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 !ATOMSMATH_INTERNAL_NAMESPACE::finitef (f) || f < -GL_FLOAT_MAX || f > GL_FLOAT_MAX;
82 }
83 
84 } // namespace
85 
87 inline void
88 throwBadMatrix (const ATOMSMATH_INTERNAL_NAMESPACE::M44f& m)
89 {
90 #ifdef ATOMS_USE_EXCEPTIONS
91  if (badFloat (m[0][0]) || badFloat (m[0][1]) || badFloat (m[0][2]) || badFloat (m[0][3]) ||
92  badFloat (m[1][0]) || badFloat (m[1][1]) || badFloat (m[1][2]) || badFloat (m[1][3]) ||
93  badFloat (m[2][0]) || badFloat (m[2][1]) || badFloat (m[2][2]) || badFloat (m[2][3]) ||
94  badFloat (m[3][0]) || badFloat (m[3][1]) || badFloat (m[3][2]) || badFloat (m[3][3]))
95  throw std::invalid_argument ("GL matrix overflow");
96 #endif
97 }
98 
100 inline void
101 glMultMatrix (const ATOMSMATH_INTERNAL_NAMESPACE::M44f& m)
102 {
103  throwBadMatrix (m);
104  glMultMatrixf ((GLfloat*) m[0]);
105 }
106 
108 inline void
109 glMultMatrix (const ATOMSMATH_INTERNAL_NAMESPACE::M44f* m)
110 {
111  throwBadMatrix (*m);
112  glMultMatrixf ((GLfloat*) (*m)[0]);
113 }
114 
116 inline void
117 glLoadMatrix (const ATOMSMATH_INTERNAL_NAMESPACE::M44f& m)
118 {
119  throwBadMatrix (m);
120  glLoadMatrixf ((GLfloat*) m[0]);
121 }
122 
124 inline void
125 glLoadMatrix (const ATOMSMATH_INTERNAL_NAMESPACE::M44f* m)
126 {
127  throwBadMatrix (*m);
128  glLoadMatrixf ((GLfloat*) (*m)[0]);
129 }
130 
131 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_ENTER
132 
137 
139 {
140  public:
141  GLPushMatrix() { glPushMatrix(); }
142  ~GLPushMatrix() { glPopMatrix(); }
143 };
144 
149 
151 {
152  public:
154  GLPushAttrib (GLbitfield mask) { glPushAttrib (mask); }
155 
157  ~GLPushAttrib() { glPopAttrib(); }
158 };
159 
164 
165 class GLBegin
166 {
167  public:
168 
170  GLBegin (GLenum mode) { glBegin (mode); }
171 
173  ~GLBegin() { glEnd(); }
174 };
175 
176 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_EXIT
177 
178 #endif
Definition: ImathGL.h:166
GLBegin(GLenum mode)
Call glBegin()
Definition: ImathGL.h:170
~GLBegin()
Call glEnd()
Definition: ImathGL.h:173
Definition: ImathGL.h:151
GLPushAttrib(GLbitfield mask)
call glPushAttrib()
Definition: ImathGL.h:154
~GLPushAttrib()
call glPopAttrib()
Definition: ImathGL.h:157
Definition: ImathGL.h:139