mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[cpp][cocos2dx][sfml][sdl] Fix up runtimes according to renderer object system changes.
This commit is contained in:
parent
3d5075c7a4
commit
1a676c14fc
@ -22,7 +22,7 @@ endif()
|
|||||||
|
|
||||||
if((${SPINE_SFML}) OR (${CMAKE_CURRENT_BINARY_DIR} MATCHES "spine-sfml"))
|
if((${SPINE_SFML}) OR (${CMAKE_CURRENT_BINARY_DIR} MATCHES "spine-sfml"))
|
||||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
set(CMAKE_OSX_ARCHITECTURES x86_64;arm64)
|
set(CMAKE_OSX_ARCHITECTURES x86_64)
|
||||||
set(ONLY_ACTIVE_ARCH NO)
|
set(ONLY_ACTIVE_ARCH NO)
|
||||||
endif()
|
endif()
|
||||||
add_subdirectory(spine-c)
|
add_subdirectory(spine-c)
|
||||||
|
|||||||
@ -74,6 +74,8 @@ open build-macos/spine-cocos2dx-example.xcodeproj
|
|||||||
|
|
||||||
This will generate an Xcode project in `build-macos/spine-cocos2dx-example.xcodeproj` and open it in Xcode. To build and run the example, select the `spine-cocos2dx-example` scheme and press `CMD + R`.
|
This will generate an Xcode project in `build-macos/spine-cocos2dx-example.xcodeproj` and open it in Xcode. To build and run the example, select the `spine-cocos2dx-example` scheme and press `CMD + R`.
|
||||||
|
|
||||||
|
> **Note**: cocos2d-x only ships pre-built external libraries like Bullet or FreeType for x86_64. If you build on a machine with Apple Silicon, adjust the `cmake` command above to `mkdir build-macos && cmake . -GXcode -Bbuild-macos -DCMAKE_OSX_ARCHITECTURES=x86_64`.
|
||||||
|
|
||||||
### iOS
|
### iOS
|
||||||
Execute the following on the command line:
|
Execute the following on the command line:
|
||||||
|
|
||||||
|
|||||||
@ -41,8 +41,7 @@ static void deleteAttachmentVertices(void *vertices) {
|
|||||||
static unsigned short quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
static unsigned short quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
||||||
|
|
||||||
static void setAttachmentVertices(RegionAttachment *attachment) {
|
static void setAttachmentVertices(RegionAttachment *attachment) {
|
||||||
AtlasRegion *region = (AtlasRegion *) attachment->getRendererObject();
|
AttachmentVertices *attachmentVertices = new AttachmentVertices((Texture2D *) attachment->getRegion()->rendererObject, 4, quadTriangles, 6);
|
||||||
AttachmentVertices *attachmentVertices = new AttachmentVertices((Texture2D *) region->page->getRendererObject(), 4, quadTriangles, 6);
|
|
||||||
V3F_C4B_T2F *vertices = attachmentVertices->_triangles->verts;
|
V3F_C4B_T2F *vertices = attachmentVertices->_triangles->verts;
|
||||||
for (int i = 0, ii = 0; i < 4; ++i, ii += 2) {
|
for (int i = 0, ii = 0; i < 4; ++i, ii += 2) {
|
||||||
vertices[i].texCoords.u = attachment->getUVs()[ii];
|
vertices[i].texCoords.u = attachment->getUVs()[ii];
|
||||||
@ -52,8 +51,7 @@ static void setAttachmentVertices(RegionAttachment *attachment) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void setAttachmentVertices(MeshAttachment *attachment) {
|
static void setAttachmentVertices(MeshAttachment *attachment) {
|
||||||
AtlasRegion *region = (AtlasRegion *) attachment->getRendererObject();
|
AttachmentVertices *attachmentVertices = new AttachmentVertices((Texture2D *)attachment->getRegion()->rendererObject,
|
||||||
AttachmentVertices *attachmentVertices = new AttachmentVertices((Texture2D *) region->page->getRendererObject(),
|
|
||||||
attachment->getWorldVerticesLength() >> 1, attachment->getTriangles().buffer(), attachment->getTriangles().size());
|
attachment->getWorldVerticesLength() >> 1, attachment->getTriangles().buffer(), attachment->getTriangles().size());
|
||||||
V3F_C4B_T2F *vertices = attachmentVertices->_triangles->verts;
|
V3F_C4B_T2F *vertices = attachmentVertices->_triangles->verts;
|
||||||
for (int i = 0, ii = 0, nn = attachment->getWorldVerticesLength(); ii < nn; ++i, ii += 2) {
|
for (int i = 0, ii = 0, nn = attachment->getWorldVerticesLength(); ii < nn; ++i, ii += 2) {
|
||||||
@ -149,7 +147,7 @@ void Cocos2dTextureLoader::load(AtlasPage &page, const spine::String &path) {
|
|||||||
#endif
|
#endif
|
||||||
texture->setTexParameters(textureParams);
|
texture->setTexParameters(textureParams);
|
||||||
|
|
||||||
page.setRendererObject(texture);
|
page.texture = texture;
|
||||||
page.width = texture->getPixelsWide();
|
page.width = texture->getPixelsWide();
|
||||||
page.height = texture->getPixelsHigh();
|
page.height = texture->getPixelsHigh();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
/// Attachment that displays a texture region using a mesh.
|
/// Attachment that displays a texture region using a mesh.
|
||||||
class SP_API MeshAttachment : public VertexAttachment {
|
class SP_API MeshAttachment : public VertexAttachment, public HasRendererObject {
|
||||||
friend class SkeletonBinary;
|
friend class SkeletonBinary;
|
||||||
|
|
||||||
friend class SkeletonJson;
|
friend class SkeletonJson;
|
||||||
|
|||||||
@ -44,7 +44,7 @@ namespace spine {
|
|||||||
class Bone;
|
class Bone;
|
||||||
|
|
||||||
/// Attachment that displays a texture region.
|
/// Attachment that displays a texture region.
|
||||||
class SP_API RegionAttachment : public Attachment {
|
class SP_API RegionAttachment : public Attachment, public HasRendererObject {
|
||||||
friend class SkeletonBinary;
|
friend class SkeletonBinary;
|
||||||
|
|
||||||
friend class SkeletonJson;
|
friend class SkeletonJson;
|
||||||
|
|||||||
@ -34,7 +34,7 @@ using namespace spine;
|
|||||||
|
|
||||||
RTTI_IMPL(MeshAttachment, VertexAttachment)
|
RTTI_IMPL(MeshAttachment, VertexAttachment)
|
||||||
|
|
||||||
MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name),
|
MeshAttachment::MeshAttachment(const String &name) : VertexAttachment(name), HasRendererObject(),
|
||||||
_parentMesh(NULL),
|
_parentMesh(NULL),
|
||||||
_path(),
|
_path(),
|
||||||
_color(1, 1, 1, 1),
|
_color(1, 1, 1, 1),
|
||||||
|
|||||||
@ -47,7 +47,7 @@ const int RegionAttachment::URY = 5;
|
|||||||
const int RegionAttachment::BRX = 6;
|
const int RegionAttachment::BRX = 6;
|
||||||
const int RegionAttachment::BRY = 7;
|
const int RegionAttachment::BRY = 7;
|
||||||
|
|
||||||
RegionAttachment::RegionAttachment(const String &name) : Attachment(name),
|
RegionAttachment::RegionAttachment(const String &name) : Attachment(name), HasRendererObject(),
|
||||||
_x(0),
|
_x(0),
|
||||||
_y(0),
|
_y(0),
|
||||||
_rotation(0),
|
_rotation(0),
|
||||||
|
|||||||
@ -101,7 +101,7 @@ void SkeletonDrawable::draw(SDL_Renderer *renderer) {
|
|||||||
uvs = ®ionAttachment->getUVs();
|
uvs = ®ionAttachment->getUVs();
|
||||||
indices = &quadIndices;
|
indices = &quadIndices;
|
||||||
indicesCount = 6;
|
indicesCount = 6;
|
||||||
texture = (SDL_Texture *) ((AtlasRegion *) regionAttachment->getRendererObject())->page->getRendererObject();
|
texture = (SDL_Texture *)regionAttachment->getRegion()->rendererObject;
|
||||||
|
|
||||||
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
|
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
|
||||||
MeshAttachment *mesh = (MeshAttachment *) attachment;
|
MeshAttachment *mesh = (MeshAttachment *) attachment;
|
||||||
@ -114,7 +114,7 @@ void SkeletonDrawable::draw(SDL_Renderer *renderer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
worldVertices.setSize(mesh->getWorldVerticesLength(), 0);
|
worldVertices.setSize(mesh->getWorldVerticesLength(), 0);
|
||||||
texture = (SDL_Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->getRendererObject();
|
texture = (SDL_Texture *)mesh->getRegion()->rendererObject;
|
||||||
mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices.buffer(), 0, 2);
|
mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices.buffer(), 0, 2);
|
||||||
verticesCount = mesh->getWorldVerticesLength() >> 1;
|
verticesCount = mesh->getWorldVerticesLength() >> 1;
|
||||||
uvs = &mesh->getUVs();
|
uvs = &mesh->getUVs();
|
||||||
@ -201,7 +201,7 @@ SDL_Texture *loadTexture(SDL_Renderer *renderer, const String &path) {
|
|||||||
void SDLTextureLoader::load(AtlasPage &page, const String &path) {
|
void SDLTextureLoader::load(AtlasPage &page, const String &path) {
|
||||||
SDL_Texture *texture = loadTexture(renderer, path);
|
SDL_Texture *texture = loadTexture(renderer, path);
|
||||||
if (!texture) return;
|
if (!texture) return;
|
||||||
page.setRendererObject(texture);
|
page.texture = texture;
|
||||||
SDL_QueryTexture(texture, nullptr, nullptr, &page.width, &page.height);
|
SDL_QueryTexture(texture, nullptr, nullptr, &page.width, &page.height);
|
||||||
switch (page.magFilter) {
|
switch (page.magFilter) {
|
||||||
case TextureFilter_Nearest:
|
case TextureFilter_Nearest:
|
||||||
|
|||||||
@ -103,7 +103,6 @@ namespace spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vector<float> *vertices = &worldVertices;
|
Vector<float> *vertices = &worldVertices;
|
||||||
int verticesCount = 0;
|
|
||||||
Vector<float> *uvs = NULL;
|
Vector<float> *uvs = NULL;
|
||||||
Vector<unsigned short> *indices = NULL;
|
Vector<unsigned short> *indices = NULL;
|
||||||
int indicesCount = 0;
|
int indicesCount = 0;
|
||||||
@ -121,11 +120,10 @@ namespace spine {
|
|||||||
|
|
||||||
worldVertices.setSize(8, 0);
|
worldVertices.setSize(8, 0);
|
||||||
regionAttachment->computeWorldVertices(slot, worldVertices, 0, 2);
|
regionAttachment->computeWorldVertices(slot, worldVertices, 0, 2);
|
||||||
verticesCount = 4;
|
|
||||||
uvs = ®ionAttachment->getUVs();
|
uvs = ®ionAttachment->getUVs();
|
||||||
indices = &quadIndices;
|
indices = &quadIndices;
|
||||||
indicesCount = 6;
|
indicesCount = 6;
|
||||||
texture = (Texture *) ((AtlasRegion *) regionAttachment->getRendererObject())->page->getRendererObject();
|
texture = (Texture *)regionAttachment->getRegion()->rendererObject;
|
||||||
|
|
||||||
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
|
} else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
|
||||||
MeshAttachment *mesh = (MeshAttachment *) attachment;
|
MeshAttachment *mesh = (MeshAttachment *) attachment;
|
||||||
@ -138,9 +136,8 @@ namespace spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
worldVertices.setSize(mesh->getWorldVerticesLength(), 0);
|
worldVertices.setSize(mesh->getWorldVerticesLength(), 0);
|
||||||
texture = (Texture *) ((AtlasRegion *) mesh->getRendererObject())->page->getRendererObject();
|
texture = (Texture *)mesh->getRegion()->rendererObject;
|
||||||
mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices.buffer(), 0, 2);
|
mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), worldVertices.buffer(), 0, 2);
|
||||||
verticesCount = mesh->getWorldVerticesLength() >> 1;
|
|
||||||
uvs = &mesh->getUVs();
|
uvs = &mesh->getUVs();
|
||||||
indices = &mesh->getTriangles();
|
indices = &mesh->getTriangles();
|
||||||
indicesCount = mesh->getTriangles().size();
|
indicesCount = mesh->getTriangles().size();
|
||||||
@ -216,7 +213,6 @@ namespace spine {
|
|||||||
if (clipper.isClipping()) {
|
if (clipper.isClipping()) {
|
||||||
clipper.clipTriangles(worldVertices, *indices, *uvs, 2);
|
clipper.clipTriangles(worldVertices, *indices, *uvs, 2);
|
||||||
vertices = &clipper.getClippedVertices();
|
vertices = &clipper.getClippedVertices();
|
||||||
verticesCount = clipper.getClippedVertices().size() >> 1;
|
|
||||||
uvs = &clipper.getClippedUVs();
|
uvs = &clipper.getClippedUVs();
|
||||||
indices = &clipper.getClippedTriangles();
|
indices = &clipper.getClippedTriangles();
|
||||||
indicesCount = clipper.getClippedTriangles().size();
|
indicesCount = clipper.getClippedTriangles().size();
|
||||||
@ -245,7 +241,7 @@ namespace spine {
|
|||||||
if (page.magFilter == TextureFilter_Linear) texture->setSmooth(true);
|
if (page.magFilter == TextureFilter_Linear) texture->setSmooth(true);
|
||||||
if (page.uWrap == TextureWrap_Repeat && page.vWrap == TextureWrap_Repeat) texture->setRepeated(true);
|
if (page.uWrap == TextureWrap_Repeat && page.vWrap == TextureWrap_Repeat) texture->setRepeated(true);
|
||||||
|
|
||||||
page.setRendererObject(texture);
|
page.texture = texture;
|
||||||
Vector2u size = texture->getSize();
|
Vector2u size = texture->getSize();
|
||||||
page.width = size.x;
|
page.width = size.x;
|
||||||
page.height = size.y;
|
page.height = size.y;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user