OGLGraphicsImpl.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Oorni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  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. #pragma once
  24. #include "Color.h"
  25. #include "HashMap.h"
  26. #include "Timer.h"
  27. #if defined(ANDROID)
  28. #include <GLES2/gl2.h>
  29. #include <GLES2/gl2ext.h>
  30. #elif defined(IOS)
  31. #include <OpenGLES/ES2/gl.h>
  32. #include <OpenGLES/ES2/glext.h>
  33. #else
  34. #include <GLee.h>
  35. #endif
  36. #ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
  37. #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83f1
  38. #endif
  39. #ifndef GL_ETC1_RGB8_OES
  40. #define GL_ETC1_RGB8_OES 0x8d64
  41. #endif
  42. #ifndef COMPRESSED_RGB_PVRTC_4BPPV1_IMG
  43. #define COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8c00
  44. #endif
  45. #ifndef COMPRESSED_RGB_PVRTC_2BPPV1_IMG
  46. #define COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8c01
  47. #endif
  48. #ifndef COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
  49. #define COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8c02
  50. #endif
  51. #ifndef COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
  52. #define COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8c03
  53. #endif
  54. #include <SDL.h>
  55. namespace Urho3D
  56. {
  57. class Context;
  58. /// Cached state of a frame buffer object
  59. struct FrameBufferObject
  60. {
  61. FrameBufferObject() :
  62. fbo_(0),
  63. depthAttachment_(0),
  64. readBuffers_(M_MAX_UNSIGNED),
  65. drawBuffers_(M_MAX_UNSIGNED)
  66. {
  67. for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
  68. colorAttachments_[i] = 0;
  69. }
  70. /// Frame buffer handle.
  71. unsigned fbo_;
  72. /// Bound color attachment textures.
  73. RenderSurface* colorAttachments_[MAX_RENDERTARGETS];
  74. /// Bound depth/stencil attachment.
  75. RenderSurface* depthAttachment_;
  76. /// Read buffer bits.
  77. unsigned readBuffers_;
  78. /// Draw buffer bits.
  79. unsigned drawBuffers_;
  80. /// Use timer for cleaning up.
  81. Timer useTimer_;
  82. };
  83. /// %Graphics subsystem implementation. Holds API-specific objects.
  84. class GraphicsImpl
  85. {
  86. friend class Graphics;
  87. public:
  88. /// Construct.
  89. GraphicsImpl();
  90. /// Return the SDL window.
  91. SDL_Window* GetWindow() const { return window_; }
  92. private:
  93. /// SDL window.
  94. SDL_Window* window_;
  95. /// SDL OpenGL context.
  96. SDL_GLContext context_;
  97. /// IOS system framebuffer handle.
  98. unsigned systemFbo_;
  99. /// Active texture unit.
  100. unsigned activeTexture_;
  101. /// Vertex attributes in use.
  102. unsigned enabledAttributes_;
  103. /// Currently bound frame buffer object.
  104. unsigned boundFbo_;
  105. /// Current pixel format.
  106. int pixelFormat_;
  107. /// Map for FBO's per resolution and format.
  108. HashMap<unsigned long long, FrameBufferObject> frameBuffers_;
  109. /// Need FBO commit flag.
  110. bool fboDirty_;
  111. };
  112. }