BsGLPixelFormat.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "BsGLPrerequisites.h"
  27. #include "BsPixelUtil.h"
  28. namespace BansheeEngine {
  29. /**
  30. * Class to do pixel format mapping between GL and OGRE
  31. */
  32. class BS_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. /** Function to get the closest valid matching engine format to another engine format.
  70. */
  71. static PixelFormat getClosestValidFormat(PixelFormat fmt);
  72. /**
  73. * @brief Gets OpenGL format based on a compressed OpenGL internal format.
  74. * e.g. GL_COMPRESSED_RGBA_S3TC_DXT1_EXT will return GL_RGBA
  75. *
  76. */
  77. static GLenum getBaseFormatFromCompressedInternalFormat(GLenum internalFormat);
  78. /** Returns next power-of-two size if required by render system, in case
  79. RSC_NON_POWER_OF_2_TEXTURES is supported it returns value as-is.
  80. */
  81. static UINT32 optionalPO2(UINT32 value);
  82. };
  83. };
  84. #endif