Skip to content

Commit

Permalink
large code cleanup (#8364)
Browse files Browse the repository at this point in the history
* Remove redundant qualifiers in filament public headers

* remove redundant qualifiers in filament implementation

* remove redundant qualifiers in libutils public headers

* remove redundant qualifier for libutils implementation

* remove redundant qualifiers for libmath

* use is_same_v<> instead of is_same<>

* bring back Builder::name()

we keep Builder::name() on all object, and forward to the MixIn class
that does the implementation, so that we have correct documentation, and
better IDE completion.

* add missing const parameters in filament's implementation

* various source cleanup

- missing includes
- missing const
- C cast style
- superfluous inline keyword
  • Loading branch information
pixelflinger authored Jan 18, 2025
1 parent 1747ae8 commit bef849b
Show file tree
Hide file tree
Showing 169 changed files with 1,982 additions and 1,910 deletions.
2 changes: 1 addition & 1 deletion filament/include/filament/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ struct UTILS_PUBLIC Aabb {
* Returns the 8 corner vertices of the AABB.
*/
Corners getCorners() const {
return Aabb::Corners{ .vertices = {
return Corners{ .vertices = {
{ min.x, min.y, min.z },
{ max.x, min.y, min.z },
{ min.x, max.y, min.z },
Expand Down
4 changes: 2 additions & 2 deletions filament/include/filament/BufferObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class UTILS_PUBLIC BufferObject : public FilamentAPI {

/**
* The binding type for this buffer object. (defaults to VERTEX)
* @param BindingType Distinguishes between SSBO, VBO, etc. For now this must be VERTEX.
* @param bindingType Distinguishes between SSBO, VBO, etc. For now this must be VERTEX.
* @return A reference to this Builder for chaining calls.
*/
Builder& bindingType(BindingType bindingType) noexcept;
Expand All @@ -91,7 +91,7 @@ class UTILS_PUBLIC BufferObject : public FilamentAPI {
* @param len Length of name, should be less than or equal to 128
* @return This Builder, for chaining calls.
*/
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;

/**
* Creates the BufferObject and returns a pointer to it. After creation, the buffer
Expand Down
6 changes: 3 additions & 3 deletions filament/include/filament/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,14 @@ class UTILS_PUBLIC Camera : public FilamentAPI {
* engine.getTransformManager().getInstance(camera->getEntity()), model);
* ~~~~~~~~~~~
*
* @param model The camera position and orientation provided as a rigid transform matrix.
* @param modelMatrix The camera position and orientation provided as a rigid transform matrix.
*
* @note The Camera "looks" towards its -z axis
*
* @warning \p model must be a rigid transform
*/
void setModelMatrix(const math::mat4& model) noexcept;
void setModelMatrix(const math::mat4f& model) noexcept; //!< @overload
void setModelMatrix(const math::mat4& modelMatrix) noexcept;
void setModelMatrix(const math::mat4f& modelMatrix) noexcept; //!< @overload

/** Set the position of an eye relative to this Camera (head).
*
Expand Down
6 changes: 3 additions & 3 deletions filament/include/filament/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,19 @@ inline sRGBColorA Color::toSRGB<ACCURATE>(LinearColorA const& color) {
}

inline LinearColor Color::toLinear(RgbType type, math::float3 color) {
return (type == RgbType::LINEAR) ? color : Color::toLinear<ACCURATE>(color);
return (type == RgbType::LINEAR) ? color : toLinear<ACCURATE>(color);
}

// converts an RGBA color to linear space
// the conversion depends on the specified type
inline LinearColorA Color::toLinear(RgbaType type, math::float4 color) {
switch (type) {
case RgbaType::sRGB:
return Color::toLinear<ACCURATE>(color) * math::float4{color.a, color.a, color.a, 1.0f};
return toLinear<ACCURATE>(color) * math::float4{color.a, color.a, color.a, 1.0f};
case RgbaType::LINEAR:
return color * math::float4{color.a, color.a, color.a, 1.0f};
case RgbaType::PREMULTIPLIED_sRGB:
return Color::toLinear<ACCURATE>(color);
return toLinear<ACCURATE>(color);
case RgbaType::PREMULTIPLIED_LINEAR:
return color;
}
Expand Down
4 changes: 2 additions & 2 deletions filament/include/filament/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ class UTILS_PUBLIC Engine {
Platform* UTILS_NULLABLE platform = nullptr,
void* UTILS_NULLABLE sharedContext = nullptr,
const Config* UTILS_NULLABLE config = nullptr) {
return Engine::Builder()
return Builder()
.backend(backend)
.platform(platform)
.sharedContext(sharedContext)
Expand All @@ -557,7 +557,7 @@ class UTILS_PUBLIC Engine {
Platform* UTILS_NULLABLE platform = nullptr,
void* UTILS_NULLABLE sharedContext = nullptr,
const Config* UTILS_NULLABLE config = nullptr) {
Engine::Builder()
Builder()
.backend(backend)
.platform(platform)
.sharedContext(sharedContext)
Expand Down
2 changes: 1 addition & 1 deletion filament/include/filament/IndexBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class UTILS_PUBLIC IndexBuffer : public FilamentAPI {
* @param len Length of name, should be less than or equal to 128
* @return This Builder, for chaining calls.
*/
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;

/**
* Creates the IndexBuffer object and returns a pointer to it. After creation, the index
Expand Down
2 changes: 1 addition & 1 deletion filament/include/filament/InstanceBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class UTILS_PUBLIC InstanceBuffer : public FilamentAPI {
* @param len Length of name, should be less than or equal to 128
* @return This Builder, for chaining calls.
*/
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;

/**
* Creates the InstanceBuffer object and returns a pointer to it.
Expand Down
10 changes: 5 additions & 5 deletions filament/include/filament/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ class UTILS_PUBLIC Material : public FilamentAPI {
Builder& package(const void* UTILS_NONNULL payload, size_t size);

template<typename T>
using is_supported_constant_parameter_t = typename std::enable_if<
std::is_same<int32_t, T>::value ||
std::is_same<float, T>::value ||
std::is_same<bool, T>::value>::type;
using is_supported_constant_parameter_t = std::enable_if_t<
std::is_same_v<int32_t, T> ||
std::is_same_v<float, T> ||
std::is_same_v<bool, T>>;

/**
* Specialize a constant parameter specified in the material definition with a concrete
Expand Down Expand Up @@ -177,7 +177,7 @@ class UTILS_PUBLIC Material : public FilamentAPI {
* memory or other resources.
* @exception utils::PreConditionPanic if a parameter to a builder function was invalid.
*/
Material* UTILS_NULLABLE build(Engine& engine);
Material* UTILS_NULLABLE build(Engine& engine) const;
private:
friend class FMaterial;
};
Expand Down
82 changes: 41 additions & 41 deletions filament/include/filament/MaterialInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,35 @@ class UTILS_PUBLIC MaterialInstance : public FilamentAPI {
};

public:
using CullingMode = filament::backend::CullingMode;
using TransparencyMode = filament::TransparencyMode;
using DepthFunc = filament::backend::SamplerCompareFunc;
using StencilCompareFunc = filament::backend::SamplerCompareFunc;
using StencilOperation = filament::backend::StencilOperation;
using StencilFace = filament::backend::StencilFace;
using CullingMode = backend::CullingMode;
using TransparencyMode = TransparencyMode;
using DepthFunc = backend::SamplerCompareFunc;
using StencilCompareFunc = backend::SamplerCompareFunc;
using StencilOperation = backend::StencilOperation;
using StencilFace = backend::StencilFace;

template<typename T>
using is_supported_parameter_t = typename std::enable_if<
std::is_same<float, T>::value ||
std::is_same<int32_t, T>::value ||
std::is_same<uint32_t, T>::value ||
std::is_same<math::int2, T>::value ||
std::is_same<math::int3, T>::value ||
std::is_same<math::int4, T>::value ||
std::is_same<math::uint2, T>::value ||
std::is_same<math::uint3, T>::value ||
std::is_same<math::uint4, T>::value ||
std::is_same<math::float2, T>::value ||
std::is_same<math::float3, T>::value ||
std::is_same<math::float4, T>::value ||
std::is_same<math::mat4f, T>::value ||
using is_supported_parameter_t = std::enable_if_t<
std::is_same_v<float, T> ||
std::is_same_v<int32_t, T> ||
std::is_same_v<uint32_t, T> ||
std::is_same_v<math::int2, T> ||
std::is_same_v<math::int3, T> ||
std::is_same_v<math::int4, T> ||
std::is_same_v<math::uint2, T> ||
std::is_same_v<math::uint3, T> ||
std::is_same_v<math::uint4, T> ||
std::is_same_v<math::float2, T> ||
std::is_same_v<math::float3, T> ||
std::is_same_v<math::float4, T> ||
std::is_same_v<math::mat4f, T> ||
// these types are slower as they need a layout conversion
std::is_same<bool, T>::value ||
std::is_same<math::bool2, T>::value ||
std::is_same<math::bool3, T>::value ||
std::is_same<math::bool4, T>::value ||
std::is_same<math::mat3f, T>::value
>::type;
std::is_same_v<bool, T> ||
std::is_same_v<math::bool2, T> ||
std::is_same_v<math::bool3, T> ||
std::is_same_v<math::bool4, T> ||
std::is_same_v<math::mat3f, T>
>;

/**
* Creates a new MaterialInstance using another MaterialInstance as a template for initialization.
Expand Down Expand Up @@ -121,13 +121,13 @@ class UTILS_PUBLIC MaterialInstance : public FilamentAPI {

/** inline helper to provide the name as a null-terminated string literal */
template<typename T, typename = is_supported_parameter_t<T>>
inline void setParameter(StringLiteral name, T const& value) {
void setParameter(StringLiteral name, T const& value) {
setParameter<T>(name.data, name.size, value);
}

/** inline helper to provide the name as a null-terminated C string */
template<typename T, typename = is_supported_parameter_t<T>>
inline void setParameter(const char* UTILS_NONNULL name, T const& value) {
void setParameter(const char* UTILS_NONNULL name, T const& value) {
setParameter<T>(name, strlen(name), value);
}

Expand All @@ -148,14 +148,14 @@ class UTILS_PUBLIC MaterialInstance : public FilamentAPI {

/** inline helper to provide the name as a null-terminated string literal */
template<typename T, typename = is_supported_parameter_t<T>>
inline void setParameter(StringLiteral name, const T* UTILS_NONNULL values, size_t count) {
void setParameter(StringLiteral name, const T* UTILS_NONNULL values, size_t count) {
setParameter<T>(name.data, name.size, values, count);
}

/** inline helper to provide the name as a null-terminated C string */
template<typename T, typename = is_supported_parameter_t<T>>
inline void setParameter(const char* UTILS_NONNULL name,
const T* UTILS_NONNULL values, size_t count) {
void setParameter(const char* UTILS_NONNULL name,
const T* UTILS_NONNULL values, size_t count) {
setParameter<T>(name, strlen(name), values, count);
}

Expand All @@ -176,14 +176,14 @@ class UTILS_PUBLIC MaterialInstance : public FilamentAPI {
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler);

/** inline helper to provide the name as a null-terminated string literal */
inline void setParameter(StringLiteral name,
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) {
void setParameter(StringLiteral name,
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) {
setParameter(name.data, name.size, texture, sampler);
}

/** inline helper to provide the name as a null-terminated C string */
inline void setParameter(const char* UTILS_NONNULL name,
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) {
void setParameter(const char* UTILS_NONNULL name,
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) {
setParameter(name, strlen(name), texture, sampler);
}

Expand All @@ -202,12 +202,12 @@ class UTILS_PUBLIC MaterialInstance : public FilamentAPI {
RgbType type, math::float3 color);

/** inline helper to provide the name as a null-terminated string literal */
inline void setParameter(StringLiteral name, RgbType type, math::float3 color) {
void setParameter(StringLiteral name, RgbType type, math::float3 color) {
setParameter(name.data, name.size, type, color);
}

/** inline helper to provide the name as a null-terminated C string */
inline void setParameter(const char* UTILS_NONNULL name, RgbType type, math::float3 color) {
void setParameter(const char* UTILS_NONNULL name, RgbType type, math::float3 color) {
setParameter(name, strlen(name), type, color);
}

Expand All @@ -226,12 +226,12 @@ class UTILS_PUBLIC MaterialInstance : public FilamentAPI {
RgbaType type, math::float4 color);

/** inline helper to provide the name as a null-terminated string literal */
inline void setParameter(StringLiteral name, RgbaType type, math::float4 color) {
void setParameter(StringLiteral name, RgbaType type, math::float4 color) {
setParameter(name.data, name.size, type, color);
}

/** inline helper to provide the name as a null-terminated C string */
inline void setParameter(const char* UTILS_NONNULL name, RgbaType type, math::float4 color) {
void setParameter(const char* UTILS_NONNULL name, RgbaType type, math::float4 color) {
setParameter(name, strlen(name), type, color);
}

Expand All @@ -251,13 +251,13 @@ class UTILS_PUBLIC MaterialInstance : public FilamentAPI {

/** inline helper to provide the name as a null-terminated C string */
template<typename T, typename = is_supported_parameter_t<T>>
inline T getParameter(StringLiteral name) const {
T getParameter(StringLiteral name) const {
return getParameter<T>(name.data, name.size);
}

/** inline helper to provide the name as a null-terminated C string */
template<typename T, typename = is_supported_parameter_t<T>>
inline T getParameter(const char* UTILS_NONNULL name) const {
T getParameter(const char* UTILS_NONNULL name) const {
return getParameter<T>(name, strlen(name));
}

Expand Down
2 changes: 1 addition & 1 deletion filament/include/filament/MorphTargetBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class UTILS_PUBLIC MorphTargetBuffer : public FilamentAPI {
* @param len Length of name, should be less than or equal to 128
* @return This Builder, for chaining calls.
*/
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;

/**
* Creates the MorphTargetBuffer object and returns a pointer to it.
Expand Down
26 changes: 13 additions & 13 deletions filament/include/filament/RenderableManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class UTILS_PUBLIC RenderableManager : public FilamentAPI {
* the renderable are immutable.
* STATIC geometry has the same restrictions as STATIC_BOUNDS, but in addition disallows
* skinning, morphing and changing the VertexBuffer or IndexBuffer in any way.
* @param enable whether this renderable has static bounds. false by default.
* @param type type of geometry.
*/
Builder& geometryType(GeometryType type) noexcept;

Expand Down Expand Up @@ -454,7 +454,7 @@ class UTILS_PUBLIC RenderableManager : public FilamentAPI {
*
* @param primitiveIndex zero-based index of the primitive, must be less than the primitive
* count passed to Builder constructor
* @param indicesAndWeightsVectors pairs of bone index and bone weight for all vertices of
* @param indicesAndWeightsVector pairs of bone index and bone weight for all vertices of
* the primitive sequentially
*
* @return Builder reference for chaining calls.
Expand Down Expand Up @@ -501,7 +501,7 @@ class UTILS_PUBLIC RenderableManager : public FilamentAPI {
* @param primitiveIndex zero-based index of the primitive, must be less than the count passed to Builder constructor
* @param offset specifies where in the morph target buffer to start reading (expressed as a number of vertices)
*/
RenderableManager::Builder& morphing(uint8_t level,
Builder& morphing(uint8_t level,
size_t primitiveIndex, size_t offset) noexcept;


Expand Down Expand Up @@ -852,20 +852,20 @@ class UTILS_PUBLIC RenderableManager : public FilamentAPI {
/*! \cond PRIVATE */
template<typename T>
struct is_supported_vector_type {
using type = typename std::enable_if<
std::is_same<math::float4, T>::value ||
std::is_same<math::half4, T>::value ||
std::is_same<math::float3, T>::value ||
std::is_same<math::half3, T>::value
>::type;
using type = std::enable_if_t<
std::is_same_v<math::float4, T> ||
std::is_same_v<math::half4, T> ||
std::is_same_v<math::float3, T> ||
std::is_same_v<math::half3, T>
>;
};

template<typename T>
struct is_supported_index_type {
using type = typename std::enable_if<
std::is_same<uint16_t, T>::value ||
std::is_same<uint32_t, T>::value
>::type;
using type = std::enable_if_t<
std::is_same_v<uint16_t, T> ||
std::is_same_v<uint32_t, T>
>;
};
/*! \endcond */

Expand Down
2 changes: 1 addition & 1 deletion filament/include/filament/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class UTILS_PUBLIC Renderer : public FilamentAPI {
* @param historySize requested history size. The returned vector could be smaller.
* @return A vector of FrameInfo.
*/
utils::FixedCapacityVector<Renderer::FrameInfo> getFrameInfoHistory(
utils::FixedCapacityVector<FrameInfo> getFrameInfoHistory(
size_t historySize = 1) const noexcept;

/**
Expand Down
2 changes: 1 addition & 1 deletion filament/include/filament/SkinningBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class UTILS_PUBLIC SkinningBuffer : public FilamentAPI {
* @param len Length of name, should be less than or equal to 128
* @return This Builder, for chaining calls.
*/
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;

/**
* Creates the SkinningBuffer object and returns a pointer to it.
Expand Down
2 changes: 1 addition & 1 deletion filament/include/filament/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class UTILS_PUBLIC Stream : public FilamentAPI {
* @param len Length of name, should be less than or equal to 128
* @return This Builder, for chaining calls.
*/
// Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept; // inherited
Builder& name(const char* UTILS_NONNULL name, size_t len) noexcept;

/**
* Creates the Stream object and returns a pointer to it.
Expand Down
Loading

0 comments on commit bef849b

Please sign in to comment.