source: NonGTP/OpenEXR/include/Imath/ImathGL.h @ 855

Revision 855, 4.4 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[855]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
46inline void glVertex    ( const Imath::V3f &v ) { glVertex3f(v.x,v.y,v.z);   }
47inline void glVertex    ( const Imath::V2f &v ) { glVertex2f(v.x,v.y);       }
48inline void glNormal    ( const Imath::V3f &n ) { glNormal3f(n.x,n.y,n.z);   }
49inline void glColor     ( const Imath::V3f &c ) { glColor3f(c.x,c.y,c.z);    }
50inline void glTranslate ( const Imath::V3f &t ) { glTranslatef(t.x,t.y,t.z); }
51
52inline void glTexCoord( const Imath::V2f &t )
53{
54    glTexCoord2f(t.x,t.y);
55#ifndef PLATFORM_IRIX
56    glMultiTexCoord2f(GL_TEXTURE1, t.x, t.y);
57#endif
58}
59
60inline void glDisableTexture()
61{
62#ifndef PLATFORM_IRIX
63    glActiveTexture(GL_TEXTURE1);
64    glBindTexture(GL_TEXTURE_2D, 0);
65    glDisable(GL_TEXTURE_2D);
66
67    glActiveTexture(GL_TEXTURE0);
68#endif
69    glBindTexture(GL_TEXTURE_2D, 0);
70    glDisable(GL_TEXTURE_2D);
71}
72
73namespace {
74   
75const float GL_FLOAT_MAX = 1.8e+19; // sqrt (FLT_MAX)
76
77inline bool
78badFloat (float f)
79{
80    return !Imath::finitef (f) || f < - GL_FLOAT_MAX || f > GL_FLOAT_MAX;
81}
82
83} // namespace
84       
85inline void
86throwBadMatrix (const Imath::M44f& m)
87{
88    if (badFloat (m[0][0]) ||
89        badFloat (m[0][1]) ||
90        badFloat (m[0][2]) ||
91        badFloat (m[0][3]) ||
92        badFloat (m[1][0]) ||
93        badFloat (m[1][1]) ||
94        badFloat (m[1][2]) ||
95        badFloat (m[1][3]) ||
96        badFloat (m[2][0]) ||
97        badFloat (m[2][1]) ||
98        badFloat (m[2][2]) ||
99        badFloat (m[2][3]) ||
100        badFloat (m[3][0]) ||
101        badFloat (m[3][1]) ||
102        badFloat (m[3][2]) ||
103        badFloat (m[3][3]))
104        throw Iex::OverflowExc ("GL matrix overflow");
105}
106
107inline void
108glMultMatrix( const Imath::M44f& m )
109{
110    throwBadMatrix (m);
111    glMultMatrixf( (GLfloat*)m[0] );
112}
113
114inline void
115glMultMatrix( const Imath::M44f* m )
116{
117    throwBadMatrix (*m);
118    glMultMatrixf( (GLfloat*)(*m)[0] );
119}
120
121inline void
122glLoadMatrix( const Imath::M44f& m )
123{
124    throwBadMatrix (m);
125    glLoadMatrixf( (GLfloat*)m[0] );
126}
127
128inline void
129glLoadMatrix( const Imath::M44f* m )
130{
131    throwBadMatrix (*m);
132    glLoadMatrixf( (GLfloat*)(*m)[0] );
133}
134
135
136namespace Imath {
137
138//
139// Class objects that push/pop the GL state. These objects assist with
140// proper cleanup of the state when exceptions are thrown.
141//
142
143class GLPushMatrix {
144  public:
145
146    GLPushMatrix ()                     { glPushMatrix(); }
147    ~GLPushMatrix()                     { glPopMatrix(); }
148};
149
150class GLPushAttrib {
151  public:
152
153    GLPushAttrib (GLbitfield mask)      { glPushAttrib (mask); }
154    ~GLPushAttrib()                     { glPopAttrib(); }
155};
156
157class GLBegin {
158  public:
159
160    GLBegin (GLenum mode)               { glBegin (mode); }
161    ~GLBegin()                          { glEnd(); }
162};
163
164} // namespace Imath
165
166#endif
Note: See TracBrowser for help on using the repository browser.