From 041b6ddb00ca9c875c3d46d06769165993779845 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Fri, 13 Oct 2017 02:50:03 -0500 Subject: [PATCH 1/2] [cocos2dx] allow load custom atlas texture in _spAtlasPage_createTexture for CocosCreator (#1018) --- spine-cocos2dx/src/spine/spine-cocos2dx.cpp | 15 ++++++++++++++- spine-cocos2dx/src/spine/spine-cocos2dx.h | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/spine-cocos2dx/src/spine/spine-cocos2dx.cpp b/spine-cocos2dx/src/spine/spine-cocos2dx.cpp index 4a7378fb1..150700261 100644 --- a/spine-cocos2dx/src/spine/spine-cocos2dx.cpp +++ b/spine-cocos2dx/src/spine/spine-cocos2dx.cpp @@ -31,6 +31,13 @@ #include #include +namespace spine { + static CustomTextureLoader _customTextureLoader = nullptr; + void spAtlasPage_setCustomTextureLoader (CustomTextureLoader texLoader) { + _customTextureLoader = texLoader; + } +} + USING_NS_CC; GLuint wrap (spAtlasWrap wrap) { @@ -60,7 +67,13 @@ GLuint filter (spAtlasFilter filter) { } void _spAtlasPage_createTexture (spAtlasPage* self, const char* path) { - Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(path); + Texture2D* texture = nullptr; + if (spine::_customTextureLoader) { + texture = spine::_customTextureLoader(path); + } + if (!texture) { + texture = Director::getInstance()->getTextureCache()->addImage(path); + } CCASSERT(texture != nullptr, "Invalid image"); texture->retain(); diff --git a/spine-cocos2dx/src/spine/spine-cocos2dx.h b/spine-cocos2dx/src/spine/spine-cocos2dx.h index 81e2d7f12..497d12796 100644 --- a/spine-cocos2dx/src/spine/spine-cocos2dx.h +++ b/spine-cocos2dx/src/spine/spine-cocos2dx.h @@ -38,4 +38,10 @@ #include #include +namespace spine { + typedef cocos2d::Texture2D* (*CustomTextureLoader)(const char* path); + // set custom texture loader for _spAtlasPage_createTexture + void spAtlasPage_setCustomTextureLoader(CustomTextureLoader texLoader); +} + #endif /* SPINE_COCOS2DX_H_ */ From 9cb8745debf2838890575034586994e5a078a570 Mon Sep 17 00:00:00 2001 From: badlogic Date: Fri, 13 Oct 2017 09:51:03 +0200 Subject: [PATCH 2/2] Updated CHANGELOG --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbe7d9d31..02c37e5b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ * Added support for clipping. * Added support for rotated regions in texture atlas loaded via StarlingAtlasAttachmentLoader. * Added support for vertex effects. See `RaptorExample.as` + * Added 'getTexture()' method to 'StarlingTextureAtlasAttachmentLoader' ## C * **Breaking changes** @@ -52,7 +53,6 @@ * Added `spVertexEffect` and corresponding implementations `spJitterVertexEffect` and `spSwirlVertexEffect`. Create/dispose through the corresponding `spXXXVertexEffect_create()/dispose()` functions. Set on framework/engine specific renderer. See changes for spine-c based frameworks/engines below. * Functions in `extension.h` are not prefixed with `_sp` instead of just `_` to avoid interference with other libraries. * Introduced `SP_API` macro. Every spine-c function is prefixed with this macro. By default, it is an empty string. Can be used to markup spine-c functions with e.g. ``__declspec` when compiling to a dll or linking to that dll. - * Added `void* userData` to `spAnimationState` to be consumed in callbacks. ### Cocos2d-X * Fixed renderer to work with 3.6 changes @@ -64,6 +64,7 @@ * SkeletonRenderer now combines the displayed color of the Node (cascaded from all parents) with the skeleton color for tinting. * Added support for vertex effects. See `RaptorExample.cpp`. * Added ETC1 alpha support, thanks @halx99! Does not work when two color tint is enabled. + * Added `spAtlasPage_setCustomTextureLoader()` which let's you do texture loading manually. Thanks @jareguo. ### Cocos2d-Objc * Fixed renderer to work with 3.6 changes @@ -84,7 +85,6 @@ * Added support for two color tinting. All base materials, e.g. SpineUnlitNormalMaterial, now do proper two color tinting. No material parameters have changed. * Updated to Unreal Engine 4.16.1. Note that 4.16 has a regression which will make it impossible to compile plain .c files! * spine-c is now exposed from the plugin shared library on Windows via __declspec. - * `SkeletonRenderComponent` now generates collision meshes by default. ## C# * **Breaking changes** @@ -147,6 +147,7 @@ * Removed `RegionBatcher` and `SkeletonRegionRenderer`, renamed `SkeletonMeshRenderer` to `SkeletonRenderer` * Added support for two color tint. For it to work, you need to add the `SpineEffect.fx` file to your content project, then load it via `var effect = Content.Load("SpineEffect");`, and set it on the `SkeletonRenderer`. See the example project for code. * Added support for any `Effect` to be used by `SkeletonRenderer` + * Added support for `IVertexEffect` to modify vertices of skeletons on the CPU. `IVertexEffect` instances can be set on the `SkeletonRenderer`. See example project. * Added `SkeletonDebugRenderer` ## Java