12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679 |
- /******************************************************************************
- @File PVRShell.cpp
- @Title PVRShell
- @Version
- @Copyright Copyright (C) Imagination Technologies Limited.
- @Platform Independent
- @Description Makes programming for 3D APIs easier by wrapping surface
- initialization, Texture allocation and other functions for use by a demo.
- ******************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdarg.h>
- #include "PVRShell.h"
- #include "PVRShellOS.h"
- #include "PVRShellAPI.h"
- #include "PVRShellImpl.h"
- /*! This file simply defines a version string. It can be commented out. */
- #include "../Builds/sdkver.h"
- #ifndef PVRSDK_VERSION
- #define PVRSDK_VERSION "n.nn.nn.nnnn"
- #endif
- /*! Define to automatically stop the app after x frames. If negative, run forever. */
- #ifndef PVRSHELL_QUIT_AFTER_FRAME
- #define PVRSHELL_QUIT_AFTER_FRAME -1
- #endif
- /*! Define to automatically stop the app after x amount of seconds. If negative, run forever. */
- #ifndef PVRSHELL_QUIT_AFTER_TIME
- #define PVRSHELL_QUIT_AFTER_TIME -1
- #endif
- /*! Define for the screen shot file name. */
- #define PVRSHELL_SCREENSHOT_NAME "PVRShell"
- #if defined(_WIN32) && !defined(__BADA__)
- #define snprintf _snprintf
- #endif
- /*****************************************************************************
- ** Prototypes
- *****************************************************************************/
- static bool StringCopy(char *&pszStr, const char * const pszSrc);
- /****************************************************************************
- ** Class: PVRShell
- ****************************************************************************/
- /*!***********************************************************************
- @Function PVRShell
- @Description Constructor
- *************************************************************************/
- PVRShell::PVRShell()
- {
- m_pShellInit = NULL;
- m_pShellData = new PVRShellData;
- m_pShellData->nShellPosX=0;
- m_pShellData->nShellPosY=0;
- m_pShellData->bFullScreen=false; // note this may be overriden by some OS versions of PVRShell
- m_pShellData->nFSAAMode=0;
- m_pShellData->nColorBPP = 0;
- m_pShellData->nDepthBPP = 0;
- m_pShellData->nDieAfterFrames=PVRSHELL_QUIT_AFTER_FRAME;
- m_pShellData->fDieAfterTime=PVRSHELL_QUIT_AFTER_TIME;
- m_pShellData->bNeedPbuffer = false;
- m_pShellData->bNeedPixmap = false;
- m_pShellData->bNeedPixmapDisableCopy = false;
- m_pShellData->bNeedZbuffer = true;
- m_pShellData->bLockableBackBuffer = false;
- m_pShellData->bSoftwareRender = false;
- m_pShellData->bNeedStencilBuffer = false;
- m_pShellData->bNeedOpenVG = false;
- m_pShellData->bNeedAlphaFormatPre = false;
- m_pShellData->bUsingPowerSaving = true;
- m_pShellData->bOutputInfo = false;
- m_pShellData->bNoShellSwapBuffer = false;
- m_pShellData->pszAppName = 0;
- m_pShellData->pszExitMessage = 0;
- m_pShellData->nSwapInterval = 1;
- m_pShellData->nInitRepeats = 0;
- m_pShellData->nCaptureFrameStart = -1;
- m_pShellData->nCaptureFrameStop = -1;
- m_pShellData->nPriority = 2;
- // Internal Data
- m_pShellData->bShellPosWasDefault = true;
- m_pShellData->nShellCurFrameNum = 0;
- #ifdef PVRSHELL_FPS_OUTPUT
- m_pShellData->bOutputFPS = false;
- #endif
- }
- /*!***********************************************************************
- @Function ~PVRShell
- @Description Destructor
- *************************************************************************/
- PVRShell::~PVRShell()
- {
- delete m_pShellData;
- m_pShellData = NULL;
- }
- // Allow user to set preferences from within InitApplication
- /*!***********************************************************************
- @Function PVRShellSet
- @Input prefName Name of preference to set to value
- @Input value Value
- @Return true for success
- @Description This function is used to pass preferences to the PVRShell.
- If used, it must be called from InitApplication().
- *************************************************************************/
- bool PVRShell::PVRShellSet(const prefNameBoolEnum prefName, const bool value)
- {
- switch(prefName)
- {
- case prefFullScreen:
- m_pShellData->bFullScreen = value;
- return true;
- case prefPBufferContext:
- m_pShellData->bNeedPbuffer = value;
- return true;
- case prefPixmapContext:
- m_pShellData->bNeedPixmap = value;
- return true;
- case prefPixmapDisableCopy:
- m_pShellData->bNeedPixmapDisableCopy = value;
- return true;
- case prefZbufferContext:
- m_pShellData->bNeedZbuffer = value;
- return true;
- case prefLockableBackBuffer:
- m_pShellData->bLockableBackBuffer = value;
- return true;
- case prefSoftwareRendering:
- m_pShellData->bSoftwareRender = value;
- return true;
- case prefStencilBufferContext:
- m_pShellData->bNeedStencilBuffer = value;
- return true;
- case prefOpenVGContext:
- m_pShellData->bNeedOpenVG = value;
- return true;
- case prefAlphaFormatPre:
- m_pShellData->bNeedAlphaFormatPre = value;
- return true;
- case prefPowerSaving:
- m_pShellData->bUsingPowerSaving = value;
- return true;
- case prefOutputInfo:
- m_pShellData->bOutputInfo = value;
- return true;
- case prefNoShellSwapBuffer:
- m_pShellData->bNoShellSwapBuffer = value;
- return true;
- #ifdef PVRSHELL_FPS_OUTPUT
- case prefOutputFPS:
- m_pShellData->bOutputFPS = value;
- return true;
- #endif
- default:
- break;
- }
- return false;
- }
- /*!***********************************************************************
- @Function PVRShellGet
- @Input prefName Name of preference to set to value
- @Return Value asked for.
- @Description This function is used to get parameters from the PVRShell
- It can be called from any where in the program.
- *************************************************************************/
- bool PVRShell::PVRShellGet(const prefNameBoolEnum prefName) const
- {
- switch(prefName)
- {
- case prefFullScreen: return m_pShellData->bFullScreen;
- case prefIsRotated: return (m_pShellData->nShellDimY > m_pShellData->nShellDimX);
- case prefPBufferContext: return m_pShellData->bNeedPbuffer;
- case prefPixmapContext: return m_pShellData->bNeedPixmap;
- case prefPixmapDisableCopy: return m_pShellData->bNeedPixmapDisableCopy;
- case prefZbufferContext: return m_pShellData->bNeedZbuffer;
- case prefLockableBackBuffer: return m_pShellData->bLockableBackBuffer;
- case prefSoftwareRendering: return m_pShellData->bSoftwareRender;
- case prefNoShellSwapBuffer: return m_pShellData->bNoShellSwapBuffer;
- case prefStencilBufferContext: return m_pShellData->bNeedStencilBuffer;
- case prefOpenVGContext: return m_pShellData->bNeedOpenVG;
- case prefAlphaFormatPre: return m_pShellData->bNeedAlphaFormatPre;
- case prefPowerSaving: return m_pShellData->bUsingPowerSaving;
- case prefOutputInfo: return m_pShellData->bOutputInfo;
- #ifdef PVRSHELL_FPS_OUTPUT
- case prefOutputFPS: return m_pShellData->bOutputFPS;
- #endif
- default: return false;
- }
- }
- /*!***********************************************************************
- @Function PVRShellSet
- @Input prefName Name of preference to set to value
- @Input value Value
- @Return true for success
- @Description This function is used to pass preferences to the PVRShell.
- If used, it must be called from InitApplication().
- *************************************************************************/
- bool PVRShell::PVRShellSet(const prefNameFloatEnum prefName, const float value)
- {
- switch(prefName)
- {
- case prefQuitAfterTime:
- m_pShellData->fDieAfterTime = value;
- return true;
- default:
- break;
- }
- return false;
- }
- /*!***********************************************************************
- @Function PVRShellGet
- @Input prefName Name of preference to set to value
- @Return Value asked for.
- @Description This function is used to get parameters from the PVRShell
- It can be called from any where in the program.
- *************************************************************************/
- float PVRShell::PVRShellGet(const prefNameFloatEnum prefName) const
- {
- switch(prefName)
- {
- case prefQuitAfterTime: return m_pShellData->fDieAfterTime;
- default: return -1;
- }
- }
- /*!***********************************************************************
- @Function PVRShellSet
- @Input prefName Name of preference to set to value
- @Input value Value
- @Return true for success
- @Description This function is used to pass preferences to the PVRShell.
- If used, it must be called from InitApplication().
- *************************************************************************/
- bool PVRShell::PVRShellSet(const prefNameIntEnum prefName, const int value)
- {
- switch(prefName)
- {
- case prefWidth:
- if(value > 0)
- {
- m_pShellData->nShellDimX = value;
- return true;
- }
- return false;
- case prefHeight:
- if(value > 0)
- {
- m_pShellData->nShellDimY = value;
- return true;
- }
- return false;
- case prefPositionX:
- m_pShellData->bShellPosWasDefault = false;
- m_pShellData->nShellPosX = value;
- return true;
- case prefPositionY:
- m_pShellData->bShellPosWasDefault = false;
- m_pShellData->nShellPosY = value;
- return true;
- case prefQuitAfterFrame:
- m_pShellData->nDieAfterFrames = value;
- return true;
- case prefInitRepeats:
- m_pShellData->nInitRepeats = value;
- return true;
- case prefFSAAMode:
- if(value >= 0 && value <= 2)
- {
- m_pShellData->nFSAAMode = value;
- return true;
- }
- return false;
- case prefColorBPP:
- if(value >= 0)
- {
- m_pShellData->nColorBPP = value;
- return true;
- }
- return false;
- case prefDepthBPP:
- if(value >= 0)
- {
- m_pShellData->nDepthBPP = value;
- return true;
- }
- return false;
- case prefRotateKeys:
- {
- switch((PVRShellKeyRotate)value)
- {
- case PVRShellKeyRotateNone:
- m_pShellInit->m_eKeyMapUP = PVRShellKeyNameUP;
- m_pShellInit->m_eKeyMapLEFT = PVRShellKeyNameLEFT;
- m_pShellInit->m_eKeyMapDOWN = PVRShellKeyNameDOWN;
- m_pShellInit->m_eKeyMapRIGHT = PVRShellKeyNameRIGHT;
- break;
- case PVRShellKeyRotate90:
- m_pShellInit->m_eKeyMapUP = PVRShellKeyNameLEFT;
- m_pShellInit->m_eKeyMapLEFT = PVRShellKeyNameDOWN;
- m_pShellInit->m_eKeyMapDOWN = PVRShellKeyNameRIGHT;
- m_pShellInit->m_eKeyMapRIGHT = PVRShellKeyNameUP;
- break;
- case PVRShellKeyRotate180:
- m_pShellInit->m_eKeyMapUP = PVRShellKeyNameDOWN;
- m_pShellInit->m_eKeyMapLEFT = PVRShellKeyNameRIGHT;
- m_pShellInit->m_eKeyMapDOWN = PVRShellKeyNameUP;
- m_pShellInit->m_eKeyMapRIGHT = PVRShellKeyNameLEFT;
- break;
- case PVRShellKeyRotate270:
- m_pShellInit->m_eKeyMapUP = PVRShellKeyNameRIGHT;
- m_pShellInit->m_eKeyMapLEFT = PVRShellKeyNameUP;
- m_pShellInit->m_eKeyMapDOWN = PVRShellKeyNameLEFT;
- m_pShellInit->m_eKeyMapRIGHT = PVRShellKeyNameDOWN;
- break;
- default:
- return false;
- }
- }
- return true;
- case prefCaptureFrameStart:
- m_pShellData->nCaptureFrameStart = value;
- return true;
- case prefCaptureFrameStop:
- m_pShellData->nCaptureFrameStop = value;
- return true;
- default:
- {
- if(m_pShellInit->ApiSet(prefName, value))
- return true;
- return m_pShellInit->OsSet(prefName, value);
- }
- }
- }
- /*!***********************************************************************
- @Function PVRShellGet
- @Input prefName Name of preference to return the value of
- @Return Value asked for.
- @Description This function is used to get parameters from the PVRShell
- It can be called from any where in the program.
- *************************************************************************/
- int PVRShell::PVRShellGet(const prefNameIntEnum prefName) const
- {
- switch(prefName)
- {
- case prefWidth: return m_pShellData->nShellDimX;
- case prefHeight: return m_pShellData->nShellDimY;
- case prefPositionX: return m_pShellData->nShellPosX;
- case prefPositionY: return m_pShellData->nShellPosY;
- case prefQuitAfterFrame: return m_pShellData->nDieAfterFrames;
- case prefSwapInterval: return m_pShellData->nSwapInterval;
- case prefInitRepeats: return m_pShellData->nInitRepeats;
- case prefFSAAMode: return m_pShellData->nFSAAMode;
- case prefCommandLineOptNum: return m_pShellInit->m_CommandLine.m_nOptLen;
- case prefColorBPP: return m_pShellData->nColorBPP;
- case prefDepthBPP: return m_pShellData->nDepthBPP;
- case prefCaptureFrameStart: return m_pShellData->nCaptureFrameStart;
- case prefCaptureFrameStop: return m_pShellData->nCaptureFrameStop;
- case prefPriority: return m_pShellData->nPriority;
- default:
- {
- int n;
- if(m_pShellInit->ApiGet(prefName, &n))
- return n;
- if(m_pShellInit->OsGet(prefName, &n))
- return n;
- return -1;
- }
- }
- }
- /*!***********************************************************************
- @Function PVRShellSet
- @Input prefName Name of preference to set to value
- @Input ptrValue Value
- @Return true for success
- @Description This function is used to pass preferences to the PVRShell.
- If used, it must be called from InitApplication().
- *************************************************************************/
- bool PVRShell::PVRShellSet(const prefNamePtrEnum prefName, const void * const ptrValue)
- {
- PVRSHELL_UNREFERENCED_PARAMETER(prefName);
- PVRSHELL_UNREFERENCED_PARAMETER(ptrValue);
- return false;
- }
- /*!***********************************************************************
- @Function PVRShellGet
- @Input prefName Name of preference to set to value
- @Return Value asked for.
- @Description This function is used to get parameters from the PVRShell
- It can be called from any where in the program.
- *************************************************************************/
- void *PVRShell::PVRShellGet(const prefNamePtrEnum prefName) const
- {
- switch(prefName)
- {
- case prefNativeWindowType: return m_pShellInit->OsGetNativeWindowType();
- default:
- {
- void *p;
- if(m_pShellInit->ApiGet(prefName, &p))
- return p;
- if(m_pShellInit->OsGet(prefName, &p))
- return p;
- return NULL;
- }
- }
- }
- /*!***********************************************************************
- @Function PVRShellSet
- @Input prefName Name of preference to set to value
- @Input ptrValue Value
- @Return true for success
- @Description This function is used to pass preferences to the PVRShell.
- If used, it must be called from InitApplication().
- *************************************************************************/
- bool PVRShell::PVRShellSet(const prefNameConstPtrEnum prefName, const void * const ptrValue)
- {
- switch(prefName)
- {
- case prefAppName:
- StringCopy(m_pShellData->pszAppName, (char*)ptrValue);
- return true;
- case prefExitMessage:
- StringCopy(m_pShellData->pszExitMessage, (char*)ptrValue);
- PVRShellOutputDebug("Exit message has been set to: \"%s\".\n", ptrValue);
- return true;
- default:
- break;
- }
- return false;
- }
- /*!***********************************************************************
- @Function PVRShellGet
- @Input prefName Name of preference to set to value
- @Return Value asked for.
- @Description This function is used to get parameters from the PVRShell
- It can be called from any where in the program.
- *************************************************************************/
- const void *PVRShell::PVRShellGet(const prefNameConstPtrEnum prefName) const
- {
- switch(prefName)
- {
- case prefAppName:
- return m_pShellData->pszAppName;
- case prefExitMessage:
- return m_pShellData->pszExitMessage;
- case prefReadPath:
- return m_pShellInit->GetReadPath();
- case prefWritePath:
- return m_pShellInit->GetWritePath();
- case prefCommandLine:
- return m_pShellInit->m_CommandLine.m_psOrig;
- case prefCommandLineOpts:
- return m_pShellInit->m_CommandLine.m_pOpt;
- case prefVersion:
- return PVRSDK_VERSION;
- default:
- return 0;
- }
- }
- /*!***********************************************************************
- @Function PVRShellScreenCaptureBuffer
- @Input Width size of image to capture (relative to 0,0)
- @Input Height size of image to capture (relative to 0,0)
- @Modified pLines receives a pointer to an area of memory containing the screen buffer.
- @Return true for success
- @Description It will be stored as 24-bit per pixel, 8-bit per chanel RGB. The
- memory should be freed with free() when no longer needed.
- *************************************************************************/
- bool PVRShell::PVRShellScreenCaptureBuffer(const int Width, const int Height, unsigned char **pLines)
- {
- int Pitch;
- /* Compute line pitch */
- Pitch = 3*Width;
- if ( ((3*Width)%4)!=0 )
- {
- Pitch += 4-((3*Width)%4);
- }
- /* Allocate memory for line */
- *pLines=(unsigned char *)calloc(Pitch*Height, sizeof(unsigned char));
- if (!(*pLines)) return false;
- return m_pShellInit->ApiScreenCaptureBuffer(Width, Height, *pLines);
- }
- /*!***********************************************************************
- @Function PVRShellScreenSave
- @Input fname base of file to save screen to
- @Output ofname If non-NULL, receives the filename actually used
- @Modified pLines image data to write out (24bpp, 8-bit per channel RGB)
- @Return true for success
- @Description Writes out the image data to a BMP file with basename
- fname. The file written will be fname suffixed with a
- number to make the file unique.
- For example, if fname is "abc", this function will attempt
- to save to "abc0000.bmp"; if that file already exists, it
- will try "abc0001.bmp", repeating until a new filename is
- found. The final filename used is returned in ofname.
- *************************************************************************/
- int PVRShell::PVRShellScreenSave(
- const char * const fname,
- const unsigned char * const pLines,
- char * const ofname)
- {
- FILE *file = 0;
- const char *pszWritePath;
- char *pszFileName;
- int nScreenshotCount;
- int dwWidth = m_pShellData->nShellDimX;
- int dwHeight= m_pShellData->nShellDimY;
- int error;
- pszWritePath = (const char*)PVRShellGet(prefWritePath);
- int nFileNameSize = strlen(pszWritePath) + 200;
- pszFileName = (char*)malloc(nFileNameSize);
- /* Look for the first file name that doesn't already exist */
- for(nScreenshotCount = 0; nScreenshotCount < 10000; ++nScreenshotCount)
- {
- #if defined(__SYMBIAN32__) || defined(UITRON) || defined(_UITRON_)
- sprintf(pszFileName, "%s%s%04d.bmp", pszWritePath, fname, nScreenshotCount);
- #else
- snprintf(pszFileName, nFileNameSize, "%s%s%04d.bmp", pszWritePath, fname, nScreenshotCount);
- #endif
- file = fopen(pszFileName,"r");
- if(!file)
- break;
- fclose(file);
- }
- /* If all files already exist, replace the first one */
- if (nScreenshotCount==10000)
- {
- #if defined(__SYMBIAN32__) || defined(UITRON) || defined(_UITRON_)
- sprintf(pszFileName, "%s%s0000.bmp", pszWritePath, fname);
- #else
- snprintf(pszFileName, nFileNameSize, "%s%s0000.bmp", pszWritePath, fname);
- #endif
- PVRShellOutputDebug("PVRShell: *WARNING* : Overwriting %s\n", pszFileName);
- }
- if(ofname) // requested the output file name
- {
- strcpy(ofname, pszFileName);
- }
- error = PVRShellWriteBMPFile(pszFileName, dwWidth, dwHeight, pLines);
- FREE(pszFileName);
- if (error)
- {
- return 10*error+1;
- }
- else
- {
- // No problem occured
- return 0;
- }
- }
- /*!***********************************************************************
- @Function PVRShellByteSwap
- @Input pBytes The bytes to swap
- @Input i32ByteNo The number of bytes to swap
- @Description Swaps the bytes in pBytes from little to big endian (or vice versa)
- *************************************************************************/
- inline void PVRShellByteSwap(unsigned char* pBytes, int i32ByteNo)
- {
- int i = 0, j = i32ByteNo - 1;
- while(i < j)
- {
- unsigned char cTmp = pBytes[i];
- pBytes[i] = pBytes[j];
- pBytes[j] = cTmp;
- ++i;
- --j;
- }
- }
- /*!***********************************************************************
- @Function PVRShellWriteBMPFile
- @Input pszFilename file to save screen to
- @Input uWidth the width of the data
- @Input uHeight the height of the data
- @Input pImageData image data to write out (24bpp, 8-bit per channel RGB)
- @Return 0 on success
- @Description Writes out the image data to a BMP file with name fname.
- *************************************************************************/
- const int g_i32BMPHeaderSize = 14; /*!< The size of a BMP header */
- const int g_i32BMPInfoSize = 40; /*!< The size of a BMP info header */
- int PVRShell::PVRShellWriteBMPFile(
- const char * const pszFilename,
- const unsigned long uWidth,
- const unsigned long uHeight,
- const void * const pImageData)
- {
- #define ByteSwap(x) PVRShellByteSwap((unsigned char*) &x, sizeof(x))
- int Result = 1;
- unsigned int i,j;
- FILE* fpDumpfile = 0;
- fpDumpfile = fopen(pszFilename, "wb");
- if (fpDumpfile != 0)
- {
- short int word = 0x0001;
- char *byte = (char*) &word;
- bool bLittleEndian = byte[0] ? true : false;
- int i32Line = uWidth * 3;
- int i32BytesPerLine = i32Line;
- unsigned int i32Align = 0;
- // round up to a dword boundary
- if(i32BytesPerLine & 3)
- {
- i32BytesPerLine |= 3;
- ++i32BytesPerLine;
- i32Align = i32BytesPerLine - i32Line;
- }
- int i32RealSize = i32BytesPerLine *uHeight;
- // BMP Header
- unsigned short bfType = 0x4D42;
- unsigned long bfSize = g_i32BMPHeaderSize + g_i32BMPInfoSize + i32RealSize;
- unsigned short bfReserved1 = 0;
- unsigned short bfReserved2 = 0;
- unsigned long bfOffBits = g_i32BMPHeaderSize + g_i32BMPInfoSize;
- // BMP Info Header
- unsigned long biSize = g_i32BMPInfoSize;
- unsigned long biWidth = uWidth;
- unsigned long biHeight = uHeight;
- unsigned short biPlanes = 1;
- unsigned short biBitCount = 24;
- unsigned long biCompression = 0L;
- unsigned long biSizeImage = i32RealSize;
- unsigned long biXPelsPerMeter = 0;
- unsigned long biYPelsPerMeter = 0;
- unsigned long biClrUsed = 0;
- unsigned long biClrImportant = 0;
- unsigned char *pData = (unsigned char*) pImageData;
- if(!bLittleEndian)
- {
- for(i = 0; i < uWidth * uHeight; ++i)
- PVRShellByteSwap(pData + (3 * i), 3);
- ByteSwap(bfType);
- ByteSwap(bfSize);
- ByteSwap(bfOffBits);
- ByteSwap(biSize);
- ByteSwap(biWidth);
- ByteSwap(biHeight);
- ByteSwap(biPlanes);
- ByteSwap(biBitCount);
- ByteSwap(biCompression);
- ByteSwap(biSizeImage);
- }
- // Write Header.
- fwrite(&bfType , 1, sizeof(bfType) , fpDumpfile);
- fwrite(&bfSize , 1, sizeof(bfSize) , fpDumpfile);
- fwrite(&bfReserved1 , 1, sizeof(bfReserved1), fpDumpfile);
- fwrite(&bfReserved2 , 1, sizeof(bfReserved2), fpDumpfile);
- fwrite(&bfOffBits , 1, sizeof(bfOffBits) , fpDumpfile);
- // Write info header.
- fwrite(&biSize , 1, sizeof(biSize) , fpDumpfile);
- fwrite(&biWidth , 1, sizeof(biWidth) , fpDumpfile);
- fwrite(&biHeight , 1, sizeof(biHeight) , fpDumpfile);
- fwrite(&biPlanes , 1, sizeof(biPlanes) , fpDumpfile);
- fwrite(&biBitCount , 1, sizeof(biBitCount) , fpDumpfile);
- fwrite(&biCompression , 1, sizeof(biCompression) , fpDumpfile);
- fwrite(&biSizeImage , 1, sizeof(biSizeImage) , fpDumpfile);
- fwrite(&biXPelsPerMeter , 1, sizeof(biXPelsPerMeter), fpDumpfile);
- fwrite(&biYPelsPerMeter , 1, sizeof(biYPelsPerMeter), fpDumpfile);
- fwrite(&biClrUsed , 1, sizeof(biClrUsed) , fpDumpfile);
- fwrite(&biClrImportant , 1, sizeof(biClrImportant) , fpDumpfile);
- unsigned char align = 0x00;
- // Write image.
- if(i32Align == 0)
- {
- fwrite(pData, 1, i32RealSize, fpDumpfile);
- }
- else
- {
- for(i = 0; i < uHeight; i++)
- {
- pData += fwrite(pData, 1, i32Line, fpDumpfile);
- for(j = 0; j < i32Align; ++j)
- fwrite(&align, 1, 1, fpDumpfile);
- }
- }
- // Last but not least close the file.
- fclose(fpDumpfile);
- Result = 0;
- }
- else
- {
- PVRShellOutputDebug("PVRShell: Failed to open \"%s\" for writing screen dump.\n", pszFilename);
- }
- return Result;
- }
- /*!***********************************************************************
- @Function PVRShellGetTime
- @Returns A value which increments once per millisecond.
- @Description The number itself should be considered meaningless; an
- application should use this function to determine how much
- time has passed between two points (e.g. between each
- frame).
- *************************************************************************/
- unsigned long PVRShell::PVRShellGetTime()
- {
- // Read timer from a platform dependant function
- return m_pShellInit->OsGetTime()-m_pShellInit->m_u32ShellStartTime;
- }
- /*!***********************************************************************
- @Function PVRShellIsKeyPressed
- @Input key Code of the key to test
- @Return true if key was pressed
- @Description Check if a key was pressed. The keys on various devices
- are mapped to the PVRShell-supported keys (listed in @a PVRShellKeyName) in
- a platform-dependent manner, since most platforms have different input
- devices. Check the SDK release notes for details on how the enum values
- map to your device's input device.
- *************************************************************************/
- bool PVRShell::PVRShellIsKeyPressed(const PVRShellKeyName key)
- {
- if(!m_pShellInit)
- return false;
- return m_pShellInit->DoIsKeyPressed(key);
- }
- /*!****************************************************************************
- * @Class PVRShellCommandLine
- *****************************************************************************/
- /*!***********************************************************************
- @Function PVRShellCommandLine
- @Description Constructor
- *************************************************************************/
- PVRShellCommandLine::PVRShellCommandLine()
- {
- memset(this, 0, sizeof(*this));
- }
- /*!***********************************************************************
- @Function PVRShellCommandLine
- @Description Destructor
- *************************************************************************/
- PVRShellCommandLine::~PVRShellCommandLine()
- {
- delete [] m_psOrig;
- delete [] m_psSplit;
- FREE(m_pOpt);
- }
- /*!***********************************************************************
- @Function Set
- @Input pStr Input string
- @Description Set command-line options to pStr
- *************************************************************************/
- void PVRShellCommandLine::Set(const char *pStr)
- {
- delete [] m_psOrig;
- m_psOrig = 0;
- if(pStr)
- {
- size_t len = strlen(pStr)+1;
- m_psOrig = new char[len];
- strcpy(m_psOrig, pStr);
- }
- }
- /*!***********************************************************************
- @Function Prefix
- @Input pStr Input string
- @Description Prepend command-line options to m_psOrig
- *************************************************************************/
- void PVRShellCommandLine::Prefix(const char *pStr)
- {
- if(!m_psOrig)
- Set(pStr);
- else if(!pStr)
- return;
- else
- {
- char *pstmp = m_psOrig;
- size_t lenA = strlen(pStr);
- size_t TotalLen = lenA + 1 + strlen(m_psOrig);
- m_psOrig = new char[TotalLen + 1];
- strcpy(m_psOrig, pStr);
- m_psOrig[lenA] = ' ';
- strcpy(m_psOrig + lenA + 1, pstmp);
- m_psOrig[TotalLen] = '\0';
- delete[] pstmp;
- }
- }
- /*!***********************************************************************
- @Function PrefixFromFile
- @Input pFileName Input string
- @Description Prepend command-line options to m_psOrig from a file
- *************************************************************************/
- bool PVRShellCommandLine::PrefixFromFile(const char *pFileName)
- {
- char* nl;
- FILE *pFile = fopen(pFileName, "rb");
- if(pFile)
- {
- // Get the file size
- fseek(pFile, 0, SEEK_END);
- long m_Size = ftell(pFile) + 2;
- fseek(pFile, 0, SEEK_SET);
- char *pFullFile = new char[m_Size];
- if(pFullFile)
- {
- size_t offset = 0;
- while(fgets(pFullFile + offset, (int) (m_Size - offset), pFile))
- {
- offset = strlen(pFullFile);
- // Replace new lines with spaces
- nl = strrchr(pFullFile, '\r');
- if(nl) *nl = ' ';
- nl = strrchr(pFullFile, '\n');
- if(nl) *nl = ' ';
- }
- pFullFile[offset] = '\0';
- Prefix(pFullFile);
- delete[] pFullFile;
- fclose(pFile);
- return true;
- }
- fclose(pFile);
- }
- return false;
- }
- /*!***********************************************************************
- @Function Parse
- @Description Parse m_psOrig for command-line options and store them in m_pOpt
- *************************************************************************/
- void PVRShellCommandLine::Parse()
- {
- size_t len;
- int nIn, nOut;
- bool bInQuotes;
- SCmdLineOpt opt;
- if(!m_psOrig)
- return;
- // Tidy up any options we have already parsed
- delete [] m_psSplit;
- FREE(m_pOpt);
- // Take a copy to be edited
- len = strlen(m_psOrig) + 1;
- m_psSplit = new char[len];
- // Break the command line into options
- bInQuotes = false;
- opt.pArg = NULL;
- opt.pVal = NULL;
- nIn = -1;
- nOut = 0;
- do
- {
- ++nIn;
- if(m_psOrig[nIn] == '"')
- {
- bInQuotes = !bInQuotes;
- }
- else
- {
- if(bInQuotes && m_psOrig[nIn] != 0)
- {
- if(!opt.pArg)
- opt.pArg = &m_psSplit[nOut];
- m_psSplit[nOut++] = m_psOrig[nIn];
- }
- else
- {
- switch(m_psOrig[nIn])
- {
- case '=':
- m_psSplit[nOut++] = 0;
- opt.pVal = &m_psSplit[nOut];
- break;
- case ' ':
- case '\t':
- case '\0':
- m_psSplit[nOut++] = 0;
- if(opt.pArg || opt.pVal)
- {
- // Increase list length if necessary
- if(m_nOptLen == m_nOptMax)
- m_nOptMax = m_nOptMax * 2 + 1;
- m_pOpt = (SCmdLineOpt*)realloc(m_pOpt, m_nOptMax * sizeof(*m_pOpt));
- if(!m_pOpt)
- return;
- // Add option to list
- m_pOpt[m_nOptLen++] = opt;
- opt.pArg = NULL;
- opt.pVal = NULL;
- }
- break;
- default:
- if(!opt.pArg)
- opt.pArg = &m_psSplit[nOut];
- m_psSplit[nOut++] = m_psOrig[nIn];
- break;
- }
- }
- }
- } while(m_psOrig[nIn]);
- }
- /*!***********************************************************************
- @Function Apply
- @Input shell
- @Description Apply the command-line options to shell
- *************************************************************************/
- void PVRShellCommandLine::Apply(PVRShell &shell)
- {
- int i;
- const char *arg, *val;
- for(i = 0; i < m_nOptLen; ++i)
- {
- arg = m_pOpt[i].pArg;
- val = m_pOpt[i].pVal;
- if(!arg)
- continue;
- if(val)
- {
- if(_stricmp(arg, "-width") == 0)
- {
- shell.PVRShellSet(prefWidth, atoi(val));
- }
- else if(_stricmp(arg, "-height") == 0)
- {
- shell.PVRShellSet(prefHeight, atoi(val));
- }
- else if(_stricmp(arg, "-FSAAMode") == 0 || _stricmp(arg, "-aa") == 0)
- {
- shell.PVRShellSet(prefFSAAMode, atoi(val));
- }
- else if(_stricmp(arg, "-fullscreen") == 0)
- {
- shell.PVRShellSet(prefFullScreen, (atoi(val) != 0));
- }
- else if(_stricmp(arg, "-sw") == 0)
- {
- shell.PVRShellSet(prefSoftwareRendering, (atoi(val) != 0));
- }
- else if(_stricmp(arg, "-quitafterframe") == 0 || _stricmp(arg, "-qaf") == 0)
- {
- shell.PVRShellSet(prefQuitAfterFrame, atoi(val));
- }
- else if(_stricmp(arg, "-quitaftertime") == 0 || _stricmp(arg, "-qat") == 0)
- {
- shell.PVRShellSet(prefQuitAfterTime, (float)atof(val));
- }
- else if(_stricmp(arg, "-posx") == 0)
- {
- shell.PVRShellSet(prefPositionX, atoi(val));
- }
- else if(_stricmp(arg, "-posy") == 0)
- {
- shell.PVRShellSet(prefPositionY, atoi(val));
- }
- else if(_stricmp(arg, "-vsync") == 0)
- {
- shell.PVRShellSet(prefSwapInterval, atoi(val));
- }
- else if(_stricmp(arg, "-powersaving") == 0 || _stricmp(arg, "-ps") == 0)
- {
- shell.PVRShellSet(prefPowerSaving, (atoi(val) != 0));
- }
- else if(_stricmp(arg, "-colourbpp") == 0 || _stricmp(arg, "-colorbpp") == 0 ||_stricmp(arg, "-cbpp") == 0)
- {
- shell.PVRShellSet(prefColorBPP, atoi(val));
- }
- else if(_stricmp(arg, "-depthbpp") == 0 || _stricmp(arg, "-dbpp") == 0)
- {
- shell.PVRShellSet(prefDepthBPP, atoi(val));
- }
- else if(_stricmp(arg, "-rotatekeys") == 0)
- {
- shell.PVRShellSet(prefRotateKeys, atoi(val));
- }
- else if(_stricmp(arg, "-c") == 0)
- {
- const char* pDash = strchr(val, '-');
- shell.PVRShellSet(prefCaptureFrameStart, atoi(val));
- if(!pDash)
- shell.PVRShellSet(prefCaptureFrameStop, atoi(val));
- else
- shell.PVRShellSet(prefCaptureFrameStop, atoi(pDash + 1));
- }
- else if(_stricmp(arg, "-priority") == 0)
- {
- shell.PVRShellSet(prefPriority, atoi(val));
- }
- else if(_stricmp(arg, "-config") == 0)
- {
- shell.PVRShellSet(prefRequestedConfig, atoi(val));
- }
- else if(_stricmp(arg, "-display") == 0)
- {
- shell.PVRShellSet(prefNativeDisplay, atoi(val));
- }
- }
- else
- {
- if(_stricmp(arg, "-version") == 0)
- {
- shell.PVRShellOutputDebug("Version: \"%s\"\n", shell.PVRShellGet(prefVersion));
- }
- #ifdef PVRSHELL_FPS_OUTPUT
- else if(_stricmp(arg, "-fps") == 0)
- {
- shell.PVRShellSet(prefOutputFPS, true);
- }
- #endif
- else if(_stricmp(arg, "-info") == 0)
- {
- shell.PVRShellSet(prefOutputInfo, true);
- }
- }
- }
- }
- /*!***************************************************************************
- * @Class PVRShellInit
- ****************************************************************************/
- /*!***********************************************************************
- @Function PVRShellInit
- @Description Constructor
- *************************************************************************/
- PVRShellInit::PVRShellInit()
- {
- memset(this, 0, sizeof(*this));
- }
- /*!***********************************************************************
- @Function ~PVRShellInit
- @Description Destructor
- *************************************************************************/
- PVRShellInit::~PVRShellInit()
- {
- Deinit();
- delete [] m_pReadPath;
- m_pReadPath = NULL;
- delete [] m_pWritePath;
- m_pWritePath = NULL;
- }
- /*!***********************************************************************
- @Function Deinit
- @Input Shell
- @Description PVRShell deinitialisation.
- *************************************************************************/
- void PVRShellInit::Deinit()
- {
- if(m_pShell)
- {
- // Is the App currently running?
- if(m_eState > ePVRShellInitApp && m_eState < ePVRShellExit)
- {
- // If so force it to go through the exit procedure
- if(m_eState < ePVRShellReleaseView)
- m_eState = ePVRShellReleaseView;
- // Class the App as done
- gShellDone = true;
- // Run through the exiting states
- while(Run()){};
- }
- delete m_pShell;
- m_pShell = 0;
- }
- }
- /*!***********************************************************************
- @Function Init
- @Input Shell
- @Returns True on success and false on failure
- @description PVRShell Initialisation.
- *************************************************************************/
- bool PVRShellInit::Init()
- {
- Deinit();
- m_pShell = NewDemo();
- if(!m_pShell)
- return false;
- m_pShell->m_pShellInit = this;
- m_u32ShellStartTime = OsGetTime();
- // set default direction key mappings
- m_eKeyMapDOWN = PVRShellKeyNameDOWN;
- m_eKeyMapLEFT = PVRShellKeyNameLEFT;
- m_eKeyMapUP = PVRShellKeyNameUP;
- m_eKeyMapRIGHT = PVRShellKeyNameRIGHT;
- nLastKeyPressed = PVRShellKeyNameNull;
- OsInit();
- gShellDone = false;
- m_eState = ePVRShellInitApp;
- return true;
- }
- /*!***********************************************************************
- @Function CommandLine
- @Input str A string containing the command-line
- @Description Receives the command-line from the application.
- *************************************************************************/
- void PVRShellInit::CommandLine(char *str)
- {
- m_CommandLine.Set(str);
- }
- /*!***********************************************************************
- @Function CommandLine
- @Input argc Number of strings in argv
- @Input argv An array of strings
- @Description Receives the command-line from the application.
- *************************************************************************/
- void PVRShellInit::CommandLine(int argc, char **argv)
- {
- size_t tot, len;
- char *buf;
- int i;
- tot = 0;
- for(i = 0; i < argc; ++i)
- tot += strlen(argv[i]);
- if(!tot)
- {
- CommandLine((char*) "");
- return;
- }
- // Add room for spaces and the \0
- tot += argc;
- buf = new char[tot];
- tot = 0;
- for(i = 0; i < argc; ++i)
- {
- len = strlen(argv[i]);
- strncpy(&buf[tot], argv[i], len);
- tot += len;
- buf[tot++] = ' ';
- }
- buf[tot-1] = 0;
- CommandLine(buf);
- delete [] buf;
- }
- /*!***********************************************************************
- @Function DoIsKeyPressed
- @Input key The key we're querying for
- @description Return 'true' if the specific key has been pressed.
- *************************************************************************/
- bool PVRShellInit::DoIsKeyPressed(const PVRShellKeyName key)
- {
- if(key == nLastKeyPressed)
- {
- nLastKeyPressed = PVRShellKeyNameNull;
- return true;
- }
- else
- {
- return false;
- }
- }
- /*!***********************************************************************
- @Function KeyPressed
- @Input nkey The key that has been pressed
- @description Used by the OS-specific code to tell the Shell that a key has been pressed.
- *************************************************************************/
- void PVRShellInit::KeyPressed(PVRShellKeyName nKey)
- {
- nLastKeyPressed = nKey;
- }
- /*!***********************************************************************
- @Function GetReadPath
- @Returns A path the application is capable of reading from
- @description Used by the OS-specific code to tell the Shell where to read external files from
- *************************************************************************/
- const char* PVRShellInit::GetReadPath() const
- {
- return m_pReadPath;
- }
- /*!***********************************************************************
- @Function GetWritePath
- @Returns A path the applications is capable of writing to
- @description Used by the OS-specific code to tell the Shell where to write to
- *************************************************************************/
- const char* PVRShellInit::GetWritePath() const
- {
- return m_pWritePath;
- }
- /*!****************************************************************************
- @Function SetAppName
- @Input str The application name
- @Description Sets the default app name (to be displayed by the OS)
- *******************************************************************************/
- void PVRShellInit::SetAppName(const char * const str)
- {
- const char *pName = strrchr(str, PVRSHELL_DIR_SYM);
- if(pName)
- {
- ++pName;
- }
- else
- {
- pName = str;
- }
- m_pShell->PVRShellSet(prefAppName, pName);
- }
- /*!***********************************************************************
- @Function SetReadPath
- @Input str The read path
- @description Set the path to where the application expects to read from.
- *************************************************************************/
- void PVRShellInit::SetReadPath(const char * const str)
- {
- m_pReadPath = new char[strlen(str)+1];
- if(m_pReadPath)
- {
- strcpy(m_pReadPath, str);
- char* lastSlash = strrchr(m_pReadPath, PVRSHELL_DIR_SYM);
- if(lastSlash)
- lastSlash[1] = 0;
- }
- }
- /*!***********************************************************************
- @Function SetWritePath
- @Input str The write path
- @description Set the path to where the application expects to write to.
- *************************************************************************/
- void PVRShellInit::SetWritePath(const char * const str)
- {
- m_pWritePath = new char[strlen(str)+1];
- if(m_pWritePath)
- {
- strcpy(m_pWritePath, str);
- char* lastSlash = strrchr(m_pWritePath, PVRSHELL_DIR_SYM);
- if(lastSlash)
- lastSlash[1] = 0;
- }
- }
- #ifdef PVRSHELL_FPS_OUTPUT
- /*****************************************************************************
- * Function Name : FpsUpdate
- * Description : Calculates a value for frames-per-second (FPS).
- *****************************************************************************/
- void PVRShellInit::FpsUpdate()
- {
- unsigned int ui32TimeDelta, ui32Time;
- ui32Time = m_pShell->PVRShellGetTime();
- ++m_i32FpsFrameCnt;
- ui32TimeDelta = ui32Time - m_i32FpsTimePrev;
- if(ui32TimeDelta >= 1000)
- {
- float fFPS = 1000.0f * (float) m_i32FpsFrameCnt / (float) ui32TimeDelta;
- m_pShell->PVRShellOutputDebug("PVRShell: frame %d, FPS %.1f.\n",
- m_pShell->m_pShellData->nShellCurFrameNum, fFPS);
- m_i32FpsFrameCnt = 0;
- m_i32FpsTimePrev = ui32Time;
- }
- }
- #endif
- /*****************************************************************************
- * Function Name : Run
- * Returns : false when the app should quit
- * Description : Main message loop / render loop
- *****************************************************************************/
- bool PVRShellInit::Run()
- {
- static unsigned long StartTime = 0;
- switch(m_eState)
- {
- case ePVRShellInitApp:
- {
- // Prepend command-line options from PVRShellCL.txt
- const char * const pCL = "PVRShellCL.txt";
- const char *pPath = (const char*) m_pShell->PVRShellGet(prefReadPath);
- int nSize = strlen(pPath) + strlen(pCL) + 1;
- char *pString = new char[nSize];
- if(pString)
- {
- #if defined(__SYMBIAN32__) || defined(UITRON) || defined(_UITRON_)
- sprintf(pString, "%s%s", pPath, pCL);
- #else
- snprintf(pString, nSize, "%s%s", pPath, pCL);
- #endif
- if(!m_CommandLine.PrefixFromFile(pString))
- {
- delete[] pString;
- pPath = (const char*) m_pShell->PVRShellGet(prefWritePath);
- nSize = strlen(pPath) + strlen(pCL) + 1;
- pString = new char[nSize];
- #if defined(__SYMBIAN32__) || defined(UITRON) || defined(_UITRON_)
- sprintf(pString, "%s%s", pPath, pCL);
- #else
- snprintf(pString, nSize, "%s%s", pPath, pCL);
- #endif
- if(m_CommandLine.PrefixFromFile(pString))
- m_pShell->PVRShellOutputDebug("Loaded command-line options from %s.\n", pString);
- }
- else
- m_pShell->PVRShellOutputDebug("Loaded command-line options from %s.\n", pString);
- delete[] pString;
- }
- // Parse the command-line
- m_CommandLine.Parse();
- #if defined(_DEBUG)
- m_pShell->PVRShellOutputDebug("PVRShell command line: %d/%d\n", m_CommandLine.m_nOptLen, m_CommandLine.m_nOptMax);
- for(int i = 0; i < m_CommandLine.m_nOptLen; ++i)
- {
- m_pShell->PVRShellOutputDebug("CL %d: \"%s\"\t= \"%s\".\n", i,
- m_CommandLine.m_pOpt[i].pArg ? m_CommandLine.m_pOpt[i].pArg : "",
- m_CommandLine.m_pOpt[i].pVal ? m_CommandLine.m_pOpt[i].pVal : "");
- }
- #endif
- // Call InitApplication
- if(!m_pShell->InitApplication())
- {
- m_eState = ePVRShellExit;
- return true;
- }
- m_eState = ePVRShellInitInstance;
- return true;
- }
- case ePVRShellInitInstance:
- {
- m_CommandLine.Apply(*m_pShell);
- // Output non-api specific data if required
- OutputInfo();
- // Perform OS initialisation
- if(!OsInitOS())
- {
- m_pShell->PVRShellOutputDebug("InitOS failed!\n");
- m_eState = ePVRShellQuitApp;
- return true;
- }
- // Initialize the 3D API
- if(!OsDoInitAPI())
- {
- m_pShell->PVRShellOutputDebug("InitAPI failed!\n");
- m_eState = ePVRShellReleaseOS;
- gShellDone = true;
- return true;
- }
- // Output api specific data if required
- OutputAPIInfo();
- // Initialise the app
- if(!m_pShell->InitView())
- {
- m_pShell->PVRShellOutputDebug("InitView failed!\n");
- m_eState = ePVRShellReleaseAPI;
- gShellDone = true;
- return true;
- }
- if(StartTime==0)
- {
- StartTime = OsGetTime();
- }
- m_eState = ePVRShellRender;
- return true;
- }
- case ePVRShellRender:
- {
- // Main message loop:
- if(!m_pShell->RenderScene())
- break;
- ApiRenderComplete();
- OsRenderComplete();
- #ifdef PVRSHELL_FPS_OUTPUT
- if(m_pShell->m_pShellData->bOutputFPS)
- FpsUpdate();
- #endif
- int nCurrentFrame = m_pShell->m_pShellData->nShellCurFrameNum;
- if(DoIsKeyPressed(PVRShellKeyNameScreenshot) || (nCurrentFrame >= m_pShell->m_pShellData->nCaptureFrameStart && nCurrentFrame <= m_pShell->m_pShellData->nCaptureFrameStop))
- {
- unsigned char *pBuf;
- if(m_pShell->PVRShellScreenCaptureBuffer(m_pShell->PVRShellGet(prefWidth), m_pShell->PVRShellGet(prefHeight), &pBuf))
- {
- if(m_pShell->PVRShellScreenSave(PVRSHELL_SCREENSHOT_NAME, pBuf) != 0)
- {
- m_pShell->PVRShellSet(prefExitMessage, "Screen-shot save failed.\n");
- }
- }
- else
- {
- m_pShell->PVRShellSet(prefExitMessage, "Screen capture failed.\n");
- }
- FREE(pBuf);
- }
- if(DoIsKeyPressed(PVRShellKeyNameQUIT))
- gShellDone = true;
- if(gShellDone)
- break;
- /* Quit if maximum number of allowed frames is reached */
- if((m_pShell->m_pShellData->nDieAfterFrames>=0) && (nCurrentFrame >= m_pShell->m_pShellData->nDieAfterFrames))
- break;
- /* Quit if maximum time is reached */
- if((m_pShell->m_pShellData->fDieAfterTime>=0.0f) && (((OsGetTime()-StartTime)*0.001f) >= m_pShell->m_pShellData->fDieAfterTime))
- break;
- m_pShell->m_pShellData->nShellCurFrameNum++;
- return true;
- }
- case ePVRShellReleaseView:
- m_pShell->ReleaseView();
- case ePVRShellReleaseAPI:
- OsDoReleaseAPI();
- case ePVRShellReleaseOS:
- OsReleaseOS();
- if(!gShellDone && m_pShell->m_pShellData->nInitRepeats)
- {
- --m_pShell->m_pShellData->nInitRepeats;
- m_eState = ePVRShellInitInstance;
- return true;
- }
- m_eState = ePVRShellQuitApp;
- return true;
- case ePVRShellQuitApp:
- // Final app tidy-up
- m_pShell->QuitApplication();
- m_eState = ePVRShellExit;
- case ePVRShellExit:
- OsExit();
- StringCopy(m_pShell->m_pShellData->pszAppName, 0);
- StringCopy(m_pShell->m_pShellData->pszExitMessage, 0);
- return false;
- }
- m_eState = (EPVRShellState)(m_eState + 1);
- return true;
- }
- /*!***********************************************************************
- @Function OutputInfo
- @description When prefOutputInfo is set to true this function outputs
- various pieces of non-API dependent information via
- PVRShellOutputDebug.
- *************************************************************************/
- void PVRShellInit::OutputInfo()
- {
- if(m_pShell->PVRShellGet(prefOutputInfo))
- {
- m_pShell->PVRShellOutputDebug("\n");
- m_pShell->PVRShellOutputDebug("App name: %s\n" , m_pShell->PVRShellGet(prefAppName));
- m_pShell->PVRShellOutputDebug("SDK version: %s\n" , m_pShell->PVRShellGet(prefVersion));
- m_pShell->PVRShellOutputDebug("\n");
- m_pShell->PVRShellOutputDebug("Read path: %s\n" , m_pShell->PVRShellGet(prefReadPath));
- m_pShell->PVRShellOutputDebug("Write path: %s\n" , m_pShell->PVRShellGet(prefWritePath));
- m_pShell->PVRShellOutputDebug("\n");
- m_pShell->PVRShellOutputDebug("Command-line: %s\n" , m_pShell->PVRShellGet(prefCommandLine));
- m_pShell->PVRShellOutputDebug("\n");
- m_pShell->PVRShellOutputDebug("Power saving: %s\n" , m_pShell->PVRShellGet(prefPowerSaving) ? "On" : "Off");
- m_pShell->PVRShellOutputDebug("FSAAMode requested: %i\n", m_pShell->PVRShellGet(prefFSAAMode));
- m_pShell->PVRShellOutputDebug("Fullscreen: %s\n", m_pShell->PVRShellGet(prefFullScreen) ? "Yes" : "No");
- m_pShell->PVRShellOutputDebug("PBuffer requested: %s\n", m_pShell->PVRShellGet(prefPBufferContext) ? "Yes" : "No");
- m_pShell->PVRShellOutputDebug("ZBuffer requested: %s\n", m_pShell->PVRShellGet(prefZbufferContext) ? "Yes" : "No");
- m_pShell->PVRShellOutputDebug("Stencil buffer requested: %s\n", m_pShell->PVRShellGet(prefStencilBufferContext) ? "Yes" : "No");
- if(m_pShell->PVRShellGet(prefColorBPP) > 0)
- m_pShell->PVRShellOutputDebug("Colour buffer size requested: %i\n", m_pShell->PVRShellGet(prefColorBPP));
- if(m_pShell->PVRShellGet(prefDepthBPP) > 0)
- m_pShell->PVRShellOutputDebug("Depth buffer size requested: %i\n", m_pShell->PVRShellGet(prefDepthBPP));
- m_pShell->PVRShellOutputDebug("Software rendering requested: %s\n", m_pShell->PVRShellGet(prefSoftwareRendering) ? "Yes" : "No");
- m_pShell->PVRShellOutputDebug("OpenVG requested: %s\n", m_pShell->PVRShellGet(prefOpenVGContext) ? "Yes" : "No");
- m_pShell->PVRShellOutputDebug("Swap Interval requested: %i\n", m_pShell->PVRShellGet(prefSwapInterval));
- if(m_pShell->PVRShellGet(prefInitRepeats) > 0)
- m_pShell->PVRShellOutputDebug("No of Init repeats: %i\n", m_pShell->PVRShellGet(prefInitRepeats));
- if(m_pShell->PVRShellGet(prefQuitAfterFrame) != -1)
- m_pShell->PVRShellOutputDebug("Quit after frame: %i\n", m_pShell->PVRShellGet(prefQuitAfterFrame));
- if(m_pShell->PVRShellGet(prefQuitAfterTime) != -1.0f)
- m_pShell->PVRShellOutputDebug("Quit after time: %f\n", m_pShell->PVRShellGet(prefQuitAfterTime));
- }
- }
- /****************************************************************************
- ** Local code
- ****************************************************************************/
- /*!***********************************************************************
- @Function StringCopy
- @Modified pszStr The string to copy pszSrc into
- @Input pszSrc The source string to copy
- @description This function copies pszSrc into pszStr.
- *************************************************************************/
- static bool StringCopy(char *&pszStr, const char * const pszSrc)
- {
- size_t len;
- FREE(pszStr);
- if(!pszSrc)
- return true;
- len = strlen(pszSrc)+1;
- pszStr = (char*)malloc(len);
- if(!pszStr)
- return false;
- strcpy(pszStr, pszSrc);
- return true;
- }
- /*****************************************************************************
- End of file (PVRShell.cpp)
- *****************************************************************************/
|