From 2edb8115e69ff19bd4dde4b82c22c9630c1c94e7 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 21 Nov 2011 00:49:47 +0000 Subject: [PATCH] core: port all code to NativeClient. Nothing runs for now, but it builds. --- .gitignore | 1 + build-nacl | 10 ++++ build/lol-build | 7 +++ configure.ac | 4 ++ src/Makefile.am | 6 ++- src/application/application.cpp | 4 ++ src/debug/quad.cpp | 36 +++++++-------- src/platform/nacl/naclapp.cpp | 82 +++++++++++++++++++++++++++++++++ src/platform/nacl/naclapp.h | 42 +++++++++++++++++ src/real.h | 3 ++ src/timer.cpp | 10 ++-- test/benchmark/trig.cpp | 8 ++-- test/tutorial/tut03.cpp | 4 ++ 13 files changed, 189 insertions(+), 28 deletions(-) create mode 100755 build-nacl create mode 100644 src/platform/nacl/naclapp.cpp create mode 100644 src/platform/nacl/naclapp.h diff --git a/.gitignore b/.gitignore index 792eb45f..272b48b6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *.exe *.elf *.self +*.nexe *.userprefs *.usertasks *.pidb diff --git a/build-nacl b/build-nacl new file mode 100755 index 00000000..647a444c --- /dev/null +++ b/build-nacl @@ -0,0 +1,10 @@ +#!/bin/sh + +# This can't hurt +make distclean + +set -e +./build/lol-build bootstrap nacl-amd64 +./build/lol-build configure nacl-amd64 +./build/lol-build build nacl-amd64 + diff --git a/build/lol-build b/build/lol-build index 15f6062f..046104f6 100755 --- a/build/lol-build +++ b/build/lol-build @@ -15,6 +15,7 @@ # And is one of: # - linux-i386 # - linux-amd64 +# - nacl-amd64 # - ios-arm # - osx-amd64 # - android-arm @@ -118,6 +119,10 @@ configure() cd monsterz/android android update project --path . ;; + nacl-amd64) + # no need for "-u _ZN2pp12CreateModuleEv" but it could be helpful + ./configure CXX=x86_64-nacl-g++ CC=x86_64-nacl-gcc ac_cv_exeext=.nexe --host=none LOL_LIBS="-lppapi -lppapi_gles2 -lppapi_cpp" + ;; ps3-ppu) PATH="$PATH" ./configure CXX=ppu-lv2-g++ CC=ppu-lv2-gcc ac_cv_exeext=.elf --host=none ;; @@ -178,6 +183,8 @@ check() ;; ps3-ppu) ;; + nacl-*) + ;; windows-i386) # If neither $MSYSTEM or $DISPLAY are set, and xvfb-run # exists, use it to run the test suite. diff --git a/configure.ac b/configure.ac index ba2e44a8..9bbd7472 100644 --- a/configure.ac +++ b/configure.ac @@ -128,6 +128,9 @@ PKG_CHECK_MODULES(GLES2, glesv2, GL_CFLAGS="${GL_CFLAGS} ${GLES2_CFLAGS}" GL_LIBS="${GL_LIBS} ${GLES2_LIBS}"], [:]) +AC_CHECK_HEADER(GLES2/gl2.h, + [AC_DEFINE(HAVE_GLES_2X, 1, Define to 1 if GLES 2.x is available) + ac_cv_my_have_gl="yes"]) PKG_CHECK_MODULES(GL, gl, [ac_cv_my_have_gl="yes" @@ -152,6 +155,7 @@ AC_CHECK_HEADER(GL/gl.h, LIBS="$LIBS_save"]) AC_CHECK_HEADER(PSGL/psgl.h, [ac_cv_my_have_gl="yes"]) + if test "${ac_cv_my_have_gl}" = "no"; then AC_MSG_ERROR([[No OpenGL or OpenGL ES implementation found]]) fi diff --git a/src/Makefile.am b/src/Makefile.am index 9de31693..81bc9f31 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,7 @@ liblol_a_SOURCES = \ eglapp.cpp eglapp.h \ \ $(ps3_sources) \ + $(nacl_sources) \ $(sdl_sources) \ \ shader/shader.cpp shader/shader.h \ @@ -38,10 +39,13 @@ liblol_a_SOURCES = \ debug/quad.cpp debug/quad.h liblol_a_CPPFLAGS = @LOL_CFLAGS@ -sdl_sources = \ +sdl_sources = \ platform/sdl/sdlapp.cpp platform/sdl/sdlapp.h \ platform/sdl/sdlinput.cpp platform/sdl/sdlinput.h +nacl_sources = \ + platform/nacl/naclapp.cpp platform/nacl/naclapp.h + if HAVE_PS3 ps3_sources = \ platform/ps3/ps3app.cpp platform/ps3/ps3app.h \ diff --git a/src/application/application.cpp b/src/application/application.cpp index 55589458..cbb59346 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -17,6 +17,8 @@ #if defined __CELLOS_LV2__ # include "platform/ps3/ps3app.h" +#elif defined __native_client__ +# include "platform/nacl/naclapp.h" #elif defined HAVE_GLES_2X # include "eglapp.h" #else @@ -39,6 +41,8 @@ class ApplicationData #if defined __CELLOS_LV2__ Ps3App app; +#elif defined __native_client__ + NaClApp app; #elif defined HAVE_GLES_2X /* FIXME: this macro is only deactivated if we include "lolgl.h" */ EglApp app; diff --git a/src/debug/quad.cpp b/src/debug/quad.cpp index d90c3cbd..fa218f26 100644 --- a/src/debug/quad.cpp +++ b/src/debug/quad.cpp @@ -153,7 +153,7 @@ void DebugQuad::TickDraw(float deltams) if (!data->initialised && !IsDestroying()) { -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ glGenVertexArrays(NUM_ARRAYS, data->array); #endif glGenBuffers(NUM_BUFFERS, data->buffer); @@ -183,7 +183,7 @@ void DebugQuad::TickDraw(float deltams) } else if (data->initialised && IsDestroying()) { -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ glDeleteVertexArrays(NUM_ARRAYS, data->array); #endif glDeleteBuffers(NUM_BUFFERS, data->buffer); @@ -494,7 +494,7 @@ void DebugQuad::TickDraw(float deltams) * * Renders an orange square. */ -#if !defined __ANDROID__ && !defined __APPLE__ +#if !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ glColor4f(orange.x, orange.y, orange.z, orange.w); glEnableClientState(GL_VERTEX_ARRAY); @@ -512,7 +512,7 @@ void DebugQuad::TickDraw(float deltams) * * Renders a green sine wave made of 1-pixel points. */ -#if !defined __ANDROID__ && !defined __APPLE__ +#if !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ glColor4f(0.0f, 1.0f, 0.0f, 1.0f); glPointSize(1.0f); glEnableClientState(GL_VERTEX_ARRAY); @@ -531,7 +531,7 @@ void DebugQuad::TickDraw(float deltams) * * Renders a multicoloured square with varying colors. */ -#if !defined __ANDROID__ && !defined __APPLE__ +#if !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); @@ -552,7 +552,7 @@ void DebugQuad::TickDraw(float deltams) * Renders a multicoloured square with varying colors multiplied with an * animated distorted checkerboard. */ -#if !defined __ANDROID__ && !defined __APPLE__ +#if !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, data->texture[0]); glEnableClientState(GL_VERTEX_ARRAY); @@ -580,7 +580,7 @@ void DebugQuad::TickDraw(float deltams) * * Renders an orange square. */ -#if !defined __ANDROID__ && !defined __APPLE__ +#if !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ if (!shader[0]) #if !defined __CELLOS_LV2__ shader[0] = Shader::Create( @@ -626,7 +626,7 @@ void DebugQuad::TickDraw(float deltams) * * Renders an orange square. */ -#if !defined __ANDROID__ && !defined __APPLE__ +#if !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ if (!shader[0]) { #if !defined __CELLOS_LV2__ @@ -679,7 +679,7 @@ void DebugQuad::TickDraw(float deltams) * * Renders a static, coloured and tiled pattern. */ -#if !defined __ANDROID__ && !defined __APPLE__ +#if !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ if (!shader[0]) #if !defined __CELLOS_LV2__ shader[0] = Shader::Create( @@ -732,7 +732,7 @@ void DebugQuad::TickDraw(float deltams) * * Renders a multicoloured square with varying colors. */ -#if !defined __ANDROID__ && !defined __APPLE__ +#if !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ if (!shader[0]) { #if !defined __CELLOS_LV2__ @@ -796,7 +796,7 @@ void DebugQuad::TickDraw(float deltams) * * Renders an antialiased green sine wave made of 1-pixel points. */ -#if !defined __ANDROID__ && !defined __APPLE__ && !defined __CELLOS_LV2__ +#if !defined __ANDROID__ && !defined __APPLE__ && !defined __CELLOS_LV2__ && !defined __native_client__ if (!shader[0]) shader[0] = Shader::Create( "#version 120\n" @@ -842,7 +842,7 @@ void DebugQuad::TickDraw(float deltams) * Renders a multicoloured square with varying colors xored with an * animated distorted checkerboard. */ -#if !defined __ANDROID__ && !defined __APPLE__ +#if !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ if (!shader[0]) #if !defined __CELLOS_LV2__ shader[0] = Shader::Create( @@ -915,7 +915,7 @@ void DebugQuad::TickDraw(float deltams) * Renders a multicoloured square with varying colors xored with an * animated distorted checkerboard. */ -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ if (!shader[0]) { shader[0] = Shader::Create( @@ -985,7 +985,7 @@ void DebugQuad::TickDraw(float deltams) * Renders a multicoloured square with varying colors xored with an * animated distorted checkerboard. */ -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ if (!shader[0]) { shader[0] = Shader::Create( @@ -1073,7 +1073,7 @@ void DebugQuad::ResetState() glLoadIdentity(); #endif -#if !defined __ANDROID__ && !defined __APPLE__ +#if !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ glColor4f(1.0f, 1.0f, 1.0f, 1.0f); #endif @@ -1082,13 +1082,13 @@ void DebugQuad::ResetState() #if defined HAVE_GLBEGIN || defined USE_GLEW || defined __CELLOS_LV2__ glClientActiveTexture(GL_TEXTURE0); #endif -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE); #endif glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ glDisable(GL_POINT_SPRITE); #endif @@ -1100,7 +1100,7 @@ void DebugQuad::ResetState() cgGLDisableProfile(cgGLGetLatestProfile(CG_GL_FRAGMENT)); #endif -#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ +#if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined __APPLE__ && !defined __native_client__ glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); #endif } diff --git a/src/platform/nacl/naclapp.cpp b/src/platform/nacl/naclapp.cpp new file mode 100644 index 00000000..f85546de --- /dev/null +++ b/src/platform/nacl/naclapp.cpp @@ -0,0 +1,82 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#if defined __native_client__ +# include "ppapi/cpp/instance.h" +# include "ppapi/cpp/module.h" +# include "ppapi/cpp/var.h" +#endif + +#include "core.h" +#include "lolgl.h" +#include "naclapp.h" + +namespace lol +{ + +/* + * PS3 App implementation class + */ + +class NaClAppData +{ + friend class NaClApp; + +private: +#if defined __native_client__ +#endif +}; + +/* + * Public NaClApp class + */ + +NaClApp::NaClApp(char const *title, ivec2 res, float fps) : + data(new NaClAppData()) +{ +#if defined __native_client__ +#endif +} + +void NaClApp::ShowPointer(bool show) +{ + ; +} + +void NaClApp::Run() +{ + while (!Ticker::Finished()) + { + /* Tick the game */ + Ticker::TickGame(); + + /* Tick the renderer, show the frame and clamp to desired framerate. */ + Ticker::TickDraw(); + +#if defined __native_client__ +#endif + + Ticker::ClampFps(); + } +} + +NaClApp::~NaClApp() +{ +#if defined __native_client__ +#endif + delete data; +} + +} /* namespace lol */ + diff --git a/src/platform/nacl/naclapp.h b/src/platform/nacl/naclapp.h new file mode 100644 index 00000000..d654465a --- /dev/null +++ b/src/platform/nacl/naclapp.h @@ -0,0 +1,42 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +// +// The NaClApp class +// ----------------- +// + +#if !defined __LOL_NACLAPP_H__ +#define __LOL_NACLAPP_H__ + +#include "matrix.h" + +namespace lol +{ + +class NaClAppData; + +class NaClApp +{ +public: + NaClApp(char const *title, ivec2 res, float fps); + virtual ~NaClApp(); + + void ShowPointer(bool show); + void Run(); + +private: + NaClAppData *data; +}; + +} /* namespace lol */ + +#endif // __LOL_NACLAPP_H__ + diff --git a/src/real.h b/src/real.h index 57f59434..1cbc2328 100644 --- a/src/real.h +++ b/src/real.h @@ -18,6 +18,9 @@ #include +/* Avoid issues with NaCl headers */ +#undef log2 + namespace lol { diff --git a/src/timer.cpp b/src/timer.cpp index 9c086701..dc1f63aa 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -15,7 +15,7 @@ #include #include -#if defined __linux__ || defined __APPLE__ +#if defined __linux__ || defined __native_client__ || defined __APPLE__ # include # include #elif defined _XBOX @@ -48,7 +48,7 @@ class TimerData private: TimerData() { -#if defined __linux__ || defined __APPLE__ +#if defined __linux__ || defined __native_client__ || defined __APPLE__ gettimeofday(&tv0, NULL); #elif defined _WIN32 QueryPerformanceCounter(&cycles0); @@ -63,7 +63,7 @@ private: float GetOrWait(float deltams, bool update) { float ret, towait; -#if defined __linux__ || defined __APPLE__ +#if defined __linux__ || defined __native_client__ || defined __APPLE__ struct timeval tv; gettimeofday(&tv, NULL); ret = 1e-3f * (tv.tv_usec - tv0.tv_usec) @@ -108,7 +108,7 @@ private: static float GetMsPerCycle() { -#if defined __linux__ || defined __APPLE__ +#if defined __linux__ || defined __native_client__ || defined __APPLE__ return 1.0f; #elif defined _WIN32 LARGE_INTEGER tmp; @@ -121,7 +121,7 @@ private: #endif } -#if defined __linux__ || defined __APPLE__ +#if defined __linux__ || defined __native_client__ || defined __APPLE__ struct timeval tv0; #elif defined _WIN32 LARGE_INTEGER cycles0; diff --git a/test/benchmark/trig.cpp b/test/benchmark/trig.cpp index 9937fb1b..33697350 100644 --- a/test/benchmark/trig.cpp +++ b/test/benchmark/trig.cpp @@ -73,7 +73,7 @@ void bench_trig(int mode) /* Fast sin */ timer.GetMs(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) -#if defined HAVE_FASTMATH_H +#if defined HAVE_FASTMATH_H && !defined __native_client__ pf2[i] = f_sinf(pf[i]); #else pf2[i] = sinf(pf[i]); @@ -99,7 +99,7 @@ void bench_trig(int mode) /* Fast cos */ timer.GetMs(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) -#if defined HAVE_FASTMATH_H +#if defined HAVE_FASTMATH_H && !defined __native_client__ pf2[i] = f_cosf(pf[i]); #else pf2[i] = cosf(pf[i]); @@ -130,7 +130,7 @@ void bench_trig(int mode) timer.GetMs(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) { -#if defined HAVE_FASTMATH_H +#if defined HAVE_FASTMATH_H && !defined __native_client__ pf2[i] = f_sinf(pf[i]); pf3[i] = f_cosf(pf[i]); #else @@ -159,7 +159,7 @@ void bench_trig(int mode) /* Fast tan */ timer.GetMs(); for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) -#if defined HAVE_FASTMATH_H +#if defined HAVE_FASTMATH_H && !defined __native_client__ pf2[i] = f_tanf(pf[i]); #else pf2[i] = tanf(pf[i]); diff --git a/test/tutorial/tut03.cpp b/test/tutorial/tut03.cpp index 83acd972..44543d8e 100644 --- a/test/tutorial/tut03.cpp +++ b/test/tutorial/tut03.cpp @@ -34,6 +34,10 @@ using namespace lol; static GLint const INTERNAL_FORMAT = GL_ARGB_SCE; static GLenum const TEXTURE_FORMAT = GL_BGRA; static GLenum const TEXTURE_TYPE = GL_UNSIGNED_INT_8_8_8_8_REV; +#elif defined __native_client__ +static GLint const INTERNAL_FORMAT = GL_RGBA; +static GLenum const TEXTURE_FORMAT = GL_RGBA; +static GLenum const TEXTURE_TYPE = GL_UNSIGNED_BYTE; #else /* Seems efficient for little endian textures */ static GLint const INTERNAL_FORMAT = GL_RGBA;