Example usage for android.opengl GLUtils texSubImage2D

List of usage examples for android.opengl GLUtils texSubImage2D

Introduction

In this page you can find the example usage for android.opengl GLUtils texSubImage2D.

Prototype

public static void texSubImage2D(int target, int level, int xoffset, int yoffset, Bitmap bitmap) 

Source Link

Document

Calls glTexSubImage2D() on the current OpenGL context.

Usage

From source file:Main.java

public static int loadTexture(final Bitmap img, final int usedTexId, final boolean recycle) {
    int textures[] = new int[1];
    if (usedTexId == NO_TEXTURE) {
        GLES20.glGenTextures(1, textures, 0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, img, 0);
    } else {//from   w w  w  .j av  a  2s .c o m
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, img);
        textures[0] = usedTexId;
    }
    if (recycle) {
        img.recycle();
    }
    return textures[0];
}

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;/* w  ww  .j a  v a 2s . c  o  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);
}