Merge pull request #7339 from super626/v3

fix android, add 3d files to cocos2d.h and remove unused resources
This commit is contained in:
minggo 2014-07-08 22:09:50 +08:00
commit 0f7968de89
11 changed files with 87 additions and 225 deletions

View File

@ -447,8 +447,7 @@ bool Bundle3D::loadBinary(const std::string& path)
return false;
}
// Create bundle reader
//CC_SAFE_DELETE(_bundleReader);
// Initialise bundle reader
_binaryReader.init( (char*)_binaryBuffer->getBytes(), _binaryBuffer->getSize() );
// Read identifier info
@ -463,20 +462,23 @@ bool Bundle3D::loadBinary(const std::string& path)
// Read version
unsigned char ver[2];
if (_binaryReader.read(ver, 1, 2) == 2)
{
if (ver[0] != 0) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
if (ver[1] <= 0 || ver[1] > 2) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
if (_binaryReader.read(ver, 1, 2)!= 2){
CCLOG("Failed to read version:");
return false;
}
if (ver[0] != 0) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
if (ver[1] <= 0 || ver[1] > 2) {
clear();
CCLOGINFO(false, "Unsupported version: (%d, %d)", ver[0], ver[1]);
return false;
}
// Read ref table size
if (_binaryReader.read(&_referenceCount, 4, 1) != 1)
@ -766,17 +768,37 @@ bool Bundle3D::loadAnimationDataBinary(Animation3DData* animationdata)
GLenum Bundle3D::parseGLType(const std::string& str)
{
if (str == "GL_FLOAT")
if (str == "GL_BYTE")
{
return GL_FLOAT;
return GL_BYTE;
}
else if(str == "GL_UNSIGNED_BYTE")
{
return GL_UNSIGNED_BYTE;
}
else if(str == "GL_SHORT")
{
return GL_SHORT;
}
else if(str == "GL_UNSIGNED_SHORT")
{
return GL_UNSIGNED_SHORT;
}
else if(str == "GL_INT")
{
return GL_INT;
}
else if (str == "GL_UNSIGNED_INT")
{
return GL_UNSIGNED_INT;
}
else if (str == "GL_FLOAT")
{
return GL_FLOAT;
}
else
{
assert(0);
CCASSERT(false, "Wrong GL type");
return 0;
}
}

View File

@ -65,7 +65,7 @@ char* BundleReader::readLine(int num,char* line)
char* p = line;
char c;
ssize_t readNum = 0;
while((c=*buffer) != 10 && readNum < (ssize_t)num && m_position<(long int)m_length)
while((c=*buffer) != 10 && readNum < (ssize_t)num && m_position < m_length)
{
*p = c;
p++;
@ -91,7 +91,7 @@ ssize_t BundleReader::length()
return m_length;
}
long int BundleReader::tell()
ssize_t BundleReader::tell()
{
if (!m_buffer)
return -1;

View File

@ -112,7 +112,7 @@ public:
bool readMatrix(float* m);
private:
long int m_position;
ssize_t m_position;
ssize_t m_length;
char* m_buffer;
};
@ -136,6 +136,7 @@ inline bool BundleReader::readArray(unsigned int *length, std::vector<T> *values
{
return false;
}
if (*length > 0 && values)
{
values->resize(*length);

View File

@ -192,7 +192,7 @@ bool Mesh::init(const std::vector<float>& positions, const std::vector<float>& n
if (!bRet)
return false;
restore();
buildBuffer();
return true;
}
@ -202,7 +202,7 @@ bool Mesh::init(const std::vector<float>& vertices, int vertexSizeInFloat, const
if (!bRet)
return false;
restore();
buildBuffer();
return true;
}
@ -242,20 +242,20 @@ void Mesh::buildBuffer()
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
unsigned int indexSize = 2;
IndexFormat indexformat = IndexFormat::INDEX16;
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexSize * _renderdata._indices.size(), &_renderdata._indices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
_primitiveType = PrimitiveType::TRIANGLES;
_indexFormat = indexformat;
_indexFormat = IndexFormat::INDEX16;
_indexCount = _renderdata._indices.size();
}
void Mesh::restore()
{
cleanAndFreeBuffers();
_vertexBuffer = 0;
_indexBuffer = 0;
buildBuffer();
}

View File

@ -261,6 +261,10 @@ THE SOFTWARE.
//3d
#include "3d/CCSprite3D.h"
#include "3d/CCMesh.h"
#include "3d/CCMeshSkin.h"
#include "3d/CCAnimate3D.h"
#include "3d/CCAnimation3D.h"
#include "3d/CCSprite3DMaterial.h"
// Audio
#include "audio/include/SimpleAudioEngine.h"

View File

@ -172,7 +172,7 @@ void MeshCommand::genMaterialID(GLuint texID, void* glProgramState, void* mesh,
void MeshCommand::MatrixPalleteCallBack( GLProgram* glProgram, Uniform* uniform)
{
glProgram->setUniformLocationWith4fv(uniform->location, (const float*)_matrixPalette, _matrixPaletteSize);
glUniform4fv( uniform->location, (GLsizei)_matrixPaletteSize, (const float*)_matrixPalette );
}
void MeshCommand::preBatchDraw()
@ -183,12 +183,11 @@ void MeshCommand::preBatchDraw()
GL::bindTexture2D(_textureID);
GL::blendFunc(_blendType.src, _blendType.dst);
if (_vao == 0)
if (Configuration::getInstance()->supportsShareableVAO() && _vao == 0)
buildVAO();
if (_vao)
{
GL::bindVAO(_vao);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
}
else
{
@ -265,30 +264,27 @@ void MeshCommand::execute()
void MeshCommand::buildVAO()
{
releaseVAO();
if (Configuration::getInstance()->supportsShareableVAO())
{
glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
auto flags = _glProgramState->getVertexAttribsFlags();
for (int i = 0; flags > 0; i++) {
int flag = 1 << i;
if (flag & flags)
glEnableVertexAttribArray(i);
flags &= ~flag;
}
_glProgramState->applyAttributes(false);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
GL::bindVAO(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
auto flags = _glProgramState->getVertexAttribsFlags();
for (int i = 0; flags > 0; i++) {
int flag = 1 << i;
if (flag & flags)
glEnableVertexAttribArray(i);
flags &= ~flag;
}
_glProgramState->applyAttributes(false);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
GL::bindVAO(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
void MeshCommand::releaseVAO()
{
if (Configuration::getInstance()->supportsShareableVAO() && _vao)
if (_vao)
{
glDeleteVertexArrays(1, &_vao);
_vao = 0;
@ -299,7 +295,7 @@ void MeshCommand::releaseVAO()
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
void MeshCommand::listenBackToForeground(EventCustom* event)
{
releaseVAO();
_vao = 0;
}
#endif

View File

@ -15,7 +15,7 @@ void main(void)
);
const char* cc3D_SkinPositionTex_vert = STRINGIFY(
attribute vec4 a_position;
attribute vec3 a_position;
attribute vec4 a_blendWeight;
attribute vec4 a_blendIndex;
@ -70,10 +70,11 @@ vec4 getPosition()
vec4 _skinnedPosition;
_skinnedPosition.x = dot(a_position, matrixPalette1);
_skinnedPosition.y = dot(a_position, matrixPalette2);
_skinnedPosition.z = dot(a_position, matrixPalette3);
_skinnedPosition.w = a_position.w;
vec4 postion = vec4(a_position, 1.0);
_skinnedPosition.x = dot(postion, matrixPalette1);
_skinnedPosition.y = dot(postion, matrixPalette2);
_skinnedPosition.z = dot(postion, matrixPalette3);
_skinnedPosition.w = postion.w;
return _skinnedPosition;
}

View File

@ -176,7 +176,7 @@ static int lua_cocos2dx_ArmatureAnimation_setFrameEventCallFunc(lua_State* L)
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)wrapper, handler, ScriptHandlerMgr::HandlerType::ARMATURE_EVENT);
self->setFrameEventCallFunc([=](Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex){
self->setFrameEventCallFunc([=](cocostudio::Bone *bone, const std::string& frameEventName, int originFrameIndex, int currentFrameIndex){
if (0 != handler)
{

View File

@ -591,7 +591,7 @@ std::string TestFrameEvent::title() const
{
return "Test Frame Event";
}
void TestFrameEvent::onFrameEvent(Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex)
void TestFrameEvent::onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex)
{
CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt.c_str(), currentFrameIndex);
@ -633,7 +633,7 @@ void TestParticleDisplay::onEnter()
ParticleSystem *p1 = CCParticleSystemQuad::create("Particles/SmallSun.plist");
ParticleSystem *p2 = CCParticleSystemQuad::create("Particles/SmallSun.plist");
Bone *bone = Bone::create("p1");
cocostudio::Bone *bone = cocostudio::Bone::create("p1");
bone->addDisplay(p1, 0);
bone->changeDisplayWithIndex(0, true);
bone->setIgnoreMovementBoneData(true);
@ -641,7 +641,7 @@ void TestParticleDisplay::onEnter()
bone->setScale(1.2f);
armature->addBone(bone, "bady-a3");
bone = Bone::create("p2");
bone = cocostudio::Bone::create("p2");
bone->addDisplay(p2, 0);
bone->changeDisplayWithIndex(0, true);
bone->setIgnoreMovementBoneData(true);
@ -773,7 +773,7 @@ std::string TestColliderDetector::title() const
{
return "Test Collider Detector";
}
void TestColliderDetector::onFrameEvent(Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex)
void TestColliderDetector::onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex)
{
CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt.c_str(), currentFrameIndex);
@ -1025,10 +1025,10 @@ void TestColliderDetector::update(float delta)
// This code is just telling how to get the vertex.
// For a more accurate collider detection, you need to implemente yourself.
const Map<std::string, Bone*>& map = armature2->getBoneDic();
const Map<std::string, cocostudio::Bone*>& map = armature2->getBoneDic();
for(const auto& element : map)
{
Bone *bone = element.second;
cocostudio::Bone *bone = element.second;
ColliderDetector *detector = bone->getColliderDetector();
if (!detector)
@ -1243,7 +1243,7 @@ void Hero::changeMount(Armature *armature)
removeFromParentAndCleanup(false);
//Get the hero bone
Bone *bone = armature->getBone("hero");
cocostudio::Bone *bone = armature->getBone("hero");
//Add hero as a display to this bone
bone->addDisplay(this, 0);
//Change this bone's display

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

View File

@ -1,162 +0,0 @@
{
"version": "1.2",
"file_type": "c3t",
"mesh_data": [
{
"version": "1.2",
"mesh_vertex_attribute": [
{
"size":3,
"type":"GL_FLOAT",
"vertex_attribute":"VERTEX_ATTRIB_POSITION"
},
{
"size":3,
"type":"GL_FLOAT",
"vertex_attribute":"VERTEX_ATTRIB_NORMAL"
},
{
"size":2,
"type":"GL_FLOAT",
"vertex_attribute":"VERTEX_ATTRIB_TEX_COORD"
},
{
"size":4,
"type":"GL_FLOAT",
"vertex_attribute":"VERTEX_ATTRIB_BLEND_WEIGHT"
},
{
"size":4,
"type":"GL_FLOAT",
"vertex_attribute":"VERTEX_ATTRIB_BLEND_INDEX"
}
],
"body":[
{
"vertices": [
0.000000, -2.259414, -2.259414, 0.000000, 0.000000, -1.000000, 0.582997, 0.456003, 0.500033, 0.499967, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
-5.314565, -2.259414, -2.259414, 0.000000, 0.000000, -1.000000, 0.582997, 0.168971, 0.933581, 0.066419, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
0.000000, 2.259414, -2.259414, 0.000000, 0.000000, -1.000000, 0.827052, 0.456003, 0.500111, 0.499889, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
-5.314565, 2.259414, -2.259414, 0.000000, 0.000000, -1.000000, 0.827052, 0.168971, 0.932199, 0.067801, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
0.000000, -2.259414, 2.259414, 0.000000, -1.000000, 0.000000, 0.253258, 0.705932, 0.500033, 0.499967, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
-5.314565, -2.259414, 2.259414, 0.000000, -1.000000, 0.000000, 0.253258, 0.418900, 0.933581, 0.066419, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
-5.314565, -2.259414, -2.259414, 0.000000, -1.000000, 0.000000, 0.497313, 0.418900, 0.933581, 0.066419, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
0.000000, -2.259414, -2.259414, 0.000000, -1.000000, 0.000000, 0.497313, 0.705932, 0.500033, 0.499967, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
-5.314565, 2.259414, 2.259414, -1.000000, 0.000000, 0.000000, 0.753117, 0.748774, 0.932199, 0.067801, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
-5.314565, -2.259414, -2.259414, -1.000000, 0.000000, 0.000000, 0.997172, 0.992829, 0.933581, 0.066419, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
-5.314565, -2.259414, 2.259414, -1.000000, 0.000000, 0.000000, 0.753117, 0.992829, 0.933581, 0.066419, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
-5.314565, 2.259414, -2.259414, -1.000000, 0.000000, 0.000000, 0.997172, 0.748774, 0.932199, 0.067801, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
5.314565, -2.259414, -2.259414, 0.000000, 0.000000, -1.000000, 0.582997, 0.743034, 0.932057, 0.067943, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
5.314565, 2.259414, -2.259414, 0.000000, 0.000000, -1.000000, 0.827052, 0.743034, 0.938571, 0.061429, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
5.314565, -2.259414, 2.259414, 0.000000, -1.000000, 0.000000, 0.253258, 0.992964, 0.932057, 0.067943, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
5.314565, -2.259414, -2.259414, 0.000000, -1.000000, 0.000000, 0.497313, 0.992964, 0.932057, 0.067943, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
5.314565, 2.259414, 2.259414, 1.000000, 0.000000, 0.000000, 0.503187, 0.992829, 0.938571, 0.061429, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
5.314565, -2.259414, 2.259414, 1.000000, 0.000000, 0.000000, 0.503187, 0.748774, 0.932057, 0.067943, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
5.314565, -2.259414, -2.259414, 1.000000, 0.000000, 0.000000, 0.747243, 0.748774, 0.932057, 0.067943, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
5.314565, 2.259414, -2.259414, 1.000000, 0.000000, 0.000000, 0.747243, 0.992829, 0.938571, 0.061429, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
0.000000, 2.259414, 2.259414, 0.000000, 1.000000, 0.000000, 0.003328, 0.705932, 0.500111, 0.499889, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
-5.314565, 2.259414, -2.259414, 0.000000, 1.000000, 0.000000, 0.247384, 0.992964, 0.932199, 0.067801, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
-5.314565, 2.259414, 2.259414, 0.000000, 1.000000, 0.000000, 0.003328, 0.992964, 0.932199, 0.067801, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
0.000000, 2.259414, -2.259414, 0.000000, 1.000000, 0.000000, 0.247384, 0.705932, 0.500111, 0.499889, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
5.314565, 2.259414, 2.259414, 0.000000, 1.000000, 0.000000, 0.003328, 0.418900, 0.938571, 0.061429, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
5.314565, 2.259414, -2.259414, 0.000000, 1.000000, 0.000000, 0.247384, 0.418900, 0.938571, 0.061429, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
0.000000, 2.259414, 2.259414, 0.000000, 0.000000, 1.000000, 0.290226, 0.413161, 0.500111, 0.499889, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
-5.314565, 2.259414, 2.259414, 0.000000, 0.000000, 1.000000, 0.003194, 0.413161, 0.932199, 0.067801, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
-5.314565, -2.259414, 2.259414, 0.000000, 0.000000, 1.000000, 0.003194, 0.169105, 0.933581, 0.066419, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
0.000000, -2.259414, 2.259414, 0.000000, 0.000000, 1.000000, 0.290226, 0.169105, 0.500033, 0.499967, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
5.314565, 2.259414, 2.259414, 0.000000, 0.000000, 1.000000, 0.577257, 0.413161, 0.938571, 0.061429, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000,
5.314565, -2.259414, 2.259414, 0.000000, 0.000000, 1.000000, 0.577257, 0.169105, 0.932057, 0.067943, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000
],
"vertex_size": 512,
"indices": [
0, 1, 2, 1, 3, 2, 4, 5, 6, 4, 6, 7,
8, 9, 10, 9, 8, 11, 12, 0, 13, 0, 2, 13,
14, 4, 7, 14, 7, 15, 16, 17, 18, 16, 18, 19,
20, 21, 22, 21, 20, 23, 24, 23, 20, 23, 24, 25,
26, 27, 28, 26, 28, 29, 30, 26, 29, 30, 29, 31
],
"index_number": 60
}
]
}
],
"material_data": [
{
"file_name": "Sprite3DTest/checkboard.png"
}
],
"skin_data": [
{
"id": "cubeanim:cube",
"bind_shape": [ 0.393701, 0.000000, 0.000000, 0.000000, 0.000000, 0.393701, 0.000000, 0.000000, 0.000000, -0.000000, 0.393701, 0.000000, 0.100748, 0.000000, -0.457948, 1.000000],
"bones": [
{
"node": "bone1",
"bind_pos": [ 0.999989, 0.004613, 0.000000, 0.000000, -0.004613, 0.999989, 0.000000, 0.000000, -0.000000, -0.000000, 1.000000, 0.000000, -0.036861, 0.049203, 0.000000, 1.000000]
},
{
"node": "bone",
"bind_pos": [ 0.999958, 0.009184, 0.000000, 0.000000, -0.009184, 0.999958, 0.000000, 0.000000, -0.000000, -0.000000, 1.000000, 0.000000, -5.393930, -0.000000, -0.000000, 1.000000]
}
]
},
{
"id": "root",
"children": [
{
"id": "bone",
"children": [
{
"id": "bone1",
"children": [
{
"id": "eff"
}
]
}
]
}
]
}
],
"animation_data": [
{
"id": "Take 001",
"bones": [
{
"id": "bone1",
"keyframes": [
{
"rotation":[
{
"keytime": 0.000000,
"value": [ 0.000000, -0.000000, -0.002285, 0.999997]
},
{
"keytime": 0.333332,
"value": [ 0.000000, -0.000000, -0.002285, 0.999997]
},
{
"keytime": 0.666664,
"value": [ 0.000000, -0.000000, 0.089457, 0.995991]
},
{
"keytime": 0.800000,
"value": [ 0.000000, -0.000000, 0.184131, 0.982902]
},
{
"keytime": 0.933328,
"value": [ 0.000000, -0.000000, 0.274421, 0.961610]
},
{
"keytime": 1.000000,
"value": [ 0.000000, -0.000000, 0.362349, 0.932043]
}
]
}
]
}
]
}
]
}