Texture.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**
  2. * Copyright (c) 2006-2014 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #include "Texture.h"
  21. namespace love
  22. {
  23. namespace graphics
  24. {
  25. Texture::Filter Texture::defaultFilter;
  26. Texture::Filter::Filter()
  27. : min(FILTER_LINEAR)
  28. , mag(FILTER_LINEAR)
  29. , mipmap(FILTER_NONE)
  30. , anisotropy(1.0f)
  31. {
  32. }
  33. Texture::Wrap::Wrap()
  34. : s(WRAP_CLAMP)
  35. , t(WRAP_CLAMP)
  36. {
  37. }
  38. Texture::Texture()
  39. : width(0)
  40. , height(0)
  41. , filter(getDefaultFilter())
  42. , wrap()
  43. , vertices()
  44. {
  45. }
  46. Texture::~Texture()
  47. {
  48. }
  49. int Texture::getWidth() const
  50. {
  51. return width;
  52. }
  53. int Texture::getHeight() const
  54. {
  55. return height;
  56. }
  57. const Texture::Filter &Texture::getFilter() const
  58. {
  59. return filter;
  60. }
  61. const Texture::Wrap &Texture::getWrap() const
  62. {
  63. return wrap;
  64. }
  65. const Vertex *Texture::getVertices() const
  66. {
  67. return vertices;
  68. }
  69. void Texture::setDefaultFilter(const Filter &f)
  70. {
  71. defaultFilter = f;
  72. }
  73. const Texture::Filter &Texture::getDefaultFilter()
  74. {
  75. return defaultFilter;
  76. }
  77. bool Texture::getConstant(const char *in, FilterMode &out)
  78. {
  79. return filterModes.find(in, out);
  80. }
  81. bool Texture::getConstant(FilterMode in, const char *&out)
  82. {
  83. return filterModes.find(in, out);
  84. }
  85. bool Texture::getConstant(const char *in, WrapMode &out)
  86. {
  87. return wrapModes.find(in, out);
  88. }
  89. bool Texture::getConstant(WrapMode in, const char *&out)
  90. {
  91. return wrapModes.find(in, out);
  92. }
  93. bool Texture::getConstant(const char *in, Format &out)
  94. {
  95. return formats.find(in, out);
  96. }
  97. bool Texture::getConstant(Format in, const char *&out)
  98. {
  99. return formats.find(in, out);
  100. }
  101. StringMap<Texture::FilterMode, Texture::FILTER_MAX_ENUM>::Entry Texture::filterModeEntries[] =
  102. {
  103. { "linear", Texture::FILTER_LINEAR },
  104. { "nearest", Texture::FILTER_NEAREST },
  105. };
  106. StringMap<Texture::FilterMode, Texture::FILTER_MAX_ENUM> Texture::filterModes(Texture::filterModeEntries, sizeof(Texture::filterModeEntries));
  107. StringMap<Texture::WrapMode, Texture::WRAP_MAX_ENUM>::Entry Texture::wrapModeEntries[] =
  108. {
  109. { "clamp", Texture::WRAP_CLAMP },
  110. { "repeat", Texture::WRAP_REPEAT },
  111. };
  112. StringMap<Texture::WrapMode, Texture::WRAP_MAX_ENUM> Texture::wrapModes(Texture::wrapModeEntries, sizeof(Texture::wrapModeEntries));
  113. StringMap<Texture::Format, Texture::FORMAT_MAX_ENUM>::Entry Texture::formatEntries[] =
  114. {
  115. {"normal", Texture::FORMAT_NORMAL},
  116. {"hdr", Texture::FORMAT_HDR},
  117. {"srgb", Texture::FORMAT_SRGB},
  118. };
  119. StringMap<Texture::Format, Texture::FORMAT_MAX_ENUM> Texture::formats(Texture::formatEntries, sizeof(Texture::formatEntries));
  120. } // graphics
  121. } // love