0

UPDATED I'm trying to draw texture with openGL ES3 and used instanced drawing for my drawing application. This is my vertex shader

#version 300 es
precision highp float;

uniform mat3 u_Matrix;

in vec2 Position;
in vec2 TexPosition;

struct Data {
    vec2 pos;
    vec2 scale;
    uint color;
    float rotation;
};

layout(std140) uniform InstanceData {
    Data data[256];
};

out vec4 v_Color;
out vec2 v_TexPosition;

void main() {
vec2 endPos = Position * data[gl_InstanceID].scale;
if (data[gl_InstanceID].rotation != 0.0) {
    float cos = cos(data[gl_InstanceID].rotation);
    float sin = sin(data[gl_InstanceID].rotation);


    endPos = vec2(endPos.x * cos - endPos.y * sin, endPos.x * sin + 

    endPos.y * cos) + data[gl_InstanceID].pos;
    } else {
        endPos = endPos + data[gl_InstanceID].pos;
    }

    uint fColor = data[gl_InstanceID].color;
    v_Color.r = float((fColor & 0x00FF0000U) >> 16) / 255.0;
    v_Color.g = float((fColor & 0x0000FF00U) >> 8) / 255.0;
    v_Color.b = float(fColor & 0x000000FFU) / 255.0;
    v_Color.a = float((fColor & 0xFF000000U) >> 24) / 255.0;

    v_TexPosition = TexPosition;
    gl_Position = vec4(u_Matrix * vec3(endPos, 1.0), 1.0);
}

and this is my fragment_shader

#version 300 es
precision highp float;

in vec2 v_TexPosition;
in vec4 v_Color;

uniform sampler2D u_Texture2D;

out vec4 fragColor;

void main() {
    vec4 color = texture(u_Texture2D, v_TexPosition);
    fragColor = vec4(v_Color.rgb, color.a * v_Color.a);
}

When I created the program, attached shaders and try to link to program, the app is freezes on line glLinkProgram. Shaders and program have normal id.

This work normal on some devices (sony xperia Z -android 5.0, smasung s7 edge android 7, nexus 5x - android 7, nexus 6p - android 7) but this doesn't work on other part of devices(motX- android 5.1, smasung s5 android 6.0). All devices have android version greater then 5.0, and in code I checked for opengl ES3 supporting.

Is there some reason for this? Is it from device(how to check it)? or did I did something wrong? I'm passed data to instanceBuffer with this way :

instanceBuffer.putFloat(posX);
instanceBuffer.putFloat(posY);
instanceBuffer.putFloat(scaleX);
instanceBuffer.putFloat(scaleY);
instanceBuffer.putInt(colorARGB);
instanceBuffer.putFloat((float) Math.toRadians(rotate));
instanceBuffer.position(instanceBuffer.position() + 8);

used +8 offsets because struct data read elements with vec4 size (16byte)

When I write my struct only with one vec4 :

struct Data {
    vec4 posAndScale;
};

and pass data:

instanceBuffer.putFloat(posX);
instanceBuffer.putFloat(posY);
instanceBuffer.putFloat(scaleX);
instanceBuffer.putFloat(scaleY);

This works on all devices, But when I added one more vec4 :

struct Data {
    vec4 posAndScale;
    vec4 color;
};

and pass data

instanceBuffer.putFloat(posX);
instanceBuffer.putFloat(posY);
instanceBuffer.putFloat(scaleX);
instanceBuffer.putFloat(scaleY);
instanceBuffer.putFloat(color.r);
instanceBuffer.putFloat(color.g);
instanceBuffer.putFloat(color.b);
instanceBuffer.putFloat(color.a);

app not freezes but nothing happened when I try to draw. It's seems like on some devices std140 work with different way or like data not passed to shader when wrote struct with 2 vec4-s

Levon Vardanyan
  • 400
  • 4
  • 16
  • Is there a space before #version ? It can cause error on some devices... – andras May 02 '17 at 15:06
  • No, there are no any redundant spaces somewhere – Levon Vardanyan May 02 '17 at 15:20
  • What is actually hanging? You mention both glLinkProgram, but also instanceBuffer.putFloat, but presumably your app shouldn't even get as far as instanceBuffer.putFloat if the program failed to link ... – solidpixel May 03 '17 at 14:01
  • @solidpixel you are right, if app freezes on glLinkProgram app does not get to instanceBuffer.putFloat. But when I removed float and uint from struct it get to instnaceBuffer putting. – Levon Vardanyan May 04 '17 at 08:49
  • The linker hang just looks like a bug in the driver; drivers should never just hang like this ... – solidpixel May 04 '17 at 12:09

2 Answers2

0

Ok I found some solution. This work normally since opengl es versionl 3.1. I think 3.0 version doesn't support struct data which contains float or int element.

Levon Vardanyan
  • 400
  • 4
  • 16
  • A freez on linking indicates the usage of an opengl object that was not successfully created or is in an _invalid_ state. Did you check for compilation and other errors for all of the objects you created? – t.niese May 03 '17 at 16:56
  • Yes I checked, there are no any errors, its get to glLinkProgram line normal and no errors. – Levon Vardanyan May 04 '17 at 08:52
0

I experienced the same issue. The Nexus 7 (2013) was freezing when I called gllinkprogram(). I found that this only happened when I had 'if statements' in my shader. I was able to change both of my 'if statements' into 'conditional operators' and it worked.

E.g. (cond)? cond1:cond2

android
  • 173
  • 1
  • 8