ShellRenderInterfaceOpenGL.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 RMLUI_SHELL_SHELLRENDERINTERFACEOPENGL_H
  29. #define RMLUI_SHELL_SHELLRENDERINTERFACEOPENGL_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::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::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rml::TextureHandle texture, const Rml::Vector2f& translation) override;
  42. /// Called by RmlUi when it wants to compile geometry it believes will be static for the forseeable future.
  43. Rml::CompiledGeometryHandle CompileGeometry(Rml::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rml::TextureHandle texture) override;
  44. /// Called by RmlUi when it wants to render application-compiled geometry.
  45. void RenderCompiledGeometry(Rml::CompiledGeometryHandle geometry, const Rml::Vector2f& translation) override;
  46. /// Called by RmlUi when it wants to release application-compiled geometry.
  47. void ReleaseCompiledGeometry(Rml::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::TextureHandle& texture_handle, Rml::Vector2i& texture_dimensions, const Rml::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::TextureHandle& texture_handle, const Rml::byte* source, const Rml::Vector2i& source_dimensions) override;
  56. /// Called by RmlUi when a loaded texture is no longer required.
  57. void ReleaseTexture(Rml::TextureHandle texture_handle) override;
  58. /// Called by RmlUi when it wants to set the current transform matrix to a new matrix.
  59. void SetTransform(const Rml::Matrix4f* transform) override;
  60. // Extensions used by the test suite
  61. struct Image {
  62. int width = 0;
  63. int height = 0;
  64. int num_components = 0;
  65. Rml::UniquePtr<Rml::byte[]> data;
  66. };
  67. Image CaptureScreen();
  68. // ShellRenderInterfaceExtensions
  69. void SetViewport(int width, int height) override;
  70. bool AttachToNative(void *nativeWindow) override;
  71. void DetachFromNative(void) override;
  72. void PrepareRenderBuffer(void) override;
  73. void PresentRenderBuffer(void) override;
  74. protected:
  75. int m_width;
  76. int m_height;
  77. bool m_transform_enabled;
  78. #if defined(RMLUI_PLATFORM_MACOSX)
  79. AGLContext gl_context;
  80. #elif defined(RMLUI_PLATFORM_LINUX)
  81. struct __X11NativeWindowData nwData;
  82. GLXContext gl_context;
  83. #elif defined(RMLUI_PLATFORM_WIN32)
  84. HWND window_handle;
  85. HDC device_context;
  86. HGLRC render_context;
  87. #else
  88. #error Platform is undefined, this must be resolved so gl_context is usable.
  89. #endif
  90. };
  91. #endif