OGLGraphicsImpl.h 2.9 KB

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