gfxStructs.cpp 2.8 KB

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