Ignore:
Timestamp:
10/15/08 01:51:10 (16 years ago)
Author:
mattausch
Message:

shader working but slow

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp

    r3028 r3031  
    5757void Material::Render(RenderState *state) 
    5858{ 
    59         state->SetState(mTexture != NULL, mAlphaTestEnabled, mCullFaceEnabled); 
    60  
    61         state->SetTexture(mTexture); 
     59        state->SetState(mTexture, mAlphaTestEnabled, mCullFaceEnabled); 
    6260 
    6361        glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp

    r3028 r3031  
    1515ShaderProgram *RenderState::sCgMrtFragmentProgram = NULL; 
    1616ShaderProgram *RenderState::sCgMrtFragmentTexProgram = NULL; 
     17ShaderProgram *RenderState::sCgMrtVertexProgram = NULL; 
     18 
     19 
    1720int RenderState::sTexParam; 
    1821 
     
    3437 
    3538         
    36 bool RenderState::SetState(Mode mode) 
     39bool RenderState::SetMode(Mode mode) 
    3740{ 
    3841        /////////// 
     
    8588 
    8689         
    87 void RenderState::SetState(bool texturing, bool alphaTest, bool cullFace) 
    88 { 
     90void RenderState::SetState(Texture *tex, bool alphaTest, bool cullFace) 
     91{ 
     92        const bool texturing = (tex != NULL); 
     93 
    8994        if (!mLockCullFaceEnabled) 
    9095        { 
     
    146151                } 
    147152        } 
     153 
     154        SetTexture(tex); 
    148155} 
    149156 
     
    166173        glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
    167174 
    168         SetState(RENDER); 
     175        SetMode(RENDER); 
    169176} 
    170177 
     
    196203void RenderState::SetTexture(Texture *tex) 
    197204{ 
    198         if (tex) 
    199         { 
    200                 if (GetRenderPassType() == RenderState::DEFERRED) 
    201                 { 
    202                         RenderState::sCgMrtFragmentProgram->SetTexture("tex", tex->GetId()); 
    203                 } 
    204                 else 
    205                 { 
     205        if (GetRenderPassType() == RenderState::DEFERRED) 
     206        { 
     207                if (tex) 
     208                        RenderState::sCgMrtFragmentTexProgram->SetTexture("tex", tex->GetId()); 
     209        } 
     210        else 
     211        { 
     212                if (tex) 
    206213                        tex->Bind(); 
    207                 } 
    208         } 
    209         else 
    210         { 
    211                 if (!GetRenderPassType() == RenderState::DEFERRED) 
     214                else 
    212215                        glBindTexture(GL_TEXTURE_2D, 0);                 
    213216        } 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h

    r3028 r3031  
    4444                change was issued. 
    4545        */ 
    46         bool SetState(Mode mode); 
     46        bool SetMode(Mode mode); 
    4747        /** Sets the current render state. 
    4848        */ 
    49         void SetState(bool texturing, bool alphaTest, bool cullFace); 
     49        void SetState(Texture *tex, bool alphaTest, bool cullFace); 
    5050        /** Returns either query or render mode 
    5151        */ 
     
    8686        static ShaderProgram *sCgMrtFragmentProgram; 
    8787        static ShaderProgram *sCgMrtFragmentTexProgram; 
     88        static ShaderProgram *sCgMrtVertexProgram; 
    8889 
    8990        static int sTexParam; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r2954 r3031  
    9797        if (node->GetLastRenderedFrame() != mFrameId) 
    9898        { 
    99                 if (mRenderState->SetState(RenderState::RENDER)) 
     99                if (mRenderState->SetMode(RenderState::RENDER)) 
    100100                        ++ mStats.mNumStateChanges; 
    101101                 
     
    254254 
    255255        // change to query mode and render box 
    256         if (mRenderState->SetState(RenderState::QUERY)) 
     256        if (mRenderState->SetMode(RenderState::QUERY)) 
    257257                ++ mStats.mNumStateChanges; 
    258258 
     
    265265void RenderTraverser::ApplyRenderQueue() 
    266266{ 
    267         if (mRenderState->SetState(RenderState::RENDER)) 
     267        if (mRenderState->SetMode(RenderState::RENDER)) 
    268268                ++ mStats.mNumStateChanges; 
    269269                  
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp

    r3030 r3031  
    9292 
    9393        cgGLSetTextureParameter(p, tex); 
     94        cgGLEnableTextureParameter(p); 
     95 
    9496        mTextureParams.push_back(p); 
    9597} 
     
    101103 
    102104        // enable all texture parameters 
    103         /*CGParameterArray::const_iterator it, it_end = mTextureParams.end(); 
     105        CGParameterArray::const_iterator it, it_end = mTextureParams.end(); 
     106 
    104107        for (it = mTextureParams.begin(); it != it_end; ++ it)  
    105108                cgGLEnableTextureParameter(*it); 
    106         */ 
    107109} 
    108110 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp

    r2960 r3031  
    11#include "Transform3.h" 
    22#include "RenderState.h" 
     3#include "ShaderProgram.h" 
    34 
    45 
     
    3334        if (state->GetRenderPassType() == RenderState::DEFERRED) 
    3435        { 
    35                 cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix.x); 
     36                //cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix.x); 
     37                RenderState::sCgMrtVertexProgram->SetMatrix("modelView", mMatrix); 
    3638        } 
    3739 
     
    4951        { 
    5052                static Matrix4x4 identity = IdentityMatrix(); 
    51                 cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x); 
     53                RenderState::sCgMrtVertexProgram->SetMatrix("modelView", identity); 
    5254        } 
    5355 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3028 r3031  
    282282static CGcontext sCgContext = NULL; 
    283283 
    284 ShaderProgram *sCgMrtVertexProgram = NULL; 
    285  
    286284static CGparameter sEyePosParamTex; 
    287285static CGparameter sEyePosParam; 
     
    490488        InitCg(); 
    491489 
    492         DeferredRenderer::InitCG(sCgContext); 
    493         SkyPreetham::InitCG(sCgContext); 
    494  
    495490        Vector3 cubeCenter(470.398f, 240.364f, 182.5f); 
    496491         
     
    557552        cgGLSetManageTextureParameters(sCgContext, true); 
    558553 
    559         sCgMrtVertexProgram =  
    560                 new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgFragmentProfile, "vtx"); 
    561  
    562         if (!sCgMrtVertexProgram->IsValid()) 
     554        RenderState::sCgMrtVertexProgram =  
     555                new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgVertexProfile, "vtx"); 
     556 
     557        if (!RenderState::sCgMrtVertexProgram->IsValid()) 
    563558                cerr << "fragment program failed to load" << endl; 
    564559 
     
    567562 
    568563        if (!RenderState::sCgMrtFragmentTexProgram->IsValid()) 
    569                 cerr << "fragment program failed to load" << endl; 
     564                cerr << "fragment tex program failed to load" << endl; 
    570565 
    571566        RenderState::sCgMrtFragmentProgram =  
     
    577572 
    578573        PrintGLerror("init"); 
     574 
     575        DeferredRenderer::InitCG(sCgContext); 
     576        SkyPreetham::InitCG(sCgContext); 
    579577 
    580578        cout << "cg initialization successful" << endl; 
     
    856854        if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED)) 
    857855        { 
    858                 cgGLSetMatrixParameterfc(Transform3::sModelMatrixParam, (const float *)IdentityMatrix().x); 
     856                RenderState::sCgMrtVertexProgram->SetMatrix("modelView", IdentityMatrix()); 
    859857        } 
    860858} 
     
    908906 
    909907        cgGLEnableProfile(RenderState::sCgVertexProfile); 
    910         sCgMrtVertexProgram->Bind(); 
     908        RenderState::sCgMrtVertexProgram->Bind(); 
    911909 
    912910        cgGLEnableProfile(RenderState::sCgFragmentProfile); 
     
    915913        const Vector3 pos = camera->GetPosition(); 
    916914 
    917         cgGLSetParameter3f(sEyePosParam, pos.x, pos.y, pos.z); 
    918         cgGLSetParameter3f(sEyePosParamTex, pos.x, pos.y, pos.z); 
     915        RenderState::sCgMrtFragmentProgram->SetValue3f("eyePos", pos.x, pos.y, pos.z); 
     916        RenderState::sCgMrtFragmentTexProgram->SetValue3f("eyePos", pos.x, pos.y, pos.z); 
    919917 
    920918 
     
    17511749        DEL_PTR(RenderState::sCgMrtFragmentProgram); 
    17521750        DEL_PTR(RenderState::sCgMrtFragmentTexProgram); 
    1753         DEL_PTR(sCgMrtVertexProgram); 
     1751        DEL_PTR(RenderState::sCgMrtVertexProgram); 
    17541752         
    17551753        DeferredRenderer::ReleaseCG(); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg

    r3018 r3031  
    4343 
    4444vtxout vtx(vtxin IN,  
    45                    const uniform float4x4 ModelViewProj, 
    46                    uniform float4x4 ModelView) 
     45                   uniform float4x4 modelView) 
    4746{ 
    4847        vtxout OUT; 
     
    5251 
    5352        //OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position); 
    54         OUT.worldPos = mul(ModelView, IN.position); 
     53        OUT.worldPos = mul(modelView, IN.position); 
    5554        // transform the vertex position into eye space 
    5655        OUT.position = mul(glstate.matrix.mvp, IN.position); 
     
    7574 
    7675pixel fragtex(fragin IN,  
    77                           uniform sampler2D dirtTex, 
    7876                          uniform sampler2D tex, 
    7977                          uniform float3 eyePos, 
Note: See TracChangeset for help on using the changeset viewer.