Add stride functions and remove unneeded UNSPEC value.

This commit is contained in:
DelinWorks 2022-07-04 19:20:04 +03:00
parent 7e199cce21
commit 96158090db
35 changed files with 493 additions and 578 deletions

View File

@ -46,6 +46,28 @@ struct particle_point
float y;
};
/**
* Particle emission shapes.
* Current supported shapes are Point, Rectangle, RectangularTorus, Circle, Torus, Cone, Cone Torus, Texture alpha
* emission mask
* @since adxe-1.0.0b8
*/
enum class EmissionShapeType
{
// Emission shape of type point
POINT,
// Emission shape of type rectangle
RECT,
// Emission shape of type rectangular torus
RECTTORUS,
// Emission shape of type circle or cone
CIRCLE,
// Emission shape of type torus or cone torus
TORUS,
// Emission shape of type texture alpha mask
TEXTURE_ALPHA_MASK
};
/**
* Particle emission shapes.
* Current supported shapes are Point, Rectangle, RectangularTorus, Circle, Torus, Cone, Cone Torus, Texture alpha

View File

@ -298,7 +298,7 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas,
}
// split into submesh according to material
std::map<int, std::vector<unsigned short>> subMeshMap;
std::map<int, IndexArray> subMeshMap;
for (size_t k = 0, size = mesh.material_ids.size(); k < size; ++k)
{
int id = mesh.material_ids[k];
@ -312,9 +312,9 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas,
node->id = shape.name;
for (auto& submesh : subMeshMap)
{
meshdata->subMeshIndices.push_back(submesh.second);
auto& storedIndices = meshdata->subMeshIndices.emplace_back(std::move(submesh.second));
meshdata->subMeshAABB.push_back(
calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), submesh.second));
calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), storedIndices));
sprintf(str, "%d", ++i);
meshdata->subMeshIds.push_back(str);
@ -447,7 +447,7 @@ bool Bundle3D::loadMeshDatasBinary(MeshDatas& meshdatas)
for (unsigned int k = 0; k < meshPartCount; ++k)
{
std::vector<unsigned short> indexArray;
IndexArray indexArray{};
std::string meshPartid = _binaryReader.readString();
meshData->subMeshIds.push_back(meshPartid);
unsigned int nIndexCount;
@ -457,12 +457,12 @@ bool Bundle3D::loadMeshDatasBinary(MeshDatas& meshdatas)
goto FAILED;
}
indexArray.resize(nIndexCount);
if (_binaryReader.read(&indexArray[0], 2, nIndexCount) != nIndexCount)
if (_binaryReader.read(indexArray.data(), 2, nIndexCount) != nIndexCount)
{
CCLOG("warning: Failed to read meshdata: indices '%s'.", _path.c_str());
goto FAILED;
}
meshData->subMeshIndices.push_back(indexArray);
auto& storedIndices = meshData->subMeshIndices.emplace_back(std::move(indexArray));
meshData->numIndex = (int)meshData->subMeshIndices.size();
// meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(),
// indexArray));
@ -474,13 +474,13 @@ bool Bundle3D::loadMeshDatasBinary(MeshDatas& meshdatas)
{
CCLOG("warning: Failed to read meshdata: aabb '%s'.", _path.c_str());
goto FAILED;
}
}
meshData->subMeshAABB.push_back(AABB(Vec3(aabb[0], aabb[1], aabb[2]), Vec3(aabb[3], aabb[4], aabb[5])));
}
else
{
meshData->subMeshAABB.push_back(
calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray));
calculateAABB(meshData->vertex, meshData->getPerVertexSize(), storedIndices));
}
}
meshdatas.meshDatas.push_back(meshData);
@ -599,17 +599,17 @@ bool Bundle3D::loadMeshDatasBinary_0_1(MeshDatas& meshdatas)
return false;
}
std::vector<unsigned short> indices;
IndexArray indices;
indices.resize(nIndexCount);
if (_binaryReader.read(&indices[0], 2, nIndexCount) != nIndexCount)
if (_binaryReader.read(indices.data(), 2, nIndexCount) != nIndexCount)
{
CCLOG("warning: Failed to read meshdata: indices '%s'.", _path.c_str());
CC_SAFE_DELETE(meshdata);
return false;
}
meshdata->subMeshIndices.push_back(indices);
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices));
auto& storedIndices = meshdata->subMeshIndices.emplace_back(std::move(indices));
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), storedIndices));
}
meshdatas.meshDatas.push_back(meshdata);
@ -720,17 +720,17 @@ bool Bundle3D::loadMeshDatasBinary_0_2(MeshDatas& meshdatas)
return false;
}
std::vector<unsigned short> indices;
IndexArray indices{CustomCommand::IndexFormat::U_SHORT}; /* TODO: _version == 1.3 use U_INT?*/
indices.resize(nIndexCount);
if (_binaryReader.read(&indices[0], 2, nIndexCount) != nIndexCount)
if (_binaryReader.read(indices.data(), 2, nIndexCount) != nIndexCount)
{
CCLOG("warning: Failed to read meshdata: indices '%s'.", _path.c_str());
CC_SAFE_DELETE(meshdata);
return false;
}
meshdata->subMeshIndices.push_back(indices);
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices));
auto& storedIndices = meshdata->subMeshIndices.emplace_back(std::move(indices));
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), storedIndices));
}
meshdatas.meshDatas.push_back(meshdata);
@ -777,7 +777,7 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas)
const rapidjson::Value& mesh_part_array = mesh_data[PARTS];
for (rapidjson::SizeType i = 0, mesh_part_array_size = mesh_part_array.Size(); i < mesh_part_array_size; ++i)
{
std::vector<unsigned short> indexArray;
IndexArray indexArray;
const rapidjson::Value& mesh_part = mesh_part_array[i];
meshData->subMeshIds.push_back(mesh_part[ID].GetString());
// index_number
@ -786,7 +786,7 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas)
j < indices_val_array_size; ++j)
indexArray.push_back((unsigned short)indices_val_array[j].GetUint());
meshData->subMeshIndices.push_back(indexArray);
auto& storedIndices = meshData->subMeshIndices.emplace_back(std::move(indexArray));
meshData->numIndex = (int)meshData->subMeshIndices.size();
if (mesh_data.HasMember(AABBS))
@ -805,13 +805,12 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas)
else
{
meshData->subMeshAABB.push_back(
calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray));
calculateAABB(meshData->vertex, meshData->getPerVertexSize(), storedIndices));
}
}
else
{
meshData->subMeshAABB.push_back(
calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray));
meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(), storedIndices));
}
}
meshdatas.meshDatas.push_back(meshData);
@ -1185,15 +1184,15 @@ bool Bundle3D::loadMeshDataJson_0_1(MeshDatas& meshdatas)
unsigned int indexnum = mesh_data_body_array_0[INDEXNUM].GetUint();
// indices
std::vector<unsigned short> indices;
IndexArray indices;
indices.resize(indexnum);
const rapidjson::Value& indices_val_array = mesh_data_body_array_0[INDICES];
for (rapidjson::SizeType i = 0; i < indices_val_array.Size(); ++i)
indices[i] = (unsigned short)indices_val_array[i].GetUint();
indices.at<uint16_t>(i) = (unsigned short)indices_val_array[i].GetUint();
meshdata->subMeshIndices.push_back(indices);
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices));
auto& storedIndices = meshdata->subMeshIndices.emplace_back(std::move(indices));
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), storedIndices));
meshdatas.meshDatas.push_back(meshdata);
return true;
}
@ -1239,15 +1238,15 @@ bool Bundle3D::loadMeshDataJson_0_2(MeshDatas& meshdatas)
unsigned int indexnum = mesh_submesh_val[INDEXNUM].GetUint();
// indices
std::vector<unsigned short> indices;
IndexArray indices;
indices.resize(indexnum);
const rapidjson::Value& indices_val_array = mesh_submesh_val[INDICES];
for (rapidjson::SizeType j = 0; j < indices_val_array.Size(); ++j)
indices[j] = (unsigned short)indices_val_array[j].GetUint();
indices.at<uint16_t>(j) = (unsigned short)indices_val_array[j].GetUint();
meshdata->subMeshIndices.push_back(indices);
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices));
auto& storedIndices = meshdata->subMeshIndices.emplace_back(std::move(indices));
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), storedIndices));
}
meshdatas.meshDatas.push_back(meshdata);
return true;
@ -2301,13 +2300,12 @@ std::vector<Vec3> Bundle3D::getTrianglesList(std::string_view path)
for (auto iter : meshs.meshDatas)
{
int preVertexSize = iter->getPerVertexSize() / sizeof(float);
for (const auto& indexArray : iter->subMeshIndices)
for (const auto& indices : iter->subMeshIndices)
{
for (auto i : indexArray)
{
trianglesList.push_back(Vec3(iter->vertex[i * preVertexSize], iter->vertex[i * preVertexSize + 1],
iter->vertex[i * preVertexSize + 2]));
}
indices.for_each([&](unsigned int ind) {
trianglesList.push_back(Vec3(iter->vertex[ind * preVertexSize], iter->vertex[ind * preVertexSize + 1],
iter->vertex[ind * preVertexSize + 2]));
});
}
}
@ -2324,15 +2322,16 @@ Bundle3D::~Bundle3D()
cocos2d::AABB Bundle3D::calculateAABB(const std::vector<float>& vertex,
int stride,
const std::vector<unsigned short>& index)
const IndexArray& indices)
{
AABB aabb;
stride /= 4;
for (const auto& it : index)
{
Vec3 point(vertex[it * stride], vertex[it * stride + 1], vertex[it * stride + 2]);
aabb.updateMinMax(&point, 1);
}
indices.for_each ([&](uint32_t i) {
Vec3 point(vertex[i * stride], vertex[i * stride + 1], vertex[i * stride + 2]);
aabb.updateMinMax(&point, 1);
});
return aabb;
}

