Re: [AD] [AL] Some questions about Allegro graphics code. |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
|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?
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).
3) Because _javascript_ lacks threads, I had to write a "thread emulator"
to make sound and timers code work. It simply runs thread's function at
the beginning of each frame, before the main program's function is run.
This means that I can't write endless loops inside thread functions, but
instead I should make them re-entrable in the sense that they should
store their persistent state elsewhere and not in local scope. So I had
to rewrite some functions in this way:
Will this be acceptable if I ever want for my code to be incorporated
into main Allegro codebase, or should I do it in some other way, like
writing separate functions for Emscripten (this will lead to code
duplication, but would make it somewhat easier to read that this
#ifdef-plagued monstroisity)? I've heard rumors that Mozilla wants to
enabled some kind of threading (not WebWorkers) in Emscripten, but I
can't imagine how they are going to do it... Until then, there is no
other way to emulate threaded code.
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |