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

The following examples show how to use android.opengl.GLES20#glGenTextures() . 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: BasicCustomVideoRenderer.java    From opentok-android-sdk-samples with MIT License 6 votes vote down vote up
void setupTextures(Frame frame) {
    if (mTextureIds[0] != 0) {
        GLES20.glDeleteTextures(3, mTextureIds, 0);
    }
    GLES20.glGenTextures(3, mTextureIds, 0);

    int w = frame.getWidth();
    int h = frame.getHeight();
    int hw = (w + 1) >> 1;
    int hh = (h +1) >> 1;

    initializeTexture(GLES20.GL_TEXTURE0, mTextureIds[0], w, h);
    initializeTexture(GLES20.GL_TEXTURE1, mTextureIds[1], hw, hh);
    initializeTexture(GLES20.GL_TEXTURE2, mTextureIds[2], hw, hh);

    mTextureWidth = frame.getWidth();
    mTextureHeight = frame.getHeight();
}
 
Example 3
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 4
Source File: ExternalSurfaceTexture.java    From Spectaculum with Apache License 2.0 6 votes vote down vote up
public ExternalSurfaceTexture() {
    super();

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

    mTexture = textures[0];
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTexture);
    GLUtils.checkError("glBindTexture");

    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    GLUtils.checkError("glTexParameter");

    // This surface texture needs to be fed to the media player; through it,
    // the picture data will be written into the texture.
    mSurfaceTexture = new SurfaceTexture(mTexture);
    mSurfaceTexture.setOnFrameAvailableListener(this);
}
 
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) {
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 6
Source File: FrameRenderer.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
private void setupTextures() {
  GLES20.glGenTextures(3, yuvTextures, 0);
  for (int i = 0; i < 3; i++) {
    GLES20.glUniform1i(GLES20.glGetUniformLocation(program, TEXTURE_UNIFORMS[i]), i);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, yuvTextures[i]);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_MAG_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);
  }
  checkNoGLES2Error();
}
 
Example 7
Source File: GLUtil.java    From android-3D-model-viewer with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static int loadTexture(final InputStream is) {
	Log.v("GLUtil", "Loading texture from stream...");

	final int[] textureHandle = new int[1];

	GLES20.glGenTextures(1, textureHandle, 0);
	GLUtil.checkGlError("glGenTextures");
	if (textureHandle[0] == 0) {
		throw new RuntimeException("Error loading texture.");
	}

	Log.v("GLUtil", "Handler: " + textureHandle[0]);

	final BitmapFactory.Options options = new BitmapFactory.Options();
	// By default, Android applies pre-scaling to bitmaps depending on the resolution of your device and which
	// resource folder you placed the image in. We don’t want Android to scale our bitmap at all, so to be sure,
	// we set inScaled to false.
	options.inScaled = false;

	// Read in the resource
	final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
	if (bitmap == null) {
		throw new RuntimeException("couldnt load bitmap");
	}

	// Bind to the texture in OpenGL
	GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
	GLUtil.checkGlError("glBindTexture");
	GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
	GLUtil.checkGlError("texImage2D");
	bitmap.recycle();
	GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
	GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

	Log.v("GLUtil", "Loaded texture ok");
	return textureHandle[0];
}
 
Example 8
Source File: Texture.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public Texture() {
	int[] ids = new int[1];
	GLES20.glGenTextures( 1, ids, 0 );
	id = ids[0];

	if(id==0) {
		throw new AssertionError();
	}

	//Log.i("texture",Utils.format("creating %d", id));
	bind();
}
 
Example 9
Source File: GlSceneRenderer.java    From ParticlesDrawable with Apache License 2.0 5 votes vote down vote up
public void setupGl() {
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    GLES20.glGenTextures(2, textureHandle, 0);

    markParticleTextureDirty();
    background.init(textureHandle[0]);
    lines.init();
    particles.init(textureHandle[1]);
}
 
