move Filament headers to own directory under iOS/macOS
This commit is contained in:
@@ -40,6 +40,10 @@
|
||||
|
||||
#endif /* __STDBOOL_H */
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#include "ResourceBuffer.hpp"
|
||||
|
||||
typedef int32_t EntityId;
|
||||
|
||||
@@ -2,19 +2,23 @@
|
||||
#define RESOURCE_BUFFER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "Log.hpp"
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
//
|
||||
// Since different platforms expose different interfaces for loading assets, we want a single interface to represent the binary data backing an asset (as well as an ID that can be passed back to the native platform to free the data and unload the asset).
|
||||
// Since different platforms expose different interfaces for loading assets, we want single interface to represent the binary data backing an asset (as well as an ID that can be passed back to the native platform to free the data and unload the asset).
|
||||
//
|
||||
struct ResourceBuffer {
|
||||
void * const data;
|
||||
const int size;
|
||||
const int id;
|
||||
const void* const data;
|
||||
const int32_t size;
|
||||
const int32_t id;
|
||||
|
||||
#if defined(__cplusplus) && !defined(__ANDROID__)
|
||||
ResourceBuffer(void* const data, const int32_t size, const int32_t id) : data(data), size(size), id(id) {};
|
||||
// These only need to be constructible from C++ on Linux & Windows.
|
||||
// On iOS, MacOS & Android, this is constructed on the Swift/Kotlin side.
|
||||
// These C++ constructors seem to interfere with that, so we omit them on those platforms.
|
||||
#if defined(__cplusplus) && !defined(__ANDROID__) && !defined(__APPLE__)
|
||||
ResourceBuffer(const void* const data, const int32_t size, const int32_t id) : data(data), size(size), id(id) {};
|
||||
ResourceBuffer(const ResourceBuffer& rb) : data(rb.data), size(rb.size), id(rb.id) { };
|
||||
ResourceBuffer(const ResourceBuffer&& rb) : data(rb.data), size(rb.size), id(rb.id) { };
|
||||
ResourceBuffer& operator=(const ResourceBuffer& other) = delete;
|
||||
@@ -48,12 +52,15 @@ extern "C" {
|
||||
}
|
||||
|
||||
void free(ResourceBuffer rb) const {
|
||||
Log("Freeing rb %d of size %d", rb.id, rb.size);
|
||||
if(mFreeFilamentResourceFromOwner) {
|
||||
mFreeFilamentResourceFromOwner(rb, mOwner);
|
||||
} else {
|
||||
mFreeFilamentResource(rb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
LoadFilamentResource mLoadFilamentResource;
|
||||
FreeFilamentResource mFreeFilamentResource;
|
||||
@@ -63,7 +70,6 @@ extern "C" {
|
||||
};
|
||||
typedef struct ResourceLoaderWrapper ResourceLoaderWrapper;
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PLATFORM_H
|
||||
#define TNT_FILAMENT_BACKEND_PLATFORM_H
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class Driver;
|
||||
|
||||
/**
|
||||
* Platform is an interface that abstracts how the backend (also referred to as Driver) is
|
||||
* created. The backend provides several common Platform concrete implementations, which are
|
||||
* selected automatically. It is possible however to provide a custom Platform when creating
|
||||
* the filament Engine.
|
||||
*/
|
||||
class UTILS_PUBLIC Platform {
|
||||
public:
|
||||
struct SwapChain {};
|
||||
struct Fence {};
|
||||
struct Stream {};
|
||||
|
||||
struct DriverConfig {
|
||||
/*
|
||||
* size of handle arena in bytes. Setting to 0 indicates default value is to be used.
|
||||
* Driver clamps to valid values.
|
||||
*/
|
||||
size_t handleArenaSize = 0;
|
||||
};
|
||||
|
||||
virtual ~Platform() noexcept;
|
||||
|
||||
/**
|
||||
* Queries the underlying OS version.
|
||||
* @return The OS version.
|
||||
*/
|
||||
virtual int getOSVersion() const noexcept = 0;
|
||||
|
||||
/**
|
||||
* Creates and initializes the low-level API (e.g. an OpenGL context or Vulkan instance),
|
||||
* then creates the concrete Driver.
|
||||
* The caller takes ownership of the returned Driver* and must destroy it with delete.
|
||||
*
|
||||
* @param sharedContext an optional shared context. This is not meaningful with all graphic
|
||||
* APIs and platforms.
|
||||
* For EGL platforms, this is an EGLContext.
|
||||
*
|
||||
* @param driverConfig specifies driver initialization parameters
|
||||
*
|
||||
* @return nullptr on failure, or a pointer to the newly created driver.
|
||||
*/
|
||||
virtual backend::Driver* createDriver(void* sharedContext,
|
||||
const DriverConfig& driverConfig) noexcept = 0;
|
||||
|
||||
/**
|
||||
* Processes the platform's event queue when called from its primary event-handling thread.
|
||||
*
|
||||
* Internally, Filament might need to call this when waiting on a fence. It is only implemented
|
||||
* on platforms that need it, such as macOS + OpenGL. Returns false if this is not the main
|
||||
* thread, or if the platform does not need to perform any special processing.
|
||||
*/
|
||||
virtual bool pumpEvents() noexcept;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_PLATFORM_H
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PLATFORMS_VULKANPLATFORM_H
|
||||
#define TNT_FILAMENT_BACKEND_PLATFORMS_VULKANPLATFORM_H
|
||||
|
||||
#include <backend/Platform.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
* A Platform interface that creates a Vulkan backend.
|
||||
*/
|
||||
|
||||
class VulkanPlatform : public Platform {
|
||||
public:
|
||||
struct SurfaceBundle {
|
||||
void* surface;
|
||||
// On certain platforms, the extent of the surface cannot be queried from Vulkan. In those
|
||||
// situations, we allow the frontend to pass in the extent to use in creating the swap
|
||||
// chains. Platform implementation should set extent to 0 if they do not expect to set the
|
||||
// swap chain extent.
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
};
|
||||
|
||||
// Given a Vulkan instance and native window handle, creates the platform-specific surface.
|
||||
virtual SurfaceBundle createVkSurfaceKHR(void* nativeWindow, void* instance,
|
||||
uint64_t flags) noexcept = 0;
|
||||
|
||||
~VulkanPlatform() override;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
|
||||
#endif //TNT_FILAMENT_BACKEND_PLATFORMS_VULKANPLATFORM_H
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
virtual void post(void* user, Callback callback) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~CallbackHandler();
|
||||
virtual ~CallbackHandler() = default;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
@@ -106,7 +106,8 @@ static constexpr size_t CONFIG_SAMPLER_BINDING_COUNT = 4; // This is guarantee
|
||||
* Defines the backend's feature levels.
|
||||
*/
|
||||
enum class FeatureLevel : uint8_t {
|
||||
FEATURE_LEVEL_1 = 1, //!< OpenGL ES 3.0 features (default)
|
||||
FEATURE_LEVEL_0 = 0, //!< OpenGL ES 2.0 features
|
||||
FEATURE_LEVEL_1, //!< OpenGL ES 3.0 features (default)
|
||||
FEATURE_LEVEL_2, //!< OpenGL ES 3.1 features + 16 textures units + cubemap arrays
|
||||
FEATURE_LEVEL_3 //!< OpenGL ES 3.1 features + 31 textures units + cubemap arrays
|
||||
};
|
||||
@@ -295,6 +296,14 @@ enum class Precision : uint8_t {
|
||||
DEFAULT
|
||||
};
|
||||
|
||||
/**
|
||||
* Shader compiler priority queue
|
||||
*/
|
||||
enum class CompilerPriorityQueue : uint8_t {
|
||||
HIGH,
|
||||
LOW
|
||||
};
|
||||
|
||||
//! Texture sampler type
|
||||
enum class SamplerType : uint8_t {
|
||||
SAMPLER_2D, //!< 2D texture
|
||||
@@ -787,32 +796,54 @@ enum class SamplerCompareFunc : uint8_t {
|
||||
|
||||
//! Sampler parameters
|
||||
struct SamplerParams { // NOLINT
|
||||
union {
|
||||
struct {
|
||||
SamplerMagFilter filterMag : 1; //!< magnification filter (NEAREST)
|
||||
SamplerMinFilter filterMin : 3; //!< minification filter (NEAREST)
|
||||
SamplerWrapMode wrapS : 2; //!< s-coordinate wrap mode (CLAMP_TO_EDGE)
|
||||
SamplerWrapMode wrapT : 2; //!< t-coordinate wrap mode (CLAMP_TO_EDGE)
|
||||
SamplerMagFilter filterMag : 1; //!< magnification filter (NEAREST)
|
||||
SamplerMinFilter filterMin : 3; //!< minification filter (NEAREST)
|
||||
SamplerWrapMode wrapS : 2; //!< s-coordinate wrap mode (CLAMP_TO_EDGE)
|
||||
SamplerWrapMode wrapT : 2; //!< t-coordinate wrap mode (CLAMP_TO_EDGE)
|
||||
|
||||
SamplerWrapMode wrapR : 2; //!< r-coordinate wrap mode (CLAMP_TO_EDGE)
|
||||
uint8_t anisotropyLog2 : 3; //!< anisotropy level (0)
|
||||
SamplerCompareMode compareMode : 1; //!< sampler compare mode (NONE)
|
||||
uint8_t padding0 : 2; //!< reserved. must be 0.
|
||||
SamplerWrapMode wrapR : 2; //!< r-coordinate wrap mode (CLAMP_TO_EDGE)
|
||||
uint8_t anisotropyLog2 : 3; //!< anisotropy level (0)
|
||||
SamplerCompareMode compareMode : 1; //!< sampler compare mode (NONE)
|
||||
uint8_t padding0 : 2; //!< reserved. must be 0.
|
||||
|
||||
SamplerCompareFunc compareFunc : 3; //!< sampler comparison function (LE)
|
||||
uint8_t padding1 : 5; //!< reserved. must be 0.
|
||||
SamplerCompareFunc compareFunc : 3; //!< sampler comparison function (LE)
|
||||
uint8_t padding1 : 5; //!< reserved. must be 0.
|
||||
uint8_t padding2 : 8; //!< reserved. must be 0.
|
||||
|
||||
uint8_t padding2 : 8; //!< reserved. must be 0.
|
||||
};
|
||||
uint32_t u;
|
||||
struct Hasher {
|
||||
size_t operator()(SamplerParams p) const noexcept {
|
||||
// we don't use std::hash<> here, so we don't have to include <functional>
|
||||
return *reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&p));
|
||||
}
|
||||
};
|
||||
|
||||
struct EqualTo {
|
||||
bool operator()(SamplerParams lhs, SamplerParams rhs) const noexcept {
|
||||
auto* pLhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&lhs));
|
||||
auto* pRhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&rhs));
|
||||
return *pLhs == *pRhs;
|
||||
}
|
||||
};
|
||||
|
||||
struct LessThan {
|
||||
bool operator()(SamplerParams lhs, SamplerParams rhs) const noexcept {
|
||||
auto* pLhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&lhs));
|
||||
auto* pRhs = reinterpret_cast<uint32_t const*>(reinterpret_cast<char const*>(&rhs));
|
||||
return *pLhs == *pRhs;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
friend inline bool operator < (SamplerParams lhs, SamplerParams rhs) {
|
||||
return lhs.u < rhs.u;
|
||||
friend inline bool operator < (SamplerParams lhs, SamplerParams rhs) noexcept {
|
||||
return SamplerParams::LessThan{}(lhs, rhs);
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(SamplerParams) == 4);
|
||||
|
||||
static_assert(sizeof(SamplerParams) == sizeof(uint32_t), "SamplerParams must be 32 bits");
|
||||
// The limitation to 64-bits max comes from how we store a SamplerParams in our JNI code
|
||||
// see android/.../TextureSampler.cpp
|
||||
static_assert(sizeof(SamplerParams) <= sizeof(uint64_t),
|
||||
"SamplerParams must be no more than 64 bits");
|
||||
|
||||
//! blending equation function
|
||||
enum class BlendEquation : uint8_t {
|
||||
@@ -1117,8 +1148,6 @@ static_assert(sizeof(StencilState) == 12u,
|
||||
|
||||
using FrameScheduledCallback = void(*)(PresentCallable callable, void* user);
|
||||
|
||||
using FrameCompletedCallback = void(*)(void* user);
|
||||
|
||||
enum class Workaround : uint16_t {
|
||||
// The EASU pass must split because shader compiler flattens early-exit branch
|
||||
SPLIT_EASU,
|
||||
@@ -1129,7 +1158,14 @@ enum class Workaround : uint16_t {
|
||||
ADRENO_UNIFORM_ARRAY_CRASH,
|
||||
// Workaround a Metal pipeline compilation error with the message:
|
||||
// "Could not statically determine the target of a texture". See light_indirect.fs
|
||||
A8X_STATIC_TEXTURE_TARGET_ERROR
|
||||
A8X_STATIC_TEXTURE_TARGET_ERROR,
|
||||
// Adreno drivers sometimes aren't able to blit into a layer of a texture array.
|
||||
DISABLE_BLIT_INTO_TEXTURE_ARRAY,
|
||||
// Multiple workarounds needed for PowerVR GPUs
|
||||
POWER_VR_SHADER_WORKAROUNDS,
|
||||
// The driver has some threads pinned, and we can't easily know on which core, it can hurt
|
||||
// performance more if we end-up pinned on the same one.
|
||||
DISABLE_THREAD_AFFINITY
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
@@ -39,7 +39,6 @@ struct HwRenderTarget;
|
||||
struct HwSamplerGroup;
|
||||
struct HwStream;
|
||||
struct HwSwapChain;
|
||||
struct HwSync;
|
||||
struct HwTexture;
|
||||
struct HwTimerQuery;
|
||||
struct HwVertexBuffer;
|
||||
@@ -126,7 +125,6 @@ using RenderTargetHandle = Handle<HwRenderTarget>;
|
||||
using SamplerGroupHandle = Handle<HwSamplerGroup>;
|
||||
using StreamHandle = Handle<HwStream>;
|
||||
using SwapChainHandle = Handle<HwSwapChain>;
|
||||
using SyncHandle = Handle<HwSync>;
|
||||
using TextureHandle = Handle<HwTexture>;
|
||||
using TimerQueryHandle = Handle<HwTimerQuery>;
|
||||
using VertexBufferHandle = Handle<HwVertexBuffer>;
|
||||
168
ios/include/filament/backend/Platform.h
Normal file
168
ios/include/filament/backend/Platform.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PLATFORM_H
|
||||
#define TNT_FILAMENT_BACKEND_PLATFORM_H
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Invocable.h>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
class Driver;
|
||||
|
||||
/**
|
||||
* Platform is an interface that abstracts how the backend (also referred to as Driver) is
|
||||
* created. The backend provides several common Platform concrete implementations, which are
|
||||
* selected automatically. It is possible however to provide a custom Platform when creating
|
||||
* the filament Engine.
|
||||
*/
|
||||
class UTILS_PUBLIC Platform {
|
||||
public:
|
||||
struct SwapChain {};
|
||||
struct Fence {};
|
||||
struct Stream {};
|
||||
|
||||
struct DriverConfig {
|
||||
/*
|
||||
* size of handle arena in bytes. Setting to 0 indicates default value is to be used.
|
||||
* Driver clamps to valid values.
|
||||
*/
|
||||
size_t handleArenaSize = 0;
|
||||
};
|
||||
|
||||
Platform() noexcept;
|
||||
|
||||
virtual ~Platform() noexcept;
|
||||
|
||||
/**
|
||||
* Queries the underlying OS version.
|
||||
* @return The OS version.
|
||||
*/
|
||||
virtual int getOSVersion() const noexcept = 0;
|
||||
|
||||
/**
|
||||
* Creates and initializes the low-level API (e.g. an OpenGL context or Vulkan instance),
|
||||
* then creates the concrete Driver.
|
||||
* The caller takes ownership of the returned Driver* and must destroy it with delete.
|
||||
*
|
||||
* @param sharedContext an optional shared context. This is not meaningful with all graphic
|
||||
* APIs and platforms.
|
||||
* For EGL platforms, this is an EGLContext.
|
||||
*
|
||||
* @param driverConfig specifies driver initialization parameters
|
||||
*
|
||||
* @return nullptr on failure, or a pointer to the newly created driver.
|
||||
*/
|
||||
virtual backend::Driver* createDriver(void* sharedContext,
|
||||
const DriverConfig& driverConfig) noexcept = 0;
|
||||
|
||||
/**
|
||||
* Processes the platform's event queue when called from its primary event-handling thread.
|
||||
*
|
||||
* Internally, Filament might need to call this when waiting on a fence. It is only implemented
|
||||
* on platforms that need it, such as macOS + OpenGL. Returns false if this is not the main
|
||||
* thread, or if the platform does not need to perform any special processing.
|
||||
*/
|
||||
virtual bool pumpEvents() noexcept;
|
||||
|
||||
/**
|
||||
* InsertBlobFunc is an Invocable to an application-provided function that a
|
||||
* backend implementation may use to insert a key/value pair into the
|
||||
* cache.
|
||||
*/
|
||||
using InsertBlobFunc = utils::Invocable<
|
||||
void(const void* key, size_t keySize, const void* value, size_t valueSize)>;
|
||||
|
||||
/*
|
||||
* RetrieveBlobFunc is an Invocable to an application-provided function that a
|
||||
* backend implementation may use to retrieve a cached value from the
|
||||
* cache.
|
||||
*/
|
||||
using RetrieveBlobFunc = utils::Invocable<
|
||||
size_t(const void* key, size_t keySize, void* value, size_t valueSize)>;
|
||||
|
||||
/**
|
||||
* Sets the callback functions that the backend can use to interact with caching functionality
|
||||
* provided by the application.
|
||||
*
|
||||
* Cache functions may only be specified once during the lifetime of a
|
||||
* Platform. The <insert> and <retrieve> Invocables may be called at any time and
|
||||
* from any thread from the time at which setBlobFunc is called until the time that Platform
|
||||
* is destroyed. Concurrent calls to these functions from different threads is also allowed.
|
||||
*
|
||||
* @param insertBlob an Invocable that inserts a new value into the cache and associates
|
||||
* it with the given key
|
||||
* @param retrieveBlob an Invocable that retrieves from the cache the value associated with a
|
||||
* given key
|
||||
*/
|
||||
void setBlobFunc(InsertBlobFunc&& insertBlob, RetrieveBlobFunc&& retrieveBlob) noexcept;
|
||||
|
||||
/**
|
||||
* @return true if setBlobFunc was called.
|
||||
*/
|
||||
bool hasBlobFunc() const noexcept;
|
||||
|
||||
/**
|
||||
* To insert a new binary value into the cache and associate it with a given
|
||||
* key, the backend implementation can call the application-provided callback
|
||||
* function insertBlob.
|
||||
*
|
||||
* No guarantees are made as to whether a given key/value pair is present in
|
||||
* the cache after the set call. If a different value has been associated
|
||||
* with the given key in the past then it is undefined which value, if any, is
|
||||
* associated with the key after the set call. Note that while there are no
|
||||
* guarantees, the cache implementation should attempt to cache the most
|
||||
* recently set value for a given key.
|
||||
*
|
||||
* @param key pointer to the beginning of the key data that is to be inserted
|
||||
* @param keySize specifies the size in byte of the data pointed to by <key>
|
||||
* @param value pointer to the beginning of the value data that is to be inserted
|
||||
* @param valueSize specifies the size in byte of the data pointed to by <value>
|
||||
*/
|
||||
void insertBlob(const void* key, size_t keySize, const void* value, size_t valueSize);
|
||||
|
||||
/**
|
||||
* To retrieve the binary value associated with a given key from the cache, a
|
||||
* the backend implementation can call the application-provided callback
|
||||
* function retrieveBlob.
|
||||
*
|
||||
* If the cache contains a value for the given key and its size in bytes is
|
||||
* less than or equal to <valueSize> then the value is written to the memory
|
||||
* pointed to by <value>. Otherwise nothing is written to the memory pointed
|
||||
* to by <value>.
|
||||
*
|
||||
* @param key pointer to the beginning of the key
|
||||
* @param keySize specifies the size in bytes of the binary key pointed to by <key>
|
||||
* @param value pointer to a buffer to receive the cached binary data, if it exists
|
||||
* @param valueSize specifies the size in bytes of the memory pointed to by <value>
|
||||
* @return If the cache contains a value associated with the given key then the
|
||||
* size of that binary value in bytes is returned. Otherwise 0 is returned.
|
||||
*/
|
||||
size_t retrieveBlob(const void* key, size_t keySize, void* value, size_t valueSize);
|
||||
|
||||
private:
|
||||
InsertBlobFunc mInsertBlob;
|
||||
RetrieveBlobFunc mRetrieveBlob;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif // TNT_FILAMENT_BACKEND_PLATFORM_H
|
||||
@@ -48,7 +48,15 @@ public:
|
||||
ShaderStageFlags stageFlags = ShaderStageFlags::ALL_SHADER_STAGE_FLAGS;
|
||||
};
|
||||
|
||||
struct Uniform {
|
||||
utils::CString name; // full qualified name of the uniform field
|
||||
uint16_t offset; // offset in 'uint32_t' into the uniform buffer
|
||||
uint8_t size; // >1 for arrays
|
||||
UniformType type; // uniform type
|
||||
};
|
||||
|
||||
using UniformBlockInfo = std::array<utils::CString, UNIFORM_BINDING_COUNT>;
|
||||
using UniformInfo = utils::FixedCapacityVector<Uniform>;
|
||||
using SamplerGroupInfo = std::array<SamplerGroupData, SAMPLER_BINDING_COUNT>;
|
||||
using ShaderBlob = utils::FixedCapacityVector<uint8_t>;
|
||||
using ShaderSource = std::array<ShaderBlob, SHADER_TYPE_COUNT>;
|
||||
@@ -59,10 +67,12 @@ public:
|
||||
Program& operator=(const Program& rhs) = delete;
|
||||
|
||||
Program(Program&& rhs) noexcept;
|
||||
Program& operator=(Program&& rhs) noexcept;
|
||||
Program& operator=(Program&& rhs) noexcept = delete;
|
||||
|
||||
~Program() noexcept;
|
||||
|
||||
Program& priorityQueue(CompilerPriorityQueue priorityQueue) noexcept;
|
||||
|
||||
// sets the material name and variant for diagnostic purposes only
|
||||
Program& diagnostics(utils::CString const& name,
|
||||
utils::Invocable<utils::io::ostream&(utils::io::ostream& out)>&& logger);
|
||||
@@ -78,6 +88,14 @@ public:
|
||||
Program& uniformBlockBindings(
|
||||
utils::FixedCapacityVector<std::pair<utils::CString, uint8_t>> const& uniformBlockBindings) noexcept;
|
||||
|
||||
// Note: This is only needed for GLES2.0, this is used to emulate UBO. This function tells
|
||||
// the program everything it needs to know about the uniforms at a given binding
|
||||
Program& uniforms(uint32_t index, UniformInfo const& uniforms) noexcept;
|
||||
|
||||
// Note: This is only needed for GLES2.0.
|
||||
Program& attributes(
|
||||
utils::FixedCapacityVector<std::pair<utils::CString, uint8_t>> attributes) noexcept;
|
||||
|
||||
// sets the 'bindingPoint' sampler group descriptor for this program.
|
||||
// 'samplers' can be destroyed after this call.
|
||||
// This effectively associates a set of (BindingPoints, index) to a texture unit in the shader.
|
||||
@@ -86,13 +104,15 @@ public:
|
||||
Sampler const* samplers, size_t count) noexcept;
|
||||
|
||||
struct SpecializationConstant {
|
||||
using Type = std::variant<int32_t, float, bool>;
|
||||
uint32_t id; // id set in glsl
|
||||
std::variant<int32_t, float, bool> value; // value and type
|
||||
Type value; // value and type
|
||||
};
|
||||
|
||||
Program& specializationConstants(
|
||||
utils::FixedCapacityVector<SpecializationConstant> specConstants) noexcept;
|
||||
|
||||
Program& cacheId(uint64_t cacheId) noexcept;
|
||||
|
||||
ShaderSource const& getShadersSource() const noexcept { return mShadersSource; }
|
||||
ShaderSource& getShadersSource() noexcept { return mShadersSource; }
|
||||
@@ -103,6 +123,12 @@ public:
|
||||
SamplerGroupInfo const& getSamplerGroupInfo() const { return mSamplerGroups; }
|
||||
SamplerGroupInfo& getSamplerGroupInfo() { return mSamplerGroups; }
|
||||
|
||||
auto const& getBindingUniformInfo() const { return mBindingUniformInfo; }
|
||||
auto& getBindingUniformInfo() { return mBindingUniformInfo; }
|
||||
|
||||
auto const& getAttributes() const { return mAttributes; }
|
||||
auto& getAttributes() { return mAttributes; }
|
||||
|
||||
utils::CString const& getName() const noexcept { return mName; }
|
||||
utils::CString& getName() noexcept { return mName; }
|
||||
|
||||
@@ -113,6 +139,10 @@ public:
|
||||
return mSpecializationConstants;
|
||||
}
|
||||
|
||||
uint64_t getCacheId() const noexcept { return mCacheId; }
|
||||
|
||||
CompilerPriorityQueue getPriorityQueue() const noexcept { return mPriorityQueue; }
|
||||
|
||||
private:
|
||||
friend utils::io::ostream& operator<<(utils::io::ostream& out, const Program& builder);
|
||||
|
||||
@@ -120,8 +150,12 @@ private:
|
||||
SamplerGroupInfo mSamplerGroups = {};
|
||||
ShaderSource mShadersSource;
|
||||
utils::CString mName;
|
||||
uint64_t mCacheId{};
|
||||
utils::Invocable<utils::io::ostream&(utils::io::ostream& out)> mLogger;
|
||||
utils::FixedCapacityVector<SpecializationConstant> mSpecializationConstants;
|
||||
utils::FixedCapacityVector<std::pair<utils::CString, uint8_t>> mAttributes;
|
||||
std::array<UniformInfo, Program::UNIFORM_BINDING_COUNT> mBindingUniformInfo;
|
||||
CompilerPriorityQueue mPriorityQueue = CompilerPriorityQueue::HIGH;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
@@ -95,6 +95,19 @@ public:
|
||||
*/
|
||||
virtual void destroySwapChain(SwapChain* swapChain) noexcept = 0;
|
||||
|
||||
/**
|
||||
* Returns the set of buffers that must be preserved up to the call to commit().
|
||||
* The default value is TargetBufferFlags::NONE.
|
||||
* The color buffer is always preserved, however ancillary buffers, such as the depth buffer
|
||||
* are generally discarded. The preserve flags can be used to make sure those ancillary
|
||||
* buffers are preserved until the call to commit.
|
||||
*
|
||||
* @param swapChain
|
||||
* @return buffer that must be preserved
|
||||
* @see commit()
|
||||
*/
|
||||
virtual TargetBufferFlags getPreservedFlags(SwapChain* swapChain) noexcept;
|
||||
|
||||
/**
|
||||
* Called by the driver to establish the default FBO. The default implementation returns 0.
|
||||
* @return a GLuint casted to a uint32_t that is an OpenGL framebuffer object.
|
||||
@@ -254,6 +267,33 @@ public:
|
||||
* @return Transformed image.
|
||||
*/
|
||||
virtual AcquiredImage transformAcquiredImage(AcquiredImage source) noexcept;
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns true if additional OpenGL contexts can be created. Default: false.
|
||||
* @return true if additional OpenGL contexts can be created.
|
||||
* @see createContext
|
||||
*/
|
||||
virtual bool isExtraContextSupported() const noexcept;
|
||||
|
||||
/**
|
||||
* Creates an OpenGL context with the same configuration than the main context and makes it
|
||||
* current to the current thread. Must not be called from the main driver thread.
|
||||
* createContext() is only supported if isExtraContextSupported() returns true.
|
||||
* These additional contexts will be automatically terminated in terminate.
|
||||
*
|
||||
* @param shared whether the new context is shared with the main context.
|
||||
* @see isExtraContextSupported()
|
||||
* @see terminate()
|
||||
*/
|
||||
virtual void createContext(bool shared);
|
||||
|
||||
/**
|
||||
* Detach and destroy the current context if any and releases all resources associated to
|
||||
* this thread.
|
||||
*/
|
||||
virtual void releaseContext() noexcept;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
@@ -50,6 +50,9 @@ protected:
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// OpenGLPlatform Interface
|
||||
|
||||
bool isExtraContextSupported() const noexcept override;
|
||||
void createContext(bool shared) override;
|
||||
|
||||
void terminate() noexcept override;
|
||||
|
||||
SwapChain* createSwapChain(void* nativewindow, uint64_t flags) noexcept override;
|
||||
@@ -47,6 +47,9 @@ public:
|
||||
|
||||
uint32_t createDefaultRenderTarget() noexcept override;
|
||||
|
||||
bool isExtraContextSupported() const noexcept override;
|
||||
void createContext(bool shared) override;
|
||||
|
||||
SwapChain* createSwapChain(void* nativewindow, uint64_t flags) noexcept override;
|
||||
SwapChain* createSwapChain(uint32_t width, uint32_t height, uint64_t flags) noexcept override;
|
||||
void destroySwapChain(SwapChain* swapChain) noexcept override;
|
||||
@@ -26,6 +26,9 @@
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
@@ -35,8 +38,32 @@ class PlatformEGL : public OpenGLPlatform {
|
||||
public:
|
||||
|
||||
PlatformEGL() noexcept;
|
||||
bool isExtraContextSupported() const noexcept override;
|
||||
void createContext(bool shared) override;
|
||||
void releaseContext() noexcept override;
|
||||
|
||||
protected:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Helper for EGL configs and attributes parameters
|
||||
|
||||
class Config {
|
||||
public:
|
||||
Config();
|
||||
Config(std::initializer_list<std::pair<EGLint, EGLint>> list);
|
||||
EGLint& operator[](EGLint name);
|
||||
EGLint operator[](EGLint name) const;
|
||||
void erase(EGLint name) noexcept;
|
||||
EGLint const* data() const noexcept {
|
||||
return reinterpret_cast<EGLint const*>(mConfig.data());
|
||||
}
|
||||
size_t size() const noexcept {
|
||||
return mConfig.size();
|
||||
}
|
||||
private:
|
||||
std::vector<std::pair<EGLint, EGLint>> mConfig = {{ EGL_NONE, EGL_NONE }};
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// Platform Interface
|
||||
|
||||
@@ -79,6 +106,8 @@ protected:
|
||||
* @param name a string giving some context on the error. Typically __func__.
|
||||
*/
|
||||
static void logEglError(const char* name) noexcept;
|
||||
static void logEglError(const char* name, EGLint error) noexcept;
|
||||
static const char* getEglErrorName(EGLint error) noexcept;
|
||||
|
||||
/**
|
||||
* Calls glGetError() to clear the current error flags. logs a warning to log.w if
|
||||
@@ -98,6 +127,8 @@ protected:
|
||||
EGLSurface mCurrentReadSurface = EGL_NO_SURFACE;
|
||||
EGLSurface mEGLDummySurface = EGL_NO_SURFACE;
|
||||
EGLConfig mEGLConfig = EGL_NO_CONFIG_KHR;
|
||||
Config mContextAttribs;
|
||||
std::vector<EGLContext> mAdditionalContexts;
|
||||
|
||||
// supported extensions detected at runtime
|
||||
struct {
|
||||
@@ -105,13 +136,17 @@ protected:
|
||||
bool OES_EGL_image_external_essl3 = false;
|
||||
} gl;
|
||||
struct {
|
||||
bool KHR_no_config_context = false;
|
||||
bool ANDROID_recordable = false;
|
||||
bool KHR_create_context = false;
|
||||
bool KHR_gl_colorspace = false;
|
||||
bool KHR_no_config_context = false;
|
||||
bool KHR_surfaceless_context = false;
|
||||
} egl;
|
||||
} ext;
|
||||
|
||||
private:
|
||||
void initializeGlExtensions() noexcept;
|
||||
|
||||
private:
|
||||
EGLConfig findSwapChainConfig(uint64_t flags) const;
|
||||
};
|
||||
|
||||
@@ -23,9 +23,10 @@
|
||||
#include "utils/unwindows.h"
|
||||
|
||||
#include <backend/platforms/OpenGLPlatform.h>
|
||||
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
/**
|
||||
@@ -46,6 +47,9 @@ protected:
|
||||
|
||||
void terminate() noexcept override;
|
||||
|
||||
bool isExtraContextSupported() const noexcept override;
|
||||
void createContext(bool shared) override;
|
||||
|
||||
SwapChain* createSwapChain(void* nativewindow, uint64_t flags) noexcept override;
|
||||
SwapChain* createSwapChain(uint32_t width, uint32_t height, uint64_t flags) noexcept override;
|
||||
void destroySwapChain(SwapChain* swapChain) noexcept override;
|
||||
@@ -57,6 +61,8 @@ protected:
|
||||
HWND mHWnd = NULL;
|
||||
HDC mWhdc = NULL;
|
||||
PIXELFORMATDESCRIPTOR mPfd = {};
|
||||
std::vector<HGLRC> mAdditionalContexts;
|
||||
std::vector<int> mAttribs;
|
||||
};
|
||||
|
||||
} // namespace filament::backend
|
||||
238
ios/include/filament/backend/platforms/VulkanPlatform.h
Normal file
238
ios/include/filament/backend/platforms/VulkanPlatform.h
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_BACKEND_PLATFORMS_VULKANPLATFORM_H
|
||||
#define TNT_FILAMENT_BACKEND_PLATFORMS_VULKANPLATFORM_H
|
||||
|
||||
#include <backend/Platform.h>
|
||||
|
||||
#include <bluevk/BlueVK.h>
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
#include <utils/PrivateImplementation.h>
|
||||
|
||||
#include <tuple>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace filament::backend {
|
||||
|
||||
using SwapChain = Platform::SwapChain;
|
||||
|
||||
/**
|
||||
* Private implementation details for the provided vulkan platform.
|
||||
*/
|
||||
struct VulkanPlatformPrivate;
|
||||
|
||||
/**
|
||||
* A Platform interface that creates a Vulkan backend.
|
||||
*/
|
||||
class VulkanPlatform : public Platform, utils::PrivateImplementation<VulkanPlatformPrivate> {
|
||||
public:
|
||||
|
||||
/**
|
||||
* A collection of handles to objects and metadata that comprises a Vulkan context. The client
|
||||
* can instantiate this struct and pass to Engine::Builder::sharedContext if they wishes to
|
||||
* share their vulkan context. This is specifically necessary if the client wishes to override
|
||||
* the swapchain API.
|
||||
*/
|
||||
struct VulkanSharedContext {
|
||||
VkInstance instance = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||
VkDevice logicalDevice = VK_NULL_HANDLE;
|
||||
uint32_t graphicsQueueFamilyIndex = 0xFFFFFFFF;
|
||||
// In the usual case, the client needs to allocate at least one more graphics queue
|
||||
// for Filament, and this index is the param to pass into vkGetDeviceQueue. In the case
|
||||
// where the gpu only has one graphics queue. Then the client needs to ensure that no
|
||||
// concurrent access can occur.
|
||||
uint32_t graphicsQueueIndex = 0xFFFFFFFF;
|
||||
};
|
||||
|
||||
/**
|
||||
* Shorthand for the pointer to the Platform SwapChain struct, we use it also as a handle (i.e.
|
||||
* identifier for the swapchain).
|
||||
*/
|
||||
using SwapChainPtr = Platform::SwapChain*;
|
||||
|
||||
/**
|
||||
* Collection of images, formats, and extent (width/height) that defines the swapchain.
|
||||
*/
|
||||
struct SwapChainBundle {
|
||||
utils::FixedCapacityVector<VkImage> colors;
|
||||
VkImage depth = VK_NULL_HANDLE;
|
||||
VkFormat colorFormat = VK_FORMAT_UNDEFINED;
|
||||
VkFormat depthFormat = VK_FORMAT_UNDEFINED;
|
||||
VkExtent2D extent = {0, 0};
|
||||
};
|
||||
|
||||
VulkanPlatform();
|
||||
|
||||
~VulkanPlatform() override;
|
||||
|
||||
Driver* createDriver(void* sharedContext,
|
||||
Platform::DriverConfig const& driverConfig) noexcept override;
|
||||
|
||||
int getOSVersion() const noexcept override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// ---------- Platform Customization options ----------
|
||||
/**
|
||||
* The client preference can be stored within the struct. We allow for two specification of
|
||||
* preference:
|
||||
* 1) A substring to match against `VkPhysicalDeviceProperties.deviceName`.
|
||||
* 2) Index of the device in the list as returned by vkEnumeratePhysicalDevices.
|
||||
*/
|
||||
struct GPUPreference {
|
||||
std::string deviceName;
|
||||
int8_t index = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Client can provide a preference over the GPU to use in the vulkan instance
|
||||
* @return `GPUPreference` struct that indicates the client's preference
|
||||
*/
|
||||
virtual GPUPreference getPreferredGPU() noexcept {
|
||||
return {};
|
||||
}
|
||||
// -------- End platform customization options --------
|
||||
// ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns whether the platform supports sRGB swapchain. This is true by default, and the client
|
||||
* needs to override this method to specify otherwise.
|
||||
* @return Whether the platform supports sRGB swapchain.
|
||||
*/
|
||||
virtual bool isSRGBSwapChainSupported() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the images handles and format of the memory backing the swapchain. This should be called
|
||||
* after createSwapChain() or after recreateIfResized().
|
||||
* @param swapchain The handle returned by createSwapChain()
|
||||
* @return An array of VkImages
|
||||
*/
|
||||
virtual SwapChainBundle getSwapChainBundle(SwapChainPtr handle);
|
||||
|
||||
/**
|
||||
* Acquire the next image for rendering. The `index` will be written with an non-negative
|
||||
* integer that the backend can use to index into the `SwapChainBundle.colors` array. The
|
||||
* corresponding VkImage will be used as the output color attachment. The client should signal
|
||||
* the `clientSignal` semaphore when the image is ready to be used by the backend.
|
||||
* @param handle The handle returned by createSwapChain()
|
||||
* @param clientSignal The semaphore that the client will signal to indicate that the backend
|
||||
* may render into the image.
|
||||
* @param index Pointer to memory that will be filled with the index that corresponding
|
||||
* to an image in the `SwapChainBundle.colors` array.
|
||||
* @return Result of acquire
|
||||
*/
|
||||
virtual VkResult acquire(SwapChainPtr handle, VkSemaphore clientSignal, uint32_t* index);
|
||||
|
||||
/**
|
||||
* Present the image corresponding to `index` to the display. The client should wait on
|
||||
* `finishedDrawing` before presenting.
|
||||
* @param handle The handle returned by createSwapChain()
|
||||
* @param index Index that corresponding to an image in the
|
||||
* `SwapChainBundle.colors` array.
|
||||
* @param finishedDrawing Backend passes in a semaphore that the client will signal to
|
||||
* indicate that the client may render into the image.
|
||||
* @return Result of present
|
||||
*/
|
||||
virtual VkResult present(SwapChainPtr handle, uint32_t index, VkSemaphore finishedDrawing);
|
||||
|
||||
/**
|
||||
* Check if the surface size has changed.
|
||||
* @param handle The handle returned by createSwapChain()
|
||||
* @return Whether the swapchain has been resized
|
||||
*/
|
||||
virtual bool hasResized(SwapChainPtr handle);
|
||||
|
||||
/**
|
||||
* Carry out a recreation of the swapchain.
|
||||
* @param handle The handle returned by createSwapChain()
|
||||
* @return Result of the recreation
|
||||
*/
|
||||
virtual VkResult recreate(SwapChainPtr handle);
|
||||
|
||||
/**
|
||||
* Create a swapchain given a platform window, or if given a null `nativeWindow`, then we
|
||||
* try to create a headless swapchain with the given `extent`.
|
||||
* @param flags Optional parameters passed to the client as defined in
|
||||
* Filament::SwapChain.h.
|
||||
* @param extent Optional width and height that indicates the size of the headless swapchain.
|
||||
* @return Result of the operation
|
||||
*/
|
||||
virtual SwapChainPtr createSwapChain(void* nativeWindow, uint64_t flags = 0,
|
||||
VkExtent2D extent = {0, 0});
|
||||
|
||||
/**
|
||||
* Destroy the swapchain.
|
||||
* @param handle The handle returned by createSwapChain()
|
||||
*/
|
||||
virtual void destroy(SwapChainPtr handle);
|
||||
|
||||
/**
|
||||
* Clean up any resources owned by the Platform. For example, if the Vulkan instance handle was
|
||||
* generated by the platform, we need to clean it up in this method.
|
||||
*/
|
||||
virtual void terminate();
|
||||
|
||||
/**
|
||||
* @return The instance (VkInstance) for the Vulkan backend.
|
||||
*/
|
||||
VkInstance getInstance() const noexcept;
|
||||
|
||||
/**
|
||||
* @return The logical device (VkDevice) that was selected as the backend device.
|
||||
*/
|
||||
VkDevice getDevice() const noexcept;
|
||||
|
||||
/**
|
||||
* @return The physical device (i.e gpu) that was selected as the backend physical device.
|
||||
*/
|
||||
VkPhysicalDevice getPhysicalDevice() const noexcept;
|
||||
|
||||
/**
|
||||
* @return The family index of the graphics queue selected for the Vulkan backend.
|
||||
*/
|
||||
uint32_t getGraphicsQueueFamilyIndex() const noexcept;
|
||||
|
||||
/**
|
||||
* @return The index of the graphics queue (if there are multiple graphics queues)
|
||||
* selected for the Vulkan backend.
|
||||
*/
|
||||
uint32_t getGraphicsQueueIndex() const noexcept;
|
||||
|
||||
/**
|
||||
* @return The queue that was selected for the Vulkan backend.
|
||||
*/
|
||||
VkQueue getGraphicsQueue() const noexcept;
|
||||
|
||||
private:
|
||||
// Platform dependent helper methods
|
||||
using ExtensionSet = std::unordered_set<std::string_view>;
|
||||
static ExtensionSet getRequiredInstanceExtensions();
|
||||
|
||||
using SurfaceBundle = std::tuple<VkSurfaceKHR, VkExtent2D>;
|
||||
static SurfaceBundle createVkSurfaceKHR(void* nativeWindow, VkInstance instance,
|
||||
uint64_t flags) noexcept;
|
||||
|
||||
friend struct VulkanPlatformPrivate;
|
||||
};
|
||||
|
||||
}// namespace filament::backend
|
||||
|
||||
#endif// TNT_FILAMENT_BACKEND_PLATFORMS_VULKANPLATFORM_H
|
||||
@@ -142,13 +142,6 @@ protected:
|
||||
TargetLanguage targetLanguage;
|
||||
};
|
||||
std::vector<CodeGenParams> mCodeGenPermutations;
|
||||
// For finding properties and running semantic analysis, we always use the same code gen
|
||||
// permutation. This is the first permutation generated with default arguments passed to matc.
|
||||
static constexpr const CodeGenParams mSemanticCodeGenParams = {
|
||||
.shaderModel = ShaderModel::MOBILE,
|
||||
.targetApi = TargetApi::OPENGL,
|
||||
.targetLanguage = TargetLanguage::SPIRV
|
||||
};
|
||||
|
||||
// Keeps track of how many times MaterialBuilder::init() has been called without a call to
|
||||
// MaterialBuilder::shutdown(). Internally, glslang does something similar. We keep track for
|
||||
@@ -238,12 +231,14 @@ public:
|
||||
using TransparencyMode = filament::TransparencyMode;
|
||||
using SpecularAmbientOcclusion = filament::SpecularAmbientOcclusion;
|
||||
|
||||
using AttributeType = filament::backend::UniformType;
|
||||
using UniformType = filament::backend::UniformType;
|
||||
using ConstantType = filament::backend::ConstantType;
|
||||
using SamplerType = filament::backend::SamplerType;
|
||||
using SubpassType = filament::backend::SubpassType;
|
||||
using SamplerFormat = filament::backend::SamplerFormat;
|
||||
using ParameterPrecision = filament::backend::Precision;
|
||||
using Precision = filament::backend::Precision;
|
||||
using CullingMode = filament::backend::CullingMode;
|
||||
using FeatureLevel = filament::backend::FeatureLevel;
|
||||
|
||||
@@ -272,6 +267,9 @@ public:
|
||||
};
|
||||
using PreprocessorDefineList = std::vector<PreprocessorDefine>;
|
||||
|
||||
|
||||
MaterialBuilder& noSamplerValidation(bool enabled) noexcept;
|
||||
|
||||
//! Set the name of this material.
|
||||
MaterialBuilder& name(const char* name) noexcept;
|
||||
|
||||
@@ -578,7 +576,7 @@ public:
|
||||
MaterialBuilder& shaderDefine(const char* name, const char* value) noexcept;
|
||||
|
||||
//! Add a new fragment shader output variable. Only valid for materials in the POST_PROCESS domain.
|
||||
MaterialBuilder& output(VariableQualifier qualifier, OutputTarget target,
|
||||
MaterialBuilder& output(VariableQualifier qualifier, OutputTarget target, Precision precision,
|
||||
OutputType type, const char* name, int location = -1) noexcept;
|
||||
|
||||
MaterialBuilder& enableFramebufferFetch() noexcept;
|
||||
@@ -652,13 +650,14 @@ public:
|
||||
struct Output {
|
||||
Output() noexcept = default;
|
||||
Output(const char* outputName, VariableQualifier qualifier, OutputTarget target,
|
||||
OutputType type, int location) noexcept
|
||||
: name(outputName), qualifier(qualifier), target(target), type(type),
|
||||
location(location) { }
|
||||
Precision precision, OutputType type, int location) noexcept
|
||||
: name(outputName), qualifier(qualifier), target(target), precision(precision),
|
||||
type(type), location(location) { }
|
||||
|
||||
utils::CString name;
|
||||
VariableQualifier qualifier;
|
||||
OutputTarget target;
|
||||
Precision precision;
|
||||
OutputType type;
|
||||
int location;
|
||||
};
|
||||
@@ -719,20 +718,44 @@ public:
|
||||
FeatureLevel getFeatureLevel() const noexcept { return mFeatureLevel; }
|
||||
/// @endcond
|
||||
|
||||
struct Attribute {
|
||||
std::string_view name;
|
||||
AttributeType type;
|
||||
MaterialBuilder::VertexAttribute location;
|
||||
std::string getAttributeName() const noexcept {
|
||||
return "mesh_" + std::string{ name };
|
||||
}
|
||||
std::string getDefineName() const noexcept {
|
||||
std::string uppercase{ name };
|
||||
transform(uppercase.cbegin(), uppercase.cend(), uppercase.begin(), ::toupper);
|
||||
return "HAS_ATTRIBUTE_" + uppercase;
|
||||
}
|
||||
};
|
||||
|
||||
using AttributeDatabase = std::array<Attribute, filament::backend::MAX_VERTEX_ATTRIBUTE_COUNT>;
|
||||
|
||||
static inline AttributeDatabase const& getAttributeDatabase() noexcept {
|
||||
return sAttributeDatabase;
|
||||
}
|
||||
|
||||
private:
|
||||
static const AttributeDatabase sAttributeDatabase;
|
||||
|
||||
void prepareToBuild(MaterialInfo& info) noexcept;
|
||||
|
||||
// Return true if the shader is syntactically and semantically valid.
|
||||
// This method finds all the properties defined in the fragment and
|
||||
// vertex shaders of the material.
|
||||
bool findAllProperties() noexcept;
|
||||
bool findAllProperties(CodeGenParams const& semanticCodeGenParams) noexcept;
|
||||
|
||||
// Multiple calls to findProperties accumulate the property sets across fragment
|
||||
// and vertex shaders in mProperties.
|
||||
bool findProperties(filament::backend::ShaderStage type,
|
||||
MaterialBuilder::PropertyList& p) noexcept;
|
||||
MaterialBuilder::PropertyList& allProperties,
|
||||
CodeGenParams const& semanticCodeGenParams) noexcept;
|
||||
|
||||
bool runSemanticAnalysis(MaterialInfo const& info) noexcept;
|
||||
bool runSemanticAnalysis(MaterialInfo const& info,
|
||||
CodeGenParams const& semanticCodeGenParams) noexcept;
|
||||
|
||||
bool checkLiteRequirements() noexcept;
|
||||
|
||||
@@ -851,6 +874,8 @@ private:
|
||||
PreprocessorDefineList mDefines;
|
||||
|
||||
filament::UserVariantFilterMask mVariantFilter = {};
|
||||
|
||||
bool mNoSamplerValidation = false;
|
||||
};
|
||||
|
||||
} // namespace filamat
|
||||
@@ -58,6 +58,10 @@ class Texture;
|
||||
class UTILS_PUBLIC IBLPrefilterContext {
|
||||
public:
|
||||
|
||||
enum class Kernel : uint8_t {
|
||||
D_GGX, // Trowbridge-reitz distribution
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an IBLPrefilter context.
|
||||
* @param engine filament engine to use
|
||||
@@ -109,7 +113,7 @@ public:
|
||||
* - Must be allocated with all mip levels.
|
||||
* - Must be SAMPLEABLE
|
||||
* @param outCubemap Output cubemap. If null the texture is automatically created
|
||||
* with default parameters (size of 256 with 5 levels).
|
||||
* with default parameters (size of 256 with 9 levels).
|
||||
* - Must be a cubemap
|
||||
* - Must have SAMPLEABLE and COLOR_ATTACHMENT usage bits
|
||||
* @return returns outCubemap
|
||||
@@ -123,6 +127,100 @@ public:
|
||||
filament::Material* mEquirectMaterial = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
* IrradianceFilter is a GPU based implementation of the diffuse probe pre-integration filter.
|
||||
* An instance of IrradianceFilter is needed per filter configuration. A filter configuration
|
||||
* contains the filter's kernel and sample count.
|
||||
*/
|
||||
class IrradianceFilter {
|
||||
public:
|
||||
using Kernel = Kernel;
|
||||
|
||||
/**
|
||||
* Filter configuration.
|
||||
*/
|
||||
struct Config {
|
||||
uint16_t sampleCount = 1024u; //!< filter sample count (max 2048)
|
||||
Kernel kernel = Kernel::D_GGX; //!< filter kernel
|
||||
};
|
||||
|
||||
/**
|
||||
* Filtering options for the current environment.
|
||||
*/
|
||||
struct Options {
|
||||
float hdrLinear = 1024.0f; //!< no HDR compression up to this value
|
||||
float hdrMax = 16384.0f; //!< HDR compression between hdrLinear and hdrMax
|
||||
float lodOffset = 2.0f; //!< Good values are 2.0 or 3.0. Higher values help with heavily HDR inputs.
|
||||
bool generateMipmap = true; //!< set to false if the input environment map already has mipmaps
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a IrradianceFilter processor.
|
||||
* @param context IBLPrefilterContext to use
|
||||
* @param config Configuration of the filter
|
||||
*/
|
||||
IrradianceFilter(IBLPrefilterContext& context, Config config);
|
||||
|
||||
/**
|
||||
* Creates a filter with the default configuration.
|
||||
* @param context IBLPrefilterContext to use
|
||||
*/
|
||||
explicit IrradianceFilter(IBLPrefilterContext& context);
|
||||
|
||||
/**
|
||||
* Destroys all GPU resources created during initialization.
|
||||
*/
|
||||
~IrradianceFilter() noexcept;
|
||||
|
||||
IrradianceFilter(IrradianceFilter const&) = delete;
|
||||
IrradianceFilter& operator=(IrradianceFilter const&) = delete;
|
||||
IrradianceFilter(IrradianceFilter&& rhs) noexcept;
|
||||
IrradianceFilter& operator=(IrradianceFilter&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Generates an irradiance cubemap. Mipmaps are not generated even if present.
|
||||
* @param options Options for this environment
|
||||
* @param environmentCubemap Environment cubemap (input). Can't be null.
|
||||
* This cubemap must be SAMPLEABLE and must have all its
|
||||
* levels allocated. If Options.generateMipmap is true,
|
||||
* the mipmap levels will be overwritten, otherwise
|
||||
* it is assumed that all levels are correctly initialized.
|
||||
* @param outIrradianceTexture Output irradiance texture or, if null, it is
|
||||
* automatically created with some default parameters.
|
||||
* outIrradianceTexture must be a cubemap, it must have
|
||||
* at least COLOR_ATTACHMENT and SAMPLEABLE usages.
|
||||
*
|
||||
* @return returns outIrradianceTexture
|
||||
*/
|
||||
filament::Texture* operator()(Options options,
|
||||
filament::Texture const* environmentCubemap,
|
||||
filament::Texture* outIrradianceTexture = nullptr);
|
||||
|
||||
/**
|
||||
* Generates a prefiltered cubemap.
|
||||
* @param environmentCubemap Environment cubemap (input). Can't be null.
|
||||
* This cubemap must be SAMPLEABLE and must have all its
|
||||
* levels allocated. If Options.generateMipmap is true,
|
||||
* the mipmap levels will be overwritten, otherwise
|
||||
* it is assumed that all levels are correctly initialized.
|
||||
* @param outIrradianceTexture Output irradiance texture or, if null, it is
|
||||
* automatically created with some default parameters.
|
||||
* outIrradianceTexture must be a cubemap, it must have
|
||||
* at least COLOR_ATTACHMENT and SAMPLEABLE usages.
|
||||
*
|
||||
* @return returns outReflectionsTexture
|
||||
*/
|
||||
filament::Texture* operator()(
|
||||
filament::Texture const* environmentCubemap,
|
||||
filament::Texture* outIrradianceTexture = nullptr);
|
||||
|
||||
private:
|
||||
filament::Texture* createIrradianceTexture();
|
||||
IBLPrefilterContext& mContext;
|
||||
filament::Material* mKernelMaterial = nullptr;
|
||||
filament::Texture* mKernelTexture = nullptr;
|
||||
uint32_t mSampleCount = 0u;
|
||||
};
|
||||
|
||||
/**
|
||||
* SpecularFilter is a GPU based implementation of the specular probe pre-integration filter.
|
||||
@@ -131,9 +229,7 @@ public:
|
||||
*/
|
||||
class SpecularFilter {
|
||||
public:
|
||||
enum class Kernel : uint8_t {
|
||||
D_GGX, // Trowbridge-reitz distribution
|
||||
};
|
||||
using Kernel = Kernel;
|
||||
|
||||
/**
|
||||
* Filter configuration.
|
||||
@@ -151,7 +247,7 @@ public:
|
||||
float hdrLinear = 1024.0f; //!< no HDR compression up to this value
|
||||
float hdrMax = 16384.0f; //!< HDR compression between hdrLinear and hdrMax
|
||||
float lodOffset = 1.0f; //!< Good values are 1.0 or 2.0. Higher values help with heavily HDR inputs.
|
||||
bool generateMipmap = true; //!< set to false if the environment map already has mipmaps
|
||||
bool generateMipmap = true; //!< set to false if the input environment map already has mipmaps
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -237,6 +333,7 @@ private:
|
||||
utils::Entity mCameraEntity{};
|
||||
filament::View* mView{};
|
||||
filament::Material* mIntegrationMaterial{};
|
||||
filament::Material* mIrradianceIntegrationMaterial{};
|
||||
};
|
||||
|
||||
#endif //TNT_IBL_PREFILTER_IBLPREFILTER_H
|
||||
@@ -34,10 +34,13 @@ class Entity;
|
||||
namespace filament {
|
||||
|
||||
/**
|
||||
* Camera represents the eye through which the scene is viewed.
|
||||
* Camera represents the eye(s) through which the scene is viewed.
|
||||
*
|
||||
* A Camera has a position and orientation and controls the projection and exposure parameters.
|
||||
*
|
||||
* For stereoscopic rendering, a Camera maintains two separate "eyes": Eye 0 and Eye 1. These are
|
||||
* arbitrary and don't necessarily need to correspond to "left" and "right".
|
||||
*
|
||||
* Creation and destruction
|
||||
* ========================
|
||||
*
|
||||
@@ -140,6 +143,18 @@ namespace filament {
|
||||
* intensity and the Camera exposure interact to produce the final scene's brightness.
|
||||
*
|
||||
*
|
||||
* Stereoscopic rendering
|
||||
* ======================
|
||||
*
|
||||
* The Camera's transform (as set by setModelMatrix or via TransformManager) defines a "head" space,
|
||||
* which typically corresponds to the location of the viewer's head. Each eye's transform is set
|
||||
* relative to this head space by setEyeModelMatrix.
|
||||
*
|
||||
* Each eye also maintains its own projection matrix. These can be set with setCustomEyeProjection.
|
||||
* Care must be taken to correctly set the projectionForCulling matrix, as well as its corresponding
|
||||
* near and far values. The projectionForCulling matrix must define a frustum (in head space) that
|
||||
* bounds the frustums of both eyes. Alternatively, culling may be disabled with
|
||||
* View::setFrustumCullingEnabled.
|
||||
*
|
||||
* \see Frustum, View
|
||||
*/
|
||||
@@ -234,6 +249,24 @@ public:
|
||||
*/
|
||||
void setCustomProjection(math::mat4 const& projection, double near, double far) noexcept;
|
||||
|
||||
/** Sets a custom projection matrix for each eye.
|
||||
*
|
||||
* The projectionForCulling, near, and far parameters establish a "culling frustum" which must
|
||||
* encompass anything either eye can see.
|
||||
*
|
||||
* @param projection an array of projection matrices, only the first
|
||||
* CONFIG_STEREOSCOPIC_EYES (2) are read
|
||||
* @param count size of the projection matrix array to set, must be
|
||||
* >= CONFIG_STEREOSCOPIC_EYES (2)
|
||||
* @param projectionForCulling custom projection matrix for culling, must encompass both eyes
|
||||
* @param near distance in world units from the camera to the culling near plane. \p near > 0.
|
||||
* @param far distance in world units from the camera to the culling far plane. \p far > \p
|
||||
* near.
|
||||
* @see setCustomProjection
|
||||
*/
|
||||
void setCustomEyeProjection(math::mat4 const* projection, size_t count,
|
||||
math::mat4 const& projectionForCulling, double near, double far);
|
||||
|
||||
/** Sets the projection matrix.
|
||||
*
|
||||
* The projection matrices must be of one of the following form:
|
||||
@@ -309,11 +342,14 @@ public:
|
||||
* The projection matrix used for rendering always has its far plane set to infinity. This
|
||||
* is why it may differ from the matrix set through setProjection() or setLensProjection().
|
||||
*
|
||||
* @param eyeId the index of the eye to return the projection matrix for, must be <
|
||||
* CONFIG_STEREOSCOPIC_EYES (2)
|
||||
* @return The projection matrix used for rendering
|
||||
*
|
||||
* @see setProjection, setLensProjection, setCustomProjection, getCullingProjectionMatrix
|
||||
* @see setProjection, setLensProjection, setCustomProjection, getCullingProjectionMatrix,
|
||||
* setCustomEyeProjection
|
||||
*/
|
||||
math::mat4 getProjectionMatrix() const noexcept;
|
||||
math::mat4 getProjectionMatrix(uint8_t eyeId = 0) const;
|
||||
|
||||
|
||||
/** Returns the projection matrix used for culling (far plane is finite).
|
||||
@@ -350,6 +386,26 @@ public:
|
||||
void setModelMatrix(const math::mat4& model) noexcept;
|
||||
void setModelMatrix(const math::mat4f& model) noexcept; //!< @overload
|
||||
|
||||
/** Set the position of an eye relative to this Camera (head).
|
||||
*
|
||||
* By default, both eyes' model matrices are identity matrices.
|
||||
*
|
||||
* For example, to position Eye 0 3cm leftwards and Eye 1 3cm rightwards:
|
||||
* ~~~~~~~~~~~{.cpp}
|
||||
* const mat4 leftEye = mat4::translation(double3{-0.03, 0.0, 0.0});
|
||||
* const mat4 rightEye = mat4::translation(double3{ 0.03, 0.0, 0.0});
|
||||
* camera.setEyeModelMatrix(0, leftEye);
|
||||
* camera.setEyeModelMatrix(1, rightEye);
|
||||
* ~~~~~~~~~~~
|
||||
*
|
||||
* This method is not intended to be called every frame. Instead, to update the position of the
|
||||
* head, use Camera::setModelMatrix.
|
||||
*
|
||||
* @param eyeId the index of the eye to set, must be < CONFIG_STEREOSCOPIC_EYES (2)
|
||||
* @param model the model matrix for an individual eye
|
||||
*/
|
||||
void setEyeModelMatrix(uint8_t eyeId, math::mat4 const& model);
|
||||
|
||||
/** Sets the camera's model matrix
|
||||
*
|
||||
* @param eye The position of the camera in world space.
|
||||
@@ -448,7 +504,9 @@ public:
|
||||
//! returns this camera's sensitivity in ISO
|
||||
float getSensitivity() const noexcept;
|
||||
|
||||
//! returns the focal length in meters [m] for a 35mm camera
|
||||
/** Returns the focal length in meters [m] for a 35mm camera.
|
||||
* Eye 0's projection matrix is used to compute the focal length.
|
||||
*/
|
||||
double getFocalLength() const noexcept;
|
||||
|
||||
/**
|
||||
@@ -191,7 +191,7 @@ private:
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* // Declares a "linear sRGB" color space.
|
||||
* ColorSpace myColorSpace = Rec709-Linear-sRGB;
|
||||
* ColorSpace myColorSpace = Rec709-Linear-D65;
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/
|
||||
class PartialColorSpace {
|
||||
@@ -17,6 +17,8 @@
|
||||
#ifndef TNT_FILAMENT_ENGINE_H
|
||||
#define TNT_FILAMENT_ENGINE_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <backend/Platform.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
@@ -49,6 +51,7 @@ class SwapChain;
|
||||
class Texture;
|
||||
class VertexBuffer;
|
||||
class View;
|
||||
class InstanceBuffer;
|
||||
|
||||
class LightManager;
|
||||
class RenderableManager;
|
||||
@@ -164,6 +167,7 @@ class TransformManager;
|
||||
* @see Renderer
|
||||
*/
|
||||
class UTILS_PUBLIC Engine {
|
||||
struct BuilderDetails;
|
||||
public:
|
||||
using Platform = backend::Platform;
|
||||
using Backend = backend::Backend;
|
||||
@@ -265,96 +269,124 @@ public:
|
||||
uint32_t perFrameCommandsSizeMB = FILAMENT_PER_FRAME_COMMANDS_SIZE_IN_MB;
|
||||
};
|
||||
|
||||
|
||||
#if UTILS_HAS_THREADING
|
||||
using CreateCallback = void(void* user, void* token);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Creates an instance of Engine
|
||||
*
|
||||
* @param backend Which driver backend to use.
|
||||
*
|
||||
* @param platform A pointer to an object that implements Platform. If this is
|
||||
* provided, then this object is used to create the hardware context
|
||||
* and expose platform features to it.
|
||||
*
|
||||
* If not provided (or nullptr is used), an appropriate Platform
|
||||
* is created automatically.
|
||||
*
|
||||
* All methods of this interface are called from filament's
|
||||
* render thread, which is different from the main thread.
|
||||
*
|
||||
* The lifetime of \p platform must exceed the lifetime of
|
||||
* the Engine object.
|
||||
*
|
||||
* @param sharedGLContext A platform-dependant OpenGL context used as a shared context
|
||||
* when creating filament's internal context.
|
||||
* Setting this parameter will force filament to use the OpenGL
|
||||
* implementation (instead of Vulkan for instance).
|
||||
*
|
||||
* @param config A pointer to optional parameters to specify memory size
|
||||
* configuration options. If nullptr, then defaults used.
|
||||
*
|
||||
* @return A pointer to the newly created Engine, or nullptr if the Engine couldn't be created.
|
||||
*
|
||||
* nullptr if the GPU driver couldn't be initialized, for instance if it doesn't
|
||||
* support the right version of OpenGL or OpenGL ES.
|
||||
*
|
||||
* @exception utils::PostConditionPanic can be thrown if there isn't enough memory to
|
||||
* allocate the command buffer. If exceptions are disabled, this condition if fatal and
|
||||
* this function will abort.
|
||||
*
|
||||
* \remark
|
||||
* This method is thread-safe.
|
||||
* Engine::Builder is used to create a new filament Engine.
|
||||
*/
|
||||
static Engine* create(Backend backend = Backend::DEFAULT,
|
||||
Platform* platform = nullptr, void* sharedGLContext = nullptr,
|
||||
const Config* config = nullptr);
|
||||
class Builder : public BuilderBase<BuilderDetails> {
|
||||
friend struct BuilderDetails;
|
||||
friend class FEngine;
|
||||
public:
|
||||
Builder() noexcept;
|
||||
Builder(Builder const& rhs) noexcept;
|
||||
Builder(Builder&& rhs) noexcept;
|
||||
~Builder() noexcept;
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* @param backend Which driver backend to use
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& backend(Backend backend) noexcept;
|
||||
|
||||
/**
|
||||
* @param platform A pointer to an object that implements Platform. If this is
|
||||
* provided, then this object is used to create the hardware context
|
||||
* and expose platform features to it.
|
||||
*
|
||||
* If not provided (or nullptr is used), an appropriate Platform
|
||||
* is created automatically.
|
||||
*
|
||||
* All methods of this interface are called from filament's
|
||||
* render thread, which is different from the main thread.
|
||||
*
|
||||
* The lifetime of \p platform must exceed the lifetime of
|
||||
* the Engine object.
|
||||
*
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& platform(Platform* platform) noexcept;
|
||||
|
||||
/**
|
||||
* @param config A pointer to optional parameters to specify memory size
|
||||
* configuration options. If nullptr, then defaults used.
|
||||
*
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& config(const Config* config) noexcept;
|
||||
|
||||
/**
|
||||
* @param sharedContext A platform-dependant context used as a shared context
|
||||
* when creating filament's internal context.
|
||||
*
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& sharedContext(void* sharedContext) noexcept;
|
||||
|
||||
#if UTILS_HAS_THREADING
|
||||
/**
|
||||
* Creates the filament Engine asynchronously.
|
||||
*
|
||||
* @param callback Callback called once the engine is initialized and it is safe to
|
||||
* call Engine::getEngine().
|
||||
*/
|
||||
void build(utils::Invocable<void(void* token)>&& callback) const;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Creates an instance of Engine.
|
||||
*
|
||||
* @return A pointer to the newly created Engine, or nullptr if the Engine couldn't be
|
||||
* created.
|
||||
* nullptr if the GPU driver couldn't be initialized, for instance if it doesn't
|
||||
* support the right version of OpenGL or OpenGL ES.
|
||||
*
|
||||
* @exception utils::PostConditionPanic can be thrown if there isn't enough memory to
|
||||
* allocate the command buffer. If exceptions are disabled, this condition if
|
||||
* fatal and this function will abort.
|
||||
*/
|
||||
Engine* build() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Backward compatibility helper to create an Engine.
|
||||
* @see Builder
|
||||
*/
|
||||
static inline Engine* create(Backend backend = Backend::DEFAULT,
|
||||
Platform* platform = nullptr, void* sharedContext = nullptr,
|
||||
const Config* config = nullptr) {
|
||||
return Engine::Builder()
|
||||
.backend(backend)
|
||||
.platform(platform)
|
||||
.sharedContext(sharedContext)
|
||||
.config(config)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
#if UTILS_HAS_THREADING
|
||||
/**
|
||||
* A callback used with Engine::createAsync() called once the engine is initialized and it is
|
||||
* safe to call Engine::getEngine(token). This callback is invoked from an arbitrary worker
|
||||
* thread. Engine::getEngine() CANNOT be called from that thread, instead it must be called
|
||||
* from the same thread than Engine::createAsync() was called from.
|
||||
*
|
||||
* @param user User provided parameter given in createAsync().
|
||||
*
|
||||
* @param token An opaque token used to call Engine::getEngine().
|
||||
* Backward compatibility helper to create an Engine asynchronously.
|
||||
* @see Builder
|
||||
*/
|
||||
using CreateCallback = void(void* user, void* token);
|
||||
|
||||
/**
|
||||
* Creates an instance of Engine asynchronously
|
||||
*
|
||||
* @param callback Callback called once the engine is initialized and it is safe to
|
||||
* call Engine::getEngine.
|
||||
*
|
||||
* @param user A user provided pointer that is given back to callback unmodified.
|
||||
*
|
||||
* @param backend Which driver backend to use.
|
||||
*
|
||||
* @param platform A pointer to an object that implements Platform. If this is
|
||||
* provided, then this object is used to create the hardware context
|
||||
* and expose platform features to it.
|
||||
*
|
||||
* If not provided (or nullptr is used), an appropriate Platform
|
||||
* is created automatically.
|
||||
*
|
||||
* All methods of this interface are called from filament's
|
||||
* render thread, which is different from the main thread.
|
||||
*
|
||||
* The lifetime of \p platform must exceed the lifetime of
|
||||
* the Engine object.
|
||||
*
|
||||
* @param sharedGLContext A platform-dependant OpenGL context used as a shared context
|
||||
* when creating filament's internal context.
|
||||
* Setting this parameter will force filament to use the OpenGL
|
||||
* implementation (instead of Vulkan for instance).
|
||||
*
|
||||
* @param config A pointer to optional parameters to specify memory size
|
||||
* configuration options
|
||||
*/
|
||||
static void createAsync(CreateCallback callback, void* user,
|
||||
static inline void createAsync(CreateCallback callback, void* user,
|
||||
Backend backend = Backend::DEFAULT,
|
||||
Platform* platform = nullptr, void* sharedGLContext = nullptr,
|
||||
const Config* config = nullptr);
|
||||
Platform* platform = nullptr, void* sharedContext = nullptr,
|
||||
const Config* config = nullptr) {
|
||||
Engine::Builder()
|
||||
.backend(backend)
|
||||
.platform(platform)
|
||||
.sharedContext(sharedContext)
|
||||
.config(config)
|
||||
.build([callback, user](void* token) {
|
||||
callback(user, token);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an Engine* from createAsync(). This must be called from the same thread than
|
||||
@@ -371,6 +403,7 @@ public:
|
||||
static Engine* getEngine(void* token);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Destroy the Engine instance and all associated resources.
|
||||
*
|
||||
@@ -464,6 +497,29 @@ public:
|
||||
*/
|
||||
FeatureLevel getActiveFeatureLevel() const noexcept;
|
||||
|
||||
/**
|
||||
* Queries the maximum number of GPU instances that Filament creates when automatic instancing
|
||||
* is enabled. This value is also the limit for the number of transforms that can be stored in
|
||||
* an InstanceBuffer. This value may depend on the device and platform, but will remain constant
|
||||
* during the lifetime of this Engine.
|
||||
*
|
||||
* This value does not apply when using the instances(size_t) method on
|
||||
* RenderableManager::Builder.
|
||||
*
|
||||
* @return the number of max automatic instances
|
||||
* @see setAutomaticInstancingEnabled
|
||||
* @see RenderableManager::Builder::instances(size_t)
|
||||
* @see RenderableManager::Builder::instances(size_t, InstanceBuffer*)
|
||||
*/
|
||||
size_t getMaxAutomaticInstances() const noexcept;
|
||||
|
||||
/**
|
||||
* Queries the device and platform for instanced stereo rendering support.
|
||||
*
|
||||
* @return true if stereo rendering is supported, false otherwise
|
||||
* @see View::setStereoscopicOptions
|
||||
*/
|
||||
bool isStereoSupported() const noexcept;
|
||||
|
||||
/**
|
||||
* @return EntityManager used by filament
|
||||
@@ -625,8 +681,28 @@ public:
|
||||
bool destroy(const Texture* p); //!< Destroys a Texture object.
|
||||
bool destroy(const RenderTarget* p); //!< Destroys a RenderTarget object.
|
||||
bool destroy(const View* p); //!< Destroys a View object.
|
||||
bool destroy(const InstanceBuffer* p); //!< Destroys an InstanceBuffer object.
|
||||
void destroy(utils::Entity e); //!< Destroys all filament-known components from this entity
|
||||
|
||||
bool isValid(const BufferObject* p); //!< Tells whether a BufferObject object is valid
|
||||
bool isValid(const VertexBuffer* p); //!< Tells whether an VertexBuffer object is valid
|
||||
bool isValid(const Fence* p); //!< Tells whether a Fence object is valid
|
||||
bool isValid(const IndexBuffer* p); //!< Tells whether an IndexBuffer object is valid
|
||||
bool isValid(const SkinningBuffer* p); //!< Tells whether a SkinningBuffer object is valid
|
||||
bool isValid(const MorphTargetBuffer* p); //!< Tells whether a MorphTargetBuffer object is valid
|
||||
bool isValid(const IndirectLight* p); //!< Tells whether an IndirectLight object is valid
|
||||
bool isValid(const Material* p); //!< Tells whether an IndirectLight object is valid
|
||||
bool isValid(const Renderer* p); //!< Tells whether a Renderer object is valid
|
||||
bool isValid(const Scene* p); //!< Tells whether a Scene object is valid
|
||||
bool isValid(const Skybox* p); //!< Tells whether a SkyBox object is valid
|
||||
bool isValid(const ColorGrading* p); //!< Tells whether a ColorGrading object is valid
|
||||
bool isValid(const SwapChain* p); //!< Tells whether a SwapChain object is valid
|
||||
bool isValid(const Stream* p); //!< Tells whether a Stream object is valid
|
||||
bool isValid(const Texture* p); //!< Tells whether a Texture object is valid
|
||||
bool isValid(const RenderTarget* p); //!< Tells whether a RenderTarget object is valid
|
||||
bool isValid(const View* p); //!< Tells whether a View object is valid
|
||||
bool isValid(const InstanceBuffer* p); //!< Tells whether an InstanceBuffer object is valid
|
||||
|
||||
/**
|
||||
* Kicks the hardware thread (e.g. the OpenGL, Vulkan or Metal thread) and blocks until
|
||||
* all commands to this point are executed. Note that does guarantee that the
|
||||
@@ -28,11 +28,7 @@
|
||||
namespace filament {
|
||||
|
||||
/**
|
||||
* Fence is used to synchronize rendering operations together, with the CPU or with compute.
|
||||
*
|
||||
* \note
|
||||
* Currently Fence only provide client-side synchronization.
|
||||
*
|
||||
* Fence is used to synchronize the application main thread with filament's rendering thread.
|
||||
*/
|
||||
class UTILS_PUBLIC Fence : public FilamentAPI {
|
||||
public:
|
||||
98
ios/include/filament/filament/InstanceBuffer.h
Normal file
98
ios/include/filament/filament/InstanceBuffer.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TNT_FILAMENT_INSTANCEBUFFER_H
|
||||
#define TNT_FILAMENT_INSTANCEBUFFER_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <filament/Engine.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
/**
|
||||
* InstanceBuffer holds draw (GPU) instance transforms. These can be provided to a renderable to
|
||||
* "offset" each draw instance.
|
||||
*
|
||||
* @see RenderableManager::Builder::instances(size_t, InstanceBuffer*)
|
||||
*/
|
||||
class UTILS_PUBLIC InstanceBuffer : public FilamentAPI {
|
||||
struct BuilderDetails;
|
||||
|
||||
public:
|
||||
class Builder : public BuilderBase<BuilderDetails> {
|
||||
friend struct BuilderDetails;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @param instanceCount the number of instances this InstanceBuffer will support, must be
|
||||
* >= 1 and <= \c Engine::getMaxAutomaticInstances()
|
||||
* @see Engine::getMaxAutomaticInstances
|
||||
*/
|
||||
Builder(size_t instanceCount) noexcept;
|
||||
|
||||
Builder(Builder const& rhs) noexcept;
|
||||
Builder(Builder&& rhs) noexcept;
|
||||
~Builder() noexcept;
|
||||
Builder& operator=(Builder const& rhs) noexcept;
|
||||
Builder& operator=(Builder&& rhs) noexcept;
|
||||
|
||||
/**
|
||||
* Provide an initial local transform for each instance. Each local transform is relative to
|
||||
* the transform of the associated renderable. This forms a parent-child relationship
|
||||
* between the renderable and its instances, so adjusting the renderable's transform will
|
||||
- * affect all instances.
|
||||
*
|
||||
* The array of math::mat4f must have length instanceCount, provided when constructing this
|
||||
* Builder.
|
||||
*
|
||||
* @param localTransforms an array of math::mat4f with length instanceCount, must remain
|
||||
* valid until after build() is called
|
||||
*/
|
||||
Builder& localTransforms(math::mat4f const* localTransforms) noexcept;
|
||||
|
||||
/**
|
||||
* Creates the InstanceBuffer object and returns a pointer to it.
|
||||
*/
|
||||
InstanceBuffer* build(Engine& engine);
|
||||
|
||||
private:
|
||||
friend class FInstanceBuffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the instance count specified when building this InstanceBuffer.
|
||||
*/
|
||||
size_t getInstanceCount() const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the local transform for each instance. Each local transform is relative to the transform
|
||||
* of the associated renderable. This forms a parent-child relationship between the renderable
|
||||
* and its instances, so adjusting the renderable's transform will affect all instances.
|
||||
*
|
||||
* @param localTransforms an array of math::mat4f with length count, need not outlive this call
|
||||
* @param count the number of local transforms
|
||||
* @param offset index of the first instance to set local transforms
|
||||
*/
|
||||
void setLocalTransforms(math::mat4f const* localTransforms, size_t count, size_t offset = 0);
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif //TNT_FILAMENT_INSTANCEBUFFER_H
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <utils/EntityInstance.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
#include <math/quat.h>
|
||||
|
||||
namespace utils {
|
||||
class Entity;
|
||||
@@ -244,6 +245,7 @@ public:
|
||||
* shadows that are too far and wouldn't contribute to the scene much, improving
|
||||
* performance and quality. This value is always positive.
|
||||
* Use 0.0f to use the camera far distance.
|
||||
* This only affect directional lights.
|
||||
*/
|
||||
float shadowFar = 0.0f;
|
||||
|
||||
@@ -360,6 +362,13 @@ public:
|
||||
* enabled. (2cm by default).
|
||||
*/
|
||||
float shadowBulbRadius = 0.02f;
|
||||
|
||||
/**
|
||||
* Transforms the shadow direction. Must be a unit quaternion.
|
||||
* The default is identity.
|
||||
* Ignored if the light type isn't directional. For artistic use. Use with caution.
|
||||
*/
|
||||
math::quatf transform{ 1.0f };
|
||||
};
|
||||
|
||||
struct ShadowCascades {
|
||||
@@ -671,7 +680,7 @@ public:
|
||||
* @return true is this light is a type of directional light
|
||||
*/
|
||||
inline bool isDirectional(Instance i) const noexcept {
|
||||
Type type = getType(i);
|
||||
Type const type = getType(i);
|
||||
return type == Type::DIRECTIONAL || type == Type::SUN;
|
||||
}
|
||||
|
||||
@@ -692,7 +701,7 @@ public:
|
||||
* @return true is this light is a type of spot light
|
||||
*/
|
||||
inline bool isSpotLight(Instance i) const noexcept {
|
||||
Type type = getType(i);
|
||||
Type const type = getType(i);
|
||||
return type == Type::SPOT || type == Type::FOCUSED_SPOT;
|
||||
}
|
||||
|
||||
@@ -22,9 +22,11 @@
|
||||
#include <filament/MaterialEnums.h>
|
||||
#include <filament/MaterialInstance.h>
|
||||
|
||||
#include <backend/CallbackHandler.h>
|
||||
#include <backend/DriverEnums.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Invocable.h>
|
||||
|
||||
#include <math/mathfwd.h>
|
||||
|
||||
@@ -150,6 +152,65 @@ public:
|
||||
friend class FMaterial;
|
||||
};
|
||||
|
||||
using CompilerPriorityQueue = backend:: CompilerPriorityQueue;
|
||||
|
||||
/**
|
||||
* Asynchronously ensures that a subset of this Material's variants are compiled. After issuing
|
||||
* several Material::compile() calls in a row, it is recommended to call Engine::flush()
|
||||
* such that the backend can start the compilation work as soon as possible.
|
||||
* The provided callback is guaranteed to be called on the main thread after all specified
|
||||
* variants of the material are compiled. This can take hundreds of milliseconds.
|
||||
*
|
||||
* If all the material's variants are already compiled, the callback will be scheduled as
|
||||
* soon as possible, but this might take a few dozen millisecond, corresponding to how
|
||||
* many previous frames are enqueued in the backend. This also varies by backend. Therefore,
|
||||
* it is recommended to only call this method once per material shortly after creation.
|
||||
*
|
||||
* If the same variant is scheduled for compilation multiple times, the first scheduling
|
||||
* takes precedence; later scheduling are ignored.
|
||||
*
|
||||
* caveat: A consequence is that if a variant is scheduled on the low priority queue and later
|
||||
* scheduled again on the high priority queue, the later scheduling is ignored.
|
||||
* Therefore, the second callback could be called before the variant is compiled.
|
||||
* However, the first callback, if specified, will trigger as expected.
|
||||
*
|
||||
* The callback is guaranteed to be called. If the engine is destroyed while some material
|
||||
* variants are still compiling or in the queue, these will be discarded and the corresponding
|
||||
* callback will be called. In that case however the Material pointer passed to the callback
|
||||
* is guaranteed to be invalid (either because it's been destroyed by the user already, or,
|
||||
* because it's been cleaned-up by the Engine).
|
||||
*
|
||||
* UserVariantFilterMask::ALL should be used with caution. Only variants that an application
|
||||
* needs should be included in the variants argument. For example, the STE variant is only used
|
||||
* for stereoscopic rendering. If an application is not planning to render in stereo, this bit
|
||||
* should be turned off to avoid unnecessary material compilations.
|
||||
*
|
||||
* @param priority Which priority queue to use, LOW or HIGH.
|
||||
* @param variants Variants to include to the compile command.
|
||||
* @param handler Handler to dispatch the callback or nullptr for the default handler
|
||||
* @param callback callback called on the main thread when the compilation is done on
|
||||
* by backend.
|
||||
*/
|
||||
void compile(CompilerPriorityQueue priority,
|
||||
UserVariantFilterMask variants,
|
||||
backend::CallbackHandler* handler = nullptr,
|
||||
utils::Invocable<void(Material*)>&& callback = {}) noexcept;
|
||||
|
||||
inline void compile(CompilerPriorityQueue priority,
|
||||
UserVariantFilterBit variants,
|
||||
backend::CallbackHandler* handler = nullptr,
|
||||
utils::Invocable<void(Material*)>&& callback = {}) noexcept {
|
||||
compile(priority, UserVariantFilterMask(variants), handler,
|
||||
std::forward<utils::Invocable<void(Material*)>>(callback));
|
||||
}
|
||||
|
||||
inline void compile(CompilerPriorityQueue priority,
|
||||
backend::CallbackHandler* handler = nullptr,
|
||||
utils::Invocable<void(Material*)>&& callback = {}) noexcept {
|
||||
compile(priority, UserVariantFilterBit::ALL, handler,
|
||||
std::forward<utils::Invocable<void(Material*)>>(callback));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of this material. Material instances should be freed using
|
||||
* Engine::destroy(const MaterialInstance*).
|
||||
@@ -47,11 +47,14 @@ enum UTILS_PUBLIC ChunkType : uint64_t {
|
||||
MaterialShaderModels = charTo64bitNum("MAT_SMDL"),
|
||||
MaterialSamplerBindings = charTo64bitNum("MAT_SAMP"),
|
||||
MaterialUniformBindings = charTo64bitNum("MAT_UNIF"),
|
||||
MaterialBindingUniformInfo = charTo64bitNum("MAT_UFRM"),
|
||||
MaterialAttributeInfo = charTo64bitNum("MAT_ATTR"),
|
||||
MaterialProperties = charTo64bitNum("MAT_PROP"),
|
||||
MaterialConstants = charTo64bitNum("MAT_CONS"),
|
||||
|
||||
MaterialName = charTo64bitNum("MAT_NAME"),
|
||||
MaterialVersion = charTo64bitNum("MAT_VERS"),
|
||||
MaterialCacheId = charTo64bitNum("MAT_UUID"),
|
||||
MaterialFeatureLevel = charTo64bitNum("MAT_FEAT"),
|
||||
MaterialShading = charTo64bitNum("MAT_SHAD"),
|
||||
MaterialBlendingMode = charTo64bitNum("MAT_BLEN"),
|
||||
@@ -20,6 +20,7 @@
|
||||
#define TNT_FILAMENT_MATERIAL_ENUM_H
|
||||
|
||||
#include <utils/bitset.h>
|
||||
#include <utils/BitmaskEnum.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -27,7 +28,7 @@
|
||||
namespace filament {
|
||||
|
||||
// update this when a new version of filament wouldn't work with older materials
|
||||
static constexpr size_t MATERIAL_VERSION = 32;
|
||||
static constexpr size_t MATERIAL_VERSION = 43;
|
||||
|
||||
/**
|
||||
* Supported shading models
|
||||
@@ -232,18 +233,23 @@ enum class Property : uint8_t {
|
||||
// when adding new Properties, make sure to update MATERIAL_PROPERTIES_COUNT
|
||||
};
|
||||
|
||||
enum class UserVariantFilterBit : uint32_t {
|
||||
DIRECTIONAL_LIGHTING = 0x01,
|
||||
DYNAMIC_LIGHTING = 0x02,
|
||||
SHADOW_RECEIVER = 0x04,
|
||||
SKINNING = 0x08,
|
||||
FOG = 0x10,
|
||||
VSM = 0x20,
|
||||
SSR = 0x40,
|
||||
};
|
||||
|
||||
using UserVariantFilterMask = uint32_t;
|
||||
|
||||
enum class UserVariantFilterBit : UserVariantFilterMask {
|
||||
DIRECTIONAL_LIGHTING = 0x01, //!< Directional lighting
|
||||
DYNAMIC_LIGHTING = 0x02, //!< Dynamic lighting
|
||||
SHADOW_RECEIVER = 0x04, //!< Shadow receiver
|
||||
SKINNING = 0x08, //!< Skinning
|
||||
FOG = 0x10, //!< Fog
|
||||
VSM = 0x20, //!< Variance shadow maps
|
||||
SSR = 0x40, //!< Screen-space reflections
|
||||
STE = 0x80, //!< Instanced stereo rendering
|
||||
ALL = 0xFF,
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
template<> struct utils::EnableBitMaskOperators<filament::UserVariantFilterBit>
|
||||
: public std::true_type {};
|
||||
|
||||
#endif
|
||||
@@ -52,6 +52,7 @@ 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;
|
||||
@@ -367,6 +368,16 @@ public:
|
||||
*/
|
||||
void setDepthCulling(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default depth function state that was set on the material.
|
||||
*/
|
||||
void setDepthFunc(DepthFunc depthFunc) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the depth function state.
|
||||
*/
|
||||
DepthFunc getDepthFunc() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether depth culling is enabled.
|
||||
*/
|
||||
@@ -133,14 +133,25 @@ struct BloomOptions {
|
||||
Texture* dirt = nullptr; //!< user provided dirt texture %codegen_skip_json% %codegen_skip_javascript%
|
||||
float dirtStrength = 0.2f; //!< strength of the dirt texture %codegen_skip_json% %codegen_skip_javascript%
|
||||
float strength = 0.10f; //!< bloom's strength between 0.0 and 1.0
|
||||
uint32_t resolution = 360; //!< resolution of vertical axis (2^levels to 2048)
|
||||
uint32_t resolution = 384; //!< resolution of vertical axis (2^levels to 2048)
|
||||
float anamorphism = 1.0f; //!< bloom x/y aspect-ratio (1/32 to 32)
|
||||
uint8_t levels = 6; //!< number of blur levels (3 to 11)
|
||||
uint8_t levels = 6; //!< number of blur levels (1 to 11)
|
||||
BlendMode blendMode = BlendMode::ADD; //!< how the bloom effect is applied
|
||||
bool threshold = true; //!< whether to threshold the source
|
||||
bool enabled = false; //!< enable or disable bloom
|
||||
float highlight = 1000.0f; //!< limit highlights to this value before bloom [10, +inf]
|
||||
|
||||
/**
|
||||
* Bloom quality level.
|
||||
* LOW (default): use a more optimized down-sampling filter, however there can be artifacts
|
||||
* with dynamic resolution, this can be alleviated by using the homogenous mode.
|
||||
* MEDIUM: Good balance between quality and performance.
|
||||
* HIGH: In this mode the bloom resolution is automatically increased to avoid artifacts.
|
||||
* This mode can be significantly slower on mobile, especially at high resolution.
|
||||
* This mode greatly improves the anamorphic bloom.
|
||||
*/
|
||||
QualityLevel quality = QualityLevel::LOW;
|
||||
|
||||
bool lensFlare = false; //!< enable screen-space lens flare
|
||||
bool starburst = true; //!< enable starburst effect on lens flare
|
||||
float chromaticAberration = 0.005f; //!< amount of chromatic aberration
|
||||
@@ -237,10 +248,32 @@ struct FogOptions {
|
||||
/**
|
||||
* The fog color will be sampled from the IBL in the view direction and tinted by `color`.
|
||||
* Depending on the scene this can produce very convincing results.
|
||||
* This simulate a more anisotropic phase-function.
|
||||
*
|
||||
* This simulates a more anisotropic phase-function.
|
||||
*
|
||||
* `fogColorFromIbl` is ignored when skyTexture is specified.
|
||||
*
|
||||
* @see skyColor
|
||||
*/
|
||||
bool fogColorFromIbl = false;
|
||||
|
||||
/**
|
||||
* skyTexture must be a mipmapped cubemap. When provided, the fog color will be sampled from
|
||||
* this texture, higher resolution mip levels will be used for objects at the far clip plane,
|
||||
* and lower resolution mip levels for objects closer to the camera. The skyTexture should
|
||||
* typically be heavily blurred; a typical way to produce this texture is to blur the base
|
||||
* level with a strong gaussian filter or even an irradiance filter and then generate mip
|
||||
* levels as usual. How blurred the base level is somewhat of an artistic decision.
|
||||
*
|
||||
* This simulates a more anisotropic phase-function.
|
||||
*
|
||||
* `fogColorFromIbl` is ignored when skyTexture is specified.
|
||||
*
|
||||
* @see Texture
|
||||
* @see fogColorFromIbl
|
||||
*/
|
||||
Texture* skyColor = nullptr; //!< %codegen_skip_json% %codegen_skip_javascript%
|
||||
|
||||
/**
|
||||
* Enable or disable large-scale fog
|
||||
*/
|
||||
@@ -519,6 +552,13 @@ struct SoftShadowOptions {
|
||||
float penumbraRatioScale = 1.0f;
|
||||
};
|
||||
|
||||
/**
|
||||
* Options for stereoscopic (multi-eye) rendering.
|
||||
*/
|
||||
struct StereoscopicOptions {
|
||||
bool enabled = false;
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
|
||||
#endif //TNT_FILAMENT_OPTIONS_H
|
||||
@@ -91,8 +91,6 @@ public:
|
||||
/**
|
||||
* Sets a texture to a given attachment point.
|
||||
*
|
||||
* All RenderTargets must have a non-null COLOR attachment.
|
||||
*
|
||||
* When using a DEPTH attachment, it is important to always disable post-processing
|
||||
* in the View. Failing to do so will cause the DEPTH attachment to be ignored in most
|
||||
* cases.
|
||||
@@ -45,6 +45,7 @@ class Renderer;
|
||||
class SkinningBuffer;
|
||||
class VertexBuffer;
|
||||
class Texture;
|
||||
class InstanceBuffer;
|
||||
|
||||
class FEngine;
|
||||
class FRenderPrimitive;
|
||||
@@ -302,6 +303,14 @@ public:
|
||||
*/
|
||||
Builder& enableSkinningBuffers(bool enabled = true) noexcept;
|
||||
|
||||
/**
|
||||
* Controls if this renderable is affected by the large-scale fog.
|
||||
* @param enabled If true, enables large-scale fog on this object. Disables it otherwise.
|
||||
* True by default.
|
||||
* @return A reference to this Builder for chaining calls.
|
||||
*/
|
||||
Builder& fog(bool enabled = true) noexcept;
|
||||
|
||||
/**
|
||||
* Enables GPU vertex skinning for up to 255 bones, 0 by default.
|
||||
*
|
||||
@@ -408,22 +417,47 @@ public:
|
||||
*/
|
||||
Builder& globalBlendOrderEnabled(size_t primitiveIndex, bool enabled) noexcept;
|
||||
|
||||
|
||||
/**
|
||||
* Specifies the number of draw instance of this renderable. The default is 1 instance and
|
||||
* Specifies the number of draw instances of this renderable. The default is 1 instance and
|
||||
* the maximum number of instances allowed is 32767. 0 is invalid.
|
||||
*
|
||||
* All instances are culled using the same bounding box, so care must be taken to make
|
||||
* sure all instances render inside the specified bounding box.
|
||||
*
|
||||
* The material must set its `instanced` parameter to `true` in order to use
|
||||
* getInstanceIndex() in the vertex or fragment shader to get the instance index and
|
||||
* possibly adjust the position or transform.
|
||||
* It generally doesn't make sense to use VERTEX_DOMAIN_OBJECT in the material, since it
|
||||
* would pull the same transform for all instances.
|
||||
*
|
||||
* @param instanceCount the number of instances silently clamped between 1 and 32767.
|
||||
*/
|
||||
Builder& instances(size_t instanceCount) noexcept;
|
||||
|
||||
/**
|
||||
* Specifies the number of draw instances of this renderable and an \c InstanceBuffer
|
||||
* containing their local transforms. The default is 1 instance and the maximum number of
|
||||
* instances allowed when supplying transforms is given by
|
||||
* \c Engine::getMaxAutomaticInstances (64 on most platforms). 0 is invalid. The
|
||||
* \c InstanceBuffer must not be destroyed before this renderable.
|
||||
*
|
||||
* All instances are culled using the same bounding box, so care must be taken to make
|
||||
* sure all instances render inside the specified bounding box.
|
||||
*
|
||||
* The material must set its `instanced` parameter to `true` in order to use
|
||||
* \c getInstanceIndex() in the vertex or fragment shader to get the instance index.
|
||||
*
|
||||
* Only the \c VERTEX_DOMAIN_OBJECT vertex domain is supported.
|
||||
*
|
||||
* The local transforms of each instance can be updated with
|
||||
* \c InstanceBuffer::setLocalTransforms.
|
||||
*
|
||||
* \see InstanceBuffer
|
||||
* \see instances(size_t, * math::mat4f const*)
|
||||
* @param instanceCount the number of instances, silently clamped between 1 and
|
||||
* the result of Engine::getMaxAutomaticInstances().
|
||||
* @param instanceBuffer an InstanceBuffer containing at least instanceCount transforms
|
||||
*/
|
||||
Builder& instances(size_t instanceCount, InstanceBuffer* instanceBuffer) noexcept;
|
||||
|
||||
/**
|
||||
* Adds the Renderable component to an entity.
|
||||
*
|
||||
@@ -510,6 +544,19 @@ public:
|
||||
*/
|
||||
void setCulling(Instance instance, bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Changes whether or not the large-scale fog is applied to this renderable
|
||||
* @see Builder::fog()
|
||||
*/
|
||||
void setFogEnabled(Instance instance, bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether large-scale fog is enabled for this renderable.
|
||||
* @return True if fog is enabled for this renderable.
|
||||
* @see Builder::fog()
|
||||
*/
|
||||
bool getFogEnabled(Instance instance) const noexcept;
|
||||
|
||||
/**
|
||||
* Enables or disables a light channel.
|
||||
* Light channel 0 is enabled by default.
|
||||
@@ -18,10 +18,13 @@
|
||||
#define TNT_FILAMENT_SWAPCHAIN_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <backend/CallbackHandler.h>
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/PresentCallable.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Invocable.h>
|
||||
|
||||
namespace filament {
|
||||
|
||||
@@ -148,7 +151,7 @@ class Engine;
|
||||
class UTILS_PUBLIC SwapChain : public FilamentAPI {
|
||||
public:
|
||||
using FrameScheduledCallback = backend::FrameScheduledCallback;
|
||||
using FrameCompletedCallback = backend::FrameCompletedCallback;
|
||||
using FrameCompletedCallback = utils::Invocable<void(SwapChain*)>;
|
||||
|
||||
/**
|
||||
* Requests a SwapChain with an alpha channel.
|
||||
@@ -241,17 +244,23 @@ public:
|
||||
* contents have completed rendering on the GPU.
|
||||
*
|
||||
* Use SwapChain::setFrameCompletedCallback to set a callback on an individual SwapChain. Each
|
||||
* time a frame completes GPU rendering, the callback will be called with optional user data.
|
||||
* time a frame completes GPU rendering, the callback will be called.
|
||||
*
|
||||
* The FrameCompletedCallback is guaranteed to be called on the main Filament thread.
|
||||
* If handler is nullptr, the callback is guaranteed to be called on the main Filament thread.
|
||||
*
|
||||
* @param callback A callback, or nullptr to unset.
|
||||
* @param user An optional pointer to user data passed to the callback function.
|
||||
* Use \c setFrameCompletedCallback() (with default arguments) to unset the callback.
|
||||
*
|
||||
* @param handler Handler to dispatch the callback or nullptr for the default handler.
|
||||
* @param callback Callback called when each frame completes.
|
||||
*
|
||||
* @remark Only Filament's Metal backend supports frame callbacks. Other backends ignore the
|
||||
* callback (which will never be called) and proceed normally.
|
||||
*
|
||||
* @see CallbackHandler
|
||||
*/
|
||||
void setFrameCompletedCallback(FrameCompletedCallback callback, void* user = nullptr);
|
||||
void setFrameCompletedCallback(backend::CallbackHandler* handler = nullptr,
|
||||
FrameCompletedCallback&& callback = {}) noexcept;
|
||||
|
||||
};
|
||||
|
||||
} // namespace filament
|
||||
@@ -52,6 +52,8 @@ public:
|
||||
*/
|
||||
TextureSampler() noexcept = default;
|
||||
|
||||
explicit TextureSampler(backend::SamplerParams params) noexcept : mSamplerParams(params) { }
|
||||
|
||||
TextureSampler(const TextureSampler& rhs) noexcept = default;
|
||||
TextureSampler& operator=(const TextureSampler& rhs) noexcept = default;
|
||||
|
||||
@@ -85,6 +85,7 @@ public:
|
||||
using SoftShadowOptions = SoftShadowOptions;
|
||||
using ScreenSpaceReflectionsOptions = ScreenSpaceReflectionsOptions;
|
||||
using GuardBandOptions = GuardBandOptions;
|
||||
using StereoscopicOptions = StereoscopicOptions;
|
||||
|
||||
/**
|
||||
* Sets the View's name. Only useful for debugging.
|
||||
@@ -676,6 +677,32 @@ public:
|
||||
*/
|
||||
bool isStencilBufferEnabled() const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the stereoscopic rendering options for this view.
|
||||
*
|
||||
* Currently, only one type of stereoscopic rendering is supported: side-by-side.
|
||||
* Side-by-side stereo rendering splits the viewport into two halves: a left and right half.
|
||||
* Eye 0 will render to the left half, while Eye 1 will render into the right half.
|
||||
*
|
||||
* Currently, the following features are not supported with stereoscopic rendering:
|
||||
* - post-processing
|
||||
* - shadowing
|
||||
* - punctual lights
|
||||
*
|
||||
* Stereo rendering depends on device and platform support. To check if stereo rendering is
|
||||
* supported, use Engine::isStereoSupported().
|
||||
*
|
||||
* @param options The stereoscopic options to use on this view
|
||||
*/
|
||||
void setStereoscopicOptions(StereoscopicOptions const& options);
|
||||
|
||||
/**
|
||||
* Returns the stereoscopic options associated with this View.
|
||||
*
|
||||
* @return value set by setStereoscopicOptions().
|
||||
*/
|
||||
StereoscopicOptions const& getStereoscopicOptions() const noexcept;
|
||||
|
||||
// for debugging...
|
||||
|
||||
//! debugging: allows to entirely disable frustum culling. (culling enabled by default).
|
||||
@@ -707,6 +734,9 @@ public:
|
||||
* The viewport, projection and model matrices can be obtained from Camera. Because
|
||||
* pick() has some latency, it might be more accurate to obtain these values at the
|
||||
* time the View::pick() call is made.
|
||||
*
|
||||
* Note: if the Engine is running at FEATURE_LEVEL_0, the precision or `depth` and
|
||||
* `fragCoords.z` is only 8-bits.
|
||||
*/
|
||||
math::float3 fragCoords; //! screen space coordinates in GL convention
|
||||
};
|
||||
@@ -803,6 +833,37 @@ public:
|
||||
PickingQuery& pick(uint32_t x, uint32_t y, backend::CallbackHandler* handler,
|
||||
PickingQueryResultCallback callback) noexcept;
|
||||
|
||||
/**
|
||||
* Set the value of material global variables. There are up-to four such variable each of
|
||||
* type float4. These variables can be read in a user Material with
|
||||
* `getMaterialGlobal{0|1|2|3}()`. All variable start with a default value of { 0, 0, 0, 1 }
|
||||
*
|
||||
* @param index index of the variable to set between 0 and 3.
|
||||
* @param value new value for the variable.
|
||||
* @see getMaterialGlobal
|
||||
*/
|
||||
void setMaterialGlobal(uint32_t index, math::float4 const& value);
|
||||
|
||||
/**
|
||||
* Get the value of the material global variables.
|
||||
* All variable start with a default value of { 0, 0, 0, 1 }
|
||||
*
|
||||
* @param index index of the variable to set between 0 and 3.
|
||||
* @return current value of the variable.
|
||||
* @see setMaterialGlobal
|
||||
*/
|
||||
math::float4 getMaterialGlobal(uint32_t index) const;
|
||||
|
||||
/**
|
||||
* Get an Entity representing the large scale fog object.
|
||||
* This entity is always inherited by the View's Scene.
|
||||
*
|
||||
* It is for example possible to create a TransformManager component with this
|
||||
* Entity and apply a transformation globally on the fog.
|
||||
*
|
||||
* @return an Entity representing the large scale fog object.
|
||||
*/
|
||||
utils::Entity getFogEntity() const noexcept;
|
||||
|
||||
/**
|
||||
* List of available ambient occlusion techniques
|
||||
114
ios/include/filament/gltfio/TrsTransformManager.h
Normal file
114
ios/include/filament/gltfio/TrsTransformManager.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GLTFIO_TRSTRANSFORMMANAGER_H
|
||||
#define GLTFIO_TRSTRANSFORMMANAGER_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/EntityInstance.h>
|
||||
#include <math/quat.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/mat4.h>
|
||||
|
||||
using namespace filament::math;
|
||||
|
||||
namespace utils {
|
||||
class Entity;
|
||||
} // namespace utils
|
||||
|
||||
namespace filament::gltfio {
|
||||
|
||||
class FTrsTransformManager;
|
||||
|
||||
/**
|
||||
* TrsTransformManager is used to add entities with glTF-specific trs information.
|
||||
*
|
||||
* Trs information here just used for Animation, DON'T use for transform.
|
||||
*/
|
||||
class UTILS_PUBLIC TrsTransformManager {
|
||||
public:
|
||||
using Instance = utils::EntityInstance<TrsTransformManager>;
|
||||
using Entity = utils::Entity;
|
||||
|
||||
/**
|
||||
* Returns whether a particular Entity is associated with a component of this TrsTransformManager
|
||||
* @param e An Entity.
|
||||
* @return true if this Entity has a component associated with this manager.
|
||||
*/
|
||||
bool hasComponent(Entity e) const noexcept;
|
||||
|
||||
/**
|
||||
* Gets an Instance representing the trs transform component associated with the given Entity.
|
||||
* @param e An Entity.
|
||||
* @return An Instance object, which represents the trs transform component associated with the Entity e.
|
||||
* @note Use Instance::isValid() to make sure the component exists.
|
||||
* @see hasComponent()
|
||||
*/
|
||||
Instance getInstance(Entity e) const noexcept;
|
||||
|
||||
/**
|
||||
* Creates a trs transform component and associates it with the given entity.
|
||||
* @param entity An Entity to associate a trs transform component with.
|
||||
* @param translation The translation to initialize the trs transform component with.
|
||||
* @param rotation The rotation to initialize the trs transform component with.
|
||||
* @param scale The scale to initialize the trs transform component with.
|
||||
*
|
||||
* If this component already exists on the given entity, it is first destroyed as if
|
||||
* destroy(Entity e) was called.
|
||||
*
|
||||
* @see destroy()
|
||||
*/
|
||||
void create(Entity entity);
|
||||
void create(Entity entity, const float3& translation, const quatf& rotation,
|
||||
const float3& scale); //!< \overload
|
||||
|
||||
/**
|
||||
* Destroys this component from the given entity.
|
||||
* @param e An entity.
|
||||
*
|
||||
* @see create()
|
||||
*/
|
||||
void destroy(Entity e) noexcept;
|
||||
|
||||
void setTranslation(Instance ci, const float3& translation) noexcept;
|
||||
const float3& getTranslation(Instance ci) const noexcept;
|
||||
|
||||
void setRotation(Instance ci, const quatf& rotation) noexcept;
|
||||
const quatf& getRotation(Instance ci) const noexcept;
|
||||
|
||||
void setScale(Instance ci, const float3& scale) noexcept;
|
||||
const float3& getScale(Instance ci) const noexcept;
|
||||
|
||||
void setTrs(Instance ci, const float3& translation, const quatf& rotation,
|
||||
const float3& scale) noexcept;
|
||||
const mat4f getTransform(Instance ci) const noexcept;
|
||||
|
||||
protected:
|
||||
TrsTransformManager() noexcept = default;
|
||||
~TrsTransformManager() = default;
|
||||
|
||||
public:
|
||||
TrsTransformManager(TrsTransformManager const&) = delete;
|
||||
TrsTransformManager(TrsTransformManager&&) = delete;
|
||||
TrsTransformManager& operator=(TrsTransformManager const&) = delete;
|
||||
TrsTransformManager& operator=(TrsTransformManager&&) = delete;
|
||||
};
|
||||
|
||||
} // namespace filament::gltfio
|
||||
|
||||
#endif // GLTFIO_TRSTRANSFORMMANAGER_H
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user