View File

@ -113,7 +113,8 @@ public:
const char* mtl_basepath = nullptr);
// calculate aabb
static AABB calculateAABB(const std::vector<float>& vertex, int stride, const std::vector<unsigned short>& index);
static AABB calculateAABB(const std::vector<float>& vertex,
int stride, const IndexArray& indices);
Bundle3D();
virtual ~Bundle3D();

View File

@ -39,8 +39,136 @@
#include "3d/CC3DProgramInfo.h"
#include "yasio/detail/byte_buffer.hpp"
NS_CC_BEGIN
class IndexArray
{
static constexpr unsigned int formatToStride(backend::IndexFormat fmt) { return 1 << (int)fmt; }
static constexpr backend::IndexFormat strideToFormat(unsigned int stride)
{
return (backend::IndexFormat)(stride >> 1);
}
public:
IndexArray() : _stride(formatToStride(backend::IndexFormat::U_SHORT)) {}
IndexArray(backend::IndexFormat indexFormat) : _stride(formatToStride(indexFormat)) {}
IndexArray(std::initializer_list<uint16_t> rhs)
: _stride(formatToStride(backend::IndexFormat::U_SHORT)), _buffer(rhs)
{}
IndexArray(std::initializer_list<uint32_t> rhs, std::true_type /*U_INT*/)
: _stride(formatToStride(backend::IndexFormat::U_INT)), _buffer(rhs)
{}
IndexArray(const IndexArray& rhs) : _stride(rhs._stride), _buffer(rhs._buffer) {}
IndexArray(IndexArray&& rhs) noexcept : _stride(rhs._stride), _buffer(std::move(rhs._buffer)) {}
IndexArray& operator=(const IndexArray& rhs)
{
_stride = rhs._stride;
_buffer = rhs._buffer;
return *this;
}
IndexArray& operator=(IndexArray&& rhs) noexcept
{
this->swap(rhs);
return *this;
}
void swap(IndexArray& rhs)
{
std::swap(_stride, rhs._stride);
_buffer.swap(rhs._buffer);
}
void clear() { _buffer.clear(); }
/** clear with new index format */
void clear(backend::IndexFormat format)
{
clear();
_stride = formatToStride(format);
}
/** Pushes back a value. */
void push_back(uint32_t val)
{
assert(_stride == 2 || _stride == 4);
_buffer.append_n((uint8_t*)&val, _stride);
}
/** Inserts a list containing unsigned short (uint16_t) data. */
void insert(uint8_t* where, std::initializer_list<uint16_t> ilist)
{
assert(_stride == 2);
_buffer.insert(where, (uint8_t*)ilist.begin(), (uint8_t*)ilist.end());
}
/** Inserts a list containing unsigned int (uint32_t) data. */
void insert(uint8_t* where, std::initializer_list<uint32_t> ilist, std::true_type)
{
assert(_stride == 4);
_buffer.insert(where, (uint8_t*)ilist.begin(), (uint8_t*)ilist.end());
}
/** Inserts range data. */
void insert(uint8_t* where, const void* first, const void* last)
{
_buffer.insert(where, (const uint8_t*)first, (const uint8_t*)last);
}
template <typename _Ty>
_Ty& at(size_t idx)
{
assert(sizeof(_Ty) == _stride);
if (idx < this->size())
return (_Ty&)_buffer[idx * sizeof(_Ty)];
throw std::out_of_range("IndexArray: out of range!");
}
uint8_t* begin() noexcept { return _buffer.begin(); }
uint8_t* end() noexcept { return _buffer.end(); }
const uint8_t* begin() const noexcept { return _buffer.begin(); }
const uint8_t* end() const noexcept { return _buffer.end(); }
uint8_t* data() noexcept { return _buffer.data(); }
const uint8_t* data() const noexcept { return _buffer.data(); }
/** returns the count of indices in the container. */
size_t size() const { return _buffer.size() / _stride; }
/** returns the size of the container in bytes. */
size_t bsize() const { return _buffer.size(); }
/** resizes the count of indices in the container. */
void resize(size_t size) { _buffer.resize(size * _stride); }
/** resizes the container in bytes. */
void bresize(size_t size) { _buffer.resize(size); }
/** returns true if the container is empty. Otherwise, false. */
bool empty() const { return _buffer.empty(); }
/** returns the format of the index array. */
backend::IndexFormat format() const { return strideToFormat(_stride); }
template <typename _Fty>
void for_each(_Fty cb) const
{
assert(_stride == 2 || _stride == 4);
for (auto it = _buffer.begin(); it != _buffer.end(); it += _stride)
{
uint32_t val = 0;
memcpy(&val, it, _stride);
cb(val);
}
}
protected:
unsigned int _stride;
yasio::byte_buffer _buffer;
};
/**mesh vertex attribute
* @js NA
* @lua NA
@ -128,13 +256,14 @@ struct NodeDatas
}
};
/**mesh data
* @js NA
* @lua NA
*/
struct MeshData
{
typedef std::vector<unsigned short> IndexArray;
using IndexArray = ::cocos2d::IndexArray;
std::vector<float> vertex;
int vertexSizeInFloat;
std::vector<IndexArray> subMeshIndices;
@ -147,7 +276,7 @@ struct MeshData
public:
/**
* Get per vertex size
* @return return the sum of each vertex's all attribute size.
* @return return the sum size of all vertex attributes.
*/
int getPerVertexSize() const
{

View File

@ -113,6 +113,7 @@ Mesh::Mesh()
, _visible(true)
, _isTransparent(false)
, _force2DQueue(false)
, meshIndexFormat(CustomCommand::IndexFormat::U_SHORT)
, _meshIndexData(nullptr)
, _blend(BlendFunc::ALPHA_NON_PREMULTIPLIED)
, _blendDirty(true)
@ -222,10 +223,13 @@ Mesh* Mesh::create(const std::vector<float>& vertices,
meshdata.vertex = vertices;
meshdata.subMeshIndices.push_back(indices);
meshdata.subMeshIds.push_back("");
auto meshvertexdata = MeshVertexData::create(meshdata);
auto meshvertexdata = MeshVertexData::create(meshdata, indices.format());
auto indexData = meshvertexdata->getMeshIndexDataByIndex(0);
return create("", indexData);
auto mesh = create("", indexData);
mesh->setIndexFormat(indices.format());
return mesh;
}
Mesh* Mesh::create(std::string_view name, MeshIndexData* indexData, MeshSkin* skin)
@ -728,12 +732,18 @@ CustomCommand::PrimitiveType Mesh::getPrimitiveType() const
ssize_t Mesh::getIndexCount() const
{
return _meshIndexData->getIndexBuffer()->getSize() / sizeof(uint16_t);
return _meshIndexData->getIndexBuffer()->getSize() /
(meshIndexFormat == CustomCommand::IndexFormat::U_SHORT ? sizeof(uint16_t) : sizeof(uint32_t));
}
CustomCommand::IndexFormat Mesh::getIndexFormat() const
{
return CustomCommand::IndexFormat::U_SHORT;
return meshIndexFormat;
}
void Mesh::setIndexFormat(CustomCommand::IndexFormat indexFormat)
{
meshIndexFormat = indexFormat;
}
backend::Buffer* Mesh::getIndexBuffer() const

View File

@ -64,7 +64,7 @@ class CC_DLL Mesh : public Ref
friend class Sprite3D;
public:
typedef std::vector<unsigned short> IndexArray;
/**create mesh from positions, normals, and so on, single SubMesh*/
static Mesh* create(const std::vector<float>& positions,
const std::vector<float>& normals,
@ -191,6 +191,12 @@ public:
* @lua NA
*/
CustomCommand::IndexFormat getIndexFormat() const;
/**
* set index format
*
* @lua NA
*/
void setIndexFormat(CustomCommand::IndexFormat indexFormat);
/**
* get index buffer
*
@ -253,6 +259,7 @@ protected:
bool _visible; // is the submesh visible
bool _isTransparent; // is this mesh transparent, it is a property of material in fact
bool _force2DQueue; // add this mesh to 2D render queue
CustomCommand::IndexFormat meshIndexFormat;
std::string _name;
MeshIndexData* _meshIndexData;

View File

@ -75,7 +75,7 @@ MeshIndexData::MeshIndexData()
{
#if CC_ENABLE_CACHE_TEXTURE_DATA
_backToForegroundListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom*) {
_indexBuffer->updateData((void*)_indexData.data(), _indexData.size() * sizeof(_indexData[0]));
_indexBuffer->updateData((void*)_indexData.data(), _indexData.bsize());
});
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, 1);
#endif
@ -108,7 +108,7 @@ void MeshVertexData::setVertexData(const std::vector<float>& vertexData)
#endif
}
MeshVertexData* MeshVertexData::create(const MeshData& meshdata)
MeshVertexData* MeshVertexData::create(const MeshData& meshdata, CustomCommand::IndexFormat format)
{
auto vertexdata = new MeshVertexData();
vertexdata->_vertexBuffer = backend::Device::getInstance()->newBuffer(
@ -132,28 +132,29 @@ MeshVertexData* MeshVertexData::create(const MeshData& meshdata)
bool needCalcAABB = (meshdata.subMeshAABB.size() != meshdata.subMeshIndices.size());
for (size_t i = 0, size = meshdata.subMeshIndices.size(); i < size; ++i)
{
auto& index = meshdata.subMeshIndices[i];
auto& indices = meshdata.subMeshIndices[i];
// auto indexSize = format == CustomCommand::IndexFormat::U_SHORT ? sizeof(uint16_t) : sizeof(uint32_t);
auto indexBuffer = backend::Device::getInstance()->newBuffer(
index.size() * sizeof(index[0]), backend::BufferType::INDEX, backend::BufferUsage::STATIC);
indices.bsize() /* * indexSize*/, backend::BufferType::INDEX, backend::BufferUsage::STATIC);
indexBuffer->autorelease();
#if CC_ENABLE_CACHE_TEXTURE_DATA
indexBuffer->usingDefaultStoredData(false);
#endif
indexBuffer->updateData((void*)index.data(), index.size() * sizeof(index[0]));
indexBuffer->updateData((void*)indices.data(), indices.bsize() /* * indexSize*/);
std::string id = (i < meshdata.subMeshIds.size() ? meshdata.subMeshIds[i] : "");
MeshIndexData* indexdata = nullptr;
if (needCalcAABB)
{
auto aabb = Bundle3D::calculateAABB(meshdata.vertex, meshdata.getPerVertexSize(), index);
auto aabb = Bundle3D::calculateAABB(meshdata.vertex, meshdata.getPerVertexSize(), indices);
indexdata = MeshIndexData::create(id, vertexdata, indexBuffer, aabb);
}
else
indexdata = MeshIndexData::create(id, vertexdata, indexBuffer, meshdata.subMeshAABB[i]);
#if CC_ENABLE_CACHE_TEXTURE_DATA
indexdata->setIndexData(index);
indexdata->setIndexData(indices);
#endif
vertexdata->_indexs.pushBack(indexdata);
vertexdata->_indices.pushBack(indexdata);
}
vertexdata->autorelease();
@ -162,7 +163,7 @@ MeshVertexData* MeshVertexData::create(const MeshData& meshdata)
MeshIndexData* MeshVertexData::getMeshIndexDataById(std::string_view id) const
{
for (auto it : _indexs)
for (auto it : _indices)
{
if (it->getId() == id)
return it;
@ -193,7 +194,7 @@ MeshVertexData::MeshVertexData()
MeshVertexData::~MeshVertexData()
{
CC_SAFE_RELEASE(_vertexBuffer);
_indexs.clear();
_indices.clear();
_vertexData.clear();
#if CC_ENABLE_CACHE_TEXTURE_DATA
Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundListener);

View File

@ -112,7 +112,7 @@ class CC_DLL MeshVertexData : public Ref
public:
/**create*/
static MeshVertexData* create(const MeshData& meshdata);
static MeshVertexData* create(const MeshData& meshdata, CustomCommand::IndexFormat format = CustomCommand::IndexFormat::U_SHORT);
/** get vertexbuffer */
backend::Buffer* getVertexBuffer() const { return _vertexBuffer; }
@ -124,9 +124,9 @@ public:
const MeshVertexAttrib& getMeshVertexAttrib(ssize_t index) const { return _attribs[index]; }
/** get index data count */
ssize_t getMeshIndexDataCount() const { return _indexs.size(); }
ssize_t getMeshIndexDataCount() const { return _indices.size(); }
/** get index data by index */
MeshIndexData* getMeshIndexDataByIndex(int index) const { return _indexs.at(index); }
MeshIndexData* getMeshIndexDataByIndex(int index) const { return _indices.at(index); }
/** get index data by id */
MeshIndexData* getMeshIndexDataById(std::string_view id) const;
@ -144,8 +144,8 @@ public:
protected:
backend::Buffer* _vertexBuffer = nullptr; // vertex buffer
ssize_t _sizePerVertex = -1;
Vector<MeshIndexData*> _indexs; // index data
std::vector<MeshVertexAttrib> _attribs; // vertex attributes
Vector<MeshIndexData*> _indices; // index data
std::vector<MeshVertexAttrib> _attribs; // vertex attributes
int _vertexCount = 0; // vertex count
std::vector<float> _vertexData;

View File

@ -51,6 +51,9 @@ Sprite3DMaterial* Sprite3DMaterial::_vertexLitMaterialSkin = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_diffuseMaterialSkin = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_bumpedDiffuseMaterialSkin = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_quadTextureMaterial = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_quadColorMaterial = nullptr;
backend::ProgramState* Sprite3DMaterial::_unLitMaterialProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_unLitNoTexMaterialProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_vertexLitMaterialProgState = nullptr;
@ -63,6 +66,9 @@ backend::ProgramState* Sprite3DMaterial::_vertexLitMaterialSkinProgState = n
backend::ProgramState* Sprite3DMaterial::_diffuseMaterialSkinProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_bumpedDiffuseMaterialSkinProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_quadTextureMaterialProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_quadColorMaterialProgState = nullptr;
void Sprite3DMaterial::createBuiltInMaterial()
{
auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::SKINPOSITION_TEXTURE_3D);
@ -129,6 +135,22 @@ void Sprite3DMaterial::createBuiltInMaterial()
{
_bumpedDiffuseMaterialSkin->_type = Sprite3DMaterial::MaterialType::BUMPED_DIFFUSE;
}
program = backend::Program::getBuiltinProgram(backend::ProgramType::QUAD_TEXTURE_2D);
_quadTextureMaterialProgState = new backend::ProgramState(program);
_quadTextureMaterial = new Sprite3DMaterial();
if (_quadTextureMaterial && _quadTextureMaterial->initWithProgramState(_quadTextureMaterialProgState))
{
_quadTextureMaterial->_type = Sprite3DMaterial::MaterialType::QUAD_TEXTURE;
}
program = backend::Program::getBuiltinProgram(backend::ProgramType::QUAD_COLOR_2D);
_quadColorMaterialProgState = new backend::ProgramState(program);
_quadColorMaterial = new Sprite3DMaterial();
if (_quadColorMaterial && _quadColorMaterial->initWithProgramState(_quadColorMaterialProgState))
{
_quadColorMaterial->_type = Sprite3DMaterial::MaterialType::QUAD_COLOR;
}
}
void Sprite3DMaterial::releaseBuiltInMaterial()
@ -214,7 +236,7 @@ Sprite3DMaterial* Sprite3DMaterial::createBuiltInMaterial(MaterialType type, boo
break;
case Sprite3DMaterial::MaterialType::VERTEX_LIT:
CCASSERT(0, "not implement");
CCASSERT(0, "not implemented");
break;
case Sprite3DMaterial::MaterialType::DIFFUSE:
@ -229,6 +251,14 @@ Sprite3DMaterial* Sprite3DMaterial::createBuiltInMaterial(MaterialType type, boo
material = skinned ? _bumpedDiffuseMaterialSkin : _bumpedDiffuseMaterial;
break;
case Sprite3DMaterial::MaterialType::QUAD_TEXTURE:
material = _quadTextureMaterial;
break;
case Sprite3DMaterial::MaterialType::QUAD_COLOR:
material = _quadColorMaterial;
break;
default:
break;
}

View File

@ -63,6 +63,8 @@ public:
DIFFUSE, // diffuse (pixel lighting)
DIFFUSE_NOTEX, // diffuse (without texture)
BUMPED_DIFFUSE, // bumped diffuse
QUAD_TEXTURE, // textured quad material
QUAD_COLOR, // colored quad material (without texture)
// Custom material
CUSTOM, // Create from material file
@ -134,6 +136,9 @@ protected:
static Sprite3DMaterial* _diffuseMaterialSkin;
static Sprite3DMaterial* _bumpedDiffuseMaterialSkin;
static Sprite3DMaterial* _quadTextureMaterial;
static Sprite3DMaterial* _quadColorMaterial;
static backend::ProgramState* _unLitMaterialProgState;
static backend::ProgramState* _unLitNoTexMaterialProgState;
static backend::ProgramState* _vertexLitMaterialProgState;
@ -145,6 +150,9 @@ protected:
static backend::ProgramState* _vertexLitMaterialSkinProgState;
static backend::ProgramState* _diffuseMaterialSkinProgState;
static backend::ProgramState* _bumpedDiffuseMaterialSkinProgState;
static backend::ProgramState* _quadTextureMaterialProgState;
static backend::ProgramState* _quadColorMaterialProgState;
};
/**

View File

@ -1249,7 +1249,7 @@ void Console::commandFileUtilsSubCommandFlush(socket_native_type /*fd*/, std::st
void Console::commandFps(socket_native_type fd, std::string_view /*args*/)
{
Console::Utility::mydprintf(fd, "FPS is: %s\n", Director::getInstance()->isStatsDisplay() ? "on" : "off");
Console::Utility::mydprintf(fd, "FPS is: %s\n", Director::getInstance()->isDisplayStats() ? "on" : "off");
}
void Console::commandFpsSubCommandOnOff(socket_native_type /*fd*/, std::string_view args)
@ -1257,7 +1257,7 @@ void Console::commandFpsSubCommandOnOff(socket_native_type /*fd*/, std::string_v
bool state = (args.compare("on") == 0);
Director* dir = Director::getInstance();
Scheduler* sched = dir->getScheduler();
sched->performFunctionInCocosThread(std::bind(&Director::setStatsDisplay, dir, state));
sched->performFunctionInCocosThread(std::bind(&Director::setDisplayStats, dir, state));
}
void Console::commandHelp(socket_native_type fd, std::string_view /*args*/)

View File

@ -1303,92 +1303,11 @@ void Director::createStatsLabel()
_drawnVerticesLabel->setIgnoreContentScaleFactor(true);
_drawnVerticesLabel->setScale(scaleFactor);
setStatsAnchor();
}
void Director::setStatsAnchor(AnchorPreset anchor)
{
if (!_displayStats)
return;
// Initialize stat counters
if (!_FPSLabel)
showStats();
{
static Vec2 _fpsPosition = {0, 0};
auto safeOrigin = getSafeAreaRect().origin;
auto safeSize = getSafeAreaRect().size;
const int height_spacing = (int)(22 / CC_CONTENT_SCALE_FACTOR());
switch (anchor)
{
case AnchorPreset::BOTTOM_LEFT:
_fpsPosition = Vec2(0, 0);
_drawnVerticesLabel->setAnchorPoint({0, 0});
_drawnBatchesLabel->setAnchorPoint({0, 0});
_FPSLabel->setAnchorPoint({0, 0});
break;
case AnchorPreset::CENTER_LEFT:
_fpsPosition = Vec2(0, safeSize.height / 2 - height_spacing * 1.5);
_drawnVerticesLabel->setAnchorPoint({0, 0.0});
_drawnBatchesLabel->setAnchorPoint({0, 0.0});
_FPSLabel->setAnchorPoint({0, 0});
break;
case AnchorPreset::TOP_LEFT:
_fpsPosition = Vec2(0, safeSize.height - height_spacing * 3);
_drawnVerticesLabel->setAnchorPoint({0, 0});
_drawnBatchesLabel->setAnchorPoint({0, 0});
_FPSLabel->setAnchorPoint({0, 0});
break;
case AnchorPreset::BOTTOM_RIGHT:
_fpsPosition = Vec2(safeSize.width, 0);
_drawnVerticesLabel->setAnchorPoint({1, 0});
_drawnBatchesLabel->setAnchorPoint({1, 0});
_FPSLabel->setAnchorPoint({1, 0});
break;
case AnchorPreset::CENTER_RIGHT:
_fpsPosition = Vec2(safeSize.width, safeSize.height / 2 - height_spacing * 1.5);
_drawnVerticesLabel->setAnchorPoint({1, 0.0});
_drawnBatchesLabel->setAnchorPoint({1, 0.0});
_FPSLabel->setAnchorPoint({1, 0.0});
break;
case AnchorPreset::TOP_RIGHT:
_fpsPosition = Vec2(safeSize.width, safeSize.height - height_spacing * 3);
_drawnVerticesLabel->setAnchorPoint({1, 0});
_drawnBatchesLabel->setAnchorPoint({1, 0});
_FPSLabel->setAnchorPoint({1, 0});
break;
case AnchorPreset::BOTTOM_CENTER:
_fpsPosition = Vec2(safeSize.width / 2, 0);
_drawnVerticesLabel->setAnchorPoint({0.5, 0});
_drawnBatchesLabel->setAnchorPoint({0.5, 0});
_FPSLabel->setAnchorPoint({0.5, 0});
break;
case AnchorPreset::CENTER:
_fpsPosition = Vec2(safeSize.width / 2, safeSize.height / 2 - height_spacing * 1.5);
_drawnVerticesLabel->setAnchorPoint({0.5, 0.0});
_drawnBatchesLabel->setAnchorPoint({0.5, 0.0});
_FPSLabel->setAnchorPoint({0.5, 0.0});
break;
case AnchorPreset::TOP_CENTER:
_fpsPosition = Vec2(safeSize.width / 2, safeSize.height - height_spacing * 3);
_drawnVerticesLabel->setAnchorPoint({0.5, 0});
_drawnBatchesLabel->setAnchorPoint({0.5, 0});
_FPSLabel->setAnchorPoint({0.5, 0});
break;
default: // FPSPosition::BOTTOM_LEFT
_fpsPosition = Vec2(0, 0);
_drawnVerticesLabel->setAnchorPoint({0, 0});
_drawnBatchesLabel->setAnchorPoint({0, 0});
_FPSLabel->setAnchorPoint({0, 0});
break;
}
_drawnVerticesLabel->setPosition(Vec2(0, height_spacing * 2.0f) + _fpsPosition + safeOrigin);
_drawnBatchesLabel->setPosition(Vec2(0, height_spacing * 1.0f) + _fpsPosition + safeOrigin);
_FPSLabel->setPosition(Vec2(0, height_spacing * 0.0f) + _fpsPosition + safeOrigin);
}
auto safeOrigin = getSafeAreaRect().origin;
const int height_spacing = (int)(22 / CC_CONTENT_SCALE_FACTOR());
_drawnVerticesLabel->setPosition(Vec2(0, height_spacing * 2.0f) + safeOrigin);
_drawnBatchesLabel->setPosition(Vec2(0, height_spacing * 1.0f) + safeOrigin);
_FPSLabel->setPosition(Vec2(0, height_spacing * 0.0f) + safeOrigin);
}
#endif // #if !CC_STRIP_FPS

View File

@ -62,6 +62,21 @@ class Camera;
class Console;
/**
* @brief Matrix stack type.
*/
enum class MATRIX_STACK_TYPE
{
/// Model view matrix stack
MATRIX_STACK_MODELVIEW,
/// projection matrix stack
MATRIX_STACK_PROJECTION,
/// texture matrix stack
MATRIX_STACK_TEXTURE
};
/**
@brief Class that creates and handles the main Window and manages how
and when to execute the Scenes.
@ -143,19 +158,14 @@ public:
/** Sets the FPS value. FPS = 1/interval. */
void setAnimationInterval(float interval);
/** Whether the FPS on the bottom-left corner of the screen is displayed or not. */
bool isStatsDisplay() { return _displayStats; }
/** Whether or not displaying the FPS on the bottom-left corner of the screen is enabled or not. */
bool isDisplayStats() { return _displayStats; }
/** Display the FPS on the bottom-left corner of the screen. */
void setStatsDisplay(bool displayStats) { _displayStats = displayStats; }
void setDisplayStats(bool displayStats) { _displayStats = displayStats; }
/** Gets the seconds per frame. */
float getSecondsPerFrame() { return _secondsPerFrame; }
/** Sets the stats corner displayed on screen if display stats is enabled. */
void setStatsAnchor(AnchorPreset anchor = (AnchorPreset)0);
/** Sets the FPS value. */
/**
* Get the GLView.
* @lua NA

View File

@ -38,7 +38,6 @@ set(COCOS_BASE_HEADER
base/ccConstants.h
base/CCEvent.h
base/ccTypes.h
base/ccEnums.h
base/CCAsyncTaskPool.h
base/ccRandom.h
base/CCRef.h

View File

@ -1,140 +0,0 @@
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2020 C4games Ltd.
https://adxeproject.github.io/
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
NS_CC_BEGIN
/**
* @brief Effects used by `Label`
*/
enum class LabelEffect
{
// FIXME: Covert them to bitwise. More than one effect should be supported
NORMAL,
OUTLINE,
SHADOW,
GLOW,
ITALICS,
BOLD,
UNDERLINE,
STRIKETHROUGH,
ALL
};
/**
* @brief Interval change reason.
*/
enum class SetIntervalReason : char
{
BY_GAME = 0,
BY_ENGINE,
BY_SYSTEM,
BY_SCENE_CHANGE,
BY_DIRECTOR_PAUSE
};
/**
* @brief Texture flags.
*/
struct TextureFlag
{
enum
{
NONE = 0,
ANTIALIAS_ENABLED = 1 << 1,
PREMULTIPLIEDALPHA = 1 << 2,
RENDERTARGET = 1 << 3,
};
};
/**
* @brief Texture sampler flags.
*/
struct TextureSamplerFlag
{
enum
{
DEFAULT = 0,
DUAL_SAMPLER = 1 << 1,
};
};
/**
* @brief Matrix stack type.
*/
enum class MATRIX_STACK_TYPE
{
/// Model view matrix stack
MATRIX_STACK_MODELVIEW,
/// projection matrix stack
MATRIX_STACK_PROJECTION,
/// texture matrix stack
MATRIX_STACK_TEXTURE
};
/**
* @brief Anchor presets used to position nodes in corners
*/
enum class AnchorPreset
{
BOTTOM_LEFT = 0,
BOTTOM_CENTER = 1,
BOTTOM_RIGHT = 2,
CENTER_LEFT = 3,
CENTER = 4,
CENTER_RIGHT = 5,
TOP_LEFT = 6,
TOP_CENTER = 7,
TOP_RIGHT = 8
};
/**
* Particle emission shapes.
* Supported shapes are Point, Rectangle, RectangularTorus, Circle, Torus, Cone, Cone Torus, Texture alpha emission mask
* @since adxe-1.0.0b8
*/
enum class EmissionShapeType
{
// Emission shape of type point
POINT,
// Emission shape of type rectangle
RECT,
// Emission shape of type rectangular torus
RECTTORUS,
// Emission shape of type circle or cone
CIRCLE,
// Emission shape of type torus or cone torus
TORUS,
// Emission shape of type texture alpha mask
TEXTURE_ALPHA_MASK
};
NS_CC_END

View File

@ -33,7 +33,6 @@ THE SOFTWARE.
#include "math/CCMath.h"
#include "base/CCRef.h"
#include "renderer/backend/Types.h"
#include "ccEnums.h"
/**
* @addtogroup base
@ -623,6 +622,24 @@ struct CC_DLL FontDefinition
int _overflow = 0;
};
/**
* @brief Effects used by `Label`
*
*/
enum class LabelEffect
{
// FIXME: Covert them to bitwise. More than one effect should be supported
NORMAL,
OUTLINE,
SHADOW,
GLOW,
ITALICS,
BOLD,
UNDERLINE,
STRIKETHROUGH,
ALL
};
/** @struct Acceleration
* The device accelerometer reports values for each axis in units of g-force.
*/
@ -639,6 +656,15 @@ public:
extern const std::string CC_DLL STD_STRING_EMPTY;
extern const ssize_t CC_DLL CC_INVALID_INDEX;
enum class SetIntervalReason : char
{
BY_GAME = 0,
BY_ENGINE,
BY_SYSTEM,
BY_SCENE_CHANGE,
BY_DIRECTOR_PAUSE
};
struct CC_DLL Viewport
{
int x = 0;
@ -655,6 +681,26 @@ struct CC_DLL ScissorRect
float height = 0;
};
struct TextureFlag
{
enum
{
NONE = 0,
ANTIALIAS_ENABLED = 1 << 1,
PREMULTIPLIEDALPHA = 1 << 2,
RENDERTARGET = 1 << 3,
};
};
struct TextureSamplerFlag
{
enum
{
DEFAULT = 0,
DUAL_SAMPLER = 1 << 1,
};
};
using TextureUsage = backend::TextureUsage;
using PixelFormat = backend::PixelFormat;

View File

@ -12,7 +12,6 @@ set(COCOS_MATH_HEADER
math/MathUtil.h
math/CCMath.h
math/Rect.h
math/RngSeed.hpp
)
set(COCOS_MATH_SRC

View File

@ -1,10 +1,7 @@
#pragma warning(suppress : 4244)
#ifndef RNGSEED_H_
#define RNGSEED_H_
/** A more effective seeded random number generator struct, made by kiss rng.
* The numbers that are generated are inclusive of rhs value
* @since adxe-1.0.0b8
*/
struct RngSeed

View File

@ -53,13 +53,14 @@ public:
using PrimitiveType = backend::PrimitiveType;
/**
Buffer usage of vertex/index buffer. If the contents is not updated every frame,
then use STATIC, other use DYNAMIC.
Buffer usage of vertex/index buffer. If the contents are not updated every frame,
then STATIC should be used. Otherwise, DYNAMIC should be used.
This flag is not improtant because most GPU drivers ignore it, so it's best left to STATIC.
*/
using BufferUsage = backend::BufferUsage;
/**
The index format determine the size for index data. U_SHORT is enough for most
cases.
The index format that determines the size of index data. U_SHORT (65535 vertices) is enough for most
cases, But support for U_INT (4294967295 vertices) has been added.
*/
using IndexFormat = backend::IndexFormat;
@ -208,6 +209,8 @@ TODO: should remove it.
inline IndexFormat getIndexFormat() const { return _indexFormat; }
inline void setIndexFormat(IndexFormat format) { _indexFormat = format; }
/**
* set a callback which will be invoke before rendering
*/

View File

@ -123,6 +123,8 @@ bool ProgramCache::init()
registerProgramFactory(ProgramType::TERRAIN_3D, CC3D_terrain_vert, CC3D_terrain_frag);
registerProgramFactory(ProgramType::PARTICLE_TEXTURE_3D, CC3D_particle_vert, CC3D_particleTexture_frag);
registerProgramFactory(ProgramType::PARTICLE_COLOR_3D, CC3D_particle_vert, CC3D_particleColor_frag);
registerProgramFactory(ProgramType::QUAD_COLOR_2D, CC2D_quad_vert, CC2D_quadColor_frag);
registerProgramFactory(ProgramType::QUAD_TEXTURE_2D, CC2D_quad_vert, CC2D_quadTexture_frag);
registerProgramFactory(ProgramType::HSV, positionTextureColor_vert, hsv_frag);
registerProgramFactory(ProgramType::HSV_DUAL_SAMPLER, positionTextureColor_vert, dualSampler_hsv_frag);

View File

@ -159,8 +159,8 @@ enum class TextureUsage : uint32_t
enum class IndexFormat : uint32_t
{
U_SHORT,
U_INT
U_SHORT = 1,
U_INT = 2,
};
enum class VertexStepMode : uint32_t
@ -431,6 +431,9 @@ struct ProgramType
PARTICLE_TEXTURE_3D, // CC3D_particle_vert, CC3D_particleTexture_frag
PARTICLE_COLOR_3D, // CC3D_particle_vert, CC3D_particleColor_frag
QUAD_COLOR_2D, // CC2D_quad_vert, CC2D_quadColor_frag
QUAD_TEXTURE_2D, // CC2D_quad_vert, CC2D_quadTexture_frag
HSV,
HSV_DUAL_SAMPLER,
HSV_ETC1 = HSV_DUAL_SAMPLER,

View File

@ -73,4 +73,7 @@ NS_CC_BEGIN
#include "renderer/shaders/hsv.frag"
#include "renderer/shaders/dualSampler_hsv.frag"
#include "renderer/shaders/quad.vert"
#include "renderer/shaders/quad.frag"
NS_CC_END

View File

@ -78,6 +78,10 @@ extern CC_DLL const char* CC3D_skybox_vert;
extern CC_DLL const char* CC3D_terrain_frag;
extern CC_DLL const char* CC3D_terrain_vert;
extern CC_DLL const char* CC2D_quadTexture_frag;
extern CC_DLL const char* CC2D_quadColor_frag;
extern CC_DLL const char* CC2D_quad_vert;
extern CC_DLL const char* hsv_frag;
extern CC_DLL const char* dualSampler_hsv_frag;
NS_CC_END

View File

@ -0,0 +1,58 @@
/****************************************************************************
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
https://adxeproject.github.io/
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.
****************************************************************************/
const char* CC2D_quadTexture_frag = R"(
#ifdef GL_ES
varying mediump vec2 TextureCoordOut;
varying mediump vec4 ColorOut;
#else
varying vec4 ColorOut;
varying vec2 TextureCoordOut;
#endif
uniform vec4 u_color;
uniform sampler2D u_texture;
void main(void)
{
gl_FragColor = texture2D(u_texture, TextureCoordOut) * ColorOut * u_color;
}
)";
const char* CC2D_quadColor_frag = R"(
#ifdef GL_ES
varying mediump vec4 ColorOut;
#else
varying vec4 ColorOut;
#endif
uniform vec4 u_color;
void main(void)
{
gl_FragColor = ColorOut * u_color;
}
)";

