[Replying to the alleg-developers list, not sure alleg-main is still active]
On Thu, Apr 17, 2014 at 8:27 AM, MaxEd <max.savenkov@xxxxxxxxxx
<mailto:max.savenkov@xxxxxxxxxx>> wrote:
|As some of you may know from forums, I've been working on making
Allegro work in browser by compiling it to JavaScript with Emscripten. I
had some success and got Skater demo running, but there are a few things
in Allegro code that I had to prop up with crutches to make this work,
and I lack deeper knowledge about Allegro/OpenGL to fix them. So, if I
would be very grateful if someone could enlighten me on the following
points:
1) Default shader: when I look at the code for al_create_display, I see
that we first create backbuffer, then set it as target bitmap, and only
after it create default shader. This seems strange to me, because in the
end, we get backbuffer without attached shader (a shader is attached to
bitmap in set_target_bitmap). Because of this, graphics do not work at
all in browser, unless I call al_set_target_bitmap( al_get_backbuffer(
pDisplay) ); manually after creating display. Am I missing something
here? I do not understand why does this works on other platforms. The
only clue I have is that WebGL (browser's subset of OpenGL ES2) do not
support anything but programmable pipeline, so maybe it's the only
platform that REQUIRES backbuffer to have a shader? In that case, what
would be a proper fix to make Allegro set shader for backbuffer when
compiling with Emscripten?
Creation of the shaders was introduced in this patch by SiegeLord:
http://sourceforge.net/p/alleg/allegro/ci/db20612ef1132d18b36450ddd05a803cc519e1a0/#diff-9
I assume he simply forgot to add a call to al_use_shader. So yes, this
needs to be fixed on all platforms. (Originally shaders were only an
addon and al_create_display would not create them at all but the user did.)
2) As I mentioned above, WebGL is a subset of OpenGL ES 2 that only
supports programmable pipeline. It does not even HAVE fixed pipeline
functions, they are all missing symbols. Also, it does not support
drawing graphics via vertex arrays, only VBOs. Allegro, however, do not
use VBOs in OpenGL ES branch of code, even when programmable pipeline
(meaning ES2) is enabled. Fortunately, Emscripten provides emulation for
ES2 features missing from WebGL, so I can compile and run Allegro-based
programs. Unfortunately, that emulation comes with a performance
penalty. I do not have enough experience with OpenGL to write a new
branch of code specifically for Emscripten/WebGL with VBOs, and what's
more, I don't really want to make ogl_flush_vertex_cache any more
complex... So I am looking for an advice on what to do here (simple
using desktop OpenGL's branch does not work too).
The same is true for all OpenGL ES 2 ports, i.e. also Android and IOS
(except those also have ES1 versions). I seem to remember adding VBOs
myself at some point for ES2 - but I don't remember if that was ever
committed or maybe reverted again.