8 spaces indentation -> tabs

This commit is contained in:
Pierre Bourdon 2011-12-11 11:08:18 +01:00 committed by Sonicadvance1
parent a5257c1a0a
commit 3c6d0fc710
10 changed files with 467 additions and 467 deletions

View File

@ -49,16 +49,16 @@
// Annoying sure, can be removed once we get up to GLSL ~1.3 // Annoying sure, can be removed once we get up to GLSL ~1.3
const s_svar PSVar_Loc[] = { {I_COLORS, C_COLORS, 4 }, const s_svar PSVar_Loc[] = { {I_COLORS, C_COLORS, 4 },
{I_KCOLORS, C_KCOLORS, 4 }, {I_KCOLORS, C_KCOLORS, 4 },
{I_ALPHA, C_ALPHA, 1 }, {I_ALPHA, C_ALPHA, 1 },
{I_TEXDIMS, C_TEXDIMS, 8 }, {I_TEXDIMS, C_TEXDIMS, 8 },
{I_ZBIAS , C_ZBIAS, 2 }, {I_ZBIAS , C_ZBIAS, 2 },
{I_INDTEXSCALE , C_INDTEXSCALE, 2 }, {I_INDTEXSCALE , C_INDTEXSCALE, 2 },
{I_INDTEXMTX, C_INDTEXMTX, 6 }, {I_INDTEXMTX, C_INDTEXMTX, 6 },
{I_FOG, C_FOG, 3 }, {I_FOG, C_FOG, 3 },
{I_PLIGHTS, C_PLIGHTS, 40 }, {I_PLIGHTS, C_PLIGHTS, 40 },
{I_PMATERIALS, C_PMATERIALS, 4 }, {I_PMATERIALS, C_PMATERIALS, 4 },
}; };
// DO NOT make anything in this class virtual. // DO NOT make anything in this class virtual.
template<bool safe> template<bool safe>

View File

@ -68,11 +68,11 @@ u16 GetEncodedSampleCount(u32 format)
} }
const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num) const char* WriteRegister(API_TYPE ApiType, const char *prefix, const u32 num)
{ {
if(ApiType == API_GLSL) if(ApiType == API_GLSL)
return ""; // Once we switch to GLSL 1.3 we can do something here return ""; // Once we switch to GLSL 1.3 we can do something here
static char result[64]; static char result[64];
sprintf(result, " : register(%s%d)", prefix, num); sprintf(result, " : register(%s%d)", prefix, num);
return result; return result;
} }
const char *WriteLocation(API_TYPE ApiType) const char *WriteLocation(API_TYPE ApiType)
{ {
@ -821,13 +821,13 @@ void WriteZ24Encoder(char* p, API_TYPE ApiType)
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
WRITE(p, " depth%i *= 16777215.0f;\n", i); WRITE(p, " depth%i *= 16777215.0f;\n", i);
WRITE(p, " expanded%i.r = floor(depth%i / (256 * 256));\n", i, i); WRITE(p, " expanded%i.r = floor(depth%i / (256 * 256));\n", i, i);
WRITE(p, " depth%i -= expanded%i.r * 256 * 256;\n", i, i); WRITE(p, " depth%i -= expanded%i.r * 256 * 256;\n", i, i);
WRITE(p, " expanded%i.g = floor(depth%i / 256);\n", i, i); WRITE(p, " expanded%i.g = floor(depth%i / 256);\n", i, i);
WRITE(p, " depth%i -= expanded%i.g * 256;\n", i, i); WRITE(p, " depth%i -= expanded%i.g * 256;\n", i, i);
WRITE(p, " expanded%i.b = depth%i;\n", i, i); WRITE(p, " expanded%i.b = depth%i;\n", i, i);
} }
WRITE(p, " if(cl > 0.5f) {\n"); WRITE(p, " if(cl > 0.5f) {\n");

View File

@ -48,15 +48,15 @@
#define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64) #define C_DEPTHPARAMS (C_POSTTRANSFORMMATRICES + 64)
#define C_VENVCONST_END (C_DEPTHPARAMS + 1) #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 },
{I_LIGHTS, C_LIGHTS, 40 }, {I_LIGHTS, C_LIGHTS, 40 },
{I_TEXMATRICES, C_TEXMATRICES, 24 }, {I_TEXMATRICES, C_TEXMATRICES, 24 },
{I_TRANSFORMMATRICES , C_TRANSFORMMATRICES, 64 }, {I_TRANSFORMMATRICES , C_TRANSFORMMATRICES, 64 },
{I_NORMALMATRICES , C_NORMALMATRICES, 32 }, {I_NORMALMATRICES , C_NORMALMATRICES, 32 },
{I_POSTTRANSFORMMATRICES, C_POSTTRANSFORMMATRICES, 64 }, {I_POSTTRANSFORMMATRICES, C_POSTTRANSFORMMATRICES, 64 },
{I_DEPTHPARAMS, C_DEPTHPARAMS, 1 }, {I_DEPTHPARAMS, C_DEPTHPARAMS, 1 },
}; };
template<bool safe> template<bool safe>
class _VERTEXSHADERUID class _VERTEXSHADERUID
{ {

View File

@ -154,9 +154,9 @@ inline unsigned int GetPow2(unsigned int val)
} }
struct s_svar struct s_svar
{ {
const char *name; const char *name;
const unsigned int reg; const unsigned int reg;
const unsigned int size; const unsigned int size;
}; };
#endif // _VIDEOCOMMON_H #endif // _VIDEOCOMMON_H

View File

