ShellRenderInterfaceOpenGL.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. virtual void RenderGeometry(Rml::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rml::Core::TextureHandle texture, const Rml::Core::Vector2f& translation);
  42. /// Called by RmlUi when it wants to compile geometry it believes will be static for the forseeable future.
  43. virtual Rml::Core::CompiledGeometryHandle CompileGeometry(Rml::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rml::Core::TextureHandle texture);
  44. /// Called by RmlUi when it wants to render application-compiled geometry.
  45. virtual void RenderCompiledGeometry(Rml::Core::CompiledGeometryHandle geometry, const Rml::Core::Vector2f& translation);
  46. /// Called by RmlUi when it wants to release application-compiled geometry.
  47. virtual void ReleaseCompiledGeometry(Rml::Core::CompiledGeometryHandle geometry);
  48. /// Called by RmlUi when it wants to enable or disable scissoring to clip content.
  49. virtual void EnableScissorRegion(bool enable);
  50. /// Called by RmlUi when it wants to change the scissor region.
  51. virtual void SetScissorRegion(int x, int y, int width, int height);
  52. /// Called by RmlUi when a texture is required by the library.
  53. virtual bool LoadTexture(Rml::Core::TextureHandle& texture_handle, Rml::Core::Vector2i& texture_dimensions, const Rml::Core::String& source);
  54. /// Called by RmlUi when a texture is required to be built from an internally-generated sequence of pixels.
  55. virtual bool GenerateTexture(Rml::Core::TextureHandle& texture_handle, const Rml::Core::byte* source, const Rml::Core::Vector2i& source_dimensions);
  56. /// Called by RmlUi when a loaded texture is no longer required.
  57. virtual void ReleaseTexture(Rml::Core::TextureHandle texture_handle);
  58. /// Called by RmlUi when it wants to set the current transform matrix to a new matrix.
  59. virtual void PushTransform(const Rml::Core::RowMajorMatrix4f& transform);
  60. virtual void PushTransform(const Rml::Core::ColumnMajorMatrix4f& transform);
  61. /// Called by RmlUi when it wants to revert the latest transform change.
  62. virtual void PopTransform(const Rml::Core::Matrix4f& transform);
  63. // ShellRenderInterfaceExtensions
  64. virtual void SetViewport(int width, int height);
  65. virtual void SetContext(void *context);
  66. virtual bool AttachToNative(void *nativeWindow);
  67. virtual void DetachFromNative(void);
  68. virtual void PrepareRenderBuffer(void);
  69. virtual void PresentRenderBuffer(void);
  70. protected:
  71. int m_width;
  72. int m_height;
  73. int m_transforms;
  74. void *m_rmlui_context;
  75. #if defined(RMLUI_PLATFORM_MACOSX)
  76. AGLContext gl_context;
  77. #elif defined(RMLUI_PLATFORM_LINUX)
  78. struct __X11NativeWindowData nwData;
  79. GLXContext gl_context;
  80. #elif defined(RMLUI_PLATFORM_WIN32)
  81. HWND window_handle;
  82. HDC device_context;
  83. HGLRC render_context;
  84. #else
  85. #error Platform is undefined, this must be resolved so gl_context is usable.
  86. #endif
  87. };
  88. #endif