diff --git a/native/cocos/renderer/gfx/DeviceGraphics.cpp b/native/cocos/renderer/gfx/DeviceGraphics.cpp index 93f0f33614..2e96592456 100644 --- a/native/cocos/renderer/gfx/DeviceGraphics.cpp +++ b/native/cocos/renderer/gfx/DeviceGraphics.cpp @@ -1094,13 +1094,11 @@ void DeviceGraphics::commitTextures() // DeviceGraphics::Uniform::Uniform() : dirty(true) -, value(nullptr) , elementType(UniformElementType::FLOAT) {} DeviceGraphics::Uniform::Uniform(const void* v, size_t bytes, UniformElementType elementType_) : dirty(true) -, value(nullptr) , elementType(elementType_) { setValue(v, bytes); diff --git a/native/cocos/renderer/gfx/DeviceGraphics.h b/native/cocos/renderer/gfx/DeviceGraphics.h index 03a0eeaaff..62ae7bf8d4 100644 --- a/native/cocos/renderer/gfx/DeviceGraphics.h +++ b/native/cocos/renderer/gfx/DeviceGraphics.h @@ -79,7 +79,7 @@ public: void setValue(const void* v, size_t bytes); - void* value; + void* value = NULL; bool dirty; UniformElementType elementType; private: diff --git a/native/cocos/renderer/memop/RecyclePool.hpp b/native/cocos/renderer/memop/RecyclePool.hpp index e4a66034d3..9b259a205c 100644 --- a/native/cocos/renderer/memop/RecyclePool.hpp +++ b/native/cocos/renderer/memop/RecyclePool.hpp @@ -39,12 +39,22 @@ public: { _count = 0; _data.resize(size); - }; + + for (int i = 0; i < size; i++) + { + _data[i] = new T(); + } + } ~RecyclePool() { + for (int i = 0, len = (int)_data.size(); i < len; i++) + { + delete _data[i]; + } + _data.clear(); - }; + } const T* getData(const int index) const { @@ -54,7 +64,7 @@ public: return nullptr; } - return &_data[index]; + return _data[index]; } const int getLength() const @@ -65,26 +75,34 @@ public: void reset() { _count = 0; - }; + } T* add() { int size = (int)_data.size(); - if (_count >= size) { - _data.resize(size * 2); + if (_count >= size) + { + resize(size * 2); } - return &_data[_count++]; - }; + return _data[_count++]; + } void resize(int size) { - _data.resize(size); - }; + if (size > _data.size()) + { + for (int i = (int)_data.size(); i < size; i++) + { + _data[i] = new T(); + } + } + } void remove(int index) { - if (index >= _count) { + if (index >= _count) + { return; } @@ -93,10 +111,10 @@ public: _data[index] = _data[last]; _data[last] = tmp; _count -= 1; - }; + } private: int _count = 0; - std::vector _data; + std::vector _data; }; diff --git a/native/cocos/renderer/renderer/BaseRenderer.cpp b/native/cocos/renderer/renderer/BaseRenderer.cpp index 19114edd19..aaab24786e 100644 --- a/native/cocos/renderer/renderer/BaseRenderer.cpp +++ b/native/cocos/renderer/renderer/BaseRenderer.cpp @@ -170,11 +170,11 @@ void BaseRenderer::render(const View& view, const Scene* scene) } } -void BaseRenderer::setProperty (Property& prop) +void BaseRenderer::setProperty (Effect::Property& prop) { Technique::Parameter::Type propType = prop.getType(); auto& propName = prop.getName(); - if (Property::Type::UNKNOWN == propType) + if (Effect::Property::Type::UNKNOWN == propType) { RENDERER_LOGW("Failed to set technique property, type unknown"); return; @@ -182,9 +182,9 @@ void BaseRenderer::setProperty (Property& prop) if (nullptr == prop.getValue()) { - prop = Property(propName, propType); + prop = Effect::Property(propName, propType); - if (Property::Type::TEXTURE_2D == propType) + if (Effect::Property::Type::TEXTURE_2D == propType) { prop.setTexture(_defaultTexture); } @@ -196,8 +196,8 @@ void BaseRenderer::setProperty (Property& prop) return; } - if (Property::Type::TEXTURE_2D == propType || - Property::Type::TEXTURE_CUBE == propType) + if (Effect::Property::Type::TEXTURE_2D == propType || + Effect::Property::Type::TEXTURE_CUBE == propType) { if (1 == prop.getCount()) { @@ -215,7 +215,7 @@ void BaseRenderer::setProperty (Property& prop) } _device->setTextureArray(propName, - std::move(prop.getTextureArray()), + prop.getTextureArray(), slots); } } @@ -241,9 +241,9 @@ void BaseRenderer::setProperty (Property& prop) } uint16_t bytes = prop.getBytes(); - if (Property::Type::INT == propType || - Property::Type::INT2 == propType || - Property::Type::INT4 == propType) + if (Effect::Property::Type::INT == propType || + Effect::Property::Type::INT2 == propType || + Effect::Property::Type::INT4 == propType) { _device->setUniformiv(propName, bytes / sizeof(int), (const int*)prop.getValue()); } @@ -269,7 +269,7 @@ void BaseRenderer::draw(const StageItem& item) auto& properties = effect->getProperties(); for (auto it = properties.begin(); it != properties.end(); it++) { - Property& prop = const_cast(it->second); + Effect::Property& prop = const_cast(it->second); setProperty(prop); } diff --git a/native/cocos/renderer/renderer/BaseRenderer.h b/native/cocos/renderer/renderer/BaseRenderer.h index 96a0efd1a7..f1ac091107 100644 --- a/native/cocos/renderer/renderer/BaseRenderer.h +++ b/native/cocos/renderer/renderer/BaseRenderer.h @@ -104,7 +104,7 @@ public: protected: void render(const View&, const Scene* scene); void draw(const StageItem& item); - void setProperty (Property& prop); + void setProperty (Effect::Property& prop); struct StageInfo { @@ -125,8 +125,6 @@ protected: Program* _program = nullptr; Texture2D* _defaultTexture = nullptr; std::unordered_map _stage2fn; - //std::vector _drawItems; - //std::vector _stageInfos; RecyclePool* _drawItems; RecyclePool* _stageInfos; RecyclePool* _views; diff --git a/native/cocos/renderer/renderer/CustomProperties.cpp b/native/cocos/renderer/renderer/CustomProperties.cpp index 5148e70f32..d9371f348d 100644 --- a/native/cocos/renderer/renderer/CustomProperties.cpp +++ b/native/cocos/renderer/renderer/CustomProperties.cpp @@ -47,7 +47,7 @@ void CustomProperties::setProperty(const std::string name, const Property& prope _dirty = true; } -const Property& CustomProperties::getProperty(std::string name) const +const CustomProperties::Property& CustomProperties::getProperty(std::string name) const { static Property EMPTY_PROPERTY; if (_properties.end() == _properties.find(name)) @@ -79,7 +79,7 @@ Value CustomProperties::getDefine(const std::string& name) const return Value::Null; } -std::unordered_map CustomProperties::extractProperties() +std::unordered_map CustomProperties::extractProperties() { return _properties; } diff --git a/native/cocos/renderer/renderer/CustomProperties.hpp b/native/cocos/renderer/renderer/CustomProperties.hpp index 6f28b20d85..a605a78778 100644 --- a/native/cocos/renderer/renderer/CustomProperties.hpp +++ b/native/cocos/renderer/renderer/CustomProperties.hpp @@ -31,11 +31,11 @@ RENDERER_BEGIN -using Property = Technique::Parameter; - class CustomProperties { public: + using Property = Technique::Parameter; + CustomProperties(); ~CustomProperties(); diff --git a/native/cocos/renderer/renderer/ForwardRenderer.cpp b/native/cocos/renderer/renderer/ForwardRenderer.cpp index d1e948e70f..0b5412e3b9 100644 --- a/native/cocos/renderer/renderer/ForwardRenderer.cpp +++ b/native/cocos/renderer/renderer/ForwardRenderer.cpp @@ -153,13 +153,13 @@ void ForwardRenderer::submitLightsUniforms() for (int i = 0; i < count; ++i) { auto* light = _directionalLights.at(i); - lightVec3.set(std::move(light->getDirectionUniform())); + lightVec3.set(light->getDirectionUniform()); *directions++ = lightVec3.x; *directions++ = lightVec3.y; *directions++ = lightVec3.z; *directions++ = 0; - colorVec3.set(std::move(light->getColorUniform())); + colorVec3.set(light->getColorUniform()); *colors++ = colorVec3.x; *colors++ = colorVec3.y; *colors++ = colorVec3.z; @@ -179,13 +179,13 @@ void ForwardRenderer::submitLightsUniforms() for (int i = 0; i < count; ++i) { auto* light = _pointLights.at(i); - posVec3.set(std::move(light->getPositionUniform())); + posVec3.set(light->getPositionUniform()); *positionAndRanges++ = posVec3.x; *positionAndRanges++ = posVec3.y; *positionAndRanges++ = posVec3.z; *positionAndRanges++ = light->getRange(); - colorVec3.set(std::move(light->getColorUniform())); + colorVec3.set(light->getColorUniform()); *colors++ = colorVec3.x; *colors++ = colorVec3.y; *colors++ = colorVec3.z; @@ -207,19 +207,19 @@ void ForwardRenderer::submitLightsUniforms() for (int i = 0; i < count; ++i) { auto* light = _spotLights.at(i); - lightVec3.set(std::move(light->getDirectionUniform())); + lightVec3.set(light->getDirectionUniform()); *directions++ = lightVec3.x; *directions++ = lightVec3.y; *directions++ = lightVec3.z; *directions++ = 0; - posVec3.set(std::move(light->getPositionUniform())); + posVec3.set(light->getPositionUniform()); *positionAndRanges++ = posVec3.x; *positionAndRanges++ = posVec3.y; *positionAndRanges++ = posVec3.z; *positionAndRanges++ = light->getRange(); - colorVec3.set(std::move(light->getColorUniform())); + colorVec3.set(light->getColorUniform()); *colors++ = colorVec3.x; *colors++ = colorVec3.y; *colors++ = colorVec3.z; @@ -237,7 +237,7 @@ void ForwardRenderer::submitLightsUniforms() for (int i = 0; i < count; ++i) { auto* light = _ambientLights.at(i); - colorVec3.set(std::move(light->getColorUniform())); + colorVec3.set(light->getColorUniform()); *colors++ = colorVec3.x; *colors++ = colorVec3.y; *colors++ = colorVec3.z; @@ -335,7 +335,7 @@ void ForwardRenderer::drawItems(const std::vector& items) shadowMaps.push_back(light->getShadowMap()); slots.push_back(allocTextureUnit()); } - _device->setTextureArray("cc_shadow_map", std::move(shadowMaps), slots); + _device->setTextureArray("cc_shadow_map", shadowMaps, slots); updateShaderDefines(item); draw(item); } diff --git a/native/cocos/renderer/renderer/Model.cpp b/native/cocos/renderer/renderer/Model.cpp index 92877b3d0a..1316e6ebc2 100644 --- a/native/cocos/renderer/renderer/Model.cpp +++ b/native/cocos/renderer/renderer/Model.cpp @@ -84,12 +84,12 @@ void Model::setEffect(Effect* effect, CustomProperties* customProperties) _uniforms.clear(); if (effect != nullptr) { - _defines.push_back(std::move(effect->extractDefines())); + _defines.push_back(effect->extractDefines()); _uniforms.push_back(effect->extractProperties()); } if (customProperties != nullptr) { - _defines.push_back(std::move(customProperties->extractDefines())); + _defines.push_back(customProperties->extractDefines()); _uniforms.push_back(customProperties->extractProperties()); } } @@ -100,7 +100,7 @@ void Model::extractDrawItem(DrawItem& out) const { out.model = const_cast(this); out.ia = nullptr; - out.effect = std::move(_effect); + out.effect = _effect; out.defines = out.effect->extractDefines(); return; @@ -108,7 +108,7 @@ void Model::extractDrawItem(DrawItem& out) const out.model = const_cast(this); out.ia = const_cast(&(_inputAssembler)); - out.effect = std::move(_effect); + out.effect = _effect; out.defines = out.effect->extractDefines(); } diff --git a/native/cocos/renderer/renderer/Model.h b/native/cocos/renderer/renderer/Model.h index 5d9dc71ee6..be570ef08a 100644 --- a/native/cocos/renderer/renderer/Model.h +++ b/native/cocos/renderer/renderer/Model.h @@ -84,7 +84,7 @@ public: /** * @brief Sets model matrix. */ - inline void setWorldMatix(const Mat4& matrix) { _worldMatrix = std::move(matrix); } + inline void setWorldMatix(const Mat4& matrix) { _worldMatrix = matrix; } /** * @brief Gets mode matrix. */ @@ -126,13 +126,13 @@ private: friend class ModelPool; void reset(); - NodeProxy* _node; + NodeProxy* _node = nullptr; Mat4 _worldMatrix; - Effect* _effect; + Effect* _effect = nullptr; InputAssembler _inputAssembler; std::vector _defines; - std::vector> _uniforms; + std::vector> _uniforms; bool _dynamicIA = false; int _cullingMask = -1; int _userKey = -1;