Beispiel #1
0
  public static void reset(final GL10 pGL) {
    GLHelper.sCurrentHardwareBufferID = -1;
    GLHelper.sCurrentHardwareTextureID = -1;
    GLHelper.sCurrentMatrix = -1;

    GLHelper.sCurrentSourceBlendMode = -1;
    GLHelper.sCurrentDestinationBlendMode = -1;

    GLHelper.sCurrentVertexFloatBuffer = null;
    GLHelper.sCurrentTextureFloatBuffer = null;

    GLHelper.enableDither(pGL);
    GLHelper.enableLightning(pGL);
    GLHelper.enableDepthTest(pGL);
    GLHelper.enableMultisample(pGL);

    GLHelper.disableBlend(pGL);
    GLHelper.disableCulling(pGL);
    GLHelper.disableTextures(pGL);
    GLHelper.disableTexCoordArray(pGL);
    GLHelper.disableVertexArray(pGL);

    GLHelper.sLineWidth = 1;

    GLHelper.sRed = -1;
    GLHelper.sGreen = -1;
    GLHelper.sBlue = -1;
    GLHelper.sAlpha = -1;

    GLHelper.EXTENSIONS_VERTEXBUFFEROBJECTS = false;
    GLHelper.EXTENSIONS_DRAWTEXTURE = false;
    GLHelper.EXTENSIONS_TEXTURE_NON_POWER_OF_TWO = false;
  }
Beispiel #2
0
  public static void enableExtensions(final GL10 pGL, final RenderOptions pRenderOptions) {
    final String version = pGL.glGetString(GL10.GL_VERSION);
    final String renderer = pGL.glGetString(GL10.GL_RENDERER);
    final String extensions = pGL.glGetString(GL10.GL_EXTENSIONS);

    Debug.d("RENDERER: " + renderer);
    Debug.d("VERSION: " + version);
    Debug.d("EXTENSIONS: " + extensions);

    final boolean isOpenGL10 = version.contains("1.0");
    final boolean isOpenGL2X = version.contains("2.");
    final boolean isSoftwareRenderer = renderer.contains("PixelFlinger");
    final boolean isVBOCapable = extensions.contains("_vertex_buffer_object");
    final boolean isDrawTextureCapable = extensions.contains("draw_texture");
    final boolean isTextureNonPowerOfTwoCapable = extensions.contains("texture_npot");

    GLHelper.EXTENSIONS_VERTEXBUFFEROBJECTS =
        !pRenderOptions.isDisableExtensionVertexBufferObjects()
            && !isSoftwareRenderer
            && (isVBOCapable || !isOpenGL10);
    GLHelper.EXTENSIONS_DRAWTEXTURE =
        !pRenderOptions.isDisableExtensionVertexBufferObjects()
            && (isDrawTextureCapable || !isOpenGL10);
    GLHelper.EXTENSIONS_TEXTURE_NON_POWER_OF_TWO = isTextureNonPowerOfTwoCapable || isOpenGL2X;

    GLHelper.hackBrokenDevices();
    Debug.d("EXTENSIONS_VERXTEXBUFFEROBJECTS = " + GLHelper.EXTENSIONS_VERTEXBUFFEROBJECTS);
    Debug.d("EXTENSIONS_DRAWTEXTURE = " + GLHelper.EXTENSIONS_DRAWTEXTURE);
  }
Beispiel #3
0
  private static Buffer getPixels(final Bitmap pBitmap, final PixelFormat pPixelFormat) {
    final int[] pixelsARGB_8888 = GLHelper.getPixelsARGB_8888(pBitmap);

    switch (pPixelFormat) {
      case RGB_565:
        return ByteBuffer.wrap(GLHelper.convertARGB_8888toRGB_565(pixelsARGB_8888));
      case RGBA_8888:
        return IntBuffer.wrap(GLHelper.convertARGB_8888toRGBA_8888(pixelsARGB_8888));
      case RGBA_4444:
        return ByteBuffer.wrap(GLHelper.convertARGB_8888toARGB_4444(pixelsARGB_8888));
      case A_8:
        return ByteBuffer.wrap(GLHelper.convertARGB_8888toA_8(pixelsARGB_8888));
      default:
        throw new IllegalArgumentException(
            "Unexpected " + PixelFormat.class.getSimpleName() + ": '" + pPixelFormat + "'.");
    }
  }
  public void selectOnHardware(final GL11 pGL11) {
    final int hardwareBufferID = this.mHardwareBufferID;
    if (hardwareBufferID == -1) {
      return;
    }

    GLHelper.bindBuffer(
        pGL11,
        hardwareBufferID); // TODO Does this always need to be binded, or are just for buffers of
                           // the same 'type'(texture/vertex)?

    if (this.mHardwareBufferNeedsUpdate) {
      //			Debug.d("BufferObject.updating: ID = "  + this.mHardwareBufferID);
      this.mHardwareBufferNeedsUpdate = false;
      // BufferUtils.copy(mBufferData, mFloatBuffer, mFloatBuffer.capacity(), 0);
      pGL11.glBufferData(
          GL11.GL_ARRAY_BUFFER, mFloatBuffer.capacity() * 4, mFloatBuffer, mDrawType);
    }
  }
Beispiel #5
0
  /**
   * <b>Note:</b> does not pre-multiply the alpha channel!</br> Except that difference, same as:
   * {@link GLUtils#texSubImage2D(int, int, int, int, Bitmap, int, int)}</br> </br> See topic: '<a
   * href="http://groups.google.com/group/android-developers/browse_thread/thread/baa6c33e63f82fca">PNG
   * loading that doesn't premultiply alpha?</a>'
   *
   * @param pBorder
   */
  public static void glTexImage2D(
      final GL10 pGL,
      final int pTarget,
      final int pLevel,
      final Bitmap pBitmap,
      final int pBorder,
      final PixelFormat pPixelFormat) {
    final Buffer pixelBuffer = GLHelper.getPixels(pBitmap, pPixelFormat);

    pGL.glTexImage2D(
        pTarget,
        pLevel,
        pPixelFormat.getGLFormat(),
        pBitmap.getWidth(),
        pBitmap.getHeight(),
        pBorder,
        pPixelFormat.getGLFormat(),
        pPixelFormat.getGLType(),
        pixelBuffer);
  }
 private void deleteBufferOnHardware(final GL11 pGL11) {
   GLHelper.deleteBuffer(pGL11, this.mHardwareBufferID);
 }
 protected void onInitDraw(GL10 paramGL10) {
   super.onInitDraw(paramGL10);
   GLHelper.enableTextures(paramGL10);
   GLHelper.enableTexCoordArray(paramGL10);
 }
Beispiel #8
0
 public static void setModelViewIdentityMatrix(final GL10 pGL) {
   GLHelper.switchToModelViewMatrix(pGL);
   pGL.glLoadIdentity();
 }
Beispiel #9
0
 public static void setProjectionIdentityMatrix(final GL10 pGL) {
   GLHelper.switchToProjectionMatrix(pGL);
   pGL.glLoadIdentity();
 }