Opengles 2 GOTCHA

B5262118b588a5a420230bfbef4a2cdf
1
Stainless 151 May 03, 2013 at 07:45 opengl-es

Was testing my new OpenGLES 2 renderer yesterday, and it completely failed on some devices.

It worked perfectly on everything except Samsung phones and Broadcom set top boxes.

On those devices it displayed nothing. No errors. No exceptions. Just a black screen.

After a lot of playing around I finally tracked down the problem to my shader class.

//create the shader program
program = glCreateProgram();

//attach the fragment and vertex shaders to it
glAttachShader(program, vertShaderId);
glAttachShader(program, fragShaderId);

Link();


glBindAttribLocation(program, 0, "a_v4_vertex");
glBindAttribLocation(program, 1, "a_v4_normal");
glBindAttribLocation(program, 2, "a_v2_texcord");
glUniform1i(sampler_location, 0);

The issue turned out to be linking before binding the attributes, changing the above code to this.

//create the shader program
program = glCreateProgram();

//attach the fragment and vertex shaders to it
glAttachShader(program, vertShaderId);
glAttachShader(program, fragShaderId);


glBindAttribLocation(program, 0, "a_v4_vertex");
glBindAttribLocation(program, 1, "a_v4_normal");
glBindAttribLocation(program, 2, "a_v2_texcord");
glUniform1i(sampler_location, 0);


Link();

Solved the problem. It now runs at 60Hz on all devices, and looks awesome at 1920 by 1080 on the Broadcom box.

It was such a bitch to find that I thought it would be a good idea to post it here.

4169732\_orig.png

7 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 May 03, 2013 at 16:17

Just curious, do you check OpenGL errors in your init code? Did they return anything interesting? One would hope the driver would let you know somehow if you try to bind after linking and it doesn’t support that…very sad if it does not. :(

3c5be51fdeec526e1f232d6b68cc0954
0
Sol_HSA 119 May 03, 2013 at 17:49

That’s… odd. Sounds like overly-aggressive shader compiler optimization. (“you’re not using these? okay, I’ll just throw them away then..)

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 May 07, 2013 at 08:01

The glGetError() returned invalid enum all the time, even when it ran.

Of no use in working out what was going on.

I also had a few errors in my shaders where I had 1and 0 instead of 1.0 and 0.0

These compiled on some platforms and failed on others. That is in the spec though, so I should have known about it.

3c5be51fdeec526e1f232d6b68cc0954
0
Sol_HSA 119 May 07, 2013 at 08:14

There’s some situations in GLES where error reporting doesn’t make sense.. you request something at time A, and it’s acted upon on time B, at which point it fails, and the API doesn’t really let the driver to tell the software anything sensible. Those situations are pretty rare, though…

Just saying, while I think those drivers are broken, sometimes it’s not so easy being a driver developer, either =)

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 May 07, 2013 at 09:19

Yes, it’s a pain.

I’m just downloading new drivers for my laptop to (hopefully) solve a different problem.

I cannot use a texture cube and a 2D texture in the same texture. Cannot see anything wrong with the code. Disabling the 2D texture let’s the texture cube work, disabling the texture cube let’s the 2D texture work. They are on different texture units and I’ve had the code checked on a different machine. On the other machine it looks like the shader works (though I have the blending equation wrong).

It’s fun at the moment… :(

6837d514b487de395be51432d9cdd078
0
TheNut 179 May 07, 2013 at 13:32

It might be that you’re binding a specific index to the attributes rather than getting the assigned index after linking (which is what I do). I’m not sure how drivers handle these indices internally (I would assume a table of some sort), but it could be a driver issue in that it doesn’t update its table when you request it to. Perhaps it was their choice of memory management that lead to that decision. A quick look at the spec does not list any such rule how to handle this scenario, so that leaves the implementation decision up to the vendor.

What is your GPU? Intel is notorious for providing subpar opengl drivers.

As for the texture issue, are you setting the sampler uniform value, then calling glActiveTexture(…), and finally binding the texture? If so, then it’s likely another driver issue. Although I think you meant to say using a cube texture and 2d texture in the same shader, since using them in the same texture sounds weird :)

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 May 07, 2013 at 13:44

It was a driver issue, the new drivers work fine and I get my nice subtle reflections in the glass.

Now I’m going to add ambient occlusion, though I’m going to have to pre-calculate everything as I cannot be sure to have render to texture available on all devices.