arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

multiTex.cpp

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////
00002 // 6/6/02       Aaron Lefohn    Scientific Computing and Imaging Institute
00003 // School of Computing          University of Utah
00004 //
00005 //  This library is free software; you can redistribute it and/or
00006 //  modify it under the terms of the GNU Lesser General Public
00007 //  License as published by the Free Software Foundation; either
00008 //  version 2.1 of the License, or (at your option) any later version.
00009 //
00010 //  This library is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 //  Lesser General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU Lesser General Public
00016 //  License along with this library; if not, write to the Free Software
00017 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 ////////////////////////////////////////////////////////////////////////
00019 //
00020 // multiTexture.cpp: implementation of the MultiTex class.
00021 //
00022 /////////////////////////////////////////////////////////////////////
00023 
00024 #include <texture/multiTex.h>
00025 #include <iostream>
00026 #include <util/gliftUtil.h>
00027 #include <GL/glUtil.h>
00028 using namespace std;
00029 
00030 using namespace glift;
00031 
00032 extern const GLenum g_texUnitName[NUM_TEX_UNIT_NAMES];
00033 
00034 MultiTex::MultiTex( const VecTexP& vecTexPtr, const VecMultiTexUState& vecTexUnitState )
00035 {
00036    initMembers( vecTexPtr, vecTexUnitState );
00037 }
00038 
00039 MultiTex::MultiTex( const MultiTex& rhs )
00040 {
00041    initMembers( rhs.m_texPtr, rhs.m_texUnitState );
00042 }
00043 
00044 MultiTex& MultiTex::operator=( const MultiTex& rhs )
00045 {
00046    if( &rhs != this ) {
00047       initMembers( rhs.m_texPtr, rhs.m_texUnitState );
00048    }
00049    return *this;
00050 }
00051 
00052 MultiTex::~MultiTex()
00053 {}
00054 
00055 void MultiTex::initMembers( const VecTexP& vecTexPtr, const VecMultiTexUState& vecTexUnitState )
00056 {
00057 #ifndef GL_ARB_multitexture
00058    err() << "initMembers() Error:\n"
00059       << "\tGL_ARB_multitexture is not defined.\n"
00060       << "\tMultiTexture is not available.\n";
00061    exit(1);
00062 #endif
00063 
00064    /// Ensure that the 2 vectors are the same size.
00065    if( !vecTexUnitState.empty() &&
00066       vecTexPtr.size() != vecTexUnitState.size() ) {
00067          err() << "initMembers(...) Error:\n"
00068             << "\tMust have the same number of textures as texUnitStates.\n";
00069          exit(1);
00070       }
00071 
00072       m_texPtr = vecTexPtr;
00073       m_texUnitState = vecTexUnitState;
00074 }
00075 
00076 void MultiTex::bindDef()
00077 {
00078 #ifdef GL_ARB_multitexture
00079    //Enable all of the texture units
00080    for(unsigned int i=0; i < m_texPtr.size(); i++) {
00081       //                        assert( m_texPtr[i] );
00082       glActiveTexture( g_texUnitName[i] ); //GL_TEXTUREn_ARB, n=0,1,2,3,4,5
00083 
00084       if( !m_texUnitState.empty() ) {
00085          if( m_texPtr[i] ) {
00086             m_texUnitState[i].bind( m_texPtr[i]->texType() ); /// Bind the state for this texture unit
00087          }
00088       }
00089 
00090       if( m_texPtr[i] ) {
00091          m_texPtr[i]->bind();                                                     /// Bind the texture
00092       }
00093       glErr(estr(),"MultiTex", "bindDef() 1");
00094    }
00095    glActiveTexture( g_texUnitName[0] );
00096 #endif
00097    glErr(estr(),"MultiTex:bindDef() 2");
00098 }
00099 
00100 void MultiTex::releaseDef()
00101 {
00102 #ifdef GL_ARB_multitexture
00103    //Disable all of the texture units
00104    for(unsigned int i=0; i < m_texPtr.size(); i++) {
00105       glActiveTexture( g_texUnitName[i] );
00106 
00107       if( !m_texUnitState.empty() ) {
00108          m_texUnitState[i].release();/// Release the texture unit state
00109       }
00110 
00111       if( m_texPtr[i] ) {
00112          m_texPtr[i]->release();                /// Release the texture
00113       }
00114    }
00115 
00116    glActiveTexture( g_texUnitName[0] );
00117 #endif
00118 
00119    glErr(estr(),"MultiTex:release()");
00120 }
00121 
00122 void MultiTex::reset( const VecTexP& texture, const VecMultiTexUState& vecTexUnitState )
00123 {
00124    /// Only replace 'm_texUnitState' if 'vecTexUnitState' is non-empty.
00125    if( vecTexUnitState.empty() ) {
00126       initMembers( texture, m_texUnitState );
00127    }
00128    else {
00129       initMembers( texture, vecTexUnitState );
00130    }
00131 }
00132 
00133 void MultiTex::reset( const VecMultiTexUState& vecTexUnitState )
00134 {
00135    initMembers( m_texPtr, vecTexUnitState );
00136 }
00137 
00138 

Send questions, comments, and bug reports to:
jmk