HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ImathGL.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
4 // Digital Ltd. LLC
5 //
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 // * Neither the name of Industrial Light & Magic nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 ///////////////////////////////////////////////////////////////////////////
34 
35 
36 #ifndef INCLUDED_IMATHGL_H
37 #define INCLUDED_IMATHGL_H
38 
39 #include <GL/gl.h>
40 
41 #include "ImathVec.h"
42 #include "ImathMatrix.h"
43 #include "IexMathExc.h"
44 #include "ImathFun.h"
45 #include "ImathNamespace.h"
46 
47 inline void glVertex ( const IMATH_INTERNAL_NAMESPACE::V3f &v ) { glVertex3f(v.x,v.y,v.z); }
48 inline void glVertex ( const IMATH_INTERNAL_NAMESPACE::V2f &v ) { glVertex2f(v.x,v.y); }
49 inline void glNormal ( const IMATH_INTERNAL_NAMESPACE::V3f &n ) { glNormal3f(n.x,n.y,n.z); }
50 inline void glColor ( const IMATH_INTERNAL_NAMESPACE::V3f &c ) { glColor3f(c.x,c.y,c.z); }
51 inline void glTranslate ( const IMATH_INTERNAL_NAMESPACE::V3f &t ) { glTranslatef(t.x,t.y,t.z); }
52 
54 {
55  glTexCoord2f(t.x,t.y);
56 }
57 
58 inline void glDisableTexture()
59 {
60  glActiveTexture(GL_TEXTURE1);
63 
64  glActiveTexture(GL_TEXTURE0);
65 }
66 
67 namespace {
68 
69 const float GL_FLOAT_MAX = 1.8e+19; // sqrt (FLT_MAX)
70 
71 inline bool
72 badFloat (float f)
73 {
74  return !IMATH_INTERNAL_NAMESPACE::finitef (f) || f < - GL_FLOAT_MAX || f > GL_FLOAT_MAX;
75 }
76 
77 } // namespace
78 
79 inline void
81 {
82  if (badFloat (m[0][0]) ||
83  badFloat (m[0][1]) ||
84  badFloat (m[0][2]) ||
85  badFloat (m[0][3]) ||
86  badFloat (m[1][0]) ||
87  badFloat (m[1][1]) ||
88  badFloat (m[1][2]) ||
89  badFloat (m[1][3]) ||
90  badFloat (m[2][0]) ||
91  badFloat (m[2][1]) ||
92  badFloat (m[2][2]) ||
93  badFloat (m[2][3]) ||
94  badFloat (m[3][0]) ||
95  badFloat (m[3][1]) ||
96  badFloat (m[3][2]) ||
97  badFloat (m[3][3]))
98  throw IEX_NAMESPACE::OverflowExc ("GL matrix overflow");
99 }
100 
101 inline void
103 {
104  throwBadMatrix (m);
105  glMultMatrixf( (GLfloat*)m[0] );
106 }
107 
108 inline void
110 {
111  throwBadMatrix (*m);
112  glMultMatrixf( (GLfloat*)(*m)[0] );
113 }
114 
115 inline void
117 {
118  throwBadMatrix (m);
119  glLoadMatrixf( (GLfloat*)m[0] );
120 }
121 
122 inline void
124 {
125  throwBadMatrix (*m);
126  glLoadMatrixf( (GLfloat*)(*m)[0] );
127 }
128 
129 
130 
131 
133 
134 
135 //
136 // Class objects that push/pop the GL state. These objects assist with
137 // proper cleanup of the state when exceptions are thrown.
138 //
139 
141  public:
142 
143  GLPushMatrix () { glPushMatrix(); }
144  ~GLPushMatrix() { glPopMatrix(); }
145 };
146 
148  public:
149 
150  GLPushAttrib (GLbitfield mask) { glPushAttrib (mask); }
151  ~GLPushAttrib() { glPopAttrib(); }
152 };
153 
154 class GLBegin {
155  public:
156 
157  GLBegin (GLenum mode) { glBegin (mode); }
158  ~GLBegin() { glEnd(); }
159 };
160 
161 
162 
164 
165 
166 #endif
#define IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
GLPushMatrix()
Definition: ImathGL.h:143
GLPushAttrib(GLbitfield mask)
Definition: ImathGL.h:150
~GLPushMatrix()
Definition: ImathGL.h:144
float GLfloat
Definition: glcorearb.h:88
#define GL_TEXTURE_2D
Definition: glcorearb.h:308
Matrix44< float > M44f
Definition: ImathMatrix.h:873
void glColor(const IMATH_INTERNAL_NAMESPACE::V3f &c)
Definition: ImathGL.h:50
#define IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
const GLdouble * v
Definition: glcorearb.h:836
#define GL_TEXTURE0
Definition: glcorearb.h:488
GLAPI void APIENTRY glBindTexture(GLenum target, GLuint texture)
GLint GLuint mask
Definition: glcorearb.h:123
bool finitef(float f)
Definition: ImathFun.h:249
unsigned int GLenum
Definition: cl.hpp:166
void glTranslate(const IMATH_INTERNAL_NAMESPACE::V3f &t)
Definition: ImathGL.h:51
~GLPushAttrib()
Definition: ImathGL.h:151
void throwBadMatrix(const IMATH_INTERNAL_NAMESPACE::M44f &m)
Definition: ImathGL.h:80
GLdouble n
Definition: glcorearb.h:2007
GLfloat f
Definition: glcorearb.h:1925
GLAPI void APIENTRY glDisable(GLenum cap)
void glTexCoord(const IMATH_INTERNAL_NAMESPACE::V2f &t)
Definition: ImathGL.h:53
GLenum mode
Definition: glcorearb.h:98
Vec2< float > V2f
Definition: ImathVec.h:689
Vec3< float > V3f
Definition: ImathVec.h:693
void glNormal(const IMATH_INTERNAL_NAMESPACE::V3f &n)
Definition: ImathGL.h:49
void glMultMatrix(const IMATH_INTERNAL_NAMESPACE::M44f &m)
Definition: ImathGL.h:102
void glLoadMatrix(const IMATH_INTERNAL_NAMESPACE::M44f &m)
Definition: ImathGL.h:116
#define GL_TEXTURE1
Definition: glcorearb.h:489
void glDisableTexture()
Definition: ImathGL.h:58
GLBegin(GLenum mode)
Definition: ImathGL.h:157
void glVertex(const IMATH_INTERNAL_NAMESPACE::V3f &v)
Definition: ImathGL.h:47
~GLBegin()
Definition: ImathGL.h:158
unsigned int GLbitfield
Definition: glcorearb.h:91