Light objects, material objects

Hi,

Actually, whenever some material has to be setup, we have to call glMaterial for every parameter of it. Couldn’t we create some kind of material objects ? Something like :

GLuint my_material[2];
GLfloat blue_color[] = {1,0,0,1};
glGenMaterials(1, my_materials);
glBindMaterial(GL_FRONT, my_materials[0]);
glBindMaterial(GL_BACK, my_materials[1]);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_color);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.f);

Then, using a material would consist in a single call to :
glBindMaterial(GL_FRONT, my_materials[0]);
and why not :
glBindMaterial(GL_FRONT_AND_BACK, my_materials[0]);

On the same scheme, lights could be setup with :
GLuint my_light;
GLfloat yellow_color[] = [1,1,0,1};
glGenLights(1, &my_light);
glBindLight(GL_LIGHT0, my_light);
glLightfv(GL_LIGHT0, GL_SPECULAR, yellow_color);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.001f);

Then use it with :
glBindLight(GL_LIGHT0, my_light);
and certainly this would also be allowed :
glBindLight(GL_LIGHT5, my_light);

I know the concept of glGenX/glBindX/glDeleteX is redundant in OpenGL, but currently I’m tired of calling thousands of glLight and glMaterial commands. I know that display lists can help, but still display lists are less flexible (a light that has been setup on GL_LIGHT0 in a list will never end on GL_LIGHT1).

[This message has been edited by vincoof (edited 05-07-2003).]

Considering that so much focus is directed on vertex programs these days, which replace the glLight* and glMaterial* calls, I don’t think you’re going to see a lot of willingness for anyone to bother improving these models.

Now, an object model for vertex and fragment program parameters would be nice.

I agree that vertex and fragment programs grab much more attention, but I think the fully programmable models lack some kind of flexibility.

If your vertex program computes lighting with 3 lights, what if you want 2 lights only ? You have to bind a completely new vertex program, just because 4 lines out of the 100 lines of the vertex program have changed. That’s not something I really like to work with, so I keep vertex programs for critical cases only.

What do you mean by “object model for program parameters” ? I don’t get how the program parameters could be improved with an object model.

[This message has been edited by vincoof (edited 05-07-2003).]

Looping, and conditional branches, are coming in vertex shaders. They already exist in NV_vertex_program_2; it’s just a matter of time until ARB_vertex_program_2 supports them.

Fortunately, probably conditional branching and loops would resolve that kind of problem.
Unfortunately, I don’t think we really need cards that support vertex programs for supporting light and material objects. I mean, I’d like to use light and material objects on cards like TNT2 and Rage128.