From ee90d099376f95ef34d9a6d33555fbef0b0d2768 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 27 Jun 2015 17:51:57 -0300 Subject: [PATCH] Fixed smooth lines drawn with the 'none' line join mode. --- src/modules/graphics/opengl/Polyline.cpp | 2 +- src/modules/graphics/opengl/Polyline.h | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/modules/graphics/opengl/Polyline.cpp b/src/modules/graphics/opengl/Polyline.cpp index 8bfd63aaf..561da7442 100644 --- a/src/modules/graphics/opengl/Polyline.cpp +++ b/src/modules/graphics/opengl/Polyline.cpp @@ -420,7 +420,7 @@ void Polyline::draw() gl.useVertexAttribArrays(enabledattribs); - glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, vertices + vertex_start); + glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, vertices); // Draw the core line and the overdraw in a single draw call. We can do this // because the vertex array contains both the core line and the overdraw diff --git a/src/modules/graphics/opengl/Polyline.h b/src/modules/graphics/opengl/Polyline.h index 132002649..56957b81f 100644 --- a/src/modules/graphics/opengl/Polyline.h +++ b/src/modules/graphics/opengl/Polyline.h @@ -30,6 +30,7 @@ // C++ #include +#include namespace love { @@ -52,7 +53,6 @@ public: , overdraw_vertex_count(0) , draw_mode(mode) , use_quad_indices(quadindices) - , vertex_start(0) , overdraw_vertex_start(0) {} virtual ~Polyline(); @@ -97,7 +97,6 @@ protected: size_t overdraw_vertex_count; GLenum draw_mode; bool use_quad_indices; - size_t vertex_start; size_t overdraw_vertex_start; }; // Polyline @@ -117,9 +116,18 @@ public: void render(const float *vertices, size_t count, float halfwidth, float pixel_size, bool draw_overdraw) { Polyline::render(vertices, count, 2 * count - 4, halfwidth, pixel_size, draw_overdraw); - // discard the first two vertices. (these are redundant) - vertex_start = 2; - vertex_count -= 2; + + // discard the first and last two vertices. (these are redundant) + for (size_t i = 0; i < vertex_count - 4; ++i) + this->vertices[i] = this->vertices[i+2]; + + // The last quad is now garbage, so zero it out to make sure it doesn't + // get rasterized. These vertices are in between the core line vertices + // and the overdraw vertices in the combined vertex array, so they still + // get "rendered" since we draw everything with one draw call. + memset(&this->vertices[vertex_count - 4], 0, sizeof(love::Vector) * 4); + + vertex_count -= 4; } protected: