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 5 of 5

Thread: uniform struct array

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    11

    uniform struct array

    Hi, all.

    I try to write a structure and declare an array as follow :

    Code :
    struct ShadowMapping
    {
    	mat4            light_coordinate_system;
    	sampler2DShadow shadow_map;
    	int             shadow_map_width;
    	int             shadow_map_height;
    };
     
    ...
     
    //shadow mapping info
    uniform ShadowMapping shadow_mapping_list[8]; //declaration
    uniform int           shadow_mapping_number;

    Then I use the array in my shading program(fragment shader).

    If the condition in for loop is large than 1, I won't get all location of variables in my shader.

    So how can I use the uniform struct array in my shader?

    P.S. I post my code occurring the problem.

    Code :
     
            int i;
            for( i = 0 ; i < shadow_mapping_number ; i++)//if I modify the shadow_mapping_number to a constant 1, it's working. Otherwise, it's failure.
    	{
    		//use the uniform struct array by the form : shadow_mapping_list[i].light_coordinate_system, and etc... .
    	}

    And my version of glsl is #version 120
    Graphics card is Nvidia GTX 460

    By the way, the complied result is on error occurred in any shader.

    Thanks.
    Last edited by LaLaChen; 04-26-2013 at 10:07 AM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Of course it's an error. Samplers are opaque types. And you can't put opaque types in structs. Nor can they be aggregated into interface blocks.

    I'm pretty sure that if you printed out that error, it would tell you exactly what was wrong.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    11
    Quote Originally Posted by Alfonse Reinheart View Post
    Of course it's an error. Samplers are opaque types. And you can't put opaque types in structs. Nor can they be aggregated into interface blocks.

    I'm pretty sure that if you printed out that error, it would tell you exactly what was wrong.
    Thank you very much.

    I check my compiler error after reading your answer.

    But I didn't see any error in vertex shader log, fragment shader log, and linking log.

    Maybe it's related with compiler.

    And I have another question.

    If I want to use an array with sampler, what type I should declare ? Is sampler2DArray or else?

    And how I bind the textures from c++ program to shading program ??
    Last edited by LaLaChen; 04-27-2013 at 12:15 AM.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    800
    Regards,
    Mobeen

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    11
    Thank you. I will try it.

Posting Permissions

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