View File

@ -0,0 +1,44 @@
/****************************************************************************
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
https://adxeproject.github.io/
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.
****************************************************************************/
const char* CC2D_quad_vert = R"(
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord;
varying vec2 TextureCoordOut;
varying vec4 ColorOut;
uniform mat4 u_PMatrix;
void main()
{
ColorOut = a_color;
TextureCoordOut = a_texCoord;
TextureCoordOut.y = 1.0 - TextureCoordOut.y;
gl_Position = u_PMatrix * a_position;
}
)";

View File

@ -78,7 +78,7 @@ bool AppDelegate::applicationDidFinishLaunching()
}
// turn on display FPS
director->setStatsDisplay(true);
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0f / 60);

View File

@ -188,49 +188,22 @@ void SimpleSnake::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event)
{
switch (keyCode)
{
case EventKeyboard::KeyCode::KEY_LEFT_ARROW:
case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_ARROW:
if (dir != 2)
dir = 1;
break;
case EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
if (dir != 1)
dir = 2;
break;
case EventKeyboard::KeyCode::KEY_UP_ARROW:
case cocos2d::EventKeyboard::KeyCode::KEY_UP_ARROW:
if (dir != 3)
dir = 0;
break;
case EventKeyboard::KeyCode::KEY_DOWN_ARROW:
case cocos2d::EventKeyboard::KeyCode::KEY_DOWN_ARROW:
if (dir != 0)
dir = 3;
break;
case EventKeyboard::KeyCode::KEY_1:
Director::getInstance()->setFPSPos(FPSPosition::BOTTOM_LEFT);
break;
case EventKeyboard::KeyCode::KEY_4:
Director::getInstance()->setFPSPos(FPSPosition::CENTER_LEFT);
break;
case EventKeyboard::KeyCode::KEY_7:
Director::getInstance()->setFPSPos(FPSPosition::TOP_LEFT);
break;
case EventKeyboard::KeyCode::KEY_8:
Director::getInstance()->setFPSPos(FPSPosition::TOP_CENTER);
break;
case EventKeyboard::KeyCode::KEY_9:
Director::getInstance()->setFPSPos(FPSPosition::TOP_RIGHT);
break;
case EventKeyboard::KeyCode::KEY_6:
Director::getInstance()->setFPSPos(FPSPosition::CENTER_RIGHT);
break;
case EventKeyboard::KeyCode::KEY_3:
Director::getInstance()->setFPSPos(FPSPosition::BOTTOM_RIGHT);
break;
case EventKeyboard::KeyCode::KEY_2:
Director::getInstance()->setFPSPos(FPSPosition::BOTTOM_CENTER);
break;
case EventKeyboard::KeyCode::KEY_5:
Director::getInstance()->setFPSPos(FPSPosition::CENTER);
break;
default:
break;
}

View File

@ -16851,67 +16851,6 @@ int lua_cocos2dx_Director_drawScene(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_Director_setStatsAnchor(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Director* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Director",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Director*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Director_setStatsAnchor'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Director_setStatsAnchor'", nullptr);
return 0;
}
cobj->setStatsAnchor();
lua_settop(tolua_S, 1);
return 1;
}
if (argc == 1)
{
cocos2d::AnchorPreset arg0;
ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "cc.Director:setStatsAnchor");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Director_setStatsAnchor'", nullptr);
return 0;
}
cobj->setStatsAnchor(arg0);
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Director:setStatsAnchor",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Director_setStatsAnchor'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Director_restart(lua_State* tolua_S)
{
int argc = 0;
@ -17056,7 +16995,7 @@ int lua_cocos2dx_Director_loadIdentityMatrix(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_Director_isStatsDisplay(lua_State* tolua_S)
int lua_cocos2dx_Director_isDisplayStats(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Director* cobj = nullptr;
@ -17076,7 +17015,7 @@ int lua_cocos2dx_Director_isStatsDisplay(lua_State* tolua_S)
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Director_isStatsDisplay'", nullptr);
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Director_isDisplayStats'", nullptr);
return 0;
}
#endif
@ -17086,19 +17025,19 @@ int lua_cocos2dx_Director_isStatsDisplay(lua_State* tolua_S)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Director_isStatsDisplay'", nullptr);
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Director_isDisplayStats'", nullptr);
return 0;
}
bool ret = cobj->isStatsDisplay();
bool ret = cobj->isDisplayStats();
tolua_pushboolean(tolua_S,(bool)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Director:isStatsDisplay",argc, 0);
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Director:isDisplayStats",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Director_isStatsDisplay'.",&tolua_err);
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Director_isDisplayStats'.",&tolua_err);
#endif
return 0;
@ -17638,7 +17577,7 @@ int lua_cocos2dx_Director_isPaused(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_Director_setStatsDisplay(lua_State* tolua_S)
int lua_cocos2dx_Director_setDisplayStats(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Director* cobj = nullptr;
@ -17658,7 +17597,7 @@ int lua_cocos2dx_Director_setStatsDisplay(lua_State* tolua_S)
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Director_setStatsDisplay'", nullptr);
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Director_setDisplayStats'", nullptr);
return 0;
}
#endif
@ -17668,22 +17607,22 @@ int lua_cocos2dx_Director_setStatsDisplay(lua_State* tolua_S)
{
bool arg0;
ok &= luaval_to_boolean(tolua_S, 2,&arg0, "cc.Director:setStatsDisplay");
ok &= luaval_to_boolean(tolua_S, 2,&arg0, "cc.Director:setDisplayStats");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Director_setStatsDisplay'", nullptr);
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Director_setDisplayStats'", nullptr);
return 0;
}
cobj->setStatsDisplay(arg0);
cobj->setDisplayStats(arg0);
lua_settop(tolua_S, 1);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Director:setStatsDisplay",argc, 1);
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Director:setDisplayStats",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Director_setStatsDisplay'.",&tolua_err);
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Director_setDisplayStats'.",&tolua_err);
#endif
return 0;
@ -17975,11 +17914,10 @@ int lua_register_cocos2dx_Director(lua_State* tolua_S)
tolua_function(tolua_S,"setNotificationNode",lua_cocos2dx_Director_setNotificationNode);
tolua_function(tolua_S,"setChildrenIndexerEnabled",lua_cocos2dx_Director_setChildrenIndexerEnabled);
tolua_function(tolua_S,"drawScene",lua_cocos2dx_Director_drawScene);
tolua_function(tolua_S,"setStatsAnchor",lua_cocos2dx_Director_setStatsAnchor);
tolua_function(tolua_S,"restart",lua_cocos2dx_Director_restart);
tolua_function(tolua_S,"popScene",lua_cocos2dx_Director_popScene);
tolua_function(tolua_S,"loadIdentityMatrix",lua_cocos2dx_Director_loadIdentityMatrix);
tolua_function(tolua_S,"isStatsDisplay",lua_cocos2dx_Director_isStatsDisplay);
tolua_function(tolua_S,"isDisplayStats",lua_cocos2dx_Director_isDisplayStats);
tolua_function(tolua_S,"setProjection",lua_cocos2dx_Director_setProjection);
tolua_function(tolua_S,"getConsole",lua_cocos2dx_Director_getConsole);
tolua_function(tolua_S,"multiplyMatrix",lua_cocos2dx_Director_multiplyMatrix);
@ -17991,7 +17929,7 @@ int lua_register_cocos2dx_Director(lua_State* tolua_S)
tolua_function(tolua_S,"pushScene",lua_cocos2dx_Director_pushScene);
tolua_function(tolua_S,"getAnimationInterval",lua_cocos2dx_Director_getAnimationInterval);
tolua_function(tolua_S,"isPaused",lua_cocos2dx_Director_isPaused);
tolua_function(tolua_S,"setStatsDisplay",lua_cocos2dx_Director_setStatsDisplay);
tolua_function(tolua_S,"setDisplayStats",lua_cocos2dx_Director_setDisplayStats);
tolua_function(tolua_S,"getEventDispatcher",lua_cocos2dx_Director_getEventDispatcher);
tolua_function(tolua_S,"replaceScene",lua_cocos2dx_Director_replaceScene);
tolua_function(tolua_S,"setAnimationInterval",lua_cocos2dx_Director_setAnimationInterval);

View File

@ -2406,7 +2406,6 @@ int register_all_cocos2dx(lua_State* tolua_S);
#endif // __cocos2dx_h__

View File

@ -78,7 +78,7 @@ bool AppDelegate::applicationDidFinishLaunching()
}
// turn on display FPS
director->setStatsDisplay(true);
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0f / 60);

