From d62878fbb8aa163f8279c0abc6eedc4504e1fb96 Mon Sep 17 00:00:00 2001 From: Alexander Szpakowski Date: Fri, 28 Dec 2012 21:32:13 -0400 Subject: [PATCH] Use GLSL #line preprocessor directive instead of manually trying to convert error message lines; flag shader objects for lazy-deletion after linking with program object instead of detaching them immediately (debuggers can now view source code of shader programs) --- src/modules/graphics/opengl/ShaderEffect.cpp | 19 +-------- src/modules/graphics/opengl/ShaderEffect.h | 2 +- src/scripts/graphics.lua | 19 +++------ src/scripts/graphics.lua.h | 43 ++++++-------------- 4 files changed, 21 insertions(+), 62 deletions(-) diff --git a/src/modules/graphics/opengl/ShaderEffect.cpp b/src/modules/graphics/opengl/ShaderEffect.cpp index ebce4011a..e1d5d61e9 100644 --- a/src/modules/graphics/opengl/ShaderEffect.cpp +++ b/src/modules/graphics/opengl/ShaderEffect.cpp @@ -167,7 +167,7 @@ void ShaderEffect::createProgram(const std::vector &shaderids) glLinkProgram(_program); for (it = shaderids.begin(); it != shaderids.end(); ++it) - glDetachShader(_program, *it); // we can freely detach shaders after linking + glDeleteShader(*it); // flag shaders for deletion as soon as program object is deleted GLint link_ok; glGetProgramiv(_program, GL_LINK_STATUS, &link_ok); @@ -196,22 +196,7 @@ bool ShaderEffect::loadVolatile() if (shaderids.size() == 0) throw love::Exception("Cannot create shader effect: no valid source code!"); - try - { - createProgram(shaderids); - } - catch (love::Exception &e) - { - std::vector::const_iterator it; - for (it = shaderids.begin(); it != shaderids.end(); ++it) - glDeleteShader(*it); - - throw; - } - - std::vector::const_iterator it; - for (it = shaderids.begin(); it != shaderids.end(); ++it) - glDeleteShader(*it); + createProgram(shaderids); if (current == this) { diff --git a/src/modules/graphics/opengl/ShaderEffect.h b/src/modules/graphics/opengl/ShaderEffect.h index 1d43ed53c..3b85f4587 100644 --- a/src/modules/graphics/opengl/ShaderEffect.h +++ b/src/modules/graphics/opengl/ShaderEffect.h @@ -81,7 +81,7 @@ private: GLint getUniformLocation(const std::string &name); void checkSetUniformError(); GLuint createShader(const ShaderSource &source); - void createProgram(const std::vector &shaders); + void createProgram(const std::vector &shaderids); std::vector _shadersources; // all shader code attached to this ShaderEffect diff --git a/src/scripts/graphics.lua b/src/scripts/graphics.lua index e052a771b..3d1b1e64e 100644 --- a/src/scripts/graphics.lua +++ b/src/scripts/graphics.lua @@ -1284,7 +1284,6 @@ do end local GLSL_VERT = { - HEADER_LINE_COUNT = 7, HEADER = [[ #version 120 #define number float @@ -1292,7 +1291,8 @@ do #define extern uniform #define Texel texture2D #define VERTEX -uniform sampler2D _tex0_;]], +uniform sampler2D _tex0_; +#line 0]], FOOTER = [[ void main() { gl_TexCoord[0] = gl_MultiTexCoord0; @@ -1302,7 +1302,6 @@ void main() { } local GLSL_FRAG = { - HEADER_LINE_COUNT = 7, HEADER = [[ #version 120 #define number float @@ -1310,7 +1309,8 @@ void main() { #define extern uniform #define Texel texture2D #define PIXEL -uniform sampler2D _tex0_;]], +uniform sampler2D _tex0_; +#line 0]], FOOTER = [[ void main() { // fix weird crashing issue in OSX when _tex0_ is unused within effect() @@ -1342,10 +1342,10 @@ void main() { end if vertcode then - vertcode = table.concat{GLSL_VERT.HEADER, "\n", vertcode, GLSL_VERT.FOOTER} + vertcode = table.concat({GLSL_VERT.HEADER, vertcode, GLSL_VERT.FOOTER}, "\n") end if fragcode then - fragcode = table.concat{GLSL_FRAG.HEADER, "\n", fragcode, GLSL_FRAG.FOOTER} + fragcode = table.concat({GLSL_FRAG.HEADER, fragcode, GLSL_FRAG.FOOTER}, "\n") end return vertcode, fragcode @@ -1370,13 +1370,6 @@ void main() { end end if linenumber and what and message then - local headerlinecount = 0 - if shadertype == "fragment" then - headerlinecount = GLSL_FRAG.HEADER_LINE_COUNT - elseif shadertype == "vertex" then - headerlinecount = GLSL_VERT.HEADER_LINE_COUNT - end - linenumber = linenumber - headerlinecount lines[#lines+1] = ("Line %d: %s: %s"):format(linenumber, what, message) end end diff --git a/src/scripts/graphics.lua.h b/src/scripts/graphics.lua.h index 2011c4efc..b02ddfd7a 100644 --- a/src/scripts/graphics.lua.h +++ b/src/scripts/graphics.lua.h @@ -6262,8 +6262,6 @@ const unsigned char graphics_lua[] = 0x09, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x20, 0x3d, 0x20, 0x7b, 0x0a, - 0x09, 0x09, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x5f, 0x4c, 0x49, 0x4e, 0x45, 0x5f, 0x43, 0x4f, 0x55, 0x4e, - 0x54, 0x20, 0x3d, 0x20, 0x37, 0x2c, 0x0a, 0x09, 0x09, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x20, 0x3d, 0x20, 0x5b, 0x5b, 0x0a, 0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x32, 0x30, 0x0a, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, 0x66, 0x6c, 0x6f, @@ -6276,7 +6274,8 @@ const unsigned char graphics_lua[] = 0x75, 0x72, 0x65, 0x32, 0x44, 0x0a, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, - 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x3b, 0x5d, 0x5d, 0x2c, 0x0a, + 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x3b, 0x0a, + 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x30, 0x5d, 0x5d, 0x2c, 0x0a, 0x09, 0x09, 0x46, 0x4f, 0x4f, 0x54, 0x45, 0x52, 0x20, 0x3d, 0x20, 0x5b, 0x5b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x20, 0x7b, 0x0a, 0x09, 0x67, 0x6c, 0x5f, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x5b, 0x30, 0x5d, 0x20, 0x3d, 0x20, @@ -6292,8 +6291,6 @@ const unsigned char graphics_lua[] = 0x09, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x46, 0x52, 0x41, 0x47, 0x20, 0x3d, 0x20, 0x7b, 0x0a, - 0x09, 0x09, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x5f, 0x4c, 0x49, 0x4e, 0x45, 0x5f, 0x43, 0x4f, 0x55, 0x4e, - 0x54, 0x20, 0x3d, 0x20, 0x37, 0x2c, 0x0a, 0x09, 0x09, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x20, 0x3d, 0x20, 0x5b, 0x5b, 0x0a, 0x23, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x31, 0x32, 0x30, 0x0a, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, 0x66, 0x6c, 0x6f, @@ -6306,7 +6303,8 @@ const unsigned char graphics_lua[] = 0x75, 0x72, 0x65, 0x32, 0x44, 0x0a, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, - 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x3b, 0x5d, 0x5d, 0x2c, 0x0a, + 0x5f, 0x74, 0x65, 0x78, 0x30, 0x5f, 0x3b, 0x0a, + 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x30, 0x5d, 0x5d, 0x2c, 0x0a, 0x09, 0x09, 0x46, 0x4f, 0x4f, 0x54, 0x45, 0x52, 0x20, 0x3d, 0x20, 0x5b, 0x5b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x20, 0x7b, 0x0a, 0x09, 0x2f, 0x2f, 0x20, 0x66, 0x69, 0x78, 0x20, 0x77, 0x65, 0x69, 0x72, 0x64, 0x20, 0x63, 0x72, 0x61, 0x73, @@ -6375,17 +6373,17 @@ const unsigned char graphics_lua[] = 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x76, 0x65, 0x72, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x76, 0x65, 0x72, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x61, 0x62, 0x6c, - 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x7b, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, - 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x2c, 0x20, 0x76, 0x65, 0x72, - 0x74, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x2e, 0x46, - 0x4f, 0x4f, 0x54, 0x45, 0x52, 0x7d, 0x0a, + 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x7b, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, + 0x54, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, 0x76, 0x65, 0x72, 0x74, 0x63, 0x6f, 0x64, 0x65, + 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x2e, 0x46, 0x4f, 0x4f, 0x54, 0x45, 0x52, + 0x7d, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x69, 0x66, 0x20, 0x66, 0x72, 0x61, 0x67, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x66, 0x72, 0x61, 0x67, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x61, 0x62, 0x6c, - 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x7b, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x46, 0x52, 0x41, 0x47, - 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x2c, 0x20, 0x66, 0x72, 0x61, - 0x67, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x46, 0x52, 0x41, 0x47, 0x2e, 0x46, - 0x4f, 0x4f, 0x54, 0x45, 0x52, 0x7d, 0x0a, + 0x65, 0x2e, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x7b, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x46, 0x52, 0x41, + 0x47, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, 0x66, 0x72, 0x61, 0x67, 0x63, 0x6f, 0x64, 0x65, + 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x46, 0x52, 0x41, 0x47, 0x2e, 0x46, 0x4f, 0x4f, 0x54, 0x45, 0x52, + 0x7d, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x0a, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x0a, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x65, 0x72, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x2c, @@ -6450,23 +6448,6 @@ const unsigned char graphics_lua[] = 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x77, 0x68, 0x61, 0x74, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x6c, 0x69, - 0x6e, 0x65, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x30, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x74, 0x79, 0x70, 0x65, 0x20, - 0x3d, 0x3d, 0x20, 0x22, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x09, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x6c, 0x69, 0x6e, 0x65, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x46, 0x52, 0x41, 0x47, 0x2e, 0x48, 0x45, 0x41, - 0x44, 0x45, 0x52, 0x5f, 0x4c, 0x49, 0x4e, 0x45, 0x5f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x74, - 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x22, 0x20, 0x74, 0x68, - 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x09, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x6c, 0x69, 0x6e, 0x65, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x2e, 0x48, 0x45, 0x41, - 0x44, 0x45, 0x52, 0x5f, 0x4c, 0x49, 0x4e, 0x45, 0x5f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, 0x3d, 0x20, 0x6c, - 0x69, 0x6e, 0x65, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x20, 0x2d, 0x20, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, - 0x6c, 0x69, 0x6e, 0x65, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x5b, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x2b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x28, 0x22, 0x4c, 0x69, 0x6e, 0x65, 0x20, 0x25, 0x64, 0x3a, 0x20, 0x25, 0x73, 0x3a, 0x20, 0x25, 0x73, 0x22, 0x29, 0x3a, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x28, 0x6c, 0x69, 0x6e, 0x65, 0x6e,