From ec7565176e6dc440748382577529fdc8a8ad003c Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 24 Oct 2016 21:35:22 -0300 Subject: [PATCH 1/7] Add love.window.isMaximized --- src/modules/window/Window.h | 2 ++ src/modules/window/sdl/Window.cpp | 5 +++++ src/modules/window/sdl/Window.h | 2 ++ src/modules/window/wrap_Window.cpp | 7 +++++++ 4 files changed, 16 insertions(+) diff --git a/src/modules/window/Window.h b/src/modules/window/Window.h index 6b66adcf8..307adadc5 100644 --- a/src/modules/window/Window.h +++ b/src/modules/window/Window.h @@ -143,6 +143,8 @@ public: virtual void minimize() = 0; virtual void maximize() = 0; + virtual bool isMaximized() const = 0; + // default no-op implementation virtual void swapBuffers(); diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index bdc3e2ce7..d3d727877 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -866,6 +866,11 @@ void Window::maximize() } } +bool Window::isMaximized() const +{ + return window != nullptr && (SDL_GetWindowFlags(window) & SDL_WINDOW_MAXIMIZED); +} + void Window::swapBuffers() { SDL_GL_SwapWindow(window); diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index fcabb0cc5..f920f8536 100644 --- a/src/modules/window/sdl/Window.h +++ b/src/modules/window/sdl/Window.h @@ -76,6 +76,8 @@ public: void minimize(); void maximize(); + bool isMaximized() const; + void swapBuffers(); bool hasFocus() const; diff --git a/src/modules/window/wrap_Window.cpp b/src/modules/window/wrap_Window.cpp index c7a7a1497..48ae7af3d 100644 --- a/src/modules/window/wrap_Window.cpp +++ b/src/modules/window/wrap_Window.cpp @@ -432,6 +432,12 @@ int w_maximize(lua_State *) return 0; } +int w_isMaximized(lua_State *L) +{ + luax_pushboolean(L, instance()->isMaximized()); + return 0; +} + int w_showMessageBox(lua_State *L) { Window::MessageBoxData data = {}; @@ -533,6 +539,7 @@ static const luaL_Reg functions[] = { "fromPixels", w_fromPixels }, { "minimize", w_minimize }, { "maximize", w_maximize }, + { "isMaximized", w_isMaximized }, { "showMessageBox", w_showMessageBox }, { "requestAttention", w_requestAttention }, { 0, 0 } From 7a6e626c745e10e4e918e9123d98eeeecc627500 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Tue, 25 Oct 2016 15:21:31 +0200 Subject: [PATCH 2/7] Make stb_image only use SSE2 on x86_64, or when an override has been set (fixes #1173) Turns out, this is a gcc bug: detecting sse2 support cannot be done in shared libraries. For now we'll assume 32-bit x86 builds are intended to also run on devices without SSE2 (how old!). In the future we might decide we only support machines that support SSE2, if we secretly don't already. --- platform/unix/configure.ac | 6 ++++++ src/libraries/stb/stb_image.h | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/platform/unix/configure.ac b/platform/unix/configure.ac index 8ccf20b24..ddfa8345d 100644 --- a/platform/unix/configure.ac +++ b/platform/unix/configure.ac @@ -36,6 +36,12 @@ AS_VAR_IF([enable_osx], [no], [], #else AC_SUBST([LDFLAGS], ["${LDFLAGS} -framework CoreFoundation -framework Cocoa"]) AC_SUBST([CPPFLAGS], ["${CPPFLAGS} -I../platform/macosx"])) +# stb_image sse2 override (https://github.com/nothings/stb/issues/280) +AC_ARG_ENABLE([stbi-sse2-override], + AC_HELP_STRING([--enable-stbi-sse2-override], [Force stb_image SSE2 support]), [], [enable_stbi_sse2_override=no]) +AS_VAR_IF([enable_stbi_sse2_override], [no], [], #else + AC_SUBST([CPPFLAGS], ["${CPPFLAGS} -DLOVE_STBI_SSE2_OVERRIDE"])) + # --with-lua and --with-luaversion AC_ARG_WITH([lua], [AS_HELP_STRING([--with-lua], [Select the lua implementation])], [], [with_lua=luajit]) diff --git a/src/libraries/stb/stb_image.h b/src/libraries/stb/stb_image.h index fd4c872bc..13ba6c75c 100644 --- a/src/libraries/stb/stb_image.h +++ b/src/libraries/stb/stb_image.h @@ -712,12 +712,18 @@ static int stbi__sse2_available() static int stbi__sse2_available() { -#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 // GCC 4.8 or later - // GCC 4.8+ has a nice way to do this - return __builtin_cpu_supports("sse2"); +#if defined(STBI__X64_TARGET) + // on x64, SSE2 can be assumed to be available. + return 1; +#elif defined(LOVE_STBI_SSE2_OVERRIDE) + return 1; #else - // portable way to do this, preferably without using GCC inline ASM? - // just bail for now. +# warning "stb_image compiled without SSE2 support, define LOVE_STBI_SSE2_OVERRIDE to force SSE2 support" + // __builtin_cpu_supports is buggy on GCC 5 and above, causing problems if + // referenced in a shared object, giving missing __cpu_model hidden symbol errors. + // To get around that, just assume that SSE2 is not available on x86. + // + // See https://github.com/nothings/stb/issues/280 for more information. return 0; #endif } From 6d95ff7fb729ce6367267783f9d51aa3bedab0d8 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Tue, 25 Oct 2016 15:33:30 +0200 Subject: [PATCH 3/7] Remove old (cmake-only) workaround for issue #1173. --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a547e2c98..38d2e718b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,9 +200,6 @@ Please see http://bitbucket.org/rude/megasource ${LOVE_LUA_LIBRARY} ) - # Work-around for gcc bug 1568899. - set(LOVE_LINK_LIBRARIES ${LOVE_LINK_LIBRARIES} gcc_s gcc) - if(LOVE_MPG123) find_package(MPG123 REQUIRED) set(LOVE_LINK_LIBRARIES From cdf7199c487eea3cc420ae167fd44b998e69fed6 Mon Sep 17 00:00:00 2001 From: Julio Felipe Angelini Date: Wed, 26 Oct 2016 17:33:03 -0200 Subject: [PATCH 4/7] Added new raw values constructor to Matrix4 and Matrix4::setRawTransformation(). --HG-- branch : set-raw-transform --- src/common/Matrix.cpp | 17 +++++++++++++++++ src/common/Matrix.h | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/common/Matrix.cpp b/src/common/Matrix.cpp index 14cacba6e..67e71105e 100644 --- a/src/common/Matrix.cpp +++ b/src/common/Matrix.cpp @@ -36,6 +36,11 @@ Matrix4::Matrix4() { setIdentity(); } + +Matrix4::Matrix4(float t00, float t10, float t01, float t11, float x, float y) +{ + setRawTransformation(t00, t10, t01, t11, x, y); +} Matrix4::Matrix4(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) { @@ -129,6 +134,18 @@ void Matrix4::setShear(float kx, float ky) e[1] = ky; e[4] = kx; } + +void Matrix4::setRawTransformation(float t00, float t10, float t01, float t11, float x, float y) +{ + memset(e, 0, sizeof(float)*16); // zero out matrix + e[10] = e[15] = 1.0f; + e[0] = t00; + e[1] = t10; + e[4] = t01; + e[5] = t11; + e[12] = x; + e[13] = y; +} void Matrix4::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) { diff --git a/src/common/Matrix.h b/src/common/Matrix.h index 406d49328..c1b621466 100644 --- a/src/common/Matrix.h +++ b/src/common/Matrix.h @@ -40,6 +40,11 @@ public: * Creates a new identity matrix. **/ Matrix4(); + + /** + * Creates a new matrix with the transform values set. + **/ + Matrix4(float t00, float t10, float t01, float t11, float x, float y); /** * Creates a new matrix set to a transformation. @@ -101,6 +106,21 @@ public: * @param ky Shear along y-axis. **/ void setShear(float kx, float ky); + + /** + * Sets a transformation's values directly. Useful if you want to modify them inplace, + * or if you want to create a transformation that's not buildable with setTransformation() + * i.e. the inverse of setTransformation() is not easily built with another call + * to setTransformation() with tweaked values. + * + * @param t00 The sx*cos(angle) component of the transformation. + * @param t10 The sx*sin(angle) component of the transformation. + * @param t01 The sy*(-sin(angle)) component of the transformation. + * @param t11 The sy*cos(angle) component of the transformation. + * @param x The x translation component of the transformation. + * @param y The y translation component of the transformation. + **/ + void setRawTransformation(float t00, float t10, float t01, float t11, float x, float y); /** * Creates a transformation with a certain position, orientation, scale From 53c528aa449d47ed2285e331e9d3f40cb3b5fd87 Mon Sep 17 00:00:00 2001 From: Nathan Korth Date: Fri, 28 Oct 2016 16:26:28 -0400 Subject: [PATCH 5/7] Add 'ellipse' distribution to ParticleSystem --- src/modules/graphics/ParticleSystem.cpp | 8 ++++++++ src/modules/graphics/ParticleSystem.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/modules/graphics/ParticleSystem.cpp b/src/modules/graphics/ParticleSystem.cpp index 2a4f2accf..fdb445fc0 100644 --- a/src/modules/graphics/ParticleSystem.cpp +++ b/src/modules/graphics/ParticleSystem.cpp @@ -242,6 +242,7 @@ void ParticleSystem::initParticle(Particle *p, float t) p->position = pos; + float rand_x, rand_y; switch (areaSpreadDistribution) { case DISTRIBUTION_UNIFORM: @@ -252,6 +253,12 @@ void ParticleSystem::initParticle(Particle *p, float t) p->position.x += (float) rng.randomNormal(areaSpread.getX()); p->position.y += (float) rng.randomNormal(areaSpread.getY()); break; + case DISTRIBUTION_ELLIPSE: + rand_x = (float) rng.random(-1, 1); + rand_y = (float) rng.random(-1, 1); + p->position.x += areaSpread.getX() * (rand_x * sqrt(1 - 0.5f*pow(rand_y, 2))); + p->position.y += areaSpread.getY() * (rand_y * sqrt(1 - 0.5f*pow(rand_x, 2))); + break; case DISTRIBUTION_NONE: default: break; @@ -969,6 +976,7 @@ StringMap ParticleSystem::distributions(ParticleSystem::distributionsEntries, sizeof(ParticleSystem::distributionsEntries)); diff --git a/src/modules/graphics/ParticleSystem.h b/src/modules/graphics/ParticleSystem.h index cae0307d4..b95941c30 100644 --- a/src/modules/graphics/ParticleSystem.h +++ b/src/modules/graphics/ParticleSystem.h @@ -46,13 +46,14 @@ class ParticleSystem : public Drawable { public: /** - * Type of distribution new particles are drawn from: None, uniform, normal. + * Type of distribution new particles are drawn from: None, uniform, normal, ellipse. */ enum AreaSpreadDistribution { DISTRIBUTION_NONE, DISTRIBUTION_UNIFORM, DISTRIBUTION_NORMAL, + DISTRIBUTION_ELLIPSE, DISTRIBUTION_MAX_ENUM }; From ba215122593115039cb8e8c7cebf7b1a76686b7e Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 29 Oct 2016 12:30:15 -0300 Subject: [PATCH 6/7] Updated the changelog --- changes.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/changes.txt b/changes.txt index 3a82e87ab..fc9d3c825 100644 --- a/changes.txt +++ b/changes.txt @@ -6,6 +6,7 @@ Released: N/A * Added lovec.exe in Windows. It is the same as love.exe but built with the Console subsystem, so it always uses or provides a console. * Added the ability to restart the game via love.event.quit("restart"). * Added support for passing a table to love.mouse.isDown, love.keyboard.isDown, love.keyboard.isScancodeDown, Joystick:isDown, and Joystick:isGamepadDown. + * Added love.window.isMaximized. * Added 'shaderswitches' field to the table returned by love.graphics.getStats. * Added Quad:getTextureDimensions. * Added PrismaticJoint:getAxis and WheelJoint:getAxis. @@ -15,11 +16,13 @@ Released: N/A * Added optional reference angle arguments to RevoluteJoint, PrismaticJoint, and WeldJoint constructors. * Added RevoluteJoint:getReferenceAngle, PrismaticJoint:getReferenceAngle, and WeldJoint:getReferenceAngle. - * Deprecated Shader:sendTexture, Shader:sendMatrix, Shader:sendInt, and Shader:sendFloat. + * Deprecated undocumented Shader:sendTexture, Shader:sendMatrix, Shader:sendInt, and Shader:sendFloat functions. * Fixed love on iOS 6. * Fixed os.execute always returning -1 on Linux. * Fixed the love.lowmemory callback to call collectgarbage() after the callback has fired, instead of before. + * Fixed love.math.noise(nil) to error instead of returning nil. + * Fixed an occasional crash when a Thread ends. * Fixed a hang at the end of video playback with some video files. * Fixed the video decoding thread to not do any work when there are no videos to decode. * Fixed love.graphics.newVideo(file) to no longer error if love.audio is disabled. @@ -28,6 +31,7 @@ Released: N/A * Fixed stencils inside Canvases on some OpenGL ES 2 devices. * Fixed an OpenGL error in OpenGL ES 3 when multiple render targets are used. * Fixed love.window.setMode crashing when called with a Canvas active. + * Fixed love.window.maximize to update the reported window dimensions immediately. * Fixed gamma correction of ImageFonts and BMFonts with colored images. * Fixed the default shader improperly applying gamma correction to per-vertex colors when gamma correction is requested but not supported on OpenGL ES. * Fixed text coloring breaking because of an empty string. @@ -36,6 +40,7 @@ Released: N/A * Fixed MouseJoint:getBodies unconditionally erroring. * Fixed memory leak in Text:set. * Fixed incorrect kerning caused by using kerning information for the wrong character in some fonts. + * Fixed ImageData:setPixel/getPixel/mapPixel and SoundData:setSample/getSample to properly handle non-integer coordinates. * Improved performance of Channel methods by roughly 2x in many cases. * Improved performance of Shader:send when small numbers of arguments are given. From 5ba449d1ffacd4831ed2dea874d15f6442ff5fc9 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 29 Oct 2016 23:42:40 -0300 Subject: [PATCH 7/7] Add support for BC4-7 compressed texture formats in KTX files. Updated the changelog. --- changes.txt | 2 + src/modules/image/magpie/KTXHandler.cpp | 61 +++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/changes.txt b/changes.txt index fc9d3c825..66a501d4f 100644 --- a/changes.txt +++ b/changes.txt @@ -9,6 +9,8 @@ Released: N/A * Added love.window.isMaximized. * Added 'shaderswitches' field to the table returned by love.graphics.getStats. * Added Quad:getTextureDimensions. + * Added 'ellipse' area distribution to ParticleSystems. + * Added support for BC4-7 compressed texture formats in KTX files. * Added PrismaticJoint:getAxis and WheelJoint:getAxis. * Added 2-point version of love.physics.newRevoluteJoint. * Added table variants of Fixture:setCategory and Fixture:setMask. diff --git a/src/modules/image/magpie/KTXHandler.cpp b/src/modules/image/magpie/KTXHandler.cpp index 70de4b0ee..9207895f2 100644 --- a/src/modules/image/magpie/KTXHandler.cpp +++ b/src/modules/image/magpie/KTXHandler.cpp @@ -67,6 +67,7 @@ enum KTXGLInternalFormat { KTX_GL_ETC1_RGB8_OES = 0x8D64, + // ETC2 and EAC. KTX_GL_COMPRESSED_R11_EAC = 0x9270, KTX_GL_COMPRESSED_SIGNED_R11_EAC = 0x9271, KTX_GL_COMPRESSED_RG11_EAC = 0x9272, @@ -78,17 +79,33 @@ enum KTXGLInternalFormat KTX_GL_COMPRESSED_RGBA8_ETC2_EAC = 0x9278, KTX_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279, - // I don't know if any KTX file contains PVR data, but why not support it. + // PVRTC1. KTX_GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00, KTX_GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01, KTX_GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02, KTX_GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03, - // Same with DXT1/3/5. - KTX_GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0, - KTX_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2, - KTX_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3, + // DXT1, DXT3, and DXT5. + KTX_GL_COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0, + KTX_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2, + KTX_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3, + KTX_GL_COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C, + KTX_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E, + KTX_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F, + // BC4 and BC5. + KTX_GL_COMPRESSED_RED_RGTC1 = 0x8DBB, + KTX_GL_COMPRESSED_SIGNED_RED_RGTC1 = 0x8DBC, + KTX_GL_COMPRESSED_RG_RGTC2 = 0x8DBD, + KTX_GL_COMPRESSED_SIGNED_RG_RGTC2 = 0x8DBE, + + // BC6 and BC7. + KTX_GL_COMPRESSED_RGBA_BPTC_UNORM = 0x8E8C, + KTX_GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM = 0x8E8D, + KTX_GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT = 0x8E8E, + KTX_GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT = 0x8E8F, + + // ASTC. KTX_GL_COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0, KTX_GL_COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93B1, KTX_GL_COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93B2, @@ -129,6 +146,8 @@ CompressedImageData::Format convertFormat(uint32 glformat, bool &sRGB) { case KTX_GL_ETC1_RGB8_OES: return CompressedImageData::FORMAT_ETC1; + + // EAC and ETC2. case KTX_GL_COMPRESSED_R11_EAC: return CompressedImageData::FORMAT_EAC_R; case KTX_GL_COMPRESSED_SIGNED_R11_EAC: @@ -152,6 +171,8 @@ CompressedImageData::Format convertFormat(uint32 glformat, bool &sRGB) case KTX_GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: sRGB = true; return CompressedImageData::FORMAT_ETC2_RGBA; + + // PVRTC. case KTX_GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: return CompressedImageData::FORMAT_PVR1_RGB4; case KTX_GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: @@ -160,12 +181,42 @@ CompressedImageData::Format convertFormat(uint32 glformat, bool &sRGB) return CompressedImageData::FORMAT_PVR1_RGBA4; case KTX_GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: return CompressedImageData::FORMAT_PVR1_RGBA2; + + // DXT. + case KTX_GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: + sRGB = true; case KTX_GL_COMPRESSED_RGB_S3TC_DXT1_EXT: return CompressedImageData::FORMAT_DXT1; + case KTX_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: + sRGB = true; case KTX_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: return CompressedImageData::FORMAT_DXT3; + case KTX_GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: + sRGB = true; case KTX_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: return CompressedImageData::FORMAT_DXT5; + + // BC4 and BC5. + case KTX_GL_COMPRESSED_RED_RGTC1: + return CompressedImageData::FORMAT_BC4; + case KTX_GL_COMPRESSED_SIGNED_RED_RGTC1: + return CompressedImageData::FORMAT_BC4s; + case KTX_GL_COMPRESSED_RG_RGTC2: + return CompressedImageData::FORMAT_BC5; + case KTX_GL_COMPRESSED_SIGNED_RG_RGTC2: + return CompressedImageData::FORMAT_BC5s; + + // BC6 and BC7. + case KTX_GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM: + sRGB = true; + case KTX_GL_COMPRESSED_RGBA_BPTC_UNORM: + return CompressedImageData::FORMAT_BC7; + case KTX_GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT: + return CompressedImageData::FORMAT_BC6Hs; + case KTX_GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT: + return CompressedImageData::FORMAT_BC6H; + + // ASTC. case KTX_GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: sRGB = true; case KTX_GL_COMPRESSED_RGBA_ASTC_4x4_KHR: