初始化

This commit is contained in:
SmallMain
2022-06-25 00:23:03 +08:00
commit ef0589e8e5
2264 changed files with 617829 additions and 0 deletions

View File

@@ -0,0 +1,285 @@
/****************************************************************************
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 "Assembler.hpp"
#include "../NodeProxy.hpp"
#include "../ModelBatcher.hpp"
#include "../MeshBuffer.hpp"
#include "../../renderer/Scene.h"
#include "math/CCMath.h"
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
#include "cocos/scripting/js-bindings/manual/jsb_conversions.hpp"
#include "cocos/scripting/js-bindings/auto/jsb_renderer_auto.hpp"
#include "../RenderFlow.hpp"
RENDERER_BEGIN
Assembler::IARenderData::IARenderData()
{
}
Assembler::IARenderData::IARenderData(const IARenderData& o)
{
meshIndex = o.meshIndex;
verticesStart = o.verticesStart;
verticesCount = o.verticesCount;
indicesStart = o.indicesStart;
indicesCount = o.indicesCount;
setEffect(o.getEffect());
}
Assembler::IARenderData::~IARenderData()
{
CC_SAFE_RELEASE(_effect);
}
void Assembler::IARenderData::setEffect(EffectVariant* effect)
{
if (effect == _effect) return;
CC_SAFE_RELEASE(_effect);
_effect = effect;
CC_SAFE_RETAIN(_effect);
}
EffectVariant* Assembler::IARenderData::getEffect() const
{
return _effect;
}
Assembler::Assembler()
{
}
Assembler::~Assembler()
{
CC_SAFE_RELEASE_NULL(_datas);
CC_SAFE_RELEASE(_vfmt);
}
void Assembler::updateMeshIndex(std::size_t iaIndex, int meshIndex)
{
if (iaIndex >= _iaDatas.size())
{
_iaDatas.resize(iaIndex + 1);
}
IARenderData& ia = _iaDatas[iaIndex];
ia.meshIndex = meshIndex;
}
void Assembler::updateIndicesRange(std::size_t iaIndex, int start, int count)
{
if (iaIndex >= _iaDatas.size())
{
_iaDatas.resize(iaIndex + 1);
}
IARenderData& ia = _iaDatas[iaIndex];
ia.indicesStart = start;
ia.indicesCount = count;
}
void Assembler::updateVerticesRange(std::size_t iaIndex, int start, int count)
{
if (iaIndex >= _iaDatas.size())
{
_iaDatas.resize(iaIndex + 1);
}
IARenderData& ia = _iaDatas[iaIndex];
ia.verticesStart = start;
ia.verticesCount = count;
enableDirty(AssemblerBase::VERTICES_OPACITY_CHANGED);
}
void Assembler::updateEffect(std::size_t iaIndex, EffectVariant* effect)
{
if (iaIndex >= _iaDatas.size())
{
_iaDatas.resize(iaIndex + 1);
}
IARenderData& ia = _iaDatas[iaIndex];
ia.setEffect(effect);
}
void Assembler::reset()
{
_iaDatas.clear();
}
void Assembler::handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene)
{
batcher->commit(node, this, node->getCullingMask());
}
void Assembler::fillBuffers(NodeProxy* node, ModelBatcher* batcher, std::size_t index)
{
if(!_datas || !_vfmt)
{
return;
}
MeshBuffer* buffer = batcher->getBuffer(_vfmt);
const IARenderData& ia = _iaDatas[index];
std::size_t meshIndex = ia.meshIndex >= 0 ? ia.meshIndex : index;
RenderData* data = _datas->getRenderData(meshIndex);
if (!data)
{
return;
}
CCASSERT(data->getVBytes() % _bytesPerVertex == 0, "Assembler::fillBuffers vertices data doesn't follow vertex format");
uint32_t vertexCount = ia.verticesCount >= 0 ? (uint32_t)ia.verticesCount : (uint32_t)data->getVBytes() / _bytesPerVertex;
uint32_t indexCount = ia.indicesCount >= 0 ? (uint32_t)ia.indicesCount : (uint32_t)data->getIBytes() / sizeof(unsigned short);
uint32_t vertexStart = (uint32_t)ia.verticesStart;
// must retrieve offset before request
auto& bufferOffset = buffer->request(vertexCount, indexCount);
uint32_t vBufferOffset = bufferOffset.vByte / sizeof(float);
uint32_t indexId = bufferOffset.index;
uint32_t vertexId = bufferOffset.vertex;
uint32_t vertexOffset = vertexId - vertexStart;
uint32_t num = _vfPos->num;
float* worldVerts = buffer->vData + vBufferOffset;
memcpy(worldVerts, data->getVertices() + vertexStart * _bytesPerVertex, vertexCount * _bytesPerVertex);
// Calculate vertices world positions
if (!_useModel && !_ignoreWorldMatrix)
{
size_t dataPerVertex = _bytesPerVertex / sizeof(float);
float* ptrPos = worldVerts + _posOffset;
auto& worldMat = node->getWorldMatrix();
switch (num) {
// Vertex is X Y Z Format
case 3:
for (uint32_t i = 0; i < vertexCount; ++i)
{
((cocos2d::Vec3*)ptrPos)->transformMat4(*((cocos2d::Vec3*)ptrPos), worldMat);
ptrPos += dataPerVertex;
}
break;
// Vertex is X Y Format
case 2:
for (uint32_t i = 0; i < vertexCount; ++i)
{
float z = ptrPos[2];
ptrPos[2] = 0;
worldMat.transformPoint((cocos2d::Vec3*)ptrPos);
ptrPos[2] = z;
ptrPos += dataPerVertex;
}
break;
}
}
// Copy index buffer with vertex offset
uint16_t* indices = (uint16_t*)data->getIndices();
uint16_t* dst = buffer->iData;
for (auto i = 0, j = ia.indicesStart; i < indexCount; ++i, ++j)
{
dst[indexId++] = vertexOffset + indices[j];
}
}
void Assembler::setVertexFormat(VertexFormat* vfmt)
{
if (_vfmt == vfmt) return;
CC_SAFE_RETAIN(vfmt);
CC_SAFE_RELEASE(_vfmt);
_vfmt = vfmt;
if (_vfmt)
{
_bytesPerVertex = _vfmt->getBytes();
_vfPos = _vfmt->getElement(ATTRIB_NAME_POSITION_HASH);
_posOffset = _vfPos->offset / 4;
_vfColor = _vfmt->getElement(ATTRIB_NAME_COLOR_HASH);
if (_vfColor != nullptr)
{
_alphaOffset = _vfColor->offset + 3;
}
}
}
void Assembler::setRenderDataList(RenderDataList* datas)
{
if (_datas == datas) return;
CC_SAFE_RELEASE(_datas);
_datas = datas;
CC_SAFE_RETAIN(_datas);
}
void Assembler::updateOpacity(std::size_t index, uint8_t opacity)
{
// has no color info in vertex buffer
if(!_vfColor || !_datas || !_vfmt)
{
return;
}
const IARenderData& ia = _iaDatas[index];
std::size_t meshIndex = ia.meshIndex >= 0 ? ia.meshIndex : index;
RenderData* data = _datas->getRenderData(meshIndex);
if (!data)
{
return;
}
CCASSERT(data->getVBytes() % _bytesPerVertex == 0, "Assembler::updateOpacity vertices data doesn't follow vertex format");
uint32_t vertexCount = (uint32_t)data->getVBytes() / _bytesPerVertex;
size_t dataPerVertex = _bytesPerVertex / sizeof(uint8_t);
uint8_t* ptrAlpha = (uint8_t*)data->getVertices() + _alphaOffset;
const Vector<Pass*>& passes = ia.getEffect()->getPasses();
if (passes.at(0)->getBlendSrc() == BlendFactor::ONE)
{
float alpha = opacity / 255.0;
for (uint32_t i = 0; i < vertexCount; ++i)
{
*(ptrAlpha-1) *= alpha;
*(ptrAlpha-2) *= alpha;
*(ptrAlpha-3) *= alpha;
*ptrAlpha = opacity;
ptrAlpha += dataPerVertex;
}
}
else
{
for (uint32_t i = 0; i < vertexCount; ++i)
{
*ptrAlpha = opacity;
ptrAlpha += dataPerVertex;
}
}
*_dirty &= ~VERTICES_OPACITY_CHANGED;
}
RENDERER_END

View File

@@ -0,0 +1,202 @@
/****************************************************************************
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 "../../Macro.h"
#include "AssemblerBase.hpp"
#include "../MeshBuffer.hpp"
#include "math/CCMath.h"
#include "../../renderer/Effect.h"
#include "RenderDataList.hpp"
#include "../../renderer/EffectVariant.hpp"
namespace se {
class Object;
class HandleObject;
}
RENDERER_BEGIN
class NodeProxy;
class ModelBatcher;
/**
* @addtogroup scene
* @{
*/
class Assembler : public AssemblerBase
{
public:
class IARenderData {
public:
IARenderData();
IARenderData(const IARenderData& o);
~IARenderData();
void setEffect(EffectVariant* effect);
EffectVariant* getEffect() const;
private:
EffectVariant* _effect = nullptr;
public:
int meshIndex = -1;
int verticesStart = 0;
int verticesCount = -1;
int indicesStart = 0;
int indicesCount = -1;
};
Assembler();
virtual ~Assembler();
/*
* @brief Commit the current render handle to ModelBatcher
*/
virtual void handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override;
/*
* @brief Do nothing
*/
virtual void postHandle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override {}
/*
* @brief before fill buffers handle
*/
virtual void beforeFillBuffers(std::size_t index) {}
/*
* @brief Fills render data in given index to the MeshBuffer
* @param[in] buffer The shared mesh buffer
* @param[in] index The index of render data to be updated
* @param[in] node
*/
virtual void fillBuffers(NodeProxy* node, ModelBatcher* batcher, std::size_t index);
/**
* @brief Sets IArenderDataList
*/
virtual void setRenderDataList(RenderDataList* datas);
/**
* @brief Gets the vertex format.
*/
VertexFormat* getVertexFormat() const { return _vfmt; };
/**
* @brief Sets the vertex format.
*/
virtual void setVertexFormat(VertexFormat* vfmt);
/*
* @brief Update local render buffer opacity
* @param[in] index The index of render data to be updated
* @param[in] opacity Inherit opacity
*/
virtual void updateOpacity(std::size_t index, uint8_t opacity);
/**
* @brief ignore opacity flag, it will always not update vertices opacity
*/
void ignoreOpacityFlag() { _ignoreOpacityFlag = true; }
/**
* @brief Is ignore opacity.
* @return _ignoreOpacityFlag
*/
bool isIgnoreOpacityFlag() { return _ignoreOpacityFlag; }
/**
* @brief Enable ignore world matrix.
*/
void ignoreWorldMatrix() { _ignoreWorldMatrix = true; }
/**
* @brief Is ignore world matrix.
* @return _opacityAlwaysDirty
*/
bool isIgnoreWorldMatrix() { return _ignoreWorldMatrix; }
/**
* @brief Updates mesh index
*/
void updateMeshIndex(std::size_t iaIndex, int meshIndex);
/**
* @brief Updates indices range
*/
void updateIndicesRange(std::size_t iaIndex, int start, int count);
/**
* @brief Updates vertices range
*/
void updateVerticesRange(std::size_t iaIndex, int start, int count);
/**
* @brief Update the material for the given index.
* @param[in] iaIndex Render data index.
* @param[in] effect Effect pointer.
*/
virtual void updateEffect(std::size_t iaIndex, EffectVariant* effect);
/**
* @brief Resets ia data.
*/
virtual void reset() override;
/**
* @brief Gets the material for the given index.
* @param[in] index Render data index.
* @return Effect pointer.
*/
inline EffectVariant* getEffect(std::size_t index) const
{
if (index >= _iaDatas.size())
{
return nullptr;
}
return _iaDatas[index].getEffect();
}
/**
* @brief Gets Effect count.
* @return Count.
*/
inline std::size_t getIACount() const
{
return _iaDatas.size();
}
protected:
RenderDataList* _datas = nullptr;
std::vector<IARenderData> _iaDatas;
uint32_t _bytesPerVertex = 0;
size_t _posOffset = 0;
size_t _alphaOffset = 0;
VertexFormat* _vfmt = nullptr;
const VertexFormat::Element* _vfPos = nullptr;
const VertexFormat::Element* _vfColor = nullptr;
bool _ignoreWorldMatrix = false;
bool _ignoreOpacityFlag = false;
};
// end of scene group
/// @}
RENDERER_END

