Java Code Examples for android.opengl.GLES20#glTexSubImage2D()

The following examples show how to use android.opengl.GLES20#glTexSubImage2D() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLUtil.java    From PhotoMovie with Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final IntBuffer data, final Size size, final int usedTexId) {
    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);
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, size.width, size.height,
                0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, size.width,
                size.height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example 2
Source File: OpenGlUtils.java    From TikTok with Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final Buffer data, final int width, final int height, final int usedTexId) {
if(data == null)
	return NO_TEXTURE;
   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);
       GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height,
               0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
   } else {
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
       GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, width,
               height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
       textures[0] = usedTexId;
   }
   return textures[0];
  }
 
Example 3
Source File: OpenGlUtils.java    From TikTok with Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final Buffer data, final int width, final int height, final int usedTexId, final int type) {
if(data == null)
	return NO_TEXTURE;
   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);
       GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height,
               0, GLES20.GL_RGBA, type, data);
   } else {
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
       GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, width,
               height, GLES20.GL_RGBA, type, data);
       textures[0] = usedTexId;
   }
   return textures[0];
  }
 
Example 4
Source File: OpenGlUtils.java    From TikTok with Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final Buffer data, final int width, final int height, final int usedTexId) {
if(data == null)
	return NO_TEXTURE;
   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);
       GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height,
               0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
   } else {
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
       GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, width,
               height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
       textures[0] = usedTexId;
   }
   return textures[0];
  }
 
Example 5
Source File: OpenGlUtils.java    From TikTok with Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final Buffer data, final int width, final int height, final int usedTexId, final int type) {
if(data == null)
	return NO_TEXTURE;
   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);
       GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height,
               0, GLES20.GL_RGBA, type, data);
   } else {
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
       GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, width,
               height, GLES20.GL_RGBA, type, data);
       textures[0] = usedTexId;
   }
   return textures[0];
  }
 
Example 6
Source File: CameraPluginActivity.java    From unity-android-native-camera with MIT License 6 votes vote down vote up
private void requestJavaRendering(int texturePointer) {

        if (!_update) {
            return;
        }

        int[] imageBuffer = new int[0];

        if (_conversionScript != null) {
            imageBuffer = _conversionScript.getOutputBuffer();
        }

        if (imageBuffer.length > 1) {
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texturePointer);

            GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, _previewSize.getWidth(),
                    _previewSize.getHeight(), GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE,
                    IntBuffer.wrap(imageBuffer));

        }
    }
 
Example 7
Source File: TextureUtils.java    From In77Camera with MIT License 6 votes vote down vote up
public static int getTextureFromByteBufferWithOldTexId(ByteBuffer byteBuffer,int width,int height,int usedTexId){
    if(byteBuffer.array().length!=width*height*4) throw new RuntimeException("Illegal byte array");
    int textures[] = new int[1];
    if (usedTexId == GLEtc.NO_TEXTURE) {
        return getTextureFromByteBuffer(byteBuffer,width,height);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D,0,0,0,
                width,height,
                GLES20.GL_RGBA,
                GLES20.GL_UNSIGNED_BYTE,
                byteBuffer
        );
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example 8
Source File: OpenGlUtils.java    From SimpleVideoEditor with Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final IntBuffer data, final Size size, final int usedTexId) {
    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);
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, size.width, size.height,
                0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, size.width,
                size.height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example 9
Source File: OpenGlUtils.java    From Fatigue-Detection with MIT License 6 votes vote down vote up
public static int loadTexture(Buffer paramBuffer, int paramInt1, int paramInt2, int paramInt3)
{
    int[] arrayOfInt = new int[1];
    if (paramInt3 == -1)
    {
        GLES20.glGenTextures(1, arrayOfInt, 0);
        GLES20.glBindTexture(3553, arrayOfInt[0]);
        GLES20.glTexParameterf(3553, 10240, 9729.0F);

        GLES20.glTexParameterf(3553, 10241, 9729.0F);

        GLES20.glTexParameterf(3553, 10242, 33071.0F);

        GLES20.glTexParameterf(3553, 10243, 33071.0F);

        GLES20.glTexImage2D(3553, 0, 6408, paramInt1, paramInt2, 0, 6408, 5121, paramBuffer);
    }
    else
    {
        GLES20.glBindTexture(3553, paramInt3);
        GLES20.glTexSubImage2D(3553, 0, 0, 0, paramInt1, paramInt2, 6408, 5121, paramBuffer);

        arrayOfInt[0] = paramInt3;
    }
    return arrayOfInt[0];
}
 
