Sampler.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "Base.h"
  2. #include "Sampler.h"
  3. #include "FileIO.h"
  4. namespace gameplay
  5. {
  6. using std::string;
  7. using std::map;
  8. Sampler::Sampler(const char* id) :
  9. _id(id)
  10. {
  11. }
  12. Sampler::~Sampler(void)
  13. {
  14. }
  15. const string& Sampler::getId() const
  16. {
  17. return _id;
  18. }
  19. const char* Sampler::getString(const string& name)
  20. {
  21. map<string, string>::const_iterator it = props.find(name);
  22. if (it != props.end())
  23. {
  24. return it->second.c_str();
  25. }
  26. return NULL;
  27. }
  28. void Sampler::set(const string& name, const string& value)
  29. {
  30. props[name] = value;
  31. }
  32. void Sampler::writeMaterial(FILE* file, unsigned int indent, Sampler* parent)
  33. {
  34. writeIndent(indent, file);
  35. fprintf(file, "sampler %s\n", _id.c_str());
  36. writeIndent(indent, file);
  37. fprintf(file, "{\n");
  38. ++indent;
  39. const char* relativePath = getString("relativePath");
  40. if (relativePath)
  41. set("path", relativePath);
  42. writeProperty(file, "path", indent, parent);
  43. writeProperty(file, "mipmap", indent, parent);
  44. writeProperty(file, "wrapS", indent, parent);
  45. writeProperty(file, "wrapT", indent, parent);
  46. writeProperty(file, MIN_FILTER, indent, parent);
  47. writeProperty(file, MAG_FILTER, indent, parent);
  48. --indent;
  49. writeIndent(indent, file);
  50. fprintf(file, "}\n");
  51. }
  52. void Sampler::writeProperty(FILE* file, const string& name, unsigned int indent, Sampler* parent)
  53. {
  54. const char* value = getString(name);
  55. if (value != NULL)
  56. {
  57. const char* parentValue = NULL;
  58. // Don't print the property if it is the same as the parent's property
  59. if (parent != NULL)
  60. {
  61. parentValue = parent->getString(name);
  62. }
  63. if (parentValue == NULL || strcmp(value, parentValue) != 0)
  64. {
  65. writeIndent(indent, file);
  66. fprintf(file, "%s = %s\n", name.c_str(), value);
  67. }
  68. }
  69. }
  70. }