dolphin/Source/Core/VideoBackends/OGL/ProgramShaderCache.h

122 lines
2.5 KiB
C
Raw Normal View History

// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#pragma once
#include "Common/LinearDiskCache.h"
#include "Core/ConfigManager.h"
#include "VideoBackends/OGL/GLUtil.h"
2014-10-30 22:40:03 +00:00
#include "VideoCommon/GeometryShaderGen.h"
#include "VideoCommon/PixelShaderGen.h"
#include "VideoCommon/VertexShaderGen.h"
namespace OGL
{
class SHADERUID
{
public:
VertexShaderUid vuid;
PixelShaderUid puid;
GeometryShaderUid guid;
SHADERUID() {}
SHADERUID(const SHADERUID& r) : vuid(r.vuid), puid(r.puid), guid(r.guid) {}
bool operator <(const SHADERUID& r) const
{
if (puid < r.puid)
return true;
if (r.puid < puid)
return false;
if (vuid < r.vuid)
return true;
if (r.vuid < vuid)
return false;
if (guid < r.guid)
return true;
return false;
}
bool operator ==(const SHADERUID& r) const
{
return puid == r.puid && vuid == r.vuid && guid == r.guid;
}
};
struct SHADER
{
SHADER() : glprogid(0) { }
void Destroy()
{
glDeleteProgram(glprogid);
glprogid = 0;
}
2014-11-14 19:46:49 +00:00
GLuint glprogid; // OpenGL program id
std::string strvprog, strpprog, strgprog;
void SetProgramVariables();
void SetProgramBindings();
void Bind();
};
class ProgramShaderCache
{
public:
2011-12-11 10:08:18 +00:00
struct PCacheEntry
2011-12-11 10:08:18 +00:00
{
SHADER shader;
2013-02-13 15:30:15 +00:00
bool in_cache;
void Destroy()
{
shader.Destroy();
}
};
2013-03-29 14:08:00 +00:00
typedef std::map<SHADERUID, PCacheEntry> PCache;
static PCacheEntry GetShaderProgram();
static GLuint GetCurrentProgram();
static SHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components, u32 primitive_type);
static void GetShaderId(SHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 components, u32 primitive_type);
static bool CompileShader(SHADER &shader, const char* vcode, const char* pcode, const char* gcode = nullptr);
static GLuint CompileSingleShader(GLuint type, const char *code);
static void UploadConstants();
static void Init();
static void Shutdown();
static void CreateHeader();
private:
class ProgramShaderCacheInserter : public LinearDiskCacheReader<SHADERUID, u8>
{
public:
void Read(const SHADERUID &key, const u8 *value, u32 value_size) override;
2011-12-11 10:08:18 +00:00
};
2011-12-11 10:08:18 +00:00
static PCache pshaders;
static PCacheEntry* last_entry;
static SHADERUID last_uid;
2011-12-11 10:08:18 +00:00
2013-04-29 19:00:39 +00:00
static UidChecker<PixelShaderUid,PixelShaderCode> pixel_uid_checker;
static UidChecker<VertexShaderUid,VertexShaderCode> vertex_uid_checker;
static UidChecker<GeometryShaderUid,ShaderCode> geometry_uid_checker;
2013-04-29 19:00:39 +00:00
static u32 s_ubo_buffer_size;
static s32 s_ubo_align;
};
} // namespace OGL