mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-05 19:12:40 +08:00
Merge branch 'v2.0-release' of github.com:cocos-creator/cocos2d-x-lite into v2.1-release
This commit is contained in:
@@ -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 = "<group>"; };
|
||||
04AF62FD219190ED00AED9DE /* TypedArrayPool.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = TypedArrayPool.cpp; path = "../cocos/editor-support/TypedArrayPool.cpp"; sourceTree = "<group>"; };
|
||||
04AF62FE219190ED00AED9DE /* TypedArrayPool.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TypedArrayPool.h; path = "../cocos/editor-support/TypedArrayPool.h"; sourceTree = "<group>"; };
|
||||
04ED68D621F8188F006E82F8 /* MeshBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = MeshBuffer.cpp; path = "../cocos/editor-support/MeshBuffer.cpp"; sourceTree = "<group>"; };
|
||||
04ED68D721F8188F006E82F8 /* MeshBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MeshBuffer.h; path = "../cocos/editor-support/MeshBuffer.h"; sourceTree = "<group>"; };
|
||||
051C016F21E2F85C00D4A347 /* CCModuleConfigIOS.debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CCModuleConfigIOS.debug.xcconfig; sourceTree = "<group>"; };
|
||||
051C017021E2F85C00D4A347 /* CCModuleConfigIOS.release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CCModuleConfigIOS.release.xcconfig; sourceTree = "<group>"; };
|
||||
051C017121E2F86900D4A347 /* CCModuleConfigMac.release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CCModuleConfigMac.release.xcconfig; sourceTree = "<group>"; };
|
||||
@@ -1906,6 +1912,8 @@
|
||||
046B688E21A00F5600B33469 /* IOTypedArray.cpp */,
|
||||
046B688F21A00F5600B33469 /* IOTypedArray.h */,
|
||||
046B689421A10D5800B33469 /* MiddlewareMacro.h */,
|
||||
04ED68D621F8188F006E82F8 /* MeshBuffer.cpp */,
|
||||
04ED68D721F8188F006E82F8 /* MeshBuffer.h */,
|
||||
);
|
||||
name = "editor-support";
|
||||
sourceTree = "<group>";
|
||||
@@ -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 */,
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
<ClCompile Include="..\cocos\editor-support\dragonbones\parser\BinaryDataParser.cpp" />
|
||||
<ClCompile Include="..\cocos\editor-support\dragonbones\parser\DataParser.cpp" />
|
||||
<ClCompile Include="..\cocos\editor-support\dragonbones\parser\JSONDataParser.cpp" />
|
||||
<ClCompile Include="..\cocos\editor-support\MeshBuffer.cpp" />
|
||||
<ClCompile Include="..\cocos\editor-support\middleware-adapter.cpp" />
|
||||
<ClCompile Include="..\cocos\editor-support\MiddlewareManager.cpp" />
|
||||
<ClCompile Include="..\cocos\editor-support\IOBuffer.cpp" />
|
||||
@@ -323,6 +324,7 @@
|
||||
<ClInclude Include="..\cocos\editor-support\dragonbones\parser\DataParser.h" />
|
||||
<ClInclude Include="..\cocos\editor-support\dragonbones\parser\JSONDataParser.h" />
|
||||
<ClInclude Include="..\cocos\editor-support\IOBuffer.h" />
|
||||
<ClInclude Include="..\cocos\editor-support\MeshBuffer.h" />
|
||||
<ClInclude Include="..\cocos\editor-support\middleware-adapter.h" />
|
||||
<ClInclude Include="..\cocos\editor-support\MiddlewareMacro.h" />
|
||||
<ClInclude Include="..\cocos\editor-support\MiddlewareManager.h" />
|
||||
|
||||
@@ -680,6 +680,9 @@
|
||||
<ClCompile Include="..\cocos\editor-support\spine\PathConstraintData.c">
|
||||
<Filter>editor-support\spine</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\cocos\editor-support\MeshBuffer.cpp">
|
||||
<Filter>editor-support</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\cocos\base\base64.h">
|
||||
@@ -1508,6 +1511,9 @@
|
||||
<ClInclude Include="..\cocos\editor-support\spine\PathConstraintData.h">
|
||||
<Filter>editor-support\spine</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cocos\editor-support\MeshBuffer.h">
|
||||
<Filter>editor-support</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="base">
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <string>
|
||||
#include "MiddlewareMacro.h"
|
||||
#include <math.h>
|
||||
#include <functional>
|
||||
|
||||
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<void()> 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
|
||||
|
||||
@@ -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
|
||||
@@ -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 <vector>
|
||||
|
||||
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<uint32_t> _glIBArr;
|
||||
std::vector<uint32_t> _glVBArr;
|
||||
|
||||
std::size_t _bufferPos = 0;
|
||||
IOBuffer _vb;
|
||||
IOBuffer _ib;
|
||||
};
|
||||
|
||||
MIDDLEWARE_END
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "IOBuffer.h"
|
||||
#include "MeshBuffer.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#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<IMiddleware*, bool> _updateMap;
|
||||
std::vector<IMiddleware*> _removeList;
|
||||
|
||||
uint32_t _glIBID = 0;
|
||||
cocos2d::middleware::IOBuffer _ib;
|
||||
|
||||
std::map<int, uint32_t> _glVBMap;
|
||||
std::map<int, cocos2d::middleware::IOBuffer*> _vbMap;
|
||||
std::vector<int> _vfList;
|
||||
std::map<int, MeshBuffer*> _mbMap;
|
||||
|
||||
static MiddlewareManager* _instance;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -461,7 +461,7 @@ public:
|
||||
static bool checkInPool;
|
||||
|
||||
private:
|
||||
std::vector<BaseObject*> _objects;
|
||||
std::map<BaseObject*,bool> _objectsMap;
|
||||
std::vector<EventObject*> _events;
|
||||
WorldClock* _clock;
|
||||
IEventDispatcher* _eventManager;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,18 +734,18 @@ 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;
|
||||
dst[i + 1] = *src;
|
||||
dst[i + 2] = *src++;
|
||||
dst[i + 3] = *src;
|
||||
dst[i + 3] = *src++;
|
||||
}
|
||||
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;
|
||||
@@ -774,33 +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 = cvIA2RGBA(length, src);
|
||||
break;
|
||||
case GL_ALPHA:
|
||||
case GL_LUMINANCE:
|
||||
dst = cvI2RGBA(length, src);
|
||||
break;
|
||||
case GL_RGB:
|
||||
dst = cvRGB2RGBA(length, src);
|
||||
break;
|
||||
default:
|
||||
SE_LOGE("unknown image format");
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,4 +24,4 @@
|
||||
"url": "https://github.com/cocos-creator/cocos2d-x-lite/issues"
|
||||
},
|
||||
"homepage": "https://github.com/cocos-creator/cocos2d-x-lite#readme"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="org.cocos2dx.javascript">
|
||||
|
||||
<dist:module dist:instant="true" />
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
||||
@@ -28,7 +28,7 @@ classes = Texture2D MiddlewareManager
|
||||
|
||||
classes_need_extend =
|
||||
|
||||
skip = MiddlewareManager::[addTimer removeTimer getVB getIB]
|
||||
skip = MiddlewareManager::[addTimer removeTimer getMeshBuffer]
|
||||
|
||||
remove_prefix =
|
||||
|
||||
|
||||
Reference in New Issue
Block a user