Java Code Examples for android.opengl.GLES20#GL_RGBA

The following examples show how to use android.opengl.GLES20#GL_RGBA . 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: Texture.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static int generateTexture(Size size) {
    int texture;
    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_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);

    int width = (int) size.width;
    int height = (int) size.height;
    int format = GLES20.GL_RGBA;
    int type = GLES20.GL_UNSIGNED_BYTE;

    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, format, width, height, 0, format, type, null);

    return texture;
}
 
Example 2
Source File: WaterMarkFilter.java    From sealrtc-android with MIT License 6 votes vote down vote up
public WaterMarkFilter(Context context, boolean isFrontCamera, Bitmap waterBmp) {
    mTextureFilter = new GlTextureFrameBuffer(GLES20.GL_RGBA);
    mWaterSign = new CommonFilter();
    mWaterSign.setShaderProgram(new CommonProgram());

    mFrame = new CommonFilter();
    mFrame.setShaderProgram(new CommonProgram());

    mWaterWidth = waterBmp.getWidth();
    mWaterHeight = waterBmp.getHeight();
    mWaterTexId = TextureHelper.loadTexture(waterBmp);
    mDisplay =
            ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
                    .getDefaultDisplay();
    angleChange(isFrontCamera);
}
 
Example 3
Source File: GlTextureFrameBuffer.java    From sealrtc-android with MIT License 6 votes vote down vote up
/**
 * Generate texture and framebuffer resources. An EGLContext must be bound on the current thread
 * when calling this function. The framebuffer is not complete until setSize() is called.
 */
public GlTextureFrameBuffer(int pixelFormat) {
    switch (pixelFormat) {
        case GLES20.GL_LUMINANCE:
        case GLES20.GL_RGB:
        case GLES20.GL_RGBA:
            this.pixelFormat = pixelFormat;
            break;
        default:
            throw new IllegalArgumentException("Invalid pixel format: " + pixelFormat);
    }

    // Create texture.
    textureId = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D);
    this.width = 0;
    this.height = 0;

    // Create framebuffer object.
    final int frameBuffers[] = new int[1];
    GLES20.glGenFramebuffers(1, frameBuffers, 0);
    frameBufferId = frameBuffers[0];
}
 
Example 4
Source File: Texture.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static int generateTexture(Size size) {
    int texture;
    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_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);

    int width = (int) size.width;
    int height = (int) size.height;
    int format = GLES20.GL_RGBA;
    int type = GLES20.GL_UNSIGNED_BYTE;

    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, format, width, height, 0, format, type, null);

    return texture;
}
 
Example 5
Source File: YuvConverter.java    From VideoCRE with MIT License 6 votes vote down vote up
/**
 * This class should be constructed on a thread that has an active EGL context.
 */
public YuvConverter() {
  threadChecker.checkIsOnValidThread();
  textureFrameBuffer = new GlTextureFrameBuffer(GLES20.GL_RGBA);
  shader = new GlShader(VERTEX_SHADER, FRAGMENT_SHADER);
  shader.useProgram();
  texMatrixLoc = shader.getUniformLocation("texMatrix");
  xUnitLoc = shader.getUniformLocation("xUnit");
  coeffsLoc = shader.getUniformLocation("coeffs");
  GLES20.glUniform1i(shader.getUniformLocation("oesTex"), 0);
  GlUtil.checkNoGLES2Error("Initialize fragment shader uniform values.");
  // Initialize vertex shader attributes.
  shader.setVertexAttribArray("in_pos", 2, DEVICE_RECTANGLE);
  // If the width is not a multiple of 4 pixels, the texture
  // will be scaled up slightly and clipped at the right border.
  shader.setVertexAttribArray("in_tc", 2, TEXTURE_RECTANGLE);
}
 
Example 6
Source File: GlTextureFrameBuffer.java    From VideoCRE with MIT License 6 votes vote down vote up
/**
 * Generate texture and framebuffer resources. An EGLContext must be bound on the current thread
 * when calling this function. The framebuffer is not complete until setSize() is called.
 */
