Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync official-v4 20191130 #16

Merged
merged 6 commits into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions cocos/2d/CCFastTMXLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions cocos/editor-support/cocostudio/CCDatas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ FrameData::FrameData()

FrameData::~FrameData()
{
CC_SAFE_DELETE(easingParams);
CC_SAFE_DELETE_ARRAY(easingParams);
}

void FrameData::copy(const BaseData *baseData)
Expand All @@ -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];
Expand Down
10 changes: 5 additions & 5 deletions cocos/renderer/CCTrianglesCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -86,7 +86,7 @@ void TrianglesCommand::generateMaterialID()
struct
{
void* texture;
void* program;
backend::ProgramType programType;
backend::BlendFactor src;
backend::BlendFactor dst;
}hashMe;
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion cocos/renderer/CCTrianglesCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
18 changes: 9 additions & 9 deletions cocos/renderer/backend/Program.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -146,8 +140,14 @@ class Program : public Ref
* @return The uniformInfos.
*/
virtual const std::unordered_map<std::string, UniformInfo>& 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.
Expand Down Expand Up @@ -179,12 +179,12 @@ class Program : public Ref
*/
virtual const std::unordered_map<std::string, int> 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
Expand Down
1 change: 1 addition & 0 deletions cocos/renderer/backend/ShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion cocos/renderer/backend/ShaderModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions cocos/renderer/backend/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions cocos/renderer/backend/metal/RenderPipelineMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ProgramMTL*>(pipelineDescirptor.programState->getProgram());
hashMe.vertexShaderHash = program->getVertexShader()->getHashValue();
hashMe.fragmentShaderHash = program->getFragmentShader()->getHashValue();
hashMe.colorAttachment = _colorAttachmentsFormat[0];
hashMe.depthAttachment = _depthAttachmentFormat;
hashMe.stencilAttachment =_stencilAttachmentFormat;
Expand Down Expand Up @@ -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)
{
Expand Down
51 changes: 0 additions & 51 deletions cocos/scripting/lua-bindings/auto/lua_cocos2dx_backend_auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ int register_all_cocos2dx_backend(lua_State* tolua_S);






#endif // __cocos2dx_backend_h__
2 changes: 1 addition & 1 deletion templates/lua-template-default/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading