From 96b8d29a5c94e7b2f5670276f04834860b0f44bd Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 28 Jun 2020 21:58:13 -0300 Subject: [PATCH 1/4] Clean up code for computing smooth line vertex colors. --- src/modules/graphics/Polyline.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/modules/graphics/Polyline.cpp b/src/modules/graphics/Polyline.cpp index da1397b42..eabd11c45 100644 --- a/src/modules/graphics/Polyline.cpp +++ b/src/modules/graphics/Polyline.cpp @@ -405,18 +405,28 @@ void Polyline::draw(love::graphics::Graphics *gfx) Color32 *colordata = (Color32 *) data.stream[1]; + int draw_rough_count = std::min(cmd.vertexCount, (int) vertex_count - vertex_start); + // Constant vertex color up to the overdraw vertices. - for (int i = 0; i < std::min(cmd.vertexCount, (int) vertex_count - vertex_start); i++) + for (int i = 0; i < draw_rough_count; i++) colordata[i] = curcolor; - int colorcount = 0; if (overdraw) - colorcount = std::min(cmd.vertexCount, overdraw_count - (vertex_start - overdraw_start)); - - if (colorcount > 0) { - Color32 *colors = colordata + std::max(0, (overdraw_start - vertex_start)); - fill_color_array(curcolor, colors, colorcount); + int draw_remaining_count = cmd.vertexCount - draw_rough_count; + + int draw_overdraw_begin = overdraw_start - vertex_start; + int draw_overdraw_end = draw_overdraw_begin + overdraw_count; + + draw_overdraw_begin = std::max(0, draw_overdraw_begin); + + int draw_overdraw_count = std::min(draw_remaining_count, draw_overdraw_end - draw_overdraw_begin); + + if (draw_overdraw_count > 0) + { + Color32 *colors = colordata + draw_overdraw_begin; + fill_color_array(curcolor, colors, draw_overdraw_count); + } } } } From 50eeed7bb16f286a85a50bb8c99866a0d6db4b5e Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 10 Jul 2020 22:52:23 -0300 Subject: [PATCH 2/4] Fix Shader:send's Data variant when a matrix layout arg is used. Also add a second more consistent Data+matrix layout variant of Shader:send which matches the argument order of the table+matrix layout variant - Shader:send(name, matrixlayout, data, ...). --- src/modules/graphics/wrap_Shader.cpp | 50 ++++++++++++++++++---------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/modules/graphics/wrap_Shader.cpp b/src/modules/graphics/wrap_Shader.cpp index 2c34727b0..fb677dbfb 100644 --- a/src/modules/graphics/wrap_Shader.cpp +++ b/src/modules/graphics/wrap_Shader.cpp @@ -313,20 +313,36 @@ static int w_Shader_sendData(lua_State *L, int startidx, Shader *shader, const S if (info->baseType == Shader::UNIFORM_SAMPLER) return luaL_error(L, "Uniform sampler values (textures) cannot be sent to Shaders via Data objects."); - bool columnmajor = false; - if (info->baseType == Shader::UNIFORM_MATRIX && lua_type(L, startidx + 1) == LUA_TSTRING) + math::Transform::MatrixLayout layout = math::Transform::MATRIX_ROW_MAJOR; + int dataidx = startidx; + if (info->baseType == Shader::UNIFORM_MATRIX) { - const char *layoutstr = lua_tostring(L, startidx + 1); - math::Transform::MatrixLayout layout; - if (!math::Transform::getConstant(layoutstr, layout)) - return luax_enumerror(L, "matrix layout", math::Transform::getConstants(layout), layoutstr); + if (lua_type(L, startidx) == LUA_TSTRING) + { + // (matrixlayout, data, ...) + const char *layoutstr = lua_tostring(L, startidx); + if (!math::Transform::getConstant(layoutstr, layout)) + return luax_enumerror(L, "matrix layout", math::Transform::getConstants(layout), layoutstr); - columnmajor = (layout == math::Transform::MATRIX_COLUMN_MAJOR); - startidx++; + startidx++; + dataidx = startidx; + } + else if (lua_type(L, startidx + 1) == LUA_TSTRING) + { + // (data, matrixlayout, ...) + // Should be deprecated in the future (doesn't match the argument + // order of Shader:send(name, matrixlayout, table)) + const char *layoutstr = lua_tostring(L, startidx + 1); + if (!math::Transform::getConstant(layoutstr, layout)) + return luax_enumerror(L, "matrix layout", math::Transform::getConstants(layout), layoutstr); + + startidx++; + } } - Data *data = luax_checktype(L, startidx); + bool columnmajor = (layout == math::Transform::MATRIX_COLUMN_MAJOR); + Data *data = luax_checktype(L, dataidx); size_t size = data->getSize(); ptrdiff_t offset = (ptrdiff_t) luaL_optinteger(L, startidx + 1, 0); @@ -339,17 +355,17 @@ static int w_Shader_sendData(lua_State *L, int startidx, Shader *shader, const S if (!lua_isnoneornil(L, startidx + 2)) { - lua_Integer datasize = luaL_checkinteger(L, startidx + 2); - if (datasize <= 0) + lua_Integer sizearg = luaL_checkinteger(L, startidx + 2); + if (sizearg <= 0) return luaL_error(L, "Size must be greater than 0."); - else if ((size_t) datasize > size - offset) + else if ((size_t) sizearg > size - offset) return luaL_error(L, "Size and offset must fit within the Data's bounds."); - else if (size % uniformstride != 0) - return luaL_error(L, "Size must be a multiple of the uniform's size in bytes."); - else if (size > info->dataSize) + else if (sizearg % uniformstride != 0) + return luaL_error(L, "Size (%d) must be a multiple of the uniform's size in bytes (%d).", sizearg, uniformstride); + else if ((size_t) sizearg > info->dataSize) return luaL_error(L, "Size must not be greater than the uniform's total size in bytes."); - size = (size_t) datasize; + size = (size_t) sizearg; } else { @@ -415,7 +431,7 @@ int w_Shader_send(lua_State *L) int startidx = 3; - if (luax_istype(L, startidx, Data::type)) + if (luax_istype(L, startidx, Data::type) || (info->baseType == Shader::UNIFORM_MATRIX && luax_istype(L, startidx + 1, Data::type))) return w_Shader_sendData(L, startidx, shader, info, false); else return w_Shader_sendLuaValues(L, startidx, shader, info, name); From d60d8867f48feb1778216f354add560acb2e1d34 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 11 Jul 2020 17:21:26 -0300 Subject: [PATCH 3/4] Possible workaround for an Intel driver bug with readable depth buffers https://github.com/love2d/love/issues/1592 --- src/modules/graphics/opengl/Canvas.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 0057db773..c6a2ba7c5 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -39,6 +39,11 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo glGenFramebuffers(1, &framebuffer); gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, framebuffer); + // Might work around an Intel driver bug: https://github.com/love2d/love/issues/1592 + bool current_srgb = gl.isStateEnabled(OpenGL::ENABLE_FRAMEBUFFER_SRGB); + if (current_srgb && isPixelFormatDepthStencil(format)) + gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, false); + if (texture != 0) { if (isPixelFormatDepthStencil(format) && (GLAD_ES_VERSION_3_0 || !GLAD_ES_VERSION_2_0)) @@ -104,6 +109,11 @@ static GLenum createFBO(GLuint &framebuffer, TextureType texType, PixelFormat fo GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); gl.bindFramebuffer(OpenGL::FRAMEBUFFER_ALL, current_fbo); + + // Restore sRGB state if we turned it off above. + if (current_srgb && isPixelFormatDepthStencil(format)) + gl.setEnableState(OpenGL::ENABLE_FRAMEBUFFER_SRGB, current_srgb); + return status; } From dde3db300640adb291ea7abaa2693922cbf21ec3 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 12 Jul 2020 18:25:55 -0300 Subject: [PATCH 4/4] Apply Image:replacePixels/missing text workaround to more ATI drivers issue #1563 --- src/modules/graphics/opengl/OpenGL.cpp | 4 ++-- src/modules/graphics/opengl/OpenGL.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index fa0525ecc..d0e93b4fa 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -160,11 +160,11 @@ bool OpenGL::initContext() #ifdef LOVE_WINDOWS if (getVendor() == VENDOR_AMD) { - // Radeon HD drivers switched from "ATI Radeon" to "AMD Radeon" around + // Radeon drivers switched from "ATI Radeon" to "AMD Radeon" around // the 7000 series. We'll assume this bug doesn't affect those newer // GPUs / drivers. const char *device = (const char *) glGetString(GL_RENDERER); - if (strstr(device, "ATI Radeon HD ") || strstr(device, "ATI Mobility Radeon HD")) + if (strstr(device, "ATI Radeon") || strstr(device, "ATI Mobility Radeon")) bugs.texStorageBreaksSubImage = true; } #endif diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index e926459de..a1a6cb61a 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -165,7 +165,7 @@ public: * initial full-size one (determined after some investigation with an * affected user on Discord.) * https://bitbucket.org/rude/love/issues/1436/bug-with-lovegraphicsprint-on-older-ati - * + * https://github.com/love2d/love/issues/1563 **/ bool texStorageBreaksSubImage;