4

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?

Edward83
  • 6,664
  • 14
  • 74
  • 102
  • 1
    Have you considered tracing the actual value of `projectionUniformLocation`? You may not have noticed but `glGetActiveUniform (...)` expects a `GLuint` value for the uniform index, but `glGetUniformLocation (...)` returns a signed integer (**-1**) on failure. In the odd event that it is failing, it will return **-1** which if you pass directly to `glGetActiveUniform (...)` will be re-interpreted as `0xffffffff` assuming the system uses 2's complement for signed numbers. – Andon M. Coleman Dec 21 '13 at 04:08
  • I updated my question. projectionUniformLocation is positive value; – Edward83 Dec 23 '13 at 06:55
  • 1
    I have some code in an [answer](http://stackoverflow.com/questions/19894839/opengl-uniform-array-of-structures/19918602#19918602) to another similar question that you may find helpful. It is related to desktop GL, so many of the constants will be undefined but if you comment them out and run that code it should really help clear things up. – Andon M. Coleman Dec 24 '13 at 18:01
  • Andon thank you! I am glad to any help;) – Edward83 Dec 25 '13 at 06:59

1 Answers1

0

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 );
Community
  • 1
  • 1
Edward83
  • 6,664
  • 14
  • 74
  • 102