pioneerspacesim/pioneer — pull request #1432 by Luomu (2012-08-13 03:20:54+00:00)
Title: Material refactor

This is not entirely done but I ran out of weekend. It could use some testing anyway since the chance of something being broken is high!

The use of materials in rendering is now slightly changed. Previously a renderer would figure out which shader or settings to use during each draw from the generic Graphics::Material.
Now, a material needs to be requested beforehand based on a MaterialDescriptor structure. A renderer will then return a new Material best suited for the task.
A renderer does not own the materials, since they are not generally shareable. The GL2 renderer will however take care of reusing and deleting Programs.
The relation of Materials and Programs in the GL2 renderer: a Program contains uniforms, but a Material handles setting those uniforms. This, or the existence of Program is not visible to the users of a Material...

In the Moving Things Around department:
- removed old Graphics::Shader, added GL2::Program, newly structured shaders under data/shaders/gl2
- programs, materials and other GL2 specific classes are under graphics/gl2. Legacy renderer doesn't have many new classes so it didn't get a subdirectory. You might have some opinions about file names.
- GL2 shaders now have "#version 120" added to the top.

To be considered:
- requesting a specific number of lights is a bit meh. Renderer should be able to create a correct lighting variation, multiple variations can be stored inside one GL2::Program after some changes.

Don't get too stuck on GeoSphere, it is a bit of an anomaly again. I think it's a lot cleaner but still not quite finished material-wise. The geosphere shader(s) uses several uniforms that cannot be communicated using the generic material parameters (of course we could have other cases too, but none at the moment). Two options:
- renderer->CreateMaterial\(descriptor), assuming multiple inheritance works as I would like it to (returned material needs to inherit from Graphics::SpecialMaterial and Graphics::GL2::Material), returns a material with additional parameters.
- m_geosphereSurfaceMaterial->AddParameterBlock(some_agreed_slot_id, MaterialParameter\(this)) or something like that. GL2::GSMaterial can then assume that a GeoSphere\* is found under some_agreed_slot_id.

In any case, a Material is supposed to pull the parameters out of somewhere, and GS is not supposed to do program->SetSomethingSpecific(...).

LMR also has a special solution applied to it.

sorry about possible 755s jpab