RenderInterfaceCompatibility.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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-2023 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_CORE_RENDERINTERFACECOMPATIBILITY_H
  29. #define RMLUI_CORE_RENDERINTERFACECOMPATIBILITY_H
  30. #include "RenderInterface.h"
  31. namespace Rml {
  32. class RenderInterfaceAdapter;
  33. /**
  34. Provides a backward-compatible adapter for render interfaces written for RmlUi 5 and lower. The compatibility adapter
  35. should be used as follows.
  36. 1. In your legacy RenderInterface implementation, derive from Rml::RenderInterfaceCompatibility instead of
  37. Rml::RenderInterface.
  38. #include <RmlUi/Core/RenderInterfaceCompatibility.h>
  39. class MyRenderInterface : public Rml::RenderInterfaceCompatibility { ... };
  40. 2. Use the adapted interface when setting the RmlUi render interface.
  41. Rml::SetRenderInterface(my_render_interface.GetAdaptedInterface());
  42. New rendering features are not supported when using the compatibility adapter.
  43. */
  44. class RMLUICORE_API RenderInterfaceCompatibility : public NonCopyMoveable {
  45. public:
  46. RenderInterfaceCompatibility();
  47. virtual ~RenderInterfaceCompatibility();
  48. virtual void RenderGeometry(Vertex* vertices, int num_vertices, int* indices, int num_indices, TextureHandle texture,
  49. const Vector2f& translation) = 0;
  50. virtual CompiledGeometryHandle CompileGeometry(Vertex* vertices, int num_vertices, int* indices, int num_indices, TextureHandle texture);
  51. virtual void RenderCompiledGeometry(CompiledGeometryHandle geometry, const Vector2f& translation);
  52. virtual void ReleaseCompiledGeometry(CompiledGeometryHandle geometry);
  53. virtual void EnableScissorRegion(bool enable) = 0;
  54. virtual void SetScissorRegion(int x, int y, int width, int height) = 0;
  55. virtual bool LoadTexture(TextureHandle& texture_handle, Vector2i& texture_dimensions, const String& source);
  56. virtual bool GenerateTexture(TextureHandle& texture_handle, const byte* source, const Vector2i& source_dimensions);
  57. virtual void ReleaseTexture(TextureHandle texture);
  58. virtual void SetTransform(const Matrix4f* transform);
  59. RenderInterface* GetAdaptedInterface();
  60. private:
  61. UniquePtr<RenderInterfaceAdapter> adapter;
  62. };
  63. /*
  64. The render interface adapter takes calls from the render interface, makes any necessary conversions, and passes the
  65. calls on to the legacy render interface.
  66. */
  67. class RMLUICORE_API RenderInterfaceAdapter : public RenderInterface {
  68. public:
  69. CompiledGeometryHandle CompileGeometry(Span<const Vertex> vertices, Span<const int> indices) override;
  70. void RenderGeometry(CompiledGeometryHandle handle, Vector2f translation, TextureHandle texture) override;
  71. void ReleaseGeometry(CompiledGeometryHandle handle) override;
  72. void EnableScissorRegion(bool enable) override;
  73. void SetScissorRegion(Rectanglei region) override;
  74. TextureHandle LoadTexture(Vector2i& texture_dimensions, const String& source) override;
  75. TextureHandle GenerateTexture(Span<const byte> source_data, Vector2i source_dimensions) override;
  76. void ReleaseTexture(TextureHandle texture_handle) override;
  77. void EnableClipMask(bool enable) override;
  78. void RenderToClipMask(ClipMaskOperation operation, CompiledGeometryHandle geometry, Vector2f translation) override;
  79. void SetTransform(const Matrix4f* transform) override;
  80. private:
  81. using LegacyCompiledGeometryHandle = CompiledGeometryHandle;
  82. struct AdaptedGeometry {
  83. Vector<Vertex> vertices;
  84. Vector<int> indices;
  85. SmallUnorderedMap<TextureHandle, LegacyCompiledGeometryHandle> textures;
  86. };
  87. RenderInterfaceAdapter(RenderInterfaceCompatibility& legacy);
  88. RenderInterfaceCompatibility& legacy;
  89. friend Rml::RenderInterfaceCompatibility::RenderInterfaceCompatibility();
  90. };
  91. } // namespace Rml
  92. #endif