Platform.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 Filename    :   Platform.h
00004 Content     :   Platform-independent app and rendering framework for Oculus samples
00005 Created     :   September 6, 2012
00006 Authors     :   Andrew Reisse
00007 
00008 Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
00009 
00010 Licensed under the Apache License, Version 2.0 (the "License");
00011 you may not use this file except in compliance with the License.
00012 You may obtain a copy of the License at
00013 
00014 http://www.apache.org/licenses/LICENSE-2.0
00015 
00016 Unless required by applicable law or agreed to in writing, software
00017 distributed under the License is distributed on an "AS IS" BASIS,
00018 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019 See the License for the specific language governing permissions and
00020 limitations under the License.
00021 
00022 ************************************************************************************/
00023 
00024 #ifndef OVR_Platform_h
00025 #define OVR_Platform_h
00026 
00027 #include "OVR.h"
00028 
00029 #include "Kernel/OVR_KeyCodes.h"
00030 
00031 namespace OVR { namespace Render {
00032     class RenderDevice;
00033     struct DisplayId;
00034     struct RendererParams;
00035 }}
00036 
00037 namespace OVR { namespace Platform {
00038 
00039 using Render::RenderDevice;
00040 
00041 class PlatformCore;
00042 class Application;
00043 class GamepadManager;
00044 
00045 // MouseMode configures mouse input behavior of the app. Three states are
00046 // currently supported:
00047 //   Normal          - Reports absolute coordinates with cursor shown.
00048 //   Relative        - Reports relative delta coordinates with cursor hidden
00049 //                     until 'Esc' key is pressed or window loses focus.
00050 //   RelativeEscaped - Relative input is desired, but has been escaped until
00051 //                     mouse is clicked in the window, which will return the state
00052 //                     to relative. Absolute coordinates are reported.
00053 
00054 enum MouseMode
00055 {
00056     Mouse_Normal,
00057     Mouse_Relative,        // Cursor hidden, mouse grab, OnMouseMove reports relative deltas.
00058     Mouse_RelativeEscaped, // Clicking in window will return to Relative state.
00059 };
00060 
00061 
00062 enum Modifiers
00063 {
00064     Mod_Shift       = 0x001,
00065     Mod_Control     = 0x002,
00066     Mod_Meta        = 0x004,
00067     Mod_Alt         = 0x008,
00068 
00069     // Set for input Mouse_Relative mode, indicating that x,y are relative deltas.
00070     Mod_MouseRelative = 0x100,
00071 };
00072 
00073 //-------------------------------------------------------------------------------------
00074 // ***** SetupGraphicsDeviceSet
00075 
00076 typedef RenderDevice* (*RenderDeviceCreateFunc)(const Render::RendererParams&, void*);
00077 
00078 // SetupGraphicsDeviceSet is a PlatformCore::SetupGraphics initialization helper class,
00079 // used to build up a list of RenderDevices that can be used for rendering.
00080 // Specifying a smaller set allows application to avoid linking unused graphics devices.
00081 struct SetupGraphicsDeviceSet
00082 {    
00083     SetupGraphicsDeviceSet(const char* typeArg, RenderDeviceCreateFunc createFunc)
00084         : pTypeArg(typeArg), pCreateDevice(createFunc), pNext(0) { }
00085     SetupGraphicsDeviceSet(const char* typeArg, RenderDeviceCreateFunc createFunc,
00086                            const SetupGraphicsDeviceSet& next)
00087         : pTypeArg(typeArg), pCreateDevice(createFunc), pNext(&next) { }
00088 
00089     // Selects graphics object based on type string; returns 'this' if not found.
00090     const SetupGraphicsDeviceSet* PickSetupDevice(const char* typeArg) const;
00091 
00092     const char*               pTypeArg;
00093     RenderDeviceCreateFunc    pCreateDevice;        
00094 
00095 private:
00096     const SetupGraphicsDeviceSet*  pNext;
00097 };
00098 
00099 //-------------------------------------------------------------------------------------
00100 // ***** PlatformCore
00101 
00102 // PlatformCore defines abstract system window/viewport setup functionality and
00103 // maintains a renderer. This class is separated from Application because it can have
00104 // derived platform-specific implementations.
00105 // Specific implementation classes are hidden within platform-specific versions
00106 // such as Win32::PlatformCore.
00107 
00108 class PlatformCore : public NewOverrideBase
00109 {
00110 protected:
00111     Application*        pApp;
00112     Ptr<RenderDevice>   pRender;
00113     Ptr<GamepadManager> pGamepadManager;
00114     UInt64              StartupTicks; 
00115 
00116 public:
00117     PlatformCore(Application *app);
00118     virtual ~PlatformCore() { }
00119     Application*    GetApp() { return pApp; }
00120     RenderDevice*   GetRenderer() const { return pRender; }
00121     GamepadManager* GetGamepadManager() const { return pGamepadManager; }
00122 
00123     virtual bool    SetupWindow(int w, int h) = 0;
00124     // Destroys window and also releases renderer.
00125     virtual void    DestroyWindow() = 0;
00126     virtual void    Exit(int exitcode) = 0;
00127 
00128     virtual void    ShowWindow(bool visible) = 0;
00129     
00130     virtual bool    SetFullscreen(const Render::RendererParams& rp, int fullscreen);
00131    
00132     // Search for a matching graphics renderer based on type argument and initializes it.    
00133     virtual RenderDevice* SetupGraphics(const SetupGraphicsDeviceSet& setupGraphicsDesc,
00134                                         const char* gtype,
00135                                         const Render::RendererParams& rp) = 0;
00136 
00137     virtual void    SetMouseMode(MouseMode mm) { OVR_UNUSED(mm); }
00138 
00139     virtual void    GetWindowSize(int* w, int* h) const = 0;
00140 
00141     virtual void    SetWindowTitle(const char*title) = 0;
00142         virtual void    PlayMusicFile(const char *fileName) { OVR_UNUSED(fileName); }
00143     virtual int     GetDisplayCount() { return 0; }
00144     virtual Render::DisplayId GetDisplay(int screen);
00145     
00146     // Get time since start of application in seconds.
00147     double          GetAppTime() const; 
00148     
00149     virtual String  GetContentDirectory() const { return "."; }
00150 };
00151 
00152 //-------------------------------------------------------------------------------------
00153 // PlatformApp is a base application class from which end-user application
00154 // classes derive.
00155 
00156 class Application : public NewOverrideBase
00157 {
00158 protected:
00159     class PlatformCore* pPlatform;
00160 
00161 public:
00162     virtual ~Application() { }
00163 
00164     virtual int  OnStartup(int argc, const char** argv) = 0;
00165     virtual void OnQuitRequest() { pPlatform->Exit(0); }
00166 
00167     virtual void OnIdle() {}
00168 
00169     virtual void OnKey(KeyCode key, int chr, bool down, int modifiers)
00170     { OVR_UNUSED4(key, chr, down, modifiers); }
00171     virtual void OnMouseMove(int x, int y, int modifiers)
00172     { OVR_UNUSED3(x, y, modifiers); }
00173 
00174     virtual void OnResize(int width, int height)
00175     { OVR_UNUSED2(width, height); }
00176 
00177     void         SetPlatformCore(PlatformCore* p) { pPlatform = p; }
00178     PlatformCore* GetPlatformCore() const         { return pPlatform; }
00179 
00180 
00181     // Static functions defined by OVR_PLATFORM_APP and used to initialize and
00182     // shut down the application class.
00183     static Application* CreateApplication();
00184     static void         DestroyApplication(Application* app);
00185 };
00186 
00187 
00188 }}
00189 
00190 #endif


oculus_sdk
Author(s):
autogenerated on Mon Oct 6 2014 03:01:19