View File

@ -84,7 +84,7 @@ bool AppDelegate::applicationDidFinishLaunching()
director->setOpenGLView(glview);
}
director->setStatsDisplay(true);
director->setDisplayStats(true);
director->setAnimationInterval(1.0f / 60);
auto screenSize = glview->getFrameSize();

View File

@ -35,92 +35,6 @@
USING_NS_CC;
namespace {
class TextButton : public Label {
public:
static TextButton *
create(std::string_view text, const std::function<void(TextButton *)> &onTriggered) {
auto ret = new TextButton();
TTFConfig ttfconfig("fonts/arial.ttf", 25);
if (ret->setTTFConfig(ttfconfig)) {
ret->setString(text);
ret->_onTriggered = onTriggered;
ret->autorelease();
return ret;
}
delete ret;
return nullptr;
}
void setEnabled(bool enabled) {
_enabled = enabled;
if (_enabled) {
this->setColor(Color3B::WHITE);
} else {
this->setColor(Color3B::GRAY);
}
}
private:
TextButton() : _onTriggered(nullptr), _enabled(true) {
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(TextButton::onTouchBegan, this);
listener->onTouchEnded = CC_CALLBACK_2(TextButton::onTouchEnded, this);
listener->onTouchCancelled = CC_CALLBACK_2(TextButton::onTouchCancelled, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
bool touchHits(Touch *touch) {
auto hitPos = this->convertToNodeSpace(touch->getLocation());
if (hitPos.x >= 0 && hitPos.y >= 0 && hitPos.x <= _contentSize.width &&
hitPos.y <= _contentSize.height) {
return true;
}
return false;
}
bool onTouchBegan(Touch *touch, Event *event) {
auto hits = touchHits(touch);
if (hits) {
scaleButtonTo(0.95f);
}
return hits;
}
void onTouchEnded(Touch *touch, Event *event) {
if (_enabled) {
auto hits = touchHits(touch);
if (hits && _onTriggered) {
_onTriggered(this);
}
}
scaleButtonTo(1);
}
void onTouchCancelled(Touch *touch, Event *event) { scaleButtonTo(1); }
void scaleButtonTo(float scale) {
auto action = ScaleTo::create(0.05f, scale);
action->setTag(10000);
stopActionByTag(10000);
runAction(action);
}
std::function<void(TextButton *)> _onTriggered;
bool _enabled;
};
}
EventDispatcherTests::EventDispatcherTests()
{
ADD_TEST_CASE(TouchableSpriteTest);
@ -544,7 +458,6 @@ void LabelKeyboardEventTest::onEnter()
Vec2 origin = Director::getInstance()->getVisibleOrigin();
Size size = Director::getInstance()->getVisibleSize();
#ifdef CC_PLATFORM_PC
auto statusLabel = Label::createWithSystemFont("No keyboard event received!", "", 20);
statusLabel->setPosition(origin + Vec2(size.width / 2, size.height / 2));
addChild(statusLabel);
@ -555,39 +468,6 @@ void LabelKeyboardEventTest::onEnter()
sprintf(buf, "Key %d was pressed!", (int)keyCode);
auto label = static_cast<Label*>(event->getCurrentTarget());
label->setString(buf);
switch (keyCode)
{
case EventKeyboard::KeyCode::KEY_1:
Director::getInstance()->setStatsAnchor(AnchorPreset::BOTTOM_LEFT);
break;
case EventKeyboard::KeyCode::KEY_4:
Director::getInstance()->setStatsAnchor(AnchorPreset::CENTER_LEFT);
break;
case EventKeyboard::KeyCode::KEY_7:
Director::getInstance()->setStatsAnchor(AnchorPreset::TOP_LEFT);
break;
case EventKeyboard::KeyCode::KEY_8:
Director::getInstance()->setStatsAnchor(AnchorPreset::TOP_CENTER);
break;
case EventKeyboard::KeyCode::KEY_9:
Director::getInstance()->setStatsAnchor(AnchorPreset::TOP_RIGHT);
break;
case EventKeyboard::KeyCode::KEY_6:
Director::getInstance()->setStatsAnchor(AnchorPreset::CENTER_RIGHT);
break;
case EventKeyboard::KeyCode::KEY_3:
Director::getInstance()->setStatsAnchor(AnchorPreset::BOTTOM_RIGHT);
break;
case EventKeyboard::KeyCode::KEY_2:
Director::getInstance()->setStatsAnchor(AnchorPreset::BOTTOM_CENTER);
break;
case EventKeyboard::KeyCode::KEY_5:
Director::getInstance()->setStatsAnchor(AnchorPreset::CENTER);
break;
default:
break;
}
};
listener->onKeyReleased = [](EventKeyboard::KeyCode keyCode, Event* event) {
@ -598,31 +478,6 @@ void LabelKeyboardEventTest::onEnter()
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, statusLabel);
#else
auto& layerSize = this->getContentSize();
static AnchorPreset anchor = AnchorPreset::BOTTOM_LEFT;
anchor = AnchorPreset::BOTTOM_LEFT;
auto playPrev = TextButton::create("Show Fps Prev Pos", [=](TextButton* button) {
if (anchor > AnchorPreset::BOTTOM_LEFT)
{
anchor = static_cast<AnchorPreset>((int)anchor - 1);
Director::getInstance()->setStatsAnchor(anchor);
}
});
playPrev->setPosition(layerSize.width * 0.35f, layerSize.height * 0.5f);
addChild(playPrev);
auto playNext = TextButton::create("Show Fps Next Pos", [=](TextButton* button) {
if (anchor < AnchorPreset::TOP_RIGHT)
{
anchor = static_cast<AnchorPreset>((int)anchor + 1);
Director::getInstance()->setStatsAnchor(anchor);
}
});
playNext->setPosition(layerSize.width * 0.65f, layerSize.height * 0.5f);
addChild(playNext);
Director::getInstance()->setStatsAnchor(AnchorPreset::BOTTOM_LEFT);
#endif
}
std::string LabelKeyboardEventTest::title() const
@ -632,11 +487,7 @@ std::string LabelKeyboardEventTest::title() const
std::string LabelKeyboardEventTest::subtitle() const
{
#ifdef CC_PLATFORM_PC
return "Press keys 1 through 9 to change the stats anchor on the screen.";
#else
return "Change the stats anchor [1-9]";
#endif
return "Please click keyboard\n(Only available on Desktop, Android\nand Windows Universal Apps)";
}
// SpriteAccelerationEventTest

View File

@ -50,7 +50,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
}
// turn on display FPS
director->setStatsDisplay(true);
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0f / 60);

View File

@ -80,7 +80,7 @@ bool AppDelegate::applicationDidFinishLaunching()
}
// turn on display FPS
director->setStatsDisplay(true);
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0f / 60);

View File

@ -34,7 +34,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
director->getOpenGLView()->setDesignResolutionSize(960, 640, ResolutionPolicy::SHOW_ALL);
// turn on display FPS
director->setStatsDisplay(true);
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0 / 60);