Best would be to use a buffer-backed uniform block and update with GL_DYNAMIC_DRAW and glBufferSubData().
i have no idea how to achieve this using cocos2dx and i'm new to openglES as well, better u can help me understand.
Setting uniform variables isn't very expensive, they can be updated every frame or even multiple times per frame without much of a performance hit.
Try profiling your code to see what slows it down.
actually i'm running a pixel shader on a full screen size image (960x640), i have distance calculation as well that eats up most of the fps. i could see this by commenting out the distance calculation
without shader FPS - 60
With shader FPS - 15
i have pasted my code here plz have a look and let me know whats wrong in this code
#ifdef GL_ES
precision mediump float;
#endif
struct Light
{
vec3 position;
vec3 color;
float intensity;
int active;
};
uniform Light lights[5];
varying mediump vec2 v_texCoord;
uniform float u_lightInnerFallOff;
uniform vec2 u_resolution;
uniform float u_fragAlpha;
void main()
{
vec4 fragColor = texture2D(CC_Texture0, v_texCoord);
vec3 v_fragmentIntensity = fragColor.rgb;
float fragAlpha = u_fragAlpha;
for (int index = 0; index < 5; index++)
{
if (lights[index].active == 1)
{
mediump float lightDist = distance(vec3((v_texCoord * u_resolution), 0.0), lights[index].position);
lowp float lightValue;
if (lightDist < u_lightInnerFallOff)
{
lightValue = 1.0;
v_fragmentIntensity = lights[index].color * vec3(1.0, 1.0, 1.0);
}
else
{
lightValue = u_lightInnerFallOff/lightDist;
v_fragmentIntensity = lights[index].color * v_fragmentIntensity;
}
fragAlpha = fragAlpha + (lightValue * lights[index].intensity);
}
}
gl_FragColor = vec4(v_fragmentIntensity, fragAlpha);
}
Things i have tried so far
1. changed the precision to lowp - no performance boost
2. commented out the v_Coord manipulation as per apple dev doc - no performance boost
3. after commenting distance calculation in shader FPS increased to 30;
still something is eating up 30 fps, dont know where, all helps are highly appreciated.
Thanks