glGetUniformLocation OpenGL ES 2.0(在ipad 3 iOS 7.0.3上返回错误结果)



这是我的顶点着色器:

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模拟器中运行良好。它显示了有纹理的四边形,从跟踪我的项目来看,UniformLocationGL_FLOAT_MAT4的类型,所以它是正确的。

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

更新:在模拟器projectionUniformLocation中的Windows上,索引为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上市:

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:关于iPad3制服的更多信息(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,为什么我看不到我的纹理

有什么想法吗?

幸运的是,这个问题对我有帮助。两行代码解决了我的问题,纹理出现了:

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

最新更新