After coming back to my old code, arrange hundred versions of the same files, and being able to compile some of my past project I could finally started again coding some modifications to my old 64kb Introsystem.

One of the things that gaves me many headaches was the material manager. And of course it couldn’t resist to come back to me :D.

During all this time a lot of things have changed related to the treatment of the materials, shaders, render passes and so on. So I decided to spend few days asking my dear friends and making draft on papers about how to manage that problem.

Having in mind that it will be used in 64kb intro I needed to have the feet on the ground and try to keep it simple

So here is it my first draft.

Render passes diagram

The main class is Scene were you store all the nodes. After loading the objects you just add the passes you need for each material on each group of objects using addPass

During rendering, you should call on each frame update to compute the transformation matrix for each node.

Right after compute the matrices you could call render function that will iterate throw all the passes for the scene:

void Scene::render()
{
  setGlobalState();
  setWorldTransformation();

  for (iPass=0;iPass<passesList.Count;iPass++)
    passesList[iPass].render();

  restoreWorldTransformation();
  restoreGlobalState();
}

In the ```Pass::Render()`` function we should just activate the current render context (Usually just a camera, or a render to texture object), following by the call to apply the selected material:

void Pass::render()
{
  renderContext->activate();
  material->applyMaterial(objectList,sceneID);
}

Finally the ```ApplyMaterial`` function do all the passes for each state and shader program to the selected objects passed by parameter (We’re assuming a scene manager singleton):

void Material::applyMaterial(objectList[] objList, int sceneID)
{
  for (int iPass=0;iPass<numPasses;iPass++)
  {
    loadPrograms(iPass);
    setStates(iPass);
    vprogram=getVProgram(iPass);
    pprogram=getPProgram(iPass);

    for (int iText=0;iText<numTextures;iText++)
      loadTextures(iPass,iText);

    vprogram->activate();
    pprogram->activate();

    // Get the scene from singleton and 
    // render the selected objects
    SCENE_MANAGER.Get(sceneID)->renderSelected(objList);

    // Disable everything
    vprogram->deactivate();
    pprogram->deactivate();
    unloadTextures();
    restoreStates(iPass);
  }
}

Note also that in the last code you could use something like setCurrentPass(iPass) on each iteration instead of call all the methods with this parameter. I just left it like that to make it clear that those functions are dependents on the pass

That’s all for today. I’ll try to implement it during next days. I’ll let you know how is going :) (Wish me good luck)