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: Can't initialize an array with a single element???

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    4

    Can't initialize an array with a single element???

    Hi,

    why do I get a shader compile error when I try to put this code in my vertex shader:

    vec3 lightColor[1] = vec3[](vec3(1,1,1));

    but this works:

    vec3 lightColor[2] = vec3[](vec3(1,1,1),vec3(1,1,1));

    If GLSL doesn't allow me to initialize my single-element array this way, how can I do it?

    Rob.
    Last edited by hooyacrusty; 08-22-2013 at 11:05 AM. Reason: dumbness

  2. #2
    Newbie Newbie
    Join Date
    Aug 2013
    Posts
    3
    Actually, this works for me.

    But why would you want a single element array, why can't you just use a standard vec3?
    vec3 lightColor = vec3(1,1,1);

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,129
    why do I get a shader compile error
    What vendor? What error? This should work:

    Quote Originally Posted by Section 4.1.9 of the GLSL Spec
    When an array size is specified in a declaration, it must be an integral constant expression (see section 4.3.3 “Constant Expressions”) greater than zero.
    This implies that single-element arrays are legal.

    Also, does it change anything when you provide an explicit size on the right hand-side of the initialization

    Code :
    vec3 lightColor[1] = vec3[1](vec3(1,1,1));

    or when you leave explicit size out of the state in general

    Code :
    vec3 lightColor[] = vec3[](vec3(1,1,1));

    ?

Posting Permissions

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