#ifndef __ResourceManager_H__ #define __ResourceManager_H__ #include #include #include #include #include "common.h" class igzstream; namespace CHCDemoEngine { class SceneEntity; class Material; class Geometry; class Texture; class Matrix4x4; class Transform3; class ShaderProgram; /** Loads a scene and also handles the cleanup */ class ResourceManager { public: /** Loads a model */ bool Load(const std::string &filename, SceneEntityContainer &geometry); /** Returns number of scene entities loaded with this manager. */ int GetNumEntities() const { return (int)mSceneEntities.size(); } /** Creates new gpu program parameters. */ GPUProgramParameters *CreateGPUProgramParameters(ShaderProgram *p); /** Creates a new shader program. */ ShaderProgram *CreateFragmentProgram(const std::string &filename, const std::string &funcName); ShaderProgram *CreateVertexProgram(const std::string &filename, const std::string &funcName); void EnableFragmentProfile(); void EnableVertexProfile(); void DisableFragmentProfile(); void DisableVertexProfile(); /** Returns pointer to shape container. */ const ShapeContainer * const GetShapes() const { return &mShapes; } /** Returns pointer to scene entity container. */ const SceneEntityContainer * const GetSceneEntities() const { return &mSceneEntities; } /** Returns the resource manager as a singleton. */ inline static ResourceManager *GetSingleton(); /** We also want full control over the delete. */ static void DelSingleton(); protected: /** Default constructor. The constructor is protected to have control over instantiation using the singleton pattern. */ ResourceManager(); ~ResourceManager(); void InitCg(); void LoadTextures(igzstream &str); void LoadShapes(igzstream &str); void LoadSceneEntities(igzstream &str, SceneEntityContainer &entities); SceneEntity *LoadSceneEntity(igzstream &str); Material *LoadMaterial(igzstream &str); Geometry *LoadGeometry(igzstream &str); std::map mTextureTable; std::map mMaterialTable; std::map mGeometryTable; //std::map mShapesTable; ///////////// //-- these are kept to be able to delete these resources afterwards TextureContainer mTextures; MaterialContainer mMaterials; GeometryContainer mGeometry; TransformContainer mTrafos; GPUParamContainer mGPUParameters; ShaderContainer mShaders; ShapeContainer mShapes; LODContainer mLODs; /// the scene entities SceneEntityContainer mSceneEntities; //////////// //-- default shader programs ShaderProgram *mMrtDefaultVertexProgram; ShaderProgram *mMrtDefaultFragmentProgram; ShaderProgram *mMrtDefaultFragmentTexProgram; private: static ResourceManager *sResourceManager; }; ResourceManager *ResourceManager::GetSingleton() { if (!sResourceManager) sResourceManager = new ResourceManager(); return sResourceManager; } } #endif