View File

@@ -0,0 +1,69 @@
/****************************************************************************
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 "AssemblerBase.hpp"
RENDERER_BEGIN
AssemblerBase::AssemblerBase()
{
}
AssemblerBase::~AssemblerBase()
{
if (_jsDirty)
{
_jsDirty->unroot();
_jsDirty->decRef();
_jsDirty = nullptr;
}
_dirty = nullptr;
_dirtyLen = 0;
clearCustomWorldMatirx();
}
void AssemblerBase::setDirty(se_object_ptr jsDirty)
{
if (_jsDirty == jsDirty) return;
if (_jsDirty)
{
_jsDirty->unroot();
_jsDirty->decRef();
_jsDirty = nullptr;
}
if (jsDirty == nullptr) return;
_jsDirty = jsDirty;
_jsDirty->root();
_jsDirty->incRef();
_dirty = nullptr;
_dirtyLen = 0;
_jsDirty->getTypedArrayData((uint8_t**)&_dirty, &_dirtyLen);
}
RENDERER_END

View File

@@ -0,0 +1,180 @@
/****************************************************************************
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 "../../Macro.h"
#include <stdint.h>
#include "base/CCVector.h"
#include "../../renderer/Effect.h"
#include "scripting/js-bindings/jswrapper/Object.hpp"
#include "math/Mat4.h"
RENDERER_BEGIN
class NodeProxy;
class ModelBatcher;
class Scene;
/**
* @addtogroup scene
* @{
*/
/**
* @brief Base class for all assembler
* A assembler could take actions during node visit process, before and after all children visit.
*/
class AssemblerBase: public cocos2d::Ref
{
public:
enum AssemblerFlag {
VERTICES_OPACITY_CHANGED = 1 << 0,
VERTICES_DIRTY = 1 << 1,
};
AssemblerBase();
virtual ~AssemblerBase();
/**
* @brief Callback which will be invoked before visiting child nodes.
* @param[in] node The node being processed.
* @param[in] batcher
* @param[in] scene
*/
virtual void handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) {}
/**
* @brief Callback which will be invoked after visiting child nodes.
* @param[in] node The node being processed.
* @param[in] batcher
* @param[in] scene
*/
virtual void postHandle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) {}
/**
* @brief Gets whether the current handle should use model matrix uniform during rendering
*/
bool getUseModel() const
{
return _useModel;
}
/**
* @brief Sets whether the current handle should use model matrix uniform during rendering
*/
void setUseModel(bool useModel)
{
_useModel = useModel;
}
/**
* @brief Gets custom world matrix
*/
const cocos2d::Mat4* getCustomWorldMatrix() const
{
return _worldMatrix;
}
/**
* @brief Sets custom world matrix
*/
void setCustomWorldMatrix(const cocos2d::Mat4& matrix)
{
if (!_worldMatrix)
{
_worldMatrix = new cocos2d::Mat4();
}
*_worldMatrix = matrix;
}
/**
* @brief Clear custom world matrix
*/
void clearCustomWorldMatirx()
{
if (_worldMatrix)
{
delete _worldMatrix;
_worldMatrix = nullptr;
}
}
/**
* @brief Sync script dirty flag.
*/
void setDirty(se_object_ptr jsDirty);
/**
* @brief Changes dirty flag.
*/
void enableDirty(uint32_t flag)
{
if (_dirty)
{
*_dirty |= flag;
}
}
/**
* @brief Changes dirty flag.
*/
void disableDirty(uint32_t flag)
{
if (_dirty)
{
*_dirty &= ~flag;
}
}
/**
* @brief Is flag dirty.
*/
bool isDirty(uint32_t flag)
{
if (_dirty)
{
return *_dirty & flag;
}
return false;
}
/**
* @brief Resets data.
*/
virtual void reset() {}
protected:
se::Object* _jsDirty = nullptr;
uint32_t* _dirty = nullptr;
std::size_t _dirtyLen = 0;
bool _useModel = false;
cocos2d::Mat4* _worldMatrix = nullptr;
};
// end of scene group
/// @}
RENDERER_END

