diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index d7017a7e0a..6a4d384ba6 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -528,24 +528,6 @@ const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType if (ApiType == API_OPENGL) { - // A few required defines and ones that will make our lives a lot easier - WRITE(p, "#version 130\n"); - if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) - WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n"); - WRITE(p, "#define ATTRIN in\n"); - WRITE(p, "#define ATTROUT out\n"); - WRITE(p, "#define VARYIN in\n"); - WRITE(p, "#define VARYOUT out\n"); - - // Silly differences - WRITE(p, "#define float2 vec2\n"); - WRITE(p, "#define float3 vec3\n"); - WRITE(p, "#define float4 vec4\n"); - - // cg to glsl function translation - WRITE(p, "#define frac(x) fract(x)\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"); // A function here // Fmod implementation gleaned from Nvidia diff --git a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp index 3dbb3aaa38..b20b6aeea0 100644 --- a/Source/Core/VideoCommon/Src/TextureConversionShader.cpp +++ b/Source/Core/VideoCommon/Src/TextureConversionShader.cpp @@ -822,27 +822,6 @@ const char *GenerateEncodingShader(u32 format,API_TYPE ApiType) char *p = text; - if (ApiType == API_OPENGL) - { - // A few required defines and ones that will make our lives a lot easier - WRITE(p, "#version 130\n"); - if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) - WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n"); - - // Silly differences - WRITE(p, "#define float2 vec2\n"); - WRITE(p, "#define float3 vec3\n"); - WRITE(p, "#define float4 vec4\n"); - - // cg to glsl function translation - WRITE(p, "#define frac(x) fract(x)\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"); - - // We require this here - WRITE(p, "#ifdef GL_ARB_texture_rectangle\n #extension GL_ARB_texture_rectangle : require\n#endif\n"); - } - switch (format) { case GX_TF_I4: diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 42b63f0929..a84d680855 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -184,29 +184,6 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE ApiType) char *p = text; WRITE(p, "//Vertex Shader: comp:%x, \n", components); - if (ApiType == API_OPENGL) - { - // A few required defines and ones that will make our lives a lot easier - - WRITE(p, "#version 130\n"); - if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) - WRITE(p, "#extension GL_ARB_uniform_buffer_object : enable\n"); - WRITE(p, "#define ATTRIN in\n"); - WRITE(p, "#define ATTROUT out\n"); - WRITE(p, "#define VARYIN in\n"); - WRITE(p, "#define VARYOUT out\n"); - - // Silly differences - WRITE(p, "#define float2 vec2\n"); - WRITE(p, "#define float3 vec3\n"); - WRITE(p, "#define float4 vec4\n"); - - // cg to glsl function translation - WRITE(p, "#define frac(x) fract(x)\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"); - } - // uniforms if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) WRITE(p, "layout(std140) uniform VSBlock {\n"); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp index 0fe2ef1d68..51a7887308 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.cpp @@ -26,20 +26,21 @@ namespace OGL static const u32 UBO_LENGTH = 4*1024*1024; -static GLuint CurrentProgram = 0; -ProgramShaderCache::PCache ProgramShaderCache::pshaders; GLintptr ProgramShaderCache::s_vs_data_offset; u8 *ProgramShaderCache::s_ubo_buffer; u32 ProgramShaderCache::s_ubo_buffer_size; bool ProgramShaderCache::s_ubo_dirty; -LinearDiskCache g_program_disk_cache; - static StreamBuffer *s_buffer; +LinearDiskCache g_program_disk_cache; +static GLuint CurrentProgram = 0; +ProgramShaderCache::PCache ProgramShaderCache::pshaders; ProgramShaderCache::PCacheEntry* ProgramShaderCache::last_entry; SHADERUID ProgramShaderCache::last_uid; +static char s_glsl_header[1024] = ""; + const char *UniformNames[NUM_UNIFORMS] = { // PIXEL SHADER UNIFORMS @@ -291,7 +292,9 @@ bool ProgramShaderCache::CompileShader ( SHADER& shader, const char* vcode, cons FILE *fp = fopen(szTemp, "wb"); fwrite(infoLog, length, 1, fp); delete[] infoLog; + fwrite(s_glsl_header, strlen(s_glsl_header), 1, fp); fwrite(vcode, strlen(vcode), 1, fp); + fwrite(s_glsl_header, strlen(s_glsl_header), 1, fp); fwrite(pcode, strlen(pcode), 1, fp); fclose(fp); } @@ -318,9 +321,9 @@ GLuint ProgramShaderCache::CompileSingleShader (GLuint type, const char* code ) { GLuint result = glCreateShader(type); - const char *src[] = {code}; + const char *src[] = {s_glsl_header, code}; - glShaderSource(result, 1, src, NULL); + glShaderSource(result, 2, src, NULL); glCompileShader(result); #if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL) GLsizei length = 0; @@ -335,6 +338,7 @@ GLuint ProgramShaderCache::CompileSingleShader (GLuint type, const char* code ) sprintf(szTemp, "ps_%d.txt", result); FILE *fp = fopen(szTemp, "wb"); fwrite(infoLog, strlen(infoLog), 1, fp); + fwrite(s_glsl_header, strlen(s_glsl_header), 1, fp); fwrite(code, strlen(code), 1, fp); fclose(fp); delete[] infoLog; @@ -433,6 +437,8 @@ void ProgramShaderCache::Init(void) SETSTAT(stats.numPixelShadersAlive, pshaders.size()); } + CreateHeader(); + CurrentProgram = 0; last_entry = NULL; } @@ -480,6 +486,36 @@ void ProgramShaderCache::Shutdown(void) } } +void ProgramShaderCache::CreateHeader ( void ) +{ + snprintf(s_glsl_header, sizeof(s_glsl_header), + "#version %s\n" + "#extension GL_ARB_texture_rectangle : enable\n" + "%s\n" // ubo + + "\n"// A few required defines and ones that will make our lives a lot easier + "#define ATTRIN in\n" + "#define ATTROUT out\n" + "#define VARYIN in\n" + "#define VARYOUT out\n" + + // Silly differences + "#define float2 vec2\n" + "#define float3 vec3\n" + "#define float4 vec4\n" + + // hlsl to glsl function translation + "#define frac(x) fract(x)\n" + "#define saturate(x) clamp(x, 0.0f, 1.0f)\n" + "#define lerp(x, y, z) mix(x, y, z)\n" + + + , "130" + , g_ActiveConfig.backend_info.bSupportsGLSLUBO ? "#extension GL_ARB_uniform_buffer_object : enable" : "// ubo disabled" + ); +} + + void ProgramShaderCache::ProgramShaderCacheInserter::Read ( const SHADERUID& key, const u8* value, u32 value_size ) { const u8 *binary = value+sizeof(GLenum); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h index b8fbe40ef1..8903e800ba 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/ProgramShaderCache.h @@ -110,6 +110,7 @@ public: static void Init(void); static void Shutdown(void); + static void CreateHeader(void); private: class ProgramShaderCacheInserter : public LinearDiskCacheReader diff --git a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp index 19e36b0774..0ba2a5b1ae 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/RasterFont.cpp @@ -127,7 +127,6 @@ const u8 rasters[char_count][char_height] = { }; static const char *s_vertexShaderSrc = - "#version 130\n" "uniform vec2 charSize;\n" "in vec2 rawpos;\n" "in vec2 tex0;\n" @@ -138,7 +137,6 @@ static const char *s_vertexShaderSrc = "}\n"; static const char *s_fragmentShaderSrc = - "#version 130\n" "uniform sampler2D samp8;\n" "uniform vec4 color;\n" "in vec2 uv0;\n" diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index 1383fe648d..847ffa7acf 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -438,7 +438,6 @@ void Renderer::Init() s_pfont = new RasterFont(); ProgramShaderCache::CompileShader(s_ShowEFBCopyRegions, - "#version 130\n" "in vec2 rawpos;\n" "in vec3 color0;\n" "out vec4 c;\n" @@ -446,7 +445,6 @@ void Renderer::Init() " gl_Position = vec4(rawpos,0,1);\n" " c = vec4(color0, 1.0);\n" "}\n", - "#version 130\n" "in vec4 c;\n" "out vec4 ocol0;\n" "void main(void) {\n" diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp index 9a6f2c85ec..850bd39471 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureCache.cpp @@ -476,8 +476,6 @@ void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, co TextureCache::TextureCache() { const char *pColorMatrixProg = - "#version 130\n" - "#extension GL_ARB_texture_rectangle : enable\n" "uniform sampler2DRect samp9;\n" "uniform vec4 colmat[7];\n" "in vec2 uv0;\n" @@ -490,8 +488,6 @@ TextureCache::TextureCache() "}\n"; const char *pDepthMatrixProg = - "#version 130\n" - "#extension GL_ARB_texture_rectangle : enable\n" "uniform sampler2DRect samp9;\n" "uniform vec4 colmat[5];\n" "in vec2 uv0;\n" @@ -506,7 +502,6 @@ TextureCache::TextureCache() const char *VProgram = - "#version 130\n" "in vec2 rawpos;\n" "in vec2 tex0;\n" "out vec2 uv0;\n" diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp index 6914f00379..c076563310 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureConverter.cpp @@ -66,7 +66,6 @@ static int s_cached_srcWidth = 0; static int s_cached_srcHeight = 0; static const char *VProgram = - "#version 130\n" "in vec2 rawpos;\n" "in vec2 tex0;\n" "out vec2 uv0;\n" @@ -80,8 +79,6 @@ void CreatePrograms() { // Output is BGRA because that is slightly faster than RGBA. const char *FProgramRgbToYuyv = - "#version 130\n" - "#extension GL_ARB_texture_rectangle : enable\n" "uniform sampler2DRect samp9;\n" "in vec2 uv0;\n" "out vec4 ocol0;\n" @@ -98,8 +95,6 @@ void CreatePrograms() "}\n"; const char *FProgramYuyvToRgb = - "#version 130\n" - "#extension GL_ARB_texture_rectangle : enable\n" "uniform sampler2DRect samp9;\n" "in vec2 uv0;\n" "out vec4 ocol0;\n"