不glClear添加剂勾兑 [英] Additive blending without glClear

查看:177
本文介绍了不glClear添加剂勾兑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的摄像头preVIEW的表面纹理绑定到我的OpenGL上下文添加剂调合而成。

我越来越古怪渲染纹理时启用混合(20嘈杂的广场越来越呈现),如果我叫GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); preVIEW是正确的,但我失去了我的添加剂调合而成,因为我已经清除缓冲区!

使用glClear电话

不glClear电话

我不知道什么问题,我是新手的OpenGL-ES,有什么建​​议? 如果需要任何一张code,我可以提供更好的理解这个问题。

把相关的code只。请为code。如果有必要的任何其他部分。

 公共无效onSurfaceCreated(GL10未使用的,EGLConfig配置){

//编译着色器,链接程序....等不再赘述

//使添加剂调合
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_ONE,GLES20.GL_ONE);
GLES20.glBlendEquation(GLES30.GL_MAX);
}

公共无效onDrawFrame(GL10未使用){
//不想这样做,但如果我做preVIEW是正常的,但我失去了我的混合
//GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
surfaceTexture.updateTexImage();
    GLES20.glUseProgram(_onscreenShader);

    INT第= GLES20.glGetUniformLocation(_onscreenShadersTexture);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,_rawVideoTexture);
    GLES20.glUniform1i(日,0);
    GLES20.glVertexAttribPointer(_onscreenPositionAttribute,2,GLES20.GL_FLOAT,假,4 * 2,pVertex);
    GLES20.glVertexAttribPointer(_onscreenUVAttribute,2,GLES20.GL_FLOAT,假,4 * 2,pTexCoord);
    GLES20.glEnableVertexAttribArray(_onscreenPositionAttribute);
    GLES20.glEnableVertexAttribArray(_onscreenUVAttribute);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP,0,4);
}
 

解决方案

大多数Android设备有PowerVR的,马里,为Adreno或Vivante的GPU核心里面全是延期,瓷砖为基础的渲染器。这种架构需要glClear操作在每帧时清除内部三角形分级队列以及帧缓冲器告诉OpenGL ES的驱动的开始。如果你不这样做的glClear,这种缓存设计不能正常工作,你会得到奇怪的结果,这将不同于一个GPU类型到另一个。所以,你真的必须这样做glClear。

I want to do additive blending on camera preview's surface texture binded to my opengl context.

I am getting weirdly rendered texture when i enable blending(20 noisy squares getting rendered), if I call GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); preview is proper but i lose my additive blending as i have cleared the buffer!

With glClear call

Without glClear call

I have no clue whats the problem is, i am newbie to opengl-es, Any suggestions? If any piece of code is needed i can provide to better understand the issue.

putting relevant code only. Ask for any other part of code if necessary.

public void onSurfaceCreated(GL10 unused, EGLConfig config) {

//compile shader, link program.... etc omitted for brevity 

//enable additive blending
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE);
GLES20.glBlendEquation(GLES30.GL_MAX);
}

public void onDrawFrame(GL10 unused) {
// Do not want to do this, but if i do preview is normal but i lose my blending
//GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);    
surfaceTexture.updateTexImage();
    GLES20.glUseProgram(_onscreenShader); 

    int th = GLES20.glGetUniformLocation(_onscreenShader, "sTexture");
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, _rawVideoTexture); 
    GLES20.glUniform1i(th, 0);
    GLES20.glVertexAttribPointer(_onscreenPositionAttribute, 2, GLES20.GL_FLOAT, false, 4 * 2, pVertex);
    GLES20.glVertexAttribPointer(_onscreenUVAttribute, 2, GLES20.GL_FLOAT, false, 4 * 2, pTexCoord);
    GLES20.glEnableVertexAttribArray(_onscreenPositionAttribute);
    GLES20.glEnableVertexAttribArray(_onscreenUVAttribute);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); 
}

解决方案

Most Android devices have a PowerVR, Mali, Adreno or Vivante GPU core which are all deferred, tiled-based renderers. This architecture requires the glClear operation at the start of each frame to tell the OpenGL ES driver when to clear internal triangle binning queues as well as the frame buffer. If you don't do the glClear, this caching design does not work properly and you will get weird results that will differ from one GPU type to another. So, you really must do the glClear.

这篇关于不glClear添加剂勾兑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