-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Geometry and Texture, introduce unique render resources
Unique render resources - Consist of a unique handle and a pointer to its render manger. - Automatically cleans up its underlying resource when out of scope. - Ensuring resources are always released in the correct render interface. - Geometry, CompiledShader, CompiledFilter and CallbackTexture, are now unique render resources. - All of which are constructed through the render manager. RenderManager - Now the owner of all resources constructed through the render interface. - Wraps all calls to the render interface, the interface should no longer be called directly. - Added back ability to use multiple render interfaces for separate contexts. - Each render interface is wrapped by a unique render manager. Geometry - Geometry is now a unique render resource. - Geometry is now constructed from a Mesh through the render manager. The mesh cannot be modified after it is submitted. However, it can be released to reuse its buffers, then resubmitted. - With this change, we can guarantee pointer stability of submitted vertex and index pointers, until the call to ReleaseCompiledGeometry. - Move texture out of Geometry, instead, a texture can be provided during the call to render. Mesh - Simple data structure, contains indices and vertices defining the mesh. - Meshes can be constructed directly or using MeshUtilities (previously GeometryUtilities). Texture - The render manager now owns and stores file textures. - File textures are released when the render manager is destroyed, during Rml::Shutdown. - Each render manager has its own texture database to lookup and reuse textures with the same path. - `Texture` is now simply a non-owning view and can be freely copied. - The user is responsible for ensuring validity of the underlying resource's lifetime. - `CallbackTexture` on the other hand is a unique render resource, automatically released when out of scope. - Can make a non-owning reference (Texture). - Handlers are available for managing texture sources for unknown or multiple render managers, generating references (Texture) as needed. - `TextureSource` for file textures and `CallbackTextureSource` for callback textures. StableVector - New container for stable indices which remain valid after entries are erased. Breaking changes - New procedure for generating geometry and textures (see above for details). - GeometryUtilities renamed to MeshUtilities.
- Loading branch information
Showing
132 changed files
with
2,217 additions
and
1,821 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* This source file is part of RmlUi, the HTML/CSS Interface Middleware | ||
* | ||
* For the latest information, see http://github.com/mikke89/RmlUi | ||
* | ||
* Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd | ||
* Copyright (c) 2019-2023 The RmlUi Team, and contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#ifndef RMLUI_CORE_CALLBACKTEXTURE_H | ||
#define RMLUI_CORE_CALLBACKTEXTURE_H | ||
|
||
#include "Header.h" | ||
#include "Types.h" | ||
#include "UniqueRenderResource.h" | ||
|
||
namespace Rml { | ||
|
||
class RenderInterface; | ||
class RenderManager; | ||
class CallbackTextureInterface; | ||
class Texture; | ||
|
||
/* | ||
Callback function for generating textures on demand. | ||
/// @param[in] texture_interface The interface used to specify the texture. | ||
/// @return True on success. | ||
*/ | ||
using CallbackTextureFunction = Function<bool(const CallbackTextureInterface& texture_interface)>; | ||
|
||
/** | ||
Callback texture is a unique render resource for generating textures on demand. | ||
It is constructed through the render manager. | ||
*/ | ||
class RMLUICORE_API CallbackTexture final : public UniqueRenderResource<CallbackTexture, StableVectorIndex, StableVectorIndex::Invalid> { | ||
public: | ||
CallbackTexture() = default; | ||
|
||
operator Texture() const; | ||
|
||
void Release(); | ||
|
||
private: | ||
CallbackTexture(RenderManager* render_manager, StableVectorIndex resource_handle) : UniqueRenderResource(render_manager, resource_handle) {} | ||
friend class RenderManager; | ||
}; | ||
|
||
/** | ||
Interface handed to the texture callback function, which the client can use to submit a single texture. | ||
*/ | ||
class RMLUICORE_API CallbackTextureInterface { | ||
public: | ||
CallbackTextureInterface(RenderManager& render_manager, RenderInterface& render_interface, TextureHandle& texture_handle, Vector2i& dimensions); | ||
|
||
/// Generate texture from byte source. | ||
/// @param[in] source Texture data in 8-bit RGBA (premultiplied) format. | ||
/// @param[in] dimensions The width and height of the texture. | ||
/// @return True on success. | ||
bool GenerateTexture(const byte* source, Vector2i dimensions) const; | ||
|
||
/// Store the current layer as a texture, so that it can be rendered with geometry later. | ||
/// @param[in] dimensions The dimensions of the resulting texture, which will be copied from the top-left part of the active layer. | ||
void SaveLayerAsTexture(Vector2i dimensions) const; | ||
|
||
RenderManager& GetRenderManager() const; | ||
|
||
private: | ||
RenderManager& render_manager; | ||
RenderInterface& render_interface; | ||
TextureHandle& texture_handle; | ||
Vector2i& dimensions; | ||
}; | ||
|
||
/** | ||
Stores a texture callback function, which is used to generate and cache callback textures possibly for multiple render managers. | ||
*/ | ||
class RMLUICORE_API CallbackTextureSource { | ||
public: | ||
CallbackTextureSource() = default; | ||
CallbackTextureSource(CallbackTextureFunction&& callback); | ||
~CallbackTextureSource() = default; | ||
|
||
CallbackTextureSource(const CallbackTextureSource&) = delete; | ||
CallbackTextureSource& operator=(const CallbackTextureSource&) = delete; | ||
|
||
CallbackTextureSource(CallbackTextureSource&& other) noexcept; | ||
CallbackTextureSource& operator=(CallbackTextureSource&& other) noexcept; | ||
|
||
Texture GetTexture(RenderManager& render_manager) const; | ||
|
||
private: | ||
CallbackTextureFunction callback; | ||
mutable SmallUnorderedMap<RenderManager*, CallbackTexture> textures; | ||
}; | ||
|
||
} // namespace Rml | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* This source file is part of RmlUi, the HTML/CSS Interface Middleware | ||
* | ||
* For the latest information, see http://github.com/mikke89/RmlUi | ||
* | ||
* Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd | ||
* Copyright (c) 2019-2023 The RmlUi Team, and contributors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#ifndef RMLUI_CORE_COMPILEDFILTERSHADER_H | ||
#define RMLUI_CORE_COMPILEDFILTERSHADER_H | ||
|
||
#include "Header.h" | ||
#include "UniqueRenderResource.h" | ||
|
||
namespace Rml { | ||
|
||
class RenderManager; | ||
|
||
/** | ||
A compiled filter to be applied during layer pop in its render manager. A unique resource constructed through the render manager. | ||
*/ | ||
class RMLUICORE_API CompiledFilter final : public UniqueRenderResource<CompiledFilter, CompiledFilterHandle, CompiledFilterHandle(0)> { | ||
public: | ||
CompiledFilter() = default; | ||
|
||
void AddHandleTo(FilterHandleList& list); | ||
|
||
void Release(); | ||
|
||
private: | ||
CompiledFilter(RenderManager* render_manager, CompiledFilterHandle resource_handle) : UniqueRenderResource(render_manager, resource_handle) {} | ||
friend class RenderManager; | ||
}; | ||
|
||
/** | ||
A compiled shader to be used when rendering geometry. A unique resource constructed through the render manager. | ||
*/ | ||
class RMLUICORE_API CompiledShader final : public UniqueRenderResource<CompiledShader, CompiledShaderHandle, CompiledShaderHandle(0)> { | ||
public: | ||
CompiledShader() = default; | ||
|
||
void Release(); | ||
|
||
private: | ||
CompiledShader(RenderManager* render_manager, CompiledShaderHandle resource_handle) : UniqueRenderResource(render_manager, resource_handle) {} | ||
friend class RenderManager; | ||
}; | ||
|
||
} // namespace Rml | ||
|
||
#endif |
Oops, something went wrong.