Browse Source

Add render interface commands for layers and filters

Michael Ragazzon 2 years ago
parent
commit
1be3e86be1
3 changed files with 43 additions and 0 deletions
  1. 29 0
      Include/RmlUi/Core/RenderInterface.h
  2. 3 0
      Include/RmlUi/Core/Types.h
  3. 11 0
      Source/Core/RenderInterface.cpp

+ 29 - 0
Include/RmlUi/Core/RenderInterface.h

@@ -37,6 +37,19 @@
 
 namespace Rml {
 
+enum class LayerFill {
+	None,  // No operation necessary, does not care about the layer color.
+	Clear, // Clear the layer to transparent black.
+	Clone, // Copy the color data from the previous layer.
+};
+enum class BlendMode {
+	Blend,   // Normal alpha blending.
+	Replace, // Replace the destination colors from the source.
+	Discard, // Leave the destination colors unaltered.
+};
+
+using FilterHandleList = Vector<CompiledFilterHandle>;
+
 /**
     The abstract base class for application-specific rendering implementation. Your application must provide a concrete
     implementation of this class and install it through Rml::SetRenderInterface() in order for anything to be rendered.
@@ -110,6 +123,22 @@ public:
 	/// is submitted. Then it expects the renderer to use an identity matrix or otherwise omit the multiplication with the transform.
 	/// @param[in] transform The new transform to apply, or nullptr if no transform applies to the current element.
 	virtual void SetTransform(const Matrix4f* transform);
+
+	/// Called by RmlUi when it wants to push a new layer onto the render stack.
+	/// @param[in] layer_fill Specifies how the color data of the new layer should be filled.
+	virtual void PushLayer(LayerFill layer_fill);
+	/// Called by RmlUi when it wants to pop the render layer stack, after applying filters to the top layer and blending it into the layer below.
+	/// @param[in] blend_mode The mode used to blend the top layer into the one below.
+	/// @param[in] filters A list of compiled filters which should be applied to the top layer before blending.
+	virtual void PopLayer(BlendMode blend_mode, const FilterHandleList& filters);
+
+	/// Called by RmlUi when it wants to compile a new filter.
+	/// @param[in] name The name of the filter.
+	/// @param[in] parameters The list of name-value parameters specified for the filter.
+	virtual CompiledFilterHandle CompileFilter(const String& name, const Dictionary& parameters);
+	/// Called by RmlUi when it no longer needs a previously compiled filter.
+	/// @param[in] filter The handle to a previously compiled filter.
+	virtual void ReleaseCompiledFilter(CompiledFilterHandle filter);
 };
 
 } // namespace Rml

+ 3 - 0
Include/RmlUi/Core/Types.h

@@ -89,6 +89,7 @@ struct Animation;
 struct Transition;
 struct TransitionList;
 struct DecoratorDeclarationList;
+struct FilterDeclarationList;
 enum class EventId : uint16_t;
 enum class PropertyId : uint8_t;
 enum class MediaQueryId : uint8_t;
@@ -98,6 +99,7 @@ enum class FamilyId : int;
 using FileHandle = uintptr_t;
 using TextureHandle = uintptr_t;
 using CompiledGeometryHandle = uintptr_t;
+using CompiledFilterHandle = uintptr_t;
 using DecoratorDataHandle = uintptr_t;
 using FontFaceHandle = uintptr_t;
 using FontEffectsHandle = uintptr_t;
@@ -129,6 +131,7 @@ struct FontEffects {
 // Additional smart pointers
 using TransformPtr = SharedPtr<Transform>;
 using DecoratorsPtr = SharedPtr<const DecoratorDeclarationList>;
+using FiltersPtr = SharedPtr<const FilterDeclarationList>;
 using FontEffectsPtr = SharedPtr<const FontEffects>;
 
 // Data binding types

+ 11 - 0
Source/Core/RenderInterface.cpp

@@ -66,4 +66,15 @@ void RenderInterface::ReleaseTexture(TextureHandle /*texture*/) {}
 
 void RenderInterface::SetTransform(const Matrix4f* /*transform*/) {}
 
+void RenderInterface::PushLayer(LayerFill /*layer_fill*/) {}
+
+void RenderInterface::PopLayer(BlendMode /*blend_mode*/, const FilterHandleList& /*filters*/) {}
+
+CompiledFilterHandle RenderInterface::CompileFilter(const String& /*name*/, const Dictionary& /*parameters*/)
+{
+	return CompiledFilterHandle{};
+}
+
+void RenderInterface::ReleaseCompiledFilter(CompiledFilterHandle /*filter*/) {}
+
 } // namespace Rml