diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-06-07 20:45:14 +0900 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-06-08 17:12:28 +0900 |
commit | ce72e34b359c323ef7ff96a70500810a9cd8703a (patch) | |
tree | 7436ef509b6670c4331d2e2f0c552728e13ea1f8 /vcl/opengl/combinedFragmentShader.glsl | |
parent | 4bdbfdd6426460c562746c67c29a3b5e2bef8563 (diff) |
opengl: batch drawing of polylines
To get polylines to draw in a batch it was necessary to refactor
the polyline code to work with GL_TRIANGLES instead of the previous
used GL_TRIANGLE_STRIP. For this and to make the code easier to
handle a new class was introduced: LineBuilder, which purpose is
to assemble vertices for a polyline (line ends, line joints).
In addition we need to know the line width, anti-aliasing (AA) per
vertex basis (in addition to color, normal and extrusion) so we
can draw many polylines with one draw call. This info is now
stored in Vertex struct which is used when drawing lines or
triangles (fills).
Uploading of vertices has also been changed, previously we
uploaded the vertices with the drawcall. a convention in Modern
OpenGL is however to use VBO (Vertex Buffer Object) for this.
With this we can upload the to the GPU vertices independently
and not upload them if this is not needed (which is currently
not used yet). A vector of Vertex structs is now uploaded to the
GPU using a VBO which is handeled with a new VertexBufferObject
class.
In addition to reduce the ammount of duplicated vertices, we use
a index vector (handled by IndexBufferObject class) where we only
define the indices of the vertex buffer which should be drawn.
Change-Id: I49dc9c6260b459f4f4ce3a5e4fa4c8ad05a7b878
Diffstat (limited to 'vcl/opengl/combinedFragmentShader.glsl')
-rw-r--r-- | vcl/opengl/combinedFragmentShader.glsl | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/vcl/opengl/combinedFragmentShader.glsl b/vcl/opengl/combinedFragmentShader.glsl index b20060108965..ba4fe2eef665 100644 --- a/vcl/opengl/combinedFragmentShader.glsl +++ b/vcl/opengl/combinedFragmentShader.glsl @@ -8,14 +8,13 @@ */ varying float fade_factor; // 0->1 fade factor used for AA +varying float multiply; #ifdef USE_VERTEX_COLORS varying vec4 vertex_color; #endif uniform vec4 color; -uniform float line_width; -uniform float feather; #define TYPE_NORMAL 0 #define TYPE_LINE 1 @@ -24,8 +23,6 @@ uniform int type; void main() { - float alpha = 1.0; - #ifdef USE_VERTEX_COLORS vec4 result = vertex_color; #else @@ -34,20 +31,11 @@ void main() if (type == TYPE_LINE) { - float start = (line_width / 2.0) - feather; // where we start to apply alpha - float end = (line_width / 2.0) + feather; // where we end to apply alpha - - // Calculate the multiplier so we can transform the 0->1 fade factor - // to take feather and line width into account. - float multiplied = start == end ? 1.0 : 1.0 / (1.0 - (start / end)); - - float dist = (1.0 - abs(fade_factor)) * multiplied; - - alpha = clamp(dist, 0.0, 1.0); + float dist = (1.0 - abs(fade_factor)) * multiply; + float alpha = clamp(dist, 0.0, 1.0); + result.a = result.a * alpha; } - result.a = result.a * alpha; - gl_FragColor = result; } |