OGLGraphicsImpl.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  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 "Map.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. #include <SDL.h>
  37. class Context;
  38. /// Cached state of a frame buffer object
  39. struct FrameBufferObject
  40. {
  41. FrameBufferObject() :
  42. fbo_(0),
  43. readBuffers_(M_MAX_UNSIGNED),
  44. drawBuffers_(M_MAX_UNSIGNED),
  45. depthAttachment_(0)
  46. {
  47. for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
  48. colorAttachments_[i] = 0;
  49. }
  50. /// Frame buffer handle.
  51. unsigned fbo_;
  52. /// Bound color attachment textures.
  53. RenderSurface* colorAttachments_[MAX_RENDERTARGETS];
  54. /// Bound depth/stencil attachment.
  55. RenderSurface* depthAttachment_;
  56. /// Read buffer bits.
  57. unsigned readBuffers_;
  58. /// Draw buffer bits.
  59. unsigned drawBuffers_;
  60. /// Use timer for cleaning up.
  61. Timer useTimer_;
  62. };
  63. /// %Graphics subsystem implementation. Holds API-specific objects.
  64. class GraphicsImpl
  65. {
  66. friend class Graphics;
  67. public:
  68. /// Construct.
  69. GraphicsImpl();
  70. /// Return the SDL window.
  71. SDL_Window* GetWindow() const { return window_; }
  72. private:
  73. /// SDL window.
  74. SDL_Window* window_;
  75. /// SDL OpenGL context.
  76. SDL_GLContext context_;
  77. /// IOS system framebuffer handle.
  78. unsigned systemFbo_;
  79. /// Active texture unit.
  80. unsigned activeTexture_;
  81. /// Vertex attributes in use.
  82. unsigned enabledAttributes_;
  83. /// Currently bound frame buffer object.
  84. unsigned boundFbo_;
  85. /// Current pixel format.
  86. int pixelFormat_;
  87. /// Map for FBO's per resolution and format.
  88. Map<unsigned long long, FrameBufferObject> frameBuffers_;
  89. /// Need FBO commit flag.
  90. bool fboDirty_;
  91. };