1 | #ifndef __ResourceManager_H__
|
---|
2 | #define __ResourceManager_H__
|
---|
3 |
|
---|
4 |
|
---|
5 | #include <string>
|
---|
6 | #include <iostream>
|
---|
7 | #include <fstream>
|
---|
8 | #include <map>
|
---|
9 | #include "common.h"
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 | class igzstream;
|
---|
14 |
|
---|
15 |
|
---|
16 | namespace CHCDemoEngine
|
---|
17 | {
|
---|
18 |
|
---|
19 | class SceneEntity;
|
---|
20 | class Material;
|
---|
21 | class Geometry;
|
---|
22 | class Texture;
|
---|
23 | class Matrix4x4;
|
---|
24 | class Transform3;
|
---|
25 | class ShaderProgram;
|
---|
26 |
|
---|
27 |
|
---|
28 | /** Loads a scene and also handles the cleanup
|
---|
29 | */
|
---|
30 | class ResourceManager
|
---|
31 | {
|
---|
32 | public:
|
---|
33 |
|
---|
34 | /** Returns the resource manager as a singleton.
|
---|
35 | */
|
---|
36 | static ResourceManager *GetSingleton()
|
---|
37 | {
|
---|
38 | if (!sResourceManager)
|
---|
39 | {
|
---|
40 | sResourceManager = new ResourceManager();
|
---|
41 | }
|
---|
42 |
|
---|
43 | return sResourceManager;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /** We also want full control over the delete.
|
---|
47 | */
|
---|
48 | static void DelSingleton()
|
---|
49 | {
|
---|
50 | DEL_PTR(sResourceManager);
|
---|
51 | }
|
---|
52 |
|
---|
53 | /** Loads a model
|
---|
54 | */
|
---|
55 | bool Load(const std::string &filename, SceneEntityContainer &geometry);
|
---|
56 |
|
---|
57 | int GetNumEntities() const { return (int)mSceneEntities.size(); }
|
---|
58 |
|
---|
59 | /** Creates new gpu program parameters.
|
---|
60 | */
|
---|
61 | GPUProgramParameters *CreateGPUProgramParameters(ShaderProgram *p);
|
---|
62 | /** Creates a new shader program.
|
---|
63 | */
|
---|
64 | ShaderProgram *CreateFragmentProgram(const std::string &filename, const std::string &funcName);
|
---|
65 | ShaderProgram *CreateVertexProgram(const std::string &filename, const std::string &funcName);
|
---|
66 |
|
---|
67 | void EnableFragmentProfile();
|
---|
68 | void EnableVertexProfile();
|
---|
69 |
|
---|
70 | void DisableFragmentProfile();
|
---|
71 | void DisableVertexProfile();
|
---|
72 |
|
---|
73 |
|
---|
74 | protected:
|
---|
75 |
|
---|
76 | /** Default constructor. The constructor is protected
|
---|
77 | to have control over instantiation using the
|
---|
78 | singleton pattern.
|
---|
79 | */
|
---|
80 | ResourceManager();
|
---|
81 |
|
---|
82 | ~ResourceManager();
|
---|
83 |
|
---|
84 |
|
---|
85 | void InitCg();
|
---|
86 |
|
---|
87 | void LoadTextures(igzstream &str);
|
---|
88 | void LoadShapes(igzstream &str);
|
---|
89 | void LoadSceneEntities(igzstream &str, SceneEntityContainer &entities);
|
---|
90 |
|
---|
91 | SceneEntity *LoadSceneEntity(igzstream &str);
|
---|
92 | Material *LoadMaterial(igzstream &str);
|
---|
93 | Geometry *LoadGeometry(igzstream &str);
|
---|
94 |
|
---|
95 | std::map<int, Texture *> mTextureTable;
|
---|
96 | std::map<int, Material *> mMaterialTable;
|
---|
97 | std::map<int, Geometry *> mGeometryTable;
|
---|
98 | //std::map<int, Shape *> mShapesTable;
|
---|
99 |
|
---|
100 |
|
---|
101 | /////////////
|
---|
102 | //-- these are kept to be able to delete these resources afterwards
|
---|
103 |
|
---|
104 | TextureContainer mTextures;
|
---|
105 | MaterialContainer mMaterials;
|
---|
106 | GeometryContainer mGeometry;
|
---|
107 | TransformContainer mTrafos;
|
---|
108 | GPUParamContainer mGPUParameters;
|
---|
109 | ShaderContainer mShaders;
|
---|
110 | ShapeContainer mShapes;
|
---|
111 | LODContainer mLODs;
|
---|
112 |
|
---|
113 | ////////
|
---|
114 |
|
---|
115 | /// the scene entities
|
---|
116 |
|
---|
117 | SceneEntityContainer mSceneEntities;
|
---|
118 |
|
---|
119 |
|
---|
120 | ////////////
|
---|
121 | //-- default shader programs
|
---|
122 |
|
---|
123 | ShaderProgram *mMrtDefaultVertexProgram;
|
---|
124 | ShaderProgram *mMrtDefaultFragmentProgram;
|
---|
125 | ShaderProgram *mMrtDefaultFragmentTexProgram;
|
---|
126 |
|
---|
127 |
|
---|
128 | private:
|
---|
129 |
|
---|
130 | static ResourceManager *sResourceManager;
|
---|
131 | };
|
---|
132 |
|
---|
133 |
|
---|
134 | }
|
---|
135 | #endif
|
---|