Changeset 3021


Ignore:
Timestamp:
10/10/08 13:53:22 (16 years ago)
Author:
mattausch
Message:

removed leaks. added class for shaders

Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj

    r3019 r3021  
    4242                                Optimization="0" 
    4343                                AdditionalIncludeDirectories="libs;libs/GL;libs/Devil/include;src;libs/Zlib/include;"$(CG_INC_PATH)"" 
    44                                 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS" 
     44                                PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_CRT_SET" 
    4545                                MinimalRebuild="true" 
    4646                                BasicRuntimeChecks="3" 
     
    244244                        </File> 
    245245                        <File 
     246                                RelativePath=".\src\ShaderProgram.h" 
     247                                > 
     248                        </File> 
     249                        <File 
    246250                                RelativePath=".\src\SkyPreetham.cpp" 
    247251                                > 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp

    r2951 r3021  
    77#include <cassert> 
    88#include <iostream> 
     9 
     10#ifdef _CRT_SET 
     11        #define _CRTDBG_MAP_ALLOC 
     12        #include <stdlib.h> 
     13        #include <crtdbg.h> 
     14 
     15        // redefine new operator 
     16        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     17        #define new DEBUG_NEW 
     18#endif 
     19 
    920 
    1021using namespace std; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r2963 r3021  
    1 #include <queue> 
    2 #include <stack> 
    3 #include <fstream> 
    4 #include <iostream> 
    5 #include <iomanip> 
    6  
    71#include "Bvh.h" 
    82#include "Camera.h" 
     
    159#include "Material.h" 
    1610#include "gzstream.h" 
     11 
     12#include <queue> 
     13#include <stack> 
     14#include <fstream> 
     15#include <iostream> 
     16#include <iomanip> 
     17 
     18 
     19#ifdef _CRT_SET 
     20        #define _CRTDBG_MAP_ALLOC 
     21        #include <stdlib.h> 
     22        #include <crtdbg.h> 
     23 
     24        // redefine new operator 
     25        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     26        #define new DEBUG_NEW 
     27#endif 
    1728 
    1829 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp

    r2964 r3021  
    66#include "BvhLoader.h" 
    77#include "gzstream.h" 
     8 
     9 
     10#ifdef _CRT_SET 
     11        #define _CRTDBG_MAP_ALLOC 
     12        #include <stdlib.h> 
     13        #include <crtdbg.h> 
     14 
     15        // redefine new operator 
     16        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     17        #define new DEBUG_NEW 
     18#endif 
    819 
    920 
     
    6576        BvhNode *root = LoadNextNode(stream, NULL); 
    6677 
    67 #if 0 
     78#if 1 
    6879 
    6980        bvh->mRoot = root; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp

    r3020 r3021  
    1414 
    1515 
     16#ifdef _CRT_SET 
     17        #define _CRTDBG_MAP_ALLOC 
     18        #include <stdlib.h> 
     19        #include <crtdbg.h> 
     20 
     21        // redefine new operator 
     22        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     23        #define new DEBUG_NEW 
     24#endif 
     25 
     26 
    1627using namespace std; 
    1728 
     
    6273 
    6374ShaderContainer DeferredRenderer::sShaders; 
     75 
    6476 
    6577/////////////////////////////////////// 
     
    347359DeferredRenderer::~DeferredRenderer()  
    348360{ 
     361        CLEAR_CONTAINER(mFBOs); 
     362        glDeleteTextures(1, &noiseTex); 
     363} 
     364 
     365 
     366void DeferredRenderer::SetUseTemporalCoherence(bool temporal) 
     367{ 
     368        mUseTemporalCoherence = temporal; 
     369} 
     370 
     371 
     372void DeferredRenderer::ReleaseCG() 
     373{ 
    349374        CLEAR_CONTAINER(sShaders); 
    350         CLEAR_CONTAINER(mFBOs); 
    351  
    352         glDeleteTextures(1, &noiseTex); 
    353 } 
    354  
    355  
    356 void DeferredRenderer::SetUseTemporalCoherence(bool temporal) 
    357 { 
    358         mUseTemporalCoherence = temporal; 
    359 } 
    360  
    361  
    362 void DeferredRenderer::Init(CGcontext context) 
     375} 
     376 
     377 
     378void DeferredRenderer::InitCG(CGcontext context) 
    363379{        
    364380        ShaderProgram *pr; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h

    r3019 r3021  
    44#include "common.h" 
    55#include "glInterface.h" 
     6#include "ShaderProgram.h" 
    67 
    78#include <Cg/cg.h> 
     
    2021 
    2122 
    22 class ShaderProgram 
    23 { 
    24 public: 
    2523 
    26         ShaderProgram(CGprogram program): mProgram(program) {} 
    27  
    28         ~ShaderProgram() { cgDestroyProgram(mProgram); } 
    29  
    30         CGprogram mProgram; 
    31 }; 
    32  
    33  
    34 typedef  std::vector<ShaderProgram *> ShaderContainer; 
    3524typedef  std::vector<FrameBufferObject *> FBOContainer; 
    3625 
     
    5443                a smoothing factor for temporal coherence 
    5544        */ 
     45 
     46        ~DeferredRenderer(); 
     47 
    5648        void Render(FrameBufferObject *fbo,  
    5749                        const Matrix4x4 &oldProjViewMatrix,  
     
    6355                                ); 
    6456 
    65         /** Initialises the deferred shader and loads the required shaders: 
    66                 This function has to be called only once. 
    67         */ 
    68         static void Init(CGcontext context); 
    69  
    70         ~DeferredRenderer(); 
    71  
     57         
    7258        void SetUseTemporalCoherence(bool temporal); 
    7359 
     
    7864 
    7965        void SetShadingMethod(SHADING_METHOD s); 
     66         
     67        /** Initialises the deferred shader and loads the required shaders: 
     68                This function has to be called only once. 
     69        */ 
     70        static void InitCG(CGcontext context); 
     71        /** Releases all shader resources. 
     72        */ 
     73        static void ReleaseCG(); 
     74 
    8075        static int colorBufferIdx; 
    8176 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/FrameBufferObject.cpp

    r3017 r3021  
    1 #include <iostream> 
    21#include "FrameBufferObject.h" 
    32#include "glInterface.h" 
     3#include <iostream> 
     4 
     5 
     6#ifdef _CRT_SET 
     7        #define _CRTDBG_MAP_ALLOC 
     8        #include <stdlib.h> 
     9        #include <crtdbg.h> 
     10 
     11        // redefine new operator 
     12        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     13        #define new DEBUG_NEW 
     14#endif 
     15 
    416 
    517using namespace std; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp

    r2980 r3021  
    33#include "glInterface.h" 
    44#include "RenderState.h" 
     5 
     6 
     7#ifdef _CRT_SET 
     8        #define _CRTDBG_MAP_ALLOC 
     9        #include <stdlib.h> 
     10        #include <crtdbg.h> 
     11 
     12        // redefine new operator 
     13        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     14        #define new DEBUG_NEW 
     15#endif 
    516 
    617 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Polyhedron.cpp

    r2944 r3021  
    33#include "Polygon3.h" 
    44#include "Plane3.h" 
     5 
     6 
     7#ifdef _CRT_SET 
     8        #define _CRTDBG_MAP_ALLOC 
     9        #include <stdlib.h> 
     10        #include <crtdbg.h> 
     11 
     12        // redefine new operator 
     13        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     14        #define new DEBUG_NEW 
     15#endif 
    516 
    617 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r3019 r3021  
    1313 
    1414 
     15#ifdef _CRT_SET 
     16        #define _CRTDBG_MAP_ALLOC 
     17        #include <stdlib.h> 
     18        #include <crtdbg.h> 
     19 
     20        // redefine new operator 
     21        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     22        #define new DEBUG_NEW 
     23#endif 
     24 
     25 
    1526using namespace std; 
    1627 
     
    129140                mTextureTable[i] = tex; 
    130141                mTextures.push_back(tex); 
     142 
     143                delete [] texname; 
    131144        } 
    132145 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneQuery.cpp

    r3001 r3021  
    1111 
    1212 
     13#ifdef _CRT_SET 
     14        #define _CRTDBG_MAP_ALLOC 
     15        #include <stdlib.h> 
     16        #include <crtdbg.h> 
     17 
     18        // redefine new operator 
     19        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     20        #define new DEBUG_NEW 
     21#endif 
     22 
     23 
    1324using namespace std; 
    1425 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp

    r3019 r3021  
    515515         
    516516        Polyhedron *clippedPolyhedron = box.CalcIntersection(*p); 
    517  
    518517        DEL_PTR(p); 
    519518         
     
    715714        glPopMatrix(); 
    716715 
    717          
    718716        glDisable(GL_POLYGON_OFFSET_FILL); 
    719717} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp

    r3020 r3021  
    77#include "RenderState.h" 
    88 
     9 
     10#ifdef _CRT_SET 
     11        #define _CRTDBG_MAP_ALLOC 
     12        #include <stdlib.h> 
     13        #include <crtdbg.h> 
     14 
     15        // redefine new operator 
     16        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     17        #define new DEBUG_NEW 
     18#endif 
     19 
     20 
    921using namespace CHCDemoEngine; 
    1022using namespace std; 
    11  
    1223 
    1324 
     
    2637static CGparameter sMultiplierParam; 
    2738 
     39ShaderContainer SkyPreetham::sShaders; 
    2840 
    2941 
     
    4052 
    4153 
    42 void SkyPreetham::Init(CGcontext context) 
     54void SkyPreetham::InitCG(CGcontext context) 
    4355{        
     56        ShaderProgram *pr; 
     57 
    4458        sCgSkyProgram =  
    4559                cgCreateProgramFromFile(context,  
     
    6478 
    6579                sMultiplierParam = cgGetNamedParameter(sCgSkyProgram, "multiplier"); 
     80 
     81                pr = new ShaderProgram(sCgSkyProgram); 
     82                sShaders.push_back(pr); 
    6683        } 
    6784        else 
     
    8097                cgGLLoadProgram(sCgMrtFragmentSkyDomeProgram); 
    8198                //cgGLSetParameter1f(sMaxDepthParam, MAX_DEPTH_CONST / farDist); 
     99 
     100                pr = new ShaderProgram(sCgMrtFragmentSkyDomeProgram); 
     101                sShaders.push_back(pr); 
    82102        } 
    83103        else 
    84104                cerr << "fragment skyprogram failed to load" << endl; 
     105} 
     106 
     107 
     108void SkyPreetham::ReleaseCG() 
     109{ 
     110        CLEAR_CONTAINER(sShaders); 
    85111} 
    86112 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.h

    r2983 r3021  
    44#include "glInterface.h" 
    55#include "common.h" 
     6#include "ShaderProgram.h" 
     7 
    68#include <Cg/cg.h> 
    79#include <Cg/cgGL.h> 
    810 
    911 
    10 namespace CHCDemoEngine{ 
    11 class Vector3; 
    12 class SceneEntity; 
    13 class RenderState; 
    14 class Camera; 
     12namespace CHCDemoEngine { 
     13        class Vector3; 
     14        class SceneEntity; 
     15        class RenderState; 
     16        class Camera; 
    1517} 
    1618 
     
    2022        /// Constructor taking sky turbitity as parameter and the sky dome geometry 
    2123        SkyPreetham(float turbitity, CHCDemoEngine::SceneEntity *skyDome); 
    22         virtual ~SkyPreetham(); 
     24         
     25        ~SkyPreetham(); 
    2326 
    24         void RenderSkyDome(const CHCDemoEngine::Vector3 &sunDir, CHCDemoEngine::Camera *camera, CHCDemoEngine::RenderState *state, bool scaleToRange); 
    25  
    26         static void Init(CGcontext context); 
     27        void RenderSkyDome(const CHCDemoEngine::Vector3 &sunDir,  
     28                               CHCDemoEngine::Camera *camera,  
     29                                           CHCDemoEngine::RenderState *state,  
     30                                           bool scaleToRange); 
    2731 
    2832        void ComputeFactors(const CHCDemoEngine::Vector3 &sunDir,  
     
    3539                                                 CHCDemoEngine::Vector3 &diffuse, 
    3640                                                 bool scaleToRange) const; 
     41 
     42        static void InitCG(CGcontext context); 
     43        static void ReleaseCG(); 
    3744 
    3845 
     
    5360 
    5461        float mTurbidity; 
     62 
     63        static CHCDemoEngine::ShaderContainer sShaders; 
    5564}; 
    5665 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3020 r3021  
    11// chcdemo.cpp : Defines the entry point for the console application. 
    22// 
     3 
     4 
     5#include "common.h" 
    36 
    47#ifdef _CRT_SET 
     
    69        #include <stdlib.h> 
    710        #include <crtdbg.h> 
    8 #endif 
    9  
    10 #include "common.h" 
    11  
    12 #ifdef _CRT_SET 
     11 
    1312        // redefine new operator 
    1413        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
    1514        #define new DEBUG_NEW 
    1615#endif 
    17  
    1816 
    1917#include <math.h> 
     
    490488        InitCg(); 
    491489 
    492         DeferredRenderer::Init(sCgContext); 
    493         SkyPreetham::Init(sCgContext); 
     490        DeferredRenderer::InitCG(sCgContext); 
     491        SkyPreetham::InitCG(sCgContext); 
    494492 
    495493        Vector3 cubeCenter(470.398f, 240.364f, 182.5f); 
     
    17881786                cgDestroyProgram(RenderState::sCgMrtFragmentTexProgram); 
    17891787         
     1788        DeferredRenderer::ReleaseCG(); 
     1789        SkyPreetham::ReleaseCG(); 
     1790 
    17901791        if (sCgContext) 
    17911792                cgDestroyContext(sCgContext); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.cpp

    r3019 r3021  
     1#include "common.h" 
     2 
     3#ifdef _X_WINDOW_ 
     4#include "xwindow.h" 
     5#endif 
     6 
     7#ifdef _CRT_SET 
     8        #define _CRTDBG_MAP_ALLOC 
     9        #include <stdlib.h> 
     10        #include <crtdbg.h> 
     11 
     12        // redefine new operator 
     13        #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) 
     14        #define new DEBUG_NEW 
     15#endif 
     16 
     17#include <stdlib.h> 
    118#include <math.h> 
    219#include <stdio.h> 
    3 #include <stdlib.h> 
    420#include <time.h> 
    5  
    6 #include "common.h" 
    7  
    8 #ifdef _X_WINDOW_ 
    9 #include "xwindow.h" 
    10 #endif 
    1121 
    1222#ifndef _MSC_VER 
     
    2131#include <sys/timeb.h> 
    2232#endif 
     33 
    2334 
    2435 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h

    r3019 r3021  
    504504#define INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES 1000 
    505505 
    506  
    507 } 
    508  
    509 #endif 
    510  
    511  
    512  
    513  
    514  
    515  
    516  
    517  
     506} 
     507 
     508 
     509 
     510#endif 
     511 
     512 
     513 
     514 
     515 
     516 
     517 
     518 
Note: See TracChangeset for help on using the changeset viewer.