if(ts.getNumberOfSetTextures() < prevTextureNumber) { for(int i = ts.getNumberOfSetTextures(); i < prevTextureNumber; i++) { GL13.glClientActiveTexture(GL13.GL_TEXTURE0 + i); GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY); } }
if (ts.getNumberOfSetTextures() < prevTextureNumber) { for (int i = ts.getNumberOfSetTextures(); i < prevTextureNumber; i++) { if (capabilities.GL_ARB_multitexture && capabilities.OpenGL13) { GL13.glClientActiveTexture(GL13.GL_TEXTURE0 + i); } GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY); } }
    private void predrawGeometry(Geometry t) {        // set world matrix        if (!generatingDisplayList || (t.getLocks() & Spatial.LOCKED_TRANSFORMS) != 0) {            doTransforms(t);        }        VBOInfo vbo = t.getVBOInfo();        if (vbo != null && capabilities.GL_ARB_vertex_buffer_object) {            prepVBO(t);            ignoreVBO = false;        } else            ignoreVBO = true;        // render the object        int oldLimit = -1;        FloatBuffer verticies = t.getVertexBuffer();        if (verticies != null) {            oldLimit = verticies.limit();            verticies.limit(t.getVertQuantity() * 3); // make sure only the                                                        // necessary verts are                                                        // sent through on old                                                        // cards.        }        if ((!ignoreVBO && vbo.getVBOVertexID() > 0)) { // use VBO            usingVBO = true;            GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);            ARBVertexBufferObject.glBindBufferARB(                    ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbo                            .getVBOVertexID());            GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);        } else if (verticies == null) {            GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);        } else if (prevVerts != verticies) {              // textures have changed            GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);            if (usingVBO)                ARBVertexBufferObject.glBindBufferARB(                        ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);            verticies.rewind();            GL11.glVertexPointer(3, 0, verticies);        }        if (oldLimit != -1)            verticies.limit(oldLimit);        prevVerts = verticies;        FloatBuffer normals = t.getNormalBuffer();        oldLimit = -1;        if (normals != null) {            oldLimit = normals.limit();            normals.limit(t.getVertQuantity() * 3); // make sure only the                                                    // necessary normals are                                                    // sent through on old                                                    // cards.        }        if ((!ignoreVBO && vbo.getVBONormalID() > 0)) { // use VBO            usingVBO = true;            GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);            ARBVertexBufferObject.glBindBufferARB(                    ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbo                            .getVBONormalID());            GL11.glNormalPointer(GL11.GL_FLOAT, 0, 0);        } else if (normals == null) {            GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);        } else if (prevNorms != normals) {              // textures have changed            GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);            if (usingVBO)                ARBVertexBufferObject.glBindBufferARB(                        ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);            normals.rewind();            GL11.glNormalPointer(0, normals);        }        if (oldLimit != -1)            normals.limit(oldLimit);        prevNorms = normals;        FloatBuffer colors = t.getColorBuffer();        oldLimit = -1;        if (colors != null) {            oldLimit = colors.limit();            colors.limit(t.getVertQuantity() * 3); // make sure only the                                                    // necessary colors are sent                                                    // through on old cards.        }        if ((!ignoreVBO && vbo.getVBOColorID() > 0)) { // use VBO            usingVBO = true;            GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);            ARBVertexBufferObject.glBindBufferARB(                    ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbo                            .getVBOColorID());            GL11.glColorPointer(4, GL11.GL_FLOAT, 0, 0);        } else if (colors == null) {            GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);            ColorRGBA defCol = t.getDefaultColor();            if (defCol != null)                GL11.glColor4f(defCol.r, defCol.g, defCol.b, defCol.a);        } else if (prevColor != colors) {              // textures have changed            GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);            if (usingVBO)                ARBVertexBufferObject.glBindBufferARB(                        ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);            colors.rewind();            GL11.glColorPointer(4, 0, colors);        }        if (oldLimit != -1)            colors.limit(oldLimit);        prevColor = colors;        TextureState ts = (TextureState) Spatial                .getCurrentState(RenderState.RS_TEXTURE);        int offset = 0;        if(ts != null) {            offset = ts.getTextureCoordinateOffset();                        for(int i = 0; i < ts.getNumberOfSetTextures(); i++) {                FloatBuffer textures = t.getTextureBuffer(i + offset);                oldLimit = -1;                if (textures != null) {                    oldLimit = textures.limit();                    textures.limit(t.getVertQuantity() * 2); // make sure                                                                // only the                                                                // necessary                                                                // texture                                                                // coords are                                                                // sent through                                                                // on old cards.                }                // todo: multitexture is in GL13 - according to forum post:                // topic=2000                if (capabilities.GL_ARB_multitexture && capabilities.OpenGL13) {                    GL13.glClientActiveTexture(GL13.GL_TEXTURE0 + i);                }                if ((!ignoreVBO && vbo.getVBOTextureID(i) > 0)) { // use VBO                    usingVBO = true;                    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);                    ARBVertexBufferObject.glBindBufferARB(                            ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vbo                                    .getVBOTextureID(i));                    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);                } else if (textures == null) {                    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);                } else if (prevTex[i] != textures) {                      // textures have changed                    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);                    if (usingVBO)                        ARBVertexBufferObject.glBindBufferARB(                                ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0);                    textures.rewind();                    GL11.glTexCoordPointer(2, 0, textures);                }                prevTex[i] = textures;                if (oldLimit != -1)                    textures.limit(oldLimit);            }                        if(ts.getNumberOfSetTextures() < prevTextureNumber) {                for(int i = ts.getNumberOfSetTextures(); i < prevTextureNumber; i++) {                    GL13.glClientActiveTexture(GL13.GL_TEXTURE0 + i);                    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);                }            }                        prevTextureNumber = ts.getNumberOfSetTextures();        }    }   