// When drawing with vertex arrays we can bind the vertex buffer once. When using vertex buffer objects
// we need to check to make sure that the vbo is available each time through the loop because loading
// textures may force vbos out of the cache (see loop below).
if (!this.shouldUseVBOs(dc))
{
FloatBuffer vb = this.coordBuffer;
gl.glVertexPointer(ColladaAbstractGeometry.COORDS_PER_VERTEX, GL.GL_FLOAT, 0, vb.rewind());
}
for (Geometry geometry : this.geometries)
{
Material nextMaterial = geometry.material != null ? geometry.material : defaultMaterial;
// Apply new material if necessary
if (!dc.isPickingMode() && !nextMaterial.equals(activeMaterial))
{
this.applyMaterial(dc, nextMaterial);
activeMaterial = nextMaterial;
}
if (!dc.isPickingMode()
&& this.mustApplyTexture(geometry)
&& this.getTexture(geometry).bind(dc)) // bind initiates retrieval
{
this.getTexture(geometry).applyInternalTransform(dc);
if (!texturesEnabled)
{
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
texturesEnabled = true;
}
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
gl.glTexCoordPointer(ColladaAbstractGeometry.TEX_COORDS_PER_VERTEX, GL.GL_FLOAT, 0,
this.textureCoordsBuffer.rewind());
}
else if (texturesEnabled)
{
gl.glDisable(GL.GL_TEXTURE_2D);
gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
texturesEnabled = false;
}
// If this geometry is double sided, then backface culling must be disabled. Otherwise backface culling
// must be enabled, because some SketchUp models will not render correctly without it.
if (geometry.doubleSided && cullingEnabled)
{
gl.glDisable(GL.GL_CULL_FACE);
cullingEnabled = false;
}
else if (!geometry.doubleSided && !cullingEnabled)
{
gl.glEnable(GL.GL_CULL_FACE);
cullingEnabled = true;
}
// Look up VBO IDs each time through the loop because binding a texture may bump a VBO out of the cache.
// If VBOs are not used, the vertex array is bound once, before the loop.
int[] vboIds = null;
if (this.shouldUseVBOs(dc))
{
vboIds = this.getVboIds(dc);
if (vboIds == null)
{
FloatBuffer vb = this.coordBuffer;
gl.glVertexPointer(ColladaAbstractGeometry.COORDS_PER_VERTEX, GL.GL_FLOAT, 0, vb.rewind());
}
}
if (vboIds != null)
this.doDrawInteriorVBO(dc, geometry, vboIds);