From f54c270042ff2ca2d5723d3de0e151fcc1d61f86 Mon Sep 17 00:00:00 2001 From: Alexander Szpakowski Date: Mon, 24 Dec 2012 17:07:29 -0500 Subject: [PATCH] minor cleanup and fixes --- src/modules/graphics/opengl/ShaderEffect.cpp | 10 ++-- src/modules/graphics/opengl/ShaderEffect.h | 5 +- src/scripts/graphics.lua | 24 ++++++---- src/scripts/graphics.lua.h | 49 +++++++++++++++----- 4 files changed, 60 insertions(+), 28 deletions(-) diff --git a/src/modules/graphics/opengl/ShaderEffect.cpp b/src/modules/graphics/opengl/ShaderEffect.cpp index d57f15e60..ebce4011a 100644 --- a/src/modules/graphics/opengl/ShaderEffect.cpp +++ b/src/modules/graphics/opengl/ShaderEffect.cpp @@ -122,7 +122,7 @@ GLuint ShaderEffect::createShader(const ShaderSource &source) if (err == GL_INVALID_OPERATION) // should only happen between glBegin() and glEnd() throw love::Exception("Cannot create %s shader object.", shadertypename); - else if (err == GL_INVALID_ENUM) + else if (err == GL_INVALID_ENUM) // invalid or unsupported shader type throw love::Exception("Cannot create %s shader object: %s shaders not supported.", shadertypename, shadertypename); } @@ -189,9 +189,9 @@ bool ShaderEffect::loadVolatile() std::vector shaderids; - std::vector::const_iterator cursource; - for (cursource = _shadersources.begin(); cursource != _shadersources.end(); ++cursource) - shaderids.push_back(createShader(*cursource)); + std::vector::const_iterator source; + for (source = _shadersources.begin(); source != _shadersources.end(); ++source) + shaderids.push_back(createShader(*source)); if (shaderids.size() == 0) throw love::Exception("Cannot create shader effect: no valid source code!"); @@ -323,9 +323,7 @@ void ShaderEffect::sendFloat(const std::string &name, int size, const GLfloat *v GLint location = getUniformLocation(name); if (size < 1 || size > 4) - { throw love::Exception("Invalid variable size: %d (expected 1-4).", size); - } switch (size) { diff --git a/src/modules/graphics/opengl/ShaderEffect.h b/src/modules/graphics/opengl/ShaderEffect.h index 421ffd9a7..1d43ed53c 100644 --- a/src/modules/graphics/opengl/ShaderEffect.h +++ b/src/modules/graphics/opengl/ShaderEffect.h @@ -58,6 +58,7 @@ public: ShaderEffect(const std::vector &shadersources); virtual ~ShaderEffect(); + std::string getWarnings() const; virtual bool loadVolatile(); @@ -69,7 +70,7 @@ public: static std::string getGLSLVersion(); static bool isSupported(); - static ShaderEffect *current; + static ShaderEffect *current; // pointer to currently active ShaderEffect void sendFloat(const std::string &name, int size, const GLfloat *vec, int count); void sendMatrix(const std::string &name, int size, const GLfloat *m, int count); @@ -82,7 +83,7 @@ private: GLuint createShader(const ShaderSource &source); void createProgram(const std::vector &shaders); - std::vector _shadersources; // list of all shader code attached to this ShaderEffect + std::vector _shadersources; // all shader code attached to this ShaderEffect GLuint _program; // volatile diff --git a/src/scripts/graphics.lua b/src/scripts/graphics.lua index f81b2da8a..e052a771b 100644 --- a/src/scripts/graphics.lua +++ b/src/scripts/graphics.lua @@ -1282,11 +1282,9 @@ do love.graphics.printf = _printf love.graphics.printf(...) end - - -- PIXEL EFFECTS - local HEADER_LINE_COUNT = 7 local GLSL_VERT = { + HEADER_LINE_COUNT = 7, HEADER = [[ #version 120 #define number float @@ -1304,6 +1302,7 @@ void main() { } local GLSL_FRAG = { + HEADER_LINE_COUNT = 7, HEADER = [[ #version 120 #define number float @@ -1325,20 +1324,20 @@ void main() { local s = vertcode:gsub("\r\n\t", " ") s = s:gsub("%w+(%s+)%(", "") if s:match("vec4 effect%(") then - fragcode = vertcode + fragcode = vertcode -- first argument contains frag shader code end if not s:match("vec4 transform%(") then - vertcode = nil + vertcode = nil -- first argument doesn't contain vert shader code end end if fragcode then local s = fragcode:gsub("\r\n\t", " ") s = s:gsub("%w+(%s+)%(", "") if s:match("vec4 transform%(") then - vertcode = fragcode + vertcode = fragcode -- second argument contains vert shader code end if not s:match("vec4 effect%(") then - fragcode = nil + fragcode = nil -- second argument doesn't contain frag shader code end end @@ -1364,10 +1363,17 @@ void main() { -- ati compiler message: -- ERROR 0:: error/warning(#[NUMBER]) [ERRORNAME]: linenumber, what, message = l:match("^%w+: 0:(%d+):%s*(%w+)%([^%)]+%)%s*(.+)$") + if not linenumber then + -- OSX compiler message: + -- ERROR: 0:: + what, linenumber, message = l:match("^(%w+): %d+:(%d+): (.+)$") + end end if linenumber and what and message then - local headerlinecount = GLSL_FRAG.HEADER_LINE_COUNT - if shadertype == "vertex" 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 diff --git a/src/scripts/graphics.lua.h b/src/scripts/graphics.lua.h index 580db6280..2011c4efc 100644 --- a/src/scripts/graphics.lua.h +++ b/src/scripts/graphics.lua.h @@ -6259,12 +6259,11 @@ const unsigned char graphics_lua[] = 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x66, 0x28, 0x2e, 0x2e, 0x2e, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, - 0x09, 0x2d, 0x2d, 0x20, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x20, 0x45, 0x46, 0x46, 0x45, 0x43, 0x54, 0x53, 0x0a, - 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x5f, 0x4c, 0x49, 0x4e, 0x45, - 0x5f, 0x43, 0x4f, 0x55, 0x4e, 0x54, 0x20, 0x3d, 0x20, 0x37, 0x0a, 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, @@ -6293,6 +6292,8 @@ 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, @@ -6336,12 +6337,17 @@ const unsigned char graphics_lua[] = 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x73, 0x3a, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x28, 0x22, 0x76, 0x65, 0x63, 0x34, 0x20, 0x65, 0x66, 0x66, 0x65, 0x63, 0x74, 0x25, 0x28, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x66, 0x72, 0x61, 0x67, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x76, 0x65, 0x72, - 0x74, 0x63, 0x6f, 0x64, 0x65, 0x0a, + 0x74, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x2d, 0x2d, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x61, 0x72, 0x67, + 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x73, 0x20, 0x66, 0x72, 0x61, + 0x67, 0x20, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x3a, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x28, 0x22, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x6f, 0x72, 0x6d, 0x25, 0x28, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x76, 0x65, 0x72, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x76, 0x65, 0x72, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, + 0x20, 0x2d, 0x2d, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, + 0x20, 0x64, 0x6f, 0x65, 0x73, 0x6e, 0x27, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x20, 0x76, + 0x65, 0x72, 0x74, 0x20, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 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, @@ -6354,12 +6360,17 @@ const unsigned char graphics_lua[] = 0x34, 0x20, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x6f, 0x72, 0x6d, 0x25, 0x28, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x76, 0x65, 0x72, 0x74, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x66, 0x72, 0x61, - 0x67, 0x63, 0x6f, 0x64, 0x65, 0x0a, + 0x67, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x2d, 0x2d, 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x61, 0x72, + 0x67, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x73, 0x20, 0x76, 0x65, + 0x72, 0x74, 0x20, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x73, 0x3a, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x28, 0x22, 0x76, 0x65, 0x63, 0x34, 0x20, 0x65, 0x66, 0x66, 0x65, 0x63, 0x74, 0x25, 0x28, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x66, 0x72, 0x61, 0x67, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x66, 0x72, 0x61, 0x67, 0x63, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x6e, 0x69, 0x6c, + 0x20, 0x2d, 0x2d, 0x20, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65, 0x6e, + 0x74, 0x20, 0x64, 0x6f, 0x65, 0x73, 0x6e, 0x27, 0x74, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x20, + 0x66, 0x72, 0x61, 0x67, 0x20, 0x73, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x63, 0x6f, 0x64, 0x65, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 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, @@ -6423,16 +6434,32 @@ const unsigned char graphics_lua[] = 0x74, 0x63, 0x68, 0x28, 0x22, 0x5e, 0x25, 0x77, 0x2b, 0x3a, 0x20, 0x30, 0x3a, 0x28, 0x25, 0x64, 0x2b, 0x29, 0x3a, 0x25, 0x73, 0x2a, 0x28, 0x25, 0x77, 0x2b, 0x29, 0x25, 0x28, 0x5b, 0x5e, 0x25, 0x29, 0x5d, 0x2b, 0x25, 0x29, 0x25, 0x73, 0x2a, 0x28, 0x2e, 0x2b, 0x29, 0x24, 0x22, 0x29, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x6e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x4f, 0x53, 0x58, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x69, 0x6c, + 0x65, 0x72, 0x20, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x3a, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x3a, 0x20, 0x30, 0x3a, 0x3c, + 0x6c, 0x69, 0x6e, 0x65, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x3e, 0x3a, 0x20, 0x3c, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x3e, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x09, 0x77, 0x68, 0x61, 0x74, 0x2c, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x6e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x2c, 0x20, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x3d, 0x20, 0x6c, 0x3a, 0x6d, + 0x61, 0x74, 0x63, 0x68, 0x28, 0x22, 0x5e, 0x28, 0x25, 0x77, 0x2b, 0x29, 0x3a, 0x20, 0x25, 0x64, 0x2b, 0x3a, + 0x28, 0x25, 0x64, 0x2b, 0x29, 0x3a, 0x20, 0x28, 0x2e, 0x2b, 0x29, 0x24, 0x22, 0x29, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a, 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, 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, + 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, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, + 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,