OGLGraphicsImpl.h 2.9 KB

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