diff --git a/cocos/bindings/dop/BufferAllocator.cpp b/cocos/bindings/dop/BufferAllocator.cpp index 83b1953f898..845787fa18e 100644 --- a/cocos/bindings/dop/BufferAllocator.cpp +++ b/cocos/bindings/dop/BufferAllocator.cpp @@ -29,11 +29,13 @@ namespace se { -cc::map BufferAllocator::_pools; +cc::vector BufferAllocator::pools(BUFFER_ALLOCATOR_SIZE); BufferAllocator::BufferAllocator(PoolType type) : _type(type) { - BufferAllocator::_pools[_type] = this; + if (IS_BUFFER_ALLOCATOR_TYPE(type)) { + BufferAllocator::pools[GET_ARRAY_POOL_ID(type)] = this; + } } BufferAllocator::~BufferAllocator() { @@ -41,7 +43,7 @@ BufferAllocator::~BufferAllocator() { buffer.second->decRef(); } _buffers.clear(); - BufferAllocator::_pools.erase(_type); + _caches.clear(); } Object *BufferAllocator::alloc(uint index, uint bytes) { @@ -53,6 +55,11 @@ Object *BufferAllocator::alloc(uint index, uint bytes) { obj->incRef(); _buffers[index] = obj; + uint8_t *ret = nullptr; + size_t len; + obj->getArrayBufferData(static_cast(&ret), &len); + _caches[index] = ret; + return obj; } @@ -62,6 +69,10 @@ void BufferAllocator::free(uint index) { oldObj->decRef(); _buffers.erase(index); } + + if (_caches.count(index)) { + _caches.erase(index); + } } } // namespace se diff --git a/cocos/bindings/dop/BufferAllocator.h b/cocos/bindings/dop/BufferAllocator.h index d6e1b9ea118..8393d54a039 100644 --- a/cocos/bindings/dop/BufferAllocator.h +++ b/cocos/bindings/dop/BufferAllocator.h @@ -37,42 +37,58 @@ namespace se { class CC_DLL BufferAllocator final : public cc::Object { public: template - CC_INLINE static T *getBuffer(PoolType type, uint index) { - uint size = 0; - return BufferAllocator::getBuffer(type, index, &size); + static T *getBuffer(PoolType type, uint index) { + index &= BUFFER_MASK; + const auto p = GET_ARRAY_POOL_ID(type); + +#ifdef CC_DEBUG + CCASSERT(BufferAllocator::pools[p] != nullptr, "BufferPool: Invalid buffer pool type"); +#endif + + auto *const pool = BufferAllocator::pools[p]; + +#ifdef CC_DEBUG + CCASSERT(pool->_caches.count(index) != 0, "BufferPool: Invalid buffer pool index"); +#endif + + return reinterpret_cast(pool->_caches[index]); } template static T *getBuffer(PoolType type, uint index, uint *size) { - index &= _bufferMask; - if (BufferAllocator::_pools.count(type) != 0) { - const auto pool = BufferAllocator::_pools[type]; - if (pool->_buffers.count(index) != 0) { - T *ret = nullptr; - size_t len; - pool->_buffers[index]->getArrayBufferData((uint8_t **)&ret, &len); - *size = (uint)len; - return ret; - } else { - return nullptr; - } - } else { - return nullptr; - } + index &= BUFFER_MASK; + const auto p = GET_ARRAY_POOL_ID(type); + +#ifdef CC_DEBUG + CCASSERT(BufferAllocator::pools[p] != nullptr, "BufferPool: Invalid buffer pool type"); +#endif + + auto *const pool = BufferAllocator::pools[p]; + +#ifdef CC_DEBUG + CCASSERT(pool->_buffers.count(index) != 0, "BufferPool: Invalid buffer pool index"); +#endif + + T * ret = nullptr; + size_t len; + pool->_buffers[index]->getArrayBufferData(static_cast(&ret), &len); + *size = static_cast(len); + return ret; } - BufferAllocator(PoolType type); - ~BufferAllocator(); + explicit BufferAllocator(PoolType type); + ~BufferAllocator() override; Object *alloc(uint index, uint bytes); - void free(uint index); + void free(uint index); private: - static cc::map _pools; - static constexpr uint _bufferMask = ~(1 << 30); + static cc::vector pools; + static constexpr uint BUFFER_MASK = ~(1 << 30); - cc::map _buffers; - PoolType _type = PoolType::UNKNOWN; + cc::map _buffers; + cc::map _caches; + PoolType _type = PoolType::UNKNOWN; }; } // namespace se diff --git a/cocos/bindings/dop/BufferPool.cpp b/cocos/bindings/dop/BufferPool.cpp index 78057be3c91..c579543d894 100644 --- a/cocos/bindings/dop/BufferPool.cpp +++ b/cocos/bindings/dop/BufferPool.cpp @@ -29,33 +29,29 @@ namespace se { -cc::map BufferPool::_poolMap; +cc::vector BufferPool::poolMap(BUFFER_POOL_SIZE); BufferPool::BufferPool(PoolType type, uint entryBits, uint bytesPerEntry) : _allocator(type), _entryBits(entryBits), _bytesPerEntry(bytesPerEntry), _type(type) { - CCASSERT(BufferPool::_poolMap.count(type) == 0, "The type of pool is already exist"); - _entriesPerChunk = 1 << entryBits; - _entryMask = _entriesPerChunk - 1; - _chunkMask = 0xffffffff & ~(_entryMask | _poolFlag); + _entryMask = _entriesPerChunk - 1; + _chunkMask = 0xffffffff & ~(_entryMask | POOL_FLAG); _bytesPerChunk = _bytesPerEntry * _entriesPerChunk; - BufferPool::_poolMap[type] = this; + BufferPool::poolMap[GET_BUFFER_POOL_ID(type)] = this; } -BufferPool::~BufferPool() { - BufferPool::_poolMap.erase(_type); -} +BufferPool::~BufferPool() = default; Object *BufferPool::allocateNewChunk() { Object *jsObj = _allocator.alloc(static_cast(_chunks.size()), _bytesPerChunk); uint8_t *realPtr = nullptr; - size_t len = 0; + size_t len = 0; jsObj->getArrayBufferData(&realPtr, &len); _chunks.push_back(realPtr); diff --git a/cocos/bindings/dop/BufferPool.h b/cocos/bindings/dop/BufferPool.h index 275f1e731f7..86b331d5e22 100644 --- a/cocos/bindings/dop/BufferPool.h +++ b/cocos/bindings/dop/BufferPool.h @@ -25,8 +25,8 @@ #pragma once -#include "PoolType.h" #include "BufferAllocator.h" +#include "PoolType.h" #include "cocos/base/Macros.h" #include "cocos/base/Object.h" #include "cocos/base/TypeDef.h" @@ -39,11 +39,11 @@ class CC_DLL BufferPool final : public cc::Object { public: using Chunk = uint8_t *; - CC_INLINE static const cc::map &getPoolMap() { return BufferPool::_poolMap; } - CC_INLINE static const uint getPoolFlag() { return _poolFlag; } + CC_INLINE static const cc::vector &getPoolMap() { return BufferPool::poolMap; } + CC_INLINE static uint getPoolFlag() { return POOL_FLAG; } BufferPool(PoolType type, uint entryBits, uint bytesPerEntry); - ~BufferPool(); + ~BufferPool() override; template T *getTypedObject(uint id) const { @@ -56,18 +56,18 @@ class CC_DLL BufferPool final : public cc::Object { Object *allocateNewChunk(); private: - static cc::map _poolMap; - static constexpr uint _poolFlag = 1 << 30; + static cc::vector poolMap; + static constexpr uint POOL_FLAG = 1 << 30; - BufferAllocator _allocator; + BufferAllocator _allocator; cc::vector _chunks; - uint _entryBits = 1 << 8; - uint _chunkMask = 0; - uint _entryMask = 0; - uint _bytesPerChunk = 0; - uint _entriesPerChunk = 0; - uint _bytesPerEntry = 0; - PoolType _type = PoolType::UNKNOWN; + uint _entryBits = 1 << 8; + uint _chunkMask = 0; + uint _entryMask = 0; + uint _bytesPerChunk = 0; + uint _entriesPerChunk = 0; + uint _bytesPerEntry = 0; + PoolType _type = PoolType::UNKNOWN; }; } // namespace se diff --git a/cocos/bindings/dop/ObjectPool.cpp b/cocos/bindings/dop/ObjectPool.cpp index 27a751a7862..b3bbf0fc78f 100644 --- a/cocos/bindings/dop/ObjectPool.cpp +++ b/cocos/bindings/dop/ObjectPool.cpp @@ -26,22 +26,29 @@ #include "ObjectPool.h" #include "base/memory/Memory.h" -using namespace se; - -cc::map ObjectPool::_poolMap; +namespace se { +cc::vector ObjectPool::poolMap(CAST_POOL_TYPE(PoolType::FRAMEBUFFER)); ObjectPool::ObjectPool(PoolType type, Object *jsArr) : _type(type), _jsArr(jsArr) { CCASSERT(jsArr->isArray(), "ObjectPool: It must be initialized with a JavaScript array"); - CCASSERT(ObjectPool::_poolMap.count(type) == 0, "This type of ObjectPool already exists."); _jsArr->incRef(); - _indexMask = 0xffffffff & ~_poolFlag; - ObjectPool::_poolMap.emplace(type, this); + _indexMask = 0xffffffff & ~_poolFlag; + ObjectPool::poolMap[GET_OBJECT_POOL_ID(type)] = this; } ObjectPool::~ObjectPool() { _jsArr->decRef(); - ObjectPool::_poolMap.erase(_type); + _array.clear(); +} + +void ObjectPool::bind(uint id, Object *obj) { + if (id >= _array.size()) { + _array.push_back(obj); + } else { + _array[id] = obj; + } } +} // namespace se diff --git a/cocos/bindings/dop/ObjectPool.h b/cocos/bindings/dop/ObjectPool.h index f485c6594cf..b3cb67baef0 100644 --- a/cocos/bindings/dop/ObjectPool.h +++ b/cocos/bindings/dop/ObjectPool.h @@ -25,48 +25,43 @@ #pragma once -#include "cocos/base/Object.h" -#include "cocos/bindings/jswrapper/Object.h" -#include "cocos/base/memory/StlAlloc.h" +#include "PoolType.h" #include "cocos/base/Macros.h" +#include "cocos/base/Object.h" #include "cocos/base/TypeDef.h" -#include "PoolType.h" +#include "cocos/base/memory/StlAlloc.h" +#include "cocos/bindings/jswrapper/Object.h" namespace se { class CC_DLL ObjectPool final : public cc::Object { public: - CC_INLINE static const cc::map &getPoolMap() { return ObjectPool::_poolMap; } + CC_INLINE static const cc::vector &getPoolMap() { return ObjectPool::poolMap; } ObjectPool(PoolType type, Object *jsArr); - ~ObjectPool(); + ~ObjectPool() override; template Type *getTypedObject(uint id) const { id = _indexMask & id; - bool ok = true; + #ifdef CC_DEBUG - uint len = 0; - ok = _jsArr->getArrayLength(&len); - CCASSERT(ok && id < len, "ObjectPool: Invalid buffer pool entry id"); + CCASSERT(id < _array.size(), "ObjectPool: Invalid buffer pool entry id"); #endif - se::Value jsEntry; - ok = _jsArr->getArrayElement(id, &jsEntry); - if (!ok || !jsEntry.isObject()) { - return nullptr; - } - Type *entry = (Type *)jsEntry.toObject()->getPrivateData(); - return entry; + return static_cast(_array[id]->getPrivateData()); } + void bind(uint id, Object *); + private: - static cc::map _poolMap; + static cc::vector poolMap; - PoolType _type = PoolType::SHADER; - Object *_jsArr = nullptr; - uint _poolFlag = 1 << 29; - uint _indexMask = 0; + cc::vector _array; + PoolType _type = PoolType::SHADER; + Object * _jsArr = nullptr; + uint _poolFlag = 1 << 29; + uint _indexMask = 0; }; } // namespace se diff --git a/cocos/bindings/dop/PoolType.h b/cocos/bindings/dop/PoolType.h index d34a45e6003..f4f88631ebb 100644 --- a/cocos/bindings/dop/PoolType.h +++ b/cocos/bindings/dop/PoolType.h @@ -26,6 +26,24 @@ #pragma once namespace se { + +#define CAST_POOL_TYPE(type) static_cast(type) + +#define BUFFER_POOL_BEGIN CAST_POOL_TYPE(se::PoolType::PASS) +#define ARRAY_POOL_BEGIN CAST_POOL_TYPE(se::PoolType::SUB_MODEL_ARRAY) +#define RAW_BUFFER_BEGIN CAST_POOL_TYPE(se::PoolType::RAW_BUFFER) + +#define OBJECT_POOL_SIZE CAST_POOL_TYPE(se::PoolType::FRAMEBUFFER) + 1 +#define BUFFER_POOL_SIZE CAST_POOL_TYPE(se::PoolType::PIPELINE_SHARED_SCENE_DATA) - BUFFER_POOL_BEGIN + 1 +#define ARRAY_POOL_SIZE CAST_POOL_TYPE(se::PoolType::UI_BATCH_ARRAY) - ARRAY_POOL_BEGIN + 1 +#define RAW_BUFFER_SIZE CAST_POOL_TYPE(se::PoolType::RAW_BUFFER) - CAST_POOL_TYPE(se::PoolType::RAW_BUFFER) + 1 +#define BUFFER_ALLOCATOR_SIZE (ARRAY_POOL_SIZE + RAW_BUFFER_SIZE) + +#define GET_OBJECT_POOL_ID(type) CAST_POOL_TYPE(type) +#define GET_BUFFER_POOL_ID(type) CAST_POOL_TYPE(type) - BUFFER_POOL_BEGIN +#define GET_ARRAY_POOL_ID(type) CAST_POOL_TYPE(type) >= RAW_BUFFER_BEGIN ? (CAST_POOL_TYPE(type) - RAW_BUFFER_BEGIN + ARRAY_POOL_SIZE) : CAST_POOL_TYPE(type) - ARRAY_POOL_BEGIN +#define IS_BUFFER_ALLOCATOR_TYPE(type) CAST_POOL_TYPE(type) >= ARRAY_POOL_BEGIN + enum class PoolType { // objects ATTRIBUTE, @@ -76,4 +94,4 @@ enum class PoolType { RAW_BUFFER = 300, UNKNOWN }; -} +} // namespace se diff --git a/cocos/bindings/dop/jsb_dop.cpp b/cocos/bindings/dop/jsb_dop.cpp index 6fd9137741d..96b1b68545a 100644 --- a/cocos/bindings/dop/jsb_dop.cpp +++ b/cocos/bindings/dop/jsb_dop.cpp @@ -25,20 +25,20 @@ #include "jsb_dop.h" +#include "BufferAllocator.h" #include "BufferPool.h" #include "ObjectPool.h" -#include "BufferAllocator.h" -#include "cocos/bindings/manual/jsb_global.h" #include "cocos/bindings/manual/jsb_classtype.h" #include "cocos/bindings/manual/jsb_conversions.h" +#include "cocos/bindings/manual/jsb_global.h" /******************************************************** BufferPool binding *******************************************************/ -se::Class *jsb_BufferPool_class = nullptr; +se::Class *jsb_BufferPool_class = nullptr; // NOLINT -static bool jsb_BufferPool_allocateNewChunk(se::State &s) { - se::BufferPool *pool = (se::BufferPool *)s.nativeThisObject(); +static bool jsb_BufferPool_allocateNewChunk(se::State &s) { // NOLINT + auto *pool = static_cast(s.nativeThisObject()); SE_PRECONDITION2(pool, false, "jsb_BufferPool_allocateNewChunk : Invalid Native Object"); s.rval().setObject(pool->allocateNewChunk()); return true; @@ -47,12 +47,12 @@ SE_BIND_FUNC(jsb_BufferPool_allocateNewChunk); SE_DECLARE_FINALIZE_FUNC(jsb_BufferPool_finalize) -static bool jsb_BufferPool_constructor(se::State &s) { +static bool jsb_BufferPool_constructor(se::State &s) { // NOLINT const auto &args = s.args(); - size_t argc = args.size(); + size_t argc = args.size(); if (argc == 3) { - uint poolType = 0; - uint entryBits = 0; + uint poolType = 0; + uint entryBits = 0; uint bytesPerEntry = 0; bool ok = true; @@ -73,27 +73,27 @@ static bool jsb_BufferPool_constructor(se::State &s) { SE_REPORT_ERROR("jsb_BufferPool_constructor: wrong number of arguments: %d", (int)argc); return false; } -SE_BIND_CTOR(jsb_BufferPool_constructor, jsb_BufferPool_class, jsb_BufferPool_finalize) +SE_BIND_CTOR(jsb_BufferPool_constructor, jsb_BufferPool_class, jsb_BufferPool_finalize) // NOLINT -static bool jsb_BufferPool_finalize(se::State &s) { +static bool jsb_BufferPool_finalize(se::State &s) { // NOLINT auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) { se::NonRefNativePtrCreatedByCtorMap::erase(iter); - se::BufferPool *cobj = (se::BufferPool *)s.nativeThisObject(); + auto *cobj = static_cast(s.nativeThisObject()); JSB_FREE(cobj); } return true; } SE_BIND_FINALIZE_FUNC(jsb_BufferPool_finalize) -static bool js_register_se_BufferPool(se::Object *obj) { +static bool js_register_se_BufferPool(se::Object *obj) { // NOLINT se::Class *cls = se::Class::create("NativeBufferPool", obj, nullptr, _SE(jsb_BufferPool_constructor)); cls->defineFunction("allocateNewChunk", _SE(jsb_BufferPool_allocateNewChunk)); cls->install(); JSBClassType::registerClass(cls); - jsb_BufferPool_class = cls; + jsb_BufferPool_class = cls; // NOLINT se::ScriptEngine::getInstance()->clearException(); return true; @@ -102,16 +102,16 @@ static bool js_register_se_BufferPool(se::Object *obj) { /*************************************************** ObjectPool binding *****************************************************/ -static se::Class *jsb_ObjectPool_class = nullptr; +static se::Class *jsb_ObjectPool_class = nullptr; // NOLINT SE_DECLARE_FINALIZE_FUNC(jsb_ObjectPool_finalize) -static bool jsb_ObjectPool_constructor(se::State &s) { +static bool jsb_ObjectPool_constructor(se::State &s) { // NOLINT const auto &args = s.args(); - size_t argc = args.size(); + size_t argc = args.size(); if (argc == 2) { uint poolType = 0; - bool ok = true; + bool ok = true; ok &= seval_to_uint(args[0], &poolType); if (!args[1].isObject()) { @@ -131,23 +131,48 @@ static bool jsb_ObjectPool_constructor(se::State &s) { } SE_BIND_CTOR(jsb_ObjectPool_constructor, jsb_ObjectPool_class, jsb_ObjectPool_finalize) -static bool jsb_ObjectPool_finalize(se::State &s) { +static bool jsb_ObjectPool_finalize(se::State &s) { // NOLINT auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) { se::NonRefNativePtrCreatedByCtorMap::erase(iter); - se::ObjectPool *cobj = (se::ObjectPool *)s.nativeThisObject(); + auto *cobj = static_cast(s.nativeThisObject()); JSB_FREE(cobj); } return true; } SE_BIND_FINALIZE_FUNC(jsb_ObjectPool_finalize) -static bool js_register_se_ObjectPool(se::Object *obj) { +static bool js_ObjectPool_bind(se::State &s) { // NOLINT + auto *cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_ObjectPool_bind : Invalid Native Object"); + const auto & args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 2) { + bool ok = true; + uint id = 0; + ok &= seval_to_uint(args[0], &id); + SE_PRECONDITION2(ok, false, "jsb_ObjectPool_bind : Error processing arguments"); + + if (!args[1].isObject()) { + SE_REPORT_ERROR("jsb_ObjectPool_bind: parameter 2 wants a Object"); + return false; + } + se::Object *value = args[1].toObject(); + cobj->bind(id, value); + return true; + } + SE_REPORT_ERROR("jsb_ObjectPool_bind: wrong number of arguments: %d, was expecting %d", (int)argc, 1); +} +SE_BIND_FUNC(js_ObjectPool_bind) + +static bool js_register_se_ObjectPool(se::Object *obj) { // NOLINT se::Class *cls = se::Class::create("NativeObjectPool", obj, nullptr, _SE(jsb_ObjectPool_constructor)); + cls->defineFunction("bind", _SE(js_ObjectPool_bind)); cls->install(); JSBClassType::registerClass(cls); - jsb_ObjectPool_class = cls; + jsb_ObjectPool_class = cls; // NOLINT se::ScriptEngine::getInstance()->clearException(); return true; @@ -156,20 +181,20 @@ static bool js_register_se_ObjectPool(se::Object *obj) { /***************************************************** Array binding ******************************************************/ -static se::Class *jsb_BufferAllocator_class = nullptr; +static se::Class *jsb_BufferAllocator_class = nullptr; // NOLINT SE_DECLARE_FINALIZE_FUNC(jsb_BufferAllocator_finalize) -static bool jsb_BufferAllocator_constructor(se::State &s) { +static bool jsb_BufferAllocator_constructor(se::State &s) { // NOLINT const auto &args = s.args(); - size_t argc = args.size(); + size_t argc = args.size(); if (argc == 1) { uint type = 0; - bool ok = seval_to_uint(args[0], &type); + bool ok = seval_to_uint(args[0], &type); - se::BufferAllocator *BufferAllocator = JSB_ALLOC(se::BufferAllocator, static_cast(type)); - s.thisObject()->setPrivateData(BufferAllocator); - se::NonRefNativePtrCreatedByCtorMap::emplace(BufferAllocator); + se::BufferAllocator *bufferAllocator = JSB_ALLOC(se::BufferAllocator, static_cast(type)); + s.thisObject()->setPrivateData(bufferAllocator); + se::NonRefNativePtrCreatedByCtorMap::emplace(bufferAllocator); return true; } @@ -178,23 +203,23 @@ static bool jsb_BufferAllocator_constructor(se::State &s) { } SE_BIND_CTOR(jsb_BufferAllocator_constructor, jsb_BufferAllocator_class, jsb_BufferAllocator_finalize) -static bool jsb_BufferAllocator_finalize(se::State &s) { +static bool jsb_BufferAllocator_finalize(se::State &s) { // NOLINT auto iter = se::NonRefNativePtrCreatedByCtorMap::find(s.nativeThisObject()); if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) { se::NonRefNativePtrCreatedByCtorMap::erase(iter); - se::BufferAllocator *cobj = (se::BufferAllocator *)s.nativeThisObject(); + auto *cobj = static_cast(s.nativeThisObject()); JSB_FREE(cobj); } return true; } SE_BIND_FINALIZE_FUNC(jsb_BufferAllocator_finalize) -static bool jsb_BufferAllocator_alloc(se::State &s) { - se::BufferAllocator *bufferAllocator = (se::BufferAllocator *)s.nativeThisObject(); +static bool jsb_BufferAllocator_alloc(se::State &s) { // NOLINT + auto *bufferAllocator = static_cast(s.nativeThisObject()); SE_PRECONDITION2(bufferAllocator, false, "jsb_Array_alloc : Invalid Native Object"); const auto &args = s.args(); - size_t argc = args.size(); + size_t argc = args.size(); if (argc == 2) { uint index = 0; seval_to_uint(args[0], &index); @@ -209,12 +234,12 @@ static bool jsb_BufferAllocator_alloc(se::State &s) { } SE_BIND_FUNC(jsb_BufferAllocator_alloc); -static bool jsb_BufferAllocator_free(se::State &s) { - se::BufferAllocator *bufferAllocator = (se::BufferAllocator *)s.nativeThisObject(); +static bool jsb_BufferAllocator_free(se::State &s) { // NOLINT + auto *bufferAllocator = static_cast(s.nativeThisObject()); SE_PRECONDITION2(bufferAllocator, false, "jsb_Array_alloc : Invalid Native Object"); const auto &args = s.args(); - size_t argc = args.size(); + size_t argc = args.size(); if (argc == 1) { uint index = 0; seval_to_uint(args[0], &index); @@ -227,21 +252,21 @@ static bool jsb_BufferAllocator_free(se::State &s) { } SE_BIND_FUNC(jsb_BufferAllocator_free); -static bool js_register_se_BufferAllocator(se::Object *obj) { +static bool js_register_se_BufferAllocator(se::Object *obj) { // NOLINT se::Class *cls = se::Class::create("NativeBufferAllocator", obj, nullptr, _SE(jsb_BufferAllocator_constructor)); cls->defineFunction("alloc", _SE(jsb_BufferAllocator_alloc)); cls->defineFunction("free", _SE(jsb_BufferAllocator_free)); cls->install(); JSBClassType::registerClass(cls); - jsb_BufferAllocator_class = cls; + jsb_BufferAllocator_class = cls; // NOLINT se::ScriptEngine::getInstance()->clearException(); return true; } -bool register_all_dop_bindings(se::Object *obj) { - // TODO: Don't make dop into jsb namespace. Currently put it into jsb namesapce just to test codes. +bool register_all_dop_bindings(se::Object *obj) { // NOLINT + // TODO(liuhang): Don't make dop into jsb namespace. Currently put it into jsb namesapce just to test codes. se::Value nsVal; if (!obj->getProperty("jsb", &nsVal)) { se::HandleObject jsobj(se::Object::createPlainObject()); @@ -250,8 +275,8 @@ bool register_all_dop_bindings(se::Object *obj) { } se::Object *ns = nsVal.toObject(); - js_register_se_BufferAllocator(ns); - js_register_se_BufferPool(ns); - js_register_se_ObjectPool(ns); + js_register_se_BufferAllocator(ns); // NOLINT + js_register_se_BufferPool(ns); // NOLINT + js_register_se_ObjectPool(ns); // NOLINT return true; } diff --git a/cocos/bindings/dop/jsb_dop.h b/cocos/bindings/dop/jsb_dop.h index ded87e44c2a..062d188d8c6 100644 --- a/cocos/bindings/dop/jsb_dop.h +++ b/cocos/bindings/dop/jsb_dop.h @@ -29,4 +29,4 @@ namespace se { class Object; } -bool register_all_dop_bindings(se::Object *obj); +bool register_all_dop_bindings(se::Object *obj); // NOLINT diff --git a/cocos/renderer/pipeline/InstancedBuffer.cpp b/cocos/renderer/pipeline/InstancedBuffer.cpp index 49d623bbdc7..db811fcc300 100644 --- a/cocos/renderer/pipeline/InstancedBuffer.cpp +++ b/cocos/renderer/pipeline/InstancedBuffer.cpp @@ -66,17 +66,19 @@ void InstancedBuffer::merge(const ModelView *model, const SubModelView *subModel } void InstancedBuffer::merge(const ModelView *model, const SubModelView *subModel, uint passIdx, gfx::Shader *shaderImplant) { - uint stride = 0; + uint stride = 0; const auto *const instancedBuffer = model->getInstancedBuffer(&stride); if (!stride) return; // we assume per-instance attributes are always present auto *sourceIA = subModel->getInputAssembler(); - auto *lightingMap = subModel->getDescriptorSet()->getTexture(LIGHTMAP_TEXTURE::BINDING); + auto *descriptorSet = subModel->getDescriptorSet(); + auto *lightingMap = descriptorSet->getTexture(LIGHTMAP_TEXTURE::BINDING); auto *shader = shaderImplant; - if (!shader) { shader = subModel->getShader(passIdx); } + if (!shader) { + shader = subModel->getShader(passIdx); + } - auto *descriptorSet = subModel->getDescriptorSet(); - for (auto & instance : _instances) { + for (auto &instance : _instances) { if (instance.ia->getIndexBuffer() != sourceIA->getIndexBuffer() || instance.count >= MAX_CAPACITY) { continue; } @@ -91,9 +93,9 @@ void InstancedBuffer::merge(const ModelView *model, const SubModelView *subModel } if (instance.count >= instance.capacity) { // resize buffers instance.capacity <<= 1; - const auto newSize = instance.stride * instance.capacity; + const auto newSize = instance.stride * instance.capacity; auto *const oldData = instance.data; - instance.data = static_cast(CC_MALLOC(newSize)); + instance.data = static_cast(CC_MALLOC(newSize)); memcpy(instance.data, oldData, instance.vb->getSize()); instance.vb->resize(newSize); CC_FREE(oldData); @@ -110,7 +112,7 @@ void InstancedBuffer::merge(const ModelView *model, const SubModelView *subModel } // Create a new instance - auto newSize = stride * INITIAL_CAPACITY; + auto newSize = stride * INITIAL_CAPACITY; auto *vb = _device->createBuffer({ gfx::BufferUsageBit::VERTEX | gfx::BufferUsageBit::TRANSFER_DST, gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, @@ -118,14 +120,14 @@ void InstancedBuffer::merge(const ModelView *model, const SubModelView *subModel static_cast(stride), }); - auto vertexBuffers = sourceIA->getVertexBuffers(); - auto attributes = sourceIA->getAttributes(); + auto vertexBuffers = sourceIA->getVertexBuffers(); + auto attributes = sourceIA->getAttributes(); auto *indexBuffer = sourceIA->getIndexBuffer(); const auto *const attributesID = model->getInstancedAttributeID(); - const auto lenght = attributesID[0]; + const auto lenght = attributesID[0]; for (uint i = 1; i <= lenght; i++) { - auto *const attribute = model->getInstancedAttribute(attributesID[i]); + auto *const attribute = ModelView::getInstancedAttribute(attributesID[i]); gfx::Attribute newAttr = {attribute->name, attribute->format, attribute->isNormalized, static_cast(vertexBuffers.size()), true, attribute->location}; attributes.emplace_back(std::move(newAttr)); } @@ -134,7 +136,7 @@ void InstancedBuffer::merge(const ModelView *model, const SubModelView *subModel memcpy(data, instancedBuffer, stride); vertexBuffers.emplace_back(vb); gfx::InputAssemblerInfo iaInfo = {attributes, vertexBuffers, indexBuffer}; - auto * ia = _device->createInputAssembler(iaInfo); + auto * ia = _device->createInputAssembler(iaInfo); InstancedItem item = {1, INITIAL_CAPACITY, vb, data, ia, stride, shader, descriptorSet, lightingMap}; _instances.emplace_back(item); _hasPendingModels = true; diff --git a/cocos/renderer/pipeline/PlanarShadowQueue.cpp b/cocos/renderer/pipeline/PlanarShadowQueue.cpp index 07ece2a5df7..3dd5b616d67 100644 --- a/cocos/renderer/pipeline/PlanarShadowQueue.cpp +++ b/cocos/renderer/pipeline/PlanarShadowQueue.cpp @@ -25,65 +25,69 @@ #include -#include "PlanarShadowQueue.h" -#include "RenderPipeline.h" #include "Define.h" #include "InstancedBuffer.h" #include "PipelineStateManager.h" +#include "PlanarShadowQueue.h" #include "RenderInstancedQueue.h" +#include "RenderPipeline.h" #include "gfx-base/GFXCommandBuffer.h" -#include "helper/SharedMemory.h" #include "gfx-base/GFXDescriptorSet.h" #include "gfx-base/GFXDevice.h" #include "gfx-base/GFXShader.h" +#include "helper/SharedMemory.h" namespace cc { namespace pipeline { PlanarShadowQueue::PlanarShadowQueue(RenderPipeline *pipeline) -:_pipeline(pipeline){ +: _pipeline(pipeline) { _instancedQueue = CC_NEW(RenderInstancedQueue); } void PlanarShadowQueue::gatherShadowPasses(Camera *camera, gfx::CommandBuffer *cmdBufferer) { clear(); - const auto sceneData = _pipeline->getPipelineSceneData(); - const auto sharedData = sceneData->getSharedData(); + auto *const sceneData = _pipeline->getPipelineSceneData(); + auto *const sharedData = sceneData->getSharedData(); const auto *shadowInfo = sharedData->getShadows(); - if (!shadowInfo->enabled || shadowInfo->getShadowType() != ShadowType::PLANAR) { return; } + if (!shadowInfo->enabled || shadowInfo->getShadowType() != ShadowType::PLANAR) { + return; + } - const auto pipelineUBO = _pipeline->getPipelineUBO(); + auto *const pipelineUBO = _pipeline->getPipelineUBO(); pipelineUBO->updateShadowUBO(camera); - const auto *scene = camera->getScene(); - const bool shadowVisible = camera->visibility & static_cast(LayerList::DEFAULT); + const auto *scene = camera->getScene(); + const bool shadowVisible = camera->visibility & static_cast(LayerList::DEFAULT); - if (!scene->getMainLight() || !shadowVisible) { return; } + if (!scene->getMainLight() || !shadowVisible) { + return; + } - const auto models = scene->getModels(); - const auto modelCount = models[0]; - auto *instancedBuffer = InstancedBuffer::get(shadowInfo->instancePass); + const auto *const models = scene->getModels(); + const auto modelCount = models[0]; + auto * instancedBuffer = InstancedBuffer::get(shadowInfo->instancePass); - uint visibility = 0, lenght = 0; + uint visibility = 0; + uint lenght = 0; for (uint i = 1; i <= modelCount; i++) { - const auto *model = scene->getModelView(models[i]); - const auto *node = model->getNode(); + const auto *model = cc::pipeline::Scene::getModelView(models[i]); + const auto *node = model->getNode(); if (model->enabled && model->castShadow) { visibility = camera->visibility; if ((model->nodeID && ((visibility & node->layer) == node->layer)) || (visibility & model->visFlags)) { - // frustum culling - if ((model->worldBoundsID) && !aabb_frustum(model->getWorldBounds(), camera->getFrustum())) { + if ((model->worldBoundsID) && !aabbFrustum(model->getWorldBounds(), camera->getFrustum())) { continue; } const auto *attributesID = model->getInstancedAttributeID(); - lenght = attributesID[0]; + lenght = attributesID[0]; if (lenght > 0) { - const auto *subModelID = model->getSubModelID(); - const auto subModelCount = subModelID[0]; + const auto *subModelID = model->getSubModelID(); + const auto subModelCount = subModelID[0]; for (uint m = 1; m <= subModelCount; ++m) { - const auto *subModel = model->getSubModelView(subModelID[m]); + const auto *subModel = cc::pipeline::ModelView::getSubModelView(subModelID[m]); instancedBuffer->merge(model, subModel, m - 1, subModel->getPlanarInstanceShader()); _instancedQueue->add(instancedBuffer); } @@ -103,26 +107,30 @@ void PlanarShadowQueue::clear() { } void PlanarShadowQueue::recordCommandBuffer(gfx::Device *device, gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer) { - const auto sceneData = _pipeline->getPipelineSceneData(); - const auto sharedData = sceneData->getSharedData(); + auto *const sceneData = _pipeline->getPipelineSceneData(); + auto *const sharedData = sceneData->getSharedData(); const auto *shadowInfo = sharedData->getShadows(); - if (!shadowInfo->enabled || shadowInfo->getShadowType() != ShadowType::PLANAR) { return; } + if (!shadowInfo->enabled || shadowInfo->getShadowType() != ShadowType::PLANAR) { + return; + } _instancedQueue->recordCommandBuffer(device, renderPass, cmdBuffer); - if (_pendingModels.empty()) { return; } + if (_pendingModels.empty()) { + return; + } const auto *pass = shadowInfo->getPlanarShadowPass(); cmdBuffer->bindDescriptorSet(MATERIAL_SET, pass->getDescriptorSet()); - for (auto model : _pendingModels) { - const auto subModelID = model->getSubModelID(); - const auto subModelCount = subModelID[0]; + for (const auto *model : _pendingModels) { + const auto *const subModelID = model->getSubModelID(); + const auto subModelCount = subModelID[0]; for (unsigned m = 1; m <= subModelCount; ++m) { - const auto subModel = model->getSubModelView(subModelID[m]); - const auto shader = subModel->getPlanarShader(); - const auto ia = subModel->getInputAssembler(); - const auto pso = PipelineStateManager::getOrCreatePipelineState(pass, shader, ia, renderPass); + const auto *const subModel = cc::pipeline::ModelView::getSubModelView(subModelID[m]); + auto *const shader = subModel->getPlanarShader(); + auto *const ia = subModel->getInputAssembler(); + auto *const pso = PipelineStateManager::getOrCreatePipelineState(pass, shader, ia, renderPass); cmdBuffer->bindPipelineState(pso); cmdBuffer->bindDescriptorSet(LOCAL_SET, subModel->getDescriptorSet()); @@ -135,5 +143,5 @@ void PlanarShadowQueue::recordCommandBuffer(gfx::Device *device, gfx::RenderPass void PlanarShadowQueue::destroy() { CC_SAFE_DELETE(_instancedQueue); } -} +} // namespace pipeline } // namespace cc diff --git a/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp b/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp index 76b7a28b385..4f3831b9d68 100644 --- a/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp +++ b/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp @@ -97,12 +97,12 @@ void RenderAdditiveLightQueue::recordCommandBuffer(gfx::Device *device, gfx::Ren for (const auto &lightPass : _lightPasses) { const auto *const subModel = lightPass.subModel; const auto *const pass = lightPass.pass; - const auto &dynamicOffsets = lightPass.dynamicOffsets; - auto * shader = lightPass.shader; - const auto lights = lightPass.lights; - auto * ia = subModel->getInputAssembler(); - auto * pso = PipelineStateManager::getOrCreatePipelineState(pass, shader, ia, renderPass); - auto * descriptorSet = subModel->getDescriptorSet(); + const auto & dynamicOffsets = lightPass.dynamicOffsets; + auto * shader = lightPass.shader; + const auto lights = lightPass.lights; + auto * ia = subModel->getInputAssembler(); + auto * pso = PipelineStateManager::getOrCreatePipelineState(pass, shader, ia, renderPass); + auto * descriptorSet = subModel->getDescriptorSet(); cmdBuffer->bindPipelineState(pso); cmdBuffer->bindDescriptorSet(MATERIAL_SET, pass->getDescriptorSet()); @@ -139,7 +139,7 @@ void RenderAdditiveLightQueue::gatherLightPasses(const Camera *camera, gfx::Comm _lightIndices.clear(); for (size_t i = 0; i < _validLights.size(); i++) { const auto *const light = _validLights[i]; - const bool isCulled = cullingLight(light, model); + const bool isCulled = cullingLight(light, model); if (!isCulled) { _lightIndices.emplace_back(i); } @@ -147,7 +147,7 @@ void RenderAdditiveLightQueue::gatherLightPasses(const Camera *camera, gfx::Comm if (_lightIndices.empty()) continue; const auto *const subModelArrayID = model->getSubModelID(); - const auto subModelCount = subModelArrayID[0]; + const auto subModelCount = subModelArrayID[0]; for (unsigned j = 1; j <= subModelCount; j++) { const auto lightPassIdx = lightPassIndices[j - 1]; if (lightPassIdx == UINT_MAX) continue; @@ -192,8 +192,8 @@ void RenderAdditiveLightQueue::clear() { void RenderAdditiveLightQueue::gatherValidLights(const Camera *camera) { const auto *const scene = camera->getScene(); const auto *const sphereLightArrayID = scene->getSphereLightArrayID(); - auto count = sphereLightArrayID ? sphereLightArrayID[0] : 0; - Sphere sphere; + auto count = sphereLightArrayID ? sphereLightArrayID[0] : 0; + Sphere sphere; for (unsigned i = 1; i <= count; i++) { const auto *const light = scene->getSphereLight(sphereLightArrayID[i]); sphere.setCenter(light->position); @@ -204,7 +204,7 @@ void RenderAdditiveLightQueue::gatherValidLights(const Camera *camera) { } } const auto *const spotLightArrayID = scene->getSpotLightArrayID(); - count = spotLightArrayID ? spotLightArrayID[0] : 0; + count = spotLightArrayID ? spotLightArrayID[0] : 0; for (unsigned i = 1; i <= count; i++) { const auto *const light = scene->getSpotLight(spotLightArrayID[i]); sphere.setCenter(light->position); @@ -219,9 +219,9 @@ void RenderAdditiveLightQueue::gatherValidLights(const Camera *camera) { bool RenderAdditiveLightQueue::cullingLight(const Light *light, const ModelView *model) { switch (light->getType()) { case LightType::SPHERE: - return model->worldBoundsID && !aabb_aabb(model->getWorldBounds(), light->getAABB()); + return model->worldBoundsID && !aabbAabb(model->getWorldBounds(), light->getAABB()); case LightType::SPOT: - return model->worldBoundsID && (!aabb_aabb(model->getWorldBounds(), light->getAABB()) || !aabb_frustum(model->getWorldBounds(), light->getFrustum())); + return model->worldBoundsID && (!aabbAabb(model->getWorldBounds(), light->getAABB()) || !aabbFrustum(model->getWorldBounds(), light->getFrustum())); default: return false; } } @@ -260,8 +260,8 @@ void RenderAdditiveLightQueue::addRenderQueue(const PassView *pass, const SubMod } void RenderAdditiveLightQueue::updateUBOs(const Camera *camera, gfx::CommandBuffer *cmdBuffer) { - const auto exposure = camera->exposure; - const auto validLightCount = _validLights.size(); + const auto exposure = camera->exposure; + const auto validLightCount = _validLights.size(); auto *const sceneData = _pipeline->getPipelineSceneData(); auto *const sharedData = sceneData->getSharedData(); if (validLightCount > _lightBufferCount) { @@ -327,9 +327,9 @@ void RenderAdditiveLightQueue::updateUBOs(const Camera *camera, gfx::CommandBuff void RenderAdditiveLightQueue::updateLightDescriptorSet(const Camera *camera, gfx::CommandBuffer *cmdBuffer) { auto *const sceneData = _pipeline->getPipelineSceneData(); - auto * shadowInfo = sceneData->getSharedData()->getShadows(); + auto * shadowInfo = sceneData->getSharedData()->getShadows(); const auto *const scene = camera->getScene(); - const Light *mainLight = nullptr; + const Light * mainLight = nullptr; if (scene->mainLightID) mainLight = scene->getMainLight(); for (const auto *light : _validLights) { @@ -398,10 +398,10 @@ bool RenderAdditiveLightQueue::getLightPassIndex(const ModelView *model, vector< bool hasValidLightPass = false; const auto *const subModelArrayID = model->getSubModelID(); - const auto count = subModelArrayID[0]; + const auto count = subModelArrayID[0]; for (unsigned i = 1; i <= count; i++) { const auto *const subModel = model->getSubModelView(subModelArrayID[i]); - uint lightPassIndex = UINT_MAX; + uint lightPassIndex = UINT_MAX; for (unsigned passIdx = 0; passIdx < subModel->passCount; passIdx++) { const auto *const pass = subModel->getPassView(passIdx); if (pass->phase == _phaseID) { diff --git a/cocos/renderer/pipeline/SceneCulling.cpp b/cocos/renderer/pipeline/SceneCulling.cpp index a26a7e8af11..a81366cbab0 100644 --- a/cocos/renderer/pipeline/SceneCulling.cpp +++ b/cocos/renderer/pipeline/SceneCulling.cpp @@ -27,11 +27,11 @@ #include #include "Define.h" -#include "helper/SharedMemory.h" #include "RenderPipeline.h" #include "SceneCulling.h" #include "gfx-base/GFXBuffer.h" #include "gfx-base/GFXDescriptorSet.h" +#include "helper/SharedMemory.h" #include "math/Quaternion.h" #include "platform/Application.h" @@ -43,8 +43,8 @@ AABB castWorldBounds; RenderObject genRenderObject(const ModelView *model, const Camera *camera) { float depth = 0; if (model->nodeID) { - const auto node = model->getTransform(); - cc::Vec3 position; + const auto *const node = model->getTransform(); + cc::Vec3 position; cc::Vec3::subtract(node->worldPosition, camera->position, &position); depth = position.dot(camera->forward); } @@ -64,76 +64,76 @@ void getShadowWorldMatrix(const Sphere *sphere, const cc::Vec4 &rotation, const } void updateSphereLight(Shadows *shadows, const Light *light, std::array &shadowUBO) { - const auto node = light->getNode(); + const auto *const node = light->getNode(); if (!node->flagsChanged && !shadows->dirty) { return; } - shadows->dirty = false; - const auto position = node->worldPosition; - const auto &normal = shadows->normal; - const auto distance = shadows->distance + 0.001f; // avoid z-fighting - const auto NdL = normal.dot(position); - const auto lx = position.x; - const auto ly = position.y; - const auto lz = position.z; - const auto nx = normal.x; - const auto ny = normal.y; - const auto nz = normal.z; - auto &matLight = shadows->matLight; - matLight.m[0] = NdL - distance - lx * nx; - matLight.m[1] = -ly * nx; - matLight.m[2] = -lz * nx; - matLight.m[3] = -nx; - matLight.m[4] = -lx * ny; - matLight.m[5] = NdL - distance - ly * ny; - matLight.m[6] = -lz * ny; - matLight.m[7] = -ny; - matLight.m[8] = -lx * nz; - matLight.m[9] = -ly * nz; - matLight.m[10] = NdL - distance - lz * nz; - matLight.m[11] = -nz; - matLight.m[12] = lx * distance; - matLight.m[13] = ly * distance; - matLight.m[14] = lz * distance; - matLight.m[15] = NdL; + shadows->dirty = false; + const auto position = node->worldPosition; + const auto &normal = shadows->normal; + const auto distance = shadows->distance + 0.001F; // avoid z-fighting + const auto ndL = normal.dot(position); + const auto lx = position.x; + const auto ly = position.y; + const auto lz = position.z; + const auto nx = normal.x; + const auto ny = normal.y; + const auto nz = normal.z; + auto & matLight = shadows->matLight; + matLight.m[0] = ndL - distance - lx * nx; + matLight.m[1] = -ly * nx; + matLight.m[2] = -lz * nx; + matLight.m[3] = -nx; + matLight.m[4] = -lx * ny; + matLight.m[5] = ndL - distance - ly * ny; + matLight.m[6] = -lz * ny; + matLight.m[7] = -ny; + matLight.m[8] = -lx * nz; + matLight.m[9] = -ly * nz; + matLight.m[10] = ndL - distance - lz * nz; + matLight.m[11] = -nz; + matLight.m[12] = lx * distance; + matLight.m[13] = ly * distance; + matLight.m[14] = lz * distance; + matLight.m[15] = ndL; memcpy(shadowUBO.data() + UBOShadow::MAT_LIGHT_PLANE_PROJ_OFFSET, matLight.m, sizeof(matLight)); } void updateDirLight(Shadows *shadows, const Light *light, std::array &shadowUBO) { - const auto node = light->getNode(); - const auto rotation = node->worldRotation; - Quaternion _qt(rotation.x, rotation.y, rotation.z, rotation.w); - Vec3 forward(0, 0, -1.0f); - forward.transformQuat(_qt); - const auto &normal = shadows->normal; - const auto distance = shadows->distance + 0.001f; // avoid z-fighting - const auto NdL = normal.dot(forward); - const auto scale = 1.0f / NdL; - const auto lx = forward.x * scale; - const auto ly = forward.y * scale; - const auto lz = forward.z * scale; - const auto nx = normal.x; - const auto ny = normal.y; - const auto nz = normal.z; - auto &matLight = shadows->matLight; - matLight.m[0] = 1 - nx * lx; - matLight.m[1] = -nx * ly; - matLight.m[2] = -nx * lz; - matLight.m[3] = 0; - matLight.m[4] = -ny * lx; - matLight.m[5] = 1 - ny * ly; - matLight.m[6] = -ny * lz; - matLight.m[7] = 0; - matLight.m[8] = -nz * lx; - matLight.m[9] = -nz * ly; - matLight.m[10] = 1 - nz * lz; - matLight.m[11] = 0; - matLight.m[12] = lx * distance; - matLight.m[13] = ly * distance; - matLight.m[14] = lz * distance; - matLight.m[15] = 1; + const auto *const node = light->getNode(); + const auto rotation = node->worldRotation; + Quaternion qt(rotation.x, rotation.y, rotation.z, rotation.w); + Vec3 forward(0, 0, -1.0F); + forward.transformQuat(qt); + const auto &normal = shadows->normal; + const auto distance = shadows->distance + 0.001F; // avoid z-fighting + const auto ndL = normal.dot(forward); + const auto scale = 1.0F / ndL; + const auto lx = forward.x * scale; + const auto ly = forward.y * scale; + const auto lz = forward.z * scale; + const auto nx = normal.x; + const auto ny = normal.y; + const auto nz = normal.z; + auto & matLight = shadows->matLight; + matLight.m[0] = 1 - nx * lx; + matLight.m[1] = -nx * ly; + matLight.m[2] = -nx * lz; + matLight.m[3] = 0; + matLight.m[4] = -ny * lx; + matLight.m[5] = 1 - ny * ly; + matLight.m[6] = -ny * lz; + matLight.m[7] = 0; + matLight.m[8] = -nz * lx; + matLight.m[9] = -nz * ly; + matLight.m[10] = 1 - nz * lz; + matLight.m[11] = 0; + matLight.m[12] = lx * distance; + matLight.m[13] = ly * distance; + matLight.m[14] = lz * distance; + matLight.m[15] = 1; memcpy(shadowUBO.data() + UBOShadow::MAT_LIGHT_PLANE_PROJ_OFFSET, matLight.m, sizeof(matLight)); memcpy(shadowUBO.data() + UBOShadow::SHADOW_COLOR_OFFSET, &shadows->color, sizeof(Vec4)); @@ -141,16 +141,16 @@ void updateDirLight(Shadows *shadows, const Light *light, std::array &validLights) { validLights.clear(); - auto *sphere = CC_NEW(Sphere); - const auto scene = camera->getScene(); - const Light *mainLight = nullptr; + auto * sphere = CC_NEW(Sphere); + const auto *const scene = camera->getScene(); + const Light * mainLight = nullptr; if (scene->mainLightID) mainLight = scene->getMainLight(); validLights.emplace_back(mainLight); - const auto spotLightArrayID = scene->getSpotLightArrayID(); - const auto count = spotLightArrayID ? spotLightArrayID[0] : 0; + const auto *const spotLightArrayID = scene->getSpotLightArrayID(); + const auto count = spotLightArrayID ? spotLightArrayID[0] : 0; for (uint32_t i = 1; i <= count; ++i) { - const auto *spotLight = scene->getSpotLight(spotLightArrayID[i]); + const auto *spotLight = cc::pipeline::Scene::getSpotLight(spotLightArrayID[i]); sphere->center.set(spotLight->position); sphere->radius = spotLight->range; if (sphere->interset(*camera->getFrustum())) { @@ -162,28 +162,28 @@ void lightCollecting(Camera *camera, std::vector &validLights) { } void shadowCollecting(RenderPipeline *pipeline, Camera *camera) { - const auto scene = camera->getScene(); - const auto sceneData = pipeline->getPipelineSceneData(); + const auto *const scene = camera->getScene(); + auto *const sceneData = pipeline->getPipelineSceneData(); castBoundsInitialized = false; RenderObjectList shadowObjects; - const auto models = scene->getModels(); - const auto modelCount = models[0]; + const auto *const models = scene->getModels(); + const auto modelCount = models[0]; for (size_t i = 1; i <= modelCount; i++) { - const auto model = scene->getModelView(models[i]); + const auto *const model = cc::pipeline::Scene::getModelView(models[i]); // filter model by view visibility if (model->enabled) { - const auto visibility = camera->visibility; - const auto node = model->getNode(); + const auto visibility = camera->visibility; + const auto *const node = model->getNode(); if ((model->nodeID && ((visibility & node->layer) == node->layer)) || (visibility & model->visFlags)) { // shadow render Object if (model->castShadow && model->getWorldBounds()) { if (!castBoundsInitialized) { - castWorldBounds = *model->getWorldBounds(); + castWorldBounds = *model->getWorldBounds(); castBoundsInitialized = true; } castWorldBounds.merge(*model->getWorldBounds()); @@ -199,11 +199,11 @@ void shadowCollecting(RenderPipeline *pipeline, Camera *camera) { } void sceneCulling(RenderPipeline *pipeline, Camera *camera) { - const auto sceneData = pipeline->getPipelineSceneData(); - const auto sharedData = sceneData->getSharedData(); - const auto shadows = sharedData->getShadows(); - const auto skyBox = sharedData->getSkybox(); - const auto scene = camera->getScene(); + auto *const sceneData = pipeline->getPipelineSceneData(); + auto *const sharedData = sceneData->getSharedData(); + auto *const shadows = sharedData->getShadows(); + auto *const skyBox = sharedData->getSkybox(); + const auto *const scene = camera->getScene(); const Light *mainLight = nullptr; if (scene->mainLightID) mainLight = scene->getMainLight(); @@ -213,20 +213,19 @@ void sceneCulling(RenderPipeline *pipeline, Camera *camera) { renderObjects.emplace_back(genRenderObject(skyBox->getModel(), camera)); } - const auto models = scene->getModels(); - const auto modelCount = models[0]; + const auto *const models = scene->getModels(); + const auto modelCount = models[0]; for (size_t i = 1; i <= modelCount; i++) { - const auto model = scene->getModelView(models[i]); + const auto *const model = cc::pipeline::Scene::getModelView(models[i]); // filter model by view visibility if (model->enabled) { - const auto visibility = camera->visibility; - const auto node = model->getNode(); + const auto visibility = camera->visibility; + const auto *const node = model->getNode(); if ((model->nodeID && ((visibility & node->layer) == node->layer)) || (visibility & model->visFlags)) { - // frustum culling - if ((model->worldBoundsID) && !aabb_frustum(model->getWorldBounds(), camera->getFrustum())) { + if ((model->worldBoundsID) && !aabbFrustum(model->getWorldBounds(), camera->getFrustum())) { continue; } diff --git a/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp b/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp index 15386149f49..f0030fada99 100644 --- a/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp +++ b/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp @@ -28,34 +28,34 @@ #include "BatchedBuffer.h" #include "Define.h" #include "InstancedBuffer.h" +#include "PipelineSceneData.h" #include "PipelineStateManager.h" +#include "PipelineUBO.h" #include "RenderBatchedQueue.h" #include "RenderInstancedQueue.h" +#include "SceneCulling.h" #include "ShadowMapBatchedQueue.h" #include "forward/ForwardPipeline.h" -#include "SceneCulling.h" #include "gfx-base/GFXCommandBuffer.h" #include "gfx-base/GFXDescriptorSet.h" #include "gfx-base/GFXDevice.h" #include "helper/SharedMemory.h" -#include "PipelineSceneData.h" -#include "PipelineUBO.h" namespace cc { namespace pipeline { ShadowMapBatchedQueue::ShadowMapBatchedQueue(ForwardPipeline *pipeline) : _phaseID(getPhaseID("shadow-caster")) { - _pipeline = pipeline; - _buffer = pipeline->getDescriptorSet()->getBuffer(UBOShadow::BINDING); + _pipeline = pipeline; + _buffer = pipeline->getDescriptorSet()->getBuffer(UBOShadow::BINDING); _instancedQueue = CC_NEW(RenderInstancedQueue); - _batchedQueue = CC_NEW(RenderBatchedQueue); + _batchedQueue = CC_NEW(RenderBatchedQueue); } void ShadowMapBatchedQueue::gatherLightPasses(const Light *light, gfx::CommandBuffer *cmdBufferer) { clear(); - const auto *sceneData = _pipeline->getPipelineSceneData(); - const auto *shadowInfo = sceneData->getSharedData()->getShadows(); + const auto *sceneData = _pipeline->getPipelineSceneData(); + const auto *shadowInfo = sceneData->getSharedData()->getShadows(); const auto &shadowObjects = sceneData->getShadowObjects(); if (light && shadowInfo->enabled && shadowInfo->getShadowType() == ShadowType::SHADOWMAP) { _pipeline->getPipelineUBO()->updateShadowUBOLight(light); @@ -69,8 +69,8 @@ void ShadowMapBatchedQueue::gatherLightPasses(const Light *light, gfx::CommandBu break; case LightType::SPOT: if (model->getWorldBounds() && - (aabb_aabb(model->getWorldBounds(), light->getAABB()) || - aabb_frustum(model->getWorldBounds(), light->getFrustum()))) { + (aabbAabb(model->getWorldBounds(), light->getAABB()) || + aabbFrustum(model->getWorldBounds(), light->getFrustum()))) { add(model, cmdBufferer); } break; @@ -95,12 +95,12 @@ void ShadowMapBatchedQueue::add(const ModelView *model, gfx::CommandBuffer *cmdB return; } - const auto subModelID = model->getSubModelID(); - const auto subModelCount = subModelID[0]; + const auto *const subModelID = model->getSubModelID(); + const auto subModelCount = subModelID[0]; for (unsigned m = 1; m <= subModelCount; ++m) { - const auto subModel = model->getSubModelView(subModelID[m]); - const auto pass = subModel->getPassView(shadowPassIdx); - const auto batchingScheme = pass->getBatchingScheme(); + const auto *const subModel = cc::pipeline::ModelView::getSubModelView(subModelID[m]); + const auto *const pass = subModel->getPassView(shadowPassIdx); + const auto batchingScheme = pass->getBatchingScheme(); if (batchingScheme == BatchingSchemes::INSTANCING) { auto *instancedBuffer = InstancedBuffer::get(subModel->passID[shadowPassIdx]); @@ -126,11 +126,11 @@ void ShadowMapBatchedQueue::recordCommandBuffer(gfx::Device *device, gfx::Render _batchedQueue->recordCommandBuffer(device, renderPass, cmdBuffer); for (size_t i = 0; i < _subModels.size(); i++) { - const auto subModel = _subModels[i]; - const auto shader = _shaders[i]; - const auto pass = _passes[i]; - const auto ia = subModel->getInputAssembler(); - const auto pso = PipelineStateManager::getOrCreatePipelineState(pass, shader, ia, renderPass); + const auto *const subModel = _subModels[i]; + auto *const shader = _shaders[i]; + const auto *const pass = _passes[i]; + auto *const ia = subModel->getInputAssembler(); + auto *const pso = PipelineStateManager::getOrCreatePipelineState(pass, shader, ia, renderPass); cmdBuffer->bindPipelineState(pso); cmdBuffer->bindDescriptorSet(MATERIAL_SET, pass->getDescriptorSet()); @@ -149,14 +149,14 @@ void ShadowMapBatchedQueue::destroy() { } int ShadowMapBatchedQueue::getShadowPassIndex(const ModelView *model) const { - const auto subModelArrayID = model->getSubModelID(); - const auto count = subModelArrayID[0]; + const auto *const subModelArrayID = model->getSubModelID(); + const auto count = subModelArrayID[0]; for (unsigned i = 1; i <= count; i++) { - const auto subModel = model->getSubModelView(subModelArrayID[i]); + const auto *const subModel = cc::pipeline::ModelView::getSubModelView(subModelArrayID[i]); for (unsigned passIdx = 0; passIdx < subModel->passCount; passIdx++) { - const auto pass = subModel->getPassView(passIdx); + const auto *const pass = subModel->getPassView(passIdx); if (pass->phase == _phaseID) { - return passIdx; + return static_cast(passIdx); } } } diff --git a/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp b/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp index 3735ebbe88f..44f4b763475 100644 --- a/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp +++ b/cocos/renderer/pipeline/deferred/DeferredPipeline.cpp @@ -43,14 +43,14 @@ namespace cc { namespace pipeline { namespace { -#define TO_VEC3(dst, src, offset) \ - dst[offset] = (src).x; \ - (dst)[(offset) + 1] = (src).y; \ +#define TO_VEC3(dst, src, offset) \ + dst[offset] = (src).x; \ + (dst)[(offset) + 1] = (src).y; \ (dst)[(offset) + 2] = (src).z; -#define TO_VEC4(dst, src, offset) \ - dst[offset] = (src).x; \ - (dst)[(offset) + 1] = (src).y; \ - (dst)[(offset) + 2] = (src).z; \ +#define TO_VEC4(dst, src, offset) \ + dst[offset] = (src).x; \ + (dst)[(offset) + 1] = (src).y; \ + (dst)[(offset) + 2] = (src).z; \ (dst)[(offset) + 3] = (src).w; } // namespace @@ -59,7 +59,7 @@ gfx::RenderPass *DeferredPipeline::getOrCreateRenderPass(gfx::ClearFlags clearFl return _renderPasses[clearFlags]; } - auto * device = gfx::Device::getInstance(); + auto * device = gfx::Device::getInstance(); gfx::ColorAttachment colorAttachment; gfx::DepthStencilAttachment depthStencilAttachment; colorAttachment.format = device->getColorFormat(); @@ -82,7 +82,7 @@ gfx::RenderPass *DeferredPipeline::getOrCreateRenderPass(gfx::ClearFlags clearFl depthStencilAttachment.beginAccesses = {gfx::AccessType::DEPTH_STENCIL_ATTACHMENT_WRITE}; } - auto *renderPass = device->createRenderPass({ + auto *renderPass = device->createRenderPass({ {colorAttachment}, depthStencilAttachment, }); @@ -144,17 +144,17 @@ void DeferredPipeline::render(const vector &cameras) { } void DeferredPipeline::updateQuadVertexData(const gfx::Rect &renderArea) { - if (_lastUsedRenderArea == renderArea) { - return; - } + if (_lastUsedRenderArea == renderArea) { + return; + } - _lastUsedRenderArea = renderArea; - float vbData[16] = {0}; - genQuadVertexData(gfx::SurfaceTransform::IDENTITY, renderArea, vbData); - _commandBuffers[0]->updateBuffer(_quadVBOffscreen, vbData); + _lastUsedRenderArea = renderArea; + float vbData[16] = {0}; + genQuadVertexData(gfx::SurfaceTransform::IDENTITY, renderArea, vbData); + _commandBuffers[0]->updateBuffer(_quadVBOffscreen, vbData); - genQuadVertexData(_device->getSurfaceTransform(), renderArea, vbData); - _commandBuffers[0]->updateBuffer(_quadVBOnscreen, vbData); + genQuadVertexData(_device->getSurfaceTransform(), renderArea, vbData); + _commandBuffers[0]->updateBuffer(_quadVBOnscreen, vbData); } void DeferredPipeline::genQuadVertexData(gfx::SurfaceTransform surfaceTransform, const gfx::Rect &renderArea, float *vbData) { @@ -163,13 +163,13 @@ void DeferredPipeline::genQuadVertexData(gfx::SurfaceTransform surfaceTransform, float minY = float(renderArea.y) / _device->getHeight(); float maxY = float(renderArea.y + renderArea.height) / _device->getHeight(); - int n = 0; + int n = 0; switch (surfaceTransform) { case (gfx::SurfaceTransform::IDENTITY): n = 0; vbData[n++] = -1.0; vbData[n++] = -1.0; - vbData[n++] = minX; // uv + vbData[n++] = minX; // uv vbData[n++] = maxY; vbData[n++] = 1.0; vbData[n++] = -1.0; @@ -188,7 +188,7 @@ void DeferredPipeline::genQuadVertexData(gfx::SurfaceTransform surfaceTransform, n = 0; vbData[n++] = -1.0; vbData[n++] = -1.0; - vbData[n++] = maxX; // uv + vbData[n++] = maxX; // uv vbData[n++] = maxY; vbData[n++] = 1.0; vbData[n++] = -1.0; @@ -207,7 +207,7 @@ void DeferredPipeline::genQuadVertexData(gfx::SurfaceTransform surfaceTransform, n = 0; vbData[n++] = -1.0; vbData[n++] = -1.0; - vbData[n++] = minX; // uv + vbData[n++] = minX; // uv vbData[n++] = minY; vbData[n++] = 1.0; vbData[n++] = -1.0; @@ -226,7 +226,7 @@ void DeferredPipeline::genQuadVertexData(gfx::SurfaceTransform surfaceTransform, n = 0; vbData[n++] = -1.0; vbData[n++] = -1.0; - vbData[n++] = minX; // uv + vbData[n++] = minX; // uv vbData[n++] = minY; vbData[n++] = 1.0; vbData[n++] = -1.0; @@ -253,7 +253,7 @@ bool DeferredPipeline::createQuadInputAssembler(gfx::Buffer **quadIB, gfx::Buffe if (*quadVB == nullptr) { *quadVB = _device->createBuffer({gfx::BufferUsageBit::VERTEX | gfx::BufferUsageBit::TRANSFER_DST, - gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, vbSize, vbStride}); + gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, vbSize, vbStride}); } if (*quadVB == nullptr) { @@ -265,7 +265,7 @@ bool DeferredPipeline::createQuadInputAssembler(gfx::Buffer **quadIB, gfx::Buffe uint ibSize = ibStride * 6; if (*quadIB == nullptr) { *quadIB = _device->createBuffer({gfx::BufferUsageBit::INDEX | gfx::BufferUsageBit::TRANSFER_DST, - gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, ibSize, ibStride}); + gfx::MemoryUsageBit::HOST | gfx::MemoryUsageBit::DEVICE, ibSize, ibStride}); } if (*quadIB == nullptr) { @@ -281,7 +281,7 @@ bool DeferredPipeline::createQuadInputAssembler(gfx::Buffer **quadIB, gfx::Buffe info.attributes.push_back({"a_texCoord", gfx::Format::RG32F}); info.vertexBuffers.push_back(*quadVB); info.indexBuffer = *quadIB; - *quadIA = _device->createInputAssembler(info); + *quadIA = _device->createInputAssembler(info); return (*quadIA) != nullptr; } @@ -343,7 +343,7 @@ bool DeferredPipeline::activeRenderer() { gfx::Address::CLAMP, gfx::Address::CLAMP, }; - const auto samplerHash = SamplerLib::genSamplerHash(info); + const auto samplerHash = SamplerLib::genSamplerHash(info); auto *const sampler = SamplerLib::getSampler(samplerHash); // Main light sampler binding diff --git a/cocos/renderer/pipeline/deferred/DeferredPipeline.h b/cocos/renderer/pipeline/deferred/DeferredPipeline.h index 96687d88cd0..f512a438aae 100644 --- a/cocos/renderer/pipeline/deferred/DeferredPipeline.h +++ b/cocos/renderer/pipeline/deferred/DeferredPipeline.h @@ -27,10 +27,10 @@ #include -#include "pipeline/RenderPipeline.h" -#include "pipeline/helper/SharedMemory.h" #include "gfx-base/GFXBuffer.h" #include "gfx-base/GFXInputAssembler.h" +#include "pipeline/RenderPipeline.h" +#include "pipeline/helper/SharedMemory.h" namespace cc { namespace pipeline { @@ -45,16 +45,16 @@ struct Sphere; struct Camera; struct CC_DLL DeferredRenderData { - gfx::TextureList gbufferRenderTargets; - gfx::Framebuffer *gbufferFrameBuffer = nullptr; - gfx::Framebuffer *lightingFrameBuff = nullptr; - gfx::Texture *lightingRenderTarget = nullptr; - gfx::Texture *depthTex = nullptr; + gfx::TextureList gbufferRenderTargets; + gfx::Framebuffer *gbufferFrameBuffer = nullptr; + gfx::Framebuffer *lightingFrameBuff = nullptr; + gfx::Texture * lightingRenderTarget = nullptr; + gfx::Texture * depthTex = nullptr; }; class CC_DLL DeferredPipeline : public RenderPipeline { public: - DeferredPipeline() = default; + DeferredPipeline() = default; ~DeferredPipeline() override = default; bool initialize(const RenderPipelineInfo &info) override; @@ -70,12 +70,12 @@ class CC_DLL DeferredPipeline : public RenderPipeline { CC_INLINE const gfx::BufferList &getLightBuffers() const { return _lightBuffers; } CC_INLINE const UintList &getLightIndexOffsets() const { return _lightIndexOffsets; } CC_INLINE const UintList &getLightIndices() const { return _lightIndices; } - gfx::InputAssembler *getQuadIAOnScreen(){return _quadIAOnscreen;} - gfx::InputAssembler *getQuadIAOffScreen(){return _quadIAOffscreen;} - gfx::Rect getRenderArea(Camera *camera, bool onScreen); - CC_INLINE DeferredRenderData *getDeferredRenderData(){return _deferredRenderData; }; - void updateQuadVertexData(const gfx::Rect &renderArea); - void genQuadVertexData(gfx::SurfaceTransform surfaceTransform, const gfx::Rect &renderArea, float *data); + gfx::InputAssembler * getQuadIAOnScreen() { return _quadIAOnscreen; } + gfx::InputAssembler * getQuadIAOffScreen() { return _quadIAOffscreen; } + gfx::Rect getRenderArea(Camera *camera, bool onScreen); + CC_INLINE DeferredRenderData *getDeferredRenderData() { return _deferredRenderData; }; + void updateQuadVertexData(const gfx::Rect &renderArea); + void genQuadVertexData(gfx::SurfaceTransform surfaceTransform, const gfx::Rect &renderArea, float *data); private: bool activeRenderer(); @@ -84,27 +84,26 @@ class CC_DLL DeferredPipeline : public RenderPipeline { void destroyDeferredData(); void generateDeferredRenderData(); - - gfx::Buffer *_lightsUBO = nullptr; - LightList _validLights; - gfx::BufferList _lightBuffers; - UintList _lightIndexOffsets; - UintList _lightIndices; + gfx::Buffer * _lightsUBO = nullptr; + LightList _validLights; + gfx::BufferList _lightBuffers; + UintList _lightIndexOffsets; + UintList _lightIndices; map _renderPasses; - gfx::Rect _lastUsedRenderArea; + gfx::Rect _lastUsedRenderArea; // light stage - gfx::Buffer *_quadIB = nullptr; - gfx::Buffer *_quadVBOnscreen = nullptr; - gfx::Buffer *_quadVBOffscreen = nullptr; - gfx::InputAssembler *_quadIAOnscreen = nullptr; + gfx::Buffer * _quadIB = nullptr; + gfx::Buffer * _quadVBOnscreen = nullptr; + gfx::Buffer * _quadVBOffscreen = nullptr; + gfx::InputAssembler *_quadIAOnscreen = nullptr; gfx::InputAssembler *_quadIAOffscreen = nullptr; DeferredRenderData *_deferredRenderData = nullptr; - gfx::RenderPass *_gbufferRenderPass = nullptr; - gfx::RenderPass *_lightingRenderPass = nullptr; - uint _width; - uint _height; + gfx::RenderPass * _gbufferRenderPass = nullptr; + gfx::RenderPass * _lightingRenderPass = nullptr; + uint _width; + uint _height; }; } // namespace pipeline diff --git a/cocos/renderer/pipeline/helper/SharedMemory.cpp b/cocos/renderer/pipeline/helper/SharedMemory.cpp index 372857b51e8..50026864967 100644 --- a/cocos/renderer/pipeline/helper/SharedMemory.cpp +++ b/cocos/renderer/pipeline/helper/SharedMemory.cpp @@ -30,27 +30,27 @@ namespace cc { namespace pipeline { -const se::PoolType ModelView::type = se::PoolType::MODEL; -const se::PoolType SubModelView::type = se::PoolType::SUB_MODEL; -const se::PoolType PassView::type = se::PoolType::PASS; -const se::PoolType Camera::type = se::PoolType::CAMERA; -const se::PoolType AABB::type = se::PoolType::AABB; -const se::PoolType Frustum::type = se::PoolType::FRUSTUM; -const se::PoolType Scene::type = se::PoolType::SCENE; -const se::PoolType Light::type = se::PoolType::LIGHT; -const se::PoolType Ambient::type = se::PoolType::AMBIENT; -const se::PoolType Fog::type = se::PoolType::FOG; -const se::PoolType Skybox::type = se::PoolType::SKYBOX; -const se::PoolType InstancedAttributeView::type = se::PoolType::INSTANCED_ATTRIBUTE; -const se::PoolType FlatBufferView::type = se::PoolType::FLAT_BUFFER; -const se::PoolType RenderingSubMesh::type = se::PoolType::SUB_MESH; -const se::PoolType Node::type = se::PoolType::NODE; -const se::PoolType Root::type = se::PoolType::ROOT; -const se::PoolType RenderWindow::type = se::PoolType::RENDER_WINDOW; -const se::PoolType Shadows::type = se::PoolType::SHADOW; -const se::PoolType Sphere::type = se::PoolType::SPHERE; -const se::PoolType UIBatch::type = se::PoolType::UI_BATCH; -const se::PoolType PipelineSharedSceneData::type = se::PoolType::PIPELINE_SHARED_SCENE_DATA; +const se::PoolType ModelView::TYPE = se::PoolType::MODEL; +const se::PoolType SubModelView::TYPE = se::PoolType::SUB_MODEL; +const se::PoolType PassView::TYPE = se::PoolType::PASS; +const se::PoolType Camera::TYPE = se::PoolType::CAMERA; +const se::PoolType AABB::TYPE = se::PoolType::AABB; +const se::PoolType Frustum::TYPE = se::PoolType::FRUSTUM; +const se::PoolType Scene::TYPE = se::PoolType::SCENE; +const se::PoolType Light::TYPE = se::PoolType::LIGHT; +const se::PoolType Ambient::TYPE = se::PoolType::AMBIENT; +const se::PoolType Fog::TYPE = se::PoolType::FOG; +const se::PoolType Skybox::TYPE = se::PoolType::SKYBOX; +const se::PoolType InstancedAttributeView::TYPE = se::PoolType::INSTANCED_ATTRIBUTE; +const se::PoolType FlatBufferView::TYPE = se::PoolType::FLAT_BUFFER; +const se::PoolType RenderingSubMesh::TYPE = se::PoolType::SUB_MESH; +const se::PoolType Node::TYPE = se::PoolType::NODE; +const se::PoolType Root::TYPE = se::PoolType::ROOT; +const se::PoolType RenderWindow::TYPE = se::PoolType::RENDER_WINDOW; +const se::PoolType Shadows::TYPE = se::PoolType::SHADOW; +const se::PoolType Sphere::TYPE = se::PoolType::SPHERE; +const se::PoolType UIBatch::TYPE = se::PoolType::UI_BATCH; +const se::PoolType PipelineSharedSceneData::TYPE = se::PoolType::PIPELINE_SHARED_SCENE_DATA; void AABB::getBoundary(cc::Vec3 &minPos, cc::Vec3 &maxPos) const { minPos = center - halfExtents; @@ -62,14 +62,15 @@ void AABB::merge(const AABB &aabb) { cc::Vec3 minB = aabb.center - aabb.halfExtents; cc::Vec3 maxA = center + halfExtents; cc::Vec3 maxB = aabb.center + aabb.halfExtents; - cc::Vec3 maxP, minP; + cc::Vec3 maxP; + cc::Vec3 minP; cc::Vec3::max(maxA, maxB, &maxP); cc::Vec3::min(minA, minB, &minP); cc::Vec3 addP = maxP + minP; cc::Vec3 subP = maxP - minP; - center = addP * 0.5f; - halfExtents = subP * 0.5f; + center = addP * 0.5F; + halfExtents = subP * 0.5F; } int Sphere::interset(const Plane &plane) const { @@ -87,7 +88,7 @@ int Sphere::interset(const Plane &plane) const { } bool Sphere::interset(const Frustum &frustum) const { - for (const auto &plane : frustum.planes) { + for (const auto &plane : frustum.planes) { // NOLINT if (this->interset(plane) == -1) { return false; } @@ -97,7 +98,7 @@ bool Sphere::interset(const Frustum &frustum) const { } void Sphere::mergePoint(const cc::Vec3 &point) { - if (radius < 0.0f) { + if (radius < 0.0F) { center = point; radius = 0.0; return; @@ -107,7 +108,7 @@ void Sphere::mergePoint(const cc::Vec3 &point) { auto distance = offset.length(); if (distance > radius) { - auto half = (distance - radius) * 0.5f; + auto half = (distance - radius) * 0.5F; radius += half; offset.scale(half / distance); center += offset; @@ -115,52 +116,58 @@ void Sphere::mergePoint(const cc::Vec3 &point) { } void Sphere::define(const AABB &aabb) { - cc::Vec3 minPos, maxPos; + cc::Vec3 minPos; + cc::Vec3 maxPos; aabb.getBoundary(minPos, maxPos); // Initialize sphere center.set(minPos); - radius = 0.0f; + radius = 0.0F; // Calculate sphere const cc::Vec3 offset = maxPos - center; const float dist = offset.length(); - const float half = dist * 0.5f; - radius += dist * 0.5f; + const float half = dist * 0.5F; + radius += dist * 0.5F; center += (half / dist) * offset; } void Sphere::mergeAABB(const AABB *aabb) { - cc::Vec3 minPos, maxPos; + cc::Vec3 minPos; + cc::Vec3 maxPos; aabb->getBoundary(minPos, maxPos); mergePoint(minPos); mergePoint(maxPos); } -int sphere_plane(const Sphere *sphere, const Plane *plane) { +int spherePlane(const Sphere *sphere, const Plane *plane) { const auto dot = cc::Vec3::dot(plane->normal, sphere->center); const auto r = sphere->radius * plane->normal.length(); if (dot + r < plane->distance) { return -1; - } else if (dot - r > plane->distance) { + } + if (dot - r > plane->distance) { return 0; } return 1; }; -bool sphere_frustum(const Sphere *sphere, const Frustum *frustum) { - for (auto i = 0; i < PLANE_LENGTH; i++) { +bool sphere_frustum(const Sphere *sphere, const Frustum *frustum) { // NOLINT + for (const auto &plane : frustum->planes) { // frustum plane normal points to the inside - if (sphere_plane(sphere, &frustum->planes[i]) == -1) { + if (spherePlane(sphere, &plane) == -1) { return false; } } // completely outside return true; } -bool aabb_aabb(const AABB *aabb1, const AABB *aabb2) { - cc::Vec3 aMin, aMax, bMin, bMax; +bool aabbAabb(const AABB *aabb1, const AABB *aabb2) { + cc::Vec3 aMin; + cc::Vec3 aMax; + cc::Vec3 bMin; + cc::Vec3 bMax; cc::Vec3::subtract(aabb1->center, aabb1->halfExtents, &aMin); cc::Vec3::add(aabb1->center, aabb1->halfExtents, &aMax); cc::Vec3::subtract(aabb2->center, aabb2->halfExtents, &bMin); @@ -170,7 +177,7 @@ bool aabb_aabb(const AABB *aabb1, const AABB *aabb2) { (aMin.z <= bMax.z && aMax.z >= bMin.z); } -int aabb_plane(const AABB *aabb, const Plane *plane) { +int aabbPlane(const AABB *aabb, const Plane *plane) { const auto &halfExtents = aabb->halfExtents; auto r = halfExtents.x * std::abs(plane->normal.x) + halfExtents.y * std::abs(plane->normal.y) + @@ -178,31 +185,32 @@ int aabb_plane(const AABB *aabb, const Plane *plane) { auto dot = Vec3::dot(plane->normal, aabb->center); if (dot + r < plane->distance) { return -1; - } else if (dot - r > plane->distance) { + } + if (dot - r > plane->distance) { return 0; } return 1; }; -bool aabb_frustum(const AABB *aabb, const Frustum *frustum) { - for (size_t i = 0; i < PLANE_LENGTH; i++) { +bool aabbFrustum(const AABB *aabb, const Frustum *frustum) { + for (const auto &plane : frustum->planes) { // frustum plane normal points to the inside - if (aabb_plane(aabb, &frustum->planes[i]) == -1) { - return 0; + if (aabbPlane(aabb, &plane) == -1) { + return false; } } // completely outside - return 1; + return true; } gfx::BlendState *getBlendStateImpl(uint index) { static gfx::BlendState blendState; - auto buffer = SharedMemory::getBuffer(se::PoolType::BLEND_STATE, index); - memcpy(&blendState, buffer, 24); + auto * buffer = SharedMemory::getBuffer(se::PoolType::BLEND_STATE, index); + memcpy(&blendState, buffer, 24); // NOLINT - uint32_t targetArrayHandle = *(buffer + 6); - const auto targetsHandle = GET_BLEND_TARGET_ARRAY(targetArrayHandle); - uint32_t targetLen = targetsHandle[0]; - auto & targets = blendState.targets; + uint32_t targetArrayHandle = *(buffer + 6); + auto *const targetsHandle = GET_BLEND_TARGET_ARRAY(targetArrayHandle); + uint32_t targetLen = targetsHandle[0]; + auto & targets = blendState.targets; targets.resize(targetLen); for (uint32_t i = 1; i <= targetLen; ++i) { memcpy(&targets[i - 1], GET_BLEND_TARGET(targetsHandle[i]), sizeof(gfx::BlendTarget)); diff --git a/cocos/renderer/pipeline/helper/SharedMemory.h b/cocos/renderer/pipeline/helper/SharedMemory.h index b5fb35edaf7..a01f0a5d1bd 100644 --- a/cocos/renderer/pipeline/helper/SharedMemory.h +++ b/cocos/renderer/pipeline/helper/SharedMemory.h @@ -29,6 +29,7 @@ #include "bindings/dop/BufferAllocator.h" #include "bindings/dop/BufferPool.h" #include "bindings/dop/ObjectPool.h" +#include "bindings/dop/PoolType.h" #include "math/Vec2.h" #include "math/Vec3.h" #include "math/Vec4.h" @@ -43,31 +44,31 @@ namespace pipeline { extern gfx::BlendState *getBlendStateImpl(uint index); //Get buffer pool data -#define GET_SUBMODEL(index) SharedMemory::getBuffer(index) -#define GET_PASS(index) SharedMemory::getBuffer(index) -#define GET_MODEL(index) SharedMemory::getBuffer(index) -#define GET_FLAT_BUFFER(index) SharedMemory::getBuffer(index) -#define GET_INSTANCE_ATTRIBUTE(index) SharedMemory::getBuffer(index) -#define GET_RENDER_SUBMESH(index) SharedMemory::getBuffer(index) -#define GET_BUFFERVIEW(index) SharedMemory::getBuffer(index) -#define GET_NODE(index) SharedMemory::getBuffer(index) -#define GET_ROOT() SharedMemory::getBuffer(se::BufferPool::getPoolFlag()) -#define GET_CAMERA(index) SharedMemory::getBuffer(index) -#define GET_SCENE(index) SharedMemory::getBuffer(index) -#define GET_LIGHT(index) SharedMemory::getBuffer(index) -#define GET_AMBIENT(index) SharedMemory::getBuffer(index) -#define GET_FOG(index) SharedMemory::getBuffer(index) -#define GET_SKYBOX(index) SharedMemory::getBuffer(index) -#define GET_FRUSTUM(index) SharedMemory::getBuffer(index) -#define GET_AABB(index) SharedMemory::getBuffer(index) -#define GET_WINDOW(index) SharedMemory::getBuffer(index) -#define GET_SHADOWS(index) SharedMemory::getBuffer(index) -#define GET_SPHERE(index) SharedMemory::getBuffer(index) -#define GET_RASTERIZER_STATE(index) SharedMemory::getBuffer(se::PoolType::RASTERIZER_STATE, index) -#define GET_DEPTH_STENCIL_STATE(index) SharedMemory::getBuffer(se::PoolType::DEPTH_STENCIL_STATE, index) -#define GET_BLEND_TARGET(index) SharedMemory::getBuffer(se::PoolType::BLEND_TARGET, index) -#define GET_BLEND_STATE(index) getBlendStateImpl(index) -#define GET_UI_BATCH(index) SharedMemory::getBuffer(index) +#define GET_SUBMODEL(index) SharedMemory::getBuffer(index) +#define GET_PASS(index) SharedMemory::getBuffer(index) +#define GET_MODEL(index) SharedMemory::getBuffer(index) +#define GET_FLAT_BUFFER(index) SharedMemory::getBuffer(index) +#define GET_INSTANCE_ATTRIBUTE(index) SharedMemory::getBuffer(index) +#define GET_RENDER_SUBMESH(index) SharedMemory::getBuffer(index) +#define GET_BUFFERVIEW(index) SharedMemory::getBuffer(index) +#define GET_NODE(index) SharedMemory::getBuffer(index) +#define GET_ROOT() SharedMemory::getBuffer(se::BufferPool::getPoolFlag()) +#define GET_CAMERA(index) SharedMemory::getBuffer(index) +#define GET_SCENE(index) SharedMemory::getBuffer(index) +#define GET_LIGHT(index) SharedMemory::getBuffer(index) +#define GET_AMBIENT(index) SharedMemory::getBuffer(index) +#define GET_FOG(index) SharedMemory::getBuffer(index) +#define GET_SKYBOX(index) SharedMemory::getBuffer(index) +#define GET_FRUSTUM(index) SharedMemory::getBuffer(index) +#define GET_AABB(index) SharedMemory::getBuffer(index) +#define GET_WINDOW(index) SharedMemory::getBuffer(index) +#define GET_SHADOWS(index) SharedMemory::getBuffer(index) +#define GET_SPHERE(index) SharedMemory::getBuffer(index) +#define GET_RASTERIZER_STATE(index) SharedMemory::getBuffer(se::PoolType::RASTERIZER_STATE, index) +#define GET_DEPTH_STENCIL_STATE(index) SharedMemory::getBuffer(se::PoolType::DEPTH_STENCIL_STATE, index) +#define GET_BLEND_TARGET(index) SharedMemory::getBuffer(se::PoolType::BLEND_TARGET, index) +#define GET_BLEND_STATE(index) getBlendStateImpl(index) +#define GET_UI_BATCH(index) SharedMemory::getBuffer(index) #define GET_PIPELINE_SHARED_SCENE_DATA(index) SharedMemory::getBuffer(index) //Get object pool data @@ -91,42 +92,48 @@ extern gfx::BlendState *getBlendStateImpl(uint index); // Get raw buffer or gfx object. #define GET_RAW_BUFFER(index, size) SharedMemory::getRawBuffer(se::PoolType::RAW_BUFFER, index, size) -static const float SHADOW_CAMERA_MAX_FAR = 2000.0f; -static const float COEFFICIENT_OF_EXPANSION = 2.0f * std::sqrtf(3.0f); +static const float SHADOW_CAMERA_MAX_FAR = 2000.0F; +static const float COEFFICIENT_OF_EXPANSION = 2.0F * std::sqrtf(3.0F); class CC_DLL SharedMemory : public Object { public: template static T *getBuffer(uint index) { const auto &bufferMap = se::BufferPool::getPoolMap(); - if (bufferMap.count(T::type) != 0) { - const se::BufferPool *bufferPool = bufferMap.at(T::type); - return bufferPool->getTypedObject(index); - } else { - return nullptr; - } + const auto type = GET_BUFFER_POOL_ID(T::TYPE); + +#ifdef CC_DEBUG + CCASSERT(bufferMap[type] != nullptr, "BufferPool: Invalid buffer pool type"); +#endif + + const se::BufferPool *bufferPool = bufferMap[type]; + return bufferPool->getTypedObject(index); } template static T *getBuffer(se::PoolType poolType, uint index) { const auto &bufferMap = se::BufferPool::getPoolMap(); - if (bufferMap.count(poolType) != 0) { - const se::BufferPool *bufferPool = bufferMap.at(poolType); - return bufferPool->getTypedObject(index); - } else { - return nullptr; - } + const auto type = GET_BUFFER_POOL_ID(poolType); + +#ifdef CC_DEBUG + CCASSERT(bufferMap[type] != nullptr, "BufferPool: Invalid buffer pool type"); +#endif + + const se::BufferPool *bufferPool = bufferMap[type]; + return bufferPool->getTypedObject(index); } template static T *getObject(uint index) { const auto &poolMap = se::ObjectPool::getPoolMap(); - if (poolMap.count(p) != 0) { - const se::ObjectPool *objectPool = poolMap.at(p); - return objectPool->getTypedObject(index); - } else { - return nullptr; - } + const auto type = GET_OBJECT_POOL_ID(p); + +#ifdef CC_DEBUG + CCASSERT(poolMap[type] != nullptr, "BufferPool: Invalid buffer pool type"); +#endif + + const se::ObjectPool *objectPool = poolMap[type]; + return objectPool->getTypedObject(index); } static uint32_t *getHandleArray(se::PoolType type, uint index) { @@ -146,39 +153,39 @@ class CC_DLL SharedMemory : public Object { struct CC_DLL Node { uint32_t flagsChanged = 0; - uint32_t layer = 0; + uint32_t layer = 0; cc::Vec3 worldScale; cc::Vec3 worldPosition; cc::Vec4 worldRotation; cc::Mat4 worldMatrix; - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL AABB { cc::Vec3 center; cc::Vec3 halfExtents; - void getBoundary(cc::Vec3 &minPos, cc::Vec3 &maxPos) const; + void getBoundary(cc::Vec3 &minPos, cc::Vec3 &maxPos) const; // NOLINT void merge(const AABB &aabb); - const static se::PoolType type; + const static se::PoolType TYPE; }; -bool aabb_aabb(const AABB *, const AABB *); +bool aabbAabb(const AABB *, const AABB *); struct CC_DLL Plane { cc::Vec3 normal; - float distance; + float distance; }; constexpr uint PLANE_LENGTH = 6; -struct CC_DLL Frustum { +struct CC_DLL Frustum { cc::Vec3 vertices[8]; - Plane planes[PLANE_LENGTH]; + Plane planes[PLANE_LENGTH]; - const static se::PoolType type; + const static se::PoolType TYPE; }; -bool aabb_frustum(const AABB *, const Frustum *); +bool aabbFrustum(const AABB *, const Frustum *); enum class LightType { DIRECTIONAL, @@ -188,56 +195,56 @@ enum class LightType { }; struct CC_DLL Light { uint32_t useColorTemperature = 0; - float luminance = 0; - uint32_t nodeID = 0; - float range = 0; - uint32_t lightType = 0; - uint32_t aabbID = 0; - uint32_t frustumID = 0; - float size = 0.15f; - float spotAngle = 0.0f; - float aspect = 1.0f; + float luminance = 0; + uint32_t nodeID = 0; + float range = 0; + uint32_t lightType = 0; + uint32_t aabbID = 0; + uint32_t frustumID = 0; + float size = 0.15F; + float spotAngle = 0.0F; + float aspect = 1.0F; cc::Vec3 direction; cc::Vec3 color; cc::Vec3 colorTemperatureRGB; cc::Vec3 position; CC_INLINE const Node *getNode() const { return GET_NODE(nodeID); } - CC_INLINE LightType getType() const { return static_cast(lightType); } + CC_INLINE LightType getType() const { return static_cast(lightType); } CC_INLINE const AABB *getAABB() const { return GET_AABB(aabbID); } CC_INLINE const Frustum *getFrustum() const { return GET_FRUSTUM(frustumID); } - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL FlatBufferView { - uint32_t stride = 0; - uint32_t count = 0; + uint32_t stride = 0; + uint32_t count = 0; uint32_t bufferID = 0; // raw buffer id CC_INLINE uint8_t *getBuffer(uint *size) const { return GET_RAW_BUFFER(bufferID, size); } - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL InstancedAttributeView { - uint32_t nameID = 0; - uint32_t format = 0; + uint32_t nameID = 0; + uint32_t format = 0; uint32_t isNormalized = 0; - uint32_t bufferID = 0; + uint32_t bufferID = 0; CC_INLINE const uint8_t *getBuffer(uint *size) const { return GET_RAW_BUFFER(bufferID, size); } - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL RenderingSubMesh { uint32_t flatBuffersID = 0; // array pool id - CC_INLINE const uint *getFlatBufferArrayID() const { return GET_FLAT_BUFFER_ARRAY(flatBuffersID); } - CC_INLINE const FlatBufferView *getFlatBuffer(uint idx) const { return GET_FLAT_BUFFER(idx); } + CC_INLINE const uint * getFlatBufferArrayID() const { return GET_FLAT_BUFFER_ARRAY(flatBuffersID); } + static CC_INLINE const FlatBufferView *getFlatBuffer(uint idx) { return GET_FLAT_BUFFER(idx); } - const static se::PoolType type; + const static se::PoolType TYPE; }; enum class CC_DLL BatchingSchemes { @@ -246,18 +253,18 @@ enum class CC_DLL BatchingSchemes { }; struct CC_DLL PassView { - uint32_t priority = 0; - uint32_t stage = 0; - uint32_t phase = 0; - uint32_t batchingScheme = 0; - uint32_t primitive = 0; - uint32_t dynamicState = 0; - uint32_t hash = 0; - uint32_t rasterizerStateID = 0; + uint32_t priority = 0; + uint32_t stage = 0; + uint32_t phase = 0; + uint32_t batchingScheme = 0; + uint32_t primitive = 0; + uint32_t dynamicState = 0; + uint32_t hash = 0; + uint32_t rasterizerStateID = 0; uint32_t depthStencilStateID = 0; - uint32_t blendStateID = 0; - uint32_t descriptorSetID = 0; - uint32_t pipelineLayoutID = 0; + uint32_t blendStateID = 0; + uint32_t descriptorSetID = 0; + uint32_t pipelineLayoutID = 0; CC_INLINE BatchingSchemes getBatchingScheme() const { return static_cast(batchingScheme); } CC_INLINE gfx::PrimitiveMode getPrimitive() const { return static_cast(primitive); } @@ -268,19 +275,19 @@ struct CC_DLL PassView { CC_INLINE gfx::DescriptorSet *getDescriptorSet() const { return GET_DESCRIPTOR_SET(descriptorSetID); } CC_INLINE gfx::PipelineLayout *getPipelineLayout() const { return GET_PIPELINE_LAYOUT(pipelineLayoutID); } - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL SubModelView { - uint32_t priority = 0; - uint32_t passCount = 0; - uint32_t passID[4] = {0, 0, 0, 0}; - uint32_t shaderID[4] = {0, 0, 0, 0}; - uint32_t planarShaderID = 0; + uint32_t priority = 0; + uint32_t passCount = 0; + uint32_t passID[4] = {0, 0, 0, 0}; + uint32_t shaderID[4] = {0, 0, 0, 0}; + uint32_t planarShaderID = 0; uint32_t planarInstanceShaderID = 0; - uint32_t descriptorSetID = 0; - uint32_t inputAssemblerID = 0; - uint32_t subMeshID = 0; + uint32_t descriptorSetID = 0; + uint32_t inputAssemblerID = 0; + uint32_t subMeshID = 0; CC_INLINE const PassView *getPassView(uint idx) const { return GET_PASS(passID[idx]); } CC_INLINE gfx::Shader *getShader(uint idx) const { return GET_SHADER(shaderID[idx]); } @@ -290,38 +297,38 @@ struct CC_DLL SubModelView { CC_INLINE gfx::InputAssembler *getInputAssembler() const { return GET_IA(inputAssemblerID); } CC_INLINE const RenderingSubMesh *getSubMesh() const { return GET_RENDER_SUBMESH(subMeshID); } - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL ModelView { - uint32_t enabled = 0; - uint32_t visFlags = 0; - uint32_t castShadow = 0; - uint32_t receiveShadow = 0; - uint32_t worldBoundsID = 0; // aabb - uint32_t nodeID = 0; - uint32_t transformID = 0; - uint32_t subModelsID = 0; // array pool id + uint32_t enabled = 0; + uint32_t visFlags = 0; + uint32_t castShadow = 0; + uint32_t receiveShadow = 0; + uint32_t worldBoundsID = 0; // aabb + uint32_t nodeID = 0; + uint32_t transformID = 0; + uint32_t subModelsID = 0; // array pool id uint32_t instancedBufferID = 0; // raw buffer id - uint32_t instancedAttrsID = 0; // array pool id + uint32_t instancedAttrsID = 0; // array pool id CC_INLINE const AABB *getWorldBounds() const { return GET_AABB(worldBoundsID); } CC_INLINE const Node *getNode() const { return GET_NODE(nodeID); } CC_INLINE const Node *getTransform() const { return GET_NODE(transformID); } - CC_INLINE const uint *getSubModelID() const { return GET_SUBMODEL_ARRAY(subModelsID); } - CC_INLINE const SubModelView *getSubModelView(uint idx) const { return GET_SUBMODEL(idx); } + CC_INLINE const uint * getSubModelID() const { return GET_SUBMODEL_ARRAY(subModelsID); } + static CC_INLINE const SubModelView *getSubModelView(uint idx) { return GET_SUBMODEL(idx); } CC_INLINE const uint8_t *getInstancedBuffer(uint *size) const { return GET_RAW_BUFFER(instancedBufferID, size); } CC_INLINE const uint *getInstancedAttributeID() const { return GET_ATTRIBUTE_ARRAY(instancedAttrsID); } - CC_INLINE gfx::Attribute *getInstancedAttribute(uint idx) const { return GET_ATTRIBUTE(idx); } - const static se::PoolType type; + static CC_INLINE gfx::Attribute *getInstancedAttribute(uint idx) { return GET_ATTRIBUTE(idx); } + const static se::PoolType TYPE; }; struct CC_DLL UIBatch { - uint32_t visFlags = 0; - uint32_t passCount = 0; - uint32_t passID[4] = {0, 0, 0, 0}; - uint32_t shaderID[4] = {0, 0, 0, 0}; - uint32_t descriptorSetID = 0; + uint32_t visFlags = 0; + uint32_t passCount = 0; + uint32_t passID[4] = {0, 0, 0, 0}; + uint32_t shaderID[4] = {0, 0, 0, 0}; + uint32_t descriptorSetID = 0; uint32_t inputAssemblerID = 0; CC_INLINE const PassView *getPassView(uint idx) const { return GET_PASS(passID[idx]); } @@ -329,134 +336,134 @@ struct CC_DLL UIBatch { CC_INLINE gfx::DescriptorSet *getDescriptorSet() const { return GET_DESCRIPTOR_SET(descriptorSetID); } CC_INLINE gfx::InputAssembler *getInputAssembler() const { return GET_IA(inputAssemblerID); } - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL Scene { uint32_t mainLightID = 0; - uint32_t modelsID = 0; // array pool - uint32_t sphereLights; // array pool - uint32_t spotLights; // array pool - uint32_t uiBatches; // array pool + uint32_t modelsID = 0; // array pool + uint32_t sphereLights; // array pool + uint32_t spotLights; // array pool + uint32_t uiBatches; // array pool CC_INLINE const Light *getMainLight() const { return GET_LIGHT(mainLightID); } - CC_INLINE const uint *getSphereLightArrayID() const { return GET_LIGHT_ARRAY(sphereLights); } - CC_INLINE const Light *getSphereLight(uint idx) const { return GET_LIGHT(idx); } - CC_INLINE const uint *getSpotLightArrayID() const { return GET_LIGHT_ARRAY(spotLights); } - CC_INLINE const Light *getSpotLight(uint idx) const { return GET_LIGHT(idx); } - CC_INLINE const uint *getModels() const { return GET_MODEL_ARRAY(modelsID); } - CC_INLINE const ModelView *getModelView(uint idx) const { return GET_MODEL(idx); } - CC_INLINE const uint *getUIBatches() const {return GET_UI_BATCH_ARRAY(uiBatches);} - - const static se::PoolType type; + CC_INLINE const uint * getSphereLightArrayID() const { return GET_LIGHT_ARRAY(sphereLights); } + static CC_INLINE const Light *getSphereLight(uint idx) { return GET_LIGHT(idx); } + CC_INLINE const uint * getSpotLightArrayID() const { return GET_LIGHT_ARRAY(spotLights); } + static CC_INLINE const Light *getSpotLight(uint idx) { return GET_LIGHT(idx); } + CC_INLINE const uint * getModels() const { return GET_MODEL_ARRAY(modelsID); } + static CC_INLINE const ModelView *getModelView(uint idx) { return GET_MODEL(idx); } + CC_INLINE const uint *getUIBatches() const { return GET_UI_BATCH_ARRAY(uiBatches); } + + const static se::PoolType TYPE; }; struct CC_DLL RenderWindow { - uint32_t hasOnScreenAttachments = 0; + uint32_t hasOnScreenAttachments = 0; uint32_t hasOffScreenAttachments = 0; - uint32_t framebufferID = 0; + uint32_t framebufferID = 0; CC_INLINE gfx::Framebuffer *getFramebuffer() const { return GET_FRAMEBUFFER(framebufferID); } - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL Camera { - uint32_t width = 0; - uint32_t height = 0; - float exposure = 0; - uint32_t clearFlag = 0; - float clearDepth = 0; - uint32_t clearStencil = 0; - uint32_t visibility = 0; - uint32_t nodeID = 0; - uint32_t sceneID = 0; - uint32_t frustumID = 0; - uint32_t windowID = 0; - cc::Vec3 forward; - cc::Vec3 position; - float viewportX = 0; - float viewportY = 0; - float viewportWidth = 0; - float viewportHeight = 0; + uint32_t width = 0; + uint32_t height = 0; + float exposure = 0; + uint32_t clearFlag = 0; + float clearDepth = 0; + uint32_t clearStencil = 0; + uint32_t visibility = 0; + uint32_t nodeID = 0; + uint32_t sceneID = 0; + uint32_t frustumID = 0; + uint32_t windowID = 0; + cc::Vec3 forward; + cc::Vec3 position; + float viewportX = 0; + float viewportY = 0; + float viewportWidth = 0; + float viewportHeight = 0; gfx::Color clearColor; - cc::Mat4 matView; - cc::Mat4 matViewProj; - cc::Mat4 matViewProjInv; - cc::Mat4 matProj; - cc::Mat4 matProjInv; - cc::Mat4 matViewProjOffscreen; - cc::Mat4 matViewProjInvOffscreen; - cc::Mat4 matProjOffscreen; - cc::Mat4 matProjInvOffscreen; + cc::Mat4 matView; + cc::Mat4 matViewProj; + cc::Mat4 matViewProjInv; + cc::Mat4 matProj; + cc::Mat4 matProjInv; + cc::Mat4 matViewProjOffscreen; + cc::Mat4 matViewProjInvOffscreen; + cc::Mat4 matProjOffscreen; + cc::Mat4 matProjInvOffscreen; CC_INLINE const Node *getNode() const { return GET_NODE(nodeID); } CC_INLINE const Scene *getScene() const { return GET_SCENE(sceneID); } CC_INLINE const Frustum *getFrustum() const { return GET_FRUSTUM(frustumID); } CC_INLINE const RenderWindow *getWindow() const { return GET_WINDOW(windowID); } - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL Ambient { - uint32_t enabled = 0; - float skyIllum = 0; + uint32_t enabled = 0; + float skyIllum = 0; cc::Vec4 skyColor; cc::Vec4 groundAlbedo; - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL Fog { - uint32_t enabled = 0; - uint32_t fogType = 0; - float fogDensity = 0; - float fogStart = 0; - float fogEnd = 0; - float fogAtten = 0; - float fogTop = 0; - float fogRange = 0; + uint32_t enabled = 0; + uint32_t fogType = 0; + float fogDensity = 0; + float fogStart = 0; + float fogEnd = 0; + float fogAtten = 0; + float fogTop = 0; + float fogRange = 0; cc::Vec4 fogColor; - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL Sphere { - float radius = 0; + float radius = 0; cc::Vec3 center; CC_INLINE void setCenter(const cc::Vec3 &val) { center = val; } CC_INLINE void setRadius(float val) { radius = val; } - void define(const AABB &aabb); - void mergeAABB(const AABB *aabb); - void mergePoint(const cc::Vec3 &point); - bool interset(const Frustum &frustum) const; - int interset(const Plane &plane) const; + void define(const AABB &aabb); + void mergeAABB(const AABB *aabb); + void mergePoint(const cc::Vec3 &point); + bool interset(const Frustum &frustum) const; + int interset(const Plane &plane) const; - const static se::PoolType type; + const static se::PoolType TYPE; }; -bool sphere_frustum(const Sphere *sphere, const Frustum *frustum); +bool sphere_frustum(const Sphere *sphere, const Frustum *frustum); //NOLINT enum class CC_DLL ShadowType { - PLANAR = 0, + PLANAR = 0, SHADOWMAP = 1 }; struct CC_DLL Shadows { - uint32_t enabled = 0; - uint32_t dirty = 0; - uint32_t shadowType = 0; - float distance = 0.0f; - uint32_t instancePass = 0; - uint32_t planarPass = 0; - float nearValue = 0.0f; - float farValue = 0.0f; - float aspect = 0.0f; - uint32_t pcfType = 0; + uint32_t enabled = 0; + uint32_t dirty = 0; + uint32_t shadowType = 0; + float distance = 0.0F; + uint32_t instancePass = 0; + uint32_t planarPass = 0; + float nearValue = 0.0F; + float farValue = 0.0F; + float aspect = 0.0F; + uint32_t pcfType = 0; uint32_t shadowMapDirty = 0; - float bias = 0.0f; - float orthoSize = 0.0f; - uint32_t autoAdapt = 0; + float bias = 0.0F; + float orthoSize = 0.0F; + uint32_t autoAdapt = 0; cc::Vec4 color; cc::Vec2 size; @@ -467,50 +474,50 @@ struct CC_DLL Shadows { CC_INLINE PassView *getPlanarShadowPass() const { return GET_PASS(planarPass); } CC_INLINE PassView *getInstancePass() const { return GET_PASS(instancePass); } - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL Skybox { uint32_t enabled = 0; - uint32_t isRGBE = 0; - uint32_t useIBL = 0; + uint32_t isRGBE = 0; + uint32_t useIBL = 0; uint32_t modelID = 0; CC_INLINE const ModelView *getModel() const { return GET_MODEL(modelID); } - const static se::PoolType type; + const static se::PoolType TYPE; }; struct CC_DLL PipelineSharedSceneData { - uint32_t shadow = 0; - uint32_t skybox = 0; - uint32_t ambient = 0; - uint32_t fog = 0; - uint32_t isHDR = 0; - uint32_t shadingScale = 0; - uint32_t fpScale = 0; - uint32_t deferredLightPass = 0; + uint32_t shadow = 0; + uint32_t skybox = 0; + uint32_t ambient = 0; + uint32_t fog = 0; + uint32_t isHDR = 0; + uint32_t shadingScale = 0; + uint32_t fpScale = 0; + uint32_t deferredLightPass = 0; uint32_t deferredLightPassShader = 0; - uint32_t deferredPostPass = 0; - uint32_t deferredPostPassShader = 0; - - CC_INLINE Shadows* getShadows() const {return GET_SHADOWS(shadow);} - CC_INLINE Skybox* getSkybox() const {return GET_SKYBOX(skybox);} - CC_INLINE Ambient* getAmbient() const {return GET_AMBIENT(ambient);} - CC_INLINE Fog* getFog() const {return GET_FOG(fog);} - CC_INLINE PassView* getDeferredLightPass() const {return GET_PASS(deferredLightPass);} - CC_INLINE gfx::Shader* getDeferredLightPassShader() const {return GET_SHADER(deferredLightPassShader);} - CC_INLINE PassView* getDeferredPostPass() const {return GET_PASS(deferredPostPass);} - CC_INLINE gfx::Shader* getDeferredPostPassShader() const {return GET_SHADER(deferredPostPassShader);} - - const static se::PoolType type; + uint32_t deferredPostPass = 0; + uint32_t deferredPostPassShader = 0; + + CC_INLINE Shadows *getShadows() const { return GET_SHADOWS(shadow); } + CC_INLINE Skybox *getSkybox() const { return GET_SKYBOX(skybox); } + CC_INLINE Ambient *getAmbient() const { return GET_AMBIENT(ambient); } + CC_INLINE Fog *getFog() const { return GET_FOG(fog); } + CC_INLINE PassView *getDeferredLightPass() const { return GET_PASS(deferredLightPass); } + CC_INLINE gfx::Shader *getDeferredLightPassShader() const { return GET_SHADER(deferredLightPassShader); } + CC_INLINE PassView *getDeferredPostPass() const { return GET_PASS(deferredPostPass); } + CC_INLINE gfx::Shader *getDeferredPostPassShader() const { return GET_SHADER(deferredPostPassShader); } + + const static se::PoolType TYPE; }; struct CC_DLL Root { float cumulativeTime = 0; - float frameTime = 0; + float frameTime = 0; - const static se::PoolType type; + const static se::PoolType TYPE; }; } //namespace pipeline