Author Topic: OpenGL ES2 and Linux and pi - now with patches!  (Read 35469 times)

0 Members and 1 Guest are viewing this topic.

Re: OpenGL ES2 and Linux (and pi)
More stuff from profiling: rendering text in the HUD is pretty expensive.  Not surprising since it uses Begin/End...

It doesn't really dominate the CPU load of rendering each frame, but it does show up pretty well despite the sheer inefficiency of the main rendering path.

 

Offline Tomo

  • 28
Re: OpenGL ES2 and Linux (and pi)
Slightly off-topic:

I need to learn OpenGL and OpenGLES. Where do you suggest I go for a good tutorial?

(My primary framework is Qt, which has some modern tutorials but they don't go into much detail and most of the other ones I've seen are the old glBegin/end style.)

 
Re: OpenGL ES2 and Linux (and pi)
Well, I stopped reading tutorials after a while and started reading specs.

But you need to know what specs to read and what concepts to have in mind first.  For that, I suggest this: http://www.learnopengles.com/android-lesson-one-getting-started/

That tutorial targets Android and OpenGL ES2.  Most of the code is in Java and there are some Android-specific parts to it.  If you are developing on another platform (eg. plain Linux, or Windows) then you will need to look up how to do several things, such as obtain a GLES2 context and manipulate matrices, on your particular platform.  However, all of the concepts, actual GL calls and GLSL code should be portable.  Most of them also port neatly to modern versions of desktop OpenGL.

You might also find the Khronos reference cards useful, eg. http://www.khronos.org/opengles/sdk/docs/reference_cards/OpenGL-ES-2_0-Reference-card.pdf  These reference cards have references back to sections of the full spec document.

ETA: http://www.g-truc.net/project-0026.html#menu is also a good set of examples, albeit with minimum explanation.  Download the latest one, sort by name and start from the top.
« Last Edit: March 10, 2012, 07:20:27 am by Kromaatikse »

 
Re: OpenGL ES2 and Linux (and pi)
Okay, first patch that I'm happy with, dealing with just the MVE cutscene player.  This is essentially a blueprint for all the other Begin/End elimination.

The patch actually does several related things at once:

1) Converts an instance of Begin/End to a vertex array call.

2) Moves the vertex array setup to a setup function, and the teardown to a teardown function.  (These already existed, conveniently.)

3) Converts the QUADS format into TRIANGLE_STRIP format, since QUADS and QUAD_STRIP are unavailable in ES or GL3 Core.  For a single quad like this, just swap the last two vertices.  For multiple quads that are not already in a strip, more effort is required.

4) Removes a use of fl2i(), replacing it with a rounding function.  This function might possibly be missing on Windows, in which case it can be implemented with ceilf(X - 0.5f) or floorf(X + 0.5f).

[attachment deleted by a ninja]

 
Re: OpenGL ES2 and Linux (and pi)
Second patch, doing essentially the same thing to the Ogg cutscene player.  Most of the intervening time was spent waiting for the FSO installer to download everything so that I could test it.


[attachment deleted by a ninja]

 

Offline sigtau

  • 29
  • unfortunate technical art assclown
Re: OpenGL ES2 and Linux (and pi)
Forgive me if this was covered in the initial post, but what kind of performance increases would this entail?  More importantly, what kind of new features would be possible if we switch to ES or GL3?
Who uses forum signatures anymore?

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: OpenGL ES2 and Linux (and pi)
sigtau, I don't know if we'd know until it's done, but if the state manager can be improved as much as it sounds, I'm guessing a very substantial increase.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 
Re: OpenGL ES2 and Linux (and pi)
I can't give hard numbers for performance improvements, partly because it will vary wildly by what machine you have.  I have however seen comments that "it should be faster than this", and this would be a definite step in that direction.  The initial step of excising the Begin/End paradigm - made obsolete by GL 1.1 for crying out loud - will not have any compatibility effects - this is pure win.

Of course, the patches I've already done and posted will have zero measurable performance impact.  They apply to a part of the code that is not performance limited at all.  There are other, more important reasons for dealing with it though.

Looking at my profile with retail data, I see that roughly all of the functions that use glBegin/glEnd are called at least once per frame and usually a lot more than that.  This corresponds to many many unnecessary GL API calls per frame.  Each GL API call is in itself an overhead that it is wise to avoid.

