PDA

View Full Version : Meaning of “bindable uniform vec4 vertices[%d]&#65307;”

apapaxionga
04-10-2012, 05:48 AM
In the OpenGL SDK 10's example :Instanced Tessellation,i found the fellowing GPU code, i do not understand the meaning of vertices[%d]. What is the actual size of vertices array?
%d equals to what? Where can i set it?

static const char * s_tessellationVertexShaderText =
"#version 120\n"
"#extension GL_EXT_bindable_uniform : enable\n"
"\n"
"bindable uniform vec4 vertices[%d];\n"
"\n"
"varying vec3 v_Normal;\n"
"\n"
"void main(void)\n"
"{\n"
" vec3 p[16];\n"
" \n"
" for (int i = 0; i < 16; i++) {\n"
" p[i] = vertices[gl_InstanceID * 16 + i].xyz;\n"
" }\n"
" \n"
" vec2 uv = gl_Vertex.xy;\n"
" \n"
" vec2 B0 = (1 - uv) * (1 - uv) * (1 - uv);\n"
" vec2 B1 = 3 * uv * (1 - uv) * (1 - uv);\n"
" vec2 B2 = 3 * uv * uv * (1 - uv);\n"
" vec2 B3 = uv * uv * uv;\n"
" \n"
" vec3 pos = \n"
" (B0.x * p[ 0] + B1.x * p[ 1] + B2.x * p[ 2] + B3.x * p[ 3]) * B0.y +\n"
" (B0.x * p[ 4] + B1.x * p[ 5] + B2.x * p[ 6] + B3.x * p[ 7]) * B1.y +\n"
" (B0.x * p[ 8] + B1.x * p[ 9] + B2.x * p[10] + B3.x * p[11]) * B2.y +\n"
" (B0.x * p[12] + B1.x * p[13] + B2.x * p[14] + B3.x * p[15]) * B3.y;\n"
" \n"
" vec2 T0 = (1 - uv) * (1 - uv);\n"
" vec2 T1 = 2 * uv * (1 - uv);\n"
" vec2 T2 = uv * uv;\n"
" \n"
" vec3 dv = \n"
" (B0.x * (p[ 4]-p[0]) + B1.x * (p[ 5]-p[1]) + B2.x * (p[ 6]-p[ 2]) + B3.x * (p[ 7]-p[ 3])) * T0.y +\n"
" (B0.x * (p[ 8]-p[4]) + B1.x * (p[ 9]-p[5]) + B2.x * (p[10]-p[ 6]) + B3.x * (p[11]-p[ 7])) * T1.y +\n"
" (B0.x * (p[12]-p[8]) + B1.x * (p[13]-p[9]) + B2.x * (p[14]-p[10]) + B3.x * (p[15]-p[11])) * T2.y;\n"
" \n"
" vec3 du = \n"
" (T0.x * (p[ 1]-p[ 0]) + T1.x * (p[ 2]-p[ 1]) + T2.x * (p[ 3]-p[ 2])) * B0.y +\n"
" (T0.x * (p[ 5]-p[ 4]) + T1.x * (p[ 6]-p[ 5]) + T2.x * (p[ 7]-p[ 6])) * B1.y +\n"
" (T0.x * (p[ 9]-p[ 8]) + T1.x * (p[10]-p[ 9]) + T2.x * (p[11]-p[10])) * B2.y +\n"
" (T0.x * (p[13]-p[12]) + T1.x * (p[14]-p[13]) + T2.x * (p[15]-p[14])) * B3.y;\n"
" \n"
" gl_Position = gl_ModelViewProjectionMatrix * vec4(pos, 1.0);\n"
// " gl_TexCoord[0].xy = uv;\n"
" vec3 nor = cross(du, dv);\n"
" nor = (length(nor) != 0) ? normalize(nor) : vec3(0.0);\n"
" v_Normal = gl_NormalMatrix * nor;\n"
"}\n"
"\n";

malexander
04-10-2012, 07:59 AM
It's probably run through printf() to hardcode the number of vertices in the shader source. There is no %d syntax in GLSL.

apapaxionga
04-10-2012, 08:03 AM
You are right&amp;#65292;Thank you&amp;#12290; i found that code