public GlTextureFrameBuffer(int pixelFormat) {
  switch (pixelFormat) {
    case GLES20.GL_LUMINANCE:
    case GLES20.GL_RGB:
    case GLES20.GL_RGBA:
      this.pixelFormat = pixelFormat;
      break;
    default:
      throw new IllegalArgumentException("Invalid pixel format: " + pixelFormat);
  }

  // Create texture.
  textureId = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D);
  this.width = 0;
  this.height = 0;

  // Create framebuffer object.
  final int frameBuffers[] = new int[1];
  GLES20.glGenFramebuffers(1, frameBuffers, 0);
  frameBufferId = frameBuffers[0];
}
 
Example 7
Source File: Texture.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static int generateTexture(Size size) {
    int texture;
    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 = (int) size.width;
    int height = (int) size.height;
    int format = GLES20.GL_RGBA;
    int type = GLES20.GL_UNSIGNED_BYTE;

    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, format, width, height, 0, format, type, null);

    return texture;
}
 
Example 8
Source File: Texture.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static int generateTexture(Size size) {
    int texture;
    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 = (int) size.width;
    int height = (int) size.height;
    int format = GLES20.GL_RGBA;
    int type = GLES20.GL_UNSIGNED_BYTE;

    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, format, width, height, 0, format, type, null);

    return texture;
}
 
Example 9
Source File: GlTextureFrameBuffer.java    From webrtc_android with MIT License 5 votes vote down vote up
/**
 * Generate texture and framebuffer resources. An EGLContext must be bound on the current thread
 * when calling this function. The framebuffer is not complete until setSize() is called.
 */
public GlTextureFrameBuffer(int pixelFormat) {
  switch (pixelFormat) {
    case GLES20.GL_LUMINANCE:
    case GLES20.GL_RGB:
    case GLES20.GL_RGBA:
      this.pixelFormat = pixelFormat;
      break;
    default:
      throw new IllegalArgumentException("Invalid pixel format: " + pixelFormat);
  }
  this.width = 0;
  this.height = 0;
}
 
Example 10
Source File: GPUImageFilter.java    From sealrtc-android with MIT License 5 votes vote down vote up
public int draw(int width, int height, int rgbTextureId) {

        // if (textureCopy == null) {
        //   textureCopy = new GlTextureFrameBuffer(GLES20.GL_RGBA);
        // }

        // textureCopy.setSize(width, height);

        // GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, textureCopy.getFrameBufferId());
        // GlUtil.checkNoGLES2Error("glBindFramebuffer");

        // Copy the OES texture content. This will also normalize the sampling matrix.
        // glRectDrawer.drawOes(oesTextureId, identityMatrix(), textureCopy.getWidth(),
        //       textureCopy.getHeight(), 0, 0, textureCopy.getWidth(), textureCopy.getHeight());

        if (textureFilter == null) {
            textureFilter = new GlTextureFrameBuffer(GLES20.GL_RGBA);
        }

        textureFilter.setSize(width, height);

        if (!mFilter.isInitialized()) {
            mFilter.init();
        }

        mFilter.onOutputSizeChanged(width, height);

        GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, textureFilter.getFrameBufferId());
        GlUtil.checkNoGLES2Error("glBindFramebuffer");

        mFilter.onDraw(rgbTextureId);
        // Restore normal framebuffer.
        GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

        return textureFilter.getTextureId();
    }
 
Example 11
Source File: Texture2D.java    From Spectaculum with Apache License 2.0 5 votes vote down vote up
public static Texture2D generateFloatTexture(int width, int height) {
    if(GLUtils.HAS_GLES30 && GLUtils.HAS_GL_OES_texture_half_float && GLUtils.HAS_FLOAT_FRAMEBUFFER_SUPPORT) {
        return new Texture2D(GLES30.GL_RGBA16F, GLES20.GL_RGBA, width, height, GLES20.GL_FLOAT, null);
    } else {
        Log.i(TAG, "Texture fallback mode to GLES20 8 bit");
        return new Texture2D(GLES20.GL_RGBA, GLES20.GL_RGBA, width, height, GLES20.GL_UNSIGNED_BYTE, null);
    }
}
 
