Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » OpenGL ES questions

This thread is locked; no one can reply to it. rss feed Print
OpenGL ES questions
Eric Johnson
Member #14,841
January 2013
avatar

I'm just a newbie trying to figure out OpenGL ES 2.0 (for use in WebGL), and I'm hoping you guys could help answer a few of my questions (all shader precision related right now):

1. I've read that all vertex shaders default to high precision, and as such, manually stating the precision is not necessary. Is this true?

2. As for fragment shaders, I've read that high precision is not supported by all devices (particularly mobile devices), and that medium precision should be used instead. Is this true, and if so, is it much of an issue? Even the iPhone 5 supports high precision, and it was released in 2012!

3. I know I can query to see if high precision is supported and use it if so, but realistically, what kind of differences could I expect to see between high, medium, and low? As is, I don't see a difference between them (at least on desktop and on a Samsung Galaxy S7), though I'm just rendering basic triangles right now.

4. Any pointers on what precision I should be using for my vertex and fragment shaders?

Thanks for reading. Any input would be most appreciated. :)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Eric Johnson
Member #14,841
January 2013
avatar

Do you have a working example you could zip up for people to try?

Not at this time. I'm currently just working in a single file, adding and removing functionality as I learn more and play around. I'm drawing textured quads now while experimenting with doing some basic "effects", like color tinting and trying to adjust contrast/exposure of an image (just for fun).

So I did some research, and it looks like high precision is implicit for vertex shaders. So that answers my first question--it's always high and I never have to manually state it (or change it, I think). Why then do vertex shaders have an implicit precision but fragment shaders do not? Why would high be available for vertex shaders but not also fragment shaders on the same hardware? I know the specification doesn't dictate the precision for fragment shaders due to the variability of mobile hardware, but it seems strange that vertex shaders are apparently always set to high on all platforms while fragment shaders have to be explicitly told what to use. But maybe my understanding of how the precision works between the two shaders is flawed...

Should I even worry about the precision of my fragment shaders? I can't tell a difference between them (though maybe I would on a more limited set of hardware). Should I always just default to medium precision and call it a day?

Edit
I guess I don't need to worry about my precision so much. I'll stick with medium.

So I experimented with drawing lots of textured quads today. I can draw about 2000, each with its own random position and tint color, before the frame-rate begins to dip. My GPU usage goes through the roof though. I'm over-saturating the bus. :o I'm using drawArrays() to draw them all. I guess I should try combining all the vertex and texture data, then drawing everything at once with just one draw call (is that what they call "batching"?). It's probably better to draw 2000 things with one call than it is to call drawArrays() 2000 times (each time only drawing one quad), right?

Edit
I did a test with drawing mutable triangles, and sure enough, combining vertex data into one call to drawArrays() yielded a big performance boost over calling drawArrays() for each triangle. Calling drawArrays() for each triangle allowed me to draw ~1100 triangles before the FPS dipped, but the improved version allowed me to draw ~8000 at 60 FPS (~4000 slow version versus ~16000 fast version in Windows; slower in Linux due to poor Nvidia drivers)! So that answers my previous question. :P

I haven't taken a look for myself yet, but does Allegro batch drawing calls behind the scenes? Instancing?

Go to: