From 35d3df7075be5c3546b00138e2fe1130aca55caf Mon Sep 17 00:00:00 2001 From: DelinWorks Date: Sun, 3 Jul 2022 22:50:19 +0300 Subject: [PATCH] Fix mobile compilation. Treat `CC_ENABLE_CACHE_TEXTURE_DATA` portion of code accordingly. --- core/2d/CCParticleSystem.h | 22 +++ core/3d/CCBundle3D.cpp | 52 +++--- core/3d/CCBundle3D.h | 3 +- core/3d/CCBundle3DData.h | 103 +++++++++++- core/3d/CCMesh.cpp | 18 ++- core/3d/CCMesh.h | 9 +- core/3d/CCMeshVertexIndexData.cpp | 21 +-- core/3d/CCMeshVertexIndexData.h | 10 +- core/3d/CCSprite3DMaterial.cpp | 32 +++- core/3d/CCSprite3DMaterial.h | 8 + core/base/CCDirector.cpp | 91 +---------- core/base/CCDirector.h | 20 ++- core/base/CMakeLists.txt | 1 - core/base/ccEnums.h | 140 ---------------- core/base/ccTypes.h | 48 +++++- core/math/CMakeLists.txt | 1 - core/math/RngSeed.hpp | 3 - core/renderer/CCCustomCommand.h | 11 +- core/renderer/backend/ProgramCache.cpp | 2 + core/renderer/backend/Types.h | 6 +- core/renderer/ccShaders.cpp | 3 + core/renderer/ccShaders.h | 4 + core/renderer/shaders/quad.frag | 58 +++++++ core/renderer/shaders/quad.vert | 44 +++++ .../SimpleSnake/Classes/SimpleSnakeScene.cpp | 35 +--- .../lua-bindings/auto/lua_cocos2dx_auto.cpp | 62 ------- .../lua-bindings/auto/lua_cocos2dx_auto.hpp | 1 - .../NewEventDispatcherTest.cpp | 151 +----------------- 28 files changed, 424 insertions(+), 535 deletions(-) delete mode 100644 core/base/ccEnums.h create mode 100644 core/renderer/shaders/quad.frag create mode 100644 core/renderer/shaders/quad.vert diff --git a/core/2d/CCParticleSystem.h b/core/2d/CCParticleSystem.h index e5ff7862d3..cc5ea53617 100644 --- a/core/2d/CCParticleSystem.h +++ b/core/2d/CCParticleSystem.h @@ -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 diff --git a/core/3d/CCBundle3D.cpp b/core/3d/CCBundle3D.cpp index 7133e05b99..2c59fb9d1a 100644 --- a/core/3d/CCBundle3D.cpp +++ b/core/3d/CCBundle3D.cpp @@ -298,14 +298,14 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, } // split into submesh according to material - std::map> subMeshMap; + std::map subMeshMap; for (size_t k = 0, size = mesh.material_ids.size(); k < size; ++k) { int id = mesh.material_ids[k]; size_t idx = k * 3; - subMeshMap[id].push_back(mesh.indices[idx]); - subMeshMap[id].push_back(mesh.indices[idx + 1]); - subMeshMap[id].push_back(mesh.indices[idx + 2]); + subMeshMap[id].push_back(mesh.indices[idx], std::true_type{}); + subMeshMap[id].push_back(mesh.indices[idx + 1], std::true_type{}); + subMeshMap[id].push_back(mesh.indices[idx + 2], std::true_type{}); } auto node = new NodeData(); @@ -447,7 +447,7 @@ bool Bundle3D::loadMeshDatasBinary(MeshDatas& meshdatas) for (unsigned int k = 0; k < meshPartCount; ++k) { - std::vector indexArray; + IndexArray indexArray{CustomCommand::IndexFormat::U_SHORT}; // TODO: _version == 1.3 use U_INT? std::string meshPartid = _binaryReader.readString(); meshData->subMeshIds.push_back(meshPartid); unsigned int nIndexCount; @@ -457,7 +457,7 @@ 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; @@ -599,9 +599,9 @@ bool Bundle3D::loadMeshDatasBinary_0_1(MeshDatas& meshdatas) return false; } - std::vector 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); @@ -720,9 +720,9 @@ bool Bundle3D::loadMeshDatasBinary_0_2(MeshDatas& meshdatas) return false; } - std::vector 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); @@ -777,14 +777,14 @@ 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 indexArray; + IndexArray indexArray; const rapidjson::Value& mesh_part = mesh_part_array[i]; meshData->subMeshIds.push_back(mesh_part[ID].GetString()); // index_number const rapidjson::Value& indices_val_array = mesh_part[INDICES]; for (rapidjson::SizeType j = 0, indices_val_array_size = indices_val_array.Size(); 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->numIndex = (int)meshData->subMeshIndices.size(); @@ -810,8 +810,8 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas) } else { - meshData->subMeshAABB.push_back( - calculateAABB(meshData->vertex, meshData->getPerVertexSize(), indexArray)); + meshData->subMeshAABB.push_back(calculateAABB(meshData->vertex, meshData->getPerVertexSize(), + indexArray)); } } 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(); // indices - std::vector 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(i) = (unsigned short)indices_val_array[i].GetUint(); 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); return true; } @@ -1239,12 +1240,12 @@ bool Bundle3D::loadMeshDataJson_0_2(MeshDatas& meshdatas) unsigned int indexnum = mesh_submesh_val[INDEXNUM].GetUint(); // indices - std::vector 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(j) = (unsigned short)indices_val_array[j].GetUint(); meshdata->subMeshIndices.push_back(indices); meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), indices)); @@ -2324,15 +2325,16 @@ Bundle3D::~Bundle3D() cocos2d::AABB Bundle3D::calculateAABB(const std::vector& vertex, int stride, - const std::vector& 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; } diff --git a/core/3d/CCBundle3D.h b/core/3d/CCBundle3D.h index 23f7a34589..a2f1fa3cb1 100644 --- a/core/3d/CCBundle3D.h +++ b/core/3d/CCBundle3D.h @@ -113,7 +113,8 @@ public: const char* mtl_basepath = nullptr); // calculate aabb - static AABB calculateAABB(const std::vector& vertex, int stride, const std::vector& index); + static AABB calculateAABB(const std::vector& vertex, + int stride, const IndexArray& indices); Bundle3D(); virtual ~Bundle3D(); diff --git a/core/3d/CCBundle3DData.h b/core/3d/CCBundle3DData.h index e877814287..c411dd9f96 100644 --- a/core/3d/CCBundle3DData.h +++ b/core/3d/CCBundle3DData.h @@ -39,8 +39,106 @@ #include "3d/CC3DProgramInfo.h" +#include "yasio/detail/byte_buffer.hpp" + NS_CC_BEGIN +class IndexArray +{ +public: + IndexArray() : _format(backend::IndexFormat::U_SHORT) {} + IndexArray(backend::IndexFormat format) : _format(format) {} + IndexArray(std::initializer_list rhs) : _format(backend::IndexFormat::U_SHORT), _buffer(rhs) {} + + IndexArray(std::initializer_list 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 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 ilist, std::true_type) + { + assert(_format == backend::IndexFormat::U_INT); + _buffer.insert(where, (uint8_t*)ilist.begin(), (uint8_t*)ilist.end()); + } + + //template + //void insert(uint8_t* where, _Iter first, const _Iter last) + //{ + // _buffer.insert(where, first, last); + //} + + template + _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 + 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(*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 * @js NA * @lua NA @@ -128,13 +226,14 @@ struct NodeDatas } }; + /**mesh data * @js NA * @lua NA */ struct MeshData { - typedef std::vector IndexArray; + using IndexArray = ::cocos2d::IndexArray; std::vector vertex; int vertexSizeInFloat; std::vector subMeshIndices; @@ -147,7 +246,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 { diff --git a/core/3d/CCMesh.cpp b/core/3d/CCMesh.cpp index e09d260f6b..28ea51deb6 100644 --- a/core/3d/CCMesh.cpp +++ b/core/3d/CCMesh.cpp @@ -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& 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 diff --git a/core/3d/CCMesh.h b/core/3d/CCMesh.h index 0ecac8a450..8c06727fa2 100644 --- a/core/3d/CCMesh.h +++ b/core/3d/CCMesh.h @@ -64,7 +64,7 @@ class CC_DLL Mesh : public Ref friend class Sprite3D; public: - typedef std::vector IndexArray; + /**create mesh from positions, normals, and so on, single SubMesh*/ static Mesh* create(const std::vector& positions, const std::vector& 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; diff --git a/core/3d/CCMeshVertexIndexData.cpp b/core/3d/CCMeshVertexIndexData.cpp index 497357a57c..f32382bbc2 100644 --- a/core/3d/CCMeshVertexIndexData.cpp +++ b/core/3d/CCMeshVertexIndexData.cpp @@ -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.size()); }); Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundListener, 1); #endif @@ -108,7 +108,7 @@ void MeshVertexData::setVertexData(const std::vector& 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.size()/* * 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.size() /* * 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); diff --git a/core/3d/CCMeshVertexIndexData.h b/core/3d/CCMeshVertexIndexData.h index 889eded961..419db962f4 100644 --- a/core/3d/CCMeshVertexIndexData.h +++ b/core/3d/CCMeshVertexIndexData.h @@ -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 _indexs; // index data - std::vector _attribs; // vertex attributes + Vector _indices; // index data + std::vector _attribs; // vertex attributes int _vertexCount = 0; // vertex count std::vector _vertexData; diff --git a/core/3d/CCSprite3DMaterial.cpp b/core/3d/CCSprite3DMaterial.cpp index 068cdcbb17..d10334a68b 100644 --- a/core/3d/CCSprite3DMaterial.cpp +++ b/core/3d/CCSprite3DMaterial.cpp @@ -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; } diff --git a/core/3d/CCSprite3DMaterial.h b/core/3d/CCSprite3DMaterial.h index 8d6473b486..dacaf2650a 100644 --- a/core/3d/CCSprite3DMaterial.h +++ b/core/3d/CCSprite3DMaterial.h @@ -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; }; /** diff --git a/core/base/CCDirector.cpp b/core/base/CCDirector.cpp index 00a50eadd8..9b92b038e6 100644 --- a/core/base/CCDirector.cpp +++ b/core/base/CCDirector.cpp @@ -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 diff --git a/core/base/CCDirector.h b/core/base/CCDirector.h index 8241c072ea..3c4242a37c 100644 --- a/core/base/CCDirector.h +++ b/core/base/CCDirector.h @@ -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. @@ -151,11 +166,6 @@ public: /** 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 diff --git a/core/base/CMakeLists.txt b/core/base/CMakeLists.txt index 3fea5e82ef..bf2f01a768 100644 --- a/core/base/CMakeLists.txt +++ b/core/base/CMakeLists.txt @@ -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 diff --git a/core/base/ccEnums.h b/core/base/ccEnums.h deleted file mode 100644 index e29b417d2f..0000000000 --- a/core/base/ccEnums.h +++ /dev/null @@ -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 diff --git a/core/base/ccTypes.h b/core/base/ccTypes.h index 90d22917f9..d654eccd2e 100644 --- a/core/base/ccTypes.h +++ b/core/base/ccTypes.h @@ -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; diff --git a/core/math/CMakeLists.txt b/core/math/CMakeLists.txt index cd454de6be..5fa4cb7540 100644 --- a/core/math/CMakeLists.txt +++ b/core/math/CMakeLists.txt @@ -12,7 +12,6 @@ set(COCOS_MATH_HEADER math/MathUtil.h math/CCMath.h math/Rect.h - math/RngSeed.hpp ) set(COCOS_MATH_SRC diff --git a/core/math/RngSeed.hpp b/core/math/RngSeed.hpp index 70807d798a..d983bf1bfc 100644 --- a/core/math/RngSeed.hpp +++ b/core/math/RngSeed.hpp @@ -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 diff --git a/core/renderer/CCCustomCommand.h b/core/renderer/CCCustomCommand.h index d7326bea5c..9eba70dfe6 100644 --- a/core/renderer/CCCustomCommand.h +++ b/core/renderer/CCCustomCommand.h @@ -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 */ diff --git a/core/renderer/backend/ProgramCache.cpp b/core/renderer/backend/ProgramCache.cpp index ba5b8cdfc3..109bb3e3d6 100644 --- a/core/renderer/backend/ProgramCache.cpp +++ b/core/renderer/backend/ProgramCache.cpp @@ -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); diff --git a/core/renderer/backend/Types.h b/core/renderer/backend/Types.h index c54c2637d7..a4380e2cc4 100644 --- a/core/renderer/backend/Types.h +++ b/core/renderer/backend/Types.h @@ -160,7 +160,8 @@ enum class TextureUsage : uint32_t enum class IndexFormat : uint32_t { U_SHORT, - U_INT + U_INT, + UNSPEC = 0xff, }; enum class VertexStepMode : uint32_t @@ -431,6 +432,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, diff --git a/core/renderer/ccShaders.cpp b/core/renderer/ccShaders.cpp index 0b5cdfb106..1e0914d42d 100644 --- a/core/renderer/ccShaders.cpp +++ b/core/renderer/ccShaders.cpp @@ -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 diff --git a/core/renderer/ccShaders.h b/core/renderer/ccShaders.h index 16c00c3800..6168d29b21 100644 --- a/core/renderer/ccShaders.h +++ b/core/renderer/ccShaders.h @@ -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 diff --git a/core/renderer/shaders/quad.frag b/core/renderer/shaders/quad.frag new file mode 100644 index 0000000000..9a9cf0872d --- /dev/null +++ b/core/renderer/shaders/quad.frag @@ -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; +} +)"; diff --git a/core/renderer/shaders/quad.vert b/core/renderer/shaders/quad.vert new file mode 100644 index 0000000000..02d3aaaf9f --- /dev/null +++ b/core/renderer/shaders/quad.vert @@ -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; +} + +)"; diff --git a/examples/SimpleSnake/Classes/SimpleSnakeScene.cpp b/examples/SimpleSnake/Classes/SimpleSnakeScene.cpp index 101213b6c1..22ecfe8929 100644 --- a/examples/SimpleSnake/Classes/SimpleSnakeScene.cpp +++ b/examples/SimpleSnake/Classes/SimpleSnakeScene.cpp @@ -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; } diff --git a/extensions/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp b/extensions/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index a17906dba7..ec8453914c 100644 --- a/extensions/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/extensions/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -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; @@ -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,"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); diff --git a/extensions/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp b/extensions/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp index 5bc3529855..db4b779a9a 100644 --- a/extensions/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/extensions/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -2406,7 +2406,6 @@ int register_all_cocos2dx(lua_State* tolua_S); - #endif // __cocos2dx_h__ diff --git a/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp b/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp index f27e6fe0cd..71ce07f4a2 100644 --- a/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp +++ b/tests/cpp-tests/Classes/NewEventDispatcherTest/NewEventDispatcherTest.cpp @@ -35,92 +35,6 @@ USING_NS_CC; -namespace { - - class TextButton : public Label { - public: - static TextButton * - create(std::string_view text, const std::function &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 _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(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((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((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