Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 19 of 19 FirstFirst ... 9171819
Results 181 to 184 of 184

Thread: Official feedback on OpenGL 4.0 thread

  1. #181
    Advanced Member Frequent Contributor
    Join Date
    Apr 2009
    Posts
    591

    Re: Official feedback on OpenGL 4.0 thread

    I just wanted to give some comments on the explicit uniform business and the layout for outs of a vertex shader

    the following (dumb and bad names) shaders fed to NV driver:

    vertex shader:
    Code :
    struct giggles
    {
      float f1[4];
      vec4 ff;
      mat4 tt;
    };
     
    uniform float g;
    uniform mat4 matrix;
    uniform float f;
    uniform float ggs[4];
    uniform struct giggles more_bad_names;
     
    layout(location=0) in vec4 vert;
    layout(location=3) in vec2 tex;
     
    layout(location=1) out vec2 ftex;
    layout(location=2) out vec2 gtex;
     
    void
    main(void)
    {
      gtex=g*tex;
      ftex=tex;
     
      for(int i=0;i<4;++i)
        {
          ftex.y+=ggs[i]+more_bad_names.f1[i];
        }
      gl_Position=matrix*(f*vert +more_bad_names.tt*more_bad_names.ff);
    }


    fragment shader:
    Code :
    layout(location=1) in vec2 ftex;
    layout(location=2) in vec2 gtex;
    out vec4 color;
     
    uniform sampler2D sl;
    uniform float ss;
     
    void
    main(void)
    {
      color=ss*texture(sl, ftex);
    }

    work fine under nVidia, notice that assigning of location to the outs of a vertex shader and same values as ins of a fragment shader.

    Using the same location twice in the vertex shader on a varying gives the error: (in this case using 2 twice)

    0(23) : error C5121: multiple bindings to output semantic "ATTR2"
    where as in the fragment shader no error is reported (I guess that means the two in's are sourced from the same place). Also no error is reported if the layouts don't match.

    Also, the output for the locations of the uniforms is instructive:


    Uniforms:
    0: f
    1: g
    2: ggs
    6: matrix
    7: more_bad_names.f1
    11: more_bad_names.ff
    12: more_bad_names.tt
    13: sl
    14: ss
    notice that a mat4 takes only one uniform slot, although it is 16 floats. People with ATI hardware, can you try the above shader pair out? (most likely remove the layout on vertex outs and fragment ins though).

    Later I will make a better shader pair to see if the location for vert outs actually has an effect... that and see if EXT_seperate_shader_object is ok if one specifies the locations of (outputs of vertex shaders)/(inputs of fragment shaders) under NV.

    Hmm.. this is kind of off topic now... maybe a new thread somewhere else for this? Though this is now walking to undocumented behavior land though.

  2. #182
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268

    Re: Official feedback on OpenGL 4.0 thread

    Quote Originally Posted by kRogue
    Later I will make a better shader pair to see if the location for vert outs actually has an effect...
    It does. I did a similar test, and you can 'mismatch' varyings names if the same location is used in vert and frag shader.

  3. #183
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,290

    Re: Official feedback on OpenGL 4.0 thread

    Quote Originally Posted by kRogue
    notice that a mat4 takes only one uniform slot, although it is 16 floats.
    The uniform locations are not offsets. They are indices, IDs. Uniform IDs, not present in your list:

    3 ggs[1]
    4 ggs[2]
    5 ggs[3]

    8 more_bad_names.f1[1]
    9 more_bad_names.f1[2]
    10 more_bad_names.f1[3]

  4. #184
    Advanced Member Frequent Contributor
    Join Date
    Apr 2009
    Posts
    591

    Re: Official feedback on OpenGL 4.0 thread

    That is what I first figured, that uniforms are ID's and not offsets. One thing that then implies is that when setting uniforms, then there is a one more additional layer of indirection, i.e. translate ID to offset (or something).

    That the mat4 was only one ID kind of irked me: in GLSL one can set a column of a mat4 matrix, but there is no GL call to just set the column of a mat4 matrix, if a mat4 took 4 ID's then one could, along the same lines setting one value of vecN is a vecN took N slots (then to go further then, a mat4 takes 16 ID's), and this does not address one still needs a way to differentiate between setting the entire element or just it's first sub-element.... pointless for me to talk of this anyways since the uniforms are handled via an ID, not an offset and for that matter the GL spec has this:

    A valid name cannot be a structure, an array of structures, or any portion of
    a single vector or a matrix.
    Though the naming convention in the GL spec kind of suggests "they are offsets" (glGetUniformLocation)... the GL spec language for getting uniforms is kind of icky too, as one passes an "index":

    void GetActiveUniform( uint program, uint index,
    sizei bufSize, sizei *length, int *size, enum *type,
    char *name );

    where 0<=index<ACTIVE_UNIFORMS. Here the value of index has really nothing in common with the ID of a uniform.

    Though, since there is this layer of indirection, no reason, except for the inckiness of handing structs, for GL API to not have something like "GL_explicit_uniform_location", as Grouvnet has been saying before.


Posting Permissions

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