View File

@@ -0,0 +1,160 @@
/****************************************************************************
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 "AssemblerSprite.hpp"
#include "../RenderFlow.hpp"
RENDERER_BEGIN
AssemblerSprite::AssemblerSprite()
{
}
AssemblerSprite::~AssemblerSprite()
{
if(_localObj != nullptr)
{
_localObj->unroot();
_localObj->decRef();
_localObj = nullptr;
_localData = nullptr;
_localLen = 0;
}
}
void AssemblerSprite::setLocalData(se_object_ptr localData)
{
if (!localData || localData == _localObj) return;
if (_localObj)
{
_localObj->unroot();
_localObj->decRef();
}
_localObj = localData;
_localObj->root();
_localObj->incRef();
_localData = nullptr;
_localLen = 0;
_localObj->getTypedArrayData((uint8_t**)&_localData, (std::size_t*)&_localLen);
}
void AssemblerSprite::fillBuffers(NodeProxy* node, ModelBatcher* batcher, std::size_t index)
{
if(!_datas || !_vfmt)
{
return;
}
if (index >= _iaDatas.size())
{
return;
}
MeshBuffer* buffer = batcher->getBuffer(_vfmt);
const IARenderData& ia = _iaDatas[index];
std::size_t meshIndex = ia.meshIndex >= 0 ? ia.meshIndex : index;
RenderData* data = _datas->getRenderData(meshIndex);
if (!data)
{
return;
}
CCASSERT(data->getVBytes() % _bytesPerVertex == 0, "AssemblerSprite::fillBuffers vertices data doesn't follow vertex format");
uint32_t vertexCount = ia.verticesCount >= 0 ? (uint32_t)ia.verticesCount : (uint32_t)data->getVBytes() / _bytesPerVertex;
uint32_t indexCount = ia.indicesCount >= 0 ? (uint32_t)ia.indicesCount : (uint32_t)data->getIBytes() / sizeof(unsigned short);
uint32_t vertexStart = (uint32_t)ia.verticesStart;
// must retrieve offset before request
auto& bufferOffset = buffer->request(vertexCount, indexCount);
uint32_t vBufferOffset = bufferOffset.vByte / sizeof(float);
uint32_t indexId = bufferOffset.index;
uint32_t vertexId = bufferOffset.vertex;
uint32_t vertexOffset = vertexId - vertexStart;
if (*_dirty & VERTICES_DIRTY || node->isDirty(RenderFlow::WORLD_TRANSFORM_CHANGED | RenderFlow::NODE_OPACITY_CHANGED))
{
generateWorldVertices();
calculateWorldVertices(node->getWorldMatrix());
}
float* dstWorldVerts = buffer->vData + vBufferOffset;
memcpy(dstWorldVerts, data->getVertices() + vertexStart * _bytesPerVertex, vertexCount * _bytesPerVertex);
// Copy index buffer with vertex offset
uint16_t* srcIndices = (uint16_t*)data->getIndices();
uint16_t* dstIndices = buffer->iData;
for (auto i = 0, j = ia.indicesStart; i < indexCount; ++i, ++j)
{
dstIndices[indexId++] = vertexOffset + srcIndices[j];
}
}
void AssemblerSprite::calculateWorldVertices(const Mat4& worldMat)
{
if(!_datas || !_vfmt)
{
return;
}
uint32_t num = _vfPos->num;
size_t dataPerVertex = _bytesPerVertex / sizeof(float);
for (std::size_t iaIdx = 0, iaCount = _iaDatas.size(); iaIdx < iaCount; iaIdx++)
{
const IARenderData& ia = _iaDatas[iaIdx];
std::size_t meshIndex = ia.meshIndex >= 0 ? ia.meshIndex : iaIdx;
RenderData* data = _datas->getRenderData(meshIndex);
if (!data) continue;
uint32_t vertexCount = ia.verticesCount >= 0 ? (uint32_t)ia.verticesCount : (uint32_t)data->getVBytes() / _bytesPerVertex;
uint32_t vertexStart = (uint32_t)ia.verticesStart;
float* srcWorldVerts = (float*)(data->getVertices() + vertexStart * _bytesPerVertex) + _posOffset;
switch (num) {
case 3:
for (uint32_t i = 0; i < vertexCount; ++i)
{
((cocos2d::Vec3*)srcWorldVerts)->transformMat4(*((cocos2d::Vec3*)srcWorldVerts), worldMat);
srcWorldVerts += dataPerVertex;
}
break;
case 2:
for (uint32_t i = 0; i < vertexCount; ++i)
{
float z = srcWorldVerts[2];
srcWorldVerts[2] = 0;
worldMat.transformPoint((cocos2d::Vec3*)srcWorldVerts);
srcWorldVerts[2] = z;
srcWorldVerts += dataPerVertex;
}
break;
}
}
*_dirty &= ~VERTICES_DIRTY;
}
RENDERER_END

View File

@@ -0,0 +1,48 @@
/****************************************************************************
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 "../../Macro.h"
#include "scripting/js-bindings/jswrapper/Object.hpp"
#include "Assembler.hpp"
RENDERER_BEGIN
class AssemblerSprite: public Assembler
{
public:
AssemblerSprite();
virtual ~AssemblerSprite();
virtual void setLocalData(se_object_ptr localData);
virtual void fillBuffers(NodeProxy* node, ModelBatcher* batcher, std::size_t index) override;
virtual void calculateWorldVertices(const Mat4& worldMat);
virtual void generateWorldVertices() {};
protected:
se::Object* _localObj = nullptr;
float* _localData = nullptr;
std::size_t _localLen = 0;
};
RENDERER_END

View File

@@ -0,0 +1,133 @@
/****************************************************************************
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 "CustomAssembler.hpp"
#include "../NodeProxy.hpp"
#include "../ModelBatcher.hpp"
#include "../../renderer/Scene.h"
RENDERER_BEGIN
CustomAssembler::CustomAssembler()
{
}
CustomAssembler::~CustomAssembler()
{
for (std::size_t i = 0, n = _iaPool.size(); i < n; i++)
{
auto ia = _iaPool[i];
delete ia;
}
_iaPool.clear();
}
void CustomAssembler::handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene)
{
batcher->commitIA(node, this, node->getCullingMask());
}
void CustomAssembler::reset()
{
_iaCount = 0;
for (auto it = _iaPool.begin(); it != _iaPool.end(); it++)
{
(*it)->clear();
}
}
void CustomAssembler::updateIARange(std::size_t index, int start, int count)
{
auto ia = adjustIA(index);
if (!ia) return;
ia->setCount(count);
ia->setStart(start);
}
void CustomAssembler::updateIABuffer(std::size_t index, VertexBuffer* vb, IndexBuffer* ib)
{
auto ia = adjustIA(index);
if (!ia) return;
ia->setVertexBuffer(vb);
ia->setIndexBuffer(ib);
}
InputAssembler* CustomAssembler::adjustIA(std::size_t index)
{
auto size = _iaPool.size();
InputAssembler* ia = nullptr;
if (index == size)
{
ia = new InputAssembler();
_iaPool.push_back(ia);
}
else if (index < size)
{
ia = _iaPool[index];
}
else
{
cocos2d::log("CustomAssembler:updateIA index:%zu is out of range", index);
return nullptr;
}
auto newIACount = index + 1;
if (_iaCount < newIACount)
{
_iaCount = newIACount;
}
return ia;
}
InputAssembler* CustomAssembler::getIA(std::size_t index) const
{
if (index >= _iaCount)
{
return nullptr;
}
return _iaPool[index];
}
void CustomAssembler::updateEffect(std::size_t index, EffectVariant* effect)
{
auto size = _effects.size();
if (index == size)
{
_effects.pushBack(effect);
return;
}
else if (index < size)
{
_effects.replace(index, effect);
return;
}
cocos2d::log("CustomAssembler:updateEffect index:%zu out of range", index);
}
RENDERER_END

View File

@@ -0,0 +1,134 @@
/****************************************************************************
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 "AssemblerBase.hpp"
#include <vector>
#include "../../renderer/InputAssembler.h"
#include "../../renderer/EffectVariant.hpp"
RENDERER_BEGIN
/**
* @addtogroup scene
* @{
*/
/**
* @brief Custom render handle base class
* Render components that manages render buffer directly like spine, dragonBones should extend from this handle type.
*/
class CustomAssembler : public AssemblerBase
{
public:
CustomAssembler();
virtual ~CustomAssembler();
/**
* @brief Updates InputAssembler indices range
* @param[in] index InputAssembler index.
* @param[in] start Indices buffer start pos
* @param[in] count Indices count
*/
virtual void updateIARange(std::size_t index, int start, int count);
/**
* @brief Updates InputAssembler indices and vertices buffer
* @param[in] index InputAssembler index.
* @param[in] vb Vertices buffer pointer
* @param[in] ib Indices buffer pointer
*/
virtual void updateIABuffer(std::size_t index, cocos2d::renderer::VertexBuffer* vb, cocos2d::renderer::IndexBuffer* ib);
/**
* @brief Gets input assembler by index
* @param[in] index.
*/
InputAssembler* getIA(std::size_t index) const;
/**
* @brief Gets input assembler count.
* @return Count.
*/
virtual inline std::size_t getIACount() const
{
return _iaCount;
}
/**
* @brief Commit the current render handle to ModelBatcher
*/
virtual void handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override;
/**
* @brief Do nothing
*/
virtual void postHandle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override {}
/**
* @brief Resets ia data.
*/
virtual void reset() override;
/**
* @brief Adjusts ia data.
*/
virtual InputAssembler* adjustIA(std::size_t index);
/**
* @brief Update the material for the given index.
* @param[in] index Render data index.
* @param[in] effect Effect pointer.
*/
virtual void updateEffect(std::size_t index, EffectVariant* effect);
/**
* @brief Gets the material for the given index.
* @param[in] index Render data index.
* @return Effect pointer.
*/
inline EffectVariant* getEffect(std::size_t index) const
{
if (index >= _effects.size())
{
return nullptr;
}
return _effects.at(index);
}
/**
* @brief Clears all effect.
* @return Count.
*/
virtual void clearEffect()
{
_effects.clear();
}
protected:
std::vector<cocos2d::renderer::InputAssembler*> _iaPool;
cocos2d::Vector<EffectVariant*> _effects;
std::size_t _iaCount = 0;
};
// end of scene group
/// @}
RENDERER_END