Example 12
Source File: MirrorImageHelper.java    From sealrtc-android with MIT License 4 votes vote down vote up
private void initGlRender() {
  mTextureFilter = new GlTextureFrameBuffer(GLES20.GL_RGBA);
  mFrame = new CommonFilter();
  mFrame.setShaderProgram(new CommonProgram());
}
 
Example 13
Source File: EglRenderer.java    From VideoCRE with MIT License 4 votes vote down vote up
private void notifyCallbacks(
    VideoRenderer.I420Frame frame, int[] yuvTextures, float[] texMatrix, boolean wasRendered) {
  if (frameListeners.isEmpty())
    return;

  final float[] bitmapMatrix = RendererCommon.multiplyMatrices(
      RendererCommon.multiplyMatrices(texMatrix,
          mirror ? RendererCommon.horizontalFlipMatrix() : RendererCommon.identityMatrix()),
      RendererCommon.verticalFlipMatrix());

  Iterator<FrameListenerAndParams> it = frameListeners.iterator();
  while (it.hasNext()) {
    FrameListenerAndParams listenerAndParams = it.next();
    if (!wasRendered && listenerAndParams.applyFpsReduction) {
      continue;
    }
    it.remove();

    final int scaledWidth = (int) (listenerAndParams.scale * frame.rotatedWidth());
    final int scaledHeight = (int) (listenerAndParams.scale * frame.rotatedHeight());

    if (scaledWidth == 0 || scaledHeight == 0) {
      listenerAndParams.listener.onFrame(null);
      continue;
    }

    if (bitmapTextureFramebuffer == null) {
      bitmapTextureFramebuffer = new GlTextureFrameBuffer(GLES20.GL_RGBA);
    }
    bitmapTextureFramebuffer.setSize(scaledWidth, scaledHeight);

    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, bitmapTextureFramebuffer.getFrameBufferId());
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
        GLES20.GL_TEXTURE_2D, bitmapTextureFramebuffer.getTextureId(), 0);

    GLES20.glClearColor(0 /* red */, 0 /* green */, 0 /* blue */, 0 /* alpha */);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    if (frame.yuvFrame) {
      listenerAndParams.drawer.drawYuv(yuvTextures, bitmapMatrix, frame.rotatedWidth(),
          frame.rotatedHeight(), 0 /* viewportX */, 0 /* viewportY */, scaledWidth, scaledHeight);
    } else {
      listenerAndParams.drawer.drawOes(frame.textureId, bitmapMatrix, frame.rotatedWidth(),
          frame.rotatedHeight(), 0 /* viewportX */, 0 /* viewportY */, scaledWidth, scaledHeight);
    }

    final ByteBuffer bitmapBuffer = ByteBuffer.allocateDirect(scaledWidth * scaledHeight * 4);
    GLES20.glViewport(0, 0, scaledWidth, scaledHeight);
    GLES20.glReadPixels(
        0, 0, scaledWidth, scaledHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, bitmapBuffer);

    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GlUtil.checkNoGLES2Error("EglRenderer.notifyCallbacks");

    final Bitmap bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    bitmap.copyPixelsFromBuffer(bitmapBuffer);
    listenerAndParams.listener.onFrame(bitmap);
  }
}
 
Example 14
Source File: Texture2D.java    From Spectaculum with Apache License 2.0 4 votes vote down vote up
public Texture2D(int width, int height) {
    this(GLES20.GL_RGBA, GLES20.GL_RGBA, width, height, GLES20.GL_UNSIGNED_BYTE, null);
}
 
Example 15
Source File: Framebuffer.java    From HoloKilo with GNU General Public License v3.0 4 votes vote down vote up
public Framebuffer(int width, int height) {
    this(width, height, GLES20.GL_RGBA);
}