I'm working on a user interface system, and I want to be able to mix textured polies with frag-coloured polies. Here's my shader code, that doesn't work:
attribute vec2 vertex_coords;
attribute float texid;
attribute vec4 fragdetails;
varying float usingtex;
varying vec4 v_fragdetails;
void main(){
gl_Position = gl_ModelViewProjectionMatrix * vec4(vertex_coords,0.0,1.0);
usingtex = texid;
v_fragdetails = fragdetails;
}
Fragment:
varying float usingtex;
varying vec4 v_fragdetails;
uniform sampler2D thetexture;
void main() {
if (usingtex != 0.0){
thetexture = int(usingtex);
gl_FragColor = texture2D(thetexture, vec2(v_fragdetails[0], v_fragdetails[1]));
} else {
thetexture;
gl_FragColor = v_fragdetails;
}
}
Frag_details consists of either [r, g, b, a] for a coloured poly, with texid set to 0, or [texture x, texture y, 0, 0] for a textured one.
However, samplers must be uniform, and uniforms can't be modified. So how on earth would I swap between textures in one draw? Do I have to set them all up as uniforms and then pick from those? I'd have to use an array, and know the length, which isn't really practical for a UI system where buttons will be clicked, tabs changed, and so on.
Is there a way to do this?
.size
or.length
. Regardless, if the List is storing textures, wouldn't you know exactly how many textures are in it ( i.e. you have to load them all in anyways, right?) ? Member int or float that increments every time a new texture is loaded will fix that problem. \$\endgroup\$bool
, I'd think ) should save you draw calls. You might want to edit in what platform and programming language you are targeting ( as tags as well, perhaps? ) to give people a little more knowledge as to your situation. \$\endgroup\$