Question on GLSL shaders in jME


trying to make some more complex things with shaders I discovered the following:

I had several Spatials (exactly: geometry meshes) that all together should use one GLSLShaderObjectState.

The number of Spatials in this group changed during time - some new added, some old detached.

The problem: When using additional per vertex attributes, this seemed to be on a per-RenderState-Level. this meant that I needed to create a new GLSLShaderObjectState from the same fragment program and vertex program for every Spatial that should use this shader und reset the attribute pointer individually.

When I call GLSLShaderObjectState.load(vpURL,fpURL), a new shader would be loaded, even though it is the same shader all over again, but with different attrib pointers.

The question: Is there an easy way (or already implemented way) to reuse shader objects in such a situation?


I have the same situation. Here is what i do (as a quick&dirty workaround):

-in the draw() method set attribute pointers for the mesh being drawn

-call relinkProgram() only once for the shader

-set currentStates[RenderState.RS_GLSL_SHADER_OBJECTS]=null

-call applyStates()

A more elegant solution would be rewriting of GLSLShaderObjectsState and moving attribute pointers to TriMesh or to the new batch system.