Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Meaning of “bindable uniform vec4 vertices[%d];”

  1. #1
    Intern Contributor
    Join Date
    Mar 2011
    Posts
    87

    Meaning of “bindable uniform vec4 vertices[%d];”

    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?
    // Vertex shader.
    static const char * s_tessellationVertexShaderText =
    "#version 120\n"
    "#extension GL_EXT_bindable_uniform : enable\n"
    "#extension GL_EXT_gpu_shader4 : 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";

  2. #2
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    257

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

    It's probably run through printf() to hardcode the number of vertices in the shader source. There is no %d syntax in GLSL.

  3. #3
    Intern Contributor
    Join Date
    Mar 2011
    Posts
    87

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

    You are right&amp;#65292;Thank you&amp;#12290; i found that code
    sprintf(vertexShaderText, s_tessellationVertexShaderText, c_teapotIndexCount);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •