ShellRenderInterfaceOpenGL.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUISHELLRENDERINTERFACEOPENGL_H
  29. #define RMLUISHELLRENDERINTERFACEOPENGL_H
  30. #include "RmlUi/Core/RenderInterface.h"
  31. #include "ShellOpenGL.h"
  32. /**
  33. Low level OpenGL render interface for RmlUi
  34. @author Peter Curry
  35. */
  36. class ShellRenderInterfaceOpenGL : public Rml::Core::RenderInterface, public ShellRenderInterfaceExtensions
  37. {
  38. public:
  39. ShellRenderInterfaceOpenGL();
  40. /// Called by RmlUi when it wants to render geometry that it does not wish to optimise.
  41. void RenderGeometry(Rml::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rml::Core::TextureHandle texture, const Rml::Core::Vector2f& translation) override;
  42. /// Called by RmlUi when it wants to compile geometry it believes will be static for the forseeable future.
  43. Rml::Core::CompiledGeometryHandle CompileGeometry(Rml::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rml::Core::TextureHandle texture) override;
  44. /// Called by RmlUi when it wants to render application-compiled geometry.
  45. void RenderCompiledGeometry(Rml::Core::CompiledGeometryHandle geometry, const Rml::Core::Vector2f& translation) override;
  46. /// Called by RmlUi when it wants to release application-compiled geometry.
  47. void ReleaseCompiledGeometry(Rml::Core::CompiledGeometryHandle geometry) override;
  48. /// Called by RmlUi when it wants to enable or disable scissoring to clip content.
  49. void EnableScissorRegion(bool enable) override;
  50. /// Called by RmlUi when it wants to change the scissor region.
  51. void SetScissorRegion(int x, int y, int width, int height) override;
  52. /// Called by RmlUi when a texture is required by the library.
  53. bool LoadTexture(Rml::Core::TextureHandle& texture_handle, Rml::Core::Vector2i& texture_dimensions, const Rml::Core::String& source) override;
  54. /// Called by RmlUi when a texture is required to be built from an internally-generated sequence of pixels.
  55. bool GenerateTexture(Rml::Core::TextureHandle& texture_handle, const Rml::Core::byte* source, const Rml::Core::Vector2i& source_dimensions) override;
  56. /// Called by RmlUi when a loaded texture is no longer required.
  57. void ReleaseTexture(Rml::Core::TextureHandle texture_handle) override;
  58. /// Called by RmlUi when it wants to set the current transform matrix to a new matrix.
  59. void PushTransform(const Rml::Core::Matrix4f& transform) override;
  60. /// Called by RmlUi when it wants to revert the latest transform change.
  61. void PopTransform(const Rml::Core::Matrix4f& transform) override;
  62. // ShellRenderInterfaceExtensions
  63. void SetViewport(int width, int height) override;
  64. void SetContext(void *context) override;
  65. bool AttachToNative(void *nativeWindow) override;
  66. void DetachFromNative(void) override;
  67. void PrepareRenderBuffer(void) override;
  68. void PresentRenderBuffer(void) override;
  69. protected:
  70. int m_width;
  71. int m_height;
  72. int m_transforms;
  73. void *m_rmlui_context;
  74. #if defined(RMLUI_PLATFORM_MACOSX)
  75. AGLContext gl_context;
  76. #elif defined(RMLUI_PLATFORM_LINUX)
  77. struct __X11NativeWindowData nwData;
  78. GLXContext gl_context;
  79. #elif defined(RMLUI_PLATFORM_WIN32)
  80. HWND window_handle;
  81. HDC device_context;
  82. HGLRC render_context;
  83. #else
  84. #error Platform is undefined, this must be resolved so gl_context is usable.
  85. #endif
  86. };
  87. #endif