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

progShader.cpp

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////
00002 // 6/13/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 #include <state/progShader.h>
00021 #include <iostream>
00022 
00023 using namespace std;
00024 using namespace gutz;
00025 
00026 using namespace glift;
00027 
00028 ProgShader::ProgShader( int numTexUnits, PixelShader* pixShader, TexCoordPerturb* texCoordPerturb )
00029 {
00030    initMembers( numTexUnits, pixShader, NULL, texCoordPerturb );
00031 }
00032 
00033 ProgShader::ProgShader( int numTexUnits, VertexShader* vertShader, TexCoordPerturb* texCoordPerturb )
00034 {
00035    initMembers( numTexUnits, NULL, vertShader, texCoordPerturb );
00036 }
00037 
00038 ProgShader::ProgShader( int numTexUnits, PixelShader* pixShader, VertexShader* vertShader, TexCoordPerturb* texCoordPerturb )
00039 {
00040    initMembers( numTexUnits, pixShader, vertShader, texCoordPerturb );
00041 }
00042 
00043 ProgShader::ProgShader( const ProgShader& rhs )
00044 {
00045    initMembers(rhs);
00046 }
00047 
00048 ProgShader& ProgShader::operator=( const ProgShader& rhs )
00049 {
00050    if( &rhs != NULL ) {
00051       initMembers(rhs);
00052    }
00053    return *this;
00054 }
00055 
00056 ProgShader::~ProgShader()
00057 {}
00058 
00059 void ProgShader::initMembers( const ProgShader& rhs )
00060 {
00061    initMembers( rhs.m_numTexUnits, rhs.m_pixelShader, rhs.m_vertexShader, rhs.m_texCoordPerturb );
00062 }
00063 
00064 void ProgShader::initMembers( int numTexUnits, PixelShader*  pixShader, VertexShader* vertShader, 
00065                              TexCoordPerturb* texCoordPerturb )
00066 {
00067    m_numTexUnits     = numTexUnits;
00068    m_pixelShader          = pixShader;
00069    m_vertexShader         = vertShader;
00070    m_texCoordPerturb = texCoordPerturb;
00071 
00072    if( m_texCoordPerturb && (m_numTexUnits != m_texCoordPerturb->numTexUnits() )) {
00073       err() << "initMembers(...) Error:\n"
00074          << "\tnumTexUnits (" << m_numTexUnits << ") and texCoordPerturb->numTexUnits() (" <<
00075          m_texCoordPerturb->numTexUnits() << ") do not match.\n";
00076       exit(1);
00077    }
00078 }
00079 
00080 /// Generate appropriate texture coordinates, taking into account 
00081 /// multiTexturing, texCoordTransforms, and texture contants
00082 MultiTexCoord* ProgShader::genTexCoords( const arrayw2f& rawTexCoord, const vec3f& primScale ) const
00083 {
00084    if( m_texCoordPerturb == NULL ) {
00085       return rawTexCoord.empty() ? NULL : new MultiTexCoord( m_numTexUnits, rawTexCoord );
00086    }
00087    else {
00088       return m_texCoordPerturb->genTexCoords( rawTexCoord, primScale );
00089    }
00090 }
00091 
00092 void ProgShader::bindDef()
00093 {
00094    if( m_vertexShader ) {m_vertexShader->bind();}
00095    if( m_pixelShader )  {m_pixelShader->bind(); }
00096 }
00097 
00098 void ProgShader::releaseDef()
00099 {
00100    if( m_pixelShader )  {m_pixelShader->release(); }
00101    if( m_vertexShader ) {m_vertexShader->release();}
00102 }
00103 

Send questions, comments, and bug reports to:
jmk