Fix mobile compilation.

Treat `CC_ENABLE_CACHE_TEXTURE_DATA` portion of code accordingly.
This commit is contained in:
DelinWorks 2022-07-03 22:50:19 +03:00
parent 3585f37d85
commit 35d3df7075
28 changed files with 424 additions and 535 deletions

View File

@ -46,6 +46,28 @@ struct particle_point
float y; 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. * Particle emission shapes.
* Current supported shapes are Point, Rectangle, RectangularTorus, Circle, Torus, Cone, Cone Torus, Texture alpha * Current supported shapes are Point, Rectangle, RectangularTorus, Circle, Torus, Cone, Cone Torus, Texture alpha

View File

@ -298,14 +298,14 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas,
} }
// split into submesh according to material // 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) for (size_t k = 0, size = mesh.material_ids.size(); k < size; ++k)
{ {
int id = mesh.material_ids[k]; int id = mesh.material_ids[k];
size_t idx = k * 3; size_t idx = k * 3;
subMeshMap[id].push_back(mesh.indices[idx]); subMeshMap[id].push_back(mesh.indices[idx], std::true_type{});
subMeshMap[id].push_back(mesh.indices[idx + 1]); subMeshMap[id].push_back(mesh.indices[idx + 1], std::true_type{});
subMeshMap[id].push_back(mesh.indices[idx + 2]); subMeshMap[id].push_back(mesh.indices[idx + 2], std::true_type{});
} }
auto node = new NodeData(); auto node = new NodeData();
@ -447,7 +447,7 @@ bool Bundle3D::loadMeshDatasBinary(MeshDatas& meshdatas)
for (unsigned int k = 0; k < meshPartCount; ++k) for (unsigned int k = 0; k < meshPartCount; ++k)
{ {
std::vector<unsigned short> indexArray; IndexArray indexArray{CustomCommand::IndexFormat::U_SHORT}; // TODO: _version == 1.3 use U_INT?
std::string meshPartid = _binaryReader.readString(); std::string meshPartid = _binaryReader.readString();
meshData->subMeshIds.push_back(meshPartid); meshData->subMeshIds.push_back(meshPartid);
unsigned int nIndexCount; unsigned int nIndexCount;
@ -457,7 +457,7 @@ bool Bundle3D::loadMeshDatasBinary(MeshDatas& meshdatas)
goto FAILED; goto FAILED;
} }
indexArray.resize(nIndexCount); 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()); CCLOG("warning: Failed to read meshdata: indices '%s'.", _path.c_str());
goto FAILED; goto FAILED;
@ -599,9 +599,9 @@ bool Bundle3D::loadMeshDatasBinary_0_1(MeshDatas& meshdatas)
return false; return false;
} }
std::vector<unsigned short> indices; IndexArray indices;
indices.resize(nIndexCount); 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()); CCLOG("warning: Failed to read meshdata: indices '%s'.", _path.c_str());
CC_SAFE_DELETE(meshdata); CC_SAFE_DELETE(meshdata);
@ -720,9 +720,9 @@ bool Bundle3D::loadMeshDatasBinary_0_2(MeshDatas& meshdatas)
return false; return false;
} }
std::vector<unsigned short> indices; IndexArray indices{CustomCommand::IndexFormat::U_SHORT}; /* TODO: _version == 1.3 use U_INT?*/
indices.resize(nIndexCount); 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()); CCLOG("warning: Failed to read meshdata: indices '%s'.", _path.c_str());
CC_SAFE_DELETE(meshdata); CC_SAFE_DELETE(meshdata);
@ -777,14 +777,14 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas)
const rapidjson::Value& mesh_part_array = mesh_data[PARTS]; 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) 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]; const rapidjson::Value& mesh_part = mesh_part_array[i];
meshData->subMeshIds.push_back(mesh_part[ID].GetString()); meshData->subMeshIds.push_back(mesh_part[ID].GetString());
// index_number // index_number
const rapidjson::Value& indices_val_array = mesh_part[INDICES]; const rapidjson::Value& indices_val_array = mesh_part[INDICES];
for (rapidjson::SizeType j = 0, indices_val_array_size = indices_val_array.Size(); for (rapidjson::SizeType j = 0, indices_val_array_size = indices_val_array.Size();
j < indices_val_array_size; ++j) j < indices_val_array_size; ++j)
indexArray.push_back((unsigned short)indices_val_array[j].GetUint()); indexArray.push_back((unsigned int)indices_val_array[j].GetUint());
meshData->subMeshIndices.push_back(indexArray); meshData->subMeshIndices.push_back(indexArray);
meshData->numIndex = (int)meshData->subMeshIndices.size(); meshData->numIndex = (int)meshData->subMeshIndices.size();
@ -810,8 +810,8 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas)
} }
else else
{ {
meshData->subMeshAABB.push_back( meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(),
calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray)); indexArray));
} }
} }
meshdatas.meshDatas.push_back(meshData); meshdatas.meshDatas.push_back(meshData);
@ -1185,15 +1185,16 @@ bool Bundle3D::loadMeshDataJson_0_1(MeshDatas& meshdatas)
unsigned int indexnum = mesh_data_body_array_0[INDEXNUM].GetUint(); unsigned int indexnum = mesh_data_body_array_0[INDEXNUM].GetUint();
// indices // indices
std::vector<unsigned short> indices; IndexArray indices;
indices.resize(indexnum); indices.resize(indexnum);
const rapidjson::Value& indices_val_array = mesh_data_body_array_0[INDICES]; const rapidjson::Value& indices_val_array = mesh_data_body_array_0[INDICES];
for (rapidjson::SizeType i = 0; i < indices_val_array.Size(); ++i) 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->subMeshIndices.push_back(indices);
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices)); meshdata->subMeshAABB.push_back(
calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices));
meshdatas.meshDatas.push_back(meshdata); meshdatas.meshDatas.push_back(meshdata);
return true; return true;
} }
@ -1239,12 +1240,12 @@ bool Bundle3D::loadMeshDataJson_0_2(MeshDatas& meshdatas)
unsigned int indexnum = mesh_submesh_val[INDEXNUM].GetUint(); unsigned int indexnum = mesh_submesh_val[INDEXNUM].GetUint();
// indices // indices
std::vector<unsigned short> indices; IndexArray indices;
indices.resize(indexnum); indices.resize(indexnum);
const rapidjson::Value& indices_val_array = mesh_submesh_val[INDICES]; const rapidjson::Value& indices_val_array = mesh_submesh_val[INDICES];
for (rapidjson::SizeType j = 0; j < indices_val_array.Size(); ++j) 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->subMeshIndices.push_back(indices);
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices)); meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices));
@ -2324,15 +2325,16 @@ Bundle3D::~Bundle3D()
cocos2d::AABB Bundle3D::calculateAABB(const std::vector<float>& vertex, cocos2d::AABB Bundle3D::calculateAABB(const std::vector<float>& vertex,
int stride, int stride,
const std::vector<unsigned short>& index) const IndexArray& indices)
{ {
AABB aabb; AABB aabb;
stride /= 4; stride /= 4;
for (const auto& it : index)
{ indices.for_each ([&](uint32_t i) {
Vec3 point(vertex[it * stride], vertex[it * stride + 1], vertex[it * stride + 2]); Vec3 point(vertex[i * stride], vertex[i * stride + 1], vertex[i * stride + 2]);
aabb.updateMinMax(&point, 1); aabb.updateMinMax(&point, 1);
} });
return aabb; return aabb;
} }

