// Copyright 2015 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. #pragma once #include #include #include "VideoCommon/GeometryShaderGen.h" #include "VideoCommon/PixelShaderGen.h" #include "VideoCommon/VertexShaderGen.h" #include "VideoCommon/VideoCommon.h" namespace Null { template class ShaderCache { public: ShaderCache(); virtual ~ShaderCache(); void Clear(); bool SetShader(u32 primitive_type); protected: virtual Uid GetUid(u32 primitive_type, APIType api_type) = 0; virtual ShaderCode GenerateCode(APIType api_type, Uid uid) = 0; private: std::map m_shaders; const std::string* m_last_entry = nullptr; Uid m_last_uid; }; class VertexShaderCache : public ShaderCache { public: static std::unique_ptr s_instance; protected: VertexShaderUid GetUid(u32 primitive_type, APIType api_type) override { return GetVertexShaderUid(); } ShaderCode GenerateCode(APIType api_type, VertexShaderUid uid) override { return GenerateVertexShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData()); } }; class GeometryShaderCache : public ShaderCache { public: static std::unique_ptr s_instance; protected: GeometryShaderUid GetUid(u32 primitive_type, APIType api_type) override { return GetGeometryShaderUid(primitive_type); } ShaderCode GenerateCode(APIType api_type, GeometryShaderUid uid) override { return GenerateGeometryShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData()); } }; class PixelShaderCache : public ShaderCache { public: static std::unique_ptr s_instance; protected: PixelShaderUid GetUid(u32 primitive_type, APIType api_type) override { return GetPixelShaderUid(); } ShaderCode GenerateCode(APIType api_type, PixelShaderUid uid) override { return GeneratePixelShaderCode(api_type, ShaderHostConfig::GetCurrent(), uid.GetUidData()); } }; } // namespace NULL