PDA

View Full Version : Uniform arrays in OpenGLES



JoshKlint
01-16-2012, 01:00 AM
In my fragment shader, I have a uniform array like this:

uniform mediump vec3 lightdirection[4];

On iPhone 4, iPad 2, and HTC Evo, I use the string "lightdirection[0]" to set the uniform value from the main program.

I got a Samsung Galaxy Tab today and it only works if I use "lightdirection" to identify the uniform. Which is it supposed to be?

JoshKlint
01-16-2012, 01:04 AM
According to this, it's both, which makes sense:
http://www.opengl.org/wiki/GLSL_Uniform

I swear it wasn't working on iOS. Can anyone comment on this?

JoshKlint
01-16-2012, 02:05 AM
I just tested, and I'm right. On iOS, only the uniform with the suffix '[0]' is recognized. On the Galaxy Tab, only the uniform without the suffix is recognized. My solution is to never use uniform arrays.

Kopelrativ
01-16-2012, 05:23 AM
Excuse me for using your thread, but please explain the idea behind declaring a uniform array with size 0.

I have a uniform array where I don't know what size I need. That is, I would like the size to be dynamic, not static. Is that when you use 0 in the declaration? I am using OpenGL 3, not ES.

The link you provided above states that each entry in the array have a location of their own. But I currently update the whole array with one call to glUniform4fv, and it seems to work. According to the documentation, you can update an array of uniforms that way.

Alfonse Reinheart
01-16-2012, 09:22 AM
My solution is to never use uniform arrays.

It's certainly one solution. You could also just upload each element individually.

It also shows how much the GL ES 2.0 conformance tests actually prevent these kinds of problems. IE: not at all.


Excuse me for using your thread, but please explain the idea behind declaring a uniform array with size 0.

He's not declaring a uniform array with size 0. He's talking about getting the uniform location for the array, so that he can upload multiple elements at once with glUniformfv

JoshKlint
01-16-2012, 09:32 AM
My solution is to never use uniform arrays.

It's certainly one solution. You could also just upload each element individually.

Ah, but you can't. The Galaxy Nexus won't recognize the uniform name with the indice appended ([0],[1],[2]). There is no reliable way to send any data to a uniform array on mobile devices.

Who produces the drivers for these? Both the iPad and Galaxy Tab use a PowerVR chip. Does Samsung actually write their own drivers for this, or do they get them from PowerVR, and just haven't updated the software?