Example 10
Source File: GLUtil.java    From CameraCompat with MIT License 6 votes vote down vote up
public static int loadTexture(final ByteBuffer data, final int width, final int height,
        final int usedTexId) {
    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);
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0,
                GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, width, height, GLES20.GL_RGBA,
                GLES20.GL_UNSIGNED_BYTE, data);
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example 11
Source File: Texture.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public int texture() {
    if (texture != 0) {
        return texture;
    }

    if (bitmap.isRecycled()) {
        return 0;
    }

    int[] textures = new int[1];
    GLES20.glGenTextures(1, textures, 0);
    texture = textures[0];

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture);

    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    for (int i = 0; i < pixels.length; i += 1) {
        int argb = pixels[i];
        pixels[i] = argb & 0xff00ff00 | ((argb & 0xff) << 16) | ((argb >> 16) & 0xff);
    }
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, IntBuffer.wrap(pixels));

    int px = bitmap.getPixel(0, 0);

    ByteBuffer buffer = ByteBuffer.allocateDirect(4); //fix for android 9.0
    buffer.putInt(px).position(0);
    GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, 1, 1, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buffer);

    Utils.HasGLError();

    return texture;
}
 
Example 12
Source File: BasicCustomVideoRenderer.java    From opentok-android-sdk-samples with MIT License 5 votes vote down vote up
void updateTextures(Frame frame) {
    int width = frame.getWidth();
    int height = frame.getHeight();
    int half_width = (width + 1) >> 1;
    int half_height = (height +1) >> 1;
    int y_size = width * height;
    int uv_size = half_width * half_height;

    ByteBuffer bb = frame.getBuffer();
    // If we are reusing this frame, make sure we reset position and
    // limit
    bb.clear();

    if (bb.remaining() == y_size + uv_size * 2) {
        bb.position(0);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureIds[0]);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, width,
                height, GLES20.GL_LUMINANCE, GLES20.GL_UNSIGNED_BYTE,
                bb);

        bb.position(y_size);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureIds[1]);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0,
                half_width, half_height, GLES20.GL_LUMINANCE,
                GLES20.GL_UNSIGNED_BYTE, bb);

        bb.position(y_size + uv_size);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureIds[2]);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0,
                half_width, half_height, GLES20.GL_LUMINANCE,
                GLES20.GL_UNSIGNED_BYTE, bb);
    } else {
        mTextureWidth = 0;
        mTextureHeight = 0;
    }

}
 
Example 13
Source File: SmartPVRTexturePixelBufferStrategy.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public void loadPVRTextureData(final IPVRTexturePixelBufferStrategyBufferManager pPVRTexturePixelBufferStrategyManager, final int pWidth, final int pHeight, final int pBytesPerPixel, final PixelFormat pPixelFormat, final int pLevel, final int pCurrentPixelDataOffset, final int pCurrentPixelDataSize) throws IOException {
	final int glFormat = pPixelFormat.getGLFormat();
	final int glType = pPixelFormat.getGLType();

	/* Create the texture with the required parameters but without data. */
	GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, pLevel, pPixelFormat.getGLInternalFormat(), pWidth, pHeight, 0, glFormat, glType, null);

	final int bytesPerRow = pWidth * pBytesPerPixel;
	final int stripeHeight = Math.max(1, this.mAllocationSizeMaximum / bytesPerRow);

	/* Load stripes. */
	int currentStripePixelDataOffset = pCurrentPixelDataOffset;
	int currentStripeOffsetY = 0;
	while(currentStripeOffsetY < pHeight) {
		final int currentStripeHeight = Math.min(pHeight - currentStripeOffsetY, stripeHeight);
		final int currentStripePixelDataSize = currentStripeHeight * bytesPerRow;

		/* Adjust buffer. */
		final Buffer pixelBuffer = pPVRTexturePixelBufferStrategyManager.getPixelBuffer(PVRTextureHeader.SIZE + currentStripePixelDataOffset, currentStripePixelDataSize);

		/* Send to hardware. */
		GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, pLevel, 0, currentStripeOffsetY, pWidth, currentStripeHeight, glFormat, glType, pixelBuffer);

		currentStripePixelDataOffset += currentStripePixelDataSize;
		currentStripeOffsetY += currentStripeHeight;
	}
}
 
