So I was wondering if it is worth keeping track of the current material in order to avoid @UseMaterial if it hasn't changed. Maybe it will speed up the rendering of my explosions?
I made a strip down example of it:
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
<OnLoaded>
<ZLibrary>
<Source>
<![CDATA[void setMaterial(int m)
{
currentMaterial = m;
switch(m)
{
case 1: @UseMaterial(Material: Material1); return;
case 2: @UseMaterial(Material: Material2); return;
}
}]]>
</Source>
</ZLibrary>
<ZExpression>
<Expression>
<![CDATA[for(int i=0; i<8; i++)
{
Dummy.Position.X = random(0, 8);
Dummy.Position.Y = random(0, 4);
Dummy.n = 1;
createModel(Dummy);
}
for(int j=0; j<8; j++)
{
Dummy.Position.X = random(0, 8);
Dummy.Position.Y = random(0, 4);
Dummy.n = 2;
createModel(Dummy);
}]]>
</Expression>
</ZExpression>
</OnLoaded>
<Content>
<Model Name="Dummy" Position="6.2233 -0.5997 0">
<Definitions>
<Variable Name="n" Type="1"/>
</Definitions>
<OnRender>
<ZExpression>
<Expression>
<![CDATA[if (currentMaterial != CurrentModel.n) SetMaterial(CurrentModel.n);
@RenderMesh(Mesh: CubeMesh);]]>
</Expression>
</ZExpression>
</OnRender>
</Model>
<Mesh Name="CubeMesh">
<Producers>
<MeshBox/>
</Producers>
</Mesh>
<Material Name="Material1">
<Textures>
<MaterialTexture Texture="Bitmap1" TexCoords="1"/>
</Textures>
</Material>
<Material Name="Material2" Color="1 0 0 1"/>
<Bitmap Name="Bitmap1">
<Producers>
<BitmapNoise/>
</Producers>
</Bitmap>
<Variable Name="CurrentMaterial" Type="1"/>
</Content>
</ZApplication>