From ded1cb1b096e3cb6040e371edf9a25db3e1306a0 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Thu, 27 Feb 2025 16:47:42 -0800 Subject: [PATCH] builders now accept StaticString names The const char* version of name is node [[deprecated]]. This change is only cosmetic, no implementation is changed. This is a first step toward eliminating non literal tags. --- filament/include/filament/BufferObject.h | 13 +++++++++++++ filament/include/filament/FilamentAPI.h | 7 +++++++ filament/include/filament/IndexBuffer.h | 13 +++++++++++++ filament/include/filament/InstanceBuffer.h | 13 +++++++++++++ filament/include/filament/MorphTargetBuffer.h | 13 +++++++++++++ filament/include/filament/SkinningBuffer.h | 13 +++++++++++++ filament/include/filament/Stream.h | 13 +++++++++++++ filament/include/filament/Texture.h | 15 ++++++++++++++- filament/include/filament/VertexBuffer.h | 13 +++++++++++++ filament/src/details/BufferObject.cpp | 5 +++++ filament/src/details/IndexBuffer.cpp | 5 +++++ filament/src/details/InstanceBuffer.cpp | 6 ++++++ filament/src/details/MorphTargetBuffer.cpp | 5 +++++ filament/src/details/SkinningBuffer.cpp | 5 +++++ filament/src/details/Stream.cpp | 5 +++++ filament/src/details/Texture.cpp | 6 ++++++ filament/src/details/VertexBuffer.cpp | 5 +++++ 17 files changed, 154 insertions(+), 1 deletion(-) diff --git a/filament/include/filament/BufferObject.h b/filament/include/filament/BufferObject.h index b946449afb..e18778052e 100644 --- a/filament/include/filament/BufferObject.h +++ b/filament/include/filament/BufferObject.h @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -90,9 +91,21 @@ public: * @param name A string to identify this BufferObject * @param len Length of name, should be less than or equal to 128 * @return This Builder, for chaining calls. + * @deprecated Use name(utils::StaticString const&) instead. */ + UTILS_DEPRECATED Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; + /** + * Associate an optional name with this BufferObject for debugging purposes. + * + * name will show in error messages and should be kept as short as possible. + * + * @param name A string literal to identify this BufferObject + * @return This Builder, for chaining calls. + */ + Builder& name(utils::StaticString const& name) noexcept; + /** * Creates the BufferObject and returns a pointer to it. After creation, the buffer * object is uninitialized. Use BufferObject::setBuffer() to initialize it. diff --git a/filament/include/filament/FilamentAPI.h b/filament/include/filament/FilamentAPI.h index 7fa1943384..0931638fa9 100644 --- a/filament/include/filament/FilamentAPI.h +++ b/filament/include/filament/FilamentAPI.h @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -61,11 +62,17 @@ UTILS_PUBLIC void builderMakeName(utils::CString& outName, const char* name, siz template class UTILS_PUBLIC BuilderNameMixin { public: + UTILS_DEPRECATED Builder& name(const char* name, size_t len) noexcept { builderMakeName(mName, name, len); return static_cast(*this); } + Builder& name(utils::StaticString const& name) noexcept { + builderMakeName(mName, name.data(), name.size()); + return static_cast(*this); + } + utils::CString const& getName() const noexcept { return mName; } private: diff --git a/filament/include/filament/IndexBuffer.h b/filament/include/filament/IndexBuffer.h index 57c95921d7..dfe0e07532 100644 --- a/filament/include/filament/IndexBuffer.h +++ b/filament/include/filament/IndexBuffer.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -95,9 +96,21 @@ public: * @param name A string to identify this IndexBuffer * @param len Length of name, should be less than or equal to 128 * @return This Builder, for chaining calls. + * @deprecated Use name(utils::StaticString const&) instead. */ + UTILS_DEPRECATED Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; + /** + * Associate an optional name with this IndexBuffer for debugging purposes. + * + * name will show in error messages and should be kept as short as possible. + * + * @param name A string literal to identify this IndexBuffer + * @return This Builder, for chaining calls. + */ + Builder& name(utils::StaticString const& name) noexcept; + /** * Creates the IndexBuffer object and returns a pointer to it. After creation, the index * buffer is uninitialized. Use IndexBuffer::setBuffer() to initialize the IndexBuffer. diff --git a/filament/include/filament/InstanceBuffer.h b/filament/include/filament/InstanceBuffer.h index b744e32c7b..09e2acee8d 100644 --- a/filament/include/filament/InstanceBuffer.h +++ b/filament/include/filament/InstanceBuffer.h @@ -21,6 +21,7 @@ #include #include +#include #include @@ -82,9 +83,21 @@ public: * @param name A string to identify this InstanceBuffer * @param len Length of name, should be less than or equal to 128 * @return This Builder, for chaining calls. + * @deprecated Use name(utils::StaticString const&) instead. */ + UTILS_DEPRECATED Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; + /** + * Associate an optional name with this InstanceBuffer for debugging purposes. + * + * name will show in error messages and should be kept as short as possible. + * + * @param name A string literal to identify this InstanceBuffer + * @return This Builder, for chaining calls. + */ + Builder& name(utils::StaticString const& name) noexcept; + /** * Creates the InstanceBuffer object and returns a pointer to it. */ diff --git a/filament/include/filament/MorphTargetBuffer.h b/filament/include/filament/MorphTargetBuffer.h index 79c2710670..594f1a6ca4 100644 --- a/filament/include/filament/MorphTargetBuffer.h +++ b/filament/include/filament/MorphTargetBuffer.h @@ -22,6 +22,7 @@ #include #include +#include #include @@ -75,9 +76,21 @@ public: * @param name A string to identify this MorphTargetBuffer * @param len Length of name, should be less than or equal to 128 * @return This Builder, for chaining calls. + * @deprecated Use name(utils::StaticString const&) instead. */ + UTILS_DEPRECATED Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; + /** + * Associate an optional name with this MorphTargetBuffer for debugging purposes. + * + * name will show in error messages and should be kept as short as possible. + * + * @param name A string literal to identify this MorphTargetBuffer + * @return This Builder, for chaining calls. + */ + Builder& name(utils::StaticString const& name) noexcept; + /** * Creates the MorphTargetBuffer object and returns a pointer to it. * diff --git a/filament/include/filament/SkinningBuffer.h b/filament/include/filament/SkinningBuffer.h index ac440425cb..c397f62b68 100644 --- a/filament/include/filament/SkinningBuffer.h +++ b/filament/include/filament/SkinningBuffer.h @@ -22,6 +22,7 @@ #include #include +#include #include @@ -81,9 +82,21 @@ public: * @param name A string to identify this SkinningBuffer * @param len Length of name, should be less than or equal to 128 * @return This Builder, for chaining calls. + * @deprecated Use name(utils::StaticString const&) instead. */ + UTILS_DEPRECATED Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; + /** + * Associate an optional name with this SkinningBuffer for debugging purposes. + * + * name will show in error messages and should be kept as short as possible. + * + * @param name A string literal to identify this SkinningBuffer + * @return This Builder, for chaining calls. + */ + Builder& name(utils::StaticString const& name) noexcept; + /** * Creates the SkinningBuffer object and returns a pointer to it. * diff --git a/filament/include/filament/Stream.h b/filament/include/filament/Stream.h index 9cf7fa1634..d3f914eb47 100644 --- a/filament/include/filament/Stream.h +++ b/filament/include/filament/Stream.h @@ -23,6 +23,7 @@ #include #include +#include #include @@ -150,9 +151,21 @@ public: * @param name A string to identify this Stream * @param len Length of name, should be less than or equal to 128 * @return This Builder, for chaining calls. + * @deprecated Use name(utils::StaticString const&) instead. */ + UTILS_DEPRECATED Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; + /** + * Associate an optional name with this Stream for debugging purposes. + * + * name will show in error messages and should be kept as short as possible. + * + * @param name A string literal to identify this Stream + * @return This Builder, for chaining calls. + */ + Builder& name(utils::StaticString const& name) noexcept; + /** * Creates the Stream object and returns a pointer to it. * diff --git a/filament/include/filament/Texture.h b/filament/include/filament/Texture.h index 3241d9a932..c352615c9b 100644 --- a/filament/include/filament/Texture.h +++ b/filament/include/filament/Texture.h @@ -26,6 +26,7 @@ #include #include +#include #include @@ -229,8 +230,20 @@ public: * @param name A string to identify this Texture * @param len Length of name, should be less than or equal to 128 * @return This Builder, for chaining calls. + * @deprecated Use name(utils::StaticString const&) instead. */ - Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; + UTILS_DEPRECATED + Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; + + /** + * Associate an optional name with this Texture for debugging purposes. + * + * name will show in error messages and should be kept as short as possible. + * + * @param name A string literal to identify this Texture + * @return This Builder, for chaining calls. + */ + Builder& name(utils::StaticString const& name) noexcept; /** * Creates an external texture. The content must be set using setExternalImage(). diff --git a/filament/include/filament/VertexBuffer.h b/filament/include/filament/VertexBuffer.h index b850aab71a..885d00199e 100644 --- a/filament/include/filament/VertexBuffer.h +++ b/filament/include/filament/VertexBuffer.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -170,9 +171,21 @@ public: * @param name A string to identify this VertexBuffer * @param len Length of name, should be less than or equal to 128 * @return This Builder, for chaining calls. + * @deprecated Use name(utils::StaticString const&) instead. */ + UTILS_DEPRECATED Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; + /** + * Associate an optional name with this VertexBuffer for debugging purposes. + * + * name will show in error messages and should be kept as short as possible. + * + * @param name A string literal to identify this VertexBuffer + * @return This Builder, for chaining calls. + */ + Builder& name(utils::StaticString const& name) noexcept; + /** * Creates the VertexBuffer object and returns a pointer to it. * diff --git a/filament/src/details/BufferObject.cpp b/filament/src/details/BufferObject.cpp index a41725295b..a3e588db81 100644 --- a/filament/src/details/BufferObject.cpp +++ b/filament/src/details/BufferObject.cpp @@ -21,6 +21,7 @@ #include "FilamentAPI-impl.h" #include +#include namespace filament { @@ -51,6 +52,10 @@ BufferObject::Builder& BufferObject::Builder::name(const char* name, size_t cons return BuilderNameMixin::name(name, len); } +BufferObject::Builder& BufferObject::Builder::name(utils::StaticString const& name) noexcept { + return BuilderNameMixin::name(name); +} + BufferObject* BufferObject::Builder::build(Engine& engine) { return downcast(engine).createBufferObject(*this); } diff --git a/filament/src/details/IndexBuffer.cpp b/filament/src/details/IndexBuffer.cpp index 27775bde49..87e04aef77 100644 --- a/filament/src/details/IndexBuffer.cpp +++ b/filament/src/details/IndexBuffer.cpp @@ -21,6 +21,7 @@ #include "FilamentAPI-impl.h" #include +#include namespace filament { @@ -51,6 +52,10 @@ IndexBuffer::Builder& IndexBuffer::Builder::name(const char* name, size_t const return BuilderNameMixin::name(name, len); } +IndexBuffer::Builder& IndexBuffer::Builder::name(utils::StaticString const& name) noexcept { + return BuilderNameMixin::name(name); +} + IndexBuffer* IndexBuffer::Builder::build(Engine& engine) { return downcast(engine).createIndexBuffer(*this); } diff --git a/filament/src/details/InstanceBuffer.cpp b/filament/src/details/InstanceBuffer.cpp index 955711ab75..cbc9b1bdf6 100644 --- a/filament/src/details/InstanceBuffer.cpp +++ b/filament/src/details/InstanceBuffer.cpp @@ -21,6 +21,8 @@ #include "FilamentAPI-impl.h" +#include + #include #include @@ -54,6 +56,10 @@ InstanceBuffer::Builder& InstanceBuffer::Builder::name(const char* name, size_t return BuilderNameMixin::name(name, len); } +InstanceBuffer::Builder& InstanceBuffer::Builder::name(utils::StaticString const& name) noexcept { + return BuilderNameMixin::name(name); +} + InstanceBuffer* InstanceBuffer::Builder::build(Engine& engine) { FILAMENT_CHECK_PRECONDITION(mImpl->mInstanceCount >= 1) << "instanceCount must be >= 1."; FILAMENT_CHECK_PRECONDITION(mImpl->mInstanceCount <= engine.getMaxAutomaticInstances()) diff --git a/filament/src/details/MorphTargetBuffer.cpp b/filament/src/details/MorphTargetBuffer.cpp index b65cd290a3..33553ffa08 100644 --- a/filament/src/details/MorphTargetBuffer.cpp +++ b/filament/src/details/MorphTargetBuffer.cpp @@ -26,6 +26,7 @@ #include #include +#include namespace filament { @@ -59,6 +60,10 @@ MorphTargetBuffer::Builder& MorphTargetBuffer::Builder::name(const char* name, s return BuilderNameMixin::name(name, len); } +MorphTargetBuffer::Builder& MorphTargetBuffer::Builder::name(utils::StaticString const& name) noexcept { + return BuilderNameMixin::name(name); +} + MorphTargetBuffer* MorphTargetBuffer::Builder::build(Engine& engine) { return downcast(engine).createMorphTargetBuffer(*this); } diff --git a/filament/src/details/SkinningBuffer.cpp b/filament/src/details/SkinningBuffer.cpp index 1b608a3aff..d381e9a538 100644 --- a/filament/src/details/SkinningBuffer.cpp +++ b/filament/src/details/SkinningBuffer.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -64,6 +65,10 @@ SkinningBuffer::Builder& SkinningBuffer::Builder::name(const char* name, size_t return BuilderNameMixin::name(name, len); } +SkinningBuffer::Builder& SkinningBuffer::Builder::name(utils::StaticString const& name) noexcept { + return BuilderNameMixin::name(name); +} + SkinningBuffer* SkinningBuffer::Builder::build(Engine& engine) { return downcast(engine).createSkinningBuffer(*this); } diff --git a/filament/src/details/Stream.cpp b/filament/src/details/Stream.cpp index 65e02d6712..294a32a147 100644 --- a/filament/src/details/Stream.cpp +++ b/filament/src/details/Stream.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -65,6 +66,10 @@ Stream::Builder& Stream::Builder::name(const char* name, size_t const len) noexc return BuilderNameMixin::name(name, len); } +Stream::Builder& Stream::Builder::name(utils::StaticString const& name) noexcept { + return BuilderNameMixin::name(name); +} + Stream* Stream::Builder::build(Engine& engine) { return downcast(engine).createStream(*this); } diff --git a/filament/src/details/Texture.cpp b/filament/src/details/Texture.cpp index 8a367a2fd3..7d1a40963a 100644 --- a/filament/src/details/Texture.cpp +++ b/filament/src/details/Texture.cpp @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include #include @@ -152,6 +154,10 @@ Texture::Builder& Texture::Builder::name(const char* name, size_t const len) noe return BuilderNameMixin::name(name, len); } +Texture::Builder& Texture::Builder::name(StaticString const& name) noexcept { + return BuilderNameMixin::name(name); +} + Texture* Texture::Builder::build(Engine& engine) { if (mImpl->mTarget != SamplerType::SAMPLER_EXTERNAL) { FILAMENT_CHECK_PRECONDITION(Texture::isTextureFormatSupported(engine, mImpl->mFormat)) diff --git a/filament/src/details/VertexBuffer.cpp b/filament/src/details/VertexBuffer.cpp index 881ff2abce..2e765c1d12 100644 --- a/filament/src/details/VertexBuffer.cpp +++ b/filament/src/details/VertexBuffer.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -152,6 +153,10 @@ VertexBuffer::Builder& VertexBuffer::Builder::name(const char* name, size_t cons return BuilderNameMixin::name(name, len); } +VertexBuffer::Builder& VertexBuffer::Builder::name(utils::StaticString const& name) noexcept { + return BuilderNameMixin::name(name); +} + VertexBuffer* VertexBuffer::Builder::build(Engine& engine) { FILAMENT_CHECK_PRECONDITION(mImpl->mVertexCount > 0) << "vertexCount cannot be 0"; FILAMENT_CHECK_PRECONDITION(mImpl->mBufferCount > 0) << "bufferCount cannot be 0";