gpt4 book ai didi

android - OpenGL、Android 和 Galaxy S3

转载 作者:行者123 更新时间:2023-11-29 21:12:30 26 4
gpt4 key购买 nike

我正在使用 GLSurfaceView 在我的 Galaxy Note 3 上显示相机图像。我使用 fragment 着色器渲染具有不同效果的相机图像。这在 Galaxy S4 和 Note 3 上运行良好,但在 Galaxy S3 上会出现问题。

我收到以下错误消息:

03-13 13:16:30.971 E/OpenGLTools( 9275): Could not compile shader 35632:
03-13 13:16:30.971 E/OpenGLTools( 9275): 0:117: S0001: Type mismatch in arithmetic operation between 'vec3' and 'vec4'

这是我的 fragment 着色器:

#extension GL_OES_EGL_image_external : require
precision mediump float;
uniform samplerExternalOES sTexture;
varying vec2 vTextureCoord;

void main() {
vec3 color = texture2D(sTexture, vTextureCoord).rgb;

float gray = dot(color, vec3(0.299, 0.587, 0.114));
color = vec3(gray);

gl_FragColor = vec4(color, 1.0);
}

这是顶点着色器:

uniform mat4 uMVPMatrix;
uniform mat4 uTexMatrix;
attribute vec4 aPosition;
attribute vec4 aTextureCoord;
varying vec2 vTextureCoord;

void main() {
gl_Position = uMVPMatrix * aPosition;
vTextureCoord = (uTexMatrix * aTextureCoord).xy;

}

有人可以解释一下如何解决这个错误吗?我认为当我尝试设置 gl_FragColor 时会出现问题,但我认为这始终是 vec4

最佳答案

这在不同的移动 GLSL 实现之间更具可移植性:

void main()
{
vec4 color = texture2D(sTexture, vTextureCoord);
float gray = dot( color, vec4(0.299, 0.587, 0.114, 0.0) );
gl_FragColor = vec4(gray, gray, gray, 1.0);
}

一般来说,尽量从代码中省略隐式转换。

关于android - OpenGL、Android 和 Galaxy S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22381965/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com