*/
public static void apply(final VertexProgramState state) {
final RenderContext context = ContextManager.getCurrentContext();
if (context.getCapabilities().isVertexProgramSupported()) {
// ask for the current state record
final VertexProgramStateRecord record = (VertexProgramStateRecord) context
.getStateRecord(StateType.VertexProgram);
context.setCurrentState(StateType.VertexProgram, state);
if (!record.isValid() || record.getReference() != state) {
record.setReference(state);
if (state.isEnabled()) {
// Vertex program not yet loaded
if (state._getProgramID() == -1) {
if (state.getProgramAsBuffer() != null) {
final int id = create(state.getProgramAsBuffer());
state._setProgramID(id);
} else {
return;
}
}
GL11.glEnable(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB);
ARBProgram.glBindProgramARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, state._getProgramID());
// load environmental parameters...
for (int i = 0; i < VertexProgramState._getEnvParameters().length; i++) {
if (VertexProgramState._getEnvParameters()[i] != null) {
ARBProgram.glProgramEnvParameter4fARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, i,
VertexProgramState._getEnvParameters()[i][0],
VertexProgramState._getEnvParameters()[i][1],
VertexProgramState._getEnvParameters()[i][2],
VertexProgramState._getEnvParameters()[i][3]);
}
}
// load local parameters...
if (state.isUsingParameters()) {
// no parameters are used
for (int i = 0; i < state._getParameters().length; i++) {
if (state._getParameters()[i] != null) {
ARBProgram.glProgramLocalParameter4fARB(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB, i,
state._getParameters()[i][0], state._getParameters()[i][1],
state._getParameters()[i][2], state._getParameters()[i][3]);
}
}
}
} else {
GL11.glDisable(ARBVertexProgram.GL_VERTEX_PROGRAM_ARB);
}
}
if (!record.isValid()) {
record.validate();
}
}
}