00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00081
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