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
|
|
|
|
2016-01-01 20:28:42 -07:00
|
|
|
#include <tuple>
|
|
|
|
|
2015-09-18 10:40:00 -06:00
|
|
|
#include "Common/GL/GLUtil.h"
|
2016-06-24 02:43:46 -06:00
|
|
|
#include "Common/LinearDiskCache.h"
|
2015-09-18 10:40:00 -06:00
|
|
|
|
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
|
|
|
{
|
2013-03-26 15:16:29 -06:00
|
|
|
class SHADERUID
|
2013-02-13 05:12:19 -07:00
|
|
|
{
|
|
|
|
public:
|
2016-06-24 02:43:46 -06:00
|
|
|
VertexShaderUid vuid;
|
|
|
|
PixelShaderUid puid;
|
|
|
|
GeometryShaderUid guid;
|
|
|
|
|
|
|
|
bool operator<(const SHADERUID& r) const
|
|
|
|
{
|
|
|
|
return std::tie(puid, vuid, guid) < std::tie(r.puid, r.vuid, r.guid);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const SHADERUID& r) const
|
|
|
|
{
|
|
|
|
return std::tie(puid, vuid, guid) == std::tie(r.puid, r.vuid, r.guid);
|
|
|
|
}
|
2013-02-13 05:12:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SHADER
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
SHADER() : glprogid(0) {}
|
|
|
|
void Destroy()
|
|
|
|
{
|
|
|
|
glDeleteProgram(glprogid);
|
|
|
|
glprogid = 0;
|
|
|
|
}
|
|
|
|
GLuint glprogid; // OpenGL program id
|
|
|
|
|
|
|
|
std::string strvprog, strpprog, strgprog;
|
|
|
|
|
|
|
|
void SetProgramVariables();
|
|
|
|
void SetProgramBindings();
|
|
|
|
void Bind();
|
2013-02-13 05:12:19 -07:00
|
|
|
};
|
2011-12-26 00:58:52 -07:00
|
|
|
|
|
|
|
class ProgramShaderCache
|
2011-11-30 20:00:21 -07:00
|
|
|
{
|
|
|
|
public:
|
2016-06-24 02:43:46 -06:00
|
|
|
struct PCacheEntry
|
|
|
|
{
|
|
|
|
SHADER shader;
|
|
|
|
bool in_cache;
|
2011-12-11 03:08:18 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void Destroy() { shader.Destroy(); }
|
|
|
|
};
|
2013-03-29 08:08:00 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
static PCacheEntry GetShaderProgram();
|
2016-12-27 17:37:41 -07:00
|
|
|
static SHADER* SetShader(u32 primitive_type);
|
|
|
|
static void GetShaderId(SHADERUID* uid, u32 primitive_type);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
static bool CompileShader(SHADER& shader, const std::string& vcode, const std::string& pcode,
|
|
|
|
const std::string& gcode = "");
|
|
|
|
static GLuint CompileSingleShader(GLuint type, const std::string& code);
|
|
|
|
static void UploadConstants();
|
2011-12-26 00:58:52 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
static void Init();
|
|
|
|
static void Shutdown();
|
|
|
|
static void CreateHeader();
|
2011-12-26 00:58:52 -07:00
|
|
|
|
|
|
|
private:
|
2016-06-24 02:43:46 -06:00
|
|
|
class ProgramShaderCacheInserter : public LinearDiskCacheReader<SHADERUID, u8>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void Read(const SHADERUID& key, const u8* value, u32 value_size) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<SHADERUID, PCacheEntry> PCache;
|
|
|
|
static PCache pshaders;
|
|
|
|
static PCacheEntry* last_entry;
|
|
|
|
static SHADERUID last_uid;
|
|
|
|
|
|
|
|
static u32 s_ubo_buffer_size;
|
|
|
|
static s32 s_ubo_align;
|
2011-11-30 20:00:21 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace OGL
|