@ -74,12 +74,12 @@ void PixelShaderCache::Init()
if(g_ActiveConfig.bUseGLSL) if(g_ActiveConfig.bUseGLSL)
{ {
pSetPSConstant4f = SetGLSLPSConstant4f; pSetPSConstant4f = SetGLSLPSConstant4f;
pSetPSConstant4fv = SetGLSLPSConstant4fv; pSetPSConstant4fv = SetGLSLPSConstant4fv;
pSetMultiPSConstant4fv = SetMultiGLSLPSConstant4fv; pSetMultiPSConstant4fv = SetMultiGLSLPSConstant4fv;
pCompilePixelShader = CompileGLSLPixelShader; pCompilePixelShader = CompileGLSLPixelShader;
// Should this be set here? // Should this be set here?
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;
if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_uniform_buffer_object") != NULL) if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_uniform_buffer_object") != NULL)
g_Config.backend_info.bSupportsGLSLUBO = true; g_Config.backend_info.bSupportsGLSLUBO = true;
@ -88,22 +88,22 @@ void PixelShaderCache::Init()
} }
else else
{ {
pSetPSConstant4f = SetCGPSConstant4f; pSetPSConstant4f = SetCGPSConstant4f;
pSetPSConstant4fv = SetCGPSConstant4fv; pSetPSConstant4fv = SetCGPSConstant4fv;
pSetMultiPSConstant4fv = SetMultiCGPSConstant4fv; pSetMultiPSConstant4fv = SetMultiCGPSConstant4fv;
pCompilePixelShader = CompileCGPixelShader; pCompilePixelShader = CompileCGPixelShader;
glEnable(GL_FRAGMENT_PROGRAM_ARB); glEnable(GL_FRAGMENT_PROGRAM_ARB);
} }
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, (GLint *)&s_nMaxPixelInstructions); glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, (GLint *)&s_nMaxPixelInstructions);
if(s_nMaxPixelInstructions == 0) // Some combination of drivers and hardware returns zero for some reason. if(s_nMaxPixelInstructions == 0) // Some combination of drivers and hardware returns zero for some reason.
s_nMaxPixelInstructions = 4096; s_nMaxPixelInstructions = 4096;
if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxPixelInstructions = 4096; if (strstr((const char*)glGetString(GL_VENDOR), "Humper") != NULL) s_nMaxPixelInstructions = 4096;
#if CG_VERSION_NUM == 2100 #if CG_VERSION_NUM == 2100
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL) if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
{ {
s_nMaxPixelInstructions = 4096; s_nMaxPixelInstructions = 4096;
} }
#endif #endif
@ -347,7 +347,7 @@ void PixelShaderCache::Shutdown()
s_DepthMatrixProgram.Destroy(); s_DepthMatrixProgram.Destroy();
PSCache::iterator iter = PixelShaders.begin(); PSCache::iterator iter = PixelShaders.begin();
for (; iter != PixelShaders.end(); iter++) for (; iter != PixelShaders.end(); iter++)
iter->second.Destroy(); iter->second.Destroy();
PixelShaders.clear(); PixelShaders.clear();
} }
@ -359,12 +359,12 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp
// Check if the shader is already set // Check if the shader is already set
if (last_entry) if (last_entry)
{ {
if (uid == last_uid) if (uid == last_uid)
{ {
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
ValidatePixelShaderIDs(API_OPENGL, last_entry->safe_uid, last_entry->shader.strprog, dstAlphaMode, components); ValidatePixelShaderIDs(API_OPENGL, last_entry->safe_uid, last_entry->shader.strprog, dstAlphaMode, components);
return &last_entry->shader; return &last_entry->shader;
} }
} }
last_uid = uid; last_uid = uid;
@ -372,12 +372,12 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp
PSCache::iterator iter = PixelShaders.find(uid); PSCache::iterator iter = PixelShaders.find(uid);
if (iter != PixelShaders.end()) if (iter != PixelShaders.end())
{ {
PSCacheEntry &entry = iter->second; PSCacheEntry &entry = iter->second;
last_entry = &entry; last_entry = &entry;
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components); ValidatePixelShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, dstAlphaMode, components);
return &last_entry->shader; return &last_entry->shader;
} }
// Make an entry in the table // Make an entry in the table
@ -387,23 +387,23 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 comp
if (g_ActiveConfig.bEnableShaderDebugging && code) if (g_ActiveConfig.bEnableShaderDebugging && code)
{ {
GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components); GetSafePixelShaderId(&newentry.safe_uid, dstAlphaMode, components);
newentry.shader.strprog = code; newentry.shader.strprog = code;
} }
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) { if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
static int counter = 0; static int counter = 0;
char szTemp[MAX_PATH]; char szTemp[MAX_PATH];
sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++); sprintf(szTemp, "%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
SaveData(szTemp, code); SaveData(szTemp, code);
} }
#endif #endif
if (!code || !CompilePixelShader(newentry.shader, code)) { if (!code || !CompilePixelShader(newentry.shader, code)) {
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true); GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
return NULL; return NULL;
} }
INCSTAT(stats.numPixelShadersCreated); INCSTAT(stats.numPixelShadersCreated);
@ -424,8 +424,8 @@ void PixelShaderCache::DisableShader()
assert(true); assert(true);
if(ShaderEnabled) if(ShaderEnabled)
{ {
glDisable(GL_FRAGMENT_PROGRAM_ARB); glDisable(GL_FRAGMENT_PROGRAM_ARB);
ShaderEnabled = false; ShaderEnabled = false;
} }
} }
@ -436,14 +436,14 @@ void PixelShaderCache::SetCurrentShader(GLuint Shader)
assert(true); assert(true);
if(!ShaderEnabled) if(!ShaderEnabled)
{ {
glEnable(GL_FRAGMENT_PROGRAM_ARB); glEnable(GL_FRAGMENT_PROGRAM_ARB);
ShaderEnabled = true; ShaderEnabled = true;
} }
if(CurrentShader != Shader) if(CurrentShader != Shader)
{ {
if(Shader != 0) if(Shader != 0)
CurrentShader = Shader; CurrentShader = Shader;
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, CurrentShader);
} }
} }
// GLSL Specific // GLSL Specific
@ -493,31 +493,31 @@ void PixelShaderCache::SetPSSampler(const char * name, unsigned int Tex)
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;
else else
{ {
glUniform1i(tmp.UniformLocations[a], Tex); glUniform1i(tmp.UniformLocations[a], Tex);
return; return;
} }
} }
} }
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;
else else
{ {
glUniform4fv(tmp.UniformLocations[a] + offset, count, f); glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
return; return;
} }
} }
} }
void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
@ -531,12 +531,12 @@ void SetGLSLPSConstant4f(unsigned int const_number, float f1, float f2, float f3
} }
for (unsigned int a = 0; a < 10; ++a) 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)) 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);
return; return;
} }
} }
} }
@ -549,12 +549,12 @@ void SetGLSLPSConstant4fv(unsigned int const_number, const float *f)
} }
for (unsigned int a = 0; a < 10; ++a) 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)) 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);
return; return;
} }
} }
} }
@ -567,12 +567,12 @@ void SetMultiGLSLPSConstant4fv(unsigned int const_number, unsigned int count, co
} }
for (unsigned int a = 0; a < 10; ++a) 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)) 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);
return; return;
} }
} }
} }
// CG Specific // CG Specific
@ -582,7 +582,7 @@ bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
GLenum err = GL_REPORT_ERROR(); GLenum err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR) if (err != GL_NO_ERROR)
{ {
ERROR_LOG(VIDEO, "glError %08x before PS!", err); ERROR_LOG(VIDEO, "glError %08x before PS!", err);
} }
#if defined HAVE_CG && HAVE_CG #if defined HAVE_CG && HAVE_CG
@ -591,28 +591,28 @@ bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
// handle errors // handle errors
if (!cgIsProgram(tempprog)) if (!cgIsProgram(tempprog))
{ {
cgDestroyProgram(tempprog); cgDestroyProgram(tempprog);
static int num_failures = 0; static int num_failures = 0;
char szTemp[MAX_PATH]; char szTemp[MAX_PATH];
sprintf(szTemp, "bad_ps_%04i.txt", num_failures++); sprintf(szTemp, "bad_ps_%04i.txt", num_failures++);
std::ofstream file(szTemp); std::ofstream file(szTemp);
file << pstrprogram; file << pstrprogram;
file.close(); file.close();
PanicAlert("Failed to compile pixel shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s", PanicAlert("Failed to compile pixel shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
num_failures - 1, szTemp, num_failures - 1, szTemp,
g_cgfProf, g_cgfProf,
cgGetLastListing(g_cgcontext)); cgGetLastListing(g_cgcontext));
return false; return false;
} }
// handle warnings // handle warnings
if (cgGetError() != CG_NO_ERROR) if (cgGetError() != CG_NO_ERROR)
{ {
WARN_LOG(VIDEO, "Warnings on compile ps %s:", cgGetLastListing(g_cgcontext)); WARN_LOG(VIDEO, "Warnings on compile ps %s:", cgGetLastListing(g_cgcontext));
WARN_LOG(VIDEO, "%s", pstrprogram); WARN_LOG(VIDEO, "%s", pstrprogram);
} }
// This looks evil - we modify the program through the const char * we got from cgGetProgramString! // This looks evil - we modify the program through the const char * we got from cgGetProgramString!
@ -621,9 +621,9 @@ bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
char *plocal = strstr(pcompiledprog, "program.local"); char *plocal = strstr(pcompiledprog, "program.local");
while (plocal != NULL) while (plocal != NULL)
{ {
const char *penv = " program.env"; const char *penv = " program.env";
memcpy(plocal, penv, 13); memcpy(plocal, penv, 13);
plocal = strstr(plocal+13, "program.local"); plocal = strstr(plocal+13, "program.local");
} }
glGenProgramsARB(1, &ps.glprogid); glGenProgramsARB(1, &ps.glprogid);
@ -634,23 +634,23 @@ bool CompileCGPixelShader(FRAGMENTSHADER& ps, const char* pstrprogram)
err = GL_REPORT_ERROR(); err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR) if (err != GL_NO_ERROR)
{ {
GLint error_pos, native_limit; GLint error_pos, native_limit;
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos); glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);
glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native_limit); glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native_limit);
// Error occur // Error occur
if (error_pos != -1) { if (error_pos != -1) {
const char *program_error = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB); const char *program_error = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB);
char line[256]; char line[256];
strncpy(line, (const char *)pcompiledprog + error_pos, 255); strncpy(line, (const char *)pcompiledprog + error_pos, 255);
line[255] = 0; line[255] = 0;
ERROR_LOG(VIDEO, "Error at %i: %s", error_pos, program_error); ERROR_LOG(VIDEO, "Error at %i: %s", error_pos, program_error);
ERROR_LOG(VIDEO, "Line dump: \n%s", line); ERROR_LOG(VIDEO, "Line dump: \n%s", line);
} else if (native_limit != -1) { } else if (native_limit != -1) {
ERROR_LOG(VIDEO, "Hit limit? %i", native_limit); ERROR_LOG(VIDEO, "Hit limit? %i", native_limit);
// TODO // TODO
} }
ERROR_LOG(VIDEO, "%s", pstrprogram); ERROR_LOG(VIDEO, "%s", pstrprogram);
ERROR_LOG(VIDEO, "%s", pcompiledprog); ERROR_LOG(VIDEO, "%s", pcompiledprog);
} }
cgDestroyProgram(tempprog); cgDestroyProgram(tempprog);
@ -672,21 +672,21 @@ void SetCGPSConstant4fv(unsigned int const_number, const float *f)
void SetMultiCGPSConstant4fv(unsigned int const_number, unsigned int count, const float *f) void SetMultiCGPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{ {
for (unsigned int i = 0; i < count; i++,f+=4) for (unsigned int i = 0; i < count; i++,f+=4)
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number + i, f); glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, const_number + i, f);
} }
// Renderer functions // Renderer functions
void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) void Renderer::SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{ {
pSetPSConstant4f(const_number, f1, f2, f3, f4); pSetPSConstant4f(const_number, f1, f2, f3, f4);
} }
void Renderer::SetPSConstant4fv(unsigned int const_number, const float *f) void Renderer::SetPSConstant4fv(unsigned int const_number, const float *f)
{ {
pSetPSConstant4fv(const_number, f); pSetPSConstant4fv(const_number, f);
} }
void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f) void Renderer::SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{ {
pSetMultiPSConstant4fv(const_number, count, f); pSetMultiPSConstant4fv(const_number, count, f);
} }
} // namespace OGL } // namespace OGL

