#ifndef OPENMW_COMPONENTS_SHADERMANAGER_H #define OPENMW_COMPONENTS_SHADERMANAGER_H #include #include #include #include #include namespace Shader { /// @brief Reads shader template files and turns them into a concrete shader, based on a list of define's. /// @par Shader templates can get the value of a define with the syntax @define. class ShaderManager { public: void setShaderPath(const std::string& path); typedef std::map DefineMap; /// Create or retrieve a shader instance. /// @param shaderTemplate The filename of the shader template. /// @param defines Define values that can be retrieved by the shader template. /// @param shaderType The type of shader (usually vertex or fragment shader). /// @note May return NULL on failure. /// @note Thread safe. osg::ref_ptr getShader(const std::string& shaderTemplate, const DefineMap& defines, osg::Shader::Type shaderType); osg::ref_ptr getProgram(osg::ref_ptr vertexShader, osg::ref_ptr fragmentShader); void releaseGLObjects(osg::State* state); private: std::string mPath; // typedef std::map TemplateMap; TemplateMap mShaderTemplates; typedef std::pair MapKey; typedef std::map > ShaderMap; ShaderMap mShaders; typedef std::map, osg::ref_ptr >, osg::ref_ptr > ProgramMap; ProgramMap mPrograms; OpenThreads::Mutex mMutex; }; } #endif