Question

EDIT:

Seems the mistake was, that I am not allowed to compile the shader in a seperate thread? Since I've been pushing the object-loading just now into a threaded environment, the error message came up. Just didn't think that it could be the reason for it.


My current vertex shader fails to compile for some reason. The error message I'm getting is not existent, and I can't find the mistake.

uniform mat4 u_MVPMatrix;       
uniform mat4 u_MVMatrix;        
uniform vec3 u_CameraPos;

attribute vec4 a_Position;      
attribute vec4 a_Color;         
attribute vec3 a_Normal;        

varying vec3 v_Position;        
varying vec4 v_Color;           
varying vec3 v_Normal;          
varying vec3 v_CameraPosition;
varying vec4 v_Ambient;         

void main()
{
    v_Position = vec3(u_MVMatrix * a_Position);

    v_Color = a_Color;

    v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0));
    //v_CameraPosition = vec3(u_MVMatrix * vec4(u_CameraPos, 0.0)); // taken out to debug
    v_CameraPosition = u_CameraPos;

    gl_Position = u_MVPMatrix * a_Position;
}

The fragment shader for this one is:

precision mediump float;        

uniform vec3 u_LightPos;        
uniform vec4 u_Light;
uniform vec4 u_Ambient;
uniform vec3 u_LightDirection;
uniform vec3 u_CameraPos;

varying vec4 v_Ambient;        
varying vec3 v_Position;        
varying vec4 v_Color;           
varying vec3 v_Normal;          
varying vec3 v_CameraPosition;

// The entry point for our fragment shader.
void main()
{
    float distance = length(u_LightPos - v_Position);
    vec3 lightVector = normalize(u_LightPos - v_Position);

    float diffuse = max(dot(v_Normal, lightVector), 0.1);

    diffuse = diffuse * (1.0 / (1.0 + (0.25 * distance * distance)));

    // specular lighting removed due to debugging

    gl_FragColor = v_Color * (u_Ambient + (diffuse * u_Light));
}

"Trying" to get an error message:

Log.d(TAG, "Compilation -> " + GLES20.glGetShaderInfoLog(iShader));

Returns an empty string from the method, as well as

Log.e(TAG, "Vertex Shader Failed -> " + GLES20.glGetError());

is returning simply 0.

I am developing for OpenGL ES 2.0 for Android, if there are any restrictions for Android that I am unaware of?

Thank you for any help!

Was it helpful?

Solution

OpenGL contexts work only per-thread so you are correct. If you want to create a background loading thread you need to not only create a new context in that thread, but also make sure it's sharing resources (the third parameter in eglCreateContext). Be aware that sharing context resources might not be work on some (older) devices.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top