diff --git a/.travis.yml b/.travis.yml index cb120771e4a0..2b86ad5bce74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,6 +53,16 @@ matrix: env: BUILD_TARGET=linux_cocos_new_test language: cpp sudo: required + - os: osx + env: BUILD_TARGET=ios_cocos_new_lua_test + language: cpp + osx_image: xcode11 + sudo: required + - os: osx + env: BUILD_TARGET=ios_cocos_new_cpp_test + language: cpp + osx_image: xcode11 + sudo: required script: - tools/travis-scripts/run-script.sh diff --git a/cocos/2d/CCFastTMXLayer.cpp b/cocos/2d/CCFastTMXLayer.cpp index a11c0cd1ec3e..5a38a1a9dd17 100644 --- a/cocos/2d/CCFastTMXLayer.cpp +++ b/cocos/2d/CCFastTMXLayer.cpp @@ -130,15 +130,8 @@ FastTMXLayer::~FastTMXLayer() void FastTMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flags) { updateTotalQuads(); - - bool isViewProjectionUpdated = true; - auto visitingCamera = Camera::getVisitingCamera(); - auto defaultCamera = Camera::getDefaultCamera(); - if (visitingCamera == defaultCamera) { - isViewProjectionUpdated = visitingCamera->isViewProjectionUpdated(); - } - if( flags != 0 || _dirty || _quadsDirty || isViewProjectionUpdated) + if( flags != 0 || _dirty || _quadsDirty) { Size s = Director::getInstance()->getVisibleSize(); const Vec2 &anchor = getAnchorPoint(); @@ -284,7 +277,7 @@ void FastTMXLayer::updateIndexBuffer() if (!_indexBuffer) { auto device = backend::Device::getInstance(); - _indexBuffer = device->newBuffer(indexBufferSize, backend::BufferType::INDEX, backend::BufferUsage::STATIC); + _indexBuffer = device->newBuffer(indexBufferSize, backend::BufferType::INDEX, backend::BufferUsage::DYNAMIC); } _indexBuffer->updateData(&_indices[0], indexBufferSize); } diff --git a/cocos/editor-support/cocostudio/CCDatas.cpp b/cocos/editor-support/cocostudio/CCDatas.cpp index 6bfb69a1f94f..935a5a332690 100644 --- a/cocos/editor-support/cocostudio/CCDatas.cpp +++ b/cocos/editor-support/cocostudio/CCDatas.cpp @@ -266,7 +266,7 @@ FrameData::FrameData() FrameData::~FrameData() { - CC_SAFE_DELETE(easingParams); + CC_SAFE_DELETE_ARRAY(easingParams); } void FrameData::copy(const BaseData *baseData) @@ -281,7 +281,7 @@ void FrameData::copy(const BaseData *baseData) tweenEasing = frameData->tweenEasing; easingParamNumber = frameData->easingParamNumber; - CC_SAFE_DELETE(easingParams); + CC_SAFE_DELETE_ARRAY(easingParams); if (easingParamNumber != 0) { easingParams = new (std::nothrow) float[easingParamNumber]; diff --git a/cocos/renderer/CCTrianglesCommand.cpp b/cocos/renderer/CCTrianglesCommand.cpp index 1b389da72bd2..c9c0571d16e9 100644 --- a/cocos/renderer/CCTrianglesCommand.cpp +++ b/cocos/renderer/CCTrianglesCommand.cpp @@ -48,16 +48,16 @@ void TrianglesCommand::init(float globalOrder, Texture2D* texture, const BlendFu } _mv = mv; - if (_program != _pipelineDescriptor.programState->getProgram() || + if (_programType != _pipelineDescriptor.programState->getProgram()->getProgramType() || _texture != texture->getBackendTexture() || _blendType != blendType) { - _program = _pipelineDescriptor.programState->getProgram(); + _programType = _pipelineDescriptor.programState->getProgram()->getProgramType(); _texture = texture->getBackendTexture(); _blendType = blendType; //since it would be too expensive to check the uniforms, simplify enable batching for built-in program. - if(_program->getProgramType() == backend::ProgramType::INVALID_PROGRAM) + if(_programType == backend::ProgramType::CUSTOM_PROGRAM) setSkipBatching(true); //TODO: minggo set it in Node? @@ -86,7 +86,7 @@ void TrianglesCommand::generateMaterialID() struct { void* texture; - void* program; + backend::ProgramType programType; backend::BlendFactor src; backend::BlendFactor dst; }hashMe; @@ -99,7 +99,7 @@ void TrianglesCommand::generateMaterialID() hashMe.texture = _texture; hashMe.src = _blendType.src; hashMe.dst = _blendType.dst; - hashMe.program = _program; + hashMe.programType = _programType; _materialID = XXH32((const void*)&hashMe, sizeof(hashMe), 0); } diff --git a/cocos/renderer/CCTrianglesCommand.h b/cocos/renderer/CCTrianglesCommand.h index 337933935728..94acffffc76a 100644 --- a/cocos/renderer/CCTrianglesCommand.h +++ b/cocos/renderer/CCTrianglesCommand.h @@ -116,7 +116,7 @@ class CC_DLL TrianglesCommand : public RenderCommand // Cached value to determine to generate material id or not. BlendFunc _blendType = BlendFunc::DISABLE; - backend::Program* _program = nullptr; + backend::ProgramType _programType = backend::ProgramType::CUSTOM_PROGRAM; backend::TextureBackend* _texture = nullptr; }; diff --git a/cocos/renderer/backend/Program.h b/cocos/renderer/backend/Program.h index 5d58233524d6..b07ccbf6fd84 100644 --- a/cocos/renderer/backend/Program.h +++ b/cocos/renderer/backend/Program.h @@ -120,12 +120,6 @@ class Program : public Ref */ ProgramType getProgramType() const { return _programType; } - /** - * Set engin built-in program type. - * @param type Specifies the program type. - */ - void setProgramType(ProgramType type); - /** * Get uniform buffer size in bytes that can hold all the uniforms. * @param stage Specifies the shader stage. The symbolic constant can be either VERTEX or FRAGMENT. @@ -146,8 +140,14 @@ class Program : public Ref * @return The uniformInfos. */ virtual const std::unordered_map& getAllActiveUniformInfo(ShaderStage stage) const = 0; - + protected: + /** + * Set engin built-in program type. + * @param type Specifies the program type. + */ + void setProgramType(ProgramType type); + /** * @param vs Specifes the vertex shader source. * @param fs Specifes the fragment shader source. @@ -179,12 +179,12 @@ class Program : public Ref */ virtual const std::unordered_map getAllUniformsLocation() const = 0; friend class ProgramState; - friend class ProgramCache; #endif + friend class ProgramCache; std::string _vertexShader; ///< Vertex shader. std::string _fragmentShader; ///< Fragment shader. - ProgramType _programType = ProgramType::INVALID_PROGRAM; ///< built-in program type. + ProgramType _programType = ProgramType::CUSTOM_PROGRAM; ///< built-in program type, initial value is CUSTOM_PROGRAM. }; //end of _backend group diff --git a/cocos/renderer/backend/ShaderCache.cpp b/cocos/renderer/backend/ShaderCache.cpp index f0586e18366a..5664291fe14d 100644 --- a/cocos/renderer/backend/ShaderCache.cpp +++ b/cocos/renderer/backend/ShaderCache.cpp @@ -82,6 +82,7 @@ backend::ShaderModule* ShaderCache::newShaderModule(backend::ShaderStage stage, return iter->second; auto shader = backend::Device::getInstance()->newShaderModule(stage, shaderSource); + shader->setHashValue(key); _cachedShaders.emplace(key, shader); return shader; diff --git a/cocos/renderer/backend/ShaderModule.h b/cocos/renderer/backend/ShaderModule.h index 7c94a80831f9..31c101038b6c 100644 --- a/cocos/renderer/backend/ShaderModule.h +++ b/cocos/renderer/backend/ShaderModule.h @@ -71,12 +71,16 @@ class ShaderModule : public cocos2d::Ref */ ShaderStage getShaderStage() const; + std::size_t getHashValue() const { return _hash; } protected: ShaderModule(ShaderStage stage); virtual ~ShaderModule(); - + void setHashValue(std::size_t hash) { _hash = hash; } + + friend class ShaderCache; ShaderStage _stage = ShaderStage::VERTEX; + std::size_t _hash = 0; }; //end of _backend group diff --git a/cocos/renderer/backend/Types.h b/cocos/renderer/backend/Types.h index e70ac8c956c3..30661128cee5 100644 --- a/cocos/renderer/backend/Types.h +++ b/cocos/renderer/backend/Types.h @@ -326,9 +326,8 @@ enum class TextureCubeFace : uint32_t NEGATIVE_Z = 5 }; -enum class ProgramType : int +enum class ProgramType : size_t { - INVALID_PROGRAM = -1, POSITION_COLOR_LENGTH_TEXTURE, //positionColorLengthTexture_vert, positionColorLengthTexture_frag POSITION_COLOR_TEXTURE_AS_POINTSIZE, //positionColorTextureAsPointsize_vert, positionColor_frag POSITION_COLOR, //positionColor_vert, positionColor_frag @@ -362,6 +361,8 @@ enum class ProgramType : int SKINPOSITION_BUMPEDNORMAL_TEXTURE_3D, //CC3D_skinPositionNormalTexture_vert, CC3D_colorNormalTexture_frag PARTICLE_TEXTURE_3D, //CC3D_particle_vert, CC3D_particleTexture_frag PARTICLE_COLOR_3D, //CC3D_particle_vert, CC3D_particleColor_frag + + CUSTOM_PROGRAM, //user-define program }; ///built-in uniform name diff --git a/cocos/renderer/backend/metal/RenderPipelineMTL.mm b/cocos/renderer/backend/metal/RenderPipelineMTL.mm index 5306de5be01f..cea240935c56 100644 --- a/cocos/renderer/backend/metal/RenderPipelineMTL.mm +++ b/cocos/renderer/backend/metal/RenderPipelineMTL.mm @@ -167,7 +167,8 @@ MTLBlendOperation toMTLBlendOperation(BlendOperation operation) { struct { - void* program; + size_t vertexShaderHash; + size_t fragmentShaderHash; unsigned int vertexLayoutInfo[32]; backend::PixelFormat colorAttachment; backend::PixelFormat depthAttachment; @@ -185,7 +186,9 @@ MTLBlendOperation toMTLBlendOperation(BlendOperation operation) memset(&hashMe, 0, sizeof(hashMe)); const auto& blendDescriptor = pipelineDescirptor.blendDescriptor; getAttachmentFormat(renderPassDescriptor, _colorAttachmentsFormat[0], _depthAttachmentFormat, _stencilAttachmentFormat); - hashMe.program = pipelineDescirptor.programState->getProgram(); + auto program = static_cast(pipelineDescirptor.programState->getProgram()); + hashMe.vertexShaderHash = program->getVertexShader()->getHashValue(); + hashMe.fragmentShaderHash = program->getFragmentShader()->getHashValue(); hashMe.colorAttachment = _colorAttachmentsFormat[0]; hashMe.depthAttachment = _depthAttachmentFormat; hashMe.stencilAttachment =_stencilAttachmentFormat; @@ -215,8 +218,8 @@ MTLBlendOperation toMTLBlendOperation(BlendOperation operation) ((unsigned int)attribute.needToBeNormallized & 0x1); } - NSUInteger hash = XXH32((const void*)&hashMe, sizeof(hashMe), 0); - NSNumber* key = [[NSNumber numberWithUnsignedInteger:hash] autorelease]; + unsigned int hash = XXH32((const void*)&hashMe, sizeof(hashMe), 0); + NSNumber* key = @(hash); id obj = [_mtlRenderPipelineStateCache objectForKey:key]; if (obj != nil) { diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.cpp index f8f2c29006c6..b61a23aeb427 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.cpp @@ -556,56 +556,6 @@ int lua_cocos2dx_backend_Program_getUniformBufferSize(lua_State* tolua_S) return 0; } -int lua_cocos2dx_backend_Program_setProgramType(lua_State* tolua_S) -{ - int argc = 0; - cocos2d::backend::Program* cobj = nullptr; - bool ok = true; - -#if COCOS2D_DEBUG >= 1 - tolua_Error tolua_err; -#endif - - -#if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S,1,"ccb.Program",0,&tolua_err)) goto tolua_lerror; -#endif - - cobj = (cocos2d::backend::Program*)tolua_tousertype(tolua_S,1,0); - -#if COCOS2D_DEBUG >= 1 - if (!cobj) - { - tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_backend_Program_setProgramType'", nullptr); - return 0; - } -#endif - - argc = lua_gettop(tolua_S)-1; - if (argc == 1) - { - cocos2d::backend::ProgramType arg0; - - ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "ccb.Program:setProgramType"); - if(!ok) - { - tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_backend_Program_setProgramType'", nullptr); - return 0; - } - cobj->setProgramType(arg0); - lua_settop(tolua_S, 1); - return 1; - } - luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccb.Program:setProgramType",argc, 1); - return 0; - -#if COCOS2D_DEBUG >= 1 - tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_backend_Program_setProgramType'.",&tolua_err); -#endif - - return 0; -} int lua_cocos2dx_backend_Program_getUniformLocation(lua_State* tolua_S) { int argc = 0; @@ -909,7 +859,6 @@ int lua_register_cocos2dx_backend_Program(lua_State* tolua_S) tolua_function(tolua_S,"getMaxFragmentLocation",lua_cocos2dx_backend_Program_getMaxFragmentLocation); tolua_function(tolua_S,"getFragmentShader",lua_cocos2dx_backend_Program_getFragmentShader); tolua_function(tolua_S,"getUniformBufferSize",lua_cocos2dx_backend_Program_getUniformBufferSize); - tolua_function(tolua_S,"setProgramType",lua_cocos2dx_backend_Program_setProgramType); tolua_function(tolua_S,"getUniformLocation",lua_cocos2dx_backend_Program_getUniformLocation); tolua_function(tolua_S,"getProgramType",lua_cocos2dx_backend_Program_getProgramType); tolua_function(tolua_S,"getActiveAttributes",lua_cocos2dx_backend_Program_getActiveAttributes); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.hpp index d022b93be193..ddcac997317a 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.hpp @@ -56,7 +56,6 @@ int register_all_cocos2dx_backend(lua_State* tolua_S); - #endif // __cocos2dx_backend_h__ diff --git a/templates/lua-template-default/CMakeLists.txt b/templates/lua-template-default/CMakeLists.txt index 653927e5fa78..2680a6196de1 100644 --- a/templates/lua-template-default/CMakeLists.txt +++ b/templates/lua-template-default/CMakeLists.txt @@ -136,7 +136,7 @@ if(APPLE) LINK_FLAGS "-pagezero_size 10000 -image_base 100000000" ) elseif(IOS) - cocos_pak_xcode(${APP_NAME} INFO_PLIST "${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/Info.plist") + set_xcode_property(${APP_NAME} INFOPLIST_FILE "${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/Info.plist") set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon") set_xcode_property(${APP_NAME} DEVELOPMENT_TEAM "") set_xcode_property(${APP_NAME} CODE_SIGN_IDENTITY "iPhone Developer") diff --git a/tools/travis-scripts/run-script.sh b/tools/travis-scripts/run-script.sh old mode 100755 new mode 100644 index 6c6b961489ac..e89086af9c27 --- a/tools/travis-scripts/run-script.sh +++ b/tools/travis-scripts/run-script.sh @@ -33,10 +33,10 @@ function build_linux() echo "Building tests ..." source ../environment.sh cd $COCOS2DX_ROOT - mkdir -p linux-build - cd linux-build - cmake .. - cmake --build . + set -x + cmake . -G "Unix Makefiles" -Blinux-build-release -DCMAKE_BUILD_TYPE=Release + cmake --build linux-build-release -- -j `nproc` + set +x } function build_mac_cmake() @@ -51,10 +51,10 @@ function build_mac_cmake() mkdir -p mac_cmake_build cd mac_cmake_build cmake .. -GXcode - # cmake --build . - xcodebuild -project Cocos2d-x.xcodeproj -alltargets -jobs $NUM_OF_CORES build | xcpretty - #the following commands must not be removed - xcodebuild -project Cocos2d-x.xcodeproj -alltargets -jobs $NUM_OF_CORES build + cmake --build . --config Release -- -quiet + #xcodebuild -project Cocos2d-x.xcodeproj -alltargets -jobs $NUM_OF_CORES build | xcpretty + ##the following commands must not be removed + #xcodebuild -project Cocos2d-x.xcodeproj -alltargets -jobs $NUM_OF_CORES build exit 0 } @@ -70,12 +70,12 @@ function build_ios_cmake() mkdir -p ios_cmake_build cd ios_cmake_build cmake .. -GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator - # cmake --build . --config Release --target cpp-tests # too much logs on console when "cmake --build ." - # cmake --build . - xcodebuild -project Cocos2d-x.xcodeproj -target cpp-tests -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty - #the following commands must not be removed - xcodebuild -project Cocos2d-x.xcodeproj -target cpp-tests -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build + cmake --build . --config Release -- -quiet -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" + + #xcodebuild -project Cocos2d-x.xcodeproj -alltargets -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build | xcpretty + ##the following commands must not be removed + #xcodebuild -project Cocos2d-x.xcodeproj -alltargets -jobs $NUM_OF_CORES -destination "platform=iOS Simulator,name=iPhone Retina (4-inch)" build exit 0 } @@ -216,24 +216,64 @@ function run_pull_request() update_cocos_files python -u tools/cocos2d-console/bin/cocos.py --agreement n new -l lua -p my.pack.qqqq cocos_new_test popd - echo "Building tests ..." + + set -x cd $COCOS2DX_ROOT/cocos_new_test mkdir -p linux-build cd linux-build - cmake .. - cmake --build . + cmake .. -G"Unix Makefiles" + cmake --build . -- -j `nproc` + exit 0 + fi + + if [ "$BUILD_TARGET" == "ios_cocos_new_lua_test" ]; then + export PATH=$PATH:$COCOS2DX_ROOT/tools/cocos2d-console/bin + #NUM_OF_CORES=`getconf _NPROCESSORS_ONLN` + genernate_binding_codes + pushd $COCOS2DX_ROOT + echo "Creating tests ..." + + set -x + cocos --agreement n new -l lua ios_new_lua_proj + cd ios_new_lua_proj + mkdir build + cd build + cmake .. -GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator + cmake --build . --config Release -- -quiet + popd + exit 0 + fi + + if [ "$BUILD_TARGET" == "ios_cocos_new_cpp_test" ]; then + export PATH=$PATH:$COCOS2DX_ROOT/tools/cocos2d-console/bin + #NUM_OF_CORES=`getconf _NPROCESSORS_ONLN` + genernate_binding_codes + pushd $COCOS2DX_ROOT + echo "Creating tests ..." + + set -x + cocos --agreement n new -l cpp ios_new_cpp_proj + cd ios_new_cpp_proj + mkdir build + cd build + echo "Building tests ..." + cmake .. -GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator + cmake --build . --config Release -- -quiet + popd exit 0 fi if [ $BUILD_TARGET == 'mac_cmake' ]; then genernate_binding_codes + set -x build_mac_cmake exit 0 fi if [ $BUILD_TARGET == 'ios_cmake' ]; then genernate_binding_codes + set -x build_ios_cmake exit 0 fi