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

116 lines
2.3 KiB
C
Raw Normal View History

// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
#ifndef PROGRAM_SHADER_CACHE_H_
#define PROGRAM_SHADER_CACHE_H_
#include "GLUtil.h"
#include "PixelShaderGen.h"
#include "VertexShaderGen.h"
#include "LinearDiskCache.h"
#include "ConfigManager.h"
namespace OGL
{
class SHADERUID
{
public:
VertexShaderUid vuid;
PixelShaderUid puid;
SHADERUID() {}
SHADERUID(const SHADERUID& r) : vuid(r.vuid), puid(r.puid) {}
bool operator <(const SHADERUID& r) const
{
if(puid < r.puid) return true;
if(r.puid < puid) return false;
if(vuid < r.vuid) return true;
return false;
}
bool operator ==(const SHADERUID& r) const
{
return puid == r.puid && vuid == r.vuid;
}
};
const int NUM_UNIFORMS = 19;
extern const char *UniformNames[NUM_UNIFORMS];
struct SHADER
{
SHADER() : glprogid(0) { }
void Destroy()
{
glDeleteProgram(glprogid);
glprogid = 0;
}
GLuint glprogid; // opengl program id
std::string strvprog, strpprog;
GLint UniformLocations[NUM_UNIFORMS];
2013-08-23 09:52:47 -06:00
u32 UniformSize[NUM_UNIFORMS];
void SetProgramVariables();
void SetProgramBindings();
void Bind();
};
class ProgramShaderCache
{
public:
2011-12-11 03:08:18 -07:00
struct PCacheEntry
2011-12-11 03:08:18 -07:00
{
SHADER shader;
2013-02-13 08:30:15 -07:00
bool in_cache;
void Destroy()
{
shader.Destroy();
}
};
2013-03-29 08:08:00 -06:00
typedef std::map<SHADERUID, PCacheEntry> PCache;
static PCacheEntry GetShaderProgram(void);
static GLuint GetCurrentProgram(void);
static SHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
static void GetShaderId(SHADERUID *uid, DSTALPHA_MODE dstAlphaMode, u32 components);
static bool CompileShader(SHADER &shader, const char* vcode, const char* pcode);
static GLuint CompileSingleShader(GLuint type, const char *code);
static void UploadConstants();
static void Init(void);
static void Shutdown(void);
2013-02-13 13:34:48 -07:00
static void CreateHeader(void);
private:
class ProgramShaderCacheInserter : public LinearDiskCacheReader<SHADERUID, u8>
{
public:
void Read(const SHADERUID &key, const u8 *value, u32 value_size);
2011-12-11 03:08:18 -07:00
};
2011-12-11 03:08:18 -07:00
static PCache pshaders;
static PCacheEntry* last_entry;
static SHADERUID last_uid;
2011-12-11 03:08:18 -07:00
2013-04-29 13:00:39 -06:00
static UidChecker<PixelShaderUid,PixelShaderCode> pixel_uid_checker;
static UidChecker<VertexShaderUid,VertexShaderCode> vertex_uid_checker;
static u32 s_ubo_buffer_size;
static s32 s_ubo_align;
};
} // namespace OGL
#endif