mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Refactor IntrusivePtr, remove reinterpret_cast (#4221)
* Refactor IntrusivePtr, remove reinterpret_cast
This commit is contained in:
@@ -169,6 +169,8 @@ DataWritterCallback getWriter(DataView &dataView, gfx::Format format) {
|
||||
|
||||
} // namespace
|
||||
|
||||
Mesh::~Mesh() = default;
|
||||
|
||||
cc::any Mesh::getNativeAsset() const {
|
||||
return _data; //cjh FIXME: need copy? could be _data pointer?
|
||||
}
|
||||
|
||||
@@ -160,8 +160,8 @@ public:
|
||||
Uint8Array data;
|
||||
};
|
||||
|
||||
Mesh() = default;
|
||||
~Mesh() override = default;
|
||||
Mesh() = default;
|
||||
~Mesh() override;
|
||||
|
||||
cc::any getNativeAsset() const override;
|
||||
void setNativeAsset(const cc::any &obj) override;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "3d/misc/BufferBlob.h"
|
||||
#include "core/ArrayBuffer.h"
|
||||
#include "core/DataView.h"
|
||||
#include "core/assets/RenderingSubMesh.h"
|
||||
#include "renderer/gfx-base/GFXDef-common.h"
|
||||
|
||||
namespace cc {
|
||||
@@ -178,8 +179,8 @@ Mesh::ICreateInfo createMeshInfo(const IGeometry &geometry, const ICreateMeshOpt
|
||||
|
||||
// Fill index buffer.
|
||||
ArrayBuffer::Ptr indexBuffer;
|
||||
uint32_t idxCount = 0;
|
||||
const uint32_t idxStride = 2;
|
||||
uint32_t idxCount = 0;
|
||||
const uint32_t idxStride = 2;
|
||||
if (geometry.indices.has_value()) {
|
||||
const std::vector<uint32_t> &indices = geometry.indices.value();
|
||||
idxCount = static_cast<uint32_t>(indices.size());
|
||||
|
||||
+6
-13
@@ -78,7 +78,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
#include "base/RefCounted.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
@@ -88,44 +87,38 @@ public:
|
||||
using element_type = T;
|
||||
|
||||
IntrusivePtr() {
|
||||
static_assert(std::is_base_of<RefCounted, T>::value, "RefCounted required!");
|
||||
}
|
||||
|
||||
IntrusivePtr(T *p) : _ptr(p) { // NOLINT
|
||||
static_assert(std::is_base_of<RefCounted, T>::value, "RefCounted required!");
|
||||
if (_ptr) {
|
||||
reinterpret_cast<RefCounted *>(_ptr)->addRef();
|
||||
_ptr->addRef();
|
||||
}
|
||||
}
|
||||
|
||||
IntrusivePtr(const IntrusivePtr<T> &r) : _ptr(r._ptr) {
|
||||
static_assert(std::is_base_of<RefCounted, T>::value, "RefCounted required!");
|
||||
if (_ptr) {
|
||||
reinterpret_cast<RefCounted *>(_ptr)->addRef();
|
||||
_ptr->addRef();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
IntrusivePtr(const IntrusivePtr<U> &r) : _ptr(r.get()) { // NOLINT
|
||||
static_assert(std::is_base_of<RefCounted, T>::value, "RefCounted required!");
|
||||
if (_ptr) {
|
||||
reinterpret_cast<RefCounted *>(_ptr)->addRef();
|
||||
_ptr->addRef();
|
||||
}
|
||||
}
|
||||
|
||||
// Move constructors.
|
||||
IntrusivePtr(IntrusivePtr<T> &&r) noexcept : _ptr(r.release()) {
|
||||
static_assert(std::is_base_of<RefCounted, T>::value, "RefCounted required!");
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
IntrusivePtr(IntrusivePtr<U> &&r) noexcept : _ptr(r.release()) { // NOLINT
|
||||
static_assert(std::is_base_of<RefCounted, T>::value, "RefCounted required!");
|
||||
}
|
||||
|
||||
~IntrusivePtr() {
|
||||
if (_ptr) {
|
||||
reinterpret_cast<RefCounted *>(_ptr)->release();
|
||||
_ptr->release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,10 +132,10 @@ public:
|
||||
IntrusivePtr<T> &operator=(T *p) {
|
||||
// AddRef first so that self assignment should work
|
||||
if (p) {
|
||||
reinterpret_cast<RefCounted *>(p)->addRef();
|
||||
p->addRef();
|
||||
}
|
||||
if (_ptr) {
|
||||
reinterpret_cast<RefCounted *>(_ptr)->release();
|
||||
_ptr->release();
|
||||
}
|
||||
_ptr = p;
|
||||
return *this;
|
||||
|
||||
@@ -46,6 +46,8 @@ TextureBase::TextureBase() {
|
||||
_textureHash = murmurhash2::MurmurHash2(_id.data(), static_cast<int>(_id.length()), 666); //cjh TODO: How about using boost hash functionality?
|
||||
}
|
||||
|
||||
TextureBase::~TextureBase() = default;
|
||||
|
||||
void TextureBase::setWrapMode(WrapMode wrapS, WrapMode wrapT, WrapMode wrapR) {
|
||||
_wrapS = wrapS;
|
||||
_samplerInfo.addressU = static_cast<gfx::Address>(wrapS),
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
*/
|
||||
using Filter = Filter;
|
||||
|
||||
~TextureBase() override = default;
|
||||
~TextureBase() override;
|
||||
/**
|
||||
* @en Whether the pixel data is compressed.
|
||||
* @zh 此贴图是否为压缩的像素格式。
|
||||
|
||||
@@ -70,6 +70,8 @@ TextureCube *TextureCube::fromTexture2DArray(const std::vector<Texture2D *> &tex
|
||||
return out;
|
||||
}
|
||||
|
||||
TextureCube::~TextureCube() = default;
|
||||
|
||||
void TextureCube::setMipmaps(const std::vector<ITextureCubeMipmap> &value) {
|
||||
_mipmaps = value;
|
||||
setMipmapLevel(static_cast<uint32_t>(_mipmaps.size()));
|
||||
|
||||
@@ -73,8 +73,8 @@ class TextureCube final : public SimpleTexture {
|
||||
public:
|
||||
using Super = SimpleTexture;
|
||||
|
||||
explicit TextureCube() = default;
|
||||
~TextureCube() override = default;
|
||||
explicit TextureCube() = default;
|
||||
~TextureCube() override;
|
||||
|
||||
/**
|
||||
* @en The index for all faces of the cube
|
||||
@@ -122,7 +122,7 @@ public:
|
||||
|
||||
void setMipmaps(const std::vector<ITextureCubeMipmap> &value);
|
||||
|
||||
void setMipmapsForJS(const std::vector<ITextureCubeMipmap>& value) {
|
||||
void setMipmapsForJS(const std::vector<ITextureCubeMipmap> &value) {
|
||||
_mipmaps = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,4 +64,10 @@ void SceneGlobals::activate() {
|
||||
}
|
||||
}
|
||||
|
||||
void SceneGlobals::setAmbientInfo(scene::AmbientInfo *info) { _ambientInfo = info; }
|
||||
void SceneGlobals::setShadowsInfo(scene::ShadowsInfo *info) { _shadowInfo = info; }
|
||||
void SceneGlobals::setSkyboxInfo(scene::SkyboxInfo *info) { _skyboxInfo = info; }
|
||||
void SceneGlobals::setFogInfo(scene::FogInfo *info) { _fogInfo = info; }
|
||||
void SceneGlobals::setOctreeInfo(scene::OctreeInfo *info) { _octreeInfo = info; }
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -51,11 +51,11 @@ public:
|
||||
inline scene::FogInfo * getFogInfo() const { return _fogInfo.get(); }
|
||||
inline scene::OctreeInfo * getOctreeInfo() const { return _octreeInfo.get(); }
|
||||
|
||||
inline void setAmbientInfo(scene::AmbientInfo *info) { _ambientInfo = info; }
|
||||
inline void setShadowsInfo(scene::ShadowsInfo *info) { _shadowInfo = info; }
|
||||
inline void setSkyboxInfo(scene::SkyboxInfo *info) { _skyboxInfo = info; }
|
||||
inline void setFogInfo(scene::FogInfo *info) { _fogInfo = info; }
|
||||
inline void setOctreeInfo(scene::OctreeInfo *info) { _octreeInfo = info; }
|
||||
void setAmbientInfo(scene::AmbientInfo *info);
|
||||
void setShadowsInfo(scene::ShadowsInfo *info);
|
||||
void setSkyboxInfo(scene::SkyboxInfo *info);
|
||||
void setFogInfo(scene::FogInfo *info);
|
||||
void setOctreeInfo(scene::OctreeInfo *info);
|
||||
|
||||
private:
|
||||
IntrusivePtr<scene::AmbientInfo> _ambientInfo;
|
||||
|
||||
@@ -24,13 +24,15 @@
|
||||
****************************************************************************/
|
||||
#include "primitive/Primitive.h"
|
||||
#include "3d/misc/CreateMesh.h"
|
||||
#include "core/assets/RenderingSubMesh.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
Primitive::Primitive(PrimitiveType type)
|
||||
: Mesh(), type(type) {
|
||||
Primitive::Primitive(PrimitiveType type) : type(type) {
|
||||
}
|
||||
|
||||
Primitive::~Primitive() = default;
|
||||
|
||||
void Primitive::onLoaded() {
|
||||
reset(createMeshInfo(createGeometry(type)));
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
Record<std::string, float> info; //cjh float?
|
||||
|
||||
explicit Primitive(PrimitiveType type = PrimitiveType::BOX);
|
||||
~Primitive() override = default;
|
||||
~Primitive() override;
|
||||
/**
|
||||
* @en
|
||||
* Construct the primitive mesh with `type` and `info`.
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "renderer/core/PassInstance.h"
|
||||
#include <cstdint>
|
||||
#include "renderer/core/ProgramLib.h"
|
||||
#include "renderer/pipeline/BatchedBuffer.h"
|
||||
#include "renderer/pipeline/InstancedBuffer.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
|
||||
@@ -341,5 +341,9 @@ void RenderPipeline::framegraphGC() {
|
||||
}
|
||||
}
|
||||
|
||||
void RenderPipeline::setGeometryRenderer(GeometryRenderer *geometryRenderer) {
|
||||
_geometryRenderer = geometryRenderer;
|
||||
}
|
||||
|
||||
} // namespace pipeline
|
||||
} // namespace cc
|
||||
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
inline void setProfiler(scene::Model *value) { _profiler = value; }
|
||||
|
||||
inline GeometryRenderer *getGeometryRenderer() const { return _geometryRenderer; }
|
||||
inline void setGeometryRenderer(GeometryRenderer *geometryRenderer) { _geometryRenderer = geometryRenderer; }
|
||||
void setGeometryRenderer(GeometryRenderer *geometryRenderer);
|
||||
|
||||
inline bool isClusterEnabled() const { return _clusterEnabled; }
|
||||
inline void setClusterEnabled(bool enable) { _clusterEnabled = enable; }
|
||||
|
||||
Reference in New Issue
Block a user