Browse Source

base: break the main loop apart for the emscripten port.

legacy
Sam Hocevar sam 11 years ago
parent
commit
1093e75006
6 changed files with 49 additions and 19 deletions
  1. +4
    -0
      configure.ac
  2. +36
    -13
      src/application/application.cpp
  3. +1
    -2
      src/application/application.h
  4. +4
    -0
      tutorial/01_triangle.lolfx
  5. +4
    -0
      tutorial/04_texture.lolfx
  6. +0
    -4
      tutorial/11_fractal.lolfx

+ 4
- 0
configure.ac View File

@@ -309,6 +309,10 @@ AC_LANG_POP(C++)
AM_CONDITIONAL(USE_NACL, test "${ac_cv_my_have_nacl}" != "no")


dnl Use Emscripten?
AC_CHECK_HEADERS(emscripten.h)


dnl Use Android? FIXME: super hacks!
ac_cv_my_have_android="no"
AC_CHECK_LIB(log, __android_log_vprint,


+ 36
- 13
src/application/application.cpp View File

@@ -8,26 +8,30 @@
// http://www.wtfpl.net/ for more details.
//

#if defined HAVE_CONFIG_H
#if HAVE_CONFIG_H
# include "config.h"
#endif

#if HAVE_EMSCRIPTEN_H
# include <emscripten.h>
#endif

#include "core.h"

#include "lolgl.h"

#if defined __CELLOS_LV2__
#if __CELLOS_LV2__
# include "platform/ps3/ps3app.h"
#elif defined _XBOX
#elif _XBOX
# include "platform/xbox/xboxapp.h"
#elif defined __native_client__
#elif __native_client__
# include "platform/nacl/nacl-app.h"
#elif defined __ANDROID__
#elif __ANDROID__
# include "platform/android/androidapp.h"
#elif defined USE_SDL
#elif USE_SDL
# include "platform/sdl/sdlapp.h"
# include "platform/sdl/sdlinput.h"
#elif defined HAVE_GLES_2X
#elif HAVE_GLES_2X
# include "eglapp.h"
#endif

@@ -44,17 +48,17 @@ class ApplicationData
: app(name, resolution, framerate)
{ }

#if defined __CELLOS_LV2__
#if __CELLOS_LV2__
Ps3App app;
#elif defined _XBOX
#elif _XBOX
XboxApp app;
#elif defined __native_client__
#elif __native_client__
NaClApp app;
#elif defined __ANDROID__
#elif __ANDROID__
AndroidApp app;
#elif defined USE_SDL
#elif USE_SDL
SdlApp app;
#elif defined HAVE_GLES_2X
#elif HAVE_GLES_2X
/* FIXME: this macro is only deactivated if we include "lolgl.h" */
EglApp app;
#else
@@ -62,6 +66,15 @@ class ApplicationData
#endif
};

#if EMSCRIPTEN
static Application *g_app;

static void AppCallback()
{
g_app->Tick();
}
#endif

/*
* Public Application class
*/
@@ -83,6 +96,16 @@ void Application::Tick()
data->app.Tick();
}

void Application::Run()
{
#if EMSCRIPTEN
emscripten_set_main_loop(AppCallback, 0, 1);
#else
while (MustTick())
Tick();
#endif
}

void Application::ShowPointer(bool show)
{
data->app.ShowPointer(show);


+ 1
- 2
src/application/application.h View File

@@ -29,8 +29,7 @@ public:

bool MustTick();
void Tick();

void Run() { while(MustTick()) Tick(); }
void Run();

void ShowPointer(bool show);



+ 4
- 0
tutorial/01_triangle.lolfx View File

@@ -24,6 +24,10 @@ void main(void)
[frag.glsl]
#version 120

#if defined GL_ES
precision highp float;
#endif

void main(void)
{
gl_FragColor = vec4(0.7, 0.2, 0.5, 1.0);


+ 4
- 0
tutorial/04_texture.lolfx View File

@@ -16,6 +16,10 @@ void main(void)

#version 120

#if defined GL_ES
precision highp float;
#endif

uniform sampler2D u_Texture;

varying vec4 pass_Position;


+ 0
- 4
tutorial/11_fractal.lolfx View File

@@ -2,10 +2,6 @@

#version 120

#if defined GL_ES
precision highp float;
#endif

uniform mat4 u_ZoomSettings;
uniform vec4 u_TexelSize;
uniform vec4 u_ScreenSize;


Loading…
Cancel
Save