View File

@ -21,123 +21,123 @@
#include <assert.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]; 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] = {
// SAMPLERS // SAMPLERS
"samp0","samp1","samp2","samp3","samp4","samp5","samp6","samp7", "samp0","samp1","samp2","samp3","samp4","samp5","samp6","samp7",
// PIXEL SHADER UNIFORMS // PIXEL SHADER UNIFORMS
I_COLORS, I_COLORS,
I_KCOLORS, I_KCOLORS,
I_ALPHA, I_ALPHA,
I_TEXDIMS, I_TEXDIMS,
I_ZBIAS , I_ZBIAS ,
I_INDTEXSCALE , I_INDTEXSCALE ,
I_INDTEXMTX, I_INDTEXMTX,
I_FOG, I_FOG,
I_PLIGHTS, I_PLIGHTS,
I_PMATERIALS, I_PMATERIALS,
// VERTEX SHADER UNIFORMS // VERTEX SHADER UNIFORMS
I_POSNORMALMATRIX, I_POSNORMALMATRIX,
I_PROJECTION , I_PROJECTION ,
I_MATERIALS, I_MATERIALS,
I_LIGHTS, I_LIGHTS,
I_TEXMATRICES, I_TEXMATRICES,
I_TRANSFORMMATRICES , I_TRANSFORMMATRICES ,
I_NORMALMATRICES , I_NORMALMATRICES ,
I_POSTTRANSFORMMATRICES, I_POSTTRANSFORMMATRICES,
I_DEPTHPARAMS, I_DEPTHPARAMS,
}; };
void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS) void ProgramShaderCache::SetBothShaders(GLuint PS, GLuint VS)
{ {
PROGRAMUID uid; PROGRAMUID uid;
CurrentFShader = PS; CurrentFShader = PS;
CurrentVShader = VS; CurrentVShader = VS;
GetProgramShaderId(&uid, CurrentVShader, CurrentFShader); GetProgramShaderId(&uid, CurrentVShader, CurrentFShader);
if(uid.uid.id == 0) if(uid.uid.id == 0)
{ {
CurrentProgram = 0; CurrentProgram = 0;
glUseProgram(0); glUseProgram(0);
return; return;
} }
// Fragment shaders can survive without Vertex Shaders // Fragment shaders can survive without Vertex Shaders
// We have a valid fragment shader, let's create our program // We have a valid fragment shader, let's create our program
std::pair<u64, u64> ShaderPair = std::make_pair(uid.uid.psid, uid.uid.vsid); std::pair<u64, u64> ShaderPair = std::make_pair(uid.uid.psid, uid.uid.vsid);
PCache::iterator iter = pshaders.find(ShaderPair); PCache::iterator iter = pshaders.find(ShaderPair);
if (iter != pshaders.end()) if (iter != pshaders.end())
{ {
PCacheEntry &entry = iter->second; PCacheEntry &entry = iter->second;
glUseProgram(entry.program.glprogid); glUseProgram(entry.program.glprogid);
CurrentShaderProgram = ShaderPair; CurrentShaderProgram = ShaderPair;
CurrentProgram = entry.program.glprogid; CurrentProgram = entry.program.glprogid;
return; return;
} }
PCacheEntry entry; PCacheEntry entry;
entry.program.vsid = CurrentVShader; entry.program.vsid = CurrentVShader;
entry.program.psid = CurrentFShader; entry.program.psid = CurrentFShader;
entry.program.glprogid = glCreateProgram(); entry.program.glprogid = glCreateProgram();
// Right, the program is created now // Right, the program is created now
// 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);
glUseProgram(entry.program.glprogid); glUseProgram(entry.program.glprogid);
// Dunno why this is needed when I have the binding // Dunno why this is needed when I have the binding
// points statically set in the shader source // points statically set in the shader source
// We should only need these two functions when we don't support binding but do support UBO // We should only need these two functions when we don't support binding but do support UBO
// Driver Bug? Nvidia GTX 570, 290.xx Driver, Linux x64 // Driver Bug? Nvidia GTX 570, 290.xx Driver, Linux x64
//if(!g_ActiveConfig.backend_info.bSupportsGLSLBinding) //if(!g_ActiveConfig.backend_info.bSupportsGLSLBinding)
{ {
glUniformBlockBinding( entry.program.glprogid, 0, 1 ); glUniformBlockBinding( entry.program.glprogid, 0, 1 );
glUniformBlockBinding( entry.program.glprogid, 1, 2 ); glUniformBlockBinding( entry.program.glprogid, 1, 2 );
} }
// 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
// We can remove this // We can remove this
//For some reason this fails on my hardware //For some reason this fails on my hardware
//glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations); //glGetUniformIndices(entry.program.glprogid, NUM_UNIFORMS, UniformNames, entry.program.UniformLocations);
//Got to do it this crappy way. //Got to do it this crappy way.
if(!g_ActiveConfig.backend_info.bSupportsGLSLUBO) if(!g_ActiveConfig.backend_info.bSupportsGLSLUBO)
for(int a = 0; a < NUM_UNIFORMS; ++a) for(int a = 0; a < NUM_UNIFORMS; ++a)
entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]); entry.program.UniformLocations[a] = glGetUniformLocation(entry.program.glprogid, UniformNames[a]);
// Need to get some attribute locations // Need to get some attribute locations
if(uid.uid.vsid != 0) // We have no vertex Shader if(uid.uid.vsid != 0) // We have no vertex Shader
{ {
entry.program.attrLoc[0] = glGetAttribLocation(entry.program.glprogid, "rawnorm1"); entry.program.attrLoc[0] = glGetAttribLocation(entry.program.glprogid, "rawnorm1");
entry.program.attrLoc[1] = glGetAttribLocation(entry.program.glprogid, "rawnorm2"); entry.program.attrLoc[1] = glGetAttribLocation(entry.program.glprogid, "rawnorm2");
entry.program.attrLoc[2] = glGetAttribLocation(entry.program.glprogid, "fposmtx"); entry.program.attrLoc[2] = glGetAttribLocation(entry.program.glprogid, "fposmtx");
if(entry.program.attrLoc[0] > 0) if(entry.program.attrLoc[0] > 0)
glEnableVertexAttribArray(entry.program.attrLoc[0]); glEnableVertexAttribArray(entry.program.attrLoc[0]);
if(entry.program.attrLoc[1] > 0) if(entry.program.attrLoc[1] > 0)
glEnableVertexAttribArray(entry.program.attrLoc[1]); glEnableVertexAttribArray(entry.program.attrLoc[1]);
if(entry.program.attrLoc[2] > 0) if(entry.program.attrLoc[2] > 0)
glEnableVertexAttribArray(entry.program.attrLoc[2]); glEnableVertexAttribArray(entry.program.attrLoc[2]);
} }
else else
entry.program.attrLoc[0] = entry.program.attrLoc[1] = entry.program.attrLoc[2] = 0; entry.program.attrLoc[0] = entry.program.attrLoc[1] = entry.program.attrLoc[2] = 0;
pshaders[ShaderPair] = entry; pshaders[ShaderPair] = entry;
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) void ProgramShaderCache::SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count)
{ {
assert(Buffer > 1); assert(Buffer > 1);
@ -154,16 +154,16 @@ namespace OGL
glBufferSubData(GL_UNIFORM_BUFFER, offset * 4 * 4, count * 4 * 4, f); glBufferSubData(GL_UNIFORM_BUFFER, offset * 4 * 4, count * 4 * 4, f);
} }
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(void) PROGRAMSHADER ProgramShaderCache::GetShaderProgram(void)
{ {
return pshaders[CurrentShaderProgram].program; return pshaders[CurrentShaderProgram].program;
} }
void ProgramShaderCache::Init(void) void ProgramShaderCache::Init(void)
{ {
// We have to get the UBO alignment here because // We have to get the UBO alignment here because
@ -188,18 +188,18 @@ namespace OGL
glBufferData(GL_UNIFORM_BUFFER, ROUND_UP(C_VENVCONST_END * 4 * 4, Align), NULL, GL_DYNAMIC_DRAW); glBufferData(GL_UNIFORM_BUFFER, ROUND_UP(C_VENVCONST_END * 4 * 4, Align), NULL, GL_DYNAMIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, 2, UBOBuffers[1]); glBindBufferBase(GL_UNIFORM_BUFFER, 2, UBOBuffers[1]);
} }
void ProgramShaderCache::Shutdown(void) void ProgramShaderCache::Shutdown(void)
{ {
PCache::iterator iter = pshaders.begin(); PCache::iterator iter = pshaders.begin();
for (; iter != pshaders.end(); iter++) for (; iter != pshaders.end(); iter++)
iter->second.Destroy(); iter->second.Destroy();
pshaders.clear(); pshaders.clear();
glDeleteBuffers(2, UBOBuffers); glDeleteBuffers(2, UBOBuffers);
} }
} }
void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p) void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p)
{ {
uid->uid.vsid = _v; uid->uid.vsid = _v;
uid->uid.psid = _p; uid->uid.psid = _p;
} }

View File

@ -25,39 +25,39 @@
#include "PixelShaderGen.h" #include "PixelShaderGen.h"
#include "VertexShaderGen.h" #include "VertexShaderGen.h"
union PID union PID
{ {
struct { struct {
GLuint vsid, psid; GLuint vsid, psid;
}; };
u64 id; u64 id;
}; };
class PROGRAMUID class PROGRAMUID
{ {
public: public:
PID uid; PID uid;
PROGRAMUID() PROGRAMUID()
{ {
uid.id = 0; uid.id = 0;
} }
PROGRAMUID(const PROGRAMUID& r) PROGRAMUID(const PROGRAMUID& r)
{ {
uid.id = r.uid.id; uid.id = r.uid.id;
} }
PROGRAMUID(GLuint _v, GLuint _p) PROGRAMUID(GLuint _v, GLuint _p)
{ {
uid.vsid = _v; uid.vsid = _v;
uid.psid = _p; uid.psid = _p;
} }
int GetNumValues() const int GetNumValues() const
{ {
return uid.id; return uid.id;
} }
}; };
void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p); void GetProgramShaderId(PROGRAMUID *uid, GLuint _v, GLuint _p);
@ -69,43 +69,43 @@ extern const char *UniformNames[NUM_UNIFORMS];
struct PROGRAMSHADER struct PROGRAMSHADER
{ {
PROGRAMSHADER() : glprogid(0), vsid(0), psid(0){} PROGRAMSHADER() : glprogid(0), vsid(0), psid(0){}
GLuint glprogid; // opengl program id GLuint glprogid; // opengl program id
GLuint vsid, psid; GLuint vsid, psid;
GLint attrLoc[3]; GLint attrLoc[3];
GLint UniformLocations[NUM_UNIFORMS]; GLint UniformLocations[NUM_UNIFORMS];
}; };
class ProgramShaderCache class ProgramShaderCache
{ {
struct PCacheEntry struct PCacheEntry
{ {
PROGRAMSHADER program; PROGRAMSHADER program;
int frameCount; int frameCount;
PCacheEntry() : frameCount(0) {} PCacheEntry() : frameCount(0) {}
void Destroy() { void Destroy() {
glDeleteProgram(program.glprogid); glDeleteProgram(program.glprogid);
program.glprogid = 0; program.glprogid = 0;
} }
}; };
typedef std::map<std::pair<u64, u64>, PCacheEntry> PCache; typedef std::map<std::pair<u64, u64>, PCacheEntry> PCache;
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 // For UBOS
static GLuint UBOBuffers[2]; // PS is 0, VS is 1 static GLuint UBOBuffers[2]; // PS is 0, VS is 1
public: public:
static PROGRAMSHADER GetShaderProgram(void); 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 SetUniformObjects(int Buffer, unsigned int offset, const float *f, unsigned int count = 1);
static void Init(void); static void Init(void);
static void Shutdown(void); static void Shutdown(void);
}; };

