diff options
Diffstat (limited to 'Samples/CommonSrc')
-rw-r--r-- | Samples/CommonSrc/CMakeLists.txt | 58 | ||||
-rw-r--r-- | Samples/CommonSrc/Platform/Linux_Platform.cpp | 53 | ||||
-rw-r--r-- | Samples/CommonSrc/Platform/OSX_Platform.mm | 2 | ||||
-rw-r--r-- | Samples/CommonSrc/Platform/Platform.h | 20 | ||||
-rw-r--r-- | Samples/CommonSrc/Platform/Platform_Default.h | 11 | ||||
-rw-r--r-- | Samples/CommonSrc/Platform/Win32_Platform.cpp | 5 | ||||
-rw-r--r-- | Samples/CommonSrc/Render/Render_GL_Device.h | 5 | ||||
-rw-r--r-- | Samples/CommonSrc/Render/Render_XmlSceneLoader.h | 3 |
8 files changed, 107 insertions, 50 deletions
diff --git a/Samples/CommonSrc/CMakeLists.txt b/Samples/CommonSrc/CMakeLists.txt new file mode 100644 index 0000000..3cfa009 --- /dev/null +++ b/Samples/CommonSrc/CMakeLists.txt @@ -0,0 +1,58 @@ +project(CommonSrc) + +set(SOURCE_FILES + Platform/Platform.cpp + Platform/Platform.cpp + Render/Render_Device.cpp + Render/Render_LoadTextureDDS.cpp + Render/Render_LoadTextureTGA.cpp + Render/Render_XmlSceneLoader.cpp +) + +if(WIN32) + list(APPEND SOURCE_FILES + Platform/Win32_Platform.cpp + Platform/Win32_Gamepad.cpp + Render/Render_D3D10_Device.cpp + Render/Render_D3D11_Device.cpp + ) + + find_package(DirectX REQUIRED) + list(APPEND CommonSrc_EXTRA_LIBS + ${DirectX_D3D10_LIBRARY} + ${DirectX_D3D11_LIBRARY} + ${DirectX_LIB_SEARCH_PATH}/d3dcompiler.lib + ${DirectX_LIB_SEARCH_PATH}/dxgi.lib + ) + include_directories(${DirectX_INC_SEARCH_PATH}) + +elseif(APPLE) + + list(APPEND SOURCE_FILES + Platform/OSX_Platform.mm + Platform/OSX_Gamepad.cpp + Platform/OSX_WavPlayer.cpp + Render/Render_GL_Device.cpp + ) + + find_library(OpenGL_LIBRARY OpenGL) + find_library(COCOA_LIBRARY Cocoa) + list(APPEND CommonSrc_EXTRA_LIBS + ${COCOA_LIBRARY} + ${OpenGL_LIBRARY} + ) + +else() + + list(APPEND SOURCE_FILES + Platform/Linux_Platform.cpp + Platform/Linux_Gamepad.cpp + Render/Render_GL_Device.cpp + ) + + list(APPEND CommonSrc_EXTRA_LIBS GL GLU glut) + +endif() + +add_library (CommonSrc STATIC ${SOURCE_FILES}) +target_link_libraries(CommonSrc ${CommonSrc_EXTRA_LIBS}) diff --git a/Samples/CommonSrc/Platform/Linux_Platform.cpp b/Samples/CommonSrc/Platform/Linux_Platform.cpp index c9d3e40..e94b37f 100644 --- a/Samples/CommonSrc/Platform/Linux_Platform.cpp +++ b/Samples/CommonSrc/Platform/Linux_Platform.cpp @@ -24,7 +24,7 @@ otherwise accompanies this software in either electronic or hard copy form. // Renderers #include "../Render/Render_GL_Device.h" -#include <X11/extensions/Xinerama.h> +#include <X11/extensions/Xrandr.h> namespace OVR { namespace Platform { namespace Linux { @@ -156,7 +156,7 @@ void PlatformCore::SetWindowTitle(const char* title) { XStoreName(Disp, Win, title); } - + void PlatformCore::ShowWindow(bool show) { if (show) @@ -227,12 +227,12 @@ static KeyCode MapXKToKeyCode(unsigned vk) { key = vk - XK_F1 + Key_F1; } - else + else { for (unsigned i = 0; i< (sizeof(KeyMap) / sizeof(KeyMap[1])); i++) { if (vk == KeyMap[i][0]) - { + { key = KeyMap[i][1]; break; } @@ -311,7 +311,7 @@ void PlatformCore::processEvent(XEvent& event) case MapNotify: if (MMode == Mouse_Relative) - { + { XWarpPointer(Disp, Win, Win, 0,0,Width,Height, Width/2, Height/2); showCursor(false); } @@ -323,7 +323,7 @@ void PlatformCore::processEvent(XEvent& event) //grab if (MMode == Mouse_RelativeEscaped) - { + { XWarpPointer(Disp, Win, Win, 0,0,Width,Height, Width/2, Height/2); showCursor(false); MMode = Mouse_Relative; @@ -333,7 +333,7 @@ void PlatformCore::processEvent(XEvent& event) case FocusOut: if (MMode == Mouse_Relative) - { + { MMode = Mouse_RelativeEscaped; showCursor(true); } @@ -370,28 +370,23 @@ int PlatformCore::Run() bool PlatformCore::determineScreenOffset(int screenId, int* screenOffsetX, int* screenOffsetY) { - Display* display = XOpenDisplay(NULL); - - bool foundScreen = false; - - if (display) - { - int numberOfScreens; - XineramaScreenInfo* screens = XineramaQueryScreens(display, &numberOfScreens); - - if (screenId < numberOfScreens) - { - XineramaScreenInfo screenInfo = screens[screenId]; - *screenOffsetX = screenInfo.x_org; - *screenOffsetY = screenInfo.y_org; - - foundScreen = true; + bool result = false; + if (screenId) { + Display* display = XOpenDisplay(NULL); + XRRScreenResources *screen = XRRGetScreenResources(display, DefaultRootWindow(display)); + XRROutputInfo * info = XRRGetOutputInfo (display, screen, screenId); + if (info->crtc) { + XRRCrtcInfo * crtc_info = XRRGetCrtcInfo (display, screen, info->crtc); + *screenOffsetX = crtc_info->x; + *screenOffsetY = crtc_info->y; + XRRFreeCrtcInfo(crtc_info); + result = true; } - - XFree(screens); + XRRFreeOutputInfo (info); + XRRFreeScreenResources(screen); } - return foundScreen; + return result; } void PlatformCore::showWindowDecorations(bool show) @@ -476,11 +471,11 @@ RenderDevice* PlatformCore::SetupGraphics(const SetupGraphicsDeviceSet& setupGra { const SetupGraphicsDeviceSet* setupDesc = setupGraphicsDesc.PickSetupDevice(type); OVR_ASSERT(setupDesc); - + pRender = *setupDesc->pCreateDevice(rp, this); if (pRender) pRender->SetWindowSize(Width, Height); - + return pRender.GetPtr(); } @@ -540,7 +535,7 @@ void RenderDevice::Shutdown() }}}} -int main(int argc, const char* argv[]) +int main(int argc, char** argv) { using namespace OVR; using namespace OVR::Platform; diff --git a/Samples/CommonSrc/Platform/OSX_Platform.mm b/Samples/CommonSrc/Platform/OSX_Platform.mm index 491ff6c..9926cca 100644 --- a/Samples/CommonSrc/Platform/OSX_Platform.mm +++ b/Samples/CommonSrc/Platform/OSX_Platform.mm @@ -29,7 +29,7 @@ using namespace OVR::Platform; [self setApp:app]; [self setPlatform:platform]; - const char* argv[] = {"OVRApp"}; + char* argv[] = {"OVRApp"}; int exitCode = app->OnStartup(1, argv); if (exitCode) { diff --git a/Samples/CommonSrc/Platform/Platform.h b/Samples/CommonSrc/Platform/Platform.h index 201aad6..992a3fa 100644 --- a/Samples/CommonSrc/Platform/Platform.h +++ b/Samples/CommonSrc/Platform/Platform.h @@ -79,7 +79,7 @@ typedef RenderDevice* (*RenderDeviceCreateFunc)(const Render::RendererParams&, v // used to build up a list of RenderDevices that can be used for rendering. // Specifying a smaller set allows application to avoid linking unused graphics devices. struct SetupGraphicsDeviceSet -{ +{ SetupGraphicsDeviceSet(const char* typeArg, RenderDeviceCreateFunc createFunc) : pTypeArg(typeArg), pCreateDevice(createFunc), pNext(0) { } SetupGraphicsDeviceSet(const char* typeArg, RenderDeviceCreateFunc createFunc, @@ -90,7 +90,7 @@ struct SetupGraphicsDeviceSet const SetupGraphicsDeviceSet* PickSetupDevice(const char* typeArg) const; const char* pTypeArg; - RenderDeviceCreateFunc pCreateDevice; + RenderDeviceCreateFunc pCreateDevice; private: const SetupGraphicsDeviceSet* pNext; @@ -111,7 +111,7 @@ protected: Application* pApp; Ptr<RenderDevice> pRender; Ptr<GamepadManager> pGamepadManager; - UInt64 StartupTicks; + UInt64 StartupTicks; public: PlatformCore(Application *app); @@ -126,10 +126,10 @@ public: virtual void Exit(int exitcode) = 0; virtual void ShowWindow(bool visible) = 0; - + virtual bool SetFullscreen(const Render::RendererParams& rp, int fullscreen); - - // Search for a matching graphics renderer based on type argument and initializes it. + + // Search for a matching graphics renderer based on type argument and initializes it. virtual RenderDevice* SetupGraphics(const SetupGraphicsDeviceSet& setupGraphicsDesc, const char* gtype, const Render::RendererParams& rp) = 0; @@ -142,10 +142,10 @@ public: virtual void PlayMusicFile(const char *fileName) { OVR_UNUSED(fileName); } virtual int GetDisplayCount() { return 0; } virtual Render::DisplayId GetDisplay(int screen); - + // Get time since start of application in seconds. - double GetAppTime() const; - + double GetAppTime() const; + virtual String GetContentDirectory() const { return "."; } }; @@ -161,7 +161,7 @@ protected: public: virtual ~Application() { } - virtual int OnStartup(int argc, const char** argv) = 0; + virtual int OnStartup(int argc, char** argv) = 0; virtual void OnQuitRequest() { pPlatform->Exit(0); } virtual void OnIdle() {} diff --git a/Samples/CommonSrc/Platform/Platform_Default.h b/Samples/CommonSrc/Platform/Platform_Default.h index e4fecf2..75bd1d8 100644 --- a/Samples/CommonSrc/Platform/Platform_Default.h +++ b/Samples/CommonSrc/Platform/Platform_Default.h @@ -3,7 +3,7 @@ Filename : Platform_Default.h Content : Default Platform class and RenderDevice selection file Created : October 4, 2012 -Authors : +Authors : Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved. @@ -31,7 +31,7 @@ limitations under the License. #include "Win32_Platform.h" #include "../Render/Render_D3D11_Device.h" - #undef OVR_D3D_VERSION + #undef OVR_D3D_VERSION #include "../Render/Render_D3D10_Device.h" // #include "../Render/Render_GL_Win32_Device.h" @@ -46,14 +46,17 @@ limitations under the License. #define OVR_DEFAULT_RENDER_DEVICE_SET \ SetupGraphicsDeviceSet("GL", &OVR::Render::GL::OSX::RenderDevice::CreateDevice) - -#else +#elif defined(OVR_OS_LINUX) #include "Linux_Platform.h" #define OVR_DEFAULT_RENDER_DEVICE_SET \ SetupGraphicsDeviceSet("GL", &OVR::Render::GL::Linux::RenderDevice::CreateDevice) +#else + + #error "Not implemented yet" + #endif #endif // OVR_Platform_Default_h diff --git a/Samples/CommonSrc/Platform/Win32_Platform.cpp b/Samples/CommonSrc/Platform/Win32_Platform.cpp index eeab429..09830d2 100644 --- a/Samples/CommonSrc/Platform/Win32_Platform.cpp +++ b/Samples/CommonSrc/Platform/Win32_Platform.cpp @@ -563,7 +563,7 @@ int WINAPI WinMain(HINSTANCE hinst, HINSTANCE prevInst, LPSTR inArgs, int show) // Nested scope for container destructors to shutdown before DestroyApplication. { Array<String> args; - Array<const char*> argv; + Array<char*> argv; argv.PushBack("app"); const char* p = inArgs; @@ -584,8 +584,9 @@ int WINAPI WinMain(HINSTANCE hinst, HINSTANCE prevInst, LPSTR inArgs, int show) } if (p != pstart) args.PushBack(String(pstart, p - pstart)); + // FIXME memory leak of the command line arguments here for (UPInt i = 0; i < args.GetSize(); i++) - argv.PushBack(args[i].ToCStr()); + argv.PushBack(strdup(args[i].ToCStr())); exitCode = g_app->OnStartup((int)argv.GetSize(), &argv[0]); if (!exitCode) diff --git a/Samples/CommonSrc/Render/Render_GL_Device.h b/Samples/CommonSrc/Render/Render_GL_Device.h index 88eaff4..7b65d4c 100644 --- a/Samples/CommonSrc/Render/Render_GL_Device.h +++ b/Samples/CommonSrc/Render/Render_GL_Device.h @@ -34,7 +34,6 @@ limitations under the License. #include <OpenGL/gl.h> #include <OpenGL/glext.h> #else -#define GL_GLEXT_PROTOTYPES #include <GL/gl.h> #include <GL/glext.h> #endif @@ -154,7 +153,7 @@ public: // Set a uniform (other than the standard matrices). It is undefined whether the // uniforms from one shader occupy the same space as those in other shaders - // (unless a buffer is used, then each buffer is independent). + // (unless a buffer is used, then each buffer is independent). virtual bool SetUniform(const char* name, int n, const float* v); virtual bool SetUniform4x4f(const char* name, const Matrix4f& m); @@ -185,7 +184,7 @@ class RenderDevice : public Render::RenderDevice GLuint CurrentFbo; const LightingParams* Lighting; - + public: RenderDevice(const RendererParams& p); diff --git a/Samples/CommonSrc/Render/Render_XmlSceneLoader.h b/Samples/CommonSrc/Render/Render_XmlSceneLoader.h index 694fc2e..4a5fecd 100644 --- a/Samples/CommonSrc/Render/Render_XmlSceneLoader.h +++ b/Samples/CommonSrc/Render/Render_XmlSceneLoader.h @@ -33,7 +33,8 @@ using namespace OVR::Render; #undef new #endif -#include "../../../3rdParty/TinyXml/tinyxml2.h" +#include <tinyxml2.h> +//#include "../../../3rdParty/TinyXml/tinyxml2.h" namespace OVR { namespace Render { |