For example...
If I'm developing an application that requires more than one texture in it (unique sprites, basically), do I need to call context3D.createProgram();
and assemble a new Program3D
(with a VertexShaderAssembler
and a FragmentShaderAssembler
) for each individual textures that I wish to use in the application?
How does a Program3D
work within an engine typically? Does one program run the whole thing, or does it use one program per textures, models, maps?
And am I correct to assume that you only need to create the Program3D
once during initialization time (Event.ADDED_TO_STAGE
), and not during each frames (Event.ENTER_FRAME
), right?
For one program (shader) you can have multiple textures. Usually you write a program for each shader that you have. For example in my game I have one shader (program) for the terrain lighting, texturing and coloring. I have another shader (program) for the water.
So the programs are made once, but I tell context3d which program to use before drawing the scene. That way it will draw whatever I'm about to draw with the current program.
Example usage:
context3d.setProgram(WaterShader);
water.drawTriangles();
context3d.setProgram(TerrainShader)
terrain.drawTriangles();
I draw the water first and then the terrain, each using a different shader. My TerrainShader has multiple textures in, e.g. sand, rock and dirt textures. The shader decides which texture to use at given time. E.g. if the height of the vertex is < 10, then use the sand texture.
So, create the programs once and use them when needed.
I hope this helps you in the right way.