From 8b90f64440e05b588c0bc3fd58b9f299a90a997c Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 17 Apr 2014 19:48:16 -0300 Subject: [PATCH 01/14] Don't try to bind the love_PseudoInstanceID vertex shader attribute (it's disabled for now) --- src/modules/graphics/opengl/Shader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index 7b94e805c..f9de5707b 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -768,7 +768,7 @@ StringMap Shader::typeNames(Shader::t StringMap::Entry Shader::attribNameEntries[] = { - {"love_PseudoInstanceID", OpenGL::ATTRIB_PSEUDO_INSTANCE_ID}, +// {"love_PseudoInstanceID", OpenGL::ATTRIB_PSEUDO_INSTANCE_ID}, }; StringMap Shader::attribNames(Shader::attribNameEntries, sizeof(Shader::attribNameEntries)); From af88423285f44f9546526d234aac0360952418f5 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 23 Apr 2014 19:43:54 -0300 Subject: [PATCH 02/14] Fixed an attempted creation of an array with a constant size of 0 --- src/modules/graphics/opengl/Shader.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index f9de5707b..2240b55f5 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -186,8 +186,16 @@ void Shader::createProgram(const std::vector &shaderids) // Bind generic vertex attribute indices to names in the shader. for (int i = 0; i < int(OpenGL::ATTRIB_MAX_ENUM); i++) { + OpenGL::VertexAttrib attrib = (OpenGL::VertexAttrib) i; + + // FIXME: We skip this both because pseudo-instancing is temporarily + // disabled (see graphics.lua), and because binding a non-existant + // attribute name to a location causes a shader linker warning. + if (attrib == OpenGL::ATTRIB_PSEUDO_INSTANCE_ID) + continue; + const char *name = nullptr; - if (attribNames.find((OpenGL::VertexAttrib) i, name)) + if (attribNames.find(attrib, name)) glBindAttribLocation(program, i, (const GLchar *) name); } @@ -768,7 +776,7 @@ StringMap Shader::typeNames(Shader::t StringMap::Entry Shader::attribNameEntries[] = { -// {"love_PseudoInstanceID", OpenGL::ATTRIB_PSEUDO_INSTANCE_ID}, + {"love_PseudoInstanceID", OpenGL::ATTRIB_PSEUDO_INSTANCE_ID}, }; StringMap Shader::attribNames(Shader::attribNameEntries, sizeof(Shader::attribNameEntries)); From 3cf2a8f8a26ea06a96552305461c789f2d2d59f9 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 24 Apr 2014 15:21:53 -0300 Subject: [PATCH 03/14] Improved error message when love.math.setRandomSeed(0) is attempted (resolves issue #876) --- src/modules/math/RandomGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/math/RandomGenerator.cpp b/src/modules/math/RandomGenerator.cpp index 7c22a6e3f..6b14390f9 100644 --- a/src/modules/math/RandomGenerator.cpp +++ b/src/modules/math/RandomGenerator.cpp @@ -77,7 +77,7 @@ void RandomGenerator::setSeed(RandomGenerator::Seed newseed) { // 0 xor 0 is still 0, so Xorshift can't generate new numbers. if (newseed.b64 == 0) - throw love::Exception("Invalid random seed."); + throw love::Exception("Random seed cannot be 0."); seed = newseed; rng_state = seed; From 5484921597b3748b00495d8bc0b47957343e3c2b Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Fri, 25 Apr 2014 17:44:46 +0200 Subject: [PATCH 04/14] Make the stored data and type of Variant public, to allow for non-lua unpacking. NOTE: Not that useful in the love source, but might be nice if libraries try to interface with it. --- src/common/Variant.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/Variant.h b/src/common/Variant.h index 4592a2fa9..dd8b68fac 100644 --- a/src/common/Variant.h +++ b/src/common/Variant.h @@ -48,7 +48,6 @@ public: static Variant *fromLua(lua_State *L, int n, bool allowTables = true); void toLua(lua_State *L); -private: enum Type { UNKNOWN = 0, @@ -74,6 +73,8 @@ private: void *userdata; std::vector > *table; } data; + +private: love::Type udatatype; bits flags; From 853f741ba3ca97631ccf3d1e2a8a741e4dac36c0 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Fri, 25 Apr 2014 17:53:38 +0200 Subject: [PATCH 05/14] Prevent erroring in gen-modules when no source files are found (needed in some love-experiments branches) --- platform/unix/genmodules | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platform/unix/genmodules b/platform/unix/genmodules index 1b1ed65e7..5c4107d1a 100644 --- a/platform/unix/genmodules +++ b/platform/unix/genmodules @@ -78,11 +78,13 @@ genmodules() for library in *; do NAME="LOVE_LIBRARY_$(upper "$library")" flags="$flags library-$library" - - printf "if $NAME\n" - printf "liblove${love_amsuffix}_la_SOURCES += \\\\\n" FILES="$(sourcefind "$library" | sed "s/^/ /")" - printf "${FILES:0:${#FILES}-2}\nendif\n\n" + + if [[ ${#FILES} -gt 2 ]]; then + printf "if $NAME\n" + printf "liblove${love_amsuffix}_la_SOURCES += \\\\\n" + printf "${FILES:0:${#FILES}-2}\nendif\n\n" + fi done cd ../.. } From f30a0d72f0844ecf7d2f4e441a152b9d49f3451e Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 25 Apr 2014 20:32:42 -0300 Subject: [PATCH 06/14] Added Shader:getExternVariable(name). Returns the base type name ('float', 'image', etc.), the number of components (2 for a vec2), and number of array elements (1 for a non-array variable) for the extern variable with the specified name in the shader. Returns nil if the variable either doesn't exist or was optimized out by the driver's shader compiler. --- src/modules/graphics/opengl/Shader.cpp | 50 +++++++++++++++++--- src/modules/graphics/opengl/Shader.h | 52 ++++++++++++++------- src/modules/graphics/opengl/wrap_Shader.cpp | 33 +++++++++++++ src/modules/graphics/opengl/wrap_Shader.h | 1 + 4 files changed, 114 insertions(+), 22 deletions(-) diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index 2240b55f5..b95a0d10b 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -255,7 +255,7 @@ void Shader::mapActiveUniforms() } // If this is a built-in (LOVE-created) uniform, store the location. - BuiltinExtern builtin; + BuiltinUniform builtin; if (builtinNames.find(u.name.c_str(), builtin)) builtinUniforms[int(builtin)] = u.location; @@ -660,19 +660,36 @@ int Shader::getTextureUnit(const std::string &name) return texunit; } +Shader::UniformType Shader::getExternVariable(const std::string &name, int &components, int &count) +{ + auto it = uniforms.find(name); + + if (it == uniforms.end()) + { + components = 0; + count = 0; + return UNIFORM_UNKNOWN; + } + + components = getUniformTypeSize(it->second.type); + count = (int) it->second.count; + + return it->second.baseType; +} + bool Shader::hasVertexAttrib(OpenGL::VertexAttrib attrib) const { return vertexAttributes[int(attrib)] != -1; } -bool Shader::hasBuiltinExtern(BuiltinExtern builtin) const +bool Shader::hasBuiltinUniform(BuiltinUniform builtin) const { return builtinUniforms[int(builtin)] != -1; } -bool Shader::sendBuiltinFloat(BuiltinExtern builtin, int size, const GLfloat *vec, int count) +bool Shader::sendBuiltinFloat(BuiltinUniform builtin, int size, const GLfloat *vec, int count) { - if (!hasBuiltinExtern(builtin)) + if (!hasBuiltinUniform(builtin)) return false; GLint location = builtinUniforms[int(builtin)]; @@ -766,6 +783,16 @@ bool Shader::isSupported() return GLEE_VERSION_2_0 && getGLSLVersion() >= "1.2"; } +bool Shader::getConstant(const char *in, UniformType &out) +{ + return uniformTypes.find(in, out); +} + +bool Shader::getConstant(UniformType in, const char *&out) +{ + return uniformTypes.find(in, out); +} + StringMap::Entry Shader::typeNameEntries[] = { {"vertex", Shader::TYPE_VERTEX}, @@ -774,6 +801,17 @@ StringMap::Entry Shader::typeNameEntr StringMap Shader::typeNames(Shader::typeNameEntries, sizeof(Shader::typeNameEntries)); +StringMap::Entry Shader::uniformTypeEntries[] = +{ + {"float", Shader::UNIFORM_FLOAT}, + {"int", Shader::UNIFORM_INT}, + {"bool", Shader::UNIFORM_BOOL}, + {"image", Shader::UNIFORM_SAMPLER}, + {"unknown", Shader::UNIFORM_UNKNOWN}, +}; + +StringMap Shader::uniformTypes(Shader::uniformTypeEntries, sizeof(Shader::uniformTypeEntries)); + StringMap::Entry Shader::attribNameEntries[] = { {"love_PseudoInstanceID", OpenGL::ATTRIB_PSEUDO_INSTANCE_ID}, @@ -781,12 +819,12 @@ StringMap::Entry Shader::attribNa StringMap Shader::attribNames(Shader::attribNameEntries, sizeof(Shader::attribNameEntries)); -StringMap::Entry Shader::builtinNameEntries[] = +StringMap::Entry Shader::builtinNameEntries[] = { {"love_ScreenSize", Shader::BUILTIN_SCREEN_SIZE}, }; -StringMap Shader::builtinNames(Shader::builtinNameEntries, sizeof(Shader::builtinNameEntries)); +StringMap Shader::builtinNames(Shader::builtinNameEntries, sizeof(Shader::builtinNameEntries)); } // opengl } // graphics diff --git a/src/modules/graphics/opengl/Shader.h b/src/modules/graphics/opengl/Shader.h index db116cc47..38c70a137 100644 --- a/src/modules/graphics/opengl/Shader.h +++ b/src/modules/graphics/opengl/Shader.h @@ -56,13 +56,24 @@ public: TYPE_MAX_ENUM }; - // Built-in extern (uniform) variables. - enum BuiltinExtern + // Built-in uniform (extern) variables. + enum BuiltinUniform { BUILTIN_SCREEN_SIZE, BUILTIN_MAX_ENUM }; + // Types of potential uniform (extern) variables used in love's shaders. + enum UniformType + { + UNIFORM_FLOAT, + UNIFORM_INT, + UNIFORM_BOOL, + UNIFORM_SAMPLER, + UNIFORM_UNKNOWN, + UNIFORM_MAX_ENUM + }; + // Type for a list of shader source codes in the form of sources[shadertype] = code typedef std::map ShaderSources; @@ -135,12 +146,25 @@ public: **/ void sendTexture(const std::string &name, Texture *texture); + /** + * Gets the type, number of components, and number of array elements of + * an active 'extern' (uniform) variable in the shader. If a uniform + * variable with the specified name doesn't exist, returns UNIFORM_UNKNOWN + * and sets the 'components' and 'count' values to 0. + * + * @param name The name of the uniform variable in the source code. + * @param[out] components Number of components of the variable (2 for vec2.) + * @param[out] count Number of array elements, if the variable is an array. + * @return The base type of the uniform variable. + **/ + UniformType getExternVariable(const std::string &name, int &components, int &count); + /** * Internal use only. **/ bool hasVertexAttrib(OpenGL::VertexAttrib attrib) const; - bool hasBuiltinExtern(BuiltinExtern builtin) const; - bool sendBuiltinFloat(BuiltinExtern builtin, int size, const GLfloat *m, int count); + bool hasBuiltinUniform(BuiltinUniform builtin) const; + bool sendBuiltinFloat(BuiltinUniform builtin, int size, const GLfloat *m, int count); void checkSetScreenParams(); const std::map &getBoundRetainables() const; @@ -148,17 +172,10 @@ public: static std::string getGLSLVersion(); static bool isSupported(); -private: + static bool getConstant(const char *in, UniformType &out); + static bool getConstant(UniformType in, const char *&out); - // Types of potential uniform variables used in love's shaders. - enum UniformType - { - UNIFORM_FLOAT, - UNIFORM_INT, - UNIFORM_BOOL, - UNIFORM_SAMPLER, - UNIFORM_UNKNOWN - }; +private: // Represents a single uniform/extern shader variable. struct Uniform @@ -227,13 +244,16 @@ private: static StringMap::Entry typeNameEntries[]; static StringMap typeNames; + static StringMap::Entry uniformTypeEntries[]; + static StringMap uniformTypes; + // Names for the generic vertex attributes used by love. static StringMap::Entry attribNameEntries[]; static StringMap attribNames; // Names for the built-in uniform variables. - static StringMap::Entry builtinNameEntries[]; - static StringMap builtinNames; + static StringMap::Entry builtinNameEntries[]; + static StringMap builtinNames; }; } // opengl diff --git a/src/modules/graphics/opengl/wrap_Shader.cpp b/src/modules/graphics/opengl/wrap_Shader.cpp index dde23fde5..ed3ee1ed5 100644 --- a/src/modules/graphics/opengl/wrap_Shader.cpp +++ b/src/modules/graphics/opengl/wrap_Shader.cpp @@ -346,6 +346,38 @@ int w_Shader_send(lua_State *L) return luaL_argerror(L, 3, "number, boolean, table, image, or canvas expected"); } +int w_Shader_getExternVariable(lua_State *L) +{ + Shader *shader = luax_checkshader(L, 1); + const char *name = luaL_checkstring(L, 2); + + int components = 0; + int arrayelements = 0; + Shader::UniformType type = Shader::UNIFORM_UNKNOWN; + + type = shader->getExternVariable(name, components, arrayelements); + + // Check if the variable exists (function will set components to 0 if not.) + if (components > 0) + { + const char *tname = nullptr; + if (!Shader::getConstant(type, tname)) + return luaL_error(L, "Unknown extern variable type name."); + + lua_pushstring(L, tname); + lua_pushinteger(L, components); + lua_pushinteger(L, arrayelements); + } + else + { + lua_pushnil(L); + lua_pushnil(L); + lua_pushnil(L); + } + + return 3; +} + static const luaL_Reg functions[] = { { "getWarnings", w_Shader_getWarnings }, @@ -355,6 +387,7 @@ static const luaL_Reg functions[] = { "sendMatrix", w_Shader_sendMatrix }, { "sendTexture", w_Shader_sendTexture }, { "send", w_Shader_send }, + { "getExternVariable", w_Shader_getExternVariable }, // Deprecated since 0.9.1. { "sendImage", w_Shader_sendTexture }, diff --git a/src/modules/graphics/opengl/wrap_Shader.h b/src/modules/graphics/opengl/wrap_Shader.h index be7b81db4..f89295399 100644 --- a/src/modules/graphics/opengl/wrap_Shader.h +++ b/src/modules/graphics/opengl/wrap_Shader.h @@ -38,6 +38,7 @@ int w_Shader_sendFloat(lua_State *L); int w_Shader_sendMatrix(lua_State *L); int w_Shader_sendTexture(lua_State *L); int w_Shader_send(lua_State *L); +int w_Shader_getExternVariable(lua_State *L); extern "C" int luaopen_shader(lua_State *L); } // opengl From e667485f6813f1f1f4ed8c8370df0e06ddba7305 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Sat, 26 Apr 2014 14:35:39 +0200 Subject: [PATCH 07/14] Check argument count of newChainShape --- src/modules/physics/box2d/Physics.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/modules/physics/box2d/Physics.cpp b/src/modules/physics/box2d/Physics.cpp index a76aca20f..a016c7a05 100644 --- a/src/modules/physics/box2d/Physics.cpp +++ b/src/modules/physics/box2d/Physics.cpp @@ -133,12 +133,12 @@ int Physics::newPolygonShape(lua_State *L) int Physics::newChainShape(lua_State *L) { int argc = lua_gettop(L)-1; // first argument is looping + if (argc % 2 != 0) + return luaL_error(L, "Number of vertex components must be a multiple of two."); + int vcount = (int)argc/2; - b2ChainShape *s = new b2ChainShape(); - bool loop = luax_toboolean(L, 1); - b2Vec2 *vecs = new b2Vec2[vcount]; for (int i = 0; i Date: Thu, 1 May 2014 14:12:21 -0300 Subject: [PATCH 08/14] Minor code cleanup --- src/common/Data.h | 2 +- src/common/EnumMap.h | 20 ++++----- src/common/StringMap.h | 41 +++++++++---------- src/common/int.h | 35 +++++----------- src/modules/event/sdl/Event.cpp | 10 +---- src/modules/event/sdl/Event.h | 2 +- .../graphics/opengl/ParticleSystem.cpp | 14 +++---- src/modules/graphics/opengl/ParticleSystem.h | 2 +- src/modules/graphics/opengl/SpriteBatch.cpp | 4 +- src/modules/joystick/Joystick.cpp | 2 +- src/modules/joystick/Joystick.h | 4 +- src/modules/keyboard/sdl/Keyboard.cpp | 5 +-- src/modules/keyboard/sdl/Keyboard.h | 2 + src/modules/keyboard/wrap_Keyboard.cpp | 4 +- src/modules/mouse/sdl/Cursor.cpp | 4 +- src/modules/mouse/sdl/Mouse.cpp | 4 +- src/modules/mouse/wrap_Cursor.cpp | 2 +- src/modules/mouse/wrap_Mouse.cpp | 6 +-- src/modules/system/wrap_System.cpp | 6 +-- src/modules/thread/Channel.h | 10 ++++- src/modules/thread/LuaThread.h | 13 +++--- src/modules/thread/Thread.h | 4 +- src/modules/thread/sdl/Thread.h | 3 +- src/modules/thread/sdl/threads.cpp | 6 +++ src/modules/thread/sdl/threads.h | 15 +++++-- src/modules/thread/threads.h | 2 +- 26 files changed, 112 insertions(+), 110 deletions(-) diff --git a/src/common/Data.h b/src/common/Data.h index 1ba34c49e..aa2031077 100644 --- a/src/common/Data.h +++ b/src/common/Data.h @@ -47,7 +47,7 @@ public: * Gets a pointer to the data. This pointer will obviously not * be valid if the Data object is destroyed. **/ - virtual void *getData() const = 0 ; + virtual void *getData() const = 0; /** * Gets the size of the Data in bytes. diff --git a/src/common/EnumMap.h b/src/common/EnumMap.h index 3586c35e3..af6660845 100644 --- a/src/common/EnumMap.h +++ b/src/common/EnumMap.h @@ -26,7 +26,7 @@ namespace love { -template +template class EnumMap { public: @@ -37,14 +37,14 @@ public: U u; }; - EnumMap(Entry *entries, unsigned size) + EnumMap(const Entry *entries, unsigned int size) { - unsigned n = size/sizeof(Entry); + unsigned int n = size / sizeof(Entry); - for (unsigned i = 0; i +template class StringMap { public: @@ -37,18 +37,16 @@ public: T value; }; - StringMap(Entry *entries, unsigned num) + StringMap(const Entry *entries, unsigned int num) { - for (unsigned i = 0; i < SIZE; ++i) - reverse[i] = 0; + for (unsigned int i = 0; i < SIZE; ++i) + reverse[i] = nullptr; - unsigned n = num/sizeof(Entry); + unsigned int n = num / sizeof(Entry); - for (unsigned i = 0; i < n; ++i) - { + for (unsigned int i = 0; i < n; ++i) add(entries[i].key, entries[i].value); - } } bool streq(const char *a, const char *b) @@ -57,6 +55,7 @@ public: { if (*a != *b) return false; + ++a; ++b; } @@ -66,11 +65,11 @@ public: bool find(const char *key, T &t) { - unsigned str_hash = djb2(key); + unsigned int str_hash = djb2(key); - for (unsigned i = 0; i < MAX; ++i) + for (unsigned int i = 0; i < MAX; ++i) { - unsigned str_i = (str_hash + i) % MAX; + unsigned int str_i = (str_hash + i) % MAX; if (!records[str_i].set) return false; @@ -85,14 +84,14 @@ public: return false; } - bool find(T key, const char *&str) + bool find(T key, const char *&str) { - unsigned index = (unsigned)key; + unsigned int index = (unsigned int) key; if (index >= SIZE) return false; - if (reverse[index] != 0) + if (reverse[index] != nullptr) { str = reverse[index]; return true; @@ -105,12 +104,12 @@ public: bool add(const char *key, T value) { - unsigned str_hash = djb2(key); + unsigned int str_hash = djb2(key); bool inserted = false; - for (unsigned i = 0; i < MAX; ++i) + for (unsigned int i = 0; i < MAX; ++i) { - unsigned str_i = (str_hash + i) % MAX; + unsigned int str_i = (str_hash + i) % MAX; if (!records[str_i].set) { @@ -122,7 +121,7 @@ public: } } - unsigned index = (unsigned)value; + unsigned int index = (unsigned int) value; if (index >= SIZE) { @@ -135,9 +134,9 @@ public: return inserted; } - unsigned djb2(const char *key) + unsigned int djb2(const char *key) { - unsigned hash = 5381; + unsigned int hash = 5381; int c; while ((c = *key++)) @@ -156,7 +155,7 @@ private: Record() : set(false) {} }; - const static unsigned MAX = SIZE*2; + static const unsigned int MAX = SIZE * 2; Record records[MAX]; const char *reverse[SIZE]; diff --git a/src/common/int.h b/src/common/int.h index ac57f89ec..9cffea606 100644 --- a/src/common/int.h +++ b/src/common/int.h @@ -21,11 +21,10 @@ #ifndef LOVE_INT_H #define LOVE_INT_H -#include "common/config.h" - -#ifndef LOVE_WINDOWS +// C standard sized integer types. +// This header was added to Visual studio in VS 2012, which is LOVE's current +// minimum supported VS version (as of this comment's commit date.) #include -#endif #define LOVE_INT8_MAX 0x7F #define LOVE_UINT8_MAX 0xFF @@ -39,26 +38,14 @@ namespace love { -// Blame Microsoft -#ifdef LOVE_WINDOWS - typedef __int8 int8; - typedef unsigned __int8 uint8; - typedef __int16 int16; - typedef unsigned __int16 uint16; - typedef __int32 int32; - typedef unsigned __int32 uint32; - typedef __int64 int64; - typedef unsigned __int64 uint64; -#else // LOVE_WINDOWS - typedef int8_t int8; - typedef uint8_t uint8; - typedef int16_t int16; - typedef uint16_t uint16; - typedef int32_t int32; - typedef uint32_t uint32; - typedef int64_t int64; - typedef uint64_t uint64; -#endif // LOVE_WINDOWS +typedef int8_t int8; +typedef uint8_t uint8; +typedef int16_t int16; +typedef uint16_t uint16; +typedef int32_t int32; +typedef uint32_t uint32; +typedef int64_t int64; +typedef uint64_t uint64; } // love diff --git a/src/modules/event/sdl/Event.cpp b/src/modules/event/sdl/Event.cpp index c2a2b648c..a79819e57 100644 --- a/src/modules/event/sdl/Event.cpp +++ b/src/modules/event/sdl/Event.cpp @@ -283,10 +283,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const arg1 = new Variant(JOYSTICK_JOYSTICK_ID, (void *) &proxy); arg2 = new Variant((double)(e.jaxis.axis+1)); - float value = e.jaxis.value / 32768.0f; - if (fabsf(value) < 0.001f) value = 0.0f; - if (value < -0.99f) value = -1.0f; - if (value > 0.99f) value = 1.0f; + float value = joystick::Joystick::clampval(e.jaxis.value / 32768.0f); arg3 = new Variant((double) value); msg = new Message("joystickaxis", arg1, arg2, arg3); arg1->release(); @@ -345,10 +342,7 @@ Message *Event::convertJoystickEvent(const SDL_Event &e) const arg1 = new Variant(JOYSTICK_JOYSTICK_ID, (void *) &proxy); arg2 = new Variant(txt, strlen(txt)); - float value = e.jaxis.value / 32768.0f; - if (fabsf(value) < 0.001f) value = 0.0f; - if (value < -0.99f) value = -1.0f; - if (value > 0.99f) value = 1.0f; + float value = joystick::Joystick::clampval(e.caxis.value / 32768.0f); arg3 = new Variant((double) value); msg = new Message("gamepadaxis", arg1, arg2, arg3); arg1->release(); diff --git a/src/modules/event/sdl/Event.h b/src/modules/event/sdl/Event.h index 7b8df4ac4..1028a7211 100644 --- a/src/modules/event/sdl/Event.h +++ b/src/modules/event/sdl/Event.h @@ -80,7 +80,7 @@ private: static EnumMap::Entry buttonEntries[]; static EnumMap buttons; -}; // System +}; // Event } // sdl } // event diff --git a/src/modules/graphics/opengl/ParticleSystem.cpp b/src/modules/graphics/opengl/ParticleSystem.cpp index e47525005..49f4cf087 100644 --- a/src/modules/graphics/opengl/ParticleSystem.cpp +++ b/src/modules/graphics/opengl/ParticleSystem.cpp @@ -276,8 +276,8 @@ void ParticleSystem::initParticle(Particle *p, float t) min = speedMin; max = speedMax; float speed = (float) rng.random(min, max); - p->speed = love::Vector(cosf(p->direction), sinf(p->direction)); - p->speed *= speed; + p->velocity = love::Vector(cosf(p->direction), sinf(p->direction)); + p->velocity *= speed; p->linearAcceleration.x = (float) rng.random(linearAccelerationMin.x, linearAccelerationMax.x); p->linearAcceleration.y = (float) rng.random(linearAccelerationMin.y, linearAccelerationMax.y); @@ -302,7 +302,7 @@ void ParticleSystem::initParticle(Particle *p, float t) p->angle = p->rotation; if (relativeRotation) - p->angle += atan2f(p->speed.y, p->speed.x); + p->angle += atan2f(p->velocity.y, p->velocity.x); p->color = colors[0]; } @@ -907,11 +907,11 @@ void ParticleSystem::update(float dt) // Resize tangential. tangential *= p->tangentialAcceleration; - // Update position. - p->speed += (radial+tangential+p->linearAcceleration)*dt; + // Update velocity. + p->velocity += (radial + tangential + p->linearAcceleration) * dt; // Modify position. - ppos += p->speed * dt; + ppos += p->velocity * dt; p->position[0] = ppos.getX(); p->position[1] = ppos.getY(); @@ -924,7 +924,7 @@ void ParticleSystem::update(float dt) p->angle = p->rotation; if (relativeRotation) - p->angle += atan2f(p->speed.y, p->speed.x); + p->angle += atan2f(p->velocity.y, p->velocity.x); // Change size according to given intervals: // i = 0 1 2 3 n-1 diff --git a/src/modules/graphics/opengl/ParticleSystem.h b/src/modules/graphics/opengl/ParticleSystem.h index 272ab8303..96e6f8d5a 100644 --- a/src/modules/graphics/opengl/ParticleSystem.h +++ b/src/modules/graphics/opengl/ParticleSystem.h @@ -516,7 +516,7 @@ protected: // Particles gravitate towards this point. love::Vector origin; - love::Vector speed; + love::Vector velocity; love::Vector linearAcceleration; float radialAcceleration; float tangentialAcceleration; diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp index bd2e52f99..8b311f514 100644 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ b/src/modules/graphics/opengl/SpriteBatch.cpp @@ -111,7 +111,7 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl memcpy(sprite, texture->getVertices(), sizeof(Vertex) * 4); // Transform. - static Matrix t; + Matrix t; t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky); t.transform(sprite, sprite, 4); @@ -138,7 +138,7 @@ int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy, // Needed for colors. memcpy(sprite, quad->getVertices(), sizeof(Vertex) * 4); - static Matrix t; + Matrix t; t.setTransformation(x, y, a, sx, sy, ox, oy, kx, ky); t.transform(sprite, sprite, 4); diff --git a/src/modules/joystick/Joystick.cpp b/src/modules/joystick/Joystick.cpp index 03946abc0..fb0b72428 100644 --- a/src/modules/joystick/Joystick.cpp +++ b/src/modules/joystick/Joystick.cpp @@ -29,7 +29,7 @@ namespace love namespace joystick { -float Joystick::clampval(float x) const +float Joystick::clampval(float x) { if (fabsf(x) < 0.01) return 0.0f; diff --git a/src/modules/joystick/Joystick.h b/src/modules/joystick/Joystick.h index d2d57fa21..dde6bebdc 100644 --- a/src/modules/joystick/Joystick.h +++ b/src/modules/joystick/Joystick.h @@ -173,9 +173,7 @@ public: static bool getConstant(const char *in, InputType &out); static bool getConstant(InputType in, const char *&out); -protected: - - float clampval(float x) const; + static float clampval(float x); private: diff --git a/src/modules/keyboard/sdl/Keyboard.cpp b/src/modules/keyboard/sdl/Keyboard.cpp index 488632d6a..00b6812f7 100644 --- a/src/modules/keyboard/sdl/Keyboard.cpp +++ b/src/modules/keyboard/sdl/Keyboard.cpp @@ -51,12 +51,11 @@ bool Keyboard::hasKeyRepeat() const bool Keyboard::isDown(Key *keylist) const { - const Uint8 *keystate = SDL_GetKeyboardState(0); - std::map::const_iterator it; + const Uint8 *keystate = SDL_GetKeyboardState(nullptr); for (Key key = *keylist; key != KEY_MAX_ENUM; key = *(++keylist)) { - it = keys.find(key); + auto it = keys.find(key); if (it != keys.end() && keystate[SDL_GetScancodeFromKey(it->second)]) return true; } diff --git a/src/modules/keyboard/sdl/Keyboard.h b/src/modules/keyboard/sdl/Keyboard.h index 56271b801..9b7a5f2c4 100644 --- a/src/modules/keyboard/sdl/Keyboard.h +++ b/src/modules/keyboard/sdl/Keyboard.h @@ -56,6 +56,8 @@ public: private: + // Whether holding down a key triggers repeated key press events. + // The real implementation is in love::event::sdl::Event::Convert. bool key_repeat; static std::map createKeyMap(); diff --git a/src/modules/keyboard/wrap_Keyboard.cpp b/src/modules/keyboard/wrap_Keyboard.cpp index fc986b940..da46ba3d3 100644 --- a/src/modules/keyboard/wrap_Keyboard.cpp +++ b/src/modules/keyboard/wrap_Keyboard.cpp @@ -29,7 +29,7 @@ namespace love namespace keyboard { -static Keyboard *instance = 0; +static Keyboard *instance = nullptr; int w_setKeyRepeat(lua_State *L) { @@ -87,7 +87,7 @@ static const luaL_Reg functions[] = extern "C" int luaopen_love_keyboard(lua_State *L) { - if (instance == 0) + if (instance == nullptr) { EXCEPT_GUARD(instance = new love::keyboard::sdl::Keyboard();) } diff --git a/src/modules/mouse/sdl/Cursor.cpp b/src/modules/mouse/sdl/Cursor.cpp index 37dea9fb8..809cd6a45 100644 --- a/src/modules/mouse/sdl/Cursor.cpp +++ b/src/modules/mouse/sdl/Cursor.cpp @@ -30,7 +30,7 @@ namespace sdl { Cursor::Cursor(image::ImageData *data, int hotx, int hoty) - : cursor(0) + : cursor(nullptr) , type(CURSORTYPE_IMAGE) , systemType(CURSOR_MAX_ENUM) { @@ -63,7 +63,7 @@ Cursor::Cursor(image::ImageData *data, int hotx, int hoty) } Cursor::Cursor(mouse::Cursor::SystemCursor cursortype) - : cursor(0) + : cursor(nullptr) , type(CURSORTYPE_SYSTEM) , systemType(cursortype) { diff --git a/src/modules/mouse/sdl/Mouse.cpp b/src/modules/mouse/sdl/Mouse.cpp index 74e86291e..22f88fb05 100644 --- a/src/modules/mouse/sdl/Mouse.cpp +++ b/src/modules/mouse/sdl/Mouse.cpp @@ -71,7 +71,7 @@ const char *Mouse::getName() const } Mouse::Mouse() - : curCursor(0) + : curCursor(nullptr) { } @@ -187,7 +187,7 @@ void Mouse::setVisible(bool visible) bool Mouse::isDown(Button *buttonlist) const { - Uint32 buttonstate = SDL_GetMouseState(0, 0); + Uint32 buttonstate = SDL_GetMouseState(nullptr, nullptr); for (Button button = *buttonlist; button != BUTTON_MAX_ENUM; button = *(++buttonlist)) { diff --git a/src/modules/mouse/wrap_Cursor.cpp b/src/modules/mouse/wrap_Cursor.cpp index bb245cfba..240aedb5f 100644 --- a/src/modules/mouse/wrap_Cursor.cpp +++ b/src/modules/mouse/wrap_Cursor.cpp @@ -36,7 +36,7 @@ int w_Cursor_getType(lua_State *L) Cursor *cursor = luax_checkcursor(L, 1); Cursor::CursorType ctype = cursor->getType(); - const char *typestr = 0; + const char *typestr = nullptr; if (ctype == Cursor::CURSORTYPE_IMAGE) mouse::Cursor::getConstant(ctype, typestr); diff --git a/src/modules/mouse/wrap_Mouse.cpp b/src/modules/mouse/wrap_Mouse.cpp index 1ba9b2bc0..ea68f31d3 100644 --- a/src/modules/mouse/wrap_Mouse.cpp +++ b/src/modules/mouse/wrap_Mouse.cpp @@ -30,11 +30,11 @@ namespace love namespace mouse { -static Mouse *instance = 0; +static Mouse *instance = nullptr; int w_newCursor(lua_State *L) { - Cursor *cursor = 0; + Cursor *cursor = nullptr; if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T)) luax_convobj(L, 1, "image", "newImageData"); @@ -212,7 +212,7 @@ static const lua_CFunction types[] = extern "C" int luaopen_love_mouse(lua_State *L) { - if (instance == 0) + if (instance == nullptr) { EXCEPT_GUARD(instance = new love::mouse::sdl::Mouse();) } diff --git a/src/modules/system/wrap_System.cpp b/src/modules/system/wrap_System.cpp index 6cea1be76..a5a2e9939 100644 --- a/src/modules/system/wrap_System.cpp +++ b/src/modules/system/wrap_System.cpp @@ -27,7 +27,7 @@ namespace love namespace system { -static System *instance = 0; +static System *instance = nullptr; int w_getOS(lua_State *L) { @@ -99,7 +99,7 @@ static const luaL_Reg functions[] = extern "C" int luaopen_love_system(lua_State *L) { - if (instance == 0) + if (instance == nullptr) { instance = new love::system::sdl::System(); } @@ -111,7 +111,7 @@ extern "C" int luaopen_love_system(lua_State *L) w.name = "system"; w.flags = MODULE_T; w.functions = functions; - w.types = 0; + w.types = nullptr; return luax_register_module(L, w); } diff --git a/src/modules/thread/Channel.h b/src/modules/thread/Channel.h index e54cb57e4..3e9781d12 100644 --- a/src/modules/thread/Channel.h +++ b/src/modules/thread/Channel.h @@ -26,13 +26,14 @@ #include // LOVE -#include -#include +#include "common/Variant.h" +#include "threads.h" namespace love { namespace thread { + class Channel : public love::Object { // FOR WRAPPER USE ONLY @@ -40,8 +41,10 @@ friend void retainVariant(Channel *, Variant *); friend void releaseVariant(Channel *, Variant *); public: + Channel(); ~Channel(); + static Channel *getChannel(const std::string &name); unsigned long push(Variant *var); @@ -56,6 +59,7 @@ public: void release(); private: + Channel(const std::string &name); void lockMutex(); void unlockMutex(); @@ -68,7 +72,9 @@ private: unsigned long sent; unsigned long received; + }; // Channel + } // thread } // love diff --git a/src/modules/thread/LuaThread.h b/src/modules/thread/LuaThread.h index e7eaab6e6..e5722a750 100644 --- a/src/modules/thread/LuaThread.h +++ b/src/modules/thread/LuaThread.h @@ -25,15 +25,16 @@ #include // LOVE -#include -#include -#include -#include +#include "common/Data.h" +#include "common/Object.h" +#include "common/Variant.h" +#include "threads.h" namespace love { namespace thread { + class LuaThread : public love::Object, public Threadable { public: @@ -55,7 +56,9 @@ private: Variant **args; int nargs; -}; + +}; // LuaThread + } // thread } // love diff --git a/src/modules/thread/Thread.h b/src/modules/thread/Thread.h index 23c82b128..7adaeda9d 100644 --- a/src/modules/thread/Thread.h +++ b/src/modules/thread/Thread.h @@ -22,8 +22,8 @@ #define LOVE_THREAD_THREAD_H // LOVE -#include -#include +#include "common/runtime.h" +#include "common/Object.h" namespace love { diff --git a/src/modules/thread/sdl/Thread.h b/src/modules/thread/sdl/Thread.h index ac2a860b2..ea1f48dee 100644 --- a/src/modules/thread/sdl/Thread.h +++ b/src/modules/thread/sdl/Thread.h @@ -22,7 +22,7 @@ #define LOVE_THREAD_SDL_THREAD_H // LOVE -#include +#include "thread/Thread.h" #include "threads.h" // SDL @@ -34,6 +34,7 @@ namespace thread { namespace sdl { + class Thread : public thread::Thread { public: diff --git a/src/modules/thread/sdl/threads.cpp b/src/modules/thread/sdl/threads.cpp index 80bec15f4..f40cc265d 100644 --- a/src/modules/thread/sdl/threads.cpp +++ b/src/modules/thread/sdl/threads.cpp @@ -27,6 +27,7 @@ namespace thread { namespace sdl { + Mutex::Mutex() { mutex = SDL_CreateMutex(); @@ -81,6 +82,11 @@ bool Conditional::wait(thread::Mutex *_mutex, int timeout) } // sdl + +/** + * Implementations of the functions declared in src/modules/threads.h. + **/ + thread::Mutex *newMutex() { return new sdl::Mutex(); diff --git a/src/modules/thread/sdl/threads.h b/src/modules/thread/sdl/threads.h index 9521196c0..9916784db 100644 --- a/src/modules/thread/sdl/threads.h +++ b/src/modules/thread/sdl/threads.h @@ -21,8 +21,8 @@ #ifndef LOVE_THREAD_SDL_THREADS_H #define LOVE_THREAD_SDL_THREADS_H -#include -#include +#include "common/config.h" +#include "thread/threads.h" #include @@ -32,11 +32,13 @@ namespace thread { namespace sdl { + class Conditional; class Mutex : public thread::Mutex { public: + Mutex(); ~Mutex(); @@ -44,15 +46,18 @@ public: void unlock(); private: + SDL_mutex *mutex; Mutex(const Mutex&/* mutex*/) {} friend class Conditional; -}; + +}; // Mutex class Conditional : public thread::Conditional { public: + Conditional(); ~Conditional(); @@ -61,8 +66,10 @@ public: bool wait(thread::Mutex *mutex, int timeout=-1); private: + SDL_cond *cond; -}; + +}; // Conditional } // sdl } // thread diff --git a/src/modules/thread/threads.h b/src/modules/thread/threads.h index 7c1a26c18..f4c887e94 100644 --- a/src/modules/thread/threads.h +++ b/src/modules/thread/threads.h @@ -21,7 +21,7 @@ #ifndef LOVE_THREAD_THREADS_H #define LOVE_THREAD_THREADS_H -#include +#include "common/config.h" #include "Thread.h" namespace love From 1bc8b7346d6a6ae0ddfcfcc4dd0ce39915bd322c Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 2 May 2014 08:56:23 -0300 Subject: [PATCH 09/14] Added internal thread name support, for use with debuggers. --- src/modules/audio/openal/Audio.cpp | 1 + src/modules/thread/LuaThread.cpp | 1 + src/modules/thread/sdl/Thread.cpp | 2 +- src/modules/thread/threads.cpp | 5 +++++ src/modules/thread/threads.h | 8 ++++++++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/audio/openal/Audio.cpp b/src/modules/audio/openal/Audio.cpp index c6af9be19..c424524d5 100644 --- a/src/modules/audio/openal/Audio.cpp +++ b/src/modules/audio/openal/Audio.cpp @@ -37,6 +37,7 @@ Audio::PoolThread::PoolThread(Pool *pool) , finish(false) { mutex = thread::newMutex(); + threadName = "AudioPool"; } Audio::PoolThread::~PoolThread() diff --git a/src/modules/thread/LuaThread.cpp b/src/modules/thread/LuaThread.cpp index 807994e1e..b4e7ff1c0 100644 --- a/src/modules/thread/LuaThread.cpp +++ b/src/modules/thread/LuaThread.cpp @@ -38,6 +38,7 @@ LuaThread::LuaThread(const std::string &name, love::Data *code) , nargs(0) { code->retain(); + threadName = name; } LuaThread::~LuaThread() diff --git a/src/modules/thread/sdl/Thread.cpp b/src/modules/thread/sdl/Thread.cpp index 416846331..c6a6dc619 100644 --- a/src/modules/thread/sdl/Thread.cpp +++ b/src/modules/thread/sdl/Thread.cpp @@ -51,7 +51,7 @@ bool Thread::start() return false; if (thread) // Clean old handle up SDL_WaitThread(thread, 0); - thread = SDL_CreateThread(thread_runner, NULL, this); + thread = SDL_CreateThread(thread_runner, t->getThreadName(), this); running = (thread != 0); return running; } diff --git a/src/modules/thread/threads.cpp b/src/modules/thread/threads.cpp index 631b75b53..9abeb5899 100644 --- a/src/modules/thread/threads.cpp +++ b/src/modules/thread/threads.cpp @@ -99,5 +99,10 @@ bool Threadable::isRunning() const return owner->isRunning(); } +const char *Threadable::getThreadName() const +{ + return threadName.empty() ? nullptr : threadName.c_str(); +} + } // thread } // love diff --git a/src/modules/thread/threads.h b/src/modules/thread/threads.h index f4c887e94..516abae98 100644 --- a/src/modules/thread/threads.h +++ b/src/modules/thread/threads.h @@ -21,9 +21,13 @@ #ifndef LOVE_THREAD_THREADS_H #define LOVE_THREAD_THREADS_H +// LOVE #include "common/config.h" #include "Thread.h" +// C++ +#include + namespace love { namespace thread @@ -83,9 +87,13 @@ public: bool start(); void wait(); bool isRunning() const; + const char *getThreadName() const; protected: + Thread *owner; + std::string threadName; + }; Mutex *newMutex(); From d7f1262e20cf11969c17efb62d12004cba417d49 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 2 May 2014 11:31:12 -0300 Subject: [PATCH 10/14] Query the Decoder instead of the current OpenAL buffer when getting the sample rate for calculations in streaming audio Sources. Some OpenAL implementations return 0 for alGetSourcei(source, AL_BUFFER) if the source isn't static, which eventually results in returning 0 when querying the buffer's sample rate. --- src/modules/audio/openal/Source.cpp | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/modules/audio/openal/Source.cpp b/src/modules/audio/openal/Source.cpp index e9ef1a434..520edb7bb 100644 --- a/src/modules/audio/openal/Source.cpp +++ b/src/modules/audio/openal/Source.cpp @@ -255,10 +255,7 @@ bool Source::update() alGetSourcef(source, AL_SAMPLE_OFFSET, &curOffsetSamples); - ALint b; - alGetSourcei(source, AL_BUFFER, &b); - int freq; - alGetBufferi(b, AL_FREQUENCY, &freq); + int freq = decoder->getSampleRate(); curOffsetSecs = curOffsetSamples / freq; // Get a free buffer. @@ -334,11 +331,7 @@ void Source::seekAtomic(float offset, void *unit) if (type == TYPE_STREAM) { offsetSamples = offset; - ALint buffer; - alGetSourcei(source, AL_BUFFER, &buffer); - int freq; - alGetBufferi(buffer, AL_FREQUENCY, &freq); - offset /= freq; + offset /= decoder->getSampleRate(); offsetSeconds = offset; decoder->seek(offset); } @@ -353,11 +346,7 @@ void Source::seekAtomic(float offset, void *unit) { offsetSeconds = offset; decoder->seek(offset); - ALint buffer; - alGetSourcei(source, AL_BUFFER, &buffer); - int freq; - alGetBufferi(buffer, AL_FREQUENCY, &freq); - offsetSamples = offset*freq; + offsetSamples = offset * decoder->getSampleRate(); } else { @@ -399,11 +388,7 @@ float Source::tellAtomic(void *unit) const default: { alGetSourcef(source, AL_SAMPLE_OFFSET, &offset); - ALint buffer; - alGetSourcei(source, AL_BUFFER, &buffer); - int freq; - alGetBufferi(buffer, AL_FREQUENCY, &freq); - offset /= freq; + offset /= decoder->getSampleRate(); if (type == TYPE_STREAM) offset += offsetSeconds; } break; From 9972153696af9be48f923acec7711ad9e3edb300 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Sat, 3 May 2014 14:50:08 +0200 Subject: [PATCH 11/14] Use '#line 1' instead of '#line 0' in shader sources, for compatibility with GLES (fixes #882) --- src/scripts/graphics.lua | 4 ++-- src/scripts/graphics.lua.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/scripts/graphics.lua b/src/scripts/graphics.lua index 80cef656d..0bb209420 100644 --- a/src/scripts/graphics.lua +++ b/src/scripts/graphics.lua @@ -1368,7 +1368,7 @@ void main() { local vertexcodes = { GLSL_VERSION, GLSL_SYNTAX, GLSL_VERTEX.HEADER, GLSL_UNIFORMS, - "#line 0", + "#line 1", vertexcode, GLSL_VERTEX.FOOTER, } @@ -1379,7 +1379,7 @@ void main() { local pixelcodes = { GLSL_VERSION, GLSL_SYNTAX, GLSL_PIXEL.HEADER, GLSL_UNIFORMS, - "#line 0", + "#line 1", pixelcode, is_multicanvas and GLSL_PIXEL.FOOTER_MULTI_CANVAS or GLSL_PIXEL.FOOTER, } diff --git a/src/scripts/graphics.lua.h b/src/scripts/graphics.lua.h index 0b9c7d48a..22912839e 100644 --- a/src/scripts/graphics.lua.h +++ b/src/scripts/graphics.lua.h @@ -6410,7 +6410,7 @@ const unsigned char graphics_lua[] = 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x30, 0x22, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x31, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x46, 0x4f, 0x4f, 0x54, 0x45, 0x52, 0x2c, 0x0a, @@ -6429,7 +6429,7 @@ const unsigned char graphics_lua[] = 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x30, 0x22, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x31, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x73, 0x5f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x63, 0x61, 0x6e, 0x76, 0x61, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x46, 0x4f, 0x4f, From 4bc96f1bf66113f295511402e4b56cae2b2066d3 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 3 May 2014 21:43:20 -0300 Subject: [PATCH 12/14] Internally compose and pass an array of shader source codes to OpenGL, instead of relying on #line to make sure the line number is correct for shader error messages (resolves issue #882) --- src/modules/graphics/opengl/Graphics.cpp | 4 +- src/modules/graphics/opengl/Graphics.h | 2 +- src/modules/graphics/opengl/Shader.cpp | 39 +++++++--- src/modules/graphics/opengl/Shader.h | 14 ++-- src/modules/graphics/opengl/wrap_Graphics.cpp | 69 ++++++++++++----- src/scripts/graphics.lua | 34 ++++++--- src/scripts/graphics.lua.h | 74 ++++++++++++------- 7 files changed, 158 insertions(+), 78 deletions(-) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 68b71f379..4dd15669b 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -544,9 +544,9 @@ Canvas *Graphics::newCanvas(int width, int height, Texture::Format format, int f return NULL; // never reached } -Shader *Graphics::newShader(const Shader::ShaderSources &sources) +Shader *Graphics::newShader(const std::vector &vertcode, const std::vector &pixelcode) { - return new Shader(sources); + return new Shader(vertcode, pixelcode); } Mesh *Graphics::newMesh(const std::vector &vertices, Mesh::DrawMode mode) diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 7ab7560cd..7514dd7f4 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -210,7 +210,7 @@ public: Canvas *newCanvas(int width, int height, Texture::Format format = Texture::FORMAT_NORMAL, int fsaa = 0); - Shader *newShader(const Shader::ShaderSources &sources); + Shader *newShader(const std::vector &vertcode, const std::vector &pixelcode); Mesh *newMesh(const std::vector &vertices, Mesh::DrawMode mode = Mesh::DRAW_MODE_FAN); Mesh *newMesh(int vertexcount, Mesh::DrawMode mode = Mesh::DRAW_MODE_FAN); diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index b95a0d10b..f2beb3609 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -66,21 +66,25 @@ Shader *Shader::current = nullptr; GLint Shader::maxTexUnits = 0; std::vector Shader::textureCounters; -Shader::Shader(const ShaderSources &sources) - : shaderSources(sources) - , program(0) +Shader::Shader(const std::vector &vertcode, const std::vector &pixelcode) + : program(0) , builtinUniforms() , vertexAttributes() , lastCanvas((Canvas *) -1) , lastViewport() { - if (shaderSources.empty()) + if (vertcode.empty() && pixelcode.empty()) throw love::Exception("Cannot create shader: no source code!"); + shaderSources[TYPE_VERTEX] = vertcode; + shaderSources[TYPE_PIXEL] = pixelcode; + if (maxTexUnits <= 0) { GLint maxtexunits; glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtexunits); + + // TU 0 is never used for stored Shader images. maxTexUnits = std::max(maxtexunits - 1, 0); } @@ -106,7 +110,7 @@ Shader::~Shader() unloadVolatile(); } -GLuint Shader::compileCode(ShaderType type, const std::string &code) +GLuint Shader::compileCode(ShaderType type, const std::vector &code) { GLenum glshadertype; const char *typestr; @@ -142,9 +146,18 @@ GLuint Shader::compileCode(ShaderType type, const std::string &code) throw love::Exception("Cannot create %s shader object.", typestr); } - const char *src = code.c_str(); - size_t srclen = code.length(); - glShaderSource(shaderid, 1, (const GLchar **)&src, (GLint *)&srclen); + std::vector codelist; + std::vector lengthlist; + + for (size_t i = 0; i < code.size(); i++) + { + codelist.push_back((const GLchar *) code[i].c_str()); + lengthlist.push_back((GLint) code[i].length()); + } + + // The code parameter is a list of source code "files." We can hand them + // all to OpenGL at once using glShaderSource. + glShaderSource(shaderid, codelist.size(), &codelist[0], &lengthlist[0]); glCompileShader(shaderid); @@ -276,10 +289,12 @@ bool Shader::loadVolatile() std::vector shaderids; - ShaderSources::const_iterator source; - for (source = shaderSources.begin(); source != shaderSources.end(); ++source) + for (int i = 0; i < (int) TYPE_MAX_ENUM; i++) { - GLuint shaderid = compileCode(source->first, source->second); + if (shaderSources[i].empty()) + continue; + + GLuint shaderid = compileCode((ShaderType) i, shaderSources[i]); shaderids.push_back(shaderid); } @@ -288,7 +303,7 @@ bool Shader::loadVolatile() createProgram(shaderids); - // Retreive all active uniform variables in this shader from OpenGL. + // Get all active uniform variables in this shader from OpenGL. mapActiveUniforms(); for (int i = 0; i < int(OpenGL::ATTRIB_MAX_ENUM); i++) diff --git a/src/modules/graphics/opengl/Shader.h b/src/modules/graphics/opengl/Shader.h index 38c70a137..25e740543 100644 --- a/src/modules/graphics/opengl/Shader.h +++ b/src/modules/graphics/opengl/Shader.h @@ -74,14 +74,11 @@ public: UNIFORM_MAX_ENUM }; - // Type for a list of shader source codes in the form of sources[shadertype] = code - typedef std::map ShaderSources; - /** * Creates a new Shader using a list of source codes. - * Sources must contain either vertex or pixel shader code, or both. + * The sources must contain either vertex or pixel shader code, or both. **/ - Shader(const ShaderSources &sources); + Shader(const std::vector &vertcode, const std::vector &pixelcode); virtual ~Shader(); @@ -196,7 +193,7 @@ private: UniformType getUniformBaseType(GLenum type) const; void checkSetUniformError(const Uniform &u, int size, int count, UniformType sendtype) const; - GLuint compileCode(ShaderType type, const std::string &code); + GLuint compileCode(ShaderType type, const std::vector &code); void createProgram(const std::vector &shaderids); int getTextureUnit(const std::string &name); @@ -206,8 +203,9 @@ private: // Get any warnings or errors generated only by the shader program object. std::string getProgramWarnings() const; - // List of all shader code attached to this Shader - ShaderSources shaderSources; + // List of all shader code attached to this Shader. Each shader type has its + // own list, which represents separate "files". + std::vector shaderSources[TYPE_MAX_ENUM]; // Shader compiler warning strings for individual shader stages. std::map shaderWarnings; diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 243c9e908..d8a8cbae6 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -353,16 +353,16 @@ int w_newShader(lua_State *L) if (!Shader::isSupported()) return luaL_error(L, "Sorry, your graphics card does not support shaders."); - // clamp stack to 2 elements + // Clamp stack to 2 elements. lua_settop(L, 2); - // read any filepath arguments + // Read any filepath arguments. for (int i = 1; i <= 2; i++) { if (!lua_isstring(L, i)) continue; - // call love.filesystem.isFile(arg_i) + // Call love.filesystem.isFile(arg_i) luax_getfunction(L, "filesystem", "isFile"); lua_pushvalue(L, i); lua_call(L, 1, 1); @@ -382,43 +382,76 @@ int w_newShader(lua_State *L) bool has_arg1 = lua_isstring(L, 1); bool has_arg2 = lua_isstring(L, 2); - // require at least one string argument + // Require at least one string argument. if (!(has_arg1 || has_arg2)) luaL_checkstring(L, 1); luax_getfunction(L, "graphics", "_shaderCodeToGLSL"); - // push vertexcode and pixelcode strings to the top of the stack + // Push vertexcode and pixelcode strings to the top of the stack. lua_pushvalue(L, 1); lua_pushvalue(L, 2); - // call effectCodeToGLSL, returned values will be at the top of the stack + // Call shaderCodeToGLSL, returned values will be at the top of the stack. if (lua_pcall(L, 2, 2, 0) != 0) return luaL_error(L, "%s", lua_tostring(L, -1)); - Shader::ShaderSources sources; + // Each shader type might contain several source code strings. + std::vector sources[Shader::TYPE_MAX_ENUM]; - // vertex shader code - if (lua_isstring(L, -2)) + // Vertex shader code. + if (!lua_isnoneornil(L, -2)) { - std::string vertexcode(luaL_checkstring(L, -2)); - sources[Shader::TYPE_VERTEX] = vertexcode; + std::vector &source = sources[Shader::TYPE_VERTEX]; + + // The argument might be a Lua array containing strings for the code. + if (lua_istable(L, -2)) + { + // Convert table index to absolute. + int idx = lua_gettop(L) + 1 - 2; + + // Get all the shader code strings from the Lua array. + for (size_t i = 1; i <= lua_objlen(L, idx); i++) + { + lua_rawgeti(L, idx, i); + source.push_back(luax_checkstring(L, -1)); + lua_pop(L, 1); + } + } + else + source.push_back(luax_checkstring(L, -2)); } else if (has_arg1 && has_arg2) return luaL_error(L, "Could not parse vertex shader code (missing 'position' function?)"); - // pixel shader code - if (lua_isstring(L, -1)) + // Pixel shader code. + if (!lua_isnoneornil(L, -1)) { - std::string pixelcode(luaL_checkstring(L, -1)); - sources[Shader::TYPE_PIXEL] = pixelcode; + std::vector &source = sources[Shader::TYPE_PIXEL]; + + // The argument might be a Lua array containing strings for the code. + if (lua_istable(L, -1)) + { + // Convert table index to absolute. + int idx = lua_gettop(L) + 1 - 1; + + // Get all the shader code strings from the Lua array. + for (size_t i = 1; i <= lua_objlen(L, idx); i++) + { + lua_rawgeti(L, idx, i); + source.push_back(luax_checkstring(L, -1)); + lua_pop(L, 1); + } + } + else + source.push_back(luax_checkstring(L, -1)); } else if (has_arg1 && has_arg2) return luaL_error(L, "Could not parse pixel shader code (missing 'effect' function?)"); - if (sources.empty()) + if (sources[Shader::TYPE_VERTEX].empty() && sources[Shader::TYPE_PIXEL].empty()) { - // Original args had source code, but effectCodeToGLSL couldn't translate it + // Original args had source code, but shaderCodeToGLSL couldn't translate it for (int i = 1; i <= 2; i++) { if (lua_isstring(L, i)) @@ -429,7 +462,7 @@ int w_newShader(lua_State *L) bool should_error = false; try { - Shader *shader = instance->newShader(sources); + Shader *shader = instance->newShader(sources[Shader::TYPE_VERTEX], sources[Shader::TYPE_PIXEL]); luax_pushtype(L, "Shader", GRAPHICS_SHADER_T, shader); } catch (love::Exception &e) diff --git a/src/scripts/graphics.lua b/src/scripts/graphics.lua index 0bb209420..6478e4d1f 100644 --- a/src/scripts/graphics.lua +++ b/src/scripts/graphics.lua @@ -1365,25 +1365,35 @@ void main() { } local function createVertexCode(vertexcode) + -- If we return an array, each string in the array is considered separate to GLSL, + -- and the line numbers in GLSL errors/warnings maintain this. local vertexcodes = { - GLSL_VERSION, - GLSL_SYNTAX, GLSL_VERTEX.HEADER, GLSL_UNIFORMS, - "#line 1", - vertexcode, - GLSL_VERTEX.FOOTER, + table_concat({ + GLSL_VERSION, + GLSL_SYNTAX, GLSL_VERTEX.HEADER, GLSL_UNIFORMS, + }, "\n") .. "\n", + table_concat({ + vertexcode, + GLSL_VERTEX.FOOTER + }, "\n"), } - return table_concat(vertexcodes, "\n") + return vertexcodes end local function createPixelCode(pixelcode, is_multicanvas) + -- If we return an array, each string in the array is considered separate to GLSL, + -- and the line numbers in GLSL errors/warnings maintain this. local pixelcodes = { - GLSL_VERSION, - GLSL_SYNTAX, GLSL_PIXEL.HEADER, GLSL_UNIFORMS, - "#line 1", - pixelcode, - is_multicanvas and GLSL_PIXEL.FOOTER_MULTI_CANVAS or GLSL_PIXEL.FOOTER, + table_concat({ + GLSL_VERSION, + GLSL_SYNTAX, GLSL_PIXEL.HEADER, GLSL_UNIFORMS, + }, "\n") .. "\n", + table_concat({ + pixelcode, + is_multicanvas and GLSL_PIXEL.FOOTER_MULTI_CANVAS or GLSL_PIXEL.FOOTER, + }, "\n"), } - return table_concat(pixelcodes, "\n") + return pixelcodes end local function isVertexCode(code) diff --git a/src/scripts/graphics.lua.h b/src/scripts/graphics.lua.h index 22912839e..868b739b1 100644 --- a/src/scripts/graphics.lua.h +++ b/src/scripts/graphics.lua.h @@ -6404,42 +6404,66 @@ const unsigned char graphics_lua[] = 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x64, 0x65, 0x28, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x29, 0x0a, + 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x49, 0x66, 0x20, 0x77, 0x65, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x61, 0x6e, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x2c, 0x20, 0x65, 0x61, 0x63, 0x68, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x69, + 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72, 0x65, 0x64, 0x20, 0x73, 0x65, 0x70, 0x61, 0x72, + 0x61, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x2c, 0x0a, + 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, + 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x20, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x73, 0x2f, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x73, 0x20, 0x6d, 0x61, 0x69, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x0a, - 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, 0x4c, - 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, - 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x31, 0x22, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x46, 0x4f, 0x4f, - 0x54, 0x45, 0x52, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x7b, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, + 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, + 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x7d, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x5c, 0x6e, + 0x22, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x7b, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x46, 0x4f, + 0x4f, 0x54, 0x45, 0x52, 0x0a, + 0x09, 0x09, 0x09, 0x7d, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x2c, 0x0a, 0x09, 0x09, 0x7d, 0x0a, - 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, - 0x63, 0x61, 0x74, 0x28, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x2c, 0x20, 0x22, - 0x5c, 0x6e, 0x22, 0x29, 0x0a, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, + 0x65, 0x73, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x69, 0x78, 0x65, 0x6c, 0x43, 0x6f, 0x64, 0x65, 0x28, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x69, 0x73, 0x5f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x63, 0x61, 0x6e, 0x76, 0x61, 0x73, 0x29, 0x0a, + 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x49, 0x66, 0x20, 0x77, 0x65, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, + 0x61, 0x6e, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x2c, 0x20, 0x65, 0x61, 0x63, 0x68, 0x20, 0x73, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x69, + 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72, 0x65, 0x64, 0x20, 0x73, 0x65, 0x70, 0x61, 0x72, + 0x61, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x2c, 0x0a, + 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, + 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x20, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x73, 0x2f, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x73, 0x20, 0x6d, 0x61, 0x69, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x0a, - 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, 0x4c, - 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, 0x47, - 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x31, 0x22, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x69, 0x73, 0x5f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x63, 0x61, 0x6e, 0x76, 0x61, 0x73, 0x20, - 0x61, 0x6e, 0x64, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x46, 0x4f, 0x4f, - 0x54, 0x45, 0x52, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x5f, 0x43, 0x41, 0x4e, 0x56, 0x41, 0x53, 0x20, 0x6f, - 0x72, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x46, 0x4f, 0x4f, 0x54, 0x45, - 0x52, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x7b, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, + 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, + 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x7d, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x5c, 0x6e, + 0x22, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x7b, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x09, 0x69, 0x73, 0x5f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x63, 0x61, 0x6e, 0x76, 0x61, 0x73, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x46, 0x4f, + 0x4f, 0x54, 0x45, 0x52, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x5f, 0x43, 0x41, 0x4e, 0x56, 0x41, 0x53, 0x20, + 0x6f, 0x72, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x46, 0x4f, 0x4f, 0x54, + 0x45, 0x52, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x7d, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x2c, 0x0a, 0x09, 0x09, 0x7d, 0x0a, - 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, - 0x63, 0x61, 0x74, 0x28, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x2c, 0x20, 0x22, 0x5c, - 0x6e, 0x22, 0x29, 0x0a, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, + 0x73, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x64, 0x65, 0x28, 0x63, 0x6f, 0x64, 0x65, 0x29, 0x0a, From 5428a5d75f9a570ae1e2c3d795e1e7b82bf47f7a Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 3 May 2014 22:07:32 -0300 Subject: [PATCH 13/14] Backout changeset b3928e24add23da69dcd90c34985cd6a05454be0 --- src/modules/graphics/opengl/Graphics.cpp | 4 +- src/modules/graphics/opengl/Graphics.h | 2 +- src/modules/graphics/opengl/Shader.cpp | 39 +++------- src/modules/graphics/opengl/Shader.h | 14 ++-- src/modules/graphics/opengl/wrap_Graphics.cpp | 69 +++++------------ src/scripts/graphics.lua | 34 +++------ src/scripts/graphics.lua.h | 74 +++++++------------ 7 files changed, 78 insertions(+), 158 deletions(-) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 4dd15669b..68b71f379 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -544,9 +544,9 @@ Canvas *Graphics::newCanvas(int width, int height, Texture::Format format, int f return NULL; // never reached } -Shader *Graphics::newShader(const std::vector &vertcode, const std::vector &pixelcode) +Shader *Graphics::newShader(const Shader::ShaderSources &sources) { - return new Shader(vertcode, pixelcode); + return new Shader(sources); } Mesh *Graphics::newMesh(const std::vector &vertices, Mesh::DrawMode mode) diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 7514dd7f4..7ab7560cd 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -210,7 +210,7 @@ public: Canvas *newCanvas(int width, int height, Texture::Format format = Texture::FORMAT_NORMAL, int fsaa = 0); - Shader *newShader(const std::vector &vertcode, const std::vector &pixelcode); + Shader *newShader(const Shader::ShaderSources &sources); Mesh *newMesh(const std::vector &vertices, Mesh::DrawMode mode = Mesh::DRAW_MODE_FAN); Mesh *newMesh(int vertexcount, Mesh::DrawMode mode = Mesh::DRAW_MODE_FAN); diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index f2beb3609..b95a0d10b 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -66,25 +66,21 @@ Shader *Shader::current = nullptr; GLint Shader::maxTexUnits = 0; std::vector Shader::textureCounters; -Shader::Shader(const std::vector &vertcode, const std::vector &pixelcode) - : program(0) +Shader::Shader(const ShaderSources &sources) + : shaderSources(sources) + , program(0) , builtinUniforms() , vertexAttributes() , lastCanvas((Canvas *) -1) , lastViewport() { - if (vertcode.empty() && pixelcode.empty()) + if (shaderSources.empty()) throw love::Exception("Cannot create shader: no source code!"); - shaderSources[TYPE_VERTEX] = vertcode; - shaderSources[TYPE_PIXEL] = pixelcode; - if (maxTexUnits <= 0) { GLint maxtexunits; glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtexunits); - - // TU 0 is never used for stored Shader images. maxTexUnits = std::max(maxtexunits - 1, 0); } @@ -110,7 +106,7 @@ Shader::~Shader() unloadVolatile(); } -GLuint Shader::compileCode(ShaderType type, const std::vector &code) +GLuint Shader::compileCode(ShaderType type, const std::string &code) { GLenum glshadertype; const char *typestr; @@ -146,18 +142,9 @@ GLuint Shader::compileCode(ShaderType type, const std::vector &code throw love::Exception("Cannot create %s shader object.", typestr); } - std::vector codelist; - std::vector lengthlist; - - for (size_t i = 0; i < code.size(); i++) - { - codelist.push_back((const GLchar *) code[i].c_str()); - lengthlist.push_back((GLint) code[i].length()); - } - - // The code parameter is a list of source code "files." We can hand them - // all to OpenGL at once using glShaderSource. - glShaderSource(shaderid, codelist.size(), &codelist[0], &lengthlist[0]); + const char *src = code.c_str(); + size_t srclen = code.length(); + glShaderSource(shaderid, 1, (const GLchar **)&src, (GLint *)&srclen); glCompileShader(shaderid); @@ -289,12 +276,10 @@ bool Shader::loadVolatile() std::vector shaderids; - for (int i = 0; i < (int) TYPE_MAX_ENUM; i++) + ShaderSources::const_iterator source; + for (source = shaderSources.begin(); source != shaderSources.end(); ++source) { - if (shaderSources[i].empty()) - continue; - - GLuint shaderid = compileCode((ShaderType) i, shaderSources[i]); + GLuint shaderid = compileCode(source->first, source->second); shaderids.push_back(shaderid); } @@ -303,7 +288,7 @@ bool Shader::loadVolatile() createProgram(shaderids); - // Get all active uniform variables in this shader from OpenGL. + // Retreive all active uniform variables in this shader from OpenGL. mapActiveUniforms(); for (int i = 0; i < int(OpenGL::ATTRIB_MAX_ENUM); i++) diff --git a/src/modules/graphics/opengl/Shader.h b/src/modules/graphics/opengl/Shader.h index 25e740543..38c70a137 100644 --- a/src/modules/graphics/opengl/Shader.h +++ b/src/modules/graphics/opengl/Shader.h @@ -74,11 +74,14 @@ public: UNIFORM_MAX_ENUM }; + // Type for a list of shader source codes in the form of sources[shadertype] = code + typedef std::map ShaderSources; + /** * Creates a new Shader using a list of source codes. - * The sources must contain either vertex or pixel shader code, or both. + * Sources must contain either vertex or pixel shader code, or both. **/ - Shader(const std::vector &vertcode, const std::vector &pixelcode); + Shader(const ShaderSources &sources); virtual ~Shader(); @@ -193,7 +196,7 @@ private: UniformType getUniformBaseType(GLenum type) const; void checkSetUniformError(const Uniform &u, int size, int count, UniformType sendtype) const; - GLuint compileCode(ShaderType type, const std::vector &code); + GLuint compileCode(ShaderType type, const std::string &code); void createProgram(const std::vector &shaderids); int getTextureUnit(const std::string &name); @@ -203,9 +206,8 @@ private: // Get any warnings or errors generated only by the shader program object. std::string getProgramWarnings() const; - // List of all shader code attached to this Shader. Each shader type has its - // own list, which represents separate "files". - std::vector shaderSources[TYPE_MAX_ENUM]; + // List of all shader code attached to this Shader + ShaderSources shaderSources; // Shader compiler warning strings for individual shader stages. std::map shaderWarnings; diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index d8a8cbae6..243c9e908 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -353,16 +353,16 @@ int w_newShader(lua_State *L) if (!Shader::isSupported()) return luaL_error(L, "Sorry, your graphics card does not support shaders."); - // Clamp stack to 2 elements. + // clamp stack to 2 elements lua_settop(L, 2); - // Read any filepath arguments. + // read any filepath arguments for (int i = 1; i <= 2; i++) { if (!lua_isstring(L, i)) continue; - // Call love.filesystem.isFile(arg_i) + // call love.filesystem.isFile(arg_i) luax_getfunction(L, "filesystem", "isFile"); lua_pushvalue(L, i); lua_call(L, 1, 1); @@ -382,76 +382,43 @@ int w_newShader(lua_State *L) bool has_arg1 = lua_isstring(L, 1); bool has_arg2 = lua_isstring(L, 2); - // Require at least one string argument. + // require at least one string argument if (!(has_arg1 || has_arg2)) luaL_checkstring(L, 1); luax_getfunction(L, "graphics", "_shaderCodeToGLSL"); - // Push vertexcode and pixelcode strings to the top of the stack. + // push vertexcode and pixelcode strings to the top of the stack lua_pushvalue(L, 1); lua_pushvalue(L, 2); - // Call shaderCodeToGLSL, returned values will be at the top of the stack. + // call effectCodeToGLSL, returned values will be at the top of the stack if (lua_pcall(L, 2, 2, 0) != 0) return luaL_error(L, "%s", lua_tostring(L, -1)); - // Each shader type might contain several source code strings. - std::vector sources[Shader::TYPE_MAX_ENUM]; + Shader::ShaderSources sources; - // Vertex shader code. - if (!lua_isnoneornil(L, -2)) + // vertex shader code + if (lua_isstring(L, -2)) { - std::vector &source = sources[Shader::TYPE_VERTEX]; - - // The argument might be a Lua array containing strings for the code. - if (lua_istable(L, -2)) - { - // Convert table index to absolute. - int idx = lua_gettop(L) + 1 - 2; - - // Get all the shader code strings from the Lua array. - for (size_t i = 1; i <= lua_objlen(L, idx); i++) - { - lua_rawgeti(L, idx, i); - source.push_back(luax_checkstring(L, -1)); - lua_pop(L, 1); - } - } - else - source.push_back(luax_checkstring(L, -2)); + std::string vertexcode(luaL_checkstring(L, -2)); + sources[Shader::TYPE_VERTEX] = vertexcode; } else if (has_arg1 && has_arg2) return luaL_error(L, "Could not parse vertex shader code (missing 'position' function?)"); - // Pixel shader code. - if (!lua_isnoneornil(L, -1)) + // pixel shader code + if (lua_isstring(L, -1)) { - std::vector &source = sources[Shader::TYPE_PIXEL]; - - // The argument might be a Lua array containing strings for the code. - if (lua_istable(L, -1)) - { - // Convert table index to absolute. - int idx = lua_gettop(L) + 1 - 1; - - // Get all the shader code strings from the Lua array. - for (size_t i = 1; i <= lua_objlen(L, idx); i++) - { - lua_rawgeti(L, idx, i); - source.push_back(luax_checkstring(L, -1)); - lua_pop(L, 1); - } - } - else - source.push_back(luax_checkstring(L, -1)); + std::string pixelcode(luaL_checkstring(L, -1)); + sources[Shader::TYPE_PIXEL] = pixelcode; } else if (has_arg1 && has_arg2) return luaL_error(L, "Could not parse pixel shader code (missing 'effect' function?)"); - if (sources[Shader::TYPE_VERTEX].empty() && sources[Shader::TYPE_PIXEL].empty()) + if (sources.empty()) { - // Original args had source code, but shaderCodeToGLSL couldn't translate it + // Original args had source code, but effectCodeToGLSL couldn't translate it for (int i = 1; i <= 2; i++) { if (lua_isstring(L, i)) @@ -462,7 +429,7 @@ int w_newShader(lua_State *L) bool should_error = false; try { - Shader *shader = instance->newShader(sources[Shader::TYPE_VERTEX], sources[Shader::TYPE_PIXEL]); + Shader *shader = instance->newShader(sources); luax_pushtype(L, "Shader", GRAPHICS_SHADER_T, shader); } catch (love::Exception &e) diff --git a/src/scripts/graphics.lua b/src/scripts/graphics.lua index 6478e4d1f..0bb209420 100644 --- a/src/scripts/graphics.lua +++ b/src/scripts/graphics.lua @@ -1365,35 +1365,25 @@ void main() { } local function createVertexCode(vertexcode) - -- If we return an array, each string in the array is considered separate to GLSL, - -- and the line numbers in GLSL errors/warnings maintain this. local vertexcodes = { - table_concat({ - GLSL_VERSION, - GLSL_SYNTAX, GLSL_VERTEX.HEADER, GLSL_UNIFORMS, - }, "\n") .. "\n", - table_concat({ - vertexcode, - GLSL_VERTEX.FOOTER - }, "\n"), + GLSL_VERSION, + GLSL_SYNTAX, GLSL_VERTEX.HEADER, GLSL_UNIFORMS, + "#line 1", + vertexcode, + GLSL_VERTEX.FOOTER, } - return vertexcodes + return table_concat(vertexcodes, "\n") end local function createPixelCode(pixelcode, is_multicanvas) - -- If we return an array, each string in the array is considered separate to GLSL, - -- and the line numbers in GLSL errors/warnings maintain this. local pixelcodes = { - table_concat({ - GLSL_VERSION, - GLSL_SYNTAX, GLSL_PIXEL.HEADER, GLSL_UNIFORMS, - }, "\n") .. "\n", - table_concat({ - pixelcode, - is_multicanvas and GLSL_PIXEL.FOOTER_MULTI_CANVAS or GLSL_PIXEL.FOOTER, - }, "\n"), + GLSL_VERSION, + GLSL_SYNTAX, GLSL_PIXEL.HEADER, GLSL_UNIFORMS, + "#line 1", + pixelcode, + is_multicanvas and GLSL_PIXEL.FOOTER_MULTI_CANVAS or GLSL_PIXEL.FOOTER, } - return pixelcodes + return table_concat(pixelcodes, "\n") end local function isVertexCode(code) diff --git a/src/scripts/graphics.lua.h b/src/scripts/graphics.lua.h index 868b739b1..22912839e 100644 --- a/src/scripts/graphics.lua.h +++ b/src/scripts/graphics.lua.h @@ -6404,66 +6404,42 @@ const unsigned char graphics_lua[] = 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x64, 0x65, 0x28, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x29, 0x0a, - 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x49, 0x66, 0x20, 0x77, 0x65, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x61, 0x6e, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x2c, 0x20, 0x65, 0x61, 0x63, 0x68, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x69, - 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72, 0x65, 0x64, 0x20, 0x73, 0x65, 0x70, 0x61, 0x72, - 0x61, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x2c, 0x0a, - 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, - 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x20, 0x65, 0x72, - 0x72, 0x6f, 0x72, 0x73, 0x2f, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x73, 0x20, 0x6d, 0x61, 0x69, 0x6e, - 0x74, 0x61, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x0a, - 0x09, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x7b, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, - 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, - 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x7d, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x5c, 0x6e, - 0x22, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x7b, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x46, 0x4f, - 0x4f, 0x54, 0x45, 0x52, 0x0a, - 0x09, 0x09, 0x09, 0x7d, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, 0x4c, + 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, + 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x31, 0x22, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x46, 0x4f, 0x4f, + 0x54, 0x45, 0x52, 0x2c, 0x0a, 0x09, 0x09, 0x7d, 0x0a, - 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, - 0x65, 0x73, 0x0a, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, + 0x63, 0x61, 0x74, 0x28, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x2c, 0x20, 0x22, + 0x5c, 0x6e, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x69, 0x78, 0x65, 0x6c, 0x43, 0x6f, 0x64, 0x65, 0x28, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x69, 0x73, 0x5f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x63, 0x61, 0x6e, 0x76, 0x61, 0x73, 0x29, 0x0a, - 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x49, 0x66, 0x20, 0x77, 0x65, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, - 0x61, 0x6e, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x2c, 0x20, 0x65, 0x61, 0x63, 0x68, 0x20, 0x73, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x61, 0x72, 0x72, 0x61, 0x79, 0x20, 0x69, - 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72, 0x65, 0x64, 0x20, 0x73, 0x65, 0x70, 0x61, 0x72, - 0x61, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x2c, 0x0a, - 0x09, 0x09, 0x2d, 0x2d, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, - 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x20, 0x65, 0x72, - 0x72, 0x6f, 0x72, 0x73, 0x2f, 0x77, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x73, 0x20, 0x6d, 0x61, 0x69, 0x6e, - 0x74, 0x61, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x20, 0x3d, 0x20, 0x7b, 0x0a, - 0x09, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x7b, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, - 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, - 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x7d, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x5c, 0x6e, - 0x22, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x63, 0x61, 0x74, 0x28, 0x7b, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x09, 0x69, 0x73, 0x5f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x63, 0x61, 0x6e, 0x76, 0x61, 0x73, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x46, 0x4f, - 0x4f, 0x54, 0x45, 0x52, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x5f, 0x43, 0x41, 0x4e, 0x56, 0x41, 0x53, 0x20, - 0x6f, 0x72, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x46, 0x4f, 0x4f, 0x54, - 0x45, 0x52, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x7d, 0x2c, 0x20, 0x22, 0x5c, 0x6e, 0x22, 0x29, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, 0x4c, + 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, 0x47, + 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x31, 0x22, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x69, 0x73, 0x5f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x63, 0x61, 0x6e, 0x76, 0x61, 0x73, 0x20, + 0x61, 0x6e, 0x64, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x46, 0x4f, 0x4f, + 0x54, 0x45, 0x52, 0x5f, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x5f, 0x43, 0x41, 0x4e, 0x56, 0x41, 0x53, 0x20, 0x6f, + 0x72, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x46, 0x4f, 0x4f, 0x54, 0x45, + 0x52, 0x2c, 0x0a, 0x09, 0x09, 0x7d, 0x0a, - 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, - 0x73, 0x0a, + 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x63, 0x6f, 0x6e, + 0x63, 0x61, 0x74, 0x28, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x73, 0x2c, 0x20, 0x22, 0x5c, + 0x6e, 0x22, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x56, 0x65, 0x72, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x64, 0x65, 0x28, 0x63, 0x6f, 0x64, 0x65, 0x29, 0x0a, From 0372977dfa689598ab1414050b847ad26c8f8f96 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 3 May 2014 22:21:45 -0300 Subject: [PATCH 14/14] Backout changeset 6dd72101871f163ee0e644c751f80773d45f339f The change should only be done for GLES, not desktop GL - their specifications differ on this. --- src/scripts/graphics.lua | 4 ++-- src/scripts/graphics.lua.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/scripts/graphics.lua b/src/scripts/graphics.lua index 0bb209420..80cef656d 100644 --- a/src/scripts/graphics.lua +++ b/src/scripts/graphics.lua @@ -1368,7 +1368,7 @@ void main() { local vertexcodes = { GLSL_VERSION, GLSL_SYNTAX, GLSL_VERTEX.HEADER, GLSL_UNIFORMS, - "#line 1", + "#line 0", vertexcode, GLSL_VERTEX.FOOTER, } @@ -1379,7 +1379,7 @@ void main() { local pixelcodes = { GLSL_VERSION, GLSL_SYNTAX, GLSL_PIXEL.HEADER, GLSL_UNIFORMS, - "#line 1", + "#line 0", pixelcode, is_multicanvas and GLSL_PIXEL.FOOTER_MULTI_CANVAS or GLSL_PIXEL.FOOTER, } diff --git a/src/scripts/graphics.lua.h b/src/scripts/graphics.lua.h index 22912839e..0b9c7d48a 100644 --- a/src/scripts/graphics.lua.h +++ b/src/scripts/graphics.lua.h @@ -6410,7 +6410,7 @@ const unsigned char graphics_lua[] = 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x31, 0x22, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x30, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x56, 0x45, 0x52, 0x54, 0x45, 0x58, 0x2e, 0x46, 0x4f, 0x4f, 0x54, 0x45, 0x52, 0x2c, 0x0a, @@ -6429,7 +6429,7 @@ const unsigned char graphics_lua[] = 0x09, 0x09, 0x09, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x53, 0x59, 0x4e, 0x54, 0x41, 0x58, 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x48, 0x45, 0x41, 0x44, 0x45, 0x52, 0x2c, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x55, 0x4e, 0x49, 0x46, 0x4f, 0x52, 0x4d, 0x53, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x31, 0x22, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x22, 0x23, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x30, 0x22, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x70, 0x69, 0x78, 0x65, 0x6c, 0x63, 0x6f, 0x64, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x09, 0x69, 0x73, 0x5f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x63, 0x61, 0x6e, 0x76, 0x61, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x4c, 0x53, 0x4c, 0x5f, 0x50, 0x49, 0x58, 0x45, 0x4c, 0x2e, 0x46, 0x4f, 0x4f,