/opengles/src/Texture.h

http://ftk.googlecode.com/ · C Header · 149 lines · 82 code · 32 blank · 35 comment · 2 complexity · 51c7a50d286d1168f7f39f4a2ba393cb MD5 · raw file

  1. #ifndef EGL_TEXTURE_H
  2. #define EGL_TEXTURE_H 1
  3. // ==========================================================================
  4. //
  5. // Texture.h Texture Class for 3D Rendering Library
  6. //
  7. // --------------------------------------------------------------------------
  8. //
  9. // 09-14-2003 Hans-Martin Will initial version
  10. //
  11. // --------------------------------------------------------------------------
  12. //
  13. // Copyright (c) 2004, Hans-Martin Will. All rights reserved.
  14. //
  15. // Redistribution and use in source and binary forms, with or without
  16. // modification, are permitted provided that the following conditions are
  17. // met:
  18. //
  19. // * Redistributions of source code must retain the above copyright
  20. // notice, this list of conditions and the following disclaimer.
  21. // * Redistributions in binary form must reproduce the above copyright
  22. // notice, this list of conditions and the following disclaimer in the
  23. // documentation and/or other materials provided with the distribution.
  24. //
  25. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  30. // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  35. // THE POSSIBILITY OF SUCH DAMAGE.
  36. //
  37. // ==========================================================================
  38. #include "OGLES.h"
  39. #include "GLES/gl.h"
  40. #include "Config.h"
  41. #include "Color.h"
  42. #include "RasterizerState.h"
  43. namespace EGL {
  44. class Rasterizer;
  45. class CodeGenerator;
  46. class Texture {
  47. #ifdef EGL_ON_LINUX
  48. friend class Rasterizer;
  49. friend class CodeGenerator;
  50. #else
  51. friend Rasterizer;
  52. friend CodeGenerator;
  53. #endif
  54. public:
  55. void Init();
  56. void Dispose();
  57. bool Initialize(U32 width, U32 height, RasterizerState::TextureFormat format);
  58. U32 GetWidth() const { return 1 << m_LogWidth; }
  59. U32 GetHeight() const { return 1 << m_LogHeight; }
  60. U32 GetLogWidth() const { return m_LogWidth; }
  61. U32 GetLogHeight() const { return m_LogHeight; }
  62. U32 GetLogBytesPerPixel() const;
  63. RasterizerState::TextureFormat
  64. GetInternalFormat() const { return m_InternalFormat; }
  65. U8 GetBytesPerPixel() const { return s_BytesPerPixel[m_InternalFormat]; }
  66. void * GetData() const { return m_Data; }
  67. private:
  68. void * m_Data;
  69. U32 m_LogWidth;
  70. U32 m_LogHeight;
  71. RasterizerState::TextureFormat m_InternalFormat;
  72. const static U8 s_BytesPerPixel[];
  73. };
  74. class MultiTexture {
  75. #ifdef EGL_ON_LINUX
  76. friend class Rasterizer;
  77. #else
  78. friend Rasterizer;
  79. #endif
  80. public:
  81. enum {
  82. MAX_LEVELS = RasterizerState::LogMaxTextureSize
  83. };
  84. MultiTexture();
  85. ~MultiTexture();
  86. Texture * GetTexture(int level) { return m_TextureLevels + level; }
  87. const Texture * GetTexture(int level) const { return m_TextureLevels + level; }
  88. void SetMinFilterMode(RasterizerState::FilterMode mode) { m_MinFilterMode = mode; }
  89. void SetMagFilterMode(RasterizerState::FilterMode mode) { m_MagFilterMode = mode; }
  90. void SetMipmapFilterMode(RasterizerState::FilterMode mode) { m_MipmapFilterMode = mode; }
  91. void SetWrappingModeS(RasterizerState::WrappingMode mode) { m_WrappingModeS = mode; }
  92. void SetWrappingModeT(RasterizerState::WrappingMode mode) { m_WrappingModeT = mode; }
  93. RasterizerState::FilterMode GetMinFilterMode() const { return m_MinFilterMode; }
  94. RasterizerState::FilterMode GetMagFilterMode() const { return m_MagFilterMode; }
  95. RasterizerState::FilterMode GetMipmapFilterMode() const { return m_MipmapFilterMode; }
  96. RasterizerState::WrappingMode GetWrappingModeS() const { return m_WrappingModeS; }
  97. RasterizerState::WrappingMode GetWrappingModeT() const { return m_WrappingModeT; }
  98. RasterizerState::TextureFormat
  99. GetInternalFormat() const { return m_TextureLevels[0].GetInternalFormat(); }
  100. bool IsComplete() const;
  101. bool IsMipMap() const;
  102. private:
  103. Texture m_TextureLevels[MAX_LEVELS + 1];
  104. RasterizerState::FilterMode m_MinFilterMode;
  105. RasterizerState::FilterMode m_MagFilterMode;
  106. RasterizerState::FilterMode m_MipmapFilterMode;
  107. RasterizerState::WrappingMode m_WrappingModeS;
  108. RasterizerState::WrappingMode m_WrappingModeT;
  109. U32 m_Levels;
  110. };
  111. inline bool MultiTexture :: IsMipMap() const {
  112. return
  113. m_MipmapFilterMode == RasterizerState::FilterModeNearest ||
  114. m_MipmapFilterMode == RasterizerState::FilterModeLinear;
  115. }
  116. }
  117. #endif //ndef EGL_TEXTURE_H