Example usage for android.opengl GLES10 glBindTexture

List of usage examples for android.opengl GLES10 glBindTexture

Introduction

In this page you can find the example usage for android.opengl GLES10 glBindTexture.

Prototype

public static native void glBindTexture(int target, int texture);

Source Link

Usage

From source file:com.adobe.plugins.FastCanvasRenderer.java

public void loadTexture(Bitmap bmp, int id) {
    if (bmp == null) {
        Log.i("CANVAS", "CanvasRenderer Aborting loadtexture " + id);
        return;/*from w w  w .  j  a va  2s  .co  m*/
    }

    int[] glID = new int[1];
    GLES10.glGenTextures(1, glID, 0);
    GLES10.glBindTexture(GLES10.GL_TEXTURE_2D, glID[0]);
    GLES10.glTexParameterf(GLES10.GL_TEXTURE_2D, GLES10.GL_TEXTURE_MIN_FILTER, GLES10.GL_LINEAR);
    GLES10.glTexParameterf(GLES10.GL_TEXTURE_2D, GLES10.GL_TEXTURE_MAG_FILTER, GLES10.GL_LINEAR);

    int width = bmp.getWidth();
    int height = bmp.getHeight();
    int p2Width = 2;
    while (p2Width < width) {
        p2Width *= 2;
    }

    int p2Height = 2;
    while (p2Height < height) {
        p2Height *= 2;
    }

    if (width == p2Width && height == p2Height) {
        GLUtils.texImage2D(GLES10.GL_TEXTURE_2D, 0, bmp, 0);
    } else {
        Log.i("Canvas", "Canvas::AddTexture scaling texture " + id + " to power of 2");
        GLES10.glTexImage2D(GLES10.GL_TEXTURE_2D, 0, GLES10.GL_RGBA, p2Width, p2Height, 0, GLES10.GL_RGBA,
                GLES10.GL_UNSIGNED_BYTE, null);
        GLUtils.texSubImage2D(GLES10.GL_TEXTURE_2D, 0, 0, 0, bmp);
        width = p2Width;
        height = p2Height;
    }

    checkError();

    FastCanvasJNI.addTexture(id, glID[0], width, height);
    Log.i("CANVAS", "CanvasRenderer Leaving loadtexture " + id);
}