コード例 #1
0
 /** Resets tessellator state and prepares for drawing (with the specified draw mode). */
 public void startDrawing(int par1) {
   if (isDrawing) {
     throw new IllegalStateException("Already tesselating!");
   } else {
     isDrawing = true;
     reset();
     drawMode = par1;
     hasNormals = false;
     hasColor = false;
     hasTexture = false;
     hasBrightness = false;
     isColorDisabled = false;
     return;
   }
 }
コード例 #2
0
  /** Draws the data set up in this tessellator and resets the state to prepare for new drawing. */
  public int draw() {
    if (!isDrawing) {
      throw new IllegalStateException("Not tesselating!");
    }

    isDrawing = false;

    if (vertexCount > 0) {
      intBuffer.clear();
      intBuffer.put(rawBuffer, 0, rawBufferIndex);
      byteBuffer.position(0);
      byteBuffer.limit(rawBufferIndex * 4);

      if (useVBO) {
        vboIndex = (vboIndex + 1) % vboCount;
        ARBVertexBufferObject.glBindBufferARB(
            ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, vertexBuffers.get(vboIndex));
        ARBVertexBufferObject.glBufferDataARB(
            ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB,
            byteBuffer,
            ARBVertexBufferObject.GL_STREAM_DRAW_ARB);
      }

      if (hasTexture) {
        if (useVBO) {
          GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 32, 12L);
        } else {
          floatBuffer.position(3);
          GL11.glTexCoordPointer(2, 32, floatBuffer);
        }

        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
      }

      if (hasBrightness) {
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);

        if (useVBO) {
          GL11.glTexCoordPointer(2, GL11.GL_SHORT, 32, 28L);
        } else {
          shortBuffer.position(14);
          GL11.glTexCoordPointer(2, 32, shortBuffer);
        }

        GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
      }

      if (hasColor) {
        if (useVBO) {
          GL11.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 32, 20L);
        } else {
          byteBuffer.position(20);
          GL11.glColorPointer(4, true, 32, byteBuffer);
        }

        GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
      }

      if (hasNormals) {
        if (useVBO) {
          GL11.glNormalPointer(GL11.GL_UNSIGNED_BYTE, 32, 24L);
        } else {
          byteBuffer.position(24);
          GL11.glNormalPointer(32, byteBuffer);
        }

        GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
      }

      if (useVBO) {
        GL11.glVertexPointer(3, GL11.GL_FLOAT, 32, 0L);
      } else {
        floatBuffer.position(0);
        GL11.glVertexPointer(3, 32, floatBuffer);
      }

      GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);

      if (drawMode == 7 && convertQuadsToTriangles) {
        GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertexCount);
      } else {
        GL11.glDrawArrays(drawMode, 0, vertexCount);
      }

      GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);

      if (hasTexture) {
        GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
      }

      if (hasBrightness) {
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.lightmapTexUnit);
        GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
        OpenGlHelper.setClientActiveTexture(OpenGlHelper.defaultTexUnit);
      }

      if (hasColor) {
        GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
      }

      if (hasNormals) {
        GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
      }
    }

    int i = rawBufferIndex * 4;
    reset();
    return i;
  }