/** * Creates a texture from raw data. * * @param data Image data, in a "direct" ByteBuffer. * @param width Texture width, in pixels (not bytes). * @param height Texture height, in pixels. * @param format Image data format (use constant appropriate for glTexImage2D(), e.g. GL_RGBA). * @return Handle to texture. */ public static int createImageTexture(ByteBuffer data, int width, int height, int format) { int[] textureHandles = new int[1]; int textureHandle; GLES20.glGenTextures(1, textureHandles, 0); textureHandle = textureHandles[0]; GlUtil.checkGlError("glGenTextures"); // Bind the texture handle to the 2D texture target. GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle); // Configure min/mag filtering, i.e. what scaling method do we use if what we're rendering // is smaller or larger than the source image. GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GlUtil.checkGlError("loadImageTexture"); // Load the data from the buffer into the texture handle. GLES20.glTexImage2D( GLES20.GL_TEXTURE_2D, /*level*/ 0, format, width, height, /*border*/ 0, format, GLES20.GL_UNSIGNED_BYTE, data); GlUtil.checkGlError("loadImageTexture"); return textureHandle; }