//------------------------------------------------------------------------------ static bool linkDefaultPrograms() { #if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0) #define GLSL_VERSION_DEFINE "#version 400\n" #else #define GLSL_VERSION_DEFINE "#version 150\n" #endif { // setup samples program // // this shader takes position, uTangent and vTangent for each point // then generates 3 lines in the geometry shader. // static const char *vsSrc = GLSL_VERSION_DEFINE "in vec3 position;\n" "in vec3 uTangent;\n" "in vec3 vTangent;\n" "out vec3 p;\n" "out vec3 ut;\n" "out vec3 vt;\n" "uniform mat4 ModelViewMatrix;\n" "void main() {\n" " p = (ModelViewMatrix * vec4(position, 1)).xyz;\n" " ut = (ModelViewMatrix * vec4(uTangent, 0)).xyz;\n" " vt = (ModelViewMatrix * vec4(vTangent, 0)).xyz;\n" "}\n"; static const char *gsSrc = GLSL_VERSION_DEFINE "layout(points) in;\n" "layout(line_strip, max_vertices = 6) out;\n" "in vec3 p[];\n" "in vec3 ut[];\n" "in vec3 vt[];\n" "out vec4 c;\n" "uniform mat4 ProjectionMatrix;\n" "uniform float scale;\n" "void main() {\n" " vec3 pos = p[0]; \n" " c = vec4(1, 0, 0, 1);\n" " gl_Position = ProjectionMatrix * vec4(pos, 1);\n" " EmitVertex();\n" " \n" " pos = p[0] + ut[0] * scale; \n" " gl_Position = ProjectionMatrix * vec4(pos, 1);\n" " EmitVertex();\n" " EndPrimitive();\n" " \n" " pos = p[0]; \n" " c = vec4(0, 1, 0, 1);\n" " gl_Position = ProjectionMatrix * vec4(pos, 1);\n" " EmitVertex();\n" " \n" " pos = p[0] + vt[0] * scale; \n" " gl_Position = ProjectionMatrix * vec4(pos, 1);\n" " EmitVertex();\n" " EndPrimitive();\n" " \n" " pos = p[0]; \n" " c = vec4(0, 0, 1, 1);\n" " gl_Position = ProjectionMatrix * vec4(pos, 1);\n" " EmitVertex();\n" " \n" " pos = p[0] + cross(ut[0], vt[0]) * scale; \n" " gl_Position = ProjectionMatrix * vec4(pos, 1);\n" " EmitVertex();\n" " EndPrimitive();\n" " \n" "}\n"; static const char *fsSrc = GLSL_VERSION_DEFINE "in vec4 c;\n" "out vec4 color;\n" "void main() {\n" " color = c;\n" "}\n"; g_samplesProgram.SetVertexShaderSource(vsSrc); g_samplesProgram.SetGeometryShaderSource(gsSrc); g_samplesProgram.SetFragShaderSource(fsSrc); g_samplesProgram.AddAttribute( "position",3 ); g_samplesProgram.AddAttribute( "uTangent",3 ); g_samplesProgram.AddAttribute( "vTangent",3 ); } return true; }
//------------------------------------------------------------------------------ static bool linkDefaultPrograms() { #if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0) #define GLSL_VERSION_DEFINE "#version 400\n" #else #define GLSL_VERSION_DEFINE "#version 150\n" #endif { // setup control cage program static const char *vsSrc = GLSL_VERSION_DEFINE "in vec3 position;\n" "in vec3 color;\n" "out vec4 fragColor;\n" "uniform mat4 ModelViewProjectionMatrix;\n" "void main() {\n" " fragColor = vec4(color, 1);\n" " gl_Position = ModelViewProjectionMatrix * " " vec4(position, 1);\n" "}\n"; static const char *fsSrc = GLSL_VERSION_DEFINE "in vec4 fragColor;\n" "out vec4 color;\n" "void main() {\n" " color = fragColor;\n" "}\n"; g_cageProgram.SetVertexShaderSource(vsSrc); g_cageProgram.SetFragShaderSource(fsSrc); g_cageProgram.AddAttribute( "position",3 ); g_cageProgram.AddAttribute( "color",3 ); } { // setup samples program static const char *vsSrc = GLSL_VERSION_DEFINE "in vec3 position;\n" "uniform mat4 ModelViewProjectionMatrix;\n" "void main() {\n" " gl_Position = ModelViewProjectionMatrix * " " vec4(position, 1);\n" "}\n"; static const char *fsSrc = GLSL_VERSION_DEFINE "out vec4 color;\n" "const vec4 colors[3] = vec4[3]( vec4(1.0,0.0,0.0,1.0), \n" " vec4(0.0,1.0,0.0,1.0), \n" " vec4(0.0,0.0,1.0,1.0) ); \n" "void main() {\n" " color = colors[gl_PrimitiveID % 3];\n" "}\n"; g_samplesProgram.SetVertexShaderSource(vsSrc); g_samplesProgram.SetFragShaderSource(fsSrc); g_samplesProgram.AddAttribute( "position",3 ); } return true; }