
There are two main reasons to desire an OpenGL 2 renderer: 1. Compatibility. The compatibility profile, ironically, does not offer a lot of compatibility, and our OpenGL 1 renderer will not run on Android, iOS, or WebGL. 2. Performance. The immediate mode does not scale, and in fact becomes very slow with only a moderate amount of lines on screen, and only a somewhat large amount of triangles. This commit implements a basic OpenGL 2 renderer that uses only features from the (OpenGL 3.2) core profile. It is not yet faster than the OpenGL 1 renderer, primarily because it uses a lot of small draw calls. This commit uses OpenGL 2 on Linux and Mac OS X directly (i.e. links to the GL symbols from version 2+); on Windows this is impossible with the default drivers, so for now OpenGL 1 is still used there.
38 lines
1.0 KiB
GLSL
38 lines
1.0 KiB
GLSL
//-----------------------------------------------------------------------------
|
|
// SolveSpace Edge rendering shader
|
|
//
|
|
// Copyright 2016 Aleksey Egorov
|
|
//-----------------------------------------------------------------------------
|
|
#version 120
|
|
|
|
const float feather = 0.5;
|
|
|
|
uniform vec4 color;
|
|
uniform float pixel;
|
|
uniform float width;
|
|
uniform float patternLen;
|
|
uniform float patternScale;
|
|
uniform sampler2D pattern;
|
|
|
|
varying vec3 fragLoc;
|
|
|
|
void main() {
|
|
// lookup distance texture
|
|
vec4 v = texture2D(pattern, vec2(fragLoc.z / patternScale, 0.0));
|
|
|
|
// decode distance value
|
|
float val = dot(v, vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0));
|
|
|
|
// calculate cap
|
|
float dist = length(vec2(val * patternScale / (patternLen * width) + abs(fragLoc.x), fragLoc.y));
|
|
|
|
// perform antialising
|
|
float k = smoothstep(1.0 - 2.0 * feather * pixel / (width + feather * pixel), 1.0, abs(dist));
|
|
|
|
// perfrom alpha-test
|
|
if(k == 1.0) discard;
|
|
|
|
// write resulting color
|
|
gl_FragColor = vec4(color.rgb, color.a * (1.0 - k));
|
|
}
|