///////////////////////////////////////////////////////////////////////////1//2// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas3// Digital Ltd. LLC4//5// All rights reserved.6//7// Redistribution and use in source and binary forms, with or without8// modification, are permitted provided that the following conditions are9// met:10// * Redistributions of source code must retain the above copyright11// notice, this list of conditions and the following disclaimer.12// * Redistributions in binary form must reproduce the above13// copyright notice, this list of conditions and the following disclaimer14// in the documentation and/or other materials provided with the15// distribution.16// * Neither the name of Industrial Light & Magic nor the names of17// its contributors may be used to endorse or promote products derived18// from this software without specific prior written permission.19//20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31//32///////////////////////////////////////////////////////////////////////////333435#ifndef INCLUDED_IMATHGL_H36#define INCLUDED_IMATHGL_H3738#include <GL/gl.h>3940#include "ImathVec.h"41#include "ImathMatrix.h"42#include "IexMathExc.h"43#include "ImathFun.h"4445inline void glVertex ( const Imath::V3f &v ) { glVertex3f(v.x,v.y,v.z); }46inline void glVertex ( const Imath::V2f &v ) { glVertex2f(v.x,v.y); }47inline void glNormal ( const Imath::V3f &n ) { glNormal3f(n.x,n.y,n.z); }48inline void glColor ( const Imath::V3f &c ) { glColor3f(c.x,c.y,c.z); }49inline void glTranslate ( const Imath::V3f &t ) { glTranslatef(t.x,t.y,t.z); }5051inline void glTexCoord( const Imath::V2f &t )52{53glTexCoord2f(t.x,t.y);54}5556inline void glDisableTexture()57{58glActiveTexture(GL_TEXTURE1);59glBindTexture(GL_TEXTURE_2D, 0);60glDisable(GL_TEXTURE_2D);6162glActiveTexture(GL_TEXTURE0);63}6465namespace {6667const float GL_FLOAT_MAX = 1.8e+19; // sqrt (FLT_MAX)6869inline bool70badFloat (float f)71{72return !Imath::finitef (f) || f < - GL_FLOAT_MAX || f > GL_FLOAT_MAX;73}7475} // namespace7677inline void78throwBadMatrix (const Imath::M44f& m)79{80if (badFloat (m[0][0]) ||81badFloat (m[0][1]) ||82badFloat (m[0][2]) ||83badFloat (m[0][3]) ||84badFloat (m[1][0]) ||85badFloat (m[1][1]) ||86badFloat (m[1][2]) ||87badFloat (m[1][3]) ||88badFloat (m[2][0]) ||89badFloat (m[2][1]) ||90badFloat (m[2][2]) ||91badFloat (m[2][3]) ||92badFloat (m[3][0]) ||93badFloat (m[3][1]) ||94badFloat (m[3][2]) ||95badFloat (m[3][3]))96throw Iex::OverflowExc ("GL matrix overflow");97}9899inline void100glMultMatrix( const Imath::M44f& m )101{102throwBadMatrix (m);103glMultMatrixf( (GLfloat*)m[0] );104}105106inline void107glMultMatrix( const Imath::M44f* m )108{109throwBadMatrix (*m);110glMultMatrixf( (GLfloat*)(*m)[0] );111}112113inline void114glLoadMatrix( const Imath::M44f& m )115{116throwBadMatrix (m);117glLoadMatrixf( (GLfloat*)m[0] );118}119120inline void121glLoadMatrix( const Imath::M44f* m )122{123throwBadMatrix (*m);124glLoadMatrixf( (GLfloat*)(*m)[0] );125}126127128namespace Imath {129130//131// Class objects that push/pop the GL state. These objects assist with132// proper cleanup of the state when exceptions are thrown.133//134135class GLPushMatrix {136public:137138GLPushMatrix () { glPushMatrix(); }139~GLPushMatrix() { glPopMatrix(); }140};141142class GLPushAttrib {143public:144145GLPushAttrib (GLbitfield mask) { glPushAttrib (mask); }146~GLPushAttrib() { glPopAttrib(); }147};148149class GLBegin {150public:151152GLBegin (GLenum mode) { glBegin (mode); }153~GLBegin() { glEnd(); }154};155156} // namespace Imath157158#endif159160161