Example 10
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 11
Source File: CameraGLRendererBase.java    From Document-Scanner with GNU General Public License v3.0 5 votes vote down vote up
private void initFBO(int width, int height)
{
    Log.d(LOGTAG, "initFBO("+width+"x"+height+")");

    deleteFBO();

    GLES20.glGenTextures(1, texDraw, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texDraw[0]);
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
    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_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

    GLES20.glGenTextures(1, texFBO, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texFBO[0]);
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
    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_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

    //int hFBO;
    GLES20.glGenFramebuffers(1, FBO, 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, FBO[0]);
    GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texFBO[0], 0);
    Log.d(LOGTAG, "initFBO error status: " + GLES20.glGetError());

    int FBOstatus = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
    if (FBOstatus != GLES20.GL_FRAMEBUFFER_COMPLETE)
        Log.e(LOGTAG, "initFBO failed, status: " + FBOstatus);

    mFBOWidth  = width;
    mFBOHeight = height;
}
 
Example 12
Source File: GLDrawer.java    From Building-Android-UIs-with-Custom-Views with MIT License 5 votes vote down vote up
private int loadTexture(int resId) {
    final int[] textureIds = new int[1];
    GLES20.glGenTextures(1, textureIds, 0);

    if (textureIds[0] == 0) return -1;

    // do not scale the bitmap depending on screen density
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;

    final Bitmap textureBitmap = BitmapFactory.decodeResource(getResources(), resId, options);
    attachBitmapToTexture(textureIds[0], textureBitmap);

    return textureIds[0];
}
 
Example 13
Source File: OpenGlUtil.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
public static int createOneOesTexture() {
    int texture[] = new int[1];
    GLES20.glGenTextures(1, texture, 0);
    if (texture[0] == 0) {
        return 0;
    }
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texture[0]);
    glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
            GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
            GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    return texture[0];
}
 
Example 14
Source File: BaseRenderOffScreen.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
protected void initFBO(int width, int height, int[] fboId, int[] rboId, int[] texId) {
  GlUtil.checkGlError("initFBO_S");

  GLES20.glGenFramebuffers(1, fboId, 0);
  GLES20.glGenRenderbuffers(1, rboId, 0);
  GLES20.glGenTextures(1, texId, 0);

  GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, rboId[0]);
  GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width,
      height);
  GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboId[0]);
  GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT,
      GLES20.GL_RENDERBUFFER, rboId[0]);

  GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId[0]);
  GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
  GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
  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.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA,
      GLES20.GL_UNSIGNED_BYTE, null);
  GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0,
      GLES20.GL_TEXTURE_2D, texId[0], 0);

  int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
  if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
    throw new RuntimeException("FrameBuffer uncompleted code: " + status);
  }
  GlUtil.checkGlError("initFBO_E");
}
 
Example 15
Source File: CameraRender.java    From AudioVideoCodec with Apache License 2.0 5 votes vote down vote up
/**
 * 创建水印纹理id
 */
private void createWaterTextureId() {

    int[] textureIds = new int[1];
    //创建纹理
    GLES20.glGenTextures(1, textureIds, 0);
    waterTextureId = textureIds[0];
    //绑定纹理
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, waterTextureId);
    //环绕(超出纹理坐标范围)  (s==x t==y GL_REPEAT 重复)
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
    //过滤(纹理像素映射到坐标点)  (缩小、放大:GL_LINEAR线性)
    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);

    ByteBuffer bitmapBuffer = ByteBuffer.allocate(bitmap.getHeight() * bitmap.getWidth() * 4);//RGBA
    bitmap.copyPixelsToBuffer(bitmapBuffer);
    //将bitmapBuffer位置移动到初始位置
    bitmapBuffer.flip();

    //设置内存大小绑定内存地址
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, bitmap.getWidth(), bitmap.getHeight(),
            0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, bitmapBuffer);

    //解绑纹理
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
}
 
Example 16
Source File: FURenderer.java    From PLDroidShortVideo with Apache License 2.0 4 votes vote down vote up
private void createFBO(int width, int height) {
        if (fboTex != null && (fboWidth != width || fboHeight != height)) {
            deleteFBO();
        }

        fboWidth = width;
        fboHeight = height;

        if (fboTex == null) {
            fboId = new int[4];
            fboTex = new int[4];
            renderBufferId = new int[4];

//generate fbo id
            GLES20.glGenFramebuffers(4, fboId, 0);
//generate texture
            GLES20.glGenTextures(4, fboTex, 0);
//generate render buffer
            GLES20.glGenRenderbuffers(4, renderBufferId, 0);

            for (int i = 0; i < fboId.length; i++) {
//Bind Frame buffer
                GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboId[i]);
//Bind texture
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, fboTex[i]);
//Define texture parameters
                GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
                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);
