OGLGraphicsImpl.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // Copyright (c) 2008-2015 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../../Container/HashMap.h"
  24. #include "../../Core/Timer.h"
  25. #include "../../Math/Color.h"
  26. #if defined(ANDROID) || defined (RPI) || defined (EMSCRIPTEN)
  27. #include <GLES2/gl2.h>
  28. #include <GLES2/gl2ext.h>
  29. #elif defined(IOS)
  30. #include <OpenGLES/ES2/gl.h>
  31. #include <OpenGLES/ES2/glext.h>
  32. #else
  33. #include <GLEW/glew.h>
  34. #endif
  35. #ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
  36. #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83f1
  37. #endif
  38. #ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
  39. #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83f2
  40. #endif
  41. #ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
  42. #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83f3
  43. #endif
  44. #ifndef GL_ETC1_RGB8_OES
  45. #define GL_ETC1_RGB8_OES 0x8d64
  46. #endif
  47. #ifndef COMPRESSED_RGB_PVRTC_4BPPV1_IMG
  48. #define COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8c00
  49. #endif
  50. #ifndef COMPRESSED_RGB_PVRTC_2BPPV1_IMG
  51. #define COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8c01
  52. #endif
  53. #ifndef COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
  54. #define COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8c02
  55. #endif
  56. #ifndef COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
  57. #define COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8c03
  58. #endif
  59. #include <SDL/include/SDL.h>
  60. namespace Atomic
  61. {
  62. class Context;
  63. /// Cached state of a frame buffer object
  64. struct FrameBufferObject
  65. {
  66. FrameBufferObject() :
  67. fbo_(0),
  68. depthAttachment_(0),
  69. readBuffers_(M_MAX_UNSIGNED),
  70. drawBuffers_(M_MAX_UNSIGNED)
  71. {
  72. for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
  73. colorAttachments_[i] = 0;
  74. }
  75. /// Frame buffer handle.
  76. unsigned fbo_;
  77. /// Bound color attachment textures.
  78. RenderSurface* colorAttachments_[MAX_RENDERTARGETS];
  79. /// Bound depth/stencil attachment.
  80. RenderSurface* depthAttachment_;
  81. /// Read buffer bits.
  82. unsigned readBuffers_;
  83. /// Draw buffer bits.
  84. unsigned drawBuffers_;
  85. };
  86. /// %Graphics subsystem implementation. Holds API-specific objects.
  87. class ATOMIC_API GraphicsImpl
  88. {
  89. friend class Graphics;
  90. public:
  91. /// Construct.
  92. GraphicsImpl();
  93. /// Return the SDL window.
  94. SDL_Window* GetWindow() const { return window_; }
  95. /// Return the GL Context.
  96. const SDL_GLContext& GetGLContext() { return context_; }
  97. private:
  98. /// SDL window.
  99. SDL_Window* window_;
  100. /// SDL OpenGL context.
  101. SDL_GLContext context_;
  102. /// IOS system framebuffer handle.
  103. unsigned systemFBO_;
  104. /// Active texture unit.
  105. unsigned activeTexture_;
  106. /// Vertex attributes in use.
  107. unsigned enabledAttributes_;
  108. /// Currently bound frame buffer object.
  109. unsigned boundFBO_;
  110. /// Currently bound vertex buffer object.
  111. unsigned boundVBO_;
  112. /// Currently bound uniform buffer object.
  113. unsigned boundUBO_;
  114. /// Current pixel format.
  115. int pixelFormat_;
  116. /// Map for FBO's per resolution and format.
  117. HashMap<unsigned long long, FrameBufferObject> frameBuffers_;
  118. /// Need FBO commit flag.
  119. bool fboDirty_;
  120. /// sRGB write mode flag.
  121. bool sRGBWrite_;
  122. };
  123. }