00001 
00002 
00003 
00004 
00005 #ifndef NV_APP_BASE_H
00006 #define NV_APP_BASE_H
00007 
00008 #include <NvFoundation.h>
00009 #include <string>
00010 #include "NvGLAppContext.h"
00011 #include "NvPlatformContext.h"
00012 #include "NvGamepad/NvGamepad.h"
00013 
00016 
00017 class NvStopWatch;
00018 
00020 class NvAppBase : public NvInputCallbacks 
00021 {
00022 public:
00029     NvAppBase(NvPlatformContext* platform, const char* appTitle);
00030 
00032     virtual ~NvAppBase();
00033 
00037 
00042     virtual void initRendering(void) { }
00043 
00056     virtual void shutdownRendering(void) { }
00057 
00062     virtual void update(void) { }
00063 
00067     virtual void draw(void) { }
00068 
00074     virtual void reshape(int32_t width, int32_t height) { }
00075 
00079     virtual void focusChanged(bool focused) { }
00080 
00082 
00085     
00086     
00087     
00088     
00089     
00090     
00091     
00092     virtual bool handlePointerInput(NvInputDeviceType::Enum device, NvPointerActionType::Enum action, 
00093         uint32_t modifiers, int32_t count, NvPointerEvent* points) { return false; }
00094     virtual bool handleKeyInput(uint32_t code, NvKeyActionType::Enum action) { return false; }
00095     virtual bool handleCharacterInput(uint8_t c) { return false; }
00096     virtual bool handleGamepadChanged(uint32_t changedPadFlags) { return false; }
00097     virtual bool handleGamepadButtonChanged(uint32_t button, bool down) { return false; }
00099 
00109     virtual void configurationCallback(NvEGLConfiguration& config) { }
00110 
00114     NvGLAppContext* getGLContext() { return mContext; }
00115 
00118     void setGLContext(NvGLAppContext* context) { mContext = context; }
00119 
00122     NvPlatformContext* getPlatformContext() { return mPlatform; }
00123 
00127     bool isMobilePlatform() { return getGLContext()->getPlatformInfo().mCategory 
00128         == NvGLPlatformCategory::PLAT_MOBILE;
00129     }
00130 
00133     NvStopWatch* createStopWatch();
00134 
00137     uint64_t queryPerformanceCounter();
00138 
00141     uint64_t queryPerformanceCounterFrequency();
00142 
00149     bool showDialog(const char* title, const char *contents, bool exitApp);
00150 
00160     bool writeScreenShot(int32_t width, int32_t height, const uint8_t* data, const std::string& path);
00161 
00169     bool writeLogFile(const std::string& path, bool append, const char* fmt, ...);
00170 
00173     
00174     void forceLinkHack();
00175 
00185     virtual void mainLoop();
00186 
00198     virtual bool getRequestedWindowSize(int32_t& width, int32_t& height) { return false; }
00199 
00200 protected:
00203     void appRequestExit();
00204 
00207     bool isExiting() { return m_requestedExit; }
00208 
00209     int32_t m_width; 
00210     int32_t m_height; 
00211 
00213     NvPlatformContext* mPlatform;
00214     NvGLAppContext* mContext;
00215     std::string mAppTitle;
00216 
00217     bool m_requestedExit;
00218 };
00219 
00224 extern NvAppBase* NvAppFactory(NvPlatformContext* platform);
00225 
00226 #endif