CmGLPixelFormat.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __GLPIXELFORMAT_H__
  25. #define __GLPIXELFORMAT_H__
  26. #include "CmGLPrerequisites.h"
  27. #include "CmPixelUtil.h"
  28. namespace CamelotFramework {
  29. /**
  30. * Class to do pixel format mapping between GL and OGRE
  31. */
  32. class CM_RSGL_EXPORT GLPixelUtil
  33. {
  34. public:
  35. /** Takes the engine pixel format and returns the appropriate GL one
  36. @returns a GLenum describing the format, or 0 if there is no exactly matching
  37. one (and conversion is needed)
  38. */
  39. static GLenum getGLOriginFormat(PixelFormat mFormat);
  40. /** Takes the engine pixel format and returns type that must be provided
  41. to GL as data type for reading it into the GPU
  42. @returns a GLenum describing the data type, or 0 if there is no exactly matching
  43. one (and conversion is needed)
  44. */
  45. static GLenum getGLOriginDataType(PixelFormat mFormat);
  46. /** Takes the engine pixel format and returns the type that must be provided
  47. to GL as internal format. GL_NONE if no match exists.
  48. @param mFormat The pixel format
  49. @param hwGamma Whether a hardware gamma-corrected version is requested
  50. */
  51. static GLenum getGLInternalFormat(PixelFormat mFormat, bool hwGamma = false);
  52. /** Takes the OGRE pixel format and returns the type that must be provided
  53. to GL as internal format. If no match exists, returns the closest match.
  54. @param mFormat The pixel format
  55. @param hwGamma Whether a hardware gamma-corrected version is requested
  56. */
  57. static GLenum getClosestGLInternalFormat(PixelFormat mFormat, bool hwGamma = false);
  58. /**
  59. * @brief Returns a valid type that should be used for creating a buffer for the specified
  60. * depth/stencil format.
  61. */
  62. static GLenum getDepthStencilTypeFromFormat(PixelFormat mFormat);
  63. /** Function to get the closest matching engine format to an internal GL format. To be
  64. precise, the format will be chosen that is most efficient to transfer to the card
  65. without losing precision.
  66. @remarks It is valid for this function to always return PF_A8R8G8B8.
  67. */
  68. static PixelFormat getClosestEngineFormat(GLenum fmt);
  69. /**
  70. * @brief Gets OpenGL format based on a compressed OpenGL internal format.
  71. * e.g. GL_COMPRESSED_RGBA_S3TC_DXT1_EXT will return GL_RGBA
  72. *
  73. */
  74. static GLenum getBaseFormatFromCompressedInternalFormat(GLenum internalFormat);
  75. /** Returns the maximum number of Mipmaps that can be generated until we reach
  76. the mininum format possible. This does not count the base level.
  77. @param width
  78. The width of the area
  79. @param height
  80. The height of the area
  81. @param depth
  82. The depth of the area
  83. @param format
  84. The format of the area
  85. @remarks
  86. In case that the format is non-compressed, this simply returns
  87. how many times we can divide this texture in 2 until we reach 1x1.
  88. For compressed formats, constraints apply on minimum size and alignment
  89. so this might differ.
  90. */
  91. static UINT32 getMaxMipmaps(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format);
  92. /** Returns next power-of-two size if required by render system, in case
  93. RSC_NON_POWER_OF_2_TEXTURES is supported it returns value as-is.
  94. */
  95. static UINT32 optionalPO2(UINT32 value);
  96. };
  97. };
  98. #endif