View File

@@ -0,0 +1,91 @@
/****************************************************************************
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 "MaskAssembler.hpp"
#include "../ModelBatcher.hpp"
#include "../StencilManager.hpp"
#include "../../Macro.h"
RENDERER_BEGIN
MaskAssembler::MaskAssembler()
{
}
MaskAssembler::~MaskAssembler()
{
CC_SAFE_RELEASE(_renderSubHandle);
CC_SAFE_RELEASE(_clearSubHandle);
}
void MaskAssembler::setRenderSubHandle(Assembler* renderSubHandle)
{
if (_renderSubHandle == renderSubHandle) return;
CC_SAFE_RELEASE(_renderSubHandle);
_renderSubHandle = renderSubHandle;
CC_SAFE_RETAIN(_renderSubHandle);
}
void MaskAssembler::setClearSubHandle(Assembler* clearSubHandle)
{
if (_clearSubHandle == clearSubHandle) return;
CC_SAFE_RELEASE(_clearSubHandle);
_clearSubHandle = clearSubHandle;
CC_SAFE_RETAIN(_clearSubHandle);
}
void MaskAssembler::handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene)
{
batcher->flush();
batcher->flushIA();
StencilManager* instance = StencilManager::getInstance();
instance->pushMask(_inverted);
instance->clear();
batcher->commit(node, _clearSubHandle, node->getCullingMask());
batcher->flush();
instance->enterLevel();
if (_imageStencil)
{
batcher->commit(node, this, node->getCullingMask());
}
else if (_renderSubHandle)
{
_renderSubHandle->handle(node, batcher, scene);
}
batcher->flush();
instance->enableMask();
}
void MaskAssembler::postHandle(NodeProxy *node, ModelBatcher *batcher, Scene *scene)
{
batcher->flush();
batcher->flushIA();
batcher->setCurrentEffect(getEffect(0));
StencilManager::getInstance()->exitMask();
}
RENDERER_END

View File

@@ -0,0 +1,62 @@
/****************************************************************************
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 <stdio.h>
#include "Assembler.hpp"
#include "../MeshBuffer.hpp"
#include "math/CCMath.h"
#include "SimpleSprite2D.hpp"
class ModelBatcher;
RENDERER_BEGIN
class MaskAssembler: public SimpleSprite2D
{
public:
MaskAssembler();
virtual ~MaskAssembler();
virtual void handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override;
virtual void postHandle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override;
void setMaskInverted(bool inverted) { _inverted = inverted; };
bool getMaskInverted() { return _inverted; };
void setRenderSubHandle(Assembler* renderSubHandle);
void setClearSubHandle(Assembler* clearSubHandle);
void setImageStencil(bool isImageStencil) { _imageStencil = isImageStencil; };
protected:
bool _inverted = false;
bool _imageStencil = false;
private:
Assembler* _renderSubHandle = nullptr;
Assembler* _clearSubHandle = nullptr;
};
RENDERER_END

View File

@@ -0,0 +1,111 @@
/****************************************************************************
Copyright (c) 2019 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 "MeshAssembler.hpp"
#include "../ModelBatcher.hpp"
RENDERER_BEGIN
MeshAssembler::MeshAssembler()
{
_useModel = true;
}
MeshAssembler::~MeshAssembler()
{
RENDERER_SAFE_RELEASE(_renderNode);
}
void MeshAssembler::handle(NodeProxy *node, ModelBatcher *batcher, Scene *scene)
{
if (_renderNode != nullptr)
{
batcher->commitIA(_renderNode, this, node->getCullingMask());
}
else
{
batcher->commitIA(node, this, node->getCullingMask());
}
batcher->flushIA();
}
void MeshAssembler::setNode(NodeProxy* node)
{
if (_renderNode == node)
{
return;
}
if (_renderNode != nullptr)
{
_renderNode->release();
}
_renderNode = node;
if (_renderNode != nullptr)
{
_renderNode->retain();
}
}
void MeshAssembler::updateIAData(std::size_t index, VertexFormat* vfmt, se_object_ptr vertices, se_object_ptr indices)
{
_datas.updateMesh(index, vertices, indices);
auto data = _datas.getRenderData(index);
auto ia = adjustIA(index);
auto ib = ia->getIndexBuffer();
if (!ib) {
ib = new IndexBuffer();
ib->autorelease();
ib->init(DeviceGraphics::getInstance(), IndexFormat::UINT16, Usage::STATIC, data->getIndices(), data->getIBytes(), (uint32_t)data->getIBytes() / sizeof(unsigned short));
ia->setIndexBuffer(ib);
}
else {
ib->update(0, data->getIndices(), data->getIBytes());
}
auto vb = ia->getVertexBuffer();
if (!vb) {
vb = new VertexBuffer();
vb->autorelease();
vb->init(DeviceGraphics::getInstance(), vfmt, Usage::STATIC, data->getVertices(), data->getVBytes(), (uint32_t)data->getVBytes() / vfmt->getBytes());
ia->setVertexBuffer(vb);
}
else {
vb->update(0, data->getVertices(), data->getVBytes());
}
ia->setCount(ib->getCount());
}
void MeshAssembler::reset()
{
CustomAssembler::reset();
_datas.clear();
}
RENDERER_END

View File

@@ -0,0 +1,54 @@
/****************************************************************************
Copyright (c) 2019 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 "../../Macro.h"
#include "CustomAssembler.hpp"
#include "../NodeProxy.hpp"
#include "../../gfx/VertexFormat.h"
#include "RenderDataList.hpp"
RENDERER_BEGIN
class MeshAssembler: public CustomAssembler
{
public:
MeshAssembler();
virtual ~MeshAssembler();
virtual void handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override;
/**
* @brief Sets the related node proxy which provids model matrix for render.
*/
void setNode(NodeProxy* node);
void updateIAData(std::size_t index, VertexFormat* vfmt, se_object_ptr vertices, se_object_ptr indices);
virtual void reset() override;
protected:
NodeProxy* _renderNode = nullptr;
RenderDataList _datas;
};
RENDERER_END