View File

@ -211,7 +211,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
if (pcfmt != PC_TEX_FMT_DXT1) if (pcfmt != PC_TEX_FMT_DXT1)
{ {
if (expanded_width != width) if (expanded_width != width)
glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width); glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
if (bHaveMipMaps && autogen_mips) if (bHaveMipMaps && autogen_mips)
{ {
@ -225,7 +225,7 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
} }
if (expanded_width != width) if (expanded_width != width)
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
} }
else else
{ {
@ -399,8 +399,8 @@ TextureCache::~TextureCache()
{ {
if (s_TempFramebuffer) if (s_TempFramebuffer)
{ {
glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer); glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer);
s_TempFramebuffer = 0; s_TempFramebuffer = 0;
} }
} }

View File

@ -61,20 +61,20 @@ void VertexShaderCache::Init()
if(g_ActiveConfig.bUseGLSL) if(g_ActiveConfig.bUseGLSL)
{ {
pSetVSConstant4f = SetGLSLVSConstant4f; pSetVSConstant4f = SetGLSLVSConstant4f;
pSetVSConstant4fv = SetGLSLVSConstant4fv; pSetVSConstant4fv = SetGLSLVSConstant4fv;
pSetMultiVSConstant4fv = SetMultiGLSLVSConstant4fv; pSetMultiVSConstant4fv = SetMultiGLSLVSConstant4fv;
pSetMultiVSConstant3fv = SetMultiGLSLVSConstant3fv; pSetMultiVSConstant3fv = SetMultiGLSLVSConstant3fv;
pCompileVertexShader = CompileGLSLVertexShader; pCompileVertexShader = CompileGLSLVertexShader;
} }
else else
{ {
pSetVSConstant4f = SetCGVSConstant4f; pSetVSConstant4f = SetCGVSConstant4f;
pSetVSConstant4fv = SetCGVSConstant4fv; pSetVSConstant4fv = SetCGVSConstant4fv;
pSetMultiVSConstant4fv = SetMultiCGVSConstant4fv; pSetMultiVSConstant4fv = SetMultiCGVSConstant4fv;
pSetMultiVSConstant3fv = SetMultiCGVSConstant3fv; pSetMultiVSConstant3fv = SetMultiCGVSConstant3fv;
pCompileVertexShader = CompileCGVertexShader; pCompileVertexShader = CompileCGVertexShader;
glEnable(GL_VERTEX_PROGRAM_ARB); glEnable(GL_VERTEX_PROGRAM_ARB);
} }
glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions); glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, (GLint *)&s_nMaxVertexInstructions);
@ -82,7 +82,7 @@ void VertexShaderCache::Init()
#if CG_VERSION_NUM == 2100 #if CG_VERSION_NUM == 2100
if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL) if (strstr((const char*)glGetString(GL_VENDOR), "ATI") != NULL)
{ {
s_nMaxVertexInstructions = 4096; s_nMaxVertexInstructions = 4096;
} }
#endif #endif
} }
@ -90,7 +90,7 @@ void VertexShaderCache::Init()
void VertexShaderCache::Shutdown() void VertexShaderCache::Shutdown()
{ {
for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter) for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter)
iter->second.Destroy(); iter->second.Destroy();
vshaders.clear(); vshaders.clear();
} }
@ -101,12 +101,12 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
GetVertexShaderId(&uid, components); GetVertexShaderId(&uid, components);
if (last_entry) if (last_entry)
{ {
if (uid == last_uid) if (uid == last_uid)
{ {
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components); ValidateVertexShaderIDs(API_OPENGL, vshaders[uid].safe_uid, vshaders[uid].shader.strprog, components);
return &last_entry->shader; return &last_entry->shader;
} }
} }
last_uid = uid; last_uid = uid;
@ -114,12 +114,12 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
VSCache::iterator iter = vshaders.find(uid); VSCache::iterator iter = vshaders.find(uid);
if (iter != vshaders.end()) if (iter != vshaders.end())
{ {
VSCacheEntry &entry = iter->second; VSCacheEntry &entry = iter->second;
last_entry = &entry; last_entry = &entry;
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components); ValidateVertexShaderIDs(API_OPENGL, entry.safe_uid, entry.shader.strprog, components);
return &last_entry->shader; return &last_entry->shader;
} }
// Make an entry in the table // Make an entry in the table
@ -130,17 +130,17 @@ VERTEXSHADER* VertexShaderCache::SetShader(u32 components)
#if defined(_DEBUG) || defined(DEBUGFAST) #if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) { if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) {
static int counter = 0; static int counter = 0;
char szTemp[MAX_PATH]; char szTemp[MAX_PATH];
sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++); sprintf(szTemp, "%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
SaveData(szTemp, code); SaveData(szTemp, code);
} }
#endif #endif
if (!code || !VertexShaderCache::CompileVertexShader(entry.shader, code)) { if (!code || !VertexShaderCache::CompileVertexShader(entry.shader, code)) {
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true); GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
return NULL; return NULL;
} }
INCSTAT(stats.numVertexShadersCreated); INCSTAT(stats.numVertexShadersCreated);
@ -160,8 +160,8 @@ void VertexShaderCache::DisableShader()
assert(true); assert(true);
if (ShaderEnabled) if (ShaderEnabled)
{ {
glDisable(GL_VERTEX_PROGRAM_ARB); glDisable(GL_VERTEX_PROGRAM_ARB);
ShaderEnabled = false; ShaderEnabled = false;
} }
} }
@ -172,14 +172,14 @@ void VertexShaderCache::SetCurrentShader(GLuint Shader)
assert(true); assert(true);
if (!ShaderEnabled) if (!ShaderEnabled)
{ {
glEnable(GL_VERTEX_PROGRAM_ARB); glEnable(GL_VERTEX_PROGRAM_ARB);
ShaderEnabled= true; ShaderEnabled= true;
} }
if (CurrentShader != Shader) if (CurrentShader != Shader)
{ {
if(Shader != 0) if(Shader != 0)
CurrentShader = Shader; CurrentShader = Shader;
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader); glBindProgramARB(GL_VERTEX_PROGRAM_ARB, CurrentShader);
} }
} }
// GLSL Specific // GLSL Specific
@ -227,16 +227,16 @@ void SetVSConstant4fvByName(const char * name, unsigned int offset, const float
{ {
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;
else else
{ {
glUniform4fv(tmp.UniformLocations[a] + offset, count, f); glUniform4fv(tmp.UniformLocations[a] + offset, count, f);
return; return;
} }
} }
} }
void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{ {
@ -252,12 +252,12 @@ void SetGLSLVSConstant4f(unsigned int const_number, float f1, float f2, float f3
} }
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))
{ {
unsigned int offset = const_number - VSVar_Loc[a].reg; unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf); SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf);
return; return;
} }
} }
} }
@ -270,12 +270,12 @@ void SetGLSLVSConstant4fv(unsigned int const_number, const float *f)
} }
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))
{ {
unsigned int offset = const_number - VSVar_Loc[a].reg; unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f); SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f);
return; return;
} }
} }
} }
@ -288,12 +288,12 @@ void SetMultiGLSLVSConstant4fv(unsigned int const_number, unsigned int count, co
} }
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))
{ {
unsigned int offset = const_number - VSVar_Loc[a].reg; unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count); SetVSConstant4fvByName(VSVar_Loc[a].name, offset, f, count);
return; return;
} }
} }
} }
@ -302,10 +302,10 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co
float buf[4 * C_VENVCONST_END]; float buf[4 * C_VENVCONST_END];
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
{ {
buf[4*i ] = *f++; buf[4*i ] = *f++;
buf[4*i+1] = *f++; buf[4*i+1] = *f++;
buf[4*i+2] = *f++; buf[4*i+2] = *f++;
buf[4*i+3] = 0.f; buf[4*i+3] = 0.f;
} }
if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) if (g_ActiveConfig.backend_info.bSupportsGLSLUBO)
{ {
@ -314,12 +314,12 @@ void SetMultiGLSLVSConstant3fv(unsigned int const_number, unsigned int count, co
} }
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))
{ {
unsigned int offset = const_number - VSVar_Loc[a].reg; unsigned int offset = const_number - VSVar_Loc[a].reg;
SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count); SetVSConstant4fvByName(VSVar_Loc[a].name, offset, buf, count);
return; return;
} }
} }
} }
@ -330,34 +330,34 @@ bool CompileCGVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
GLenum err = GL_REPORT_ERROR(); GLenum err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR) if (err != GL_NO_ERROR)
{ {
ERROR_LOG(VIDEO, "glError %08x before VS!", err); ERROR_LOG(VIDEO, "glError %08x before VS!", err);
} }
#if defined HAVE_CG && HAVE_CG #if defined HAVE_CG && HAVE_CG
CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", NULL); CGprogram tempprog = cgCreateProgram(g_cgcontext, CG_SOURCE, pstrprogram, g_cgvProf, "main", NULL);
if (!cgIsProgram(tempprog)) { if (!cgIsProgram(tempprog)) {
static int num_failures = 0; static int num_failures = 0;
char szTemp[MAX_PATH]; char szTemp[MAX_PATH];
sprintf(szTemp, "bad_vs_%04i.txt", num_failures++); sprintf(szTemp, "bad_vs_%04i.txt", num_failures++);
std::ofstream file(szTemp); std::ofstream file(szTemp);
file << pstrprogram; file << pstrprogram;
file.close(); file.close();
PanicAlert("Failed to compile vertex shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s", PanicAlert("Failed to compile vertex shader %d!\nThis usually happens when trying to use Dolphin with an outdated GPU or integrated GPU like the Intel GMA series.\n\nIf you're sure this is Dolphin's error anyway, post the contents of %s along with this error message at the forums.\n\nDebug info (%d):\n%s",
num_failures - 1, szTemp, num_failures - 1, szTemp,
g_cgfProf, g_cgfProf,
cgGetLastListing(g_cgcontext)); cgGetLastListing(g_cgcontext));
cgDestroyProgram(tempprog); cgDestroyProgram(tempprog);
ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext)); ERROR_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
ERROR_LOG(VIDEO, "%s", pstrprogram); ERROR_LOG(VIDEO, "%s", pstrprogram);
return false; return false;
} }
if (cgGetError() != CG_NO_ERROR) if (cgGetError() != CG_NO_ERROR)
{ {
WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext)); WARN_LOG(VIDEO, "Failed to load vs %s:", cgGetLastListing(g_cgcontext));
WARN_LOG(VIDEO, "%s", pstrprogram); WARN_LOG(VIDEO, "%s", pstrprogram);
} }
// This looks evil - we modify the program through the const char * we got from cgGetProgramString! // This looks evil - we modify the program through the const char * we got from cgGetProgramString!
@ -365,9 +365,9 @@ bool CompileCGVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM); char *pcompiledprog = (char*)cgGetProgramString(tempprog, CG_COMPILED_PROGRAM);
char *plocal = strstr(pcompiledprog, "program.local"); char *plocal = strstr(pcompiledprog, "program.local");
while (plocal != NULL) { while (plocal != NULL) {
const char* penv = " program.env"; const char* penv = " program.env";
memcpy(plocal, penv, 13); memcpy(plocal, penv, 13);
plocal = strstr(plocal + 13, "program.local"); plocal = strstr(plocal + 13, "program.local");
} }
glGenProgramsARB(1, &vs.glprogid); glGenProgramsARB(1, &vs.glprogid);
vs.bGLSL = false; vs.bGLSL = false;
@ -376,15 +376,15 @@ bool CompileCGVertexShader(VERTEXSHADER& vs, const char* pstrprogram)
glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog); glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLsizei)strlen(pcompiledprog), pcompiledprog);
err = GL_REPORT_ERROR(); err = GL_REPORT_ERROR();
if (err != GL_NO_ERROR) { if (err != GL_NO_ERROR) {
ERROR_LOG(VIDEO, "%s", pstrprogram); ERROR_LOG(VIDEO, "%s", pstrprogram);
ERROR_LOG(VIDEO, "%s", pcompiledprog); ERROR_LOG(VIDEO, "%s", pcompiledprog);
} }
cgDestroyProgram(tempprog); cgDestroyProgram(tempprog);
#endif #endif
if (g_ActiveConfig.bEnableShaderDebugging) if (g_ActiveConfig.bEnableShaderDebugging)
vs.strprog = pstrprogram; vs.strprog = pstrprogram;
return true; return true;
} }
@ -402,12 +402,12 @@ void SetMultiCGVSConstant4fv(unsigned int const_number, unsigned int count, cons
{ {
if(GLEW_EXT_gpu_program_parameters) if(GLEW_EXT_gpu_program_parameters)
{ {
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f); glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, f);
} }
else else
{ {
for (unsigned int i = 0; i < count; i++,f+=4) for (unsigned int i = 0; i < count; i++,f+=4)
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, f); glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, f);
} }
} }
@ -415,49 +415,49 @@ void SetMultiCGVSConstant3fv(unsigned int const_number, unsigned int count, cons
{ {
if(GLEW_EXT_gpu_program_parameters) if(GLEW_EXT_gpu_program_parameters)
{ {
float buf[4 * C_VENVCONST_END]; float buf[4 * C_VENVCONST_END];
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
{ {
buf[4*i ] = *f++; buf[4*i ] = *f++;
buf[4*i+1] = *f++; buf[4*i+1] = *f++;
buf[4*i+2] = *f++; buf[4*i+2] = *f++;
buf[4*i+3] = 0.f; buf[4*i+3] = 0.f;
} }
glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, buf); glProgramEnvParameters4fvEXT(GL_VERTEX_PROGRAM_ARB, const_number, count, buf);
} }
else else
{ {
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
{ {
float buf[4]; float buf[4];
buf[0] = *f++; buf[0] = *f++;
buf[1] = *f++; buf[1] = *f++;
buf[2] = *f++; buf[2] = *f++;
buf[3] = 0.f; buf[3] = 0.f;
glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, buf); glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, const_number + i, buf);
} }
} }
} }
// Renderer Functions // Renderer Functions
void Renderer::SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4) void Renderer::SetVSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{ {
pSetVSConstant4f(const_number, f1, f2, f3, f4); pSetVSConstant4f(const_number, f1, f2, f3, f4);
} }
void Renderer::SetVSConstant4fv(unsigned int const_number, const float *f) void Renderer::SetVSConstant4fv(unsigned int const_number, const float *f)
{ {
pSetVSConstant4fv(const_number, f); pSetVSConstant4fv(const_number, f);
} }
void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f) void Renderer::SetMultiVSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{ {
pSetMultiVSConstant4fv(const_number, count, f); pSetMultiVSConstant4fv(const_number, count, f);
} }
void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f) void Renderer::SetMultiVSConstant3fv(unsigned int const_number, unsigned int count, const float *f)
{ {
pSetMultiVSConstant3fv(const_number, count, f); pSetMultiVSConstant3fv(const_number, count, f);
} }