Example 14
Source File: SmartPVRTexturePixelBufferStrategy.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public void loadPVRTextureData(final IPVRTexturePixelBufferStrategyBufferManager pPVRTexturePixelBufferStrategyManager, final int pWidth, final int pHeight, final int pBytesPerPixel, final PixelFormat pPixelFormat, final int pLevel, final int pCurrentPixelDataOffset, final int pCurrentPixelDataSize) throws IOException {
	final int glFormat = pPixelFormat.getGLFormat();
	final int glType = pPixelFormat.getGLType();

	/* Create the texture with the required parameters but without data. */
	GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, pLevel, pPixelFormat.getGLInternalFormat(), pWidth, pHeight, 0, glFormat, glType, null);

	final int bytesPerRow = pWidth * pBytesPerPixel;
	final int stripeHeight = Math.max(1, this.mAllocationSizeMaximum / bytesPerRow);

	/* Load stripes. */
	int currentStripePixelDataOffset = pCurrentPixelDataOffset;
	int currentStripeOffsetY = 0;
	while (currentStripeOffsetY < pHeight) {
		final int currentStripeHeight = Math.min(pHeight - currentStripeOffsetY, stripeHeight);
		final int currentStripePixelDataSize = currentStripeHeight * bytesPerRow;

		/* Adjust buffer. */
		final Buffer pixelBuffer = pPVRTexturePixelBufferStrategyManager.getPixelBuffer(PVRTextureHeader.SIZE + currentStripePixelDataOffset, currentStripePixelDataSize);

		/* Send to hardware. */
		GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, pLevel, 0, currentStripeOffsetY, pWidth, currentStripeHeight, glFormat, glType, pixelBuffer);

		currentStripePixelDataOffset += currentStripePixelDataSize;
		currentStripeOffsetY += currentStripeHeight;
	}
}
 
Example 15
Source File: Texture.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public int texture() {
    if (texture != 0) {
        return texture;
    }

    if (bitmap.isRecycled()) {
        return 0;
    }

    int[] textures = new int[1];
    GLES20.glGenTextures(1, textures, 0);
    texture = textures[0];

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture);

    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    for (int i = 0; i < pixels.length; i += 1) {
        int argb = pixels[i];
        pixels[i] = argb & 0xff00ff00 | ((argb & 0xff) << 16) | ((argb >> 16) & 0xff);
    }
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, IntBuffer.wrap(pixels));

    int px = bitmap.getPixel(0, 0);

    ByteBuffer buffer = ByteBuffer.allocateDirect(4); //fix for android 9.0
    buffer.putInt(px).position(0);
    GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, 1, 1, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buffer);

    Utils.HasGLError();

    return texture;
}
 
Example 16
Source File: AndroidGL.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void texSubImage2D(int target, int level, int xoffset, int yoffset, int width,
                          int height, int format, int type, Buffer pixels) {
    GLES20.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);

}
 
