PVRShellImpl.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /******************************************************************************
  2. @File PVRShellImpl.h
  3. @Title PVRShellImpl
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform Independent
  7. @Description Makes programming for 3D APIs easier by wrapping surface
  8. initialization, Texture allocation and other functions for use by a demo.
  9. ******************************************************************************/
  10. #ifndef __PVRSHELLIMPL_H_
  11. #define __PVRSHELLIMPL_H_
  12. /*****************************************************************************
  13. ** Build options
  14. *****************************************************************************/
  15. /*****************************************************************************
  16. ** Macros
  17. *****************************************************************************/
  18. #define FREE(X) { if(X) { free(X); (X)=0; } }
  19. #ifndef _ASSERT
  20. #define _ASSERT(X) /**/
  21. #endif
  22. /*****************************************************************************
  23. ** Defines
  24. *****************************************************************************/
  25. #define STR_WNDTITLE (" - Build ")
  26. /*!***************************************************************************
  27. @Struct PVRShellData
  28. @Brief Holds PVRShell internal data.
  29. *****************************************************************************/
  30. struct PVRShellData
  31. {
  32. // Shell Interface Data
  33. char *pszAppName;
  34. char *pszExitMessage;
  35. int nShellDimX;
  36. int nShellDimY;
  37. int nShellPosX;
  38. int nShellPosY;
  39. bool bFullScreen;
  40. bool bLandscape;
  41. bool bNeedPbuffer;
  42. bool bNeedZbuffer;
  43. bool bNeedStencilBuffer;
  44. bool bNeedPixmap;
  45. bool bNeedPixmapDisableCopy;
  46. bool bLockableBackBuffer;
  47. bool bSoftwareRender;
  48. bool bNeedOpenVG;
  49. bool bNeedAlphaFormatPre;
  50. bool bUsingPowerSaving;
  51. bool bOutputInfo;
  52. bool bNoShellSwapBuffer;
  53. int nSwapInterval;
  54. int nInitRepeats;
  55. int nDieAfterFrames;
  56. float fDieAfterTime;
  57. int nFSAAMode;
  58. int nColorBPP;
  59. int nDepthBPP;
  60. int nCaptureFrameStart;
  61. int nCaptureFrameStop;
  62. int nPriority;
  63. // Internal Data
  64. bool bShellPosWasDefault;
  65. int nShellCurFrameNum;
  66. #ifdef PVRSHELL_FPS_OUTPUT
  67. bool bOutputFPS;
  68. #endif
  69. };
  70. /*!***************************************************************************
  71. @Class PVRShellCommandLine
  72. @Brief Command-line interpreter
  73. *****************************************************************************/
  74. class PVRShellCommandLine
  75. {
  76. public:
  77. char *m_psOrig, *m_psSplit;
  78. SCmdLineOpt *m_pOpt;
  79. int m_nOptLen, m_nOptMax;
  80. public:
  81. /*!***********************************************************************
  82. @Function PVRShellCommandLine
  83. @Description Constructor
  84. *************************************************************************/
  85. PVRShellCommandLine();
  86. /*!***********************************************************************
  87. @Function PVRShellCommandLine
  88. @Description Destructor
  89. *************************************************************************/
  90. ~PVRShellCommandLine();
  91. /*!***********************************************************************
  92. @Function Set
  93. @Input pStr Input string
  94. @Description Set command-line options to pStr
  95. *************************************************************************/
  96. void Set(const char *pStr);
  97. /*!***********************************************************************
  98. @Function Set
  99. @Input pStr Input string
  100. @Description Prepend command-line options to m_psOrig
  101. *************************************************************************/
  102. void Prefix(const char *pStr);
  103. /*!***********************************************************************
  104. @Function PrependFromFile
  105. @Input pFileName Input string
  106. @Description Prepend command-line options to m_psOrig from a file
  107. *************************************************************************/
  108. bool PrefixFromFile(const char *pFileName);
  109. /*!***********************************************************************
  110. @Function Parse
  111. @Description Parse m_psOrig for command-line options and store them in m_pOpt
  112. *************************************************************************/
  113. void Parse();
  114. /*!***********************************************************************
  115. @Function Apply
  116. @Input shell
  117. @Description Apply the command-line options to shell
  118. *************************************************************************/
  119. void Apply(PVRShell &shell);
  120. };
  121. /*!****************************************************************************
  122. * @Enum EPVRShellState
  123. * @Brief Current Shell state
  124. *****************************************************************************/
  125. enum EPVRShellState {
  126. ePVRShellInitApp,
  127. ePVRShellInitInstance,
  128. ePVRShellRender,
  129. ePVRShellReleaseView,
  130. ePVRShellReleaseAPI,
  131. ePVRShellReleaseOS,
  132. ePVRShellQuitApp,
  133. ePVRShellExit
  134. };
  135. /*!***************************************************************************
  136. * @Class PVRShellInit
  137. * @Brief The PVRShell initialisation class
  138. ****************************************************************************/
  139. class PVRShellInit : public PVRShellInitAPI, public PVRShellInitOS
  140. {
  141. public:
  142. friend class PVRShell;
  143. friend class PVRShellInitOS;
  144. friend class PVRShellInitAPI;
  145. PVRShell *m_pShell; /*!< Our PVRShell class */
  146. PVRShellCommandLine m_CommandLine; /*!< Our Command-line class */
  147. bool gShellDone; /*!< Indicates that the application has finished */
  148. EPVRShellState m_eState; /*!< Current PVRShell state */
  149. // Key handling
  150. PVRShellKeyName nLastKeyPressed; /*!< Holds the last key pressed */
  151. PVRShellKeyName m_eKeyMapLEFT; /*!< Holds the value to be returned when PVRShellKeyNameLEFT is requested */
  152. PVRShellKeyName m_eKeyMapUP; /*!< Holds the value to be returned when PVRShellKeyNameUP is requested */
  153. PVRShellKeyName m_eKeyMapRIGHT; /*!< Holds the value to be returned when PVRShellKeyNameRIGHT is requested */
  154. PVRShellKeyName m_eKeyMapDOWN; /*!< Holds the value to be returned when PVRShellKeyNameDOWN is requested */
  155. // Read and Write path
  156. char *m_pReadPath; /*!<Holds the path where the application will read the data from */
  157. char *m_pWritePath; /*!<Holds the path where the application will write the data to */
  158. unsigned long m_u32ShellStartTime; /*!<Holds the time when the PVRShell instance was created */
  159. #ifdef PVRSHELL_FPS_OUTPUT
  160. // Frames per second (FPS)
  161. int m_i32FpsFrameCnt, m_i32FpsTimePrev;
  162. #endif
  163. public:
  164. /*!***********************************************************************
  165. @Function PVRShellInit
  166. @description Constructor
  167. *************************************************************************/
  168. PVRShellInit();
  169. /*!***********************************************************************
  170. @Function ~PVRShellInit
  171. @description Destructor
  172. *************************************************************************/
  173. ~PVRShellInit();
  174. /*!***********************************************************************
  175. @Function Init
  176. @Returns True on success and false on failure
  177. @description PVRShell Initialisation.
  178. *************************************************************************/
  179. bool Init();
  180. /*!***********************************************************************
  181. @Function Deinit
  182. @Description PVRShell Deinitialisation.
  183. *************************************************************************/
  184. void Deinit();
  185. /*!***********************************************************************
  186. @Function CommandLine
  187. @Input str A string containing the command-line
  188. @description Receives the command-line from the application.
  189. *************************************************************************/
  190. void CommandLine(char *str);
  191. /*!***********************************************************************
  192. @Function CommandLine
  193. @Input argc Number of strings in argv
  194. @Input argv An array of strings
  195. @description Receives the command-line from the application.
  196. *************************************************************************/
  197. void CommandLine(int argc, char **argv);
  198. /*!***********************************************************************
  199. @Function DoIsKeyPressed
  200. @Input key The key we're querying for
  201. @description Return 'true' if the specific key has been pressed.
  202. *************************************************************************/
  203. bool DoIsKeyPressed(const PVRShellKeyName key);
  204. /*!***********************************************************************
  205. @Function KeyPressed
  206. @Input key The key that has been pressed
  207. @description Used by the OS-specific code to tell the Shell that a key has been pressed.
  208. *************************************************************************/
  209. void KeyPressed(PVRShellKeyName key);
  210. /*!***********************************************************************
  211. @Function GetReadPath
  212. @Returns A path the application is capable of reading from
  213. @description Used by the OS-specific code to tell the Shell where to read external files from
  214. *************************************************************************/
  215. const char *GetReadPath() const;
  216. /*!***********************************************************************
  217. @Function GetWritePath
  218. @Returns A path the applications is capable of writing to
  219. @description Used by the OS-specific code to tell the Shell where to write to
  220. *************************************************************************/
  221. const char *GetWritePath() const;
  222. /*!******************************************************************************
  223. @Function SetAppName
  224. @Input str The application name
  225. @Description Sets the default app name (to be displayed by the OS)
  226. *******************************************************************************/
  227. void SetAppName(const char * const str);
  228. /*!***********************************************************************
  229. @Function SetReadPath
  230. @Input str The read path
  231. @description Set the path to where the application expects to read from.
  232. *************************************************************************/
  233. void SetReadPath(const char * const str);
  234. /*!***********************************************************************
  235. @Function SetWritePath
  236. @Input str The write path
  237. @description Set the path to where the application expects to write to.
  238. *************************************************************************/
  239. void SetWritePath(const char * const str);
  240. /*!***********************************************************************
  241. @Function Run
  242. @description Called from the OS-specific code to perform the render.
  243. When this fucntion fails the application will quit.
  244. *************************************************************************/
  245. bool Run();
  246. /*!***********************************************************************
  247. @Function OutputInfo
  248. @description When prefOutputInfo is set to true this function outputs
  249. various pieces of non-API dependent information via
  250. PVRShellOutputDebug.
  251. *************************************************************************/
  252. void OutputInfo();
  253. /*!***********************************************************************
  254. @Function OutputAPIInfo
  255. @description When prefOutputInfo is set to true this function outputs
  256. various pieces of API dependent information via
  257. PVRShellOutputDebug.
  258. *************************************************************************/
  259. void OutputAPIInfo();
  260. #ifdef PVRSHELL_FPS_OUTPUT
  261. /*!****************************************************************************
  262. @Function FpsUpdate
  263. @Description Calculates a value for frames-per-second (FPS).
  264. *****************************************************************************/
  265. void FpsUpdate();
  266. #endif
  267. /*
  268. OS functionality
  269. */
  270. /*!***********************************************************************
  271. @Function OsInit
  272. @description Initialisation for OS-specific code.
  273. *************************************************************************/
  274. void OsInit();
  275. /*!***********************************************************************
  276. @Function OsInitOS
  277. @description Saves instance handle and creates main window
  278. In this function, we save the instance handle in a global variable and
  279. create and display the main program window.
  280. *************************************************************************/
  281. bool OsInitOS();
  282. /*!***********************************************************************
  283. @Function OsReleaseOS
  284. @description Destroys main window
  285. *************************************************************************/
  286. void OsReleaseOS();
  287. /*!***********************************************************************
  288. @Function OsExit
  289. @description Destroys main window
  290. *************************************************************************/
  291. void OsExit();
  292. /*!***********************************************************************
  293. @Function OsDoInitAPI
  294. @description Perform API initialization and bring up window / fullscreen
  295. *************************************************************************/
  296. bool OsDoInitAPI();
  297. /*!***********************************************************************
  298. @Function OsDoReleaseAPI
  299. @description Clean up after we're done
  300. *************************************************************************/
  301. void OsDoReleaseAPI();
  302. /*!***********************************************************************
  303. @Function OsRenderComplete
  304. @description Main message loop / render loop
  305. *************************************************************************/
  306. void OsRenderComplete();
  307. /*!***********************************************************************
  308. @Function OsPixmapCopy
  309. @description When using pixmaps, copy the render to the display
  310. *************************************************************************/
  311. bool OsPixmapCopy();
  312. /*!***********************************************************************
  313. @Function OsGetNativeDisplayType
  314. @description Called from InitAPI() to get the NativeDisplayType
  315. *************************************************************************/
  316. void *OsGetNativeDisplayType();
  317. /*!***********************************************************************
  318. @Function OsGetNativePixmapType
  319. @description Called from InitAPI() to get the NativePixmapType
  320. *************************************************************************/
  321. void *OsGetNativePixmapType();
  322. /*!***********************************************************************
  323. @Function OsGetNativeWindowType
  324. @description Called from InitAPI() to get the NativeWindowType
  325. *************************************************************************/
  326. void *OsGetNativeWindowType();
  327. /*!***********************************************************************
  328. @Function OsGet
  329. @Input prefName Name of value to get
  330. @Modified pn A pointer set to the value asked for
  331. @Returns true on success
  332. @Description Retrieves OS-specific data
  333. *************************************************************************/
  334. bool OsGet(const prefNameIntEnum prefName, int *pn);
  335. /*!***********************************************************************
  336. @Function OsGet
  337. @Input prefName Name of value to get
  338. @Modified pp A pointer set to the value asked for
  339. @Returns true on success
  340. @Description Retrieves OS-specific data
  341. *************************************************************************/
  342. bool OsGet(const prefNamePtrEnum prefName, void **pp);
  343. /*!***********************************************************************
  344. @Function OsSet
  345. @Input prefName Name of value to set
  346. @Input i32Value The value to set our named value to
  347. @Returns true on success
  348. @Description Sets OS-specific data
  349. *************************************************************************/
  350. bool OsSet(const prefNameIntEnum prefName, const int i32Value);
  351. /*!***********************************************************************
  352. @Function OsDisplayDebugString
  353. @Input str The debug string to display
  354. @Description Prints a debug string
  355. *************************************************************************/
  356. void OsDisplayDebugString(char const * const str);
  357. /*!***********************************************************************
  358. @Function OsGetTime
  359. @Description Gets the time in milliseconds
  360. *************************************************************************/
  361. unsigned long OsGetTime();
  362. /*
  363. API functionality
  364. */
  365. /*!***********************************************************************
  366. @Function ApiInitAPI
  367. @description Initialisation for API-specific code.
  368. *************************************************************************/
  369. bool ApiInitAPI();
  370. /*!***********************************************************************
  371. @Function ApiReleaseAPI
  372. @description Releases all resources allocated by the API.
  373. *************************************************************************/
  374. void ApiReleaseAPI();
  375. /*!***********************************************************************
  376. @Function ApiScreenCaptureBuffer
  377. @Input Width Width of the region to capture
  378. @Input Height Height of the region to capture
  379. @Modified pBuf A buffer to put the screen capture into
  380. @description API-specific function to store the current content of the
  381. FrameBuffer into the memory allocated by the user.
  382. *************************************************************************/
  383. bool ApiScreenCaptureBuffer(int Width,int Height,unsigned char *pBuf);
  384. /*!***********************************************************************
  385. @Function ApiRenderComplete
  386. @description Perform API operations required after a frame has finished (e.g., flipping).
  387. *************************************************************************/
  388. void ApiRenderComplete();
  389. /*!***********************************************************************
  390. @Function ApiSet
  391. @Input prefName Name of value to set
  392. @Modified i32Value Value to set it to
  393. @description Set parameters which are specific to the API.
  394. *************************************************************************/
  395. bool ApiSet(const prefNameIntEnum prefName, const int i32Value);
  396. /*!***********************************************************************
  397. @Function ApiGet
  398. @Input prefName Name of value to get
  399. @Modified pn A pointer set to the value asked for
  400. @description Get parameters which are specific to the API.
  401. *************************************************************************/
  402. bool ApiGet(const prefNameIntEnum prefName, int *pn);
  403. /*!***********************************************************************
  404. @Function ApiGet
  405. @Input prefName Name of value to get
  406. @Modified pp A pointer set to the value asked for
  407. @description Get parameters which are specific to the API.
  408. *************************************************************************/
  409. bool ApiGet(const prefNamePtrEnum prefName, void **pp);
  410. /*!***********************************************************************
  411. @Function ApiActivatePreferences
  412. @description Run specific API code to perform the operations requested in preferences.
  413. *************************************************************************/
  414. void ApiActivatePreferences();
  415. };
  416. #endif /* __PVRSHELLIMPL_H_ */
  417. /*****************************************************************************
  418. End of file (PVRShellImpl.h)
  419. *****************************************************************************/