2013-04-24 13:57:34 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2013, Esoteric Software
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <spine/spine-cocos2dx.h>
|
|
|
|
#include <spine/extension.h>
|
|
|
|
|
|
|
|
USING_NS_CC;
|
2013-06-02 22:26:46 +08:00
|
|
|
|
2013-04-24 13:57:34 +08:00
|
|
|
namespace cocos2d { namespace extension {
|
|
|
|
|
|
|
|
void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
|
2013-06-20 14:15:53 +08:00
|
|
|
Texture2D* texture = TextureCache::sharedTextureCache()->addImage(path);
|
|
|
|
TextureAtlas* textureAtlas = TextureAtlas::createWithTexture(texture, 4);
|
2013-04-24 13:57:34 +08:00
|
|
|
textureAtlas->retain();
|
2013-06-02 22:26:46 +08:00
|
|
|
self->rendererObject = textureAtlas;
|
2013-06-06 14:22:51 +08:00
|
|
|
// Using getContentSize to make it supports the strategy of loading resources in cocos2d-x.
|
|
|
|
// self->width = texture->getPixelsWide();
|
|
|
|
// self->height = texture->getPixelsHigh();
|
|
|
|
self->width = texture->getContentSize().width;
|
|
|
|
self->height = texture->getContentSize().height;
|
2013-04-24 13:57:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void _AtlasPage_disposeTexture (AtlasPage* self) {
|
2013-06-20 14:15:53 +08:00
|
|
|
((TextureAtlas*)self->rendererObject)->release();
|
2013-04-24 13:57:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char* _Util_readFile (const char* path, int* length) {
|
|
|
|
unsigned long size;
|
2013-06-20 14:15:53 +08:00
|
|
|
char* data = reinterpret_cast<char*>(FileUtils::sharedFileUtils()->getFileData(
|
|
|
|
FileUtils::sharedFileUtils()->fullPathForFilename(path).c_str(), "r", &size));
|
2013-04-24 13:57:34 +08:00
|
|
|
*length = size;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**/
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
void RegionAttachment_updateQuad (RegionAttachment* self, Slot* slot, V3F_C4B_T2F_Quad* quad, bool premultipliedAlpha) {
|
2013-06-02 22:26:46 +08:00
|
|
|
float vertices[8];
|
|
|
|
RegionAttachment_computeVertices(self, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices);
|
2013-04-24 13:57:34 +08:00
|
|
|
|
|
|
|
GLubyte r = slot->skeleton->r * slot->r * 255;
|
|
|
|
GLubyte g = slot->skeleton->g * slot->g * 255;
|
|
|
|
GLubyte b = slot->skeleton->b * slot->b * 255;
|
2013-06-02 22:26:46 +08:00
|
|
|
float normalizedAlpha = slot->skeleton->a * slot->a;
|
|
|
|
if (premultipliedAlpha) {
|
|
|
|
r *= normalizedAlpha;
|
|
|
|
g *= normalizedAlpha;
|
|
|
|
b *= normalizedAlpha;
|
|
|
|
}
|
|
|
|
GLubyte a = normalizedAlpha * 255;
|
2013-04-24 13:57:34 +08:00
|
|
|
quad->bl.colors.r = r;
|
|
|
|
quad->bl.colors.g = g;
|
|
|
|
quad->bl.colors.b = b;
|
|
|
|
quad->bl.colors.a = a;
|
|
|
|
quad->tl.colors.r = r;
|
|
|
|
quad->tl.colors.g = g;
|
|
|
|
quad->tl.colors.b = b;
|
|
|
|
quad->tl.colors.a = a;
|
|
|
|
quad->tr.colors.r = r;
|
|
|
|
quad->tr.colors.g = g;
|
|
|
|
quad->tr.colors.b = b;
|
|
|
|
quad->tr.colors.a = a;
|
|
|
|
quad->br.colors.r = r;
|
|
|
|
quad->br.colors.g = g;
|
|
|
|
quad->br.colors.b = b;
|
|
|
|
quad->br.colors.a = a;
|
|
|
|
|
2013-06-02 22:26:46 +08:00
|
|
|
quad->bl.vertices.x = vertices[VERTEX_X1];
|
|
|
|
quad->bl.vertices.y = vertices[VERTEX_Y1];
|
|
|
|
quad->tl.vertices.x = vertices[VERTEX_X2];
|
|
|
|
quad->tl.vertices.y = vertices[VERTEX_Y2];
|
|
|
|
quad->tr.vertices.x = vertices[VERTEX_X3];
|
|
|
|
quad->tr.vertices.y = vertices[VERTEX_Y3];
|
|
|
|
quad->br.vertices.x = vertices[VERTEX_X4];
|
|
|
|
quad->br.vertices.y = vertices[VERTEX_Y4];
|
|
|
|
|
|
|
|
quad->bl.texCoords.u = self->uvs[VERTEX_X1];
|
|
|
|
quad->bl.texCoords.v = self->uvs[VERTEX_Y1];
|
|
|
|
quad->tl.texCoords.u = self->uvs[VERTEX_X2];
|
|
|
|
quad->tl.texCoords.v = self->uvs[VERTEX_Y2];
|
|
|
|
quad->tr.texCoords.u = self->uvs[VERTEX_X3];
|
|
|
|
quad->tr.texCoords.v = self->uvs[VERTEX_Y3];
|
|
|
|
quad->br.texCoords.u = self->uvs[VERTEX_X4];
|
|
|
|
quad->br.texCoords.v = self->uvs[VERTEX_Y4];
|
2013-04-24 13:57:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-02 22:26:46 +08:00
|
|
|
}} // namespace cocos2d { namespace extension {
|