The "new features" that we should expect are compatibility with newer and more interesting platforms.  For example, MacOS X will not add support for new GL features to the "compatibility profile" implementation it supports.  New features will therefore appear only in the "core profile" implementation.  Therefore in order for the Mac port to keep up with other platforms in terms of rendering features, the whole engine has to be made compatible with Core Profile, which happily is also a long way towards GLES2 compatibility.

And, of course, OpenGL ES2 support opens up non-x86-based Linux platforms, particularly the Raspberry Pi that I'm planning to target once the cleanup operation is done.  ARM based platforms generally don't come with PC-type graphics cards, and therefore don't see any need to support "legacy" OpenGL since it doesn't provide any features that mobile games and navigation apps can't easily do without.  An, if they *do* eventually move on, it will likely be to GL3 Core Profile, not back to legacy GL.

The later stages of the conversion have the *potential* to cause compatibility problems with older GL versions, specifically pre-2.0.  I think that this can be dealt with by the new state manager I proposed - by knowing what sort of rendering is to be done, it can adapt to shader mode (using Core Profile compatible calls exclusively) or fixed-function mode (using legacy calls exclusively).  The rest of the rendering code would then be decoupled from that decision to the extent possible - obviously some effects are not available without shaders.
« Last Edit: March 11, 2012, 02:18:12 pm by Kromaatikse »

 
Re: OpenGL ES2 and Linux (and pi)
Okay, here's patch 3 with conversion of three heavily-used functions in opengldraw.cpp.  I've tested this briefly, it could do with more even though it's ObviouslyCorrect (tm).

There is more state manipulation than I really like going on here, and that accounts for some of the code expansion, but that will be cleaned up when the state manager goes in.

[attachment deleted by a ninja]

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: OpenGL ES2 and Linux and pi - now with patches!
Code: [Select]
mveplayer.cpp
..\..\code\cutscene\mveplayer.cpp(483) : error C3861: 'roundf': identifier not found
..\..\code\cutscene\mveplayer.cpp(484) : error C3861: 'roundf': identifier not found
..\..\code\cutscene\mveplayer.cpp(487) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
..\..\code\cutscene\mveplayer.cpp(488) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
..\..\code\cutscene\mveplayer.cpp(615) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
..\..\code\cutscene\mveplayer.cpp(615) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
..\..\code\graphics\gropengldraw.cpp(512) : warning C4244: '=' : conversion from 'int' to 'GLfloat', possible loss of data
..\..\code\graphics\gropengldraw.cpp(513) : warning C4244: '=' : conversion from 'int' to 'GLfloat', possible loss of data
..\..\code\graphics\gropengldraw.cpp(517) : warning C4244: '=' : conversion from 'int' to 'GLfloat', possible loss of data
..\..\code\graphics\gropengldraw.cpp(518) : warning C4244: '=' : conversion from 'int' to 'GLfloat', possible loss of data
..\..\code\graphics\gropengldraw.cpp(522) : warning C4244: '=' : conversion from 'int' to 'GLfloat', possible loss of data
..\..\code\graphics\gropengldraw.cpp(523) : warning C4244: '=' : conversion from 'int' to 'GLfloat', possible loss of data
..\..\code\graphics\gropengldraw.cpp(530) : warning C4244: '=' : conversion from 'int' to 'GLfloat', possible loss of data
..\..\code\graphics\gropengldraw.cpp(531) : warning C4244: '=' : conversion from 'int' to 'GLfloat', possible loss of data
..\..\code\graphics\gropengldraw.cpp(946) : error C2057: expected constant expression
..\..\code\graphics\gropengldraw.cpp(946) : error C2466: cannot allocate an array of constant size 0
..\..\code\graphics\gropengldraw.cpp(946) : error C2133: 'vertPos' : unknown size
..\..\code\graphics\gropengldraw.cpp(947) : error C2057: expected constant expression
..\..\code\graphics\gropengldraw.cpp(947) : error C2466: cannot allocate an array of constant size 0
..\..\code\graphics\gropengldraw.cpp(947) : error C2133: 'vertCol' : unknown size
..\..\code\graphics\gropengldraw.cpp(1043) : error C3861: 'glClientActiveTexture': identifier not found
..\..\code\graphics\gropengldraw.cpp(1047) : error C3861: 'glClientActiveTexture': identifier not found
..\..\code\graphics\gropengldraw.cpp(1062) : error C3861: 'glClientActiveTexture': identifier not found

