You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
9 years ago
|
#ifndef OPENMW_COMPONENTS_SHADERMANAGER_H
|
||
|
#define OPENMW_COMPONENTS_SHADERMANAGER_H
|
||
|
|
||
|
#include <string>
|
||
|
#include <map>
|
||
|
|
||
|
#include <osg/ref_ptr>
|
||
|
|
||
|
#include <osg/Shader>
|
||
|
|
||
|
#include <OpenThreads/Mutex>
|
||
|
|
||
|
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<std::string, std::string> 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<osg::Shader> getShader(const std::string& shaderTemplate, const DefineMap& defines, osg::Shader::Type shaderType);
|
||
|
|
||
|
private:
|
||
|
std::string mPath;
|
||
|
|
||
|
// <name, code>
|
||
|
typedef std::map<std::string, std::string> TemplateMap;
|
||
|
TemplateMap mShaderTemplates;
|
||
|
|
||
|
typedef std::pair<std::string, DefineMap> MapKey;
|
||
|
typedef std::map<MapKey, osg::ref_ptr<osg::Shader> > ShaderMap;
|
||
|
ShaderMap mShaders;
|
||
|
|
||
|
OpenThreads::Mutex mMutex;
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
#endif
|