//Bind render buffer and define buffer dimension
                GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderBufferId[i]);
                GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height);
//Attach texture FBO color attachment
                GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, fboTex[i], 0);
//Attach render buffer to depth attachment
                GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, renderBufferId[i]);
//we are done, reset
                GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
                GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, 0);
                GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
            }
        }
    }
 
Example 17
Source File: GLRenderer.java    From bombsquad-remote-android with Apache License 2.0 4 votes vote down vote up
private static int newTextureID() {
  int[] temp = new int[1];
  GLES20.glGenTextures(1, temp, 0);
  return temp[0];
}
 
Example 18
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * <code>updateTexImageData</code> activates and binds the texture
 * @param img
 * @param type
 * @param mips
 */
public void updateTexImageData(Image img, Texture.Type type, boolean mips) {
    int texId = img.getId();
    if (texId == -1) {
        // create texture
        if (verboseLogging) {
            logger.info("GLES20.glGenTexture(1, buffer)");
        }

        GLES20.glGenTextures(1, intBuf1);
        texId = intBuf1.get(0);
        img.setId(texId);
        objManager.registerForCleanup(img);

        statistics.onNewTexture();
    }

    // bind texture
    int target = convertTextureType(type);
    if (context.boundTextureUnit != 0) {
        if (verboseLogging) {
            logger.info("GLES20.glActiveTexture(GLES20.GL_TEXTURE0)");
        }

        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        context.boundTextureUnit = 0;
    }
    if (context.boundTextures[0] != img) {

        if (verboseLogging) {
            logger.info("GLES20.glBindTexture(" + target + ", " + texId + ")");
        }

        GLES20.glBindTexture(target, texId);
        context.boundTextures[0] = img;
    }


    if (target == GLES20.GL_TEXTURE_CUBE_MAP) {
        // Upload a cube map / sky box
        @SuppressWarnings("unchecked")
        List<Bitmap> bmps = (List<Bitmap>) img.getEfficentData();
        if (bmps != null) {
            // Native android bitmap                                       
            if (bmps.size() != 6) {
                throw new UnsupportedOperationException("Invalid texture: " + img
                        + "Cubemap textures must contain 6 data units.");
            }
            for (int i = 0; i < 6; i++) {
                TextureUtil.uploadTextureBitmap(GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, bmps.get(i), false, powerOf2);
            }
        } else {
            // Standard jme3 image data
            List<ByteBuffer> data = img.getData();
            if (data.size() != 6) {
                logger.log(Level.WARNING, "Invalid texture: {0}\n"
                        + "Cubemap textures must contain 6 data units.", img);
                return;
            }
            for (int i = 0; i < 6; i++) {
                TextureUtil.uploadTexture(img, GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, 0, tdc, false, powerOf2);
            }
        }
    } else {
        TextureUtil.uploadTexture(img, target, 0, 0, tdc, false, powerOf2);

        if (verboseLogging) {
            logger.info("GLES20.glTexParameteri(" + target + "GLES11.GL_GENERATE_MIMAP, GLES20.GL_TRUE)");
        }

        if (!img.hasMipmaps() && mips) {
            // No pregenerated mips available,
            // generate from base level if required
            if (verboseLogging) {
                logger.info("GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D)");
            }
            GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
        }
    }

    img.clearUpdateNeeded();
}
 
