This is my vertex shader:

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;
}

And pixel shader:

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;
}

I trying to render textured quad within OpenGL ES 2.0 context on Marmalade 7.1 platform;

Source code of sending matrix data (projection uniform "u_projection") into shader:

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

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

My tracing code:

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);

Entire program works well in simulator on Windows. It shows textured quad and from tracing my projectionUniformLocation is type of GL_FLOAT_MAT4 so it is right.

BUT!!! When I run it on ipad 3 the same code works by another way. Tracing says that my projectionUniformLocation is NOT GL_FLOAT_MAT4, but it is GL_SAMPLER_2D and output buffer message contains "s_texture"!!! Visible result is black quad without texture.

Update: On Windows in simulator projectionUniformLocation index is 3, but on ipad it's index is 2;

Update2: Listing of active uniforms from simulator:

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

and listing from 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

Update3: More information about uniforms on ipad 3 (Andon M. Coleman thank you for source code):

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

Why glGetActiveUniform says that my u_projection is not mat4 and why I do not see my texture?

Any ideas?

有帮助吗?

解决方案

Fortunately this question helps me. I was not looking where it was necessary to look. Two lines of code solve my problem and texture appears:

glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top