From dc1bf59cc368cfb96cc3bfb34d7f8d0b131074bb Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Thu, 5 Sep 2019 01:10:52 +0200 Subject: [PATCH] Dummy Xbox port --- .gitignore | 7 + Makefile.nxdk | 123 ++++++ share/base_config.c | 7 + share/common.c | 4 + share/dir.c | 48 ++- share/fs_stdio.c | 5 + share/gui.c | 5 +- share/solid_draw.c | 6 +- share/video.c | 2 + xbox/GLES/gl.h | 253 +++++++++++ xbox/Makefile-libjpeg-turbo.xbox | 74 ++++ xbox/Makefile-libpng.xbox | 25 ++ xbox/Makefile-ogg.xbox | 8 + xbox/Makefile-vorbis.xbox | 31 ++ xbox/Makefile-zlib.xbox | 18 + xbox/alloca.h | 1 + xbox/direct.h | 1 + xbox/dirent.h | 13 + xbox/features.h | 0 xbox/malloc.h | 0 xbox/matrix.h | 318 ++++++++++++++ xbox/sys/stat.h | 7 + xbox/sys/time.h | 10 + xbox/windows.h | 0 xbox/xbox.c | 713 +++++++++++++++++++++++++++++++ 25 files changed, 1668 insertions(+), 11 deletions(-) create mode 100644 Makefile.nxdk create mode 100644 xbox/GLES/gl.h create mode 100644 xbox/Makefile-libjpeg-turbo.xbox create mode 100644 xbox/Makefile-libpng.xbox create mode 100644 xbox/Makefile-ogg.xbox create mode 100644 xbox/Makefile-vorbis.xbox create mode 100644 xbox/Makefile-zlib.xbox create mode 100644 xbox/alloca.h create mode 100644 xbox/direct.h create mode 100644 xbox/dirent.h create mode 100644 xbox/features.h create mode 100644 xbox/malloc.h create mode 100644 xbox/matrix.h create mode 100644 xbox/sys/stat.h create mode 100644 xbox/sys/time.h create mode 100644 xbox/windows.h create mode 100644 xbox/xbox.c diff --git a/.gitignore b/.gitignore index 45237358b..ea47b41c9 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,10 @@ /mapc.exe /contrib/curve.exe /*.dll + +*.obj +/bin +/main.exe +/main.lib +/*.iso +/default.xbe diff --git a/Makefile.nxdk b/Makefile.nxdk new file mode 100644 index 000000000..b43d1e671 --- /dev/null +++ b/Makefile.nxdk @@ -0,0 +1,123 @@ +NXDK_DIR = $(CURDIR)/../XboxDev/nxdk + +XBE_TITLE = NeverballX +OUTPUT_DIR = bin +GEN_XISO = $(XBE_TITLE).iso + +CFLAGS = + +CFLAGS += -ferror-limit=0 + +CFLAGS += -DENABLE_OPENGLES=1 +#CFLAGS += -DCONFIG_USER=\"$(USERDIR)\" \ +#CFLAGS += -DCONFIG_DATA=\"$(DATADIR)\" \ +#CFLAGS += -DCONFIG_LOCALE=\"$(LOCALEDIR)\" +CFLAGS += -I$(CURDIR)/share/ -I$(CURDIR)/xbox/ -D_CRTIMP= + +BALL_SRCS := \ + $(CURDIR)/share/lang.c \ + $(CURDIR)/share/st_common.c \ + $(CURDIR)/share/vec3.c \ + $(CURDIR)/share/base_image.c \ + $(CURDIR)/share/image.c \ + $(CURDIR)/share/solid_base.c \ + $(CURDIR)/share/solid_vary.c \ + $(CURDIR)/share/solid_draw.c \ + $(CURDIR)/share/solid_all.c \ + $(CURDIR)/share/mtrl.c \ + $(CURDIR)/share/part.c \ + $(CURDIR)/share/geom.c \ + $(CURDIR)/share/ball.c \ + $(CURDIR)/share/gui.c \ + $(CURDIR)/share/font.c \ + $(CURDIR)/share/theme.c \ + $(CURDIR)/share/base_config.c \ + $(CURDIR)/share/config.c \ + $(CURDIR)/share/video.c \ + $(CURDIR)/share/glext.c \ + $(CURDIR)/share/binary.c \ + $(CURDIR)/share/state.c \ + $(CURDIR)/share/audio.c \ + $(CURDIR)/share/text.c \ + $(CURDIR)/share/common.c \ + $(CURDIR)/share/list.c \ + $(CURDIR)/share/queue.c \ + $(CURDIR)/share/cmd.c \ + $(CURDIR)/share/array.c \ + $(CURDIR)/share/dir.c \ + $(CURDIR)/share/fbo.c \ + $(CURDIR)/share/glsl.c \ + $(CURDIR)/share/fs_common.c \ + $(CURDIR)/share/fs_png.c \ + $(CURDIR)/share/fs_jpg.c \ + $(CURDIR)/share/fs_ov.c \ + $(CURDIR)/share/log.c \ + $(CURDIR)/share/joy.c \ + $(CURDIR)/ball/hud.c \ + $(CURDIR)/ball/game_common.c \ + $(CURDIR)/ball/game_client.c \ + $(CURDIR)/ball/game_server.c \ + $(CURDIR)/ball/game_proxy.c \ + $(CURDIR)/ball/game_draw.c \ + $(CURDIR)/ball/score.c \ + $(CURDIR)/ball/level.c \ + $(CURDIR)/ball/progress.c \ + $(CURDIR)/ball/set.c \ + $(CURDIR)/ball/demo.c \ + $(CURDIR)/ball/demo_dir.c \ + $(CURDIR)/ball/util.c \ + $(CURDIR)/ball/st_conf.c \ + $(CURDIR)/ball/st_demo.c \ + $(CURDIR)/ball/st_save.c \ + $(CURDIR)/ball/st_goal.c \ + $(CURDIR)/ball/st_fail.c \ + $(CURDIR)/ball/st_done.c \ + $(CURDIR)/ball/st_level.c \ + $(CURDIR)/ball/st_over.c \ + $(CURDIR)/ball/st_play.c \ + $(CURDIR)/ball/st_set.c \ + $(CURDIR)/ball/st_start.c \ + $(CURDIR)/ball/st_title.c \ + $(CURDIR)/ball/st_help.c \ + $(CURDIR)/ball/st_name.c \ + $(CURDIR)/ball/st_shared.c \ + $(CURDIR)/ball/st_pause.c \ + $(CURDIR)/ball/st_ball.c \ + $(CURDIR)/ball/main.c + +BALL_SRCS += share/solid_sim_sol.c +BALL_SRCS += share/fs_stdio.c +BALL_SRCS += share/tilt_null.c +BALL_SRCS += share/hmd_null.c + +SRCS = $(BALL_SRCS) xbox/xbox.c +#SHADER_OBJS = ps.inl vs.inl + +# Add SDL +NXDK_SDL = y + +# Add vorbis and ogg +include $(CURDIR)/xbox/Makefile-vorbis.xbox +include $(CURDIR)/xbox/Makefile-ogg.xbox + +# Add libjpeg +include $(CURDIR)/xbox/Makefile-libjpeg-turbo.xbox + +# Add libpng (depends on zlib) +include $(CURDIR)/xbox/Makefile-zlib.xbox +include $(CURDIR)/xbox/Makefile-libpng.xbox + +# XGU +CFLAGS += -I$(CURDIR)/xbox/nxdk/lib + +all: $(OUTPUT_DIR)/default.xbe data $(GEN_XISO) + +# Add data to XISO +#FIXME: Copy files to $(OUTPUT_DIR) +data: force + @echo "Updating data" + @cp -r $(CURDIR)/data $(OUTPUT_DIR) + +force: + +include $(NXDK_DIR)/Makefile diff --git a/share/base_config.c b/share/base_config.c index bc51823eb..0a7fc6412 100644 --- a/share/base_config.c +++ b/share/base_config.c @@ -22,8 +22,10 @@ #include "fs.h" #ifdef _WIN32 +#ifndef NXDK #include #endif +#endif /*---------------------------------------------------------------------------*/ @@ -51,6 +53,7 @@ static const char *pick_data_path(const char *arg_data_path) static const char *pick_home_path(void) { #ifdef _WIN32 +#ifndef NXDK static char path[MAX_PATH]; if (SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, path) == S_OK) @@ -67,6 +70,10 @@ static const char *pick_home_path(void) } else return fs_base_dir(); +#else + //FIXME: Xbox + return fs_base_dir(); +#endif #else const char *path; diff --git a/share/common.c b/share/common.c index 319b232a8..ea91ef191 100644 --- a/share/common.c +++ b/share/common.c @@ -329,11 +329,14 @@ int rand_between(int low, int high) #ifdef _WIN32 +#ifndef NXDK /* MinGW hides this from ANSI C. MinGW-w64 doesn't. */ _CRTIMP int _putenv(const char *envstring); +#endif int set_env_var(const char *name, const char *value) { +#ifndef NXDK if (name) { char str[MAXSTR]; @@ -345,6 +348,7 @@ int set_env_var(const char *name, const char *value) return (_putenv(str) == 0); } +#endif return 0; } diff --git a/share/dir.c b/share/dir.c index 433d9dd50..b1cb6b226 100644 --- a/share/dir.c +++ b/share/dir.c @@ -12,7 +12,11 @@ * General Public License for more details. */ +#ifndef _WIN32 #include +#else +#include +#endif #include #include @@ -21,17 +25,13 @@ #include "dir.h" #include "common.h" -/* - * HACK: MinGW provides numerous POSIX extensions to MSVCRT, including - * dirent.h, so parasti ever so lazily has not bothered to port the - * code below to FindFirstFile et al. - */ - List dir_list_files(const char *path) { - DIR *dir; List files = NULL; +#ifndef _WIN32 + DIR *dir; + if ((dir = opendir(path))) { struct dirent *ent; @@ -46,6 +46,26 @@ List dir_list_files(const char *path) closedir(dir); } +#else + printf("Asking for files in '%s'\n", path); + + HANDLE hFind; + WIN32_FIND_DATA FindFileData; + + hFind = FindFirstFile(path, &FindFileData); + if (hFind != INVALID_HANDLE_VALUE) + { + BOOL status = TRUE; + while(status != FALSE) + { + //FIXME: Handle wide strings? + files = list_cons(strdup(FindFileData.cFileName), files); + + FindNextFile(hFind, &FindFileData); + } + FindClose(hFind); + } +#endif return files; } @@ -122,6 +142,7 @@ void dir_free(Array items) int dir_exists(const char *path) { +#ifndef _WIN32 DIR *dir; if ((dir = opendir(path))) @@ -130,4 +151,17 @@ int dir_exists(const char *path) return 1; } return 0; +#else + printf("Looking for '%s'\n", path); +#ifdef NXDK + //FIXME: nxdk issue #161 + DWORD dwAttrib = 0; + #define INVALID_FILE_ATTRIBUTES -1 +#else + DWORD dwAttrib = GetFileAttributes(path); +#endif + + return ((dwAttrib != INVALID_FILE_ATTRIBUTES) && + (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) ? 1 : 0; +#endif } diff --git a/share/fs_stdio.c b/share/fs_stdio.c index da020bc6e..81f3f16a1 100644 --- a/share/fs_stdio.c +++ b/share/fs_stdio.c @@ -42,6 +42,11 @@ static List fs_path; int fs_init(const char *argv0) { + if (!argv0) + { + argv0 = ""; + } + fs_dir_base = strdup(dir_name(argv0)); fs_dir_write = NULL; fs_path = NULL; diff --git a/share/gui.c b/share/gui.c index 5a660003f..d915ffec9 100644 --- a/share/gui.c +++ b/share/gui.c @@ -207,8 +207,9 @@ static void draw_enable(GLboolean c, GLboolean u, GLboolean p) static void draw_rect(int id) { - glDrawElements(GL_TRIANGLE_STRIP, RECT_ELEM, GL_UNSIGNED_SHORT, - (const GLvoid *) (id * WIDGET_ELEM * sizeof (GLushort))); +printf("Tried to draw %d\n", RECT_ELEM); + glDrawElements(GL_TRIANGLE_STRIP, RECT_ELEM, GL_UNSIGNED_SHORT, + (const GLvoid *) (id * WIDGET_ELEM * sizeof (GLushort))); } static void draw_text(int id) diff --git a/share/solid_draw.c b/share/solid_draw.c index a60aff2c7..bb79c2637 100644 --- a/share/solid_draw.c +++ b/share/solid_draw.c @@ -424,8 +424,10 @@ void sol_draw_mesh(const struct d_mesh *mp, struct s_rend *rend, int p) if (rend->curr_mtrl.base.fl & M_PARTICLE) glDrawArrays(GL_POINTS, 0, mp->vbc); - else - glDrawElements(GL_TRIANGLES, mp->ebc, GL_UNSIGNED_SHORT, 0); + else { +printf("Tried to draw %d (solid)\n", mp->ebc); + glDrawElements(GL_TRIANGLES, mp->ebc, GL_UNSIGNED_SHORT, 0); +} } } diff --git a/share/video.c b/share/video.c index c687e9389..7a91f0a78 100644 --- a/share/video.c +++ b/share/video.c @@ -179,7 +179,9 @@ int video_mode(int f, int w, int h) w, h, (f ? "fullscreen" : "windowed")); window = SDL_CreateWindow("", X, Y, w, h, +#ifndef NXDK SDL_WINDOW_OPENGL | +#endif (highdpi ? SDL_WINDOW_ALLOW_HIGHDPI : 0) | (f ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)); diff --git a/xbox/GLES/gl.h b/xbox/GLES/gl.h new file mode 100644 index 000000000..6d382de5f --- /dev/null +++ b/xbox/GLES/gl.h @@ -0,0 +1,253 @@ +typedef float GLfloat; +typedef int GLboolean; +typedef int GLenum; +typedef int GLint; +typedef int GLsizei; +typedef short GLshort; +typedef unsigned char GLubyte; +typedef unsigned int GLuint; +typedef unsigned short GLushort; +typedef void GLvoid; +typedef int GLsizeiptr; +typedef int GLintptr; +typedef unsigned int GLbitfield; + +#define GL_FALSE 0 +#define GL_TRUE 1 + + + +// Hopefully each of these is unique.. +#define GL_ALPHA_TEST 1 +#define GL_ALWAYS 2 +#define GL_AMBIENT 3 +#define GL_BACK 4 +#define GL_CCW 5 +#define GL_CLAMP_TO_EDGE 6 +#define GL_CLIP_PLANE0 7 +#define GL_CLIP_PLANE1 8 +#define GL_CLIP_PLANE2 9 +#define GL_COLOR_BUFFER_BIT 10 +#define GL_COLOR_MATERIAL 11 +#define GL_CULL_FACE 12 +#define GL_CW 13 +#define GL_DEPTH_BUFFER_BIT 14 +#define GL_DEPTH_TEST 15 +#define GL_DIFFUSE 16 +#define GL_EMISSION 17 +#define GL_EQUAL 18 +#define GL_EXTENSIONS 19 +#define GL_REPEAT 20 +#define GL_FLOAT 21 +#define GL_FRONT 22 +#define GL_FRONT_AND_BACK 23 +#define GL_GEQUAL 24 +#define GL_GREATER 25 +#define GL_KEEP 26 +#define GL_LEQUAL 27 +#define GL_LESS 28 +#define GL_STENCIL_TEST 29 +#define GL_LIGHTING 30 +#define GL_LIGHT_MODEL_AMBIENT 31 +#define GL_LIGHT_MODEL_TWO_SIDE 32 +#define GL_LINEAR 33 +#define GL_LUMINANCE 34 +#define GL_LUMINANCE_ALPHA 35 +#define GL_MAX_TEXTURE_SIZE 36 +#define GL_MAX_TEXTURE_UNITS 37 +#define GL_MODELVIEW 38 +#define GL_NEVER 39 +#define GL_NORMAL_ARRAY 40 +#define GL_NOTEQUAL 41 +#define GL_ONE 42 +#define GL_ONE_MINUS_SRC_ALPHA 43 +#define GL_PACK_ALIGNMENT 44 +#define GL_POINTS 45 +#define GL_POLYGON_OFFSET_FILL 46 +#define GL_POSITION 47 +#define GL_PROJECTION 48 +#define GL_RENDERER 49 +#define GL_REPLACE 50 +#define GL_RGB 51 +#define GL_RGBA 52 +#define GL_SHININESS 53 +#define GL_SPECULAR 54 +#define GL_SRC_ALPHA 55 +#define GL_STENCIL_BUFFER_BIT 56 +#define GL_TEXTURE 57 +#define GL_TEXTURE_2D 58 +#define GL_TEXTURE_COORD_ARRAY 59 +#define GL_TEXTURE_MAG_FILTER 60 +#define GL_TEXTURE_MIN_FILTER 61 +#define GL_TEXTURE_WRAP_S 62 +#define GL_TEXTURE_WRAP_T 63 +#define GL_TRIANGLES 64 +#define GL_TRIANGLE_STRIP 65 +#define GL_UNPACK_ALIGNMENT 66 +#define GL_UNSIGNED_BYTE 67 +#define GL_UNSIGNED_SHORT 68 +#define GL_VENDOR 69 +#define GL_VERSION 70 +#define GL_VERTEX_ARRAY 71 +#define GL_COLOR_ARRAY 72 +#define GL_SHORT 73 +#define GL_NORMALIZE 74 +#define GL_BLEND 75 +#define GL_LIGHT0 76 +#define GL_LIGHT1 77 +#define GL_LIGHT2 78 +#define GL_COMBINE 79 +#define GL_COMBINE_ALPHA 80 +#define GL_COMBINE_RGB 81 +#define GL_INTERPOLATE 82 +#define GL_MODULATE 83 +#define GL_NEAREST 84 +#define GL_OPERAND0_ALPHA 85 +#define GL_OPERAND0_RGB 86 +#define GL_OPERAND1_RGB 87 +#define GL_OPERAND2_RGB 88 +#define GL_PREVIOUS 89 +#define GL_PRIMARY_COLOR 90 +#define GL_SRC_COLOR 91 +#define GL_TEXTURE_ENV 92 +#define GL_TEXTURE_ENV_MODE 93 + + + + + + +// Defined in Neverball share/glext.h +#if 0 +#define GL_COLOR_ATTACHMENT0 0x8CE0 +#define GL_COMPILE_STATUS 0x8B81 +#define GL_COORD_REPLACE 0x8862 +#define GL_DEPTH24_STENCIL8 0x88F0 +#define GL_DEPTH_ATTACHMENT 0x8D00 +#define GL_DEPTH_STENCIL 0x84F9 +#define GL_DYNAMIC_DRAW 0x88E8 +#define GL_FRAGMENT_SHADER 0x8B30 +#define GL_FRAMEBUFFER 0x8D40 +#define GL_FRAMEBUFFER_COMPLETE 0x8CD5 +#define GL_INFO_LOG_LENGTH 0x8B84 +#define GL_LINK_STATUS 0x8B82 +#define GL_MULTISAMPLE 0x809D +#define GL_POINT_DISTANCE_ATTENUATION 0x8129 +#define GL_POINT_SIZE_MAX 0x8127 +#define GL_POINT_SIZE_MIN 0x8126 +#define GL_POINT_SPRITE 0x8861 +#define GL_SRC0_ALPHA 0x8588 +#define GL_SRC0_RGB 0x8580 +#define GL_SRC1_RGB 0x8581 +#define GL_SRC2_RGB 0x8582 +#define GL_STATIC_DRAW 0x88E4 +#define GL_STENCIL_ATTACHMENT 0x8D20 +#define GL_TEXTURE0 0x84C0 +#define GL_TEXTURE1 0x84C1 +#define GL_TEXTURE2 0x84C2 +#define GL_UNSIGNED_INT_24_8 0x84FA +#define GL_VERTEX_SHADER 0x8B31 +#else +#define GL_ARRAY_BUFFER 0x8892 +#define GL_ELEMENT_ARRAY_BUFFER 0x8893 +#endif + + + + +// Funtion specifiers +#define GL_API +#define GL_APIENTRY + + +// Getters +GL_API void GL_APIENTRY glGetIntegerv (GLenum pname, GLint *data); +GL_API const GLubyte *GL_APIENTRY glGetString (GLenum name); + +// Clearing +GL_API void GL_APIENTRY glClear (GLbitfield mask); +GL_API void GL_APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); + +// Buffers +GL_API void GL_APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); +GL_API void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer); +GL_API void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage); +GL_API void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data); +GL_API void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); + +// Vertex buffers +GL_API void GL_APIENTRY glTexCoordPointer (GLint size, GLenum type, GLsizei stride, const void *pointer); +GL_API void GL_APIENTRY glColorPointer (GLint size, GLenum type, GLsizei stride, const void *pointer); +GL_API void GL_APIENTRY glNormalPointer (GLenum type, GLsizei stride, const void *pointer); +GL_API void GL_APIENTRY glVertexPointer (GLint size, GLenum type, GLsizei stride, const void *pointer); + +// Draw calls +GL_API void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count); +GL_API void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices); + +// Matrix functions +GL_API void GL_APIENTRY glMatrixMode (GLenum mode); +GL_API void GL_APIENTRY glLoadIdentity (void); +GL_API void GL_APIENTRY glMultMatrixf (const GLfloat *m); +GL_API void GL_APIENTRY glOrthof (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f); +GL_API void GL_APIENTRY glTranslatef (GLfloat x, GLfloat y, GLfloat z); +GL_API void GL_APIENTRY glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z); +GL_API void GL_APIENTRY glScalef (GLfloat x, GLfloat y, GLfloat z); +GL_API void GL_APIENTRY glPopMatrix (void); +GL_API void GL_APIENTRY glPushMatrix (void); + +// Framebuffer setup +GL_API void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height); + +// Textures +GL_API void GL_APIENTRY glGenTextures (GLsizei n, GLuint *textures); +GL_API void GL_APIENTRY glBindTexture (GLenum target, GLuint texture); +GL_API void GL_APIENTRY glActiveTexture (GLenum texture); +GL_API void GL_APIENTRY glClientActiveTexture (GLenum texture); +GL_API void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures); +GL_API void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels); +GL_API void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param); + +// Renderstates +GL_API void GL_APIENTRY glAlphaFunc (GLenum func, GLfloat ref); +GL_API void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor); +GL_API void GL_APIENTRY glClipPlanef (GLenum p, const GLfloat *eqn); +GL_API void GL_APIENTRY glColor4ub (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); +GL_API void GL_APIENTRY glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +GL_API void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +GL_API void GL_APIENTRY glDepthFunc (GLenum func); +GL_API void GL_APIENTRY glDepthMask (GLboolean flag); +GL_API void GL_APIENTRY glEnable (GLenum cap); +GL_API void GL_APIENTRY glDisable (GLenum cap); +GL_API void GL_APIENTRY glEnableClientState (GLenum array); +GL_API void GL_APIENTRY glDisableClientState (GLenum array); +GL_API void GL_APIENTRY glCullFace (GLenum mode); +GL_API void GL_APIENTRY glFrontFace (GLenum mode); + +// Stencil actions +GL_API void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask); +GL_API void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass); + +// Misc. +GL_API void GL_APIENTRY glPointParameterf (GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glPointSize (GLfloat size); +GL_API void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units); + +// TexEnv +GL_API void GL_APIENTRY glTexEnvi (GLenum target, GLenum pname, GLint param); + +// Pixel readback +GL_API void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels); + +// Lighting +GL_API void GL_APIENTRY glLightModelf (GLenum pname, GLfloat param); +GL_API void GL_APIENTRY glLightModelfv (GLenum pname, const GLfloat *params); +GL_API void GL_APIENTRY glLightfv (GLenum light, GLenum pname, const GLfloat *params); + +// Materials +GL_API void GL_APIENTRY glMaterialfv (GLenum face, GLenum pname, const GLfloat *params); + +// Pixel pushing +GL_API void GL_APIENTRY glPixelStorei (GLenum pname, GLint param); + diff --git a/xbox/Makefile-libjpeg-turbo.xbox b/xbox/Makefile-libjpeg-turbo.xbox new file mode 100644 index 000000000..9b5563ca2 --- /dev/null +++ b/xbox/Makefile-libjpeg-turbo.xbox @@ -0,0 +1,74 @@ +#FIXME: Depends on jconfig.h being fixed up; modify: +# //#define NEED_SYS_TYPES_H 1 +# //#define NEED_BSD_STRINGS 1 +# // #define __CHAR_UNSIGNED__ 1 +#FIXME: Depends on jconfigint.h being fixed up; modify: +# #define SIZEOF_SIZE_T 4 //@SIZE_T@ +# //#cmakedefine HAVE_BUILTIN_CTZL +# //#cmakedefine HAVE_INTRIN_H +#FIXME: Extend `#if !defined(__MINGW32__) && !defined(NXDK)` in tjutil.h + +#LIBJPEG_TURBO_DIR = $(NXDK_DIR)/lib/libjpeg-turbo +LIBJPEG_TURBO_DIR = $(CURDIR)/xbox/nxdk-libjpeg-turbo + +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcapimin.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcapistd.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jccoefct.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jccolor.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcdctmgr.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jchuff.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcicc.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcinit.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcmainct.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcmarker.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcmaster.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcomapi.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcparam.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcphuff.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcprepct.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcsample.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jctrans.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdapimin.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdapistd.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdatadst.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdatasrc.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdcoefct.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdcolor.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jddctmgr.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdhuff.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdicc.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdinput.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdmainct.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdmarker.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdmaster.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdmerge.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdphuff.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdpostct.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdsample.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdtrans.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jerror.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jfdctflt.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jfdctfst.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jfdctint.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jidctflt.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jidctfst.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jidctint.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jidctred.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jquant1.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jquant2.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jutils.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jmemmgr.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jmemnobs.c) + +#FIXME: Support simd/i386/*-mmx.asm and simd/i386/*-sse.asm +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jsimd_none.c) + +#FIXME: These 3 are optional, not sure why we require them right now +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jaricom.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jcarith.c) +LIBJPEG_TURBO_SRCS += $(wildcard $(LIBJPEG_TURBO_DIR)/jdarith.c) + +SRCS += $(LIBJPEG_TURBO_SRCS) +CFLAGS += -isystem $(LIBJPEG_TURBO_DIR) +# Ideally we'd use -D__MINGW32__ here, so we can compile this lib without +# changes, but that won't work with global CFLAGS diff --git a/xbox/Makefile-libpng.xbox b/xbox/Makefile-libpng.xbox new file mode 100644 index 000000000..d5ec84f08 --- /dev/null +++ b/xbox/Makefile-libpng.xbox @@ -0,0 +1,25 @@ +#FIXME: Needs to copy $(LIBPNG_DIR)/scripts/pnglibconf.h.prebuilt to $(LIBPNG_DIR)/pnglibconf.h; modify: +# //#define PNG_FLOATING_ARITHMETIC_SUPPORTED +# //#define PNG_FLOATING_POINT_SUPPORTED + +#LIBPNG_DIR = $(NXDK_DIR)/lib/libpng +LIBPNG_DIR = $(CURDIR)/xbox/nxdk-libpng + +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/png.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngerror.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngget.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngmem.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngpread.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngread.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngrio.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngrtran.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngrutil.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngset.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngtrans.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngwio.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngwrite.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngwtran.c) +LIBPNG_SRCS += $(wildcard $(LIBPNG_DIR)/pngwutil.c) + +SRCS += $(LIBPNG_SRCS) +CFLAGS += -isystem $(LIBPNG_DIR) diff --git a/xbox/Makefile-ogg.xbox b/xbox/Makefile-ogg.xbox new file mode 100644 index 000000000..1cec027f2 --- /dev/null +++ b/xbox/Makefile-ogg.xbox @@ -0,0 +1,8 @@ +#OGG_DIR = $(NXDK_DIR)/lib/ogg +OGG_DIR = $(CURDIR)/xbox/nxdk-ogg + +OGG_SRCS += $(wildcard $(OGG_DIR)/src/framing.c) +OGG_SRCS += $(wildcard $(OGG_DIR)/src/bitwise.c) + +SRCS += $(OGG_SRCS) +CFLAGS += -isystem $(OGG_DIR)/include diff --git a/xbox/Makefile-vorbis.xbox b/xbox/Makefile-vorbis.xbox new file mode 100644 index 000000000..87e4711ad --- /dev/null +++ b/xbox/Makefile-vorbis.xbox @@ -0,0 +1,31 @@ +#VORBIS_DIR = $(NXDK_DIR)/lib/vorbis +VORBIS_DIR = $(CURDIR)/xbox/nxdk-vorbis + +# libvorbis +VORBIS_SRCS += $(VORBIS_DIR)/lib/analysis.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/bitrate.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/block.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/codebook.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/envelope.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/floor0.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/floor1.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/info.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/lookup.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/lpc.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/lsp.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/mapping0.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/mdct.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/psy.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/registry.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/res0.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/sharedbook.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/smallft.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/synthesis.c +VORBIS_SRCS += $(VORBIS_DIR)/lib/window.c + +# libvorbisfile +VORBIS_SRCS += $(VORBIS_DIR)/lib/vorbisfile.c + +SRCS += $(VORBIS_SRCS) +CFLAGS += -isystem $(VORBIS_DIR)/include \ + -DHAVE_ALLOCA_H diff --git a/xbox/Makefile-zlib.xbox b/xbox/Makefile-zlib.xbox new file mode 100644 index 000000000..5dca0d4b9 --- /dev/null +++ b/xbox/Makefile-zlib.xbox @@ -0,0 +1,18 @@ +#ZLIB_DIR = $(NXDK_DIR)/lib/zlib +ZLIB_DIR = $(CURDIR)/xbox/nxdk-zlib + +ZLIB_SRCS += $(wildcard $(ZLIB_DIR)/adler32.c) +ZLIB_SRCS += $(wildcard $(ZLIB_DIR)/crc32.c) +ZLIB_SRCS += $(wildcard $(ZLIB_DIR)/deflate.c) +ZLIB_SRCS += $(wildcard $(ZLIB_DIR)/infback.c) +ZLIB_SRCS += $(wildcard $(ZLIB_DIR)/inffast.c) +ZLIB_SRCS += $(wildcard $(ZLIB_DIR)/inflate.c) +ZLIB_SRCS += $(wildcard $(ZLIB_DIR)/inftrees.c) +ZLIB_SRCS += $(wildcard $(ZLIB_DIR)/trees.c) +ZLIB_SRCS += $(wildcard $(ZLIB_DIR)/zutil.c) + +#FIXME: gzip support + +SRCS += $(ZLIB_SRCS) +CFLAGS += -isystem $(ZLIB_DIR) \ + -DZ_SOLO diff --git a/xbox/alloca.h b/xbox/alloca.h new file mode 100644 index 000000000..e7199ac77 --- /dev/null +++ b/xbox/alloca.h @@ -0,0 +1 @@ +#define alloca(size) __builtin_alloca(size) diff --git a/xbox/direct.h b/xbox/direct.h new file mode 100644 index 000000000..a56691700 --- /dev/null +++ b/xbox/direct.h @@ -0,0 +1 @@ +int _mkdir(const char *dirname); diff --git a/xbox/dirent.h b/xbox/dirent.h new file mode 100644 index 000000000..cda6ac95b --- /dev/null +++ b/xbox/dirent.h @@ -0,0 +1,13 @@ +typedef struct { + int pad; +} DIR; + +struct dirent { + char d_name[]; +}; + +DIR *opendir(const char *__name); +struct dirent *readdir(DIR *__dirp); +int closedir(DIR *__dirp); + + diff --git a/xbox/features.h b/xbox/features.h new file mode 100644 index 000000000..e69de29bb diff --git a/xbox/malloc.h b/xbox/malloc.h new file mode 100644 index 000000000..e69de29bb diff --git a/xbox/matrix.h b/xbox/matrix.h new file mode 100644 index 000000000..374b91f8f --- /dev/null +++ b/xbox/matrix.h @@ -0,0 +1,318 @@ +// Some helper with stolen math routines +// These might have come from https://github.com/intel/external-mesa/blob/master/src/mesa/math/m_matrix.c ? +//FIXME: Verify that these are conforming to GL spec + +#define _USE_MATH_DEFINES +#include + +typedef double GLdouble; + +static void _math_matrix_translate(GLfloat *m, GLfloat x, GLfloat y, GLfloat z ) { + m[12] = m[0] * x + m[4] * y + m[8] * z + m[12]; + m[13] = m[1] * x + m[5] * y + m[9] * z + m[13]; + m[14] = m[2] * x + m[6] * y + m[10] * z + m[14]; + m[15] = m[3] * x + m[7] * y + m[11] * z + m[15]; +} + +static void matrix_identity(float* out) { + memset(out, 0x00, 4 * 4 * sizeof(float)); + for(int i = 0; i < 4; i++) { + out[i*4+i] = 1.0f; + } +} + +static void _math_matrix_scale(GLfloat *m, GLfloat x, GLfloat y, GLfloat z ) { + m[0] *= x; m[4] *= y; m[8] *= z; + m[1] *= x; m[5] *= y; m[9] *= z; + m[2] *= x; m[6] *= y; m[10] *= z; + m[3] *= x; m[7] *= y; m[11] *= z; +} + + +bool invert(float invOut[16], const float m[16]) +{ + float inv[16], det; + int i; + + inv[0] = m[5] * m[10] * m[15] - + m[5] * m[11] * m[14] - + m[9] * m[6] * m[15] + + m[9] * m[7] * m[14] + + m[13] * m[6] * m[11] - + m[13] * m[7] * m[10]; + + inv[4] = -m[4] * m[10] * m[15] + + m[4] * m[11] * m[14] + + m[8] * m[6] * m[15] - + m[8] * m[7] * m[14] - + m[12] * m[6] * m[11] + + m[12] * m[7] * m[10]; + + inv[8] = m[4] * m[9] * m[15] - + m[4] * m[11] * m[13] - + m[8] * m[5] * m[15] + + m[8] * m[7] * m[13] + + m[12] * m[5] * m[11] - + m[12] * m[7] * m[9]; + + inv[12] = -m[4] * m[9] * m[14] + + m[4] * m[10] * m[13] + + m[8] * m[5] * m[14] - + m[8] * m[6] * m[13] - + m[12] * m[5] * m[10] + + m[12] * m[6] * m[9]; + + inv[1] = -m[1] * m[10] * m[15] + + m[1] * m[11] * m[14] + + m[9] * m[2] * m[15] - + m[9] * m[3] * m[14] - + m[13] * m[2] * m[11] + + m[13] * m[3] * m[10]; + + inv[5] = m[0] * m[10] * m[15] - + m[0] * m[11] * m[14] - + m[8] * m[2] * m[15] + + m[8] * m[3] * m[14] + + m[12] * m[2] * m[11] - + m[12] * m[3] * m[10]; + + inv[9] = -m[0] * m[9] * m[15] + + m[0] * m[11] * m[13] + + m[8] * m[1] * m[15] - + m[8] * m[3] * m[13] - + m[12] * m[1] * m[11] + + m[12] * m[3] * m[9]; + + inv[13] = m[0] * m[9] * m[14] - + m[0] * m[10] * m[13] - + m[8] * m[1] * m[14] + + m[8] * m[2] * m[13] + + m[12] * m[1] * m[10] - + m[12] * m[2] * m[9]; + + inv[2] = m[1] * m[6] * m[15] - + m[1] * m[7] * m[14] - + m[5] * m[2] * m[15] + + m[5] * m[3] * m[14] + + m[13] * m[2] * m[7] - + m[13] * m[3] * m[6]; + + inv[6] = -m[0] * m[6] * m[15] + + m[0] * m[7] * m[14] + + m[4] * m[2] * m[15] - + m[4] * m[3] * m[14] - + m[12] * m[2] * m[7] + + m[12] * m[3] * m[6]; + + inv[10] = m[0] * m[5] * m[15] - + m[0] * m[7] * m[13] - + m[4] * m[1] * m[15] + + m[4] * m[3] * m[13] + + m[12] * m[1] * m[7] - + m[12] * m[3] * m[5]; + + inv[14] = -m[0] * m[5] * m[14] + + m[0] * m[6] * m[13] + + m[4] * m[1] * m[14] - + m[4] * m[2] * m[13] - + m[12] * m[1] * m[6] + + m[12] * m[2] * m[5]; + + inv[3] = -m[1] * m[6] * m[11] + + m[1] * m[7] * m[10] + + m[5] * m[2] * m[11] - + m[5] * m[3] * m[10] - + m[9] * m[2] * m[7] + + m[9] * m[3] * m[6]; + + inv[7] = m[0] * m[6] * m[11] - + m[0] * m[7] * m[10] - + m[4] * m[2] * m[11] + + m[4] * m[3] * m[10] + + m[8] * m[2] * m[7] - + m[8] * m[3] * m[6]; + + inv[11] = -m[0] * m[5] * m[11] + + m[0] * m[7] * m[9] + + m[4] * m[1] * m[11] - + m[4] * m[3] * m[9] - + m[8] * m[1] * m[7] + + m[8] * m[3] * m[5]; + + inv[15] = m[0] * m[5] * m[10] - + m[0] * m[6] * m[9] - + m[4] * m[1] * m[10] + + m[4] * m[2] * m[9] + + m[8] * m[1] * m[6] - + m[8] * m[2] * m[5]; + + det = m[0] * inv[0] + m[1] * inv[4] + m[2] * inv[8] + m[3] * inv[12]; + + if (det == 0) + return false; + + det = 1.0 / det; + + for (i = 0; i < 16; i++) + invOut[i] = inv[i] * det; + + return true; +} + +#define A(row,col) a[(col<<2)+row] +#define B(row,col) b[(col<<2)+row] +#define P(row,col) product[(col<<2)+row] +static void matmul4( GLfloat *product, const GLfloat *a, const GLfloat *b ) +{ + GLint i; + for (i = 0; i < 4; i++) { + const GLfloat ai0=A(i,0), ai1=A(i,1), ai2=A(i,2), ai3=A(i,3); + P(i,0) = ai0 * B(0,0) + ai1 * B(1,0) + ai2 * B(2,0) + ai3 * B(3,0); + P(i,1) = ai0 * B(0,1) + ai1 * B(1,1) + ai2 * B(2,1) + ai3 * B(3,1); + P(i,2) = ai0 * B(0,2) + ai1 * B(1,2) + ai2 * B(2,2) + ai3 * B(3,2); + P(i,3) = ai0 * B(0,3) + ai1 * B(1,3) + ai2 * B(2,3) + ai3 * B(3,3); + } +} +#undef A +#undef B +#undef P + +void ortho(float* r, GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearval, GLdouble farval) { + //FIXME: Multiply this onto the existing stack - don't overwrite + + GLfloat m[16]; + +#define M(row,col) m[col*4+row] + M(0,0) = 2.0F / (right-left); + M(0,1) = 0.0F; + M(0,2) = 0.0F; + M(0,3) = -(right+left) / (right-left); + + M(1,0) = 0.0F; + M(1,1) = 2.0F / (top-bottom); + M(1,2) = 0.0F; + M(1,3) = -(top+bottom) / (top-bottom); + + M(2,0) = 0.0F; + M(2,1) = 0.0F; + M(2,2) = -2.0F / (farval-nearval); + M(2,3) = -(farval+nearval) / (farval-nearval); + + M(3,0) = 0.0F; + M(3,1) = 0.0F; + M(3,2) = 0.0F; + M(3,3) = 1.0F; +#undef M + + memcpy(r, m, sizeof(m)); +} + +void _math_matrix_rotate( GLfloat *m, GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) +{ + GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c, s, c; + + s = sinf( angle * M_PI / 180.0 ); + c = cosf( angle * M_PI / 180.0 ); + +#define M(row,col) m[col*4+row] + + const GLfloat mag = sqrtf(x * x + y * y + z * z); + + if (mag <= 1.0e-4F) { + /* no rotation, leave mat as-is */ + return; + } + + x /= mag; + y /= mag; + z /= mag; + + + /* + * Arbitrary axis rotation matrix. + * + * This is composed of 5 matrices, Rz, Ry, T, Ry', Rz', multiplied + * like so: Rz * Ry * T * Ry' * Rz'. T is the final rotation + * (which is about the X-axis), and the two composite transforms + * Ry' * Rz' and Rz * Ry are (respectively) the rotations necessary + * from the arbitrary axis to the X-axis then back. They are + * all elementary rotations. + * + * Rz' is a rotation about the Z-axis, to bring the axis vector + * into the x-z plane. Then Ry' is applied, rotating about the + * Y-axis to bring the axis vector parallel with the X-axis. The + * rotation about the X-axis is then performed. Ry and Rz are + * simply the respective inverse transforms to bring the arbitrary + * axis back to its original orientation. The first transforms + * Rz' and Ry' are considered inverses, since the data from the + * arbitrary axis gives you info on how to get to it, not how + * to get away from it, and an inverse must be applied. + * + * The basic calculation used is to recognize that the arbitrary + * axis vector (x, y, z), since it is of unit length, actually + * represents the sines and cosines of the angles to rotate the + * X-axis to the same orientation, with theta being the angle about + * Z and phi the angle about Y (in the order described above) + * as follows: + * + * cos ( theta ) = x / sqrt ( 1 - z^2 ) + * sin ( theta ) = y / sqrt ( 1 - z^2 ) + * + * cos ( phi ) = sqrt ( 1 - z^2 ) + * sin ( phi ) = z + * + * Note that cos ( phi ) can further be inserted to the above + * formulas: + * + * cos ( theta ) = x / cos ( phi ) + * sin ( theta ) = y / sin ( phi ) + * + * ...etc. Because of those relations and the standard trigonometric + * relations, it is pssible to reduce the transforms down to what + * is used below. It may be that any primary axis chosen will give the + * same results (modulo a sign convention) using thie method. + * + * Particularly nice is to notice that all divisions that might + * have caused trouble when parallel to certain planes or + * axis go away with care paid to reducing the expressions. + * After checking, it does perform correctly under all cases, since + * in all the cases of division where the denominator would have + * been zero, the numerator would have been zero as well, giving + * the expected result. + */ + + xx = x * x; + yy = y * y; + zz = z * z; + xy = x * y; + yz = y * z; + zx = z * x; + xs = x * s; + ys = y * s; + zs = z * s; + one_c = 1.0F - c; + + /* We already hold the identity-matrix so we can skip some statements */ + M(0,0) = (one_c * xx) + c; + M(0,1) = (one_c * xy) - zs; + M(0,2) = (one_c * zx) + ys; +/* M(0,3) = 0.0F; */ + + M(1,0) = (one_c * xy) + zs; + M(1,1) = (one_c * yy) + c; + M(1,2) = (one_c * yz) - xs; +/* M(1,3) = 0.0F; */ + + M(2,0) = (one_c * zx) - ys; + M(2,1) = (one_c * yz) + xs; + M(2,2) = (one_c * zz) + c; +/* M(2,3) = 0.0F; */ + +/* + M(3,0) = 0.0F; + M(3,1) = 0.0F; + M(3,2) = 0.0F; + M(3,3) = 1.0F; +*/ +#undef M +} diff --git a/xbox/sys/stat.h b/xbox/sys/stat.h new file mode 100644 index 000000000..961d554b9 --- /dev/null +++ b/xbox/sys/stat.h @@ -0,0 +1,7 @@ +#define F_OK 0 //FIXME: Should be in unistd.h? + +struct stat { int st_size; }; + +int stat(const char *pathname, struct stat *statbuf); +int access(const char *pathname, int mode); + diff --git a/xbox/sys/time.h b/xbox/sys/time.h new file mode 100644 index 000000000..106f97988 --- /dev/null +++ b/xbox/sys/time.h @@ -0,0 +1,10 @@ +struct timeval { + unsigned int tv_sec; + unsigned int tv_usec; +}; + +struct timezone { + int pad; +}; + +int gettimeofday(struct timeval *tv, struct timezone *tz); diff --git a/xbox/windows.h b/xbox/windows.h new file mode 100644 index 000000000..e69de29bb diff --git a/xbox/xbox.c b/xbox/xbox.c new file mode 100644 index 000000000..cc7dbd78f --- /dev/null +++ b/xbox/xbox.c @@ -0,0 +1,713 @@ +#include +#include + +// stdlib.h +#include + +int _putenv(const char *envstring) { + assert(false); //FIXME: Implement + return 0; +} + +// direct.h +#include "direct.h" + +int _mkdir(const char *dirname) { + assert(false); //FIXME: Implement + return 0; +} + +// dirent.h +#include "dirent.h" + +DIR *opendir(const char *__name) { + assert(false); //FIXME: Implement + return NULL; +} + +struct dirent *readdir(DIR *__dirp) { + assert(false); //FIXME: Implement + return NULL; +} + +int closedir(DIR *__dirp) { + assert(false); //FIXME: Implement + return 0; +} + +// sys/stat.h +#include "sys/stat.h" + +int stat(const char *pathname, struct stat *statbuf) { + assert(false); //FIXME: Implement + return 0; +} + +int access(const char *pathname, int mode) { + assert(false); //FIXME: Implement + return 0; +} + +// sys/time.h +#include "sys/time.h" + +int gettimeofday(struct timeval *tv, struct timezone *tz) { + assert(false); //FIXME: Implement + return 0; +} + +// xgu.h +#include "xgu/xgu.h" +#include "xgu/xgux.h" + + +// GLES/gl.h +#include +#include +#include + +#include "GLES/gl.h" +//#include + + +typedef struct { + void* data; +} Object; + +typedef struct { + uint8_t* data; + size_t size; +} Buffer; + +typedef struct { + int pad; +} Texture; + +//FIXME: Allow different pools +static Object* objects = NULL; +static GLuint object_count = 0; + +static GLuint unused_object() { + //FIXME: Find object slot where data is NULL + object_count += 1; + objects = realloc(objects, sizeof(Object) * object_count); + return object_count - 1; +} + +static void gen_objects(GLsizei n, GLuint* indices, size_t size) { + for(int i = 0; i < n; i++) { + GLuint index = unused_object(); + + Object* object = &objects[index]; + object->data = malloc(size); + memset(object->data, 0x00, size); + + indices[i] = 1 + index; + } +} + +static void del_objects(GLsizei n, const GLuint* indices) { + for(int i = 0; i < n; i++) { + GLuint index = indices[i] - 1; + + Object* object = &objects[index]; + + //FIXME: Call a handler routine? + + assert(object->data != NULL); + free(object->data); + object->data = NULL; + } +} + +#include "matrix.h" + +//FIXME: Used in xgu +static DWORD* p; + +static void set_enabled(GLenum cap, bool enabled) { + switch(cap) { + case GL_ALPHA_TEST: + p = xgu_set_alpha_test_enable(p, enabled); + default: + assert(false); + break; + } +} + +static void set_client_state_enabled(GLenum array, bool enabled) { + switch(array) { + default: + assert(false); + break; + } +} + +static XguPrimitiveType gl_to_xgu_primitive_type(GLenum mode) { + switch(mode) { + case GL_TRIANGLES: return XGU_TRIANGLES; + case GL_TRIANGLE_STRIP: return XGU_TRIANGLE_STRIP; + default: + assert(false); + return -1; + } +} + +static XguStencilOp gl_to_xgu_stencil_op(GLenum op) { + switch(op) { + default: + assert(false); + return -1; + } +} + +static XguCullFace gl_to_xgu_cull_face(GLenum mode) { + switch(mode) { + default: + assert(false); + return -1; + } +} + +static XguFrontFace gl_to_xgu_front_face(GLenum mode) { + switch(mode) { + default: + assert(false); + return -1; + } +} + +static XguVertexArrayType gl_to_xgu_vertex_array_type(GLenum mode) { + switch(mode) { + case GL_FLOAT: return XGU_FLOAT; + default: + assert(false); + return -1; + } +} + +static XguBlendFactor gl_to_xgu_blend_factor(GLenum factor) { + switch(factor) { + default: + assert(false); + return -1; + } +} + +static uint8_t f_to_u8(float f) { + assert(f >= 0.0f && f <= 1.0f); + return f * 0xFF; +} + +static GLuint gl_array_buffer = 0; +static GLuint gl_element_array_buffer = 0; + +static GLuint* get_bound_buffer_store(GLenum target) { + switch(target) { + case GL_ARRAY_BUFFER: + return &gl_array_buffer; + case GL_ELEMENT_ARRAY_BUFFER: + return &gl_element_array_buffer; + default: + assert(false); + break; + } + return 0; +} + + +static void* targetMatrix = NULL; //FIXME: Use this properly or remove it + +static void prepare_drawing() { + //FIXME: Set up all matrices etc. +} + + + + + + + +GL_API void GL_APIENTRY glGetIntegerv (GLenum pname, GLint *data) { + switch(pname) { + default: + assert(false); + break; + } +} + +GL_API const GLubyte *GL_APIENTRY glGetString (GLenum name) { + switch(name) { + default: + assert(false); + break; + } + return (GLubyte*)""; +} + + +// Clearing +GL_API void GL_APIENTRY glClear (GLbitfield mask) { + + XguClearSurface flags = 0; + if (mask & GL_COLOR_BUFFER_BIT) { flags |= XGU_CLEAR_COLOR; } + if (mask & GL_DEPTH_BUFFER_BIT) { flags |= XGU_CLEAR_Z; } + if (mask & GL_STENCIL_BUFFER_BIT) { flags |= XGU_CLEAR_STENCIL; } + + uint32_t* p = pb_begin(); + //FIXME: Set clear region + p = xgu_clear_surface(p, flags); + pb_end(p); +} + +GL_API void GL_APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { + + uint32_t color = 0; + //FIXME: Verify order + color |= f_to_u8(red) << 0; + color |= f_to_u8(green) << 8; + color |= f_to_u8(blue) << 16; + color |= f_to_u8(alpha) << 24; + + uint32_t* p = pb_begin(); + p = xgu_set_color_clear_value(p, color); + pb_end(p); +} + + +// Buffers +GL_API void GL_APIENTRY glGenBuffers (GLsizei n, GLuint *buffers) { + gen_objects(n, buffers, sizeof(Buffer)); +} + +GL_API void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer) { + GLuint* bound_buffer_store = get_bound_buffer_store(target); + *bound_buffer_store = buffer; +} + +GL_API void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage) { + assert(false); + Buffer* buffer = objects[*get_bound_buffer_store(target)].data; + if (buffer->data != NULL) { + //FIXME: Assert that this memory is no longer used + MmFreeContiguousMemory(buffer->data); + } + buffer->data = MmAllocateContiguousMemory(size); + buffer->size = size; + memcpy(buffer->data, data, size); +} + +GL_API void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data) { + assert(false); + Buffer* buffer = objects[*get_bound_buffer_store(target)].data; + assert(buffer->size >= (offset + size)); + memcpy(&buffer->data[offset], data, size); +} + +GL_API void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers) { + for(int i = 0; i < n; i++) { + Buffer* buffer = objects[buffers[i]].data; + if (buffer->data != NULL) { + //FIXME: Assert that the data is no longer used + MmFreeContiguousMemory(buffer->data); + } + } + del_objects(n, buffers); +} + + +// Vertex buffers +GL_API void GL_APIENTRY glTexCoordPointer (GLint size, GLenum type, GLsizei stride, const void *pointer) { + xgux_set_attrib_pointer(XGU_TEXCOORD0_ARRAY, type, size, stride, pointer); +} + +GL_API void GL_APIENTRY glColorPointer (GLint size, GLenum type, GLsizei stride, const void *pointer) { + xgux_set_attrib_pointer(XGU_COLOR_ARRAY, type, size, stride, pointer); +} + +GL_API void GL_APIENTRY glNormalPointer (GLenum type, GLsizei stride, const void *pointer) { + xgux_set_attrib_pointer(XGU_NORMAL_ARRAY, type, 3, stride, pointer); +} + +GL_API void GL_APIENTRY glVertexPointer (GLint size, GLenum type, GLsizei stride, const void *pointer) { + xgux_set_attrib_pointer(XGU_VERTEX_ARRAY, type, size, stride, pointer); +} + + +// Draw calls +GL_API void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count) { + prepare_drawing(); + xgux_draw_arrays(gl_to_xgu_primitive_type(mode), first, count); +} + +GL_API void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices) { + prepare_drawing(); + + // This function only handles the 16 bit variant for now + switch(type) { + case GL_UNSIGNED_SHORT: { + xgux_draw_elements16(gl_to_xgu_primitive_type(mode), count, (uint16_t*)indices); + break; + } +#if 0 + //FIXME: Not declared in gl.h + untested + case GL_UNSIGNED_INT: + p = xgu_elements32(p, (uint32_t*)indices, count); + break; +#endif + default: + assert(false); + break; + } + + p = xgu_end(p); +} + + +// Matrix functions +GL_API void GL_APIENTRY glMatrixMode (GLenum mode) { + switch(mode) { + default: + assert(false); + break; + } +} + +GL_API void GL_APIENTRY glLoadIdentity (void) { + matrix_identity(targetMatrix); +} + +GL_API void GL_APIENTRY glMultMatrixf (const GLfloat *m) { + float t[4 * 4]; + matmul4(t, targetMatrix, m); + memcpy(targetMatrix, t, sizeof(t)); +} + +GL_API void GL_APIENTRY glOrthof (GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f) { + float m[4*4]; + ortho(m, l, r, b, t, n, f); + glMultMatrixf(m); +} + +GL_API void GL_APIENTRY glTranslatef (GLfloat x, GLfloat y, GLfloat z) { + float m[4*4]; + matrix_identity(m); + _math_matrix_translate(m, x, y, z); + glMultMatrixf(m); +} + +GL_API void GL_APIENTRY glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { + float m[4*4]; + matrix_identity(m); + _math_matrix_rotate(m, angle, x, y, z); + glMultMatrixf(m); +} + +GL_API void GL_APIENTRY glScalef (GLfloat x, GLfloat y, GLfloat z) { + float m[4*4]; + matrix_identity(m); + _math_matrix_scale(m, x, y, z); + glMultMatrixf(m); +} + +GL_API void GL_APIENTRY glPopMatrix (void) { + assert(false); +} + +GL_API void GL_APIENTRY glPushMatrix (void) { + assert(false); +} + + +// Framebuffer setup +GL_API void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height) { + //FIXME: Switch to xgu variant to avoid side-effects + pb_set_viewport(x, y, width, height, 0.0f, 1.0f); +} + + +// Textures +GL_API void GL_APIENTRY glGenTextures (GLsizei n, GLuint *textures) { + gen_objects(n, textures, sizeof(Texture)); +} + +GL_API void GL_APIENTRY glBindTexture (GLenum target, GLuint texture) { + assert(target == GL_TEXTURE_2D); + assert(false); +} + +GL_API void GL_APIENTRY glActiveTexture (GLenum texture) { + assert(false); +} + +GL_API void GL_APIENTRY glClientActiveTexture (GLenum texture) { + assert(false); +} + +GL_API void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures) { + del_objects(n, textures); +} + +GL_API void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels) { + assert(false); +} + +GL_API void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param) { + assert(target == GL_TEXTURE_2D); + switch(pname) { + //FIXME: Missing from XGU + default: + assert(false); + return; + } +} + + +// Renderstates +GL_API void GL_APIENTRY glAlphaFunc (GLenum func, GLfloat ref) { +#if 0 + //FIXME: https://github.com/dracc/nxdk/pull/4/files#r357990989 + // https://github.com/dracc/nxdk/pull/4/files#r357990961 + uint32_t* p = pb_begin(); + p = xgu_set_alpha_func(p, gl_to_xgu_alpha_func(func)); + p = xgu_set_alpha_ref(p, f_to_u8(ref)); + pb_end(p); +#endif +} + +GL_API void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor) { + uint32_t* p = pb_begin(); + p = xgu_set_blend_func_sfactor(p, gl_to_xgu_blend_factor(sfactor)); + p = xgu_set_blend_func_dfactor(p, gl_to_xgu_blend_factor(dfactor)); + pb_end(p); +} + +GL_API void GL_APIENTRY glClipPlanef (GLenum p, const GLfloat *eqn) { + //FIXME: Use a free texture stage and set it to cull mode + assert(false); +} + +GL_API void GL_APIENTRY glColor4ub (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) { + uint32_t* p = pb_begin(); + p = xgux_set_color4ub(p, red, green, blue, alpha); + pb_end(p); +} + +GL_API void GL_APIENTRY glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { + uint32_t* p = pb_begin(); + p = xgux_set_color4f(p, red, green, blue, alpha); + pb_end(p); +} + +GL_API void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) { + + XguColorMask mask = 0; + if (red != GL_FALSE) { mask |= XGU_RED; } + if (green != GL_FALSE) { mask |= XGU_GREEN; } + if (blue != GL_FALSE) { mask |= XGU_BLUE; } + if (alpha != GL_FALSE) { mask |= XGU_ALPHA; } + + uint32_t* p = pb_begin(); + p = xgu_set_color_mask(p, mask); + pb_end(p); +} + +GL_API void GL_APIENTRY glDepthFunc (GLenum func) { + //FIXME: Missing from XGU + assert(false); +} + +GL_API void GL_APIENTRY glDepthMask (GLboolean flag) { + //FIXME: Missing from XGU + assert(false); +} + +GL_API void GL_APIENTRY glEnable (GLenum cap) { + set_enabled(cap, true); +} + +GL_API void GL_APIENTRY glDisable (GLenum cap) { + set_enabled(cap, false); +} + +GL_API void GL_APIENTRY glEnableClientState (GLenum array) { + set_client_state_enabled(array, true); +} + +GL_API void GL_APIENTRY glDisableClientState (GLenum array) { + set_client_state_enabled(array, false); +} + +GL_API void GL_APIENTRY glCullFace (GLenum mode) { + uint32_t* p = pb_begin(); + p = xgu_set_cull_face(p, gl_to_xgu_cull_face(mode)); + pb_end(p); +} + +GL_API void GL_APIENTRY glFrontFace (GLenum mode) { + uint32_t* p = pb_begin(); + p = xgu_set_front_face(p, gl_to_xgu_front_face(mode)); + pb_end(p); +} + + +// Stencil actions +GL_API void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask) { + //FIXME: Missing from XGU + assert(false); +} + +GL_API void GL_APIENTRY glStencilOp (GLenum fail, GLenum zfail, GLenum zpass) { + uint32_t* p = pb_begin(); + p = xgu_set_stencil_op_fail(p, gl_to_xgu_stencil_op(fail)); + p = xgu_set_stencil_op_zfail(p, gl_to_xgu_stencil_op(zfail)); + p = xgu_set_stencil_op_zpass(p, gl_to_xgu_stencil_op(zpass)); + pb_end(p); +} + + +// Misc. +GL_API void GL_APIENTRY glPointParameterf (GLenum pname, GLfloat param) { + //FIXME: Bad in XGU + assert(false); +} + +GL_API void GL_APIENTRY glPointParameterfv (GLenum pname, const GLfloat *params) { + //FIXME: Bad in XGU + assert(false); +} + +GL_API void GL_APIENTRY glPointSize (GLfloat size) { + //FIXME: Bad in XGU + assert(false); +} + +GL_API void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units) { + //FIXME: Missing from XGU + assert(false); +} + + +// TexEnv +GL_API void GL_APIENTRY glTexEnvi (GLenum target, GLenum pname, GLint param) { + assert(target == GL_TEXTURE_ENV); + switch(pname) { + //FIXME: Missing from XGU + default: + assert(false); + return; + } +} + + +// Pixel readback +GL_API void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels) { + // Only used in screenshots + assert(false); +} + + +// Lighting +GL_API void GL_APIENTRY glLightModelf (GLenum pname, GLfloat param) { + switch(pname) { + default: + assert(false); + return; + } +} + +GL_API void GL_APIENTRY glLightModelfv (GLenum pname, const GLfloat *params) { + switch(pname) { + default: + assert(false); + return; + } +} + +GL_API void GL_APIENTRY glLightfv (GLenum light, GLenum pname, const GLfloat *params) { + assert(light >= GL_LIGHT0); + unsigned int light_index = light - GL_LIGHT0; + assert(light_index <= 4); //FIXME: Not sure how many lights Xbox has; there's probably some constant we can use + switch(pname) { + default: + assert(false); + return; + } +} + + +// Materials +GL_API void GL_APIENTRY glMaterialfv (GLenum face, GLenum pname, const GLfloat *params) { + + if (face == GL_FRONT_AND_BACK) { + glMaterialfv(GL_FRONT, pname, params); + glMaterialfv(GL_BACK, pname, params); + return; + } + + assert(face == GL_FRONT || face == GL_BACK); + switch(pname) { + //FIXME: Missing from XGU + default: + assert(false); + return; + } +} + + +// Pixel pushing +GL_API void GL_APIENTRY glPixelStorei (GLenum pname, GLint param) { + switch(pname) { + case GL_PACK_ALIGNMENT: + assert(param == 1); + break; + case GL_UNPACK_ALIGNMENT: + assert(param == 1); + break; + default: + assert(false); + break; + } +} + + + + +//FIXME: Use stuff like `ptr = MmAllocateContiguousMemoryEx(size, 0, 0x3ffb000, 0, 0x404);` to alloc buffer / tex + +// Initialization + +#include +#include +#include +#include +#include + +__attribute__((constructor)) static void setup_xbox(void) { + + //FIXME: Remap log, see OpenSWE1R + + // Set up display mode + XVideoSetMode(640, 480, 32, REFRESH_DEFAULT); + //FIXME: Re-enable + //pb_set_color_format(NV097_SET_SURFACE_FORMAT_COLOR_LE_X8R8G8B8, false); + + // Initialize pbkit + int err = pb_init(); + if (err) { + debugPrint("pb_init Error %d\n", err); + //XSleep(2000); + //XReboot(); + return; + } + + // Show framebuffer, not debug-screen + pb_show_front_screen(); + + // Retrieve created size + //FIXME: why? - probably not needed + int width = pb_back_buffer_width(); + int height = pb_back_buffer_height(); + + //FIXME: Bump GPU in right state +}