00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <state/pixelShaderATI8K.h>
00025 #include <iostream>
00026 using namespace std;
00027
00028 using namespace glift;
00029
00030
00031
00032
00033
00034 PixelShaderATI8K::PixelShaderATI8K( VoidFuncPtr defineShader, PBuffGlift* pbuff )
00035 {
00036 initMembers( new Command0(defineShader), 0, pbuff);
00037 this->init();
00038 }
00039
00040 PixelShaderATI8K::PixelShaderATI8K( Command* defineShader, PBuffGlift* pbuff)
00041 {
00042 initMembers( defineShader, 0, pbuff );
00043 this->init();
00044 }
00045
00046 PixelShaderATI8K::PixelShaderATI8K( const PixelShaderATI8K& rhs )
00047 {
00048 initMembers( rhs );
00049 }
00050
00051 PixelShaderATI8K& PixelShaderATI8K::operator=( const PixelShaderATI8K& rhs )
00052 {
00053 if( &rhs != NULL ) {
00054 initMembers(rhs);
00055 }
00056 return *this;
00057 }
00058
00059 void PixelShaderATI8K::initMembers( const PixelShaderATI8K& rhs )
00060 {
00061 initMembers( rhs.m_defineShader->clone(), rhs.m_shaderNum, rhs.m_pbuff );
00062 }
00063
00064 void PixelShaderATI8K::initMembers( Command* defineShader, GLuint shaderNum, PBuffGlift* pbuff )
00065 {
00066 #ifndef GL_ATI_fragment_shader
00067 err() << "initMembers() Error:\n"
00068 << "\tGL_ATI_fragment_shader is not defined.\n"
00069 << "\tPixelShaderATI only available if using an ATI GPU.\n";
00070 exit(1);
00071 #endif
00072
00073 m_defineShader = defineShader;
00074 m_shaderNum = shaderNum;
00075 m_pbuff = pbuff;
00076 }
00077
00078 PixelShaderATI8K::~PixelShaderATI8K()
00079 {
00080 destroy();
00081 delete m_defineShader;
00082 }
00083
00084 void PixelShaderATI8K::setLocalConstf( unsigned int constNum, const gutz::vec4f& val )
00085 {
00086 err() << "setLocalConstf(...)\n\t"
00087 << "Operation not defined for this shader type. Only global param are available.\n\n";
00088 exit(1);
00089 }
00090
00091 void PixelShaderATI8K::destroy()
00092 {
00093 if( m_pbuff ) {
00094 m_pbuff->enable(true);
00095 }
00096
00097 #ifdef GL_ATI_fragment_shader
00098 glEnable(GL_FRAGMENT_SHADER_ATI);
00099 glDeleteFragmentShaderATI( m_shaderNum );
00100 glDisable(GL_FRAGMENT_SHADER_ATI);
00101 #endif
00102
00103 if( m_pbuff ) {
00104 m_pbuff->disable();
00105 }
00106 }
00107
00108 void PixelShaderATI8K::init()
00109 {
00110 if( m_pbuff ) {
00111 m_pbuff->enable(true);
00112 }
00113
00114 #ifdef GL_ATI_fragment_shader
00115 m_shaderNum = glGenFragmentShadersATI(1);
00116
00117 this->bindDef();
00118
00119 glBeginFragmentShaderATI();
00120 {
00121 m_defineShader->execute();
00122 }
00123 glEndFragmentShaderATI();
00124
00125 this->releaseDef();
00126 #endif
00127
00128 if( m_pbuff ) {
00129 m_pbuff->disable();
00130 }
00131 }
00132
00133 void PixelShaderATI8K::reset()
00134 {
00135 destroy();
00136 init();
00137
00138 if( isCompiled() ) {
00139 compile();
00140 }
00141 }
00142
00143 void PixelShaderATI8K::bindDef()
00144 {
00145 #ifdef GL_ATI_fragment_shader
00146 glEnable(GL_FRAGMENT_SHADER_ATI);
00147 glBindFragmentShaderATI( m_shaderNum );
00148 #endif
00149 }
00150
00151 void PixelShaderATI8K::releaseDef()
00152 {
00153 #ifdef GL_ATI_fragment_shader
00154 glDisable(GL_FRAGMENT_SHADER_ATI);
00155 #endif
00156 }
00157
00158