In addition to your anticipated roundf incompatibility on Windows, which we can probably handle with a macro or something, I also got some other errors, attempting to compile all three patches at one time on VS 2008.  The rest were in the last patch it looks like.  Some of those warnings might have already been there.  I applied the patches to Antipodes, as it's what I've been testing with the most lately.  They applied cleanly.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 
Re: OpenGL ES2 and Linux and pi - now with patches!
Ugh, looks like your compiler doesn't have support for variable-sized local arrays.  I thought those were well supported by now - but then again, roundf() is also a C99 standard function, which means that Windows is already a decade out of date in that respect.

I'll have a look at another way of doing it later.

 
Re: OpenGL ES2 and Linux and pi - now with patches!
Right, it seems I forgot that there are syntax features in C99 but not C++, as well as library features. VLAs are one of those, but g++ accepts a union of C99 and C++ features by default. Visual Studio does not support C99 at all except for a few isolated features.

To avoid such problems in future, I suggest adding -ansi to the g++ command options.

 

Offline Echelon9

  • 210
Re: OpenGL ES2 and Linux (and pi)
Okay, here's patch 3 with conversion of three heavily-used functions in opengldraw.cpp.  I've tested this briefly, it could do with more even though it's ObviouslyCorrect (tm).

There is more state manipulation than I really like going on here, and that accounts for some of the code expansion, but that will be cleaned up when the state manager goes in.
Compiles cleanly here on LLVM 3.1 (Xcode 4.3.1, OS 10.7)

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: OpenGL ES2 and Linux and pi - now with patches!
Ugh, looks like your compiler doesn't have support for variable-sized local arrays.  I thought those were well supported by now - but then again, roundf() is also a C99 standard function, which means that Windows is already a decade out of date in that respect.

I'll have a look at another way of doing it later.

How about using C++, have you thought of that?
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: OpenGL ES2 and Linux and pi - now with patches!
Yeah, there's some rules we are still going to have to follow.  Windows is still our primary platform, as most of the tools are on it only still, if nothing else.  FRED has to be compiled with the MFCs included with Visual Studio for the time being, so switching to another compiler on Windows isn't likely any time soon.  It's also a rather good IDE, aside from its falling C standards supports.   But the C++0x support is pretty good in 2010, although we do still try to support all the way back to VC6.  So if this is possible sticking to older features of C/C++, it'll probably make everyone's lives easier if nothing else.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 
Re: OpenGL ES2 and Linux and pi - now with patches!
Well, this sucks.  Bear in mind however that as far as G++ is concerned, VLAs *are* part of (extended) C++, and really should not be difficult to implement since they are mostly syntactic sugar for alloca().

Forgive me for not being intimately familiar with Visual Studio's failings.  I very rarely write anything for Windows, and when I do I use MinGW for maximum familiarity.

Using std::vector would unfortunately involve at least one malloc/free pair behind the scenes.  This is really not as efficient as I would like.  Therefore I have *not* used the canonical C++ way of doing this.

Instead I converted the code to explicitly use alloca() - which is internally just stack pointer manipulation and thus guaranteed to be fast.  The result looks ugly in source (due to having to specify the type multiple times) but should be pretty clean in machine code.

Revised patch attached.

[attachment deleted by a ninja]

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: OpenGL ES2 and Linux and pi - now with patches!
Tried this one on VC6.  Only issue there seems to be that alloca() isn't supported on that compiler.  As far as I can tell, it's not part of any standard, ANSI or otherwise.  This may not have to be a concern, we'll see.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: OpenGL ES2 and Linux and pi - now with patches!
Works fine on 2008 though.  But can we get some explicit casts to get rid of some of those warnings?

As far as VLAs vs alloca vs std::vector, from what I've read, VLAs should only be used for small data allocations, and if it is going to be small, why not make it static?  And if it's going to be larger, are we sure that stack allocation vs heap is the best idea?

I switched the roundf() calls to ceil(X - 0.5f) and all worked fine with the mveplayer patch too.  Think roundf is any faster in machine code than the ceil() call, or would it make sense in this case to just replace it with the more available call?  We could macro it if the benefit would be worth it.
« Last Edit: March 12, 2012, 10:45:47 pm by chief1983 »
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 
Re: OpenGL ES2 and Linux and pi - now with patches!
The conversion warnings don't show up at all on G++.  I'll have to dig deeper to try and match the warnings it can produce with what your compiler does.

Meanwhile I'm dealing with a MBP battery that just started bulging.  Fun fun fun. :ick:

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: OpenGL ES2 and Linux and pi - now with patches!
I might try to see if I can fix the warnings with casts on my end and come up with an updated patch or something, if I have time.  Really busy couple of weeks coming up though.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays