gfxStructs.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. char *tempBuf = new char[dStrlen( str ) + 1];
  38. dStrcpy( tempBuf, str );
  39. #define PARSE_ELEM(type, var, func, tokParam, sep) \
  40. if(const char *ptr = dStrtok( tokParam, sep)) \
  41. { type tmp = func(ptr); if(tmp > 0) var = tmp; }
  42. PARSE_ELEM(S32, resolution.x, dAtoi, tempBuf, " x\0")
  43. PARSE_ELEM(S32, resolution.y, dAtoi, NULL, " x\0")
  44. PARSE_ELEM(S32, fullScreen, dAtob, NULL, " \0")
  45. PARSE_ELEM(S32, bitDepth, dAtoi, NULL, " \0")
  46. PARSE_ELEM(S32, refreshRate, dAtoi, NULL, " \0")
  47. PARSE_ELEM(S32, antialiasLevel, dAtoi, NULL, " \0")
  48. #undef PARSE_ELEM
  49. delete [] tempBuf;
  50. }
  51. const String GFXVideoMode::toString() const
  52. {
  53. return String::ToString("%d %d %s %d %d %d", resolution.x, resolution.y, (fullScreen ? "true" : "false"), bitDepth, refreshRate, antialiasLevel);
  54. }
  55. void GFXShaderMacro::stringize( const Vector<GFXShaderMacro> &macros, String *outString )
  56. {
  57. Vector<GFXShaderMacro>::const_iterator itr = macros.begin();
  58. for ( ; itr != macros.end(); itr++ )
  59. {
  60. (*outString) += itr->name;
  61. if ( itr->value.isNotEmpty() )
  62. {
  63. (*outString) += "=";
  64. (*outString) += itr->value;
  65. }
  66. (*outString) += ";";
  67. }
  68. }