View File

@@ -0,0 +1,136 @@
/****************************************************************************
Copyright (c) 2019 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 "Particle3DAssembler.hpp"
#include "../NodeProxy.hpp"
RENDERER_BEGIN
Particle3DAssembler::Particle3DAssembler()
{
}
Particle3DAssembler::~Particle3DAssembler()
{
CC_SAFE_RELEASE(_trailVfmt);
}
void Particle3DAssembler::setTrailVertexFormat(VertexFormat *vfmt)
{
if (_trailVfmt == vfmt) return;
CC_SAFE_RETAIN(vfmt);
CC_SAFE_RELEASE(_trailVfmt);
_trailVfmt = vfmt;
if (_trailVfmt)
{
_trailVertexBytes = _trailVfmt->getBytes();
const VertexFormat::Element* vfPos = _vfmt->getElement(ATTRIB_NAME_POSITION_HASH);
_trailPosOffset = vfPos->offset / 4;
}
}
void Particle3DAssembler::fillBuffer(NodeProxy *node, MeshBuffer *buffer, const IARenderData& ia, RenderData* data)
{
CCASSERT(data->getVBytes() % _bytesPerVertex == 0, "Assembler::fillBuffers vertices data doesn't follow vertex format");
uint32_t vertexCount = ia.verticesCount >= 0 ? (uint32_t)ia.verticesCount : (uint32_t)data->getVBytes() / _bytesPerVertex;
uint32_t indexCount = ia.indicesCount >= 0 ? (uint32_t)ia.indicesCount : (uint32_t)data->getIBytes() / sizeof(unsigned short);
uint32_t vertexStart = (uint32_t)ia.verticesStart;
// must retrieve offset before request
auto& bufferOffset = buffer->request(vertexCount, indexCount);
uint32_t vBufferOffset = bufferOffset.vByte / sizeof(float);
uint32_t indexId = bufferOffset.index;
uint32_t vertexId = bufferOffset.vertex;
uint32_t vertexOffset = vertexId - vertexStart;
float* worldVerts = buffer->vData + vBufferOffset;
memcpy(worldVerts, data->getVertices() + vertexStart * _bytesPerVertex, vertexCount * _bytesPerVertex);
// Copy index buffer with vertex offset
uint16_t* indices = (uint16_t*)data->getIndices();
uint16_t* dst = buffer->iData;
for (auto i = 0, j = ia.indicesStart; i < indexCount; ++i, ++j)
{
dst[indexId++] = vertexOffset + indices[j];
}
}
void Particle3DAssembler::fillTrailBuffer(NodeProxy *node, MeshBuffer *buffer, const IARenderData& ia, RenderData* data)
{
CCASSERT(data->getVBytes() % _trailVertexBytes == 0, "Assembler::fillBuffers vertices data doesn't follow vertex format");
uint32_t vertexCount = ia.verticesCount >= 0 ? (uint32_t)ia.verticesCount : (uint32_t)data->getVBytes() / _trailVertexBytes;
uint32_t indexCount = ia.indicesCount >= 0 ? (uint32_t)ia.indicesCount : (uint32_t)data->getIBytes() / sizeof(unsigned short);
uint32_t vertexStart = (uint32_t)ia.verticesStart;
// must retrieve offset before request
auto& bufferOffset = buffer->request(vertexCount, indexCount);
uint32_t vBufferOffset = bufferOffset.vByte / sizeof(float);
uint32_t indexId = bufferOffset.index;
uint32_t vertexId = bufferOffset.vertex;
uint32_t vertexOffset = vertexId - vertexStart;
float* worldVerts = buffer->vData + vBufferOffset;
memcpy(worldVerts, data->getVertices() + vertexStart * _trailVertexBytes, vertexCount * _trailVertexBytes);
// Copy index buffer with vertex offset
uint16_t* indices = (uint16_t*)data->getIndices();
uint16_t* dst = buffer->iData;
for (auto i = 0, j = ia.indicesStart; i < indexCount; ++i, ++j)
{
dst[indexId++] = vertexOffset + indices[j];
}
}
void Particle3DAssembler::fillBuffers(NodeProxy *node, ModelBatcher *batcher, std::size_t index)
{
VertexFormat* vfmt = index == 0 ? _vfmt : _trailVfmt;
if (!_datas || !vfmt)
{
return;
}
MeshBuffer* buffer = batcher->getBuffer(vfmt);
const IARenderData& ia = _iaDatas[index];
std::size_t meshIndex = ia.meshIndex >= 0 ? ia.meshIndex : index;
RenderData* data = _datas->getRenderData(meshIndex);
if (!data)
{
return;
}
if (index != 0)
{
fillTrailBuffer(node, buffer, ia, data);
}
else
{
fillBuffer(node, buffer, ia, data);
}
}
RENDERER_END

View File

@@ -0,0 +1,69 @@
/****************************************************************************
Copyright (c) 2019 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 "Assembler.hpp"
#include "../ModelBatcher.hpp"
RENDERER_BEGIN
class NodeProxy;
class ModelBatcher;
enum class Space: uint8_t
{
WORLD = 0,
LOCAL = 1,
CUSTOM = 2
};
class Particle3DAssembler: public Assembler
{
public:
Particle3DAssembler();
~Particle3DAssembler();
virtual void fillBuffers(NodeProxy *node, ModelBatcher *batcher, std::size_t index) override;
void setTrailVertexFormat(VertexFormat* vfmt);
void setTrailModuleEnable(bool enable) {_trailModuleEnable = enable;};
void setParticleSpace(Space space) {_particleSpace = space;};
void setTrailSpace(Space space) {_trailSpace = space;};
private:
void fillBuffer(NodeProxy *node, MeshBuffer *buffer, const IARenderData& ia, RenderData* data);
void fillTrailBuffer(NodeProxy *node, MeshBuffer *buffer, const IARenderData& ia, RenderData* data);
private:
Space _particleSpace = Space::LOCAL;
Space _trailSpace = Space::LOCAL;
uint32_t _trailVertexBytes = 0;
size_t _trailPosOffset = 0;
bool _trailModuleEnable = false;
VertexFormat* _trailVfmt = nullptr;
};
RENDERER_END

View File

@@ -0,0 +1,126 @@
/****************************************************************************
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 "RenderData.hpp"
#include "../../renderer/Effect.h"
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
RENDERER_BEGIN
RenderData::RenderData ()
{
}
RenderData::RenderData (const RenderData& o)
{
setVertices(o._jsVertices);
setIndices(o._jsIndices);
}
RenderData::~RenderData ()
{
if(_jsVertices != nullptr)
{
_jsVertices->unroot();
_jsVertices->decRef();
_jsVertices = nullptr;
_vertices = nullptr;
_vBytes = 0;
}
if(_jsIndices != nullptr)
{
_jsIndices->unroot();
_jsIndices->decRef();
_jsIndices = nullptr;
_indices = nullptr;
_iBytes = 0;
}
}
void RenderData::setVertices (se::Object* jsVertices)
{
if (!jsVertices || jsVertices == _jsVertices) return;
if (_jsVertices)
{
_jsVertices->unroot();
_jsVertices->decRef();
}
_jsVertices = jsVertices;
_jsVertices->root();
_jsVertices->incRef();
_vertices = nullptr;
_vBytes = 0;
_jsVertices->getTypedArrayData(&_vertices, (std::size_t*)&_vBytes);
}
void RenderData::setIndices (se::Object* jsIndices)
{
if (!jsIndices || jsIndices == _jsIndices) return;
if (_jsIndices)
{
_jsIndices->unroot();
_jsIndices->decRef();
}
_jsIndices = jsIndices;
_jsIndices->root();
_jsIndices->incRef();
_indices = nullptr;
_iBytes = 0;
_jsIndices->getTypedArrayData(&_indices, (std::size_t*)&_iBytes);
}
uint8_t* RenderData::getVertices () const
{
return _vertices;
}
uint8_t* RenderData::getIndices () const
{
return _indices;
}
void RenderData::clear()
{
if(_jsVertices != nullptr)
{
_jsVertices->unroot();
_jsVertices->decRef();
_jsVertices = nullptr;
}
if(_jsIndices != nullptr)
{
_jsIndices->unroot();
_jsIndices->decRef();
_jsIndices = nullptr;
}
_vBytes = 0;
_iBytes = 0;
_vertices = nullptr;
_indices = nullptr;
}
RENDERER_END

View File

@@ -0,0 +1,66 @@
/****************************************************************************
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 "../../Macro.h"
#include "base/CCRef.h"
#include <stdint.h>
namespace se {
class Object;
class HandleObject;
}
RENDERER_BEGIN
class Effect;
class RenderData {
public:
RenderData ();
RenderData (const RenderData& o);
virtual ~RenderData ();
void setVertices (se::Object* jsVertices);
void setIndices (se::Object* jsIndices);
uint8_t* getVertices () const;
uint8_t* getIndices () const;
unsigned long getVBytes () { return _vBytes; }
unsigned long getIBytes () { return _iBytes; }
void clear();
private:
unsigned long _vBytes = 0;
unsigned long _iBytes = 0;
uint8_t* _vertices = nullptr;
uint8_t* _indices = nullptr;
se::Object* _jsVertices = nullptr;
se::Object* _jsIndices = nullptr;
};
RENDERER_END

View File

@@ -0,0 +1,63 @@
/****************************************************************************
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 "RenderDataList.hpp"
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
RENDERER_BEGIN
void RenderDataList::updateMesh(std::size_t index, se_object_ptr vertices, se_object_ptr indices)
{
if (index >= _datas.size())
{
_datas.resize(index + 1);
}
se::ScriptEngine::getInstance()->clearException();
se::AutoHandleScope hs;
RenderData& data = _datas[index];
data.setVertices(vertices);
data.setIndices(indices);
}
RenderData* RenderDataList::getRenderData(std::size_t index)
{
if (index >= _datas.size())
{
return nullptr;
}
return &_datas[index];
}
void RenderDataList::clear()
{
for (auto it = _datas.begin(); it != _datas.end(); it++)
{
it->clear();
}
_datas.clear();
}
RENDERER_END

View File

@@ -0,0 +1,68 @@
/****************************************************************************
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 "base/CCRef.h"
#include <vector>
#include "RenderData.hpp"
#include "scripting/js-bindings/jswrapper/Object.hpp"
namespace se {
class Object;
class HandleObject;
}
RENDERER_BEGIN
class RenderDataList: public cocos2d::Ref {
public:
RenderDataList () {}
virtual ~RenderDataList() {}
/**
* @brief Update the mesh data for the given index.
* @param[in] index Render data index.
* @param[in] vertices Vertex data.
* @param[in] indices Index data.
*/
void updateMesh(std::size_t index, se_object_ptr vertices, se_object_ptr indices);
/**
* @brief Gets the count of render datas
* @return Count.
*/
std::size_t getMeshCount() const { return _datas.size(); };
/**
* @brief Gets IARenderData.
* @return IARenderData.
*/
RenderData* getRenderData(std::size_t index);
/**
* @brief Resets all IARenderData.
*/
void clear();
private:
std::vector<RenderData> _datas;
};
RENDERER_END

