00001
00002
00003
00004
00005
00006 #include "computeSlab.h"
00007 #include <mm.h>
00008 #include <assert.h>
00009
00010 ComputeSlab::ComputeSlab( const VecTexPtr& vecInTex, GlewShadeLang lang, const Vec2i& dimen, GLfloat z )
00011 {
00012 initInputMembers( vecInTex, lang, NULL, NULL, dimen, z );
00013 }
00014
00015 ComputeSlab::ComputeSlab( const VecTexPtr& vecInTex, GlewShadeLang lang, PBuffer* pbuffDest,
00016 const Vec2i& dimen, GLfloat z )
00017 {
00018 if( pbuffDest==NULL ) {
00019 err() << "ComputeSlab(...) Error:\n"
00020 << "\tpbuffDest == NULL.\n";
00021 exit(1);
00022 }
00023
00024 initInputMembers( vecInTex, lang, pbuffDest, NULL, dimen, z );
00025 }
00026
00027 ComputeSlab::ComputeSlab( const VecTexPtr& vecInTex, GlewShadeLang lang, BasicTexture* texDest,
00028 const Vec2i& dimen, GLfloat z )
00029 {
00030 if( texDest==NULL ) {
00031 err() << "ComputeSlab(...) Error:\n"
00032 << "\ttexDest == NULL.\n";
00033 exit(1);
00034 }
00035
00036 initInputMembers( vecInTex, lang, NULL, texDest, dimen, z );
00037 }
00038
00039 void ComputeSlab::initInputMembers( const VecTexPtr& vecInTex, GlewShadeLang lang,
00040 PBuffer* pbuffDest, BasicTexture* texDest,
00041 const Vec2i& dimen, GLfloat z )
00042 {
00043 m_texInput = new MultiTexture( vecInTex );
00044 m_lang = lang;
00045 m_pbuffDest = pbuffDest;
00046 m_texDest = texDest;
00047 m_dimen = dimen;
00048 m_z = z;
00049
00050 m_pass = NULL;
00051 m_pixShader = NULL;
00052 m_texPerturb = NULL;
00053 m_progShader = NULL;
00054 m_shader = NULL;
00055 m_quad = NULL;
00056 m_shadedPrim = NULL;
00057 }
00058
00059 void ComputeSlab::create( PixelShader* pixShader )
00060 {
00061
00062 m_pixShader = pixShader;
00063 m_texPerturb = texPerturbs( m_dimen );
00064 m_progShader = new ProgShader( numTexUnits(), m_pixShader, m_texPerturb );
00065
00066 m_shader = new Shader( m_texInput, m_progShader );
00067 m_quad = new PlanarQuad( Vec2f(0.0), Vec2f(m_dimen.w, m_dimen.h), m_z, true );
00068 m_shadedPrim = new ShadedPrim( m_quad, m_shader );
00069 m_pass = new RenderPass( m_shadedPrim, m_texDest, m_pbuffDest );
00070
00071
00072 assert( m_pixShader != NULL );
00073 assert( m_progShader != NULL );
00074 assert( m_shader != NULL );
00075 assert( m_quad != NULL );
00076 assert( m_shadedPrim != NULL );
00077 assert( nand(m_pbuffDest, m_texDest) );
00078 assert( m_pass != NULL );
00079
00080 derr("ComputeSlab::create(...): RenderPass created.);
00081 }
00082
00083 ComputeSlab::ComputeSlab( const ComputeSlab& rhs )
00084 {
00085 copyMembers(rhs);
00086 }
00087
00088 ComputeSlab& ComputeSlab::operator=( const ComputeSlab& rhs )
00089 {
00090 if( &rhs != this ) {
00091 copyMembers(rhs);
00092 }
00093 return *this;
00094 }
00095
00096 void ComputeSlab::copyMembers( const ComputeSlab& rhs )
00097 {
00098 copyMembers( rhs.m_pass, rhs.m_dimen, rhs.m_z, rhs.m_pbuffDest, rhs.m_texDest, rhs.m_lang,
00099 rhs.m_texInput, rhs.m_pixShader, rhs.m_shadedPrim, rhs.m_progShader,
00100 rhs.m_quad, rhs.m_shader, rhs.m_texPerturb );
00101 }
00102
00103 void ComputeSlab::copyMembers( RenderPass* pass, const Vec2i& dimen, GLfloat z, PBuffer* pbuffDest,
00104 BasicTexture* texDest, GlewShadeLang lang,
00105 MultiTexture* texInput, PixelShader* pixShader, ShadedPrim* shadedPrim,
00106 ProgShader* progShader, RawPrim* quad, Shader* shader,
00107 TexCoordPerturb* texPerturb )
00108 {
00109 // These are input vars so they are shallow-copied.
00110 m_dimen = dimen;
00111 m_z = z;
00112 m_pbuffDest = pbuffDest;
00113 m_texDest = texDest;
00114 m_lang = lang;
00115
00116 reset(); // Delete all instance-allocated memory.
00117
00118 // These are generated by each intance so they get deep-copied.
00119 // TODO: Call ->clone() on all of these...make a clone for ALL objects!!!
00120 m_texInput = texInput;
00121 m_pass = pass;
00122 m_pixShader = pixShader;
00123 m_shadedPrim = shadedPrim;
00124 m_progShader = progShader;
00125 m_quad = quad;
00126 m_shader = shader;
00127 m_texPerturb = texPerturb;
00128 }
00129
00130 ComputeSlab::~ComputeSlab()
00131 {
00132 reset();
00133 }
00134
00135 void ComputeSlab::reset()
00136 {
00137 delete m_pass;
00138 delete m_pixShader;
00139 delete m_shadedPrim;
00140 delete m_progShader;
00141 delete m_quad;
00142 delete m_shader;
00143 delete m_texPerturb;
00144 delete m_texInput;
00145 }
00146
00147 void ComputeSlab::render()
00148 {
00149 // This is here b/c we need the fully-constructed "this" pointer for initialization
00150 // so the constructor cannot do it (not ANSI-safe to do so even though VS 6.0 allows it).
00151 if( !m_pass ) {
00152 create( makePixShader(this) );
00153 }
00154
00155 m_pass->render();
00156 }
00157
00158 void ComputeSlab::resetShader()
00159 {
00160 if( !m_pixShader ) {
00161 create( makePixShader(this) );
00162 }
00163
00164 m_pixShader->reset();
00165 }
00166
00167 TexCoordPerturb* ComputeSlab::getTexPerturbs( const Vec2i& dimen )
00168 {
00169 return NULL;
00170 }
00171
00172 void ComputeSlab::pixShaderATI()
00173 {
00174 err() << "pixShaderATI() Error:\n"
00175 << "\tVirtual Function not defined in base class.\n";
00176 exit(1);
00177 }
00178
00179 void ComputeSlab::pixShaderNV20()
00180 {
00181 err() << "pixShaderNV20() Error:\n"
00182 << "\tVirtual Function not defined in base class.\n";
00183 exit(1);
00184 }
00185
00186 void ComputeSlab::pixShaderNV30()
00187 {
00188 err() << "pixShaderNV30() Error:\n"
00189 << "\tVirtual Function not defined in base class.\n";
00190 exit(1);
00191 }
00192
00193 void ComputeSlab::pixShaderCG()
00194 {
00195 err() << "pixShaderCG() Error:\n"
00196 << "\tVirtual Function not defined in base class.\n";
00197 exit(1);
00198 }
00199