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