Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00046
00047
00048
00049
00050
00051
00052
00053
00054 enum MouseMode
00055 {
00056 Mouse_Normal,
00057 Mouse_Relative,
00058 Mouse_RelativeEscaped,
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
00070 Mod_MouseRelative = 0x100,
00071 };
00072
00073
00074
00075
00076 typedef RenderDevice* (*RenderDeviceCreateFunc)(const Render::RendererParams&, void*);
00077
00078
00079
00080
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
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
00101
00102
00103
00104
00105
00106
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
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
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
00147 double GetAppTime() const;
00148
00149 virtual String GetContentDirectory() const { return "."; }
00150 };
00151
00152
00153
00154
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
00182
00183 static Application* CreateApplication();
00184 static void DestroyApplication(Application* app);
00185 };
00186
00187
00188 }}
00189
00190 #endif