Hi guys,
my engine has come to a stage where instancing will be required, so what i do right now is somewhat like this:
void RenderFunc(..)
{
renderAllLights
RenderDiffuse
If instancing: // This one knows if I'm rendering an instance
RenderFunc(instance);
}
Now the thing is that I'm using one render function to render all meshes, is that a bad idea? My full render function looks like this:
void C3DEngineObject::RenderMesh(UMesh &mesh, bool recursive)
{
#define Passes mesh.passes Passes is just a class containing information for the passes
ObjectBuffer.AmbientColor = Passes.GlobalMaterial.AmbientColor;
/////////PREPARE ALPHA SETTINGS////////////
ObjectBuffer.Alpha = 1.0f;
ObjectBuffer.Alpha = Passes.getAlpha();
if (Passes.Lighting)
{
ObjectBuffer.Alpha += Lights.Directional.size();
BlendStateManager.AlphaPass(devcon);
}
float alphaUp = 1.0f/ObjectBuffer.Alpha;
ObjectBuffer.Alpha = 1.0f/ObjectBuffer.Alpha;
#define AlphaStepUp ObjectBuffer.Alpha += alphaUp
if (!recursive) // Don't send the buffers if recursive
mesh.SendBuffers(devcon, dev, Camera, ObjectBuffer, Bufferphase);
/////////RENDER LIGHTING/////////////////
if (Passes.Lighting)
{
//////////////////////////////////////////////////
//// For each directional light ////
//////////////////////////////////////////////////
FOREACH (Lights.Directional.safe_size())
{
Shaders[7].ApplyShader(dev, devcon);
// INJECT!
Lights.Directional[i].Inject(FrameBuffer);
Shaders[7].UpdateObject(ObjectBuffer, devcon);
Shaders[7].UpdateWorld(FrameBuffer, devcon);
//Shaders[7].SendRegBuffer(FrameBuffer, 1, 0, devcon);
Shaders[7].Render(devcon, Bufferphase);
// Step up one alpha
AlphaStepUp;
}
}
/////////RENDER THE MESH/////////////////
for (int p = 1; p <= Passes.options; p++) // Get all the passes
{
if (Passes.getAt(p) == true) // Is this pass enabled?
{
int relative = Passes.getRelative(p); // If so, find the mat id.
Material* active = getMaterial(relative, Passes); // Find the mat of the id
active->ApplyMaterial(dev, devcon);
active->ShaderRef->UpdateObject(ObjectBuffer, devcon); // Send the object and world buffers
active->ShaderRef->UpdateWorld(FrameBuffer, devcon);
if (relative == BUMPMAP_SHADER) // Is this bump mapping?
{
MatrixBuffer.world = ObjectBuffer.Final;
active->ShaderRef->UpdateMatrix(MatrixBuffer, devcon);
active->ShaderRef->SendTexture(Passes.base->pTexture, 0, devcon);
active->ShaderRef->SendTexture(Passes.bumpmap->pTexture, 1, devcon);
}
if (relative == TEXTURE_SHADER) // Texturing?
{
active->ShaderRef->SendTexture(Passes.base->pTexture, 0, devcon);
//active->ShaderRef->SendTexture(Passes.opacityMap->pTexture, 1, devcon);
}
if (mesh.Instanced && !recursive) // Is this mesh instanced
{
FOREACH (mesh.InstancedData.size()) // For all instances
{
mesh.SendInstancedData(ObjectBuffer, Camera, i, Bufferphase); // Send the location, rotation and scaling of this instance.
RenderMesh(mesh, true); // Call this function, with recursive true so the origional matrixes wont be re-sent (removing the instance loc,rot and scaling).
}
}
// Render the mesh in diffuse mode
active->Render(devcon, Bufferphase);
// Step up one alpha
AlphaStepUp;
}
}
if (recursive)
return;
BlendStateManager.RestoreBlendState(devcon);
}
PS. The mesh.passes is just a class with contains the passes(e.g. Texture, shadows, Lighting).
Now if you look at my code, in each pass it checks if it is bump mapping or texturing, but is this a slow method, how could it be improved? Or even better, how can it be improved in the concept of instancing? ![]()
Also if you have time, it could be nice if you could post a good way of handling mesh rendering, or an efficient method, as I'm just following my minds advice, and not a professional persons advice. ![]()
Also, how much time does it take to check if a bool is true?
Thank You
Edited by Migi0027, 02 February 2013 - 05:19 AM.






