2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
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 "renderer/CCQuadCommand.h"
|
|
|
|
|
|
|
|
#include "renderer/CCMaterial.h"
|
|
|
|
#include "renderer/CCTechnique.h"
|
|
|
|
#include "renderer/CCRenderer.h"
|
|
|
|
#include "renderer/CCPass.h"
|
|
|
|
#include "renderer/CCTexture2D.h"
|
|
|
|
#include "base/ccUtils.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
int QuadCommand::__indexCapacity = -1;
|
|
|
|
uint16_t* QuadCommand::__indices = nullptr;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
QuadCommand::QuadCommand() : _indexSize(-1), _ownedIndices() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
QuadCommand::~QuadCommand()
|
|
|
|
{
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& indices : _ownedIndices)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SAFE_DELETE_ARRAY(indices);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QuadCommand::reIndex(int indicesCount)
|
|
|
|
{
|
|
|
|
// first time init: create a decent buffer size for indices to prevent too much resizing
|
|
|
|
if (__indexCapacity == -1)
|
|
|
|
{
|
|
|
|
indicesCount = std::max(indicesCount, 2048);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (indicesCount > __indexCapacity)
|
|
|
|
{
|
|
|
|
// if resizing is needed, get needed size plus 25%, but not bigger that max size
|
|
|
|
indicesCount *= 1.25;
|
|
|
|
indicesCount = std::min(indicesCount, 65536);
|
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
AXLOG("axmol: QuadCommand: resizing index size from [%d] to [%d]", __indexCapacity, indicesCount);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-08-08 13:18:33 +08:00
|
|
|
_ownedIndices.emplace_back(__indices);
|
2021-12-25 10:04:45 +08:00
|
|
|
__indices = new uint16_t[indicesCount];
|
2019-11-23 20:27:39 +08:00
|
|
|
__indexCapacity = indicesCount;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
for (int i = 0; i < __indexCapacity / 6; i++)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
__indices[i * 6 + 0] = (uint16_t)(i * 4 + 0);
|
|
|
|
__indices[i * 6 + 1] = (uint16_t)(i * 4 + 1);
|
|
|
|
__indices[i * 6 + 2] = (uint16_t)(i * 4 + 2);
|
|
|
|
__indices[i * 6 + 3] = (uint16_t)(i * 4 + 3);
|
|
|
|
__indices[i * 6 + 4] = (uint16_t)(i * 4 + 2);
|
|
|
|
__indices[i * 6 + 5] = (uint16_t)(i * 4 + 1);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_indexSize = indicesCount;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void QuadCommand::init(float globalOrder,
|
|
|
|
Texture2D* texture,
|
|
|
|
const BlendFunc& blendType,
|
|
|
|
V3F_C4B_T2F_Quad* quads,
|
|
|
|
ssize_t quadCount,
|
|
|
|
const Mat4& mv,
|
|
|
|
uint32_t flags)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (quadCount * 6 > _indexSize)
|
2021-12-25 10:04:45 +08:00
|
|
|
reIndex((int)quadCount * 6);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Triangles triangles;
|
2021-12-25 10:04:45 +08:00
|
|
|
triangles.verts = &quads->tl;
|
|
|
|
triangles.vertCount = (int)quadCount * 4;
|
|
|
|
triangles.indices = __indices;
|
2019-11-23 20:27:39 +08:00
|
|
|
triangles.indexCount = (int)quadCount * 6;
|
|
|
|
TrianglesCommand::init(globalOrder, texture, blendType, triangles, mv, flags);
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|