
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.
41 lines
1.1 KiB
GLSL
41 lines
1.1 KiB
GLSL
//-----------------------------------------------------------------------------
|
|
// SolveSpace Point rendering shader
|
|
//
|
|
// Copyright 2016 Aleksey Egorov
|
|
//-----------------------------------------------------------------------------
|
|
#version 120
|
|
|
|
const float feather = 0.5;
|
|
|
|
attribute vec3 pos;
|
|
attribute vec2 loc;
|
|
|
|
uniform mat4 modelview;
|
|
uniform mat4 projection;
|
|
uniform float width;
|
|
uniform float pixel;
|
|
|
|
varying vec2 fragLoc;
|
|
|
|
void main() {
|
|
// get camera vectors from modelview matrix
|
|
vec3 u = vec3(modelview[0].x, modelview[1].x, modelview[2].x);
|
|
vec3 v = vec3(modelview[0].y, modelview[1].y, modelview[2].y);
|
|
|
|
// calculate point contour extension basis for constant width and caps
|
|
|
|
// calculate point extension width considering antialiasing
|
|
float ext = width + feather * pixel;
|
|
|
|
// extend point contour
|
|
vec3 vertex = pos;
|
|
vertex += ext * loc.x * normalize(u);
|
|
vertex += ext * loc.y * normalize(v);
|
|
|
|
// write fragment location for calculating caps and antialiasing
|
|
fragLoc = loc;
|
|
|
|
// transform resulting vertex with modelview and projection matrices
|
|
gl_Position = projection * modelview * vec4(vertex, 1.0);
|
|
}
|