gfxStructs.cpp
Engine/source/gfx/gfxStructs.cpp
Public Defines
define
PARSE_ELEM(type, var, func, tokParam, sep) ( char *ptr = ( tokParam, sep)) \ { type tmp = func(ptr); (tmp > 0) var = tmp; }
Detailed Description
Public Defines
PARSE_ELEM(type, var, func, tokParam, sep) ( char *ptr = ( tokParam, sep)) \ { type tmp = func(ptr); (tmp > 0) var = tmp; }
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "gfx/gfxDevice.h" 25 26 27GFXVideoMode::GFXVideoMode() 28{ 29 bitDepth = 32; 30 fullScreen = false; 31 refreshRate = 60; 32 wideScreen = false; 33 resolution.set(800,600); 34 antialiasLevel = 0; 35} 36 37void GFXVideoMode::parseFromString( const char *str ) 38{ 39 if(!str) 40 return; 41 42 // Copy the string, as dStrtok is destructive 43 dsize_t tempBufLen = dStrlen(str) + 1; 44 char *tempBuf = new char[tempBufLen]; 45 dStrcpy( tempBuf, str, tempBufLen ); 46 47#define PARSE_ELEM(type, var, func, tokParam, sep) \ 48 if(const char *ptr = dStrtok( tokParam, sep)) \ 49 { type tmp = func(ptr); if(tmp > 0) var = tmp; } 50 51 PARSE_ELEM(S32, resolution.x, dAtoi, tempBuf, " x\0") 52 PARSE_ELEM(S32, resolution.y, dAtoi, NULL, " x\0") 53 const char *boolptr = dStrtok(NULL, " \0"); 54 if (boolptr) 55 fullScreen = dAtob(boolptr); 56 PARSE_ELEM(S32, bitDepth, dAtoi, NULL, " \0") 57 PARSE_ELEM(S32, refreshRate, dAtoi, NULL, " \0") 58 PARSE_ELEM(S32, antialiasLevel, dAtoi, NULL, " \0") 59 60#undef PARSE_ELEM 61 62 delete [] tempBuf; 63} 64 65const String GFXVideoMode::toString() const 66{ 67 return String::ToString("%d %d %s %d %d %d", resolution.x, resolution.y, (fullScreen ? "true" : "false"), bitDepth, refreshRate, antialiasLevel); 68} 69 70void GFXShaderMacro::stringize( const Vector<GFXShaderMacro> ¯os, String *outString ) 71{ 72 Vector<GFXShaderMacro>::const_iterator itr = macros.begin(); 73 for ( ; itr != macros.end(); itr++ ) 74 { 75 (*outString) += itr->name; 76 if ( itr->value.isNotEmpty() ) 77 { 78 (*outString) += "="; 79 (*outString) += itr->value; 80 } 81 (*outString) += ";"; 82 } 83} 84