public void setupInterleavedDataVBO(final FloatBufferData interleaved, final FloatBufferData vertexCoords,
final FloatBufferData normalCoords, final FloatBufferData colorCoords,
final List<FloatBufferData> textureCoords) {
final RenderContext context = ContextManager.getCurrentContext();
final RendererRecord rendRecord = context.getRendererRecord();
final ContextCapabilities caps = context.getCapabilities();
final int lengthBytes = getTotalInterleavedSize(context, vertexCoords, normalCoords, colorCoords, textureCoords);
int currLengthBytes = 0;
if (interleaved.getBufferLimit() > 0) {
interleaved.getBuffer().rewind();
currLengthBytes = Math.round(interleaved.getBuffer().get());
}
if (lengthBytes != currLengthBytes || interleaved.getVBOID(context.getGlContextRep()) == 0
|| interleaved.isNeedsRefresh()) {
initializeInterleavedVBO(context, interleaved, vertexCoords, normalCoords, colorCoords, textureCoords,
lengthBytes);
}
final int vboID = interleaved.getVBOID(context.getGlContextRep());
LwjglRendererUtil.setBoundVBO(rendRecord, vboID);
int offsetBytes = 0;
if (normalCoords != null) {
updateVBO(normalCoords, rendRecord, vboID, offsetBytes);
GL11.glNormalPointer(GL11.GL_FLOAT, 0, offsetBytes);
GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
offsetBytes += normalCoords.getBufferLimit() * 4;
} else {
GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
}
if (colorCoords != null) {
updateVBO(colorCoords, rendRecord, vboID, offsetBytes);
GL11.glColorPointer(colorCoords.getValuesPerTuple(), GL11.GL_FLOAT, 0, offsetBytes);
GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
offsetBytes += colorCoords.getBufferLimit() * 4;
} else {
GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
}
if (textureCoords != null) {
final TextureState ts = (TextureState) context.getCurrentState(RenderState.StateType.Texture);
int enabledTextures = rendRecord.getEnabledTextures();
final boolean valid = rendRecord.isTexturesValid();
boolean exists, wasOn;
if (ts != null) {
final int max = caps.isMultitextureSupported() ? Math.min(caps.getNumberOfFragmentTexCoordUnits(),
TextureState.MAX_TEXTURES) : 1;
for (int i = 0; i < max; i++) {
wasOn = (enabledTextures & (2 << i)) != 0;
exists = textureCoords != null && i < textureCoords.size() && textureCoords.get(i) != null
&& i <= ts.getMaxTextureIndexUsed();
if (!exists) {
if (valid && !wasOn) {
continue;
} else {
checkAndSetTextureArrayUnit(i, rendRecord, caps);
// disable bit in tracking int
enabledTextures &= ~(2 << i);
// disable state
GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
continue;
}
} else {
checkAndSetTextureArrayUnit(i, rendRecord, caps);
// grab a vboID and make sure it exists and is up to date.
final FloatBufferData textureBufferData = textureCoords.get(i);
updateVBO(textureBufferData, rendRecord, vboID, offsetBytes);
if (!valid || !wasOn) {
// enable bit in tracking int
enabledTextures |= (2 << i);
// enable state
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
}
// send data
GL11.glTexCoordPointer(textureBufferData.getValuesPerTuple(), GL11.GL_FLOAT, 0, offsetBytes);
offsetBytes += textureBufferData.getBufferLimit() * 4;
}
}
}
rendRecord.setEnabledTextures(enabledTextures);
rendRecord.setTexturesValid(true);
}
if (vertexCoords != null) {
updateVBO(vertexCoords, rendRecord, vboID, offsetBytes);
GL11.glVertexPointer(vertexCoords.getValuesPerTuple(), GL11.GL_FLOAT, 0, offsetBytes);