View File

@@ -0,0 +1,105 @@
/****************************************************************************
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 "SimpleSprite2D.hpp"
#include "../RenderFlow.hpp"
RENDERER_BEGIN
SimpleSprite2D::SimpleSprite2D()
{
}
SimpleSprite2D::~SimpleSprite2D()
{
}
void SimpleSprite2D::fillBuffers(NodeProxy* node, ModelBatcher* batcher, std::size_t index)
{
RenderData* data = _datas->getRenderData(0);
if (!data)
{
return;
}
MeshBuffer* buffer = batcher->getBuffer(_vfmt);
// must retrieve offset before request
auto& bufferOffset = buffer->request(4, 6);
uint32_t vBufferOffset = bufferOffset.vByte / sizeof(float);
uint32_t indexId = bufferOffset.index;
uint32_t vertexId = bufferOffset.vertex;
if (*_dirty & VERTICES_DIRTY || node->isDirty(RenderFlow::WORLD_TRANSFORM_CHANGED | RenderFlow::NODE_OPACITY_CHANGED))
{
float vl = _localData[0],
vr = _localData[2],
vb = _localData[1],
vt = _localData[3];
const Mat4& worldMat = node->getWorldMatrix();
size_t dataPerVertex = _bytesPerVertex / sizeof(float);
float* srcWorldVerts = (float*)data->getVertices();
// left bottom
float u = srcWorldVerts[2];
worldMat.transformVector(vl, vb, 0.0f, 1.0f, (cocos2d::Vec3*)srcWorldVerts);
srcWorldVerts[2] = u;
// right bottom
srcWorldVerts += dataPerVertex;
u = srcWorldVerts[2];
worldMat.transformVector(vr, vb, 0.0f, 1.0f, (cocos2d::Vec3*)srcWorldVerts);
srcWorldVerts[2] = u;
// left top
srcWorldVerts += dataPerVertex;
u = srcWorldVerts[2];
worldMat.transformVector(vl, vt, 0.0f, 1.0f, (cocos2d::Vec3*)srcWorldVerts);
srcWorldVerts[2] = u;
// right top
srcWorldVerts += dataPerVertex;
u = srcWorldVerts[2];
worldMat.transformVector(vr, vt, 0.0f, 1.0f, (cocos2d::Vec3*)srcWorldVerts);
srcWorldVerts[2] = u;
*_dirty &= ~VERTICES_DIRTY;
}
float* dstWorldVerts = buffer->vData + vBufferOffset;
memcpy(dstWorldVerts, data->getVertices(), 4 * _bytesPerVertex);
// Copy index buffer with vertex offset
uint16_t* srcIndices = (uint16_t*)data->getIndices();
uint16_t* dstIndices = buffer->iData;
for (auto i = 0, j = 0; i < 6; ++i, ++j)
{
dstIndices[indexId++] = vertexId + srcIndices[j];
}
}
RENDERER_END

View File

@@ -0,0 +1,39 @@
/****************************************************************************
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 "AssemblerSprite.hpp"
RENDERER_BEGIN
class SimpleSprite2D: public AssemblerSprite
{
public:
SimpleSprite2D();
virtual ~SimpleSprite2D();
virtual void fillBuffers(NodeProxy* node, ModelBatcher* batcher, std::size_t index) override;
};
RENDERER_END

View File

@@ -0,0 +1,80 @@
/****************************************************************************
Copyright (c) 2019 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 "SimpleSprite3D.hpp"
RENDERER_BEGIN
SimpleSprite3D::SimpleSprite3D()
{
}
SimpleSprite3D::~SimpleSprite3D()
{
}
void SimpleSprite3D::generateWorldVertices()
{
RenderData* data = _datas->getRenderData(0);
float* verts = (float*)data->getVertices();
auto floatsPerVert = _bytesPerVertex / sizeof(float);
std::size_t dstOffset = 0;
float vl = _localData[0],
vr = _localData[2],
vb = _localData[1],
vt = _localData[3];
// left bottom
verts[dstOffset] = vl;
verts[dstOffset+1] = vb;
verts[dstOffset+2] = 0;
dstOffset += floatsPerVert;
// right bottom
verts[dstOffset] = vr;
verts[dstOffset+1] = vb;
verts[dstOffset+2] = 0;
dstOffset += floatsPerVert;
// left top
verts[dstOffset] = vl;
verts[dstOffset+1] = vt;
verts[dstOffset+2] = 0;
dstOffset += floatsPerVert;
// right top
verts[dstOffset] = vr;
verts[dstOffset+1] = vt;
verts[dstOffset+2] = 0;
}
RENDERER_END

View File

@@ -0,0 +1,39 @@
/****************************************************************************
Copyright (c) 2019 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 "AssemblerSprite.hpp"
RENDERER_BEGIN
class SimpleSprite3D : public AssemblerSprite
{
public:
SimpleSprite3D();
virtual ~SimpleSprite3D() override;
virtual void generateWorldVertices() override;
};
RENDERER_END

View File

@@ -0,0 +1,57 @@
/****************************************************************************
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 "SlicedSprite2D.hpp"
#include "../RenderFlow.hpp"
RENDERER_BEGIN
SlicedSprite2D::SlicedSprite2D()
{
}
SlicedSprite2D::~SlicedSprite2D()
{
}
void SlicedSprite2D::generateWorldVertices()
{
RenderData* data = _datas->getRenderData(0);
float* verts = (float*)data->getVertices();
auto floatsPerVert = _bytesPerVertex / sizeof(float);
for (auto row = 0; row < 4; ++row) {
float localRowY = _localData[row * 2 + 1];
for (auto col = 0; col < 4; ++col) {
float localColX = _localData[col * 2];
std::size_t worldIndex = (row * 4 + col) * floatsPerVert;
verts[worldIndex] = localColX ;
verts[worldIndex + 1] = localRowY;
}
}
}
RENDERER_END

View File

@@ -0,0 +1,39 @@
/****************************************************************************
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 "AssemblerSprite.hpp"
RENDERER_BEGIN
class SlicedSprite2D: public AssemblerSprite
{
public:
SlicedSprite2D();
virtual ~SlicedSprite2D();
virtual void generateWorldVertices() override;
};
RENDERER_END

View File

@@ -0,0 +1,57 @@
/****************************************************************************
Copyright (c) 2019 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 "SlicedSprite3D.hpp"
RENDERER_BEGIN
SlicedSprite3D::SlicedSprite3D()
{
};
SlicedSprite3D::~SlicedSprite3D()
{
};
void SlicedSprite3D::generateWorldVertices()
{
RenderData* data = _datas->getRenderData(0);
float* verts = (float*)data->getVertices();
auto floatsPerVert = _bytesPerVertex / sizeof(float);
for (auto row = 0; row < 4; ++row) {
float localRowY = _localData[row * 2 + 1];
for (auto col = 0; col < 4; ++col) {
float localColX = _localData[col * 2];
std::size_t worldIndex = (row * 4 + col) * floatsPerVert;
verts[worldIndex] = localColX ;
verts[worldIndex + 1] = localRowY;
verts[worldIndex + 2] = 0;
}
}
};
RENDERER_END

View File

@@ -0,0 +1,39 @@
/****************************************************************************
Copyright (c) 2019 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 "AssemblerSprite.hpp"
RENDERER_BEGIN
class SlicedSprite3D : public AssemblerSprite
{
public:
SlicedSprite3D();
virtual ~SlicedSprite3D() override;
virtual void generateWorldVertices() override;
};
RENDERER_END

View File

@@ -0,0 +1,98 @@
/****************************************************************************
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 "TiledMapAssembler.hpp"
#include "../NodeProxy.hpp"
#include "../ModelBatcher.hpp"
#include "../RenderFlow.hpp"
RENDERER_BEGIN
TiledMapAssembler::TiledMapAssembler()
{
}
TiledMapAssembler::~TiledMapAssembler()
{
}
void TiledMapAssembler::updateNodes(std::size_t iaIndex, const std::vector<std::string>& nodes)
{
_nodesMap[iaIndex] = nodes;
}
void TiledMapAssembler::clearNodes(std::size_t iaIndex)
{
_nodesMap.erase(iaIndex);
}
void TiledMapAssembler::handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene)
{
_node = node;
_batcher = batcher;
// Last tiles data may be empty, but has user node, so render it by manual.
auto lastNodesIndex = getIACount();
auto it = _nodesMap.find(lastNodesIndex);
if (it != _nodesMap.end())
{
renderNodes(lastNodesIndex);
}
Assembler::handle(node, batcher, scene);
}
void TiledMapAssembler::renderNodes(std::size_t index)
{
static cocos2d::Mat4 tempWorldMat;
const auto& worldMat = _node->getWorldMatrix();
auto it = _nodesMap.find(index);
if (it != _nodesMap.end())
{
auto flow = _batcher->getFlow();
for (auto& id : it->second) {
auto child = _node->getChildByID(id);
if (child)
{
child->enableVisit(true);
child->enableUpdateWorldMatrix(false);
child->updateLocalMatrix();
auto& localMat = child->getLocalMatrix();
cocos2d::Mat4::multiply(worldMat, localMat, &tempWorldMat);
child->updateWorldMatrix(tempWorldMat);
flow->visit(child);
child->enableUpdateWorldMatrix(true);
child->enableVisit(false);
}
}
}
_batcher->changeCommitState(ModelBatcher::Common);
}
void TiledMapAssembler::beforeFillBuffers(std::size_t index)
{
renderNodes(index);
}
RENDERER_END

View File

@@ -0,0 +1,50 @@
/****************************************************************************
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 "Assembler.hpp"
#include <vector>
#include <map>
#include <string>
RENDERER_BEGIN
class TiledMapAssembler : public Assembler {
public:
TiledMapAssembler();
virtual ~TiledMapAssembler();
virtual void handle(NodeProxy *node, ModelBatcher* batcher, Scene* scene) override;
virtual void beforeFillBuffers(std::size_t index) override;
void updateNodes(std::size_t iaIndex, const std::vector<std::string>& nodes);
void clearNodes(std::size_t iaIndex);
private:
void renderNodes(std::size_t index);
private:
std::map<std::size_t, std::vector<std::string>> _nodesMap;
NodeProxy* _node = nullptr;
ModelBatcher* _batcher = nullptr;
};
RENDERER_END