Example 17
Source File: InvertedColorsVideoRenderer.java    From opentok-android-sdk-samples with MIT License 4 votes vote down vote up
void updateTextures(Frame frame) {
    int width = frame.getWidth();
    int height = frame.getHeight();
    int half_width = (width + 1) >> 1;
    int half_height = (height + 1) >> 1;
    int y_size = width * height;
    int uv_size = half_width * half_height;

    ByteBuffer bb = frame.getBuffer();
    // If we are reusing this frame, make sure we reset position and
    // limit
    bb.clear();

    if (bb.remaining() == y_size + uv_size * 2) {
        bb.position(0);

        GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
        GLES20.glPixelStorei(GLES20.GL_PACK_ALIGNMENT, 1);

        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureIds[0]);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, width,
                height, GLES20.GL_LUMINANCE, GLES20.GL_UNSIGNED_BYTE,
                bb);

        bb.position(y_size);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureIds[1]);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0,
                half_width, half_height, GLES20.GL_LUMINANCE,
                GLES20.GL_UNSIGNED_BYTE, bb);

        bb.position(y_size + uv_size);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureIds[2]);
        GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0,
                half_width, half_height, GLES20.GL_LUMINANCE,
                GLES20.GL_UNSIGNED_BYTE, bb);
    } else {
        mTextureWidth = 0;
        mTextureHeight = 0;
    }

}
 
Example 18
Source File: VisualizerRenderer.java    From MusicVisualization with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    if (!initGL(mSurfaceTexture)) {
        throw new RuntimeException("Initializing OpenGL failed");
    }

    final byte[] buf = new byte[mTextureWidth * 2];
    final int audioTexId = genAudioTexture(buf, mTextureWidth);
    if (mSceneController != null) {
        mSceneController.onSetup(mContext, audioTexId, mTextureWidth);
    }


    // Render loop
    while (!Thread.currentThread().isInterrupted()) {
        try {
            if (mSurfaceWidth < 0 && mSurfaceHeight < 0)
                GLES20.glViewport(0, 0, mSurfaceWidth = -mSurfaceWidth, mSurfaceHeight = -mSurfaceHeight);

            GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
            GLES20.glClearColor(1f, 0f, 0f, 0f);


            // Prepare the audio texture
            fillFFT(buf, 0, mTextureWidth);
            if (mWaveFormFrame != null) {
                System.arraycopy(mWaveFormFrame.getRawWaveForm(), 0, buf, mTextureWidth, mTextureWidth);
            }
            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, audioTexId);
            GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, mTextureWidth, 2,
                    GLES20.GL_LUMINANCE, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(buf));


            // Draw
            GLScene scene;
            if (mSceneController != null && (scene = mSceneController.getActivedScene()) != null) {
                scene.draw(mSurfaceWidth, mSurfaceHeight);
            }

            // Flush
            GLES20.glFlush();
            mEgl10.eglSwapBuffers(mEglDisplay, mEglSurface);

            Thread.sleep(DRAW_INTERVAL);

        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }

    // Release something
    GLES20.glDeleteTextures(1, new int[]{audioTexId}, 0);
}
 
Example 19
Source File: GLState.java    From tilt-game-android with MIT License 2 votes vote down vote up
/**
 * <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>'
 */
public void glTexSubImage2D(final int pTarget, final int pLevel, final int pX, final int pY, final Bitmap pBitmap, final PixelFormat pPixelFormat) {
	final Buffer pixelBuffer = GLHelper.getPixels(pBitmap, pPixelFormat, ByteOrder.BIG_ENDIAN);

	GLES20.glTexSubImage2D(pTarget, pLevel, pX, pY, pBitmap.getWidth(), pBitmap.getHeight(), pPixelFormat.getGLFormat(), pPixelFormat.getGLType(), pixelBuffer);
}
 
Example 20
Source File: GLState.java    From 30-android-libraries-in-30-days with Apache License 2.0 2 votes vote down vote up
/**
 * <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>'
 */
public void glTexSubImage2D(final int pTarget, final int pLevel, final int pX, final int pY, final Bitmap pBitmap, final PixelFormat pPixelFormat) {
	final Buffer pixelBuffer = GLHelper.getPixels(pBitmap, pPixelFormat, ByteOrder.BIG_ENDIAN);

	GLES20.glTexSubImage2D(pTarget, pLevel, pX, pY, pBitmap.getWidth(), pBitmap.getHeight(), pPixelFormat.getGLFormat(), pPixelFormat.getGLType(), pixelBuffer);
}