42 lines
1.0 KiB
C++
42 lines
1.0 KiB
C++
#ifndef WC3RE_RENDER_PROGRAMPROVIDER_HH__
|
|
#define WC3RE_RENDER_PROGRAMPROVIDER_HH__
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "Singleton.hh"
|
|
#include "GlResource.hh"
|
|
namespace render {
|
|
using ProgramProviderKeyType = std::tuple<std::string, std::string>;
|
|
}
|
|
|
|
namespace std
|
|
{
|
|
template<>
|
|
struct hash<render::ProgramProviderKeyType> {
|
|
typedef render::ProgramProviderKeyType argument_type;
|
|
typedef std::size_t result_type;
|
|
|
|
result_type operator()(argument_type const& s) const {
|
|
const result_type h1{std::hash<std::string>()(std::get<0>(s))};
|
|
const result_type h2{std::hash<std::string>()(std::get<1>(s))};
|
|
return h1 ^ h2;
|
|
}
|
|
};
|
|
}
|
|
|
|
namespace render {
|
|
class ProgramProvider : public Singleton<ProgramProvider> {
|
|
private:
|
|
ProgramProvider();
|
|
friend class Singleton<ProgramProvider>;
|
|
|
|
public:
|
|
gl::GLuint getProgram(std::string const& vertexShader, std::string const& fragShader);
|
|
|
|
private:
|
|
std::unordered_map<ProgramProviderKeyType, ProgramResource> programCache_;
|
|
};
|
|
}
|
|
|
|
#endif
|