gpt4 book ai didi

c++ - glGetUniformLocation OpenGL ES 2.0 (ipad 3 iOS 7.0.3 返回结果错误)

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:23:17 25 4
gpt4 key购买 nike

这是我的顶点着色器:

attribute vec4 a_position;
uniform mat4 u_projection;
uniform vec4 u_origin_translation;
uniform vec4 u_translation;
attribute vec2 a_texCoord;
varying vec2 v_texCoord;
uniform vec4 u_color;
varying vec4 v_color;
attribute vec4 a_color;

void main()
{
vec4 pos = a_position + u_origin_translation + u_translation;
gl_Position = u_projection * pos;
v_texCoord = a_texCoord;
v_color = a_color * u_color;
}

和像素着色器:

precision mediump float;
varying vec2 v_texCoord;
uniform sampler2D s_texture;
varying vec4 v_color;
void main()
{
vec4 texColor = texture2D(s_texture, v_texCoord);
gl_FragColor = texColor * v_color;
}

我尝试在 Marmalade 7.1 平台上的 OpenGL ES 2.0 上下文中渲染带纹理的四边形;

将矩阵数据(投影统一“u_projection”)发送到着色器的源代码:

GLint projectionUniformLocation = glGetUniformLocation(m_ShaderProgram->GetHandle(), m_ShaderProgram->GetProjectionUniformName().c_str());

glUniformMatrix4fv(projectionUniformLocation, 1, 0, &m_Ortho[0]);

我的跟踪代码:

glGetActiveUniform(m_ShaderProgram->GetHandle(), projectionUniformLocation, maxUniformLength, 0, &size, &type, &buffer[0]);

TRACE_OUT("Context::ApplyOrtho: type is matrix " << (type == GL_FLOAT_MAT4));
TRACE_OUT("Context::ApplyOrtho: type is " << type);
TRACE_OUT("Context::ApplyOrtho: buffer is " << &buffer[0]);
TRACE_OUT("Context::ApplyOrtho: projectionUniformLocation is " << projectionUniformLocation);

整个程序在 Windows 模拟器中运行良好。它显示带纹理的四边形,并且通过跟踪我的 projectionUniformLocationGL_FLOAT_MAT4 类型,所以它是正确的。

但是!!!当我在 ipad 3 上运行它时,相同的代码以另一种方式工作。跟踪表明我的 projectionUniformLocation 不是 GL_FLOAT_MAT4,而是 GL_SAMPLER_2D 并且输出缓冲区消息包含“s_texture”! !! 可见结果是没有纹理的黑色四边形

更新:在 Windows 模拟器上 projectionUniformLocation 索引为 3,但在 ipad 上它的索引为 2;

更新 2: 模拟器中的现役制服列表:

Context::PrintActiveUniforms: active is s_texture and it's location is 0
Context::PrintActiveUniforms: active is u_color and it's location is 1
Context::PrintActiveUniforms: active is u_origin_translation and it's location is 2
Context::PrintActiveUniforms: active is u_projection and it's location is 3
Context::PrintActiveUniforms: active is u_translation and it's location is 4

以及来自 ipad 的 list :

Context::PrintActiveUniforms: active is u_origin_translation and it's location is 0
Context::PrintActiveUniforms: active is u_color and it's location is 1
Context::PrintActiveUniforms: active is s_texture and it's location is 7
Context::PrintActiveUniforms: active is u_projection and it's location is 2
Context::PrintActiveUniforms: active is u_translation and it's location is 6

更新 3: 有关 ipad 3 制服的更多信息(Andon M. Coleman 感谢您提供源代码):

eTB_GLSL__print_uniforms: (loc=0) type=vec4 name=u_origin_translation size=1
eTB_GLSL__print_uniforms: (loc=1) type=vec4 name=u_color size=1
eTB_GLSL__print_uniforms: (loc=7) type=sampler2D name=s_texture size=1
eTB_GLSL__print_uniforms: (loc=2) type=mat4 name=u_projection size=1
eTB_GLSL__print_uniforms: (loc=6) type=vec4 name=u_translation size=1

为什么 glGetActiveUniform 说我的 u_projection 不是 mat4,为什么我看不到我的纹理?

有什么想法吗?

最佳答案

幸运的是this问题对我有帮助。我没有在需要看的地方看。两行代码解决了我的问题,纹理出现了:

glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

关于c++ - glGetUniformLocation OpenGL ES 2.0 (ipad 3 iOS 7.0.3 返回结果错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20705470/

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