let us try normal c++ static init instead...

This commit is contained in:
Shawn Hoffman 2011-12-29 16:25:03 +01:00 committed by Sonicadvance1
parent 03b09bed5d
commit 210ecad15f
2 changed files with 20 additions and 19 deletions

View File

@ -25,11 +25,12 @@ GLuint ProgramShaderCache::CurrentFShader = 0, ProgramShaderCache::CurrentVShade
ProgramShaderCache::PCache ProgramShaderCache::pshaders; ProgramShaderCache::PCache ProgramShaderCache::pshaders;
GLuint ProgramShaderCache::s_ps_vs_ubo; GLuint ProgramShaderCache::s_ps_vs_ubo;
GLintptr ProgramShaderCache::s_vs_data_offset; GLintptr ProgramShaderCache::s_vs_data_offset;
GLenum ProgramShaderCache::prog_format;
LinearDiskCache<ProgramShaderCache::ShaderUID, u8> g_program_disk_cache; LinearDiskCache<ProgramShaderCache::ShaderUID, u8> g_program_disk_cache;
GLenum ProgramFormat; GLenum ProgramFormat;
GLuint ProgramShaderCache::PCacheEntry::prog_format = ProgramShaderCache::PCacheEntry::SetProgramFormat();
std::pair<u32, u32> ProgramShaderCache::CurrentShaderProgram; std::pair<u32, u32> ProgramShaderCache::CurrentShaderProgram;
const char *UniformNames[NUM_UNIFORMS] = const char *UniformNames[NUM_UNIFORMS] =
{ {
@ -214,16 +215,6 @@ void ProgramShaderCache::Init(void)
// Read our shader cache, only if supported // Read our shader cache, only if supported
if (g_ActiveConfig.backend_info.bSupportsGLSLCache) if (g_ActiveConfig.backend_info.bSupportsGLSLCache)
{ {
GLint Supported;
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &Supported);
GLint *Formats = new GLint[Supported];
glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, Formats);
// We don't really care about format
// We just need the correct data type
prog_format = (GLenum)Formats[0];
delete[] Formats;
char cache_filename[MAX_PATH]; char cache_filename[MAX_PATH];
sprintf(cache_filename, "%sogl-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(), sprintf(cache_filename, "%sogl-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str()); SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str());

View File

@ -41,6 +41,7 @@ public:
struct PCacheEntry struct PCacheEntry
{ {
GLuint prog_id; GLuint prog_id;
static GLenum prog_format;
u8 *binary; u8 *binary;
GLint binary_size; GLint binary_size;
GLuint vsid, psid; GLuint vsid, psid;
@ -74,15 +75,26 @@ public:
glGetProgramiv(prog_id, GL_PROGRAM_BINARY_LENGTH, &binary_size); glGetProgramiv(prog_id, GL_PROGRAM_BINARY_LENGTH, &binary_size);
} }
// No idea how necessary this is
static GLenum SetProgramFormat()
{
GLint Supported;
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &Supported);
GLint *Formats = new GLint[Supported];
glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, Formats);
// We don't really care about format
GLenum prog_format = (GLenum)Formats[0];
delete[] Formats;
return prog_format;
}
u8 *GetProgram() u8 *GetProgram()
{ {
UpdateSize(); UpdateSize();
FreeProgram(); FreeProgram();
binary = new u8[binary_size]; binary = new u8[binary_size];
GLenum _form; glGetProgramBinary(prog_id, binary_size, NULL, &prog_format, binary);
glGetProgramBinary(prog_id, binary_size, NULL, &_form, binary);
if (_form != prog_format)
ERROR_LOG(VIDEO, "Returned format not the same as expected! %d vs %d", _form, prog_format);
return binary; return binary;
} }
@ -119,7 +131,8 @@ private:
// But it is fine, no need to worry about that // But it is fine, no need to worry about that
PCacheEntry entry; PCacheEntry entry;
entry.Create(key.first, key.second); entry.Create(key.first, key.second);
glProgramBinary(entry.prog_id, prog_format, value, value_size);
glProgramBinary(entry.prog_id, entry.prog_format, value, value_size);
GLint success; GLint success;
glGetProgramiv(entry.prog_id, GL_LINK_STATUS, &success); glGetProgramiv(entry.prog_id, GL_LINK_STATUS, &success);
@ -141,9 +154,6 @@ private:
static GLuint s_ps_vs_ubo; static GLuint s_ps_vs_ubo;
static GLintptr s_vs_data_offset; static GLintptr s_vs_data_offset;
static GLenum prog_format;
static void SetProgramVariables(PCacheEntry &entry); static void SetProgramVariables(PCacheEntry &entry);
}; };