View File

@ -109,23 +109,23 @@ std::string VideoBackend::GetName()
void GetShaders(std::vector<std::string> &shaders) void GetShaders(std::vector<std::string> &shaders)
{ {
shaders.clear(); shaders.clear();
if (File::IsDirectory(File::GetUserPath(D_SHADERS_IDX))) if (File::IsDirectory(File::GetUserPath(D_SHADERS_IDX)))
{ {
File::FSTEntry entry; File::FSTEntry entry;
File::ScanDirectoryTree(File::GetUserPath(D_SHADERS_IDX), entry); File::ScanDirectoryTree(File::GetUserPath(D_SHADERS_IDX), entry);
for (u32 i = 0; i < entry.children.size(); i++) for (u32 i = 0; i < entry.children.size(); i++)
{ {
std::string name = entry.children[i].virtualName.c_str(); std::string name = entry.children[i].virtualName.c_str();
if (!strcasecmp(name.substr(name.size() - 4).c_str(), ".txt")) if (!strcasecmp(name.substr(name.size() - 4).c_str(), ".txt"))
name = name.substr(0, name.size() - 4); name = name.substr(0, name.size() - 4);
shaders.push_back(name); shaders.push_back(name);
} }
} }
else else
{ {
File::CreateDir(File::GetUserPath(D_SHADERS_IDX).c_str()); File::CreateDir(File::GetUserPath(D_SHADERS_IDX).c_str());
} }
} }
void InitBackendInfo() void InitBackendInfo()