From a9887b46380340bb8e95c3bb41c6c58e18ce8bf5 Mon Sep 17 00:00:00 2001 From: owen <1053210246@qq.com> Date: Tue, 12 Feb 2019 17:14:04 +0800 Subject: [PATCH 1/8] Fix vertex exceed 65535 error and dragonbones leak (#1669) * fix exceed native-renderer * fix dragonbones memery leak * fix native db leak * fix native db leak * indent issue * add MeshBuffer into vs project * modify cocos2d_files template * optimize spine --- .../cocos2d_libs.xcodeproj/project.pbxproj | 12 ++ native/build/libcocos2d.vcxproj | 2 + native/build/libcocos2d.vcxproj.filters | 6 + native/cocos/editor-support/Android.mk | 1 + native/cocos/editor-support/IOBuffer.h | 45 +++++-- native/cocos/editor-support/MeshBuffer.cpp | 111 ++++++++++++++++ native/cocos/editor-support/MeshBuffer.h | 71 ++++++++++ native/cocos/editor-support/MiddlewareMacro.h | 12 +- .../editor-support/MiddlewareManager.cpp | 89 ++----------- .../cocos/editor-support/MiddlewareManager.h | 36 +----- .../CCArmatureDisplay.cpp | 25 +++- .../dragonbones/core/DragonBones.cpp | 22 ++-- .../dragonbones/core/DragonBones.h | 2 +- .../spine-creator-support/SpineRenderer.cpp | 122 ++++++++++-------- .../jsb_cocos2dx_editor_support_auto_api.js | 22 ---- .../auto/jsb_cocos2dx_editor_support_auto.cpp | 41 ------ .../auto/jsb_cocos2dx_editor_support_auto.hpp | 2 - native/package.json | 2 +- native/templates/cocos2dx_files.json | 2 + native/tools/tojs/cocos2dx_editor_support.ini | 2 +- 20 files changed, 358 insertions(+), 269 deletions(-) create mode 100644 native/cocos/editor-support/MeshBuffer.cpp create mode 100644 native/cocos/editor-support/MeshBuffer.h diff --git a/native/build/cocos2d_libs.xcodeproj/project.pbxproj b/native/build/cocos2d_libs.xcodeproj/project.pbxproj index e96f779496..192536b7f8 100644 --- a/native/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/native/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -387,6 +387,10 @@ 04AF6300219190ED00AED9DE /* TypedArrayPool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04AF62FD219190ED00AED9DE /* TypedArrayPool.cpp */; }; 04AF6301219190ED00AED9DE /* TypedArrayPool.h in Headers */ = {isa = PBXBuildFile; fileRef = 04AF62FE219190ED00AED9DE /* TypedArrayPool.h */; }; 04AF6302219190ED00AED9DE /* TypedArrayPool.h in Headers */ = {isa = PBXBuildFile; fileRef = 04AF62FE219190ED00AED9DE /* TypedArrayPool.h */; }; + 04ED68D821F8188F006E82F8 /* MeshBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04ED68D621F8188F006E82F8 /* MeshBuffer.cpp */; }; + 04ED68D921F8188F006E82F8 /* MeshBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 04ED68D621F8188F006E82F8 /* MeshBuffer.cpp */; }; + 04ED68DA21F8188F006E82F8 /* MeshBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 04ED68D721F8188F006E82F8 /* MeshBuffer.h */; }; + 04ED68DB21F8188F006E82F8 /* MeshBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 04ED68D721F8188F006E82F8 /* MeshBuffer.h */; }; 1A14FD912080B4E300E10ABE /* CCGLUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A14FD8F2080B4E300E10ABE /* CCGLUtils.cpp */; }; 1A14FD922080B4E300E10ABE /* CCGLUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A14FD8F2080B4E300E10ABE /* CCGLUtils.cpp */; }; 1A14FD932080B4E300E10ABE /* CCGLUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A14FD902080B4E300E10ABE /* CCGLUtils.h */; }; @@ -1369,6 +1373,8 @@ 046E070E218B01EF00B24E2D /* jsb_dragonbones_manual.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = jsb_dragonbones_manual.hpp; sourceTree = ""; }; 04AF62FD219190ED00AED9DE /* TypedArrayPool.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = TypedArrayPool.cpp; path = "../cocos/editor-support/TypedArrayPool.cpp"; sourceTree = ""; }; 04AF62FE219190ED00AED9DE /* TypedArrayPool.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TypedArrayPool.h; path = "../cocos/editor-support/TypedArrayPool.h"; sourceTree = ""; }; + 04ED68D621F8188F006E82F8 /* MeshBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = MeshBuffer.cpp; path = "../cocos/editor-support/MeshBuffer.cpp"; sourceTree = ""; }; + 04ED68D721F8188F006E82F8 /* MeshBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MeshBuffer.h; path = "../cocos/editor-support/MeshBuffer.h"; sourceTree = ""; }; 051C016F21E2F85C00D4A347 /* CCModuleConfigIOS.debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CCModuleConfigIOS.debug.xcconfig; sourceTree = ""; }; 051C017021E2F85C00D4A347 /* CCModuleConfigIOS.release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CCModuleConfigIOS.release.xcconfig; sourceTree = ""; }; 051C017121E2F86900D4A347 /* CCModuleConfigMac.release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CCModuleConfigMac.release.xcconfig; sourceTree = ""; }; @@ -1906,6 +1912,8 @@ 046B688E21A00F5600B33469 /* IOTypedArray.cpp */, 046B688F21A00F5600B33469 /* IOTypedArray.h */, 046B689421A10D5800B33469 /* MiddlewareMacro.h */, + 04ED68D621F8188F006E82F8 /* MeshBuffer.cpp */, + 04ED68D721F8188F006E82F8 /* MeshBuffer.h */, ); name = "editor-support"; sourceTree = ""; @@ -3105,6 +3113,7 @@ 46AE3FDF2092F3A600F3A228 /* env.h in Headers */, 0430124D21DCF2B80007084D /* SkeletonBinary.h in Headers */, 46AE3FE72092F3A600F3A228 /* inspector_io.h in Headers */, + 04ED68DA21F8188F006E82F8 /* MeshBuffer.h in Headers */, 46FDDBCF202ADDCE00931238 /* CCMap.h in Headers */, 1A52DB34205BCD9200350EE3 /* Object.hpp in Headers */, 469303962046AE05004A3D6C /* Class.hpp in Headers */, @@ -3611,6 +3620,7 @@ 0430123621DCF2B80007084D /* extension.h in Headers */, 46FDDAAE202ACC6A00931238 /* Macro.h in Headers */, 0430123E21DCF2B80007084D /* spine.h in Headers */, + 04ED68DB21F8188F006E82F8 /* MeshBuffer.h in Headers */, 0430129C21DCF2B80007084D /* AttachmentLoader.h in Headers */, 469303872046AE05004A3D6C /* Object.hpp in Headers */, 1A28FF5E1F20AFAB007A1D9D /* SRProxyConnect.h in Headers */, @@ -3932,6 +3942,7 @@ 46FDDBFB202ADDCE00931238 /* ccCArray.cpp in Sources */, 1AAAC8E1205CB6E9005321B9 /* AudioPlayer.mm in Sources */, 1A28FF631F20AFAB007A1D9D /* SRRunLoopThread.m in Sources */, + 04ED68D821F8188F006E82F8 /* MeshBuffer.cpp in Sources */, 50ABBD5C1925AB0000A911A9 /* Vec3.cpp in Sources */, 469303662046AE05004A3D6C /* HandleObject.cpp in Sources */, 469301D1203FC696004A3D6C /* CCConfiguration.cpp in Sources */, @@ -4122,6 +4133,7 @@ 046E06592185B41B00B24E2D /* Armature.cpp in Sources */, 403ACADC20CE542600BB433D /* jsb_module_register.cpp in Sources */, 046E06BC2185B49F00B24E2D /* TextureAtlasData.cpp in Sources */, + 04ED68D921F8188F006E82F8 /* MeshBuffer.cpp in Sources */, 46FDDA9A202ACC6A00931238 /* Model.cpp in Sources */, 046E0710218B01EF00B24E2D /* jsb_dragonbones_manual.cpp in Sources */, 4693038F2046AE05004A3D6C /* Value.cpp in Sources */, diff --git a/native/build/libcocos2d.vcxproj b/native/build/libcocos2d.vcxproj index aff17840f5..b03bcdcc93 100644 --- a/native/build/libcocos2d.vcxproj +++ b/native/build/libcocos2d.vcxproj @@ -76,6 +76,7 @@ + @@ -323,6 +324,7 @@ + diff --git a/native/build/libcocos2d.vcxproj.filters b/native/build/libcocos2d.vcxproj.filters index 435ac00a2a..0268b2418a 100644 --- a/native/build/libcocos2d.vcxproj.filters +++ b/native/build/libcocos2d.vcxproj.filters @@ -680,6 +680,9 @@ editor-support\spine + + editor-support + @@ -1508,6 +1511,9 @@ editor-support\spine + + editor-support + diff --git a/native/cocos/editor-support/Android.mk b/native/cocos/editor-support/Android.mk index e0af2071aa..c14ff0b432 100644 --- a/native/cocos/editor-support/Android.mk +++ b/native/cocos/editor-support/Android.mk @@ -10,6 +10,7 @@ LOCAL_ARM_MODE := arm LOCAL_SRC_FILES := \ ../scripting/js-bindings/manual/jsb_helper.cpp \ IOBuffer.cpp \ +MeshBuffer.cpp \ middleware-adapter.cpp \ TypedArrayPool.cpp \ IOTypedArray.cpp \ diff --git a/native/cocos/editor-support/IOBuffer.h b/native/cocos/editor-support/IOBuffer.h index b235cba189..5b2a8f8eeb 100644 --- a/native/cocos/editor-support/IOBuffer.h +++ b/native/cocos/editor-support/IOBuffer.h @@ -28,6 +28,7 @@ #include #include "MiddlewareMacro.h" #include +#include MIDDLEWARE_BEGIN /** @@ -198,16 +199,40 @@ public: return _outRange; } - inline void checkSpace (std::size_t needSize, bool needCopy = false) - { - auto needLen = _curPos + needSize; - if (_bufferSize < needLen) - { - std::size_t fitSize = ceil(needLen / float(MIN_TYPE_ARRAY_SIZE)) * MIN_TYPE_ARRAY_SIZE; - resize(fitSize, needCopy); - } - } + inline int checkSpace (std::size_t needSize, bool needCopy = false) + { + auto needLen = _curPos + needSize; + auto isFull = 0; + if (_maxSize > 0 && needLen > _maxSize) + { + isFull = 1; + if (_fullCallback) + { + _fullCallback(); + } + _curPos = 0; + } + if (_bufferSize < needLen) + { + std::size_t fitSize = ceil(needLen / float(MIN_TYPE_ARRAY_SIZE)) * MIN_TYPE_ARRAY_SIZE; + resize(fitSize, needCopy); + } + + return isFull; + } + + void setMaxSize(std::size_t maxSize) + { + _maxSize = maxSize; + } + + typedef std::function fullCallback; + void setFullCallback(fullCallback callback) + { + _fullCallback = callback; + } + /** * @brief Resize buffer * @param[in] newLen New size you want to adjustment. @@ -220,6 +245,8 @@ protected: std::size_t _curPos = 0; std::size_t _readPos = 0; bool _outRange = false; + std::size_t _maxSize = 0; + fullCallback _fullCallback = nullptr; }; MIDDLEWARE_END diff --git a/native/cocos/editor-support/MeshBuffer.cpp b/native/cocos/editor-support/MeshBuffer.cpp new file mode 100644 index 0000000000..07f07125dc --- /dev/null +++ b/native/cocos/editor-support/MeshBuffer.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** + Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "MeshBuffer.h" +#include "base/CCGLUtils.h" + +MIDDLEWARE_BEGIN + +MeshBuffer::MeshBuffer(int vertexSize) +: _ib(INIT_IB_BUFFER_SIZE) +, _vb(65535 * vertexSize) +{ + _vb.setMaxSize(65535 * vertexSize); + _vb.setFullCallback([this] + { + uploadVB(); + uploadIB(); + _vb.reset(); + _ib.reset(); + next(); + }); + + _glIBArr.resize(1); + glGenBuffers(1, &_glIBArr[0]); + + _glVBArr.resize(1); + glGenBuffers(1, &_glVBArr[0]); +} + +MeshBuffer::~MeshBuffer() +{ + auto num = _glVBArr.size(); + for (auto i = 0; i < num; i++) + { + cocos2d::ccDeleteBuffers(1, &_glIBArr[i]); + cocos2d::ccDeleteBuffers(1, &_glVBArr[i]); + } + _glIBArr.clear(); + _glVBArr.clear(); +} + +void MeshBuffer::uploadVB() +{ + auto length = _vb.length(); + if (length == 0) return; + + auto glVB = _glVBArr[_bufferPos]; + cocos2d::ccBindBuffer(GL_ARRAY_BUFFER, glVB); + glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)length, _vb.getBuffer(), GL_DYNAMIC_DRAW); + cocos2d::ccBindBuffer(GL_ARRAY_BUFFER, 0); +} + +void MeshBuffer::uploadIB() +{ + auto length = _ib.length(); + if (length == 0) return; + + GLint _oldGLID = 0; + glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &_oldGLID); + + auto glIB = _glIBArr[_bufferPos]; + cocos2d::ccBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glIB); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)length, _ib.getBuffer(), GL_STATIC_DRAW); + cocos2d::ccBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _oldGLID); +} + +void MeshBuffer::next() +{ + _bufferPos++; + if (_glIBArr.size() <= _bufferPos) + { + _glIBArr.resize(_bufferPos + 1); + glGenBuffers(1, &_glIBArr[_bufferPos]); + } + + if (_glVBArr.size() <= _bufferPos) + { + _glVBArr.resize(_bufferPos + 1); + glGenBuffers(1, &_glVBArr[_bufferPos]); + } +} + +void MeshBuffer::reset() +{ + _bufferPos = 0; + _vb.reset(); + _ib.reset(); +} + +MIDDLEWARE_END diff --git a/native/cocos/editor-support/MeshBuffer.h b/native/cocos/editor-support/MeshBuffer.h new file mode 100644 index 0000000000..7898e0a5e6 --- /dev/null +++ b/native/cocos/editor-support/MeshBuffer.h @@ -0,0 +1,71 @@ +/**************************************************************************** + Copyright (c) 2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#pragma once + +#include "IOBuffer.h" +#include + +MIDDLEWARE_BEGIN + +class MeshBuffer +{ +public: + MeshBuffer(int vertexFormat); + ~MeshBuffer(); + + uint32_t getGLVB() + { + return _glVBArr[_bufferPos]; + } + + uint32_t getGLIB() + { + return _glIBArr[_bufferPos]; + } + + IOBuffer& getVB() + { + return _vb; + } + + IOBuffer& getIB() + { + return _ib; + } + + void uploadVB(); + void uploadIB(); + void reset(); +private: + void next(); +private: + std::vector _glIBArr; + std::vector _glVBArr; + + std::size_t _bufferPos = 0; + IOBuffer _vb; + IOBuffer _ib; +}; + +MIDDLEWARE_END diff --git a/native/cocos/editor-support/MiddlewareMacro.h b/native/cocos/editor-support/MiddlewareMacro.h index 94caf6bfcc..709f01d184 100644 --- a/native/cocos/editor-support/MiddlewareMacro.h +++ b/native/cocos/editor-support/MiddlewareMacro.h @@ -22,12 +22,8 @@ THE SOFTWARE. ****************************************************************************/ #pragma once -// if buffer out range,will increase with INCREASE_BUFFER_SIZE size -#define INCREASE_BUFFER_SIZE 102400 -// vertex buffer max capacity -#define MAX_VB_BUFFER_SIZE 1024000 -// index buffer max capacity -#define MAX_IB_BUFFER_SIZE 1024000 +// index buffer init capacity +#define INIT_IB_BUFFER_SIZE 1024000 // can fill material data max capacity #define MAX_MATERIAL_BUFFER_SIZE 512 // fill debug data max capacity @@ -47,5 +43,5 @@ #define USING_NS_MW using namespace cocos2d::middleware #endif -#define VF_XYUVC 1 -#define VF_XYUVCC 2 +#define VF_XYUVC 5 +#define VF_XYUVCC 6 diff --git a/native/cocos/editor-support/MiddlewareManager.cpp b/native/cocos/editor-support/MiddlewareManager.cpp index d075a6e176..053e48f579 100644 --- a/native/cocos/editor-support/MiddlewareManager.cpp +++ b/native/cocos/editor-support/MiddlewareManager.cpp @@ -30,48 +30,37 @@ MIDDLEWARE_BEGIN MiddlewareManager* MiddlewareManager::_instance = nullptr; MiddlewareManager::MiddlewareManager() -:_ib(MAX_IB_BUFFER_SIZE) { - glGenBuffers(1, &_glIBID); - _vfList.push_back(VF_XYUVC); - _vfList.push_back(VF_XYUVCC); - - for(auto vf : _vfList) - { - glGenBuffers(1, &_glVBMap[vf]); - } } MiddlewareManager::~MiddlewareManager() { - cocos2d::ccDeleteBuffers(1, &_glIBID); - - for (auto vf : _vfList) + for (auto it : _mbMap) { - IOBuffer* buffer = _vbMap[vf]; + auto buffer = it.second; if (buffer) { delete buffer; } - cocos2d::ccDeleteBuffers(1, &_glVBMap[vf]); } + _mbMap.clear(); } -cocos2d::middleware::IOBuffer& MiddlewareManager::getVB(int format) +MeshBuffer* MiddlewareManager::getMeshBuffer(int format) { - auto buffer = _vbMap[format]; - if (buffer == nullptr) + MeshBuffer* mb = _mbMap[format]; + if (!mb) { - buffer = new IOBuffer(MAX_VB_BUFFER_SIZE); - _vbMap[format] = buffer; + mb = new MeshBuffer(format); + _mbMap[format] = mb; } - return *buffer; + return mb; } void MiddlewareManager::update(float dt) { - for (auto it : _vbMap) + for (auto it : _mbMap) { auto buffer = it.second; if (buffer) @@ -79,7 +68,6 @@ void MiddlewareManager::update(float dt) buffer->reset(); } } - _ib.reset(); isUpdating = true; @@ -114,22 +102,15 @@ void MiddlewareManager::update(float dt) _removeList.clear(); - for (auto it : _vbMap) + for (auto it : _mbMap) { auto buffer = it.second; - if (buffer && buffer->isOutRange()) + if (buffer) { - buffer->resize(buffer->getCapacity() + INCREASE_BUFFER_SIZE, true); + buffer->uploadIB(); + buffer->uploadVB(); } } - - if (_ib.isOutRange()) - { - _ib.resize(_ib.getCapacity() + INCREASE_BUFFER_SIZE, true); - } - - uploadVB(); - uploadIB(); } void MiddlewareManager::addTimer(IMiddleware* editor) @@ -157,46 +138,4 @@ void MiddlewareManager::removeTimer(IMiddleware* editor) } } } - -void MiddlewareManager::uploadVB() -{ - for(auto vf : _vfList) - { - IOBuffer* vb = _vbMap[vf]; - if (!vb) continue; - - uint32_t glVBID = _glVBMap[vf]; - if (glVBID == 0) - { - cocos2d::log("Vertex buffer is destroyed"); - continue; - } - - auto length = vb->length(); - if (length == 0) continue; - - cocos2d::ccBindBuffer(GL_ARRAY_BUFFER, glVBID); - glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)length, vb->getBuffer(), GL_DYNAMIC_DRAW); - cocos2d::ccBindBuffer(GL_ARRAY_BUFFER, 0); - } -} - -void MiddlewareManager::uploadIB() -{ - if (_glIBID == 0) - { - cocos2d::log("Index buffer is destroyed"); - return; - } - - auto length = _ib.length(); - if (length == 0) return; - - GLint _oldGLID = 0; - glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &_oldGLID); - - cocos2d::ccBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _glIBID); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)length, _ib.getBuffer(), GL_STATIC_DRAW); - cocos2d::ccBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _oldGLID); -} MIDDLEWARE_END diff --git a/native/cocos/editor-support/MiddlewareManager.h b/native/cocos/editor-support/MiddlewareManager.h index 724ac5c9e8..670f9bef68 100644 --- a/native/cocos/editor-support/MiddlewareManager.h +++ b/native/cocos/editor-support/MiddlewareManager.h @@ -23,7 +23,7 @@ ****************************************************************************/ #pragma once -#include "IOBuffer.h" +#include "MeshBuffer.h" #include #include #include "base/CCRef.h" @@ -83,28 +83,7 @@ public: */ void removeTimer(IMiddleware* editor); - /** - * @return opengl index buffer id - */ - uint32_t getGLIBID() const - { - return _glIBID; - } - - /** - * @return opengl vertex buffer id - */ - uint32_t getGLVBID(int format) - { - return _glVBMap[format]; - } - - cocos2d::middleware::IOBuffer& getVB(int format); - - cocos2d::middleware::IOBuffer& getIB() - { - return _ib; - } + MeshBuffer* getMeshBuffer(int format); MiddlewareManager(); ~MiddlewareManager(); @@ -112,19 +91,10 @@ public: // If manager is traversing _updateMap,will set the flag,untill traverse is finished. bool isUpdating = false; -private: - void uploadVB(); - void uploadIB(); private: std::map _updateMap; std::vector _removeList; - - uint32_t _glIBID = 0; - cocos2d::middleware::IOBuffer _ib; - - std::map _glVBMap; - std::map _vbMap; - std::vector _vfList; + std::map _mbMap; static MiddlewareManager* _instance; }; diff --git a/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp b/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp index eefc45ae21..969252dc0d 100644 --- a/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp +++ b/native/cocos/editor-support/dragonbones-creator-support/CCArmatureDisplay.cpp @@ -92,8 +92,9 @@ void CCArmatureDisplay::dbUpdate() auto mgr = MiddlewareManager::getInstance(); if (!mgr->isUpdating) return; - IOBuffer& vb = mgr->getVB(VF_XYUVC); - IOBuffer& ib = mgr->getIB(); + MeshBuffer* mb = mgr->getMeshBuffer(VF_XYUVC); + IOBuffer& vb = mb->getVB(); + IOBuffer& ib = mb->getIB(); _materialBuffer->reset(); @@ -226,11 +227,16 @@ void CCArmatureDisplay::traverseArmature(Armature* armature) { auto& slots = armature->getSlots(); auto mgr = MiddlewareManager::getInstance(); - IOBuffer& vb = mgr->getVB(VF_XYUVC); - IOBuffer& ib = mgr->getIB(); + MeshBuffer* mb = mgr->getMeshBuffer(VF_XYUVC); + IOBuffer& vb = mb->getVB(); + IOBuffer& ib = mb->getIB(); + int isFull = 0; for (std::size_t i = 0, len = slots.size(); i < len; i++) { + // Reset isFull flag. + isFull = 0; + CCSlot* slot = (CCSlot*)slots[i]; if (!slot->getVisible()) { @@ -271,8 +277,11 @@ void CCArmatureDisplay::traverseArmature(Armature* armature) if (!texture) continue; _curTextureIndex = texture->getRealTextureIndex(); + auto vbSize = slot->triangles.vertCount * sizeof(middleware::V2F_T2F_C4B); + isFull |= vb.checkSpace(vbSize, true); + // If texture or blendMode change,will change material. - if (_preTextureIndex != _curTextureIndex || _preBlendDst != _curBlendDst || _preBlendSrc != _curBlendSrc) + if (_preTextureIndex != _curTextureIndex || _preBlendDst != _curBlendDst || _preBlendSrc != _curBlendSrc || isFull) { if (_preISegWritePos != -1) { @@ -282,6 +291,10 @@ void CCArmatureDisplay::traverseArmature(Armature* armature) _materialBuffer->writeUint32(_curTextureIndex); _materialBuffer->writeUint32(_curBlendSrc); _materialBuffer->writeUint32(_curBlendDst); + auto glIB = mb->getGLIB(); + auto glVB = mb->getGLVB(); + _materialBuffer->writeUint32(glIB); + _materialBuffer->writeUint32(glVB); //Reserve indice segamentation count. _preISegWritePos = (int)_materialBuffer->getCurPos(); @@ -322,8 +335,6 @@ void CCArmatureDisplay::traverseArmature(Armature* armature) // Fill MiddlewareManager vertex buffer auto vertexOffset = vb.getCurPos() / sizeof(middleware::V2F_T2F_C4B); - auto vbSize = triangles.vertCount * sizeof(middleware::V2F_T2F_C4B); - vb.checkSpace(vbSize, true); vb.writeBytes((char*)worldTriangles, vbSize); auto ibSize = triangles.indexCount * sizeof(unsigned short); diff --git a/native/cocos/editor-support/dragonbones/core/DragonBones.cpp b/native/cocos/editor-support/dragonbones/core/DragonBones.cpp index 4df3f77b0f..0e6f53c5a9 100644 --- a/native/cocos/editor-support/dragonbones/core/DragonBones.cpp +++ b/native/cocos/editor-support/dragonbones/core/DragonBones.cpp @@ -13,11 +13,10 @@ bool DragonBones::yDown = true; bool DragonBones::debug = false; bool DragonBones::debugDraw = false; bool DragonBones::webAssembly = false; -bool DragonBones::checkInPool = false; +bool DragonBones::checkInPool = true; DragonBones::DragonBones(IEventDispatcher* eventManager) : _events(), - _objects(), _clock(nullptr), _eventManager(eventManager) { @@ -38,14 +37,16 @@ DragonBones::~DragonBones() void DragonBones::advanceTime(float passedTime) { - if (!_objects.empty()) + if (!_objectsMap.empty()) { - for (const auto object : _objects) + for (auto it = _objectsMap.begin(); it != _objectsMap.end(); it ++) { - object->returnToPool(); + auto object = it->first; + if (object) { + object->returnToPool(); + } } - - _objects.clear(); + _objectsMap.clear(); } if (!_events.empty()) @@ -80,11 +81,8 @@ void DragonBones::bufferEvent(EventObject* value) void DragonBones::bufferObject(BaseObject* object) { if(object == nullptr || object->isInPool())return; - auto it = std::find(_objects.begin(), _objects.end(), object); - if (it != _objects.end()) - { - _objects.push_back(object); - } + // Just mark object will be put in pool next frame, 'true' is useless. + _objectsMap[object] = true; } WorldClock* DragonBones::getClock() diff --git a/native/cocos/editor-support/dragonbones/core/DragonBones.h b/native/cocos/editor-support/dragonbones/core/DragonBones.h index 7a4537d4e4..fa5324d0d8 100644 --- a/native/cocos/editor-support/dragonbones/core/DragonBones.h +++ b/native/cocos/editor-support/dragonbones/core/DragonBones.h @@ -461,7 +461,7 @@ public: static bool checkInPool; private: - std::vector _objects; + std::map _objectsMap; std::vector _events; WorldClock* _clock; IEventDispatcher* _eventManager; diff --git a/native/cocos/editor-support/spine-creator-support/SpineRenderer.cpp b/native/cocos/editor-support/spine-creator-support/SpineRenderer.cpp index b70a90808f..050921aa8d 100644 --- a/native/cocos/editor-support/spine-creator-support/SpineRenderer.cpp +++ b/native/cocos/editor-support/spine-creator-support/SpineRenderer.cpp @@ -30,6 +30,7 @@ #include "platform/CCApplication.h" #include "base/CCScheduler.h" #include "MiddlewareMacro.h" +#include "MeshBuffer.h" USING_NS_CC; USING_NS_MW; @@ -281,8 +282,10 @@ void SpineRenderer::update (float deltaTime) Color4F darkColor; AttachmentVertices* attachmentVertices = nullptr; bool inRange = _startSlotIndex != -1 || _endSlotIndex != -1 ? false : true; - middleware::IOBuffer& vb = mgr->getVB(_useTint? VF_XYUVCC : VF_XYUVC); - middleware::IOBuffer& ib = mgr->getIB(); + auto vertexFormat = _useTint? VF_XYUVCC : VF_XYUVC; + MeshBuffer* mb = mgr->getMeshBuffer(vertexFormat); + middleware::IOBuffer& vb = mb->getVB(); + middleware::IOBuffer& ib = mb->getIB(); // vertex size in floats with one color int vs1 = sizeof(V2F_T2F_C4B) / sizeof(float); @@ -303,7 +306,8 @@ void SpineRenderer::update (float deltaTime) int debugSlotsLen = 0; int materialLen = 0; - + int isFull = 0; + if (_debugSlots || _debugBones) { // If enable debug draw,then init debug buffer. @@ -327,6 +331,8 @@ void SpineRenderer::update (float deltaTime) for (int i = 0, n = _skeleton->slotsCount; i < n; ++i) { + // Reset isFull flag. + isFull = 0; spSlot* slot = _skeleton->drawOrder[i]; if (_startSlotIndex >= 0 && _startSlotIndex == slot->data->index) { @@ -388,7 +394,7 @@ void SpineRenderer::update (float deltaTime) triangles.vertCount = attachmentVertices->_triangles->vertCount; vbSize = triangles.vertCount * sizeof(V2F_T2F_C4B); - vb.checkSpace(vbSize); + isFull |= vb.checkSpace(vbSize); triangles.verts = (V2F_T2F_C4B*)vb.getCurBuffer(); memcpy(triangles.verts, attachmentVertices->_triangles->verts, vbSize); spRegionAttachment_computeWorldVertices(attachment, slot->bone, (float*)triangles.verts, 0, vs1); @@ -404,7 +410,7 @@ void SpineRenderer::update (float deltaTime) trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount; vbSize = trianglesTwoColor.vertCount * sizeof(V2F_T2F_C4B_C4B); - vb.checkSpace(vbSize); + isFull |= vb.checkSpace(vbSize); trianglesTwoColor.verts = (V2F_T2F_C4B_C4B*)vb.getCurBuffer(); for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) { @@ -456,7 +462,7 @@ void SpineRenderer::update (float deltaTime) triangles.vertCount = attachmentVertices->_triangles->vertCount; vbSize = triangles.vertCount * sizeof(V2F_T2F_C4B); - vb.checkSpace(vbSize); + isFull |= vb.checkSpace(vbSize); triangles.verts = (V2F_T2F_C4B*)vb.getCurBuffer(); memcpy(triangles.verts, attachmentVertices->_triangles->verts, vbSize); spVertexAttachment_computeWorldVertices(SUPER(attachment), slot, 0, attachment->super.worldVerticesLength, (float*)triangles.verts, 0, vs1); @@ -472,7 +478,7 @@ void SpineRenderer::update (float deltaTime) trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount; vbSize = trianglesTwoColor.vertCount * sizeof(V2F_T2F_C4B_C4B); - vb.checkSpace(vbSize); + isFull |= vb.checkSpace(vbSize); trianglesTwoColor.verts = (V2F_T2F_C4B_C4B*)vb.getCurBuffer(); for (int ii = 0; ii < trianglesTwoColor.vertCount; ii++) { @@ -530,51 +536,6 @@ void SpineRenderer::update (float deltaTime) } darkColor.a = _premultipliedAlpha ? 255 : 0; - switch (slot->data->blendMode) - { - case SP_BLEND_MODE_ADDITIVE: - curBlendSrc = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; - curBlendDst = GL_ONE; - break; - case SP_BLEND_MODE_MULTIPLY: - curBlendSrc = GL_DST_COLOR; - curBlendDst = GL_ONE_MINUS_SRC_ALPHA; - break; - case SP_BLEND_MODE_SCREEN: - curBlendSrc = GL_ONE; - curBlendDst = GL_ONE_MINUS_SRC_COLOR; - break; - default: - curBlendSrc = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; - curBlendDst = GL_ONE_MINUS_SRC_ALPHA; - } - - curTextureIndex = attachmentVertices->_texture->getRealTextureIndex(); - // If texture or blendMode change,will change material. - if (preTextureIndex != curTextureIndex || preBlendDst != curBlendDst || preBlendSrc != curBlendSrc) - { - if (preISegWritePos != -1) - { - _materialBuffer->writeUint32(preISegWritePos, curISegLen); - } - - _materialBuffer->writeUint32(curTextureIndex); - _materialBuffer->writeUint32(curBlendSrc); - _materialBuffer->writeUint32(curBlendDst); - - //Reserve indice segamentation count. - preISegWritePos = (int)_materialBuffer->getCurPos(); - _materialBuffer->writeUint32(0); - - preTextureIndex = curTextureIndex; - preBlendDst = curBlendDst; - preBlendSrc = curBlendSrc; - - // Clear index segmentation count,prepare to next segmentation. - curISegLen = 0; - materialLen++; - } - // One color tint logic if (!_useTint) { @@ -591,7 +552,7 @@ void SpineRenderer::update (float deltaTime) triangles.vertCount = _clipper->clippedVertices->size >> 1; vbSize = triangles.vertCount * sizeof(V2F_T2F_C4B); - vb.checkSpace(vbSize); + isFull |= vb.checkSpace(vbSize); triangles.verts = (V2F_T2F_C4B*)vb.getCurBuffer(); triangles.indexCount = _clipper->clippedTriangles->size; @@ -643,7 +604,7 @@ void SpineRenderer::update (float deltaTime) trianglesTwoColor.vertCount = _clipper->clippedVertices->size >> 1; vbSize = trianglesTwoColor.vertCount * sizeof(V2F_T2F_C4B_C4B); - vb.checkSpace(vbSize); + isFull |= vb.checkSpace(vbSize); trianglesTwoColor.verts = (V2F_T2F_C4B_C4B*)vb.getCurBuffer(); trianglesTwoColor.indexCount = _clipper->clippedTriangles->size; @@ -689,6 +650,55 @@ void SpineRenderer::update (float deltaTime) } } + switch (slot->data->blendMode) + { + case SP_BLEND_MODE_ADDITIVE: + curBlendSrc = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; + curBlendDst = GL_ONE; + break; + case SP_BLEND_MODE_MULTIPLY: + curBlendSrc = GL_DST_COLOR; + curBlendDst = GL_ONE_MINUS_SRC_ALPHA; + break; + case SP_BLEND_MODE_SCREEN: + curBlendSrc = GL_ONE; + curBlendDst = GL_ONE_MINUS_SRC_COLOR; + break; + default: + curBlendSrc = _premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; + curBlendDst = GL_ONE_MINUS_SRC_ALPHA; + } + + curTextureIndex = attachmentVertices->_texture->getRealTextureIndex(); + // If texture or blendMode change,will change material. + if (preTextureIndex != curTextureIndex || preBlendDst != curBlendDst || preBlendSrc != curBlendSrc || isFull) + { + if (preISegWritePos != -1) + { + _materialBuffer->writeUint32(preISegWritePos, curISegLen); + } + + _materialBuffer->writeUint32(curTextureIndex); + _materialBuffer->writeUint32(curBlendSrc); + _materialBuffer->writeUint32(curBlendDst); + auto glIB = mb->getGLIB(); + auto glVB = mb->getGLVB(); + _materialBuffer->writeUint32(glIB); + _materialBuffer->writeUint32(glVB); + + //Reserve indice segamentation count. + preISegWritePos = (int)_materialBuffer->getCurPos(); + _materialBuffer->writeUint32(0); + + preTextureIndex = curTextureIndex; + preBlendDst = curBlendDst; + preBlendSrc = curBlendSrc; + + // Clear index segmentation count,prepare to next segmentation. + curISegLen = 0; + materialLen++; + } + if (vbSize > 0 && ibSize > 0) { auto vertexOffset = vb.getCurPos() / sizeof(middleware::V2F_T2F_C4B); @@ -722,13 +732,11 @@ void SpineRenderer::update (float deltaTime) _debugBuffer->writeFloat32(0, debugSlotsLen); } - bool isVBOutRange = vb.isOutRange(); - bool isIBOutRange = ib.isOutRange(); bool isMatOutRange = _materialBuffer->isOutRange(); // If vertex buffer or index buffer or material buffer out of range,then discard this time render // next time will enlarge vertex buffer or index buffer to fill the animation data. - if (isVBOutRange || isIBOutRange || isMatOutRange) + if (isMatOutRange) { _materialBuffer->writeUint32(0, 0); } diff --git a/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_editor_support_auto_api.js b/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_editor_support_auto_api.js index 0697d00da5..fd1330f701 100644 --- a/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_editor_support_auto_api.js +++ b/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_editor_support_auto_api.js @@ -104,18 +104,6 @@ Texture2D : function ( */ middleware.MiddlewareManager = { -/** - * @method getGLVBID - * @param {int} arg0 - * @return {unsigned int} - */ -getGLVBID : function ( -int -) -{ - return 0; -}, - /** * @method update * @param {float} arg0 @@ -126,16 +114,6 @@ float { }, -/** - * @method getGLIBID - * @return {unsigned int} - */ -getGLIBID : function ( -) -{ - return 0; -}, - /** * @method destroyInstance */ diff --git a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_editor_support_auto.cpp b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_editor_support_auto.cpp index ddad13d29a..ecf744e8de 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_editor_support_auto.cpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_editor_support_auto.cpp @@ -239,27 +239,6 @@ bool js_register_cocos2dx_editor_support_Texture2D(se::Object* obj) se::Object* __jsb_cocos2d_middleware_MiddlewareManager_proto = nullptr; se::Class* __jsb_cocos2d_middleware_MiddlewareManager_class = nullptr; -static bool js_cocos2dx_editor_support_MiddlewareManager_getGLVBID(se::State& s) -{ - cocos2d::middleware::MiddlewareManager* cobj = (cocos2d::middleware::MiddlewareManager*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_MiddlewareManager_getGLVBID : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 1) { - int arg0 = 0; - do { int32_t tmp = 0; ok &= seval_to_int32(args[0], &tmp); arg0 = (int)tmp; } while(false); - SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_MiddlewareManager_getGLVBID : Error processing arguments"); - unsigned int result = cobj->getGLVBID(arg0); - ok &= uint32_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_MiddlewareManager_getGLVBID : Error processing arguments"); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); - return false; -} -SE_BIND_FUNC(js_cocos2dx_editor_support_MiddlewareManager_getGLVBID) - static bool js_cocos2dx_editor_support_MiddlewareManager_update(se::State& s) { cocos2d::middleware::MiddlewareManager* cobj = (cocos2d::middleware::MiddlewareManager*)s.nativeThisObject(); @@ -279,24 +258,6 @@ static bool js_cocos2dx_editor_support_MiddlewareManager_update(se::State& s) } SE_BIND_FUNC(js_cocos2dx_editor_support_MiddlewareManager_update) -static bool js_cocos2dx_editor_support_MiddlewareManager_getGLIBID(se::State& s) -{ - cocos2d::middleware::MiddlewareManager* cobj = (cocos2d::middleware::MiddlewareManager*)s.nativeThisObject(); - SE_PRECONDITION2(cobj, false, "js_cocos2dx_editor_support_MiddlewareManager_getGLIBID : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 0) { - unsigned int result = cobj->getGLIBID(); - ok &= uint32_to_seval(result, &s.rval()); - SE_PRECONDITION2(ok, false, "js_cocos2dx_editor_support_MiddlewareManager_getGLIBID : Error processing arguments"); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; -} -SE_BIND_FUNC(js_cocos2dx_editor_support_MiddlewareManager_getGLIBID) - static bool js_cocos2dx_editor_support_MiddlewareManager_destroyInstance(se::State& s) { const auto& args = s.args(); @@ -358,9 +319,7 @@ bool js_register_cocos2dx_editor_support_MiddlewareManager(se::Object* obj) { auto cls = se::Class::create("MiddlewareManager", obj, nullptr, _SE(js_cocos2dx_editor_support_MiddlewareManager_constructor)); - cls->defineFunction("getGLVBID", _SE(js_cocos2dx_editor_support_MiddlewareManager_getGLVBID)); cls->defineFunction("update", _SE(js_cocos2dx_editor_support_MiddlewareManager_update)); - cls->defineFunction("getGLIBID", _SE(js_cocos2dx_editor_support_MiddlewareManager_getGLIBID)); cls->defineStaticFunction("destroyInstance", _SE(js_cocos2dx_editor_support_MiddlewareManager_destroyInstance)); cls->defineStaticFunction("getInstance", _SE(js_cocos2dx_editor_support_MiddlewareManager_getInstance)); cls->defineFinalizeFunction(_SE(js_cocos2d_middleware_MiddlewareManager_finalize)); diff --git a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_editor_support_auto.hpp b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_editor_support_auto.hpp index 8a5e9386ba..15d6788b86 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_editor_support_auto.hpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_editor_support_auto.hpp @@ -24,9 +24,7 @@ extern se::Class* __jsb_cocos2d_middleware_MiddlewareManager_class; bool js_register_cocos2d_middleware_MiddlewareManager(se::Object* obj); bool register_all_cocos2dx_editor_support(se::Object* obj); -SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_getGLVBID); SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_update); -SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_getGLIBID); SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_destroyInstance); SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_getInstance); SE_DECLARE_FUNC(js_cocos2dx_editor_support_MiddlewareManager_MiddlewareManager); diff --git a/native/package.json b/native/package.json index c930ff2083..b908f61424 100644 --- a/native/package.json +++ b/native/package.json @@ -24,4 +24,4 @@ "url": "https://github.com/cocos-creator/cocos2d-x-lite/issues" }, "homepage": "https://github.com/cocos-creator/cocos2d-x-lite#readme" -} \ No newline at end of file +} diff --git a/native/templates/cocos2dx_files.json b/native/templates/cocos2dx_files.json index 7dfcc3bf54..d49539b820 100644 --- a/native/templates/cocos2dx_files.json +++ b/native/templates/cocos2dx_files.json @@ -153,6 +153,8 @@ "cocos/editor-support/IOBuffer.h", "cocos/editor-support/IOTypedArray.cpp", "cocos/editor-support/IOTypedArray.h", + "cocos/editor-support/MeshBuffer.cpp", + "cocos/editor-support/MeshBuffer.h", "cocos/editor-support/MiddlewareMacro.h", "cocos/editor-support/MiddlewareManager.cpp", "cocos/editor-support/MiddlewareManager.h", diff --git a/native/tools/tojs/cocos2dx_editor_support.ini b/native/tools/tojs/cocos2dx_editor_support.ini index 2725910f7f..c722bc9825 100644 --- a/native/tools/tojs/cocos2dx_editor_support.ini +++ b/native/tools/tojs/cocos2dx_editor_support.ini @@ -28,7 +28,7 @@ classes = Texture2D MiddlewareManager classes_need_extend = -skip = MiddlewareManager::[addTimer removeTimer getVB getIB] +skip = MiddlewareManager::[addTimer removeTimer getMeshBuffer] remove_prefix = From 0141a98b3218e1badbe50c3f2c27ab383b178508 Mon Sep 17 00:00:00 2001 From: ColinCollins <35832931+ColinCollins@users.noreply.github.com> Date: Wed, 13 Feb 2019 12:41:42 +0800 Subject: [PATCH 2/8] modify the picture format convert method (#1677) --- .../scripting/js-bindings/manual/jsb_global.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp index 255caddf94..9859ffddd9 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp @@ -723,7 +723,7 @@ namespace bool freeData = false; }; - uint8_t* cvRGB2RGBA (uint32_t length, uint8_t* src) { + uint8_t* convertRGB2RGBA (uint32_t length, uint8_t* src) { uint8_t* dst = new uint8_t[length]; for (uint32_t i = 0; i < length; i += 4) { dst[i] = *src++; @@ -734,7 +734,7 @@ namespace return dst; } - uint8_t* cvIA2RGBA (uint32_t length, uint8_t* src) { + uint8_t* convertIA2RGBA (uint32_t length, uint8_t* src) { uint8_t* dst = new uint8_t[length]; for (uint32_t i = 0; i < length; i += 4) { dst[i] = *src; @@ -745,7 +745,7 @@ namespace return dst; } - uint8_t* cvI2RGBA (uint32_t length, uint8_t* src) { + uint8_t* convertI2RGBA (uint32_t length, uint8_t* src) { uint8_t* dst = new uint8_t[length]; for (uint32_t i = 0; i < length; i += 4) { dst[i] = *src; @@ -787,17 +787,18 @@ namespace switch(imgInfo->glFormat) { case GL_RGBA: break; case GL_LUMINANCE_ALPHA: - dst = cvIA2RGBA(length, src); + dst = convertIA2RGBA(length, src); break; case GL_ALPHA: case GL_LUMINANCE: - dst = cvI2RGBA(length, src); + dst = convertI2RGBA(length, src); break; case GL_RGB: - dst = cvRGB2RGBA(length, src); + dst = convertRGB2RGBA(length, src); break; default: SE_LOGE("unknown image format"); + break; } if (imgInfo->glFormat != GL_RGBA) { From 9c18b3a404999cb4d2f634f766c12548ae5f406b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=BA=E6=98=8E?= Date: Thu, 14 Feb 2019 17:05:09 +0800 Subject: [PATCH 3/8] support app bundle for instant app (#1673) * upgrade gradle and gradle tools version to support app bundle * upgrade gradle * support app bundle for android instant --- .../runtime-src/proj.android-studio/game/AndroidManifest.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/AndroidManifest.xml b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/AndroidManifest.xml index 273d6daf38..a25febf16c 100644 --- a/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/AndroidManifest.xml +++ b/native/templates/js-template-android-instant/frameworks/runtime-src/proj.android-studio/game/AndroidManifest.xml @@ -1,8 +1,9 @@ - + Date: Thu, 14 Feb 2019 17:06:33 +0800 Subject: [PATCH 4/8] fixed the png render error (#1678) --- native/cocos/scripting/js-bindings/manual/jsb_global.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp index 9859ffddd9..d92c8a8671 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp @@ -740,7 +740,7 @@ namespace dst[i] = *src; dst[i + 1] = *src; dst[i + 2] = *src++; - dst[i + 3] = *src; + dst[i + 3] = *src++; } return dst; } From 9b5525bdb54d61296a8646c19a602671e490ad43 Mon Sep 17 00:00:00 2001 From: ColinCollins <35832931+ColinCollins@users.noreply.github.com> Date: Fri, 15 Feb 2019 14:36:36 +0800 Subject: [PATCH 5/8] fixed the compressed texture error (#1679) copy image data size doesn't match the compress data size --- .../js-bindings/manual/jsb_global.cpp | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp index d92c8a8671..fb2264c35d 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp @@ -774,34 +774,33 @@ namespace imgInfo->hasAlpha = img->hasAlpha(); imgInfo->hasPremultipliedAlpha = img->hasPremultipliedAlpha(); imgInfo->compressed = img->isCompressed(); - imgInfo->length = img->getWidth() * img->getHeight() * 4; // Convert to RGBA888 because standard web api will return only RGBA888. // If not, then it may have issue in glTexSubImage. For example, engine // will create a big texture, and update its content with small pictures. // The big texture is RGBA888, then the small picture should be the same // format, or it will cause 0x502 error on OpenGL ES 2. - uint8_t* dst = nullptr; - uint32_t length = imgInfo->length; - uint8_t* src = imgInfo->data; - switch(imgInfo->glFormat) { - case GL_RGBA: break; - case GL_LUMINANCE_ALPHA: - dst = convertIA2RGBA(length, src); - break; - case GL_ALPHA: - case GL_LUMINANCE: - dst = convertI2RGBA(length, src); - break; - case GL_RGB: - dst = convertRGB2RGBA(length, src); - break; - default: - SE_LOGE("unknown image format"); - break; - } + if (!imgInfo->compressed && imgInfo.glFormat != GL_RGBA) { + imgInfo->length = img->getWidth() * img->getHeight() * 4; + uint8_t* dst = nullptr; + uint32_t length = imgInfo->length; + uint8_t* src = imgInfo->data; + switch(imgInfo->glFormat) { + case GL_LUMINANCE_ALPHA: + dst = convertIA2RGBA(length, src); + break; + case GL_ALPHA: + case GL_LUMINANCE: + dst = convertI2RGBA(length, src); + break; + case GL_RGB: + dst = convertRGB2RGBA(length, src); + break; + default: + SE_LOGE("unknown image format"); + break; + } - if (imgInfo->glFormat != GL_RGBA) { imgInfo->data = dst; imgInfo->hasAlpha = true; imgInfo->bpp = 32; From c4f66291749ca328ac37ffc0f28833c40aa9a872 Mon Sep 17 00:00:00 2001 From: ColinCollins <35832931+ColinCollins@users.noreply.github.com> Date: Fri, 15 Feb 2019 15:51:43 +0800 Subject: [PATCH 6/8] my fault fixed the gammar error (#1680) --- native/cocos/scripting/js-bindings/manual/jsb_global.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp index fb2264c35d..d337e767e2 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_global.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_global.cpp @@ -780,7 +780,7 @@ namespace // will create a big texture, and update its content with small pictures. // The big texture is RGBA888, then the small picture should be the same // format, or it will cause 0x502 error on OpenGL ES 2. - if (!imgInfo->compressed && imgInfo.glFormat != GL_RGBA) { + if (!imgInfo->compressed && imgInfo->glFormat != GL_RGBA) { imgInfo->length = img->getWidth() * img->getHeight() * 4; uint8_t* dst = nullptr; uint32_t length = imgInfo->length; From ae996e1fcea165070356e93f1a426ed3392356b3 Mon Sep 17 00:00:00 2001 From: leda Date: Mon, 18 Feb 2019 15:50:18 +0800 Subject: [PATCH 7/8] fix potential crash on websocket for lifecycle sync issues (#1681) --- native/cocos/scripting/js-bindings/manual/jsb_websocket.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/cocos/scripting/js-bindings/manual/jsb_websocket.cpp b/native/cocos/scripting/js-bindings/manual/jsb_websocket.cpp index b3722f5a50..6fab3ad961 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_websocket.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_websocket.cpp @@ -332,7 +332,7 @@ static bool WebSocket_constructor(se::State& s) JSB_WebSocketDelegate* delegate = new (std::nothrow) JSB_WebSocketDelegate(); if (cobj->init(*delegate, url, &protocols, caFilePath)) { - delegate->setJSDelegate(se::Value(obj)); + delegate->setJSDelegate(se::Value(obj, true)); cobj->retain(); // release in finalize function and onClose delegate method delegate->retain(); // release in finalize function and onClose delegate method } @@ -350,7 +350,7 @@ static bool WebSocket_constructor(se::State& s) JSB_WebSocketDelegate* delegate = new (std::nothrow) JSB_WebSocketDelegate(); if (cobj->init(*delegate, url)) { - delegate->setJSDelegate(se::Value(obj)); + delegate->setJSDelegate(se::Value(obj, true)); cobj->retain(); // release in finalize function and onClose delegate method delegate->retain(); // release in finalize function and onClose delegate method } From 3944c338ec8b8170c32abf977f62260613d9801c Mon Sep 17 00:00:00 2001 From: leda Date: Wed, 20 Feb 2019 16:16:25 +0800 Subject: [PATCH 8/8] fix fillRect issues for iOS & macOS (#1682) --- .../apple/CCCanvasRenderingContext2D-apple.mm | 42 ++++++------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/native/cocos/platform/apple/CCCanvasRenderingContext2D-apple.mm b/native/cocos/platform/apple/CCCanvasRenderingContext2D-apple.mm index 34cb67c4b9..af015f245e 100644 --- a/native/cocos/platform/apple/CCCanvasRenderingContext2D-apple.mm +++ b/native/cocos/platform/apple/CCCanvasRenderingContext2D-apple.mm @@ -36,28 +36,6 @@ enum class CanvasTextBaseline { BOTTOM }; -namespace { - void fillRectWithColor(uint8_t* buf, uint32_t totalWidth, uint32_t totalHeight, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint8_t r, uint8_t g, uint8_t b) - { - if ((x + width) > totalWidth || (y + height) > totalHeight) - return; - - uint32_t y0 = totalHeight - (y + height); - uint32_t y1 = totalHeight - y; - uint8_t* p; - for (uint32_t offsetY = y0; offsetY < y1; ++offsetY) - { - for (uint32_t offsetX = x; offsetX < (x + width); ++offsetX) - { - p = buf + (totalWidth * offsetY + offsetX) * 3; - *p++ = r; - *p++ = g; - *p++ = b; - } - } - } -} - @interface CanvasRenderingContext2DImpl : NSObject { NSFont* _font; NSMutableDictionary* _tokenAttributesDict; @@ -456,14 +434,18 @@ namespace { } -(void) fillRect:(CGRect) rect { - uint8_t* buffer = _imageData.getBytes(); - if (buffer) - { - uint8_t r = _fillStyle.r * 255.0f; - uint8_t g = _fillStyle.g * 255.0f; - uint8_t b = _fillStyle.b * 255.0f; - fillRectWithColor(buffer, (uint32_t)_width, (uint32_t)_height, (uint32_t)rect.origin.x, (uint32_t)rect.origin.y, (uint32_t)rect.size.width, (uint32_t)rect.size.height, r, g, b); - } + [self saveContext]; + + NSColor* color = [NSColor colorWithRed:_fillStyle.r green:_fillStyle.g blue:_fillStyle.b alpha:_fillStyle.a]; + [color setFill]; +#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC + CGRect tmpRect = CGRectMake(rect.origin.x, _height - rect.origin.y - rect.size.height, rect.size.width, rect.size.height); + [NSBezierPath fillRect:tmpRect]; +#else + NSBezierPath* path = [NSBezierPath bezierPathWithRect:rect]; + [path fill]; +#endif + [self restoreContext]; } -(void) saveContext {