Example 19
Source File: RoundedTextureView.java    From android-RoundedTextureView with Apache License 2.0 4 votes vote down vote up
@Override public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
  program = createProgram(vertexShader, fragmentShader);
  if (program == 0) {
    return;
  }
  aPositionHandle = GLES20.glGetAttribLocation(program, "aPosition");
  checkGlError("glGetAttribLocation aPosition");
  if (aPositionHandle == -1) {
    throw new RuntimeException("Could not get attrib location for aPosition");
  }
  aTextureHandle = GLES20.glGetAttribLocation(program, "aTextureCoord");
  checkGlError("glGetAttribLocation aTextureCoord");
  if (aTextureHandle == -1) {
    throw new RuntimeException("Could not get attrib location for aTextureCoord");
  }

  mvpMatrixHandle = GLES20.glGetUniformLocation(program, "uMVPMatrix");
  checkGlError("glGetUniformLocation uMVPMatrix");
  if (mvpMatrixHandle == -1) {
    throw new RuntimeException("Could not get attrib location for uMVPMatrix");
  }

  ustMatrixHandle = GLES20.glGetUniformLocation(program, "uSTMatrix");
  checkGlError("glGetUniformLocation uSTMatrix");
  if (ustMatrixHandle == -1) {
    throw new RuntimeException("Could not get attrib location for uSTMatrix");
  }

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

  textureID = textures[0];
  GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureID);
  checkGlError("glBindTexture textureID");

  GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER,
      GLES20.GL_LINEAR);
  GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER,
      GLES20.GL_LINEAR);

  surfaceTexture = new SurfaceTexture(textureID);
  surfaceTexture.setOnFrameAvailableListener(this);
  if (surfaceProvider != null) {
    surfaceProvider.onSurfaceCreated(surfaceTexture);
  }

  synchronized (this) {
    updateSurface = false;
  }
}
 
Example 20
Source File: PlaneRenderer.java    From poly-sample-android with Apache License 2.0 4 votes vote down vote up
/**
 * Allocates and initializes OpenGL resources needed by the plane renderer. Must be called on the
 * OpenGL thread, typically in {@link GLSurfaceView.Renderer#onSurfaceCreated(GL10, EGLConfig)}.
 *
 * @param context Needed to access shader source and texture PNG.
 * @param gridDistanceTextureName Name of the PNG file containing the grid texture.
 */
public void createOnGlThread(Context context, String gridDistanceTextureName) throws IOException {
  int vertexShader =
      ShaderUtil.loadGLShader(TAG, context, GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_NAME);
  int passthroughShader =
      ShaderUtil.loadGLShader(TAG, context, GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_NAME);

  planeProgram = GLES20.glCreateProgram();
  GLES20.glAttachShader(planeProgram, vertexShader);
  GLES20.glAttachShader(planeProgram, passthroughShader);
  GLES20.glLinkProgram(planeProgram);
  GLES20.glUseProgram(planeProgram);

  ShaderUtil.checkGLError(TAG, "Program creation");

  // Read the texture.
  Bitmap textureBitmap =
      BitmapFactory.decodeStream(context.getAssets().open(gridDistanceTextureName));

  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  GLES20.glGenTextures(textures.length, textures, 0);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);

  GLES20.glTexParameteri(
      GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR_MIPMAP_LINEAR);
  GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
  GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, textureBitmap, 0);
  GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
  GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

  ShaderUtil.checkGLError(TAG, "Texture loading");

  planeXZPositionAlphaAttribute = GLES20.glGetAttribLocation(planeProgram, "a_XZPositionAlpha");

  planeModelUniform = GLES20.glGetUniformLocation(planeProgram, "u_Model");
  planeNormalUniform = GLES20.glGetUniformLocation(planeProgram, "u_Normal");
  planeModelViewProjectionUniform =
      GLES20.glGetUniformLocation(planeProgram, "u_ModelViewProjection");
  textureUniform = GLES20.glGetUniformLocation(planeProgram, "u_Texture");
  lineColorUniform = GLES20.glGetUniformLocation(planeProgram, "u_lineColor");
  dotColorUniform = GLES20.glGetUniformLocation(planeProgram, "u_dotColor");
  gridControlUniform = GLES20.glGetUniformLocation(planeProgram, "u_gridControl");
  planeUvMatrixUniform = GLES20.glGetUniformLocation(planeProgram, "u_PlaneUvMatrix");

  ShaderUtil.checkGLError(TAG, "Program parameters");
}