View File

@ -113,7 +113,8 @@ public:
const char* mtl_basepath = nullptr); const char* mtl_basepath = nullptr);
// calculate aabb // 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(); Bundle3D();
virtual ~Bundle3D(); virtual ~Bundle3D();

View File

@ -39,8 +39,106 @@
#include "3d/CC3DProgramInfo.h" #include "3d/CC3DProgramInfo.h"
#include "yasio/detail/byte_buffer.hpp"
NS_CC_BEGIN NS_CC_BEGIN
class IndexArray
{
public:
IndexArray() : _format(backend::IndexFormat::U_SHORT) {}
IndexArray(backend::IndexFormat format) : _format(format) {}
IndexArray(std::initializer_list<unsigned short> rhs) : _format(backend::IndexFormat::U_SHORT), _buffer(rhs) {}
IndexArray(std::initializer_list<unsigned int> rhs, std::true_type /*U_INT*/)
: _format(backend::IndexFormat::U_INT), _buffer(rhs)
{}
void clear(backend::IndexFormat format = backend::IndexFormat::UNSPEC)
{
_buffer.clear();
if (format != backend::IndexFormat::UNSPEC)
_format = format;
}
void push_back(u_short val)
{
assert(_format == backend::IndexFormat::U_SHORT);
_buffer.append_n((uint8_t*)&val, sizeof(val));
}
void push_back(unsigned int val, std::true_type /*U_INT*/)
{
assert(_format == backend::IndexFormat::U_INT);
_buffer.append_n((uint8_t*)&val, sizeof(val));
}
void insert(uint8_t* where, std::initializer_list<unsigned short> ilist)
{
assert(_format == backend::IndexFormat::U_SHORT);
_buffer.insert(where, (uint8_t*)ilist.begin(), (uint8_t*)ilist.end());
}
void insert(uint8_t* where, std::initializer_list<unsigned int> ilist, std::true_type)
{
assert(_format == backend::IndexFormat::U_INT);
_buffer.insert(where, (uint8_t*)ilist.begin(), (uint8_t*)ilist.end());
}
//template <typename _Iter>
//void insert(uint8_t* where, _Iter first, const _Iter last)
//{
// _buffer.insert(where, first, last);
//}
template<typename _Ty>
_Ty& at(size_t idx)
{
assert((sizeof(_Ty) == sizeof(uint16_t) && _format == backend::IndexFormat::U_SHORT) ||
(sizeof(_Ty) == sizeof(uint32_t) && _format == backend::IndexFormat::U_INT));
return (_Ty&)_buffer[idx * sizeof(_Ty)];
}
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(); }
size_t size() const { return _buffer.size(); }
bool empty() const { return _buffer.size() == 0; }
void resize(size_t size) { _buffer.resize(size * sizeof(uint16_t)); }
void resize(size_t size, std::true_type) { _buffer.resize(size * sizeof(uint32_t)); }
backend::IndexFormat format() const { return _format; }
template<typename _Fty>
void for_each(_Fty cb) const
{
if (_format == backend::IndexFormat::U_SHORT)
{
for (auto it = (uint16_t*)_buffer.begin(); it != (uint16_t*)_buffer.end(); ++it)
{
cb(static_cast<uint32_t>(*it));
}
}
else if (_format == backend::IndexFormat::U_INT)
{
for (auto it = (uint32_t*)_buffer.begin(); it != (uint32_t*)_buffer.end(); ++it)
{
cb(*it);
}
}
}
protected:
backend::IndexFormat _format;
yasio::byte_buffer _buffer;
};
/**mesh vertex attribute /**mesh vertex attribute
* @js NA * @js NA
* @lua NA * @lua NA
@ -128,13 +226,14 @@ struct NodeDatas
} }
}; };
/**mesh data /**mesh data
* @js NA * @js NA
* @lua NA * @lua NA
*/ */
struct MeshData struct MeshData
{ {
typedef std::vector<unsigned short> IndexArray; using IndexArray = ::cocos2d::IndexArray;
std::vector<float> vertex; std::vector<float> vertex;
int vertexSizeInFloat; int vertexSizeInFloat;
std::vector<IndexArray> subMeshIndices; std::vector<IndexArray> subMeshIndices;
@ -147,7 +246,7 @@ struct MeshData
public: public:
/** /**
* Get per vertex size * 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 int getPerVertexSize() const
{ {

View File

@ -113,6 +113,7 @@ Mesh::Mesh()
, _visible(true) , _visible(true)
, _isTransparent(false) , _isTransparent(false)
, _force2DQueue(false) , _force2DQueue(false)
, meshIndexFormat(CustomCommand::IndexFormat::U_SHORT)
, _meshIndexData(nullptr) , _meshIndexData(nullptr)
, _blend(BlendFunc::ALPHA_NON_PREMULTIPLIED) , _blend(BlendFunc::ALPHA_NON_PREMULTIPLIED)
, _blendDirty(true) , _blendDirty(true)
@ -222,10 +223,13 @@ Mesh* Mesh::create(const std::vector<float>& vertices,
meshdata.vertex = vertices; meshdata.vertex = vertices;
meshdata.subMeshIndices.push_back(indices); meshdata.subMeshIndices.push_back(indices);
meshdata.subMeshIds.push_back(""); meshdata.subMeshIds.push_back("");
auto meshvertexdata = MeshVertexData::create(meshdata); auto meshvertexdata = MeshVertexData::create(meshdata, indices.format());
auto indexData = meshvertexdata->getMeshIndexDataByIndex(0); 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) 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 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 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 backend::Buffer* Mesh::getIndexBuffer() const

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1303,92 +1303,11 @@ void Director::createStatsLabel()
_drawnVerticesLabel->setIgnoreContentScaleFactor(true); _drawnVerticesLabel->setIgnoreContentScaleFactor(true);
_drawnVerticesLabel->setScale(scaleFactor); _drawnVerticesLabel->setScale(scaleFactor);
setStatsAnchor(); auto safeOrigin = getSafeAreaRect().origin;
} const int height_spacing = (int)(22 / CC_CONTENT_SCALE_FACTOR());
_drawnVerticesLabel->setPosition(Vec2(0, height_spacing * 2.0f) + safeOrigin);
void Director::setStatsAnchor(AnchorPreset anchor) _drawnBatchesLabel->setPosition(Vec2(0, height_spacing * 1.0f) + safeOrigin);
{ _FPSLabel->setPosition(Vec2(0, height_spacing * 0.0f) + safeOrigin);
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);
}
} }
#endif // #if !CC_STRIP_FPS #endif // #if !CC_STRIP_FPS

View File

@ -62,6 +62,21 @@ class Camera;
class Console; 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 @brief Class that creates and handles the main Window and manages how
and when to execute the Scenes. and when to execute the Scenes.
@ -151,11 +166,6 @@ public:
/** Gets the seconds per frame. */ /** Gets the seconds per frame. */
float getSecondsPerFrame() { return _secondsPerFrame; } 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. * Get the GLView.
* @lua NA * @lua NA

View File

@ -38,7 +38,6 @@ set(COCOS_BASE_HEADER
base/ccConstants.h base/ccConstants.h
base/CCEvent.h base/CCEvent.h
base/ccTypes.h base/ccTypes.h
base/ccEnums.h
base/CCAsyncTaskPool.h base/CCAsyncTaskPool.h
base/ccRandom.h base/ccRandom.h
base/CCRef.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 "math/CCMath.h"
#include "base/CCRef.h" #include "base/CCRef.h"
#include "renderer/backend/Types.h" #include "renderer/backend/Types.h"
#include "ccEnums.h"
/** /**
* @addtogroup base * @addtogroup base
@ -623,6 +622,24 @@ struct CC_DLL FontDefinition
int _overflow = 0; 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 /** @struct Acceleration
* The device accelerometer reports values for each axis in units of g-force. * 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 std::string CC_DLL STD_STRING_EMPTY;
extern const ssize_t CC_DLL CC_INVALID_INDEX; 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 struct CC_DLL Viewport
{ {
int x = 0; int x = 0;
@ -655,6 +681,26 @@ struct CC_DLL ScissorRect
float height = 0; 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 TextureUsage = backend::TextureUsage;
using PixelFormat = backend::PixelFormat; using PixelFormat = backend::PixelFormat;

View File

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

View File

@ -1,10 +1,7 @@
#pragma warning(suppress : 4244)
#ifndef RNGSEED_H_ #ifndef RNGSEED_H_
#define RNGSEED_H_ #define RNGSEED_H_
/** A more effective seeded random number generator struct, made by kiss rng. /** 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 * @since adxe-1.0.0b8
*/ */
struct RngSeed struct RngSeed

View File

@ -53,13 +53,14 @@ public:
using PrimitiveType = backend::PrimitiveType; using PrimitiveType = backend::PrimitiveType;
/** /**
Buffer usage of vertex/index buffer. If the contents is not updated every frame, Buffer usage of vertex/index buffer. If the contents are not updated every frame,
then use STATIC, other use DYNAMIC. 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; using BufferUsage = backend::BufferUsage;
/** /**
The index format determine the size for index data. U_SHORT is enough for most The index format that determines the size of index data. U_SHORT (65535 vertices) is enough for most
cases. cases, But support for U_INT (4294967295 vertices) has been added.
*/ */
using IndexFormat = backend::IndexFormat; using IndexFormat = backend::IndexFormat;
@ -208,6 +209,8 @@ TODO: should remove it.
inline IndexFormat getIndexFormat() const { return _indexFormat; } inline IndexFormat getIndexFormat() const { return _indexFormat; }
inline void setIndexFormat(IndexFormat format) { _indexFormat = format; }
/** /**
* set a callback which will be invoke before rendering * 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::TERRAIN_3D, CC3D_terrain_vert, CC3D_terrain_frag);
registerProgramFactory(ProgramType::PARTICLE_TEXTURE_3D, CC3D_particle_vert, CC3D_particleTexture_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::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, positionTextureColor_vert, hsv_frag);
registerProgramFactory(ProgramType::HSV_DUAL_SAMPLER, positionTextureColor_vert, dualSampler_hsv_frag); registerProgramFactory(ProgramType::HSV_DUAL_SAMPLER, positionTextureColor_vert, dualSampler_hsv_frag);

View File

@ -160,7 +160,8 @@ enum class TextureUsage : uint32_t
enum class IndexFormat : uint32_t enum class IndexFormat : uint32_t
{ {
U_SHORT, U_SHORT,
U_INT U_INT,
UNSPEC = 0xff,
}; };
enum class VertexStepMode : uint32_t enum class VertexStepMode : uint32_t
@ -431,6 +432,9 @@ struct ProgramType
PARTICLE_TEXTURE_3D, // CC3D_particle_vert, CC3D_particleTexture_frag PARTICLE_TEXTURE_3D, // CC3D_particle_vert, CC3D_particleTexture_frag
PARTICLE_COLOR_3D, // CC3D_particle_vert, CC3D_particleColor_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,
HSV_DUAL_SAMPLER, HSV_DUAL_SAMPLER,
HSV_ETC1 = 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/hsv.frag"
#include "renderer/shaders/dualSampler_hsv.frag" #include "renderer/shaders/dualSampler_hsv.frag"
#include "renderer/shaders/quad.vert"
#include "renderer/shaders/quad.frag"
NS_CC_END 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_frag;
extern CC_DLL const char* CC3D_terrain_vert; 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* hsv_frag;
extern CC_DLL const char* dualSampler_hsv_frag; extern CC_DLL const char* dualSampler_hsv_frag;
NS_CC_END 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

@ -188,49 +188,22 @@ void SimpleSnake::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event)
{ {
switch (keyCode) switch (keyCode)
{ {
case EventKeyboard::KeyCode::KEY_LEFT_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_LEFT_ARROW:
if (dir != 2) if (dir != 2)
dir = 1; dir = 1;
break; break;
case EventKeyboard::KeyCode::KEY_RIGHT_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_ARROW:
if (dir != 1) if (dir != 1)
dir = 2; dir = 2;
break; break;
case EventKeyboard::KeyCode::KEY_UP_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_UP_ARROW:
if (dir != 3) if (dir != 3)
dir = 0; dir = 0;
break; break;
case EventKeyboard::KeyCode::KEY_DOWN_ARROW: case cocos2d::EventKeyboard::KeyCode::KEY_DOWN_ARROW:
if (dir != 0) if (dir != 0)
dir = 3; dir = 3;
break; 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: default:
break; break;
} }

View File

@ -16851,67 +16851,6 @@ int lua_cocos2dx_Director_drawScene(lua_State* tolua_S)
return 0; 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 lua_cocos2dx_Director_restart(lua_State* tolua_S)
{ {
int argc = 0; int argc = 0;
@ -17975,7 +17914,6 @@ int lua_register_cocos2dx_Director(lua_State* tolua_S)
tolua_function(tolua_S,"setNotificationNode",lua_cocos2dx_Director_setNotificationNode); tolua_function(tolua_S,"setNotificationNode",lua_cocos2dx_Director_setNotificationNode);
tolua_function(tolua_S,"setChildrenIndexerEnabled",lua_cocos2dx_Director_setChildrenIndexerEnabled); tolua_function(tolua_S,"setChildrenIndexerEnabled",lua_cocos2dx_Director_setChildrenIndexerEnabled);
tolua_function(tolua_S,"drawScene",lua_cocos2dx_Director_drawScene); 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,"restart",lua_cocos2dx_Director_restart);
tolua_function(tolua_S,"popScene",lua_cocos2dx_Director_popScene); tolua_function(tolua_S,"popScene",lua_cocos2dx_Director_popScene);
tolua_function(tolua_S,"loadIdentityMatrix",lua_cocos2dx_Director_loadIdentityMatrix); tolua_function(tolua_S,"loadIdentityMatrix",lua_cocos2dx_Director_loadIdentityMatrix);

View File

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

View File

@ -35,92 +35,6 @@
USING_NS_CC; 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() EventDispatcherTests::EventDispatcherTests()
{ {
ADD_TEST_CASE(TouchableSpriteTest); ADD_TEST_CASE(TouchableSpriteTest);
@ -544,7 +458,6 @@ void LabelKeyboardEventTest::onEnter()
Vec2 origin = Director::getInstance()->getVisibleOrigin(); Vec2 origin = Director::getInstance()->getVisibleOrigin();
Size size = Director::getInstance()->getVisibleSize(); Size size = Director::getInstance()->getVisibleSize();
#ifdef CC_PLATFORM_PC
auto statusLabel = Label::createWithSystemFont("No keyboard event received!", "", 20); auto statusLabel = Label::createWithSystemFont("No keyboard event received!", "", 20);
statusLabel->setPosition(origin + Vec2(size.width / 2, size.height / 2)); statusLabel->setPosition(origin + Vec2(size.width / 2, size.height / 2));
addChild(statusLabel); addChild(statusLabel);
@ -555,39 +468,6 @@ void LabelKeyboardEventTest::onEnter()
sprintf(buf, "Key %d was pressed!", (int)keyCode); sprintf(buf, "Key %d was pressed!", (int)keyCode);
auto label = static_cast<Label*>(event->getCurrentTarget()); auto label = static_cast<Label*>(event->getCurrentTarget());
label->setString(buf); 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) { listener->onKeyReleased = [](EventKeyboard::KeyCode keyCode, Event* event) {
@ -598,31 +478,6 @@ void LabelKeyboardEventTest::onEnter()
}; };
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, statusLabel); _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 std::string LabelKeyboardEventTest::title() const
@ -632,11 +487,7 @@ std::string LabelKeyboardEventTest::title() const
std::string LabelKeyboardEventTest::subtitle() const std::string LabelKeyboardEventTest::subtitle() const
{ {
#ifdef CC_PLATFORM_PC return "Please click keyboard\n(Only available on Desktop, Android\nand Windows Universal Apps)";
return "Press keys 1 through 9 to change the stats anchor on the screen.";
#else
return "Change the stats anchor [1-9]";
#endif
} }
// SpriteAccelerationEventTest // SpriteAccelerationEventTest