Android GLES20.glBlendEquation not working?

旧巷老猫 提交于 2019-12-01 18:26:27

问题


Ive been trying to make a 2.5D engine with depth and normal map textures for a few weeks now, not unlike whats used here Linky. After thinking the drawing of a depth map in the fragment shader from a texture was impossible due to ES 2.0 missing the gl_fragDepth variable I found a tutorial for iOS where they used glBlendEquation with the mode GL_MIN/GL_MAX to "fake" depth buffering of the fragment to a framebuffer-texture Linky. Unfortunely GLES20.glBlendEquation makes the application crash on both my phones (SGS 1/2) with UnsupportedOperationException. So Im wondering if anyone has used this function to any success? GL_MIN/GL_MAX also seems to be missing from the Android Opengl ES 2.0 spec so Im probably out of luck here... Any ideas?

BTW It does seem to work in GL11Ext but since Im using the fragment shader for normal mapping this wont work from me.


回答1:


i was experimenting on my Vega tablet (Tegra) and this worked for me:

fragment shader:

#extension GL_NV_shader_framebuffer_fetch : require 
// makes gl_LastFragColor accessible

precision highp float;

varying vec2 v_texcoord;

uniform sampler2D n_sampler;

void main()
{
    vec4 v_tex = texture2D(n_sampler, v_texcoord);
    gl_FragColor = min(gl_LastFragColor, v_tex); // MIN blending
}

Pretty easy, huh? But i'm afraid this will be NV-only.



来源:https://stackoverflow.com/questions/7841763/android-gles20-glblendequation-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!