Add in UBOs, doesn't work yet. Still debugging here.
This commit is contained in:
parent
9119399547
commit
8e5bb59cb6
|
@ -610,6 +610,8 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
|
||||||
}
|
}
|
||||||
|
|
||||||
WRITE(p, "\n");
|
WRITE(p, "\n");
|
||||||
|
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
|
WRITE(p, "layout(std140, binding = 0) uniform PSBlock {\n");
|
||||||
|
|
||||||
WRITE(p, "%suniform float4 "I_COLORS"[4] %s;\n", WriteLocation(ApiType, C_COLORS), WriteRegister(ApiType, "c", C_COLORS));
|
WRITE(p, "%suniform float4 "I_COLORS"[4] %s;\n", WriteLocation(ApiType, C_COLORS), WriteRegister(ApiType, "c", C_COLORS));
|
||||||
WRITE(p, "%suniform float4 "I_KCOLORS"[4] %s;\n", WriteLocation(ApiType, C_KCOLORS), WriteRegister(ApiType, "c", C_KCOLORS));
|
WRITE(p, "%suniform float4 "I_KCOLORS"[4] %s;\n", WriteLocation(ApiType, C_KCOLORS), WriteRegister(ApiType, "c", C_KCOLORS));
|
||||||
|
@ -620,11 +622,12 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType
|
||||||
WRITE(p, "%suniform float4 "I_INDTEXMTX"[6] %s;\n", WriteLocation(ApiType, C_INDTEXMTX), WriteRegister(ApiType, "c", C_INDTEXMTX));
|
WRITE(p, "%suniform float4 "I_INDTEXMTX"[6] %s;\n", WriteLocation(ApiType, C_INDTEXMTX), WriteRegister(ApiType, "c", C_INDTEXMTX));
|
||||||
WRITE(p, "%suniform float4 "I_FOG"[3] %s;\n", WriteLocation(ApiType, C_FOG), WriteRegister(ApiType, "c", C_FOG));
|
WRITE(p, "%suniform float4 "I_FOG"[3] %s;\n", WriteLocation(ApiType, C_FOG), WriteRegister(ApiType, "c", C_FOG));
|
||||||
|
|
||||||
if(g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
|
// Compiler will optimize these out by itself.
|
||||||
{
|
|
||||||
WRITE(p, "%suniform float4 "I_PLIGHTS"[40] %s;\n", WriteLocation(ApiType, C_PLIGHTS), WriteRegister(ApiType, "c", C_PLIGHTS));
|
WRITE(p, "%suniform float4 "I_PLIGHTS"[40] %s;\n", WriteLocation(ApiType, C_PLIGHTS), WriteRegister(ApiType, "c", C_PLIGHTS));
|
||||||
WRITE(p, "%suniform float4 "I_PMATERIALS"[4] %s;\n", WriteLocation(ApiType, C_PMATERIALS), WriteRegister(ApiType, "c", C_PMATERIALS));
|
WRITE(p, "%suniform float4 "I_PMATERIALS"[4] %s;\n", WriteLocation(ApiType, C_PMATERIALS), WriteRegister(ApiType, "c", C_PMATERIALS));
|
||||||
}
|
|
||||||
|
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
|
WRITE(p, "};\n");
|
||||||
|
|
||||||
if(ApiType != API_GLSL)
|
if(ApiType != API_GLSL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -85,7 +85,7 @@ void PixelShaderManager::Shutdown()
|
||||||
|
|
||||||
void PixelShaderManager::SetConstants()
|
void PixelShaderManager::SetConstants()
|
||||||
{
|
{
|
||||||
if (g_ActiveConfig.bUseGLSL)
|
if (g_ActiveConfig.bUseGLSL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
Dirty();
|
Dirty();
|
||||||
for (int i = 0; i < 2; ++i)
|
for (int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -214,7 +214,11 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
|
||||||
WRITE(p, "#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
|
WRITE(p, "#define saturate(x) clamp(x, 0.0f, 1.0f)\n");
|
||||||
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
|
WRITE(p, "#define lerp(x, y, z) mix(x, y, z)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// uniforms
|
// uniforms
|
||||||
|
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
|
WRITE(p, "layout(std140, binding = 1) uniform VSBlock {\n");
|
||||||
|
|
||||||
WRITE(p, "%suniform float4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType, C_POSNORMALMATRIX), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
|
WRITE(p, "%suniform float4 "I_POSNORMALMATRIX"[6] %s;\n", WriteLocation(ApiType, C_POSNORMALMATRIX), WriteRegister(ApiType, "c", C_POSNORMALMATRIX));
|
||||||
WRITE(p, "%suniform float4 "I_PROJECTION"[4] %s;\n", WriteLocation(ApiType, C_PROJECTION), WriteRegister(ApiType, "c", C_PROJECTION));
|
WRITE(p, "%suniform float4 "I_PROJECTION"[4] %s;\n", WriteLocation(ApiType, C_PROJECTION), WriteRegister(ApiType, "c", C_PROJECTION));
|
||||||
WRITE(p, "%suniform float4 "I_MATERIALS"[4] %s;\n", WriteLocation(ApiType, C_MATERIALS), WriteRegister(ApiType, "c", C_MATERIALS));
|
WRITE(p, "%suniform float4 "I_MATERIALS"[4] %s;\n", WriteLocation(ApiType, C_MATERIALS), WriteRegister(ApiType, "c", C_MATERIALS));
|
||||||
|
@ -225,6 +229,9 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType)
|
||||||
WRITE(p, "%suniform float4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType, C_POSTTRANSFORMMATRICES), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
|
WRITE(p, "%suniform float4 "I_POSTTRANSFORMMATRICES"[64] %s;\n", WriteLocation(ApiType, C_POSTTRANSFORMMATRICES), WriteRegister(ApiType, "c", C_POSTTRANSFORMMATRICES));
|
||||||
WRITE(p, "%suniform float4 "I_DEPTHPARAMS" %s;\n", WriteLocation(ApiType, C_DEPTHPARAMS), WriteRegister(ApiType, "c", C_DEPTHPARAMS));
|
WRITE(p, "%suniform float4 "I_DEPTHPARAMS" %s;\n", WriteLocation(ApiType, C_DEPTHPARAMS), WriteRegister(ApiType, "c", C_DEPTHPARAMS));
|
||||||
|
|
||||||
|
if(ApiType == API_GLSL && g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
|
WRITE(p, "};\n");
|
||||||
|
|
||||||
p = GenerateVSOutputStruct(p, components, ApiType);
|
p = GenerateVSOutputStruct(p, components, ApiType);
|
||||||
|
|
||||||
if(ApiType == API_GLSL)
|
if(ApiType == API_GLSL)
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
#define C_NORMALMATRICES (C_TRANSFORMMATRICES + 64)
|
#define C_NORMALMATRICES (C_TRANSFORMMATRICES + 64)
|
||||||
#define C_POSTTRANSFORMMATRICES (C_NORMALMATRICES + 32)
|
#define C_POSTTRANSFORMMATRICES (C_NORMALMATRICES + 32)
|
||||||
#define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64)
|
#define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64)
|
||||||
#define C_VENVCONST_END (C_DEPTHPARAMS + 4)
|
#define C_VENVCONST_END (C_DEPTHPARAMS + 1)
|
||||||
const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 },
|
const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 },
|
||||||
{I_PROJECTION , C_PROJECTION, 4 },
|
{I_PROJECTION , C_PROJECTION, 4 },
|
||||||
{I_MATERIALS, C_MATERIALS, 4 },
|
{I_MATERIALS, C_MATERIALS, 4 },
|
||||||
|
|
|
@ -173,7 +173,7 @@ void VertexShaderManager::Dirty()
|
||||||
// TODO: A cleaner way to control the matricies without making a mess in the parameters field
|
// TODO: A cleaner way to control the matricies without making a mess in the parameters field
|
||||||
void VertexShaderManager::SetConstants()
|
void VertexShaderManager::SetConstants()
|
||||||
{
|
{
|
||||||
if (g_ActiveConfig.bUseGLSL)
|
if (g_ActiveConfig.bUseGLSL && !g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
Dirty();
|
Dirty();
|
||||||
if (nTransformMatricesChanged[0] >= 0)
|
if (nTransformMatricesChanged[0] >= 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -167,9 +167,11 @@ struct VideoConfig
|
||||||
bool bSupportsDualSourceBlend; // only supported by D3D11 and OpenGL
|
bool bSupportsDualSourceBlend; // only supported by D3D11 and OpenGL
|
||||||
bool bSupportsFormatReinterpretation;
|
bool bSupportsFormatReinterpretation;
|
||||||
bool bSupportsPixelLighting;
|
bool bSupportsPixelLighting;
|
||||||
|
|
||||||
bool bSupportsGLSL;
|
bool bSupportsGLSL;
|
||||||
bool bSupportsGLSLBinding;
|
bool bSupportsGLSLBinding;
|
||||||
bool bSupportsGLSLLocation;
|
bool bSupportsGLSLLocation;
|
||||||
|
bool bSupportsGLSLUBO;
|
||||||
} backend_info;
|
} backend_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -82,8 +82,13 @@ void PixelShaderCache::Init()
|
||||||
if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_shading_language_420pack") != NULL)
|
if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_shading_language_420pack") != NULL)
|
||||||
g_Config.backend_info.bSupportsGLSLBinding = true;
|
g_Config.backend_info.bSupportsGLSLBinding = true;
|
||||||
// This bit doesn't quite work yet, always set to false
|
// This bit doesn't quite work yet, always set to false
|
||||||
|
// TODO: Probably just drop this entirely in favour of UBOS
|
||||||
//if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_separate_shader_objects") != NULL)
|
//if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_separate_shader_objects") != NULL)
|
||||||
g_Config.backend_info.bSupportsGLSLLocation = false;
|
g_Config.backend_info.bSupportsGLSLLocation = false;
|
||||||
|
|
||||||
|
if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_uniform_buffer_object") != NULL)
|
||||||
|
g_Config.backend_info.bSupportsGLSLUBO = true;
|
||||||
|
|
||||||
UpdateActiveConfig();
|
UpdateActiveConfig();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -466,11 +471,11 @@ bool CompileGLSLPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
|
||||||
}
|
}
|
||||||
void PixelShaderCache::SetPSSampler(const char * name, unsigned int Tex)
|
void PixelShaderCache::SetPSSampler(const char * name, unsigned int Tex)
|
||||||
{
|
{
|
||||||
if(g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLBinding)
|
||||||
return;
|
return;
|
||||||
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
||||||
for(int a = 0; a < NUM_UNIFORMS; ++a)
|
for (int a = 0; a < NUM_UNIFORMS; ++a)
|
||||||
if(!strcmp(name, UniformNames[a]))
|
if (!strcmp(name, UniformNames[a]))
|
||||||
{
|
{
|
||||||
if(tmp.UniformLocations[a] == -1)
|
if(tmp.UniformLocations[a] == -1)
|
||||||
return;
|
return;
|
||||||
|
@ -484,8 +489,8 @@ void PixelShaderCache::SetPSSampler(const char * name, unsigned int Tex)
|
||||||
void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
void SetPSConstant4fvByName(const char * name, unsigned int offset, const float *f, const unsigned int count = 1)
|
||||||
{
|
{
|
||||||
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
PROGRAMSHADER tmp = ProgramShaderCache::GetShaderProgram();
|
||||||
for(int a = 0; a < NUM_UNIFORMS; ++a)
|
for (int a = 0; a < NUM_UNIFORMS; ++a)
|
||||||
if(!strcmp(name, UniformNames[a]))
|
if (!strcmp(name, UniformNames[a]))
|
||||||
{
|
{
|
||||||
if(tmp.UniformLocations[a] == -1)
|
if(tmp.UniformLocations[a] == -1)
|
||||||
return;
|
return;
|
||||||
|
@ -500,14 +505,19 @@ void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3
|
||||||
{
|
{
|
||||||
float f[4] = { f1, f2, f3, f4 };
|
float f[4] = { f1, f2, f3, f4 };
|
||||||
|
|
||||||
if(g_ActiveConfig.backend_info.bSupportsGLSLLocation)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLLocation)
|
||||||
{
|
{
|
||||||
glUniform4fv(const_number, 1, f);
|
glUniform4fv(const_number, 1, f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for( unsigned int a = 0; a < 10; ++a)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
{
|
{
|
||||||
if( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
ProgramShaderCache::SetUniformObjects(0, const_number, f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (unsigned int a = 0; a < 10; ++a)
|
||||||
|
{
|
||||||
|
if ( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
||||||
{
|
{
|
||||||
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
||||||
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
|
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
|
||||||
|
@ -518,14 +528,19 @@ void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3
|
||||||
|
|
||||||
void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
|
void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
|
||||||
{
|
{
|
||||||
if(g_ActiveConfig.backend_info.bSupportsGLSLLocation)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLLocation)
|
||||||
{
|
{
|
||||||
glUniform4fv(const_number, 1, f);
|
glUniform4fv(const_number, 1, f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for( unsigned int a = 0; a < 10; ++a)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
{
|
{
|
||||||
if( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
ProgramShaderCache::SetUniformObjects(0, const_number, f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (unsigned int a = 0; a < 10; ++a)
|
||||||
|
{
|
||||||
|
if ( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
||||||
{
|
{
|
||||||
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
||||||
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
|
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f);
|
||||||
|
@ -536,14 +551,19 @@ void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
|
||||||
|
|
||||||
void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
|
||||||
{
|
{
|
||||||
if(g_ActiveConfig.backend_info.bSupportsGLSLLocation)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLLocation)
|
||||||
{
|
{
|
||||||
glUniform4fv(const_number, count, f);
|
glUniform4fv(const_number, count, f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for( unsigned int a = 0; a < 10; ++a)
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
{
|
{
|
||||||
if( const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
ProgramShaderCache::SetUniformObjects(0, const_number, f, count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (unsigned int a = 0; a < 10; ++a)
|
||||||
|
{
|
||||||
|
if (const_number >= PSVar_Loc[a].reg && const_number < (PSVar_Loc[a].reg + PSVar_Loc[a].size))
|
||||||
{
|
{
|
||||||
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
unsigned int offset = const_number - PSVar_Loc[a].reg;
|
||||||
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f, count);
|
SetPSConstant4fvByName(PSVar_Loc[a].name, offset, f, count);
|
||||||
|
|
|
@ -14,12 +14,15 @@
|
||||||
|
|
||||||
// Official SVN repository and contact information can be found at
|
// Official SVN repository and contact information can be found at
|
||||||
// http://code.google.com/p/dolphin-emu/
|
// http://code.google.com/p/dolphin-emu/
|
||||||
|
|
||||||
#include "ProgramShaderCache.h"
|
#include "ProgramShaderCache.h"
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
namespace OGL
|
namespace OGL
|
||||||
{
|
{
|
||||||
GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0;
|
GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShader = 0, ProgramShaderCache::CurrentProgram = 0;
|
||||||
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
|
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
|
||||||
|
GLuint ProgramShaderCache::UBOBuffers[2];
|
||||||
|
|
||||||
std::pair<u64, u64> ProgramShaderCache::CurrentShaderProgram;
|
std::pair<u64, u64> ProgramShaderCache::CurrentShaderProgram;
|
||||||
const char *UniformNames[NUM_UNIFORMS] = {
|
const char *UniformNames[NUM_UNIFORMS] = {
|
||||||
|
@ -85,11 +88,13 @@ namespace OGL
|
||||||
// Let's attach everything
|
// Let's attach everything
|
||||||
if(entry.program.vsid != 0) // attaching zero vertex shader makes it freak out
|
if(entry.program.vsid != 0) // attaching zero vertex shader makes it freak out
|
||||||
glAttachShader(entry.program.glprogid, entry.program.vsid);
|
glAttachShader(entry.program.glprogid, entry.program.vsid);
|
||||||
|
|
||||||
glAttachShader(entry.program.glprogid, entry.program.psid);
|
glAttachShader(entry.program.glprogid, entry.program.psid);
|
||||||
|
|
||||||
glLinkProgram(entry.program.glprogid);
|
glLinkProgram(entry.program.glprogid);
|
||||||
//checkForGLError("linking program");
|
|
||||||
glUseProgram(entry.program.glprogid);
|
glUseProgram(entry.program.glprogid);
|
||||||
//checkForGLError("using program");
|
|
||||||
|
|
||||||
// We cache our uniform locations for now
|
// We cache our uniform locations for now
|
||||||
// Once we move up to a newer version of GLSL, ~1.30
|
// Once we move up to a newer version of GLSL, ~1.30
|
||||||
|
@ -122,18 +127,40 @@ namespace OGL
|
||||||
CurrentShaderProgram = ShaderPair;
|
CurrentShaderProgram = ShaderPair;
|
||||||
CurrentProgram = entry.program.glprogid;
|
CurrentProgram = entry.program.glprogid;
|
||||||
}
|
}
|
||||||
|
void ProgramShaderCache::SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count)
|
||||||
|
{
|
||||||
|
assert(Buffer > 1);
|
||||||
|
glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[Buffer]);
|
||||||
|
// glBufferSubData expects data in bytes, so multiply count by four
|
||||||
|
// Expects the offset in bytes as well, so multiply by *4 *4 since we are passing in a vec4 location
|
||||||
|
glBufferSubData(GL_UNIFORM_BUFFER, offset * 4 * 4, count * 4, (void*)&f[0]);
|
||||||
|
}
|
||||||
GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; }
|
GLuint ProgramShaderCache::GetCurrentProgram(void) { return CurrentProgram; }
|
||||||
|
|
||||||
GLint ProgramShaderCache::GetAttr(int num)
|
GLint ProgramShaderCache::GetAttr(int num)
|
||||||
{
|
{
|
||||||
return pshaders[CurrentShaderProgram].program.attrLoc[num];
|
return pshaders[CurrentShaderProgram].program.attrLoc[num];
|
||||||
}
|
}
|
||||||
PROGRAMSHADER ProgramShaderCache::GetShaderProgram()
|
PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void)
|
||||||
{
|
{
|
||||||
return pshaders[CurrentShaderProgram].program;
|
return pshaders[CurrentShaderProgram].program;
|
||||||
}
|
}
|
||||||
|
void ProgramShaderCache::Init(void)
|
||||||
|
{
|
||||||
|
glGenBuffers(2, UBOBuffers);
|
||||||
|
glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[0]);
|
||||||
|
// We multiply by *4*4 because we need to get down to basic machine units.
|
||||||
|
// So multiply by four to get how many floats we have from vec4s
|
||||||
|
// Then once more to get bytes
|
||||||
|
glBufferData(GL_UNIFORM_BUFFER, C_PENVCONST_END * 4 * 4, NULL, GL_DYNAMIC_DRAW);
|
||||||
|
// Now bind the buffer to the index point
|
||||||
|
// We know PS is 0 since we have it statically set in the shader
|
||||||
|
glBindBufferBase(GL_UNIFORM_BUFFER, 0, UBOBuffers[0]);
|
||||||
|
// Repeat for VS shader
|
||||||
|
glBindBuffer(GL_UNIFORM_BUFFER, UBOBuffers[1]);
|
||||||
|
glBufferData(GL_UNIFORM_BUFFER, C_VENVCONST_END * 4 * 4, NULL, GL_DYNAMIC_DRAW);
|
||||||
|
glBindBufferBase(GL_UNIFORM_BUFFER, 1, UBOBuffers[1]);
|
||||||
|
}
|
||||||
void ProgramShaderCache::Shutdown(void)
|
void ProgramShaderCache::Shutdown(void)
|
||||||
{
|
{
|
||||||
PCache::iterator iter = pshaders.begin();
|
PCache::iterator iter = pshaders.begin();
|
||||||
|
|
|
@ -94,11 +94,17 @@ class ProgramShaderCache
|
||||||
static PCache pshaders;
|
static PCache pshaders;
|
||||||
static GLuint CurrentFShader, CurrentVShader, CurrentProgram;
|
static GLuint CurrentFShader, CurrentVShader, CurrentProgram;
|
||||||
static std::pair<u64, u64> CurrentShaderProgram;
|
static std::pair<u64, u64> CurrentShaderProgram;
|
||||||
|
|
||||||
|
// For UBOS
|
||||||
|
static GLuint UBOBuffers[2]; // PS is 0, VS is 1
|
||||||
public:
|
public:
|
||||||
static PROGRAMSHADER GetShaderProgram();
|
static PROGRAMSHADER GetShaderProgram(void);
|
||||||
static GLint GetAttr(int num);
|
static GLint GetAttr(int num);
|
||||||
static void SetBothShaders(GLuint PS, GLuint VS);
|
static void SetBothShaders(GLuint PS, GLuint VS);
|
||||||
static GLuint GetCurrentProgram(void);
|
static GLuint GetCurrentProgram(void);
|
||||||
|
static void SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count = 1);
|
||||||
|
|
||||||
|
static void Init(void);
|
||||||
static void Shutdown(void);
|
static void Shutdown(void);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -239,7 +239,8 @@ void VertexManager::vFlush()
|
||||||
if(g_ActiveConfig.bUseGLSL)
|
if(g_ActiveConfig.bUseGLSL)
|
||||||
{
|
{
|
||||||
ProgramShaderCache::SetBothShaders(ps->glprogid, 0);
|
ProgramShaderCache::SetBothShaders(ps->glprogid, 0);
|
||||||
PixelShaderManager::SetConstants(); // Need to set these again
|
if(!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
|
PixelShaderManager::SetConstants(); // Need to set these again, if we don't support UBO
|
||||||
if (g_nativeVertexFmt)
|
if (g_nativeVertexFmt)
|
||||||
g_nativeVertexFmt->SetupVertexPointers();
|
g_nativeVertexFmt->SetupVertexPointers();
|
||||||
for (int i = 0; i < 8; i++)
|
for (int i = 0; i < 8; i++)
|
||||||
|
|
|
@ -252,6 +252,11 @@ void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3
|
||||||
glUniform4fv(const_number, 1, buf);
|
glUniform4fv(const_number, 1, buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
|
{
|
||||||
|
ProgramShaderCache::SetUniformObjects(1, const_number, buf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
for( unsigned int a = 0; a < 9; ++a)
|
for( unsigned int a = 0; a < 9; ++a)
|
||||||
{
|
{
|
||||||
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
||||||
|
@ -270,6 +275,11 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
|
||||||
glUniform4fv(const_number, 1, f);
|
glUniform4fv(const_number, 1, f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
|
{
|
||||||
|
ProgramShaderCache::SetUniformObjects(1, const_number, f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
for( unsigned int a = 0; a < 9; ++a)
|
for( unsigned int a = 0; a < 9; ++a)
|
||||||
{
|
{
|
||||||
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
||||||
|
@ -288,6 +298,11 @@ void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, co
|
||||||
glUniform4fv(const_number, count, f);
|
glUniform4fv(const_number, count, f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
|
{
|
||||||
|
ProgramShaderCache::SetUniformObjects(1, const_number, f, count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
for( unsigned int a = 0; a < 9; ++a)
|
for( unsigned int a = 0; a < 9; ++a)
|
||||||
{
|
{
|
||||||
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
||||||
|
@ -314,6 +329,11 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co
|
||||||
glUniform4fv(const_number, count, buf);
|
glUniform4fv(const_number, count, buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
|
||||||
|
{
|
||||||
|
ProgramShaderCache::SetUniformObjects(1, const_number, buf, count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
for( unsigned int a = 0; a < 9; ++a)
|
for( unsigned int a = 0; a < 9; ++a)
|
||||||
{
|
{
|
||||||
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
if( const_number >= VSVar_Loc[a].reg && const_number < ( VSVar_Loc[a].reg + VSVar_Loc[a].size))
|
||||||
|
|
|
@ -83,6 +83,7 @@ Make AA apply instantly during gameplay if possible
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
#include "VertexShaderCache.h"
|
#include "VertexShaderCache.h"
|
||||||
#include "VertexShaderManager.h"
|
#include "VertexShaderManager.h"
|
||||||
|
#include "ProgramShaderCache.h"
|
||||||
#include "CommandProcessor.h"
|
#include "CommandProcessor.h"
|
||||||
#include "PixelEngine.h"
|
#include "PixelEngine.h"
|
||||||
#include "TextureConverter.h"
|
#include "TextureConverter.h"
|
||||||
|
@ -199,6 +200,7 @@ void VideoBackend::Video_Prepare()
|
||||||
VertexShaderManager::Init();
|
VertexShaderManager::Init();
|
||||||
PixelShaderCache::Init();
|
PixelShaderCache::Init();
|
||||||
PixelShaderManager::Init();
|
PixelShaderManager::Init();
|
||||||
|
ProgramShaderCache::Init();
|
||||||
PostProcessing::Init();
|
PostProcessing::Init();
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
VertexLoaderManager::Init();
|
VertexLoaderManager::Init();
|
||||||
|
@ -226,6 +228,7 @@ void VideoBackend::Shutdown()
|
||||||
// And need to be called from the video thread
|
// And need to be called from the video thread
|
||||||
TextureConverter::Shutdown();
|
TextureConverter::Shutdown();
|
||||||
VertexLoaderManager::Shutdown();
|
VertexLoaderManager::Shutdown();
|
||||||
|
ProgramShaderCache::Shutdown();
|
||||||
VertexShaderCache::Shutdown();
|
VertexShaderCache::Shutdown();
|
||||||
VertexShaderManager::Shutdown();
|
VertexShaderManager::Shutdown();
|
||||||
PixelShaderManager::Shutdown();
|
PixelShaderManager::Shutdown();
|
||||||
|
|
Loading…
Reference in New Issue