From 60a2e83d54114dd99b3e1b782f95ea0781cc897e Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 26 Mar 2012 18:18:40 +0000 Subject: [PATCH] xbox: start working on an Xbox/Direct3D port. --- configure.ac | 1 + src/Makefile.am | 8 ++- src/application/application.cpp | 6 ++- src/debug/quad.cpp | 7 ++- src/debug/sphere.cpp | 7 ++- src/dict.cpp | 4 +- src/gradient.cpp | 5 +- src/real.cpp | 7 ++- src/shader/shader.cpp | 4 +- src/thread/threadbase.h | 8 ++- src/timer.cpp | 4 +- src/vector.cpp | 9 +++- src/video.cpp | 91 +++++++++++++++++++++++++++------ win32/lolcore.vcxproj | 4 +- win32/lolcore.vcxproj.filters | 9 ++++ 15 files changed, 143 insertions(+), 31 deletions(-) diff --git a/configure.ac b/configure.ac index 801ff818..f3b48317 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,7 @@ PKG_PROG_PKG_CONFIG() dnl Available platforms: some of these are not public AM_CONDITIONAL(HAVE_PS3, test -f src/platform/ps3/ps3app.cpp) +AM_CONDITIONAL(HAVE_XBOX, false) AM_CONDITIONAL(USE_GLEW, test "${ac_cv_my_have_glew}" != "no") dnl conditional builds diff --git a/src/Makefile.am b/src/Makefile.am index 3b66c706..b57775bd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,7 @@ liblol_a_SOURCES = \ eglapp.cpp eglapp.h \ \ $(ps3_sources) \ + $(xbox_sources) \ $(nacl_sources) \ $(sdl_sources) \ \ @@ -54,9 +55,14 @@ nacl_sources = \ endif if HAVE_PS3 -ps3_sources = \ +ps3_sources = \ platform/ps3/threadbase.h \ platform/ps3/ps3app.cpp platform/ps3/ps3app.h \ platform/ps3/ps3input.cpp platform/ps3/ps3input.h endif +if HAVE_XBOX +xbox_sources = \ + platform/xbox/xboxapp.cpp platform/xbox/xboxapp.h +endif + diff --git a/src/application/application.cpp b/src/application/application.cpp index cbb59346..5e59dd51 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2012 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 @@ -17,6 +17,8 @@ #if defined __CELLOS_LV2__ # include "platform/ps3/ps3app.h" +#elif defined _XBOX +# include "platform/xbox/xboxapp.h" #elif defined __native_client__ # include "platform/nacl/naclapp.h" #elif defined HAVE_GLES_2X @@ -41,6 +43,8 @@ class ApplicationData #if defined __CELLOS_LV2__ Ps3App app; +#elif defined _XBOX + XboxApp app; #elif defined __native_client__ NaClApp app; #elif defined HAVE_GLES_2X diff --git a/src/debug/quad.cpp b/src/debug/quad.cpp index 1e4d7c8d..a0b8c370 100644 --- a/src/debug/quad.cpp +++ b/src/debug/quad.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2012 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 @@ -12,7 +12,9 @@ # include "config.h" #endif -#if defined WIN32 && !defined _XBOX +#if !defined _XBOX /* This file is meaningless on Xbox */ + +#if defined WIN32 && !_XBOX # define _USE_MATH_DEFINES /* for M_PI */ # define WIN32_LEAN_AND_MEAN # include @@ -1117,3 +1119,4 @@ void DebugQuad::ResetState() } /* namespace lol */ +#endif /* !defined _XBOX */ diff --git a/src/debug/sphere.cpp b/src/debug/sphere.cpp index 469b44e2..a65a22bf 100644 --- a/src/debug/sphere.cpp +++ b/src/debug/sphere.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2012 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 @@ -12,7 +12,9 @@ # include "config.h" #endif -#if defined WIN32 && !defined _XBOX +#if !defined _XBOX /* This file is meaningless on Xbox */ + +#if defined WIN32 # define _USE_MATH_DEFINES /* for M_PI */ # define WIN32_LEAN_AND_MEAN # include @@ -208,3 +210,4 @@ DebugSphere::~DebugSphere() } /* namespace lol */ +#endif /* !defined _XBOX */ diff --git a/src/dict.cpp b/src/dict.cpp index dd68b347..f3fb31c6 100644 --- a/src/dict.cpp +++ b/src/dict.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2012 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 @@ -17,7 +17,7 @@ #include "core.h" -#if defined WIN32 +#if defined _WIN32 || defined _XBOX # define strcasecmp _stricmp #endif diff --git a/src/gradient.cpp b/src/gradient.cpp index c9b05ff4..72edcbc0 100644 --- a/src/gradient.cpp +++ b/src/gradient.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2012 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 @@ -12,6 +12,8 @@ # include "config.h" #endif +#if !defined _XBOX /* This file is meaningless on Xbox */ + #include #include "core.h" @@ -241,3 +243,4 @@ Gradient::~Gradient() } /* namespace lol */ +#endif /* !defined _XBOX */ diff --git a/src/real.cpp b/src/real.cpp index 9d48f1a3..cb4def60 100644 --- a/src/real.cpp +++ b/src/real.cpp @@ -12,7 +12,12 @@ # include "config.h" #endif -#if defined WIN32 && !defined _XBOX +#if defined _XBOX +# define _USE_MATH_DEFINES /* for M_PI */ +# include +# undef near /* Fuck Microsoft */ +# undef far /* Fuck Microsoft again */ +#elif defined WIN32 # define _USE_MATH_DEFINES /* for M_PI */ # define WIN32_LEAN_AND_MEAN # include diff --git a/src/shader/shader.cpp b/src/shader/shader.cpp index 7b6e3173..24e2ea7d 100644 --- a/src/shader/shader.cpp +++ b/src/shader/shader.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2012 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 @@ -38,6 +38,8 @@ class ShaderData friend class Shader; private: +#if defined _XBOX + #if !defined __CELLOS_LV2__ GLuint prog_id, vert_id, frag_id; #else diff --git a/src/thread/threadbase.h b/src/thread/threadbase.h index cad73944..88a17e17 100644 --- a/src/thread/threadbase.h +++ b/src/thread/threadbase.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2012 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 @@ -18,8 +18,14 @@ #if defined HAVE_PTHREAD_H # include +#elif defined _XBOX +# include +# undef near /* Fuck Microsoft */ +# undef far /* Fuck Microsoft again */ #elif defined _WIN32 # include +# undef near /* Fuck Microsoft */ +# undef far /* Fuck Microsoft again */ #else # error No threading support yet :( #endif diff --git a/src/timer.cpp b/src/timer.cpp index dc1f63aa..c6852330 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2012 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 @@ -20,6 +20,8 @@ # include #elif defined _XBOX # include +# undef near /* Fuck Microsoft */ +# undef far /* Fuck Microsoft again */ # include #elif defined _WIN32 # define WIN32_LEAN_AND_MEAN diff --git a/src/vector.cpp b/src/vector.cpp index 2b67f0da..a2541074 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2012 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 @@ -12,7 +12,12 @@ # include "config.h" #endif -#if defined WIN32 && !defined _XBOX +#if defined _XBOX +# define _USE_MATH_DEFINES /* for M_PI */ +# include +# undef near /* Fuck Microsoft */ +# undef far /* Fuck Microsoft again */ +#elif defined _WIN32 # define _USE_MATH_DEFINES /* for M_PI */ # define WIN32_LEAN_AND_MEAN # include diff --git a/src/video.cpp b/src/video.cpp index e87e7c13..6e71605e 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright: (c) 2010-2011 Sam Hocevar +// Copyright: (c) 2010-2012 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 @@ -14,7 +14,11 @@ #include -#if defined _WIN32 && !defined _XBOX +#if _XBOX +# include +# undef near /* Fuck Microsoft */ +# undef far /* Fuck Microsoft again */ +#elif defined _WIN32 # define WIN32_LEAN_AND_MEAN # include # undef near /* Fuck Microsoft */ @@ -36,20 +40,64 @@ class VideoData private: static mat4 proj_matrix, view_matrix; static ivec2 saved_viewport; +#if defined _XBOX + static Direct3D *d3d_ctx; + static D3DDevice *d3d_dev; +#endif }; mat4 VideoData::proj_matrix; mat4 VideoData::view_matrix; - ivec2 VideoData::saved_viewport(0, 0); +#if defined _XBOX +Direct3D *VideoData::d3d_ctx; +D3DDevice *VideoData::d3d_dev; +#endif + /* * Public Video class */ void Video::Setup(ivec2 size) { -#if defined USE_GLEW && !defined __APPLE__ +#if defined _XBOX + VideoData::d3d_ctx = Direct3DCreate9(D3D_SDK_VERSION); + if (!VideoData::d3d_ctx) + { + Log::Error("cannot initialise D3D\n"); + exit(EXIT_FAILURE); + } + + D3DPRESENT_PARAMETERS d3dpp; + memset(&d3dpp, 0, sizeof(d3dpp)); + + XVIDEO_MODE VideoMode; + XGetVideoMode( &VideoMode ); + if (size.x > VideoMode.dwDisplayWidth) + size.x = VideoMode.dwDisplayWidth; + if (size.y > VideoMode.dwDisplayHeight) + size.y = VideoMode.dwDisplayHeight; + VideoData::saved_viewport = size; + + d3dpp.BackBufferWidth = size.x; + d3dpp.BackBufferHeight = size.y; + d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; + d3dpp.BackBufferCount = 1; + d3dpp.EnableAutoDepthStencil = TRUE; + d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; + + if (!VideoData::d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, NULL, + D3DCREATE_HARDWARE_VERTEXPROCESSING, + &d3dpp, &VideoData::d3d_dev)) + { + Log::Error("cannot create D3D device\n"); + exit(EXIT_FAILURE); + } +#else +# if defined USE_GLEW && !defined __APPLE__ /* Initialise GLEW if necessary */ GLenum glerr = glewInit(); if (glerr != GLEW_OK) @@ -57,7 +105,7 @@ void Video::Setup(ivec2 size) Log::Error("cannot initialise GLEW: %s\n", glewGetErrorString(glerr)); exit(EXIT_FAILURE); } -#endif +# endif /* Initialise OpenGL */ glViewport(0, 0, size.x, size.y); @@ -66,9 +114,10 @@ void Video::Setup(ivec2 size) glClearColor(0.1f, 0.2f, 0.3f, 1.0f); glClearDepth(1.0); -#if defined HAVE_GL_2X && !defined __APPLE__ +# if defined HAVE_GL_2X && !defined __APPLE__ glShadeModel(GL_SMOOTH); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); +# endif #endif } @@ -126,8 +175,14 @@ void Video::SetDepth(bool set) void Video::Clear() { ivec2 size = GetSize(); +#if defined _XBOX + VideoData::d3d_dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER + | D3DCLEAR_STENCIL, + D3DCOLOR_XRGB(26, 51, 77), 1.0f, 0); +#else glViewport(0, 0, size.x, size.y); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); +#endif SetFov(0.0f); } @@ -139,26 +194,29 @@ void Video::Destroy() void Video::Capture(uint32_t *buffer) { +#if _XBOX + /* TODO */ +#else GLint v[4]; -#if defined __CELLOS_LV2__ +# if defined __CELLOS_LV2__ // FIXME: use psglCreateDeviceAuto && psglGetDeviceDimensions v[2] = 1920; v[3] = 1080; -#else +# else glGetIntegerv(GL_VIEWPORT, v); -#endif +# endif int width = v[2], height = v[3]; -#if defined HAVE_GL_2X +# if defined HAVE_GL_2X glPixelStorei(GL_PACK_ROW_LENGTH, 0); -#endif +# endif glPixelStorei(GL_PACK_ALIGNMENT, 1); -#if defined GL_BGRA +# if defined GL_BGRA glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, buffer); -#else +# else glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); -#endif +# endif for (int j = 0; j < height / 2; j++) for (int i = 0; i < width; i++) @@ -167,13 +225,16 @@ void Video::Capture(uint32_t *buffer) buffer[j * width + i] = buffer[(height - j - 1) * width + i]; buffer[(height - j - 1) * width + i] = tmp; } +#endif } ivec2 Video::GetSize() { +#if _XBOX + return VideoData::saved_viewport; +#elif 1 /* GetSize() is called too often on the game thread; we cannot rely on * the GL context at this point */ -#if 1 return VideoData::saved_viewport; #elif defined __CELLOS_LV2__ // FIXME: use psglCreateDeviceAuto && psglGetDeviceDimensions diff --git a/win32/lolcore.vcxproj b/win32/lolcore.vcxproj index 12d2c94f..f2bb10c0 100644 --- a/win32/lolcore.vcxproj +++ b/win32/lolcore.vcxproj @@ -169,6 +169,7 @@ + @@ -223,6 +224,7 @@ + @@ -245,4 +247,4 @@ - + \ No newline at end of file diff --git a/win32/lolcore.vcxproj.filters b/win32/lolcore.vcxproj.filters index 3fe873a0..18ac30a1 100644 --- a/win32/lolcore.vcxproj.filters +++ b/win32/lolcore.vcxproj.filters @@ -38,6 +38,9 @@ {123803f1-1722-4421-8245-098667654cda} + + {317cb5cc-5dcc-4e14-be90-40a125a2e2ec} + @@ -184,6 +187,9 @@ src\image\codec + + src\platform\xbox + @@ -345,5 +351,8 @@ src\image + + src\platform\xbox + \ No newline at end of file