axmol/extensions/Particle3D/PU/CCPURender.cpp

926 lines
34 KiB
C++
Raw Normal View History

2015-02-11 18:14:22 +08:00
/****************************************************************************
2015-03-02 16:05:26 +08:00
Copyright (C) 2013 Henry van Merode. All rights reserved.
Copyright (c) 2015 Chukong Technologies Inc.
2015-02-11 18:14:22 +08:00
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
2015-03-02 16:05:26 +08:00
#include "extensions/Particle3D/CCParticleSystem3D.h"
2015-03-05 13:24:06 +08:00
#include "extensions/Particle3D/PU/CCPURender.h"
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
#include "extensions/Particle3D/PU/CCPUUtil.h"
2015-02-11 18:14:22 +08:00
#include "renderer/CCMeshCommand.h"
#include "renderer/CCRenderer.h"
#include "renderer/CCTextureCache.h"
#include "renderer/CCGLProgramState.h"
#include "renderer/CCGLProgramCache.h"
#include "renderer/CCVertexIndexBuffer.h"
#include "base/CCDirector.h"
#include "3d/CCSprite3D.h"
#include "3d/CCMesh.h"
#include "2d/CCCamera.h"
NS_CC_BEGIN
2015-03-05 13:24:06 +08:00
void PURender::copyAttributesTo( PURender *render )
2015-03-02 13:07:32 +08:00
{
render->_particleSystem = _particleSystem;
render->_isVisible = _isVisible;
render->_rendererScale = _rendererScale;
render->_depthTest = _depthTest;
render->_depthWrite = _depthWrite;
render->_renderType = _renderType;
}
//static bool compareParticle3D(PUParticle3D* left, PUParticle3D* right)
//{
// return left->depthInView > right->depthInView;
//}
2015-02-11 18:14:22 +08:00
PUParticle3DQuadRender* PUParticle3DQuadRender::create(const std::string& texFile)
{
2015-03-02 16:05:26 +08:00
auto ret = new (std::nothrow) PUParticle3DQuadRender();
2015-03-02 17:47:26 +08:00
if (ret && ret->initRender(texFile))
{
ret->autorelease();
}
else
{
CC_SAFE_DELETE(ret);
}
2015-02-11 18:14:22 +08:00
return ret;
}
void PUParticle3DQuadRender::render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem)
{
//batch and generate draw
const ParticlePool &particlePool = particleSystem->getParticlePool();
if (!_isVisible || particlePool.empty())
return;
if (_vertexBuffer == nullptr){
2015-03-02 13:07:32 +08:00
GLsizei stride = sizeof(VertexInfo);
2015-02-11 18:14:22 +08:00
_vertexBuffer = VertexBuffer::create(stride, 4 * particleSystem->getParticleQuota());
2015-03-03 11:42:15 +08:00
if (_vertexBuffer == nullptr)
{
CCLOG("PUParticle3DQuadRender::render create vertex buffer failed");
return;
}
2015-02-11 18:14:22 +08:00
_vertexBuffer->retain();
}
if (_indexBuffer == nullptr){
_indexBuffer = IndexBuffer::create(IndexBuffer::IndexType::INDEX_TYPE_SHORT_16, 6 * particleSystem->getParticleQuota());
2015-03-03 11:42:15 +08:00
if (_indexBuffer == nullptr)
{
CCLOG("PUParticle3DQuadRender::render create index buffer failed");
return;
}
2015-02-11 18:14:22 +08:00
_indexBuffer->retain();
}
2015-03-02 13:07:32 +08:00
const ParticlePool::PoolList &activeParticleList = particlePool.getActiveDataList();
if (_vertices.size() < activeParticleList.size() * 4)
2015-02-11 18:14:22 +08:00
{
2015-03-02 13:07:32 +08:00
_vertices.resize(activeParticleList.size() * 4);
_indices.resize(activeParticleList.size() * 6);
2015-02-11 18:14:22 +08:00
}
auto camera = Camera::getVisitingCamera();
auto cameraMat = camera->getNodeToWorldTransform();
//for (auto iter : activeParticleList){
// iter->depthInView = -(viewMat.m[2] * iter->positionInWorld.x + viewMat.m[6] * iter->positionInWorld.y + viewMat.m[10] * iter->positionInWorld.z + viewMat.m[14]);
//}
//std::sort(activeParticleList.begin(), activeParticleList.end(), compareParticle3D);
Vec3 right(cameraMat.m[0], cameraMat.m[1], cameraMat.m[2]);
Vec3 up(cameraMat.m[4], cameraMat.m[5], cameraMat.m[6]);
Vec3 backward(cameraMat.m[8], cameraMat.m[9], cameraMat.m[10]);
Mat4 pRotMat;
Vec3 position; //particle position
int vertexindex = 0;
int index = 0;
int offsetX,offsetY;
getOriginOffset(offsetX, offsetY);
if (_type == PERPENDICULAR_COMMON){
up = _commonUp;
up.normalize();
Vec3::cross(up, _commonDir, &right);
right.normalize();
backward = _commonDir;
}else if (_type == ORIENTED_COMMON){
up = _commonDir;
up.normalize();
Vec3::cross(up, backward, &right);
right.normalize();
}
for (auto iter : activeParticleList)
{
auto particle = static_cast<PUParticle3D *>(iter);
determineUVCoords(particle);
if (_type == ORIENTED_SELF){
2015-04-10 15:58:16 +08:00
Vec3 direction = particle->direction;
//transform.transformVector(particle->direction, &direction);
2015-02-11 18:14:22 +08:00
up = direction;
up.normalize();
Vec3::cross(direction, backward, &right);
right.normalize();
}else if (_type == PERPENDICULAR_SELF){
2015-04-10 15:58:16 +08:00
Vec3 direction = particle->direction;
//transform.transformVector(particle->direction, &direction);
2015-02-11 18:14:22 +08:00
direction.normalize();
2015-03-05 13:24:06 +08:00
//up = PUUtil::perpendicular(direction);
2015-02-11 18:14:22 +08:00
//up.normalize();
Vec3::cross(_commonUp, direction, &right);
right.normalize();
Vec3::cross(direction, right, &up);
up.normalize();
backward = direction;
}else if (_type == ORIENTED_SHAPE){
up.set(particle->orientation.x, particle->orientation.y, particle->orientation.z);
2015-02-11 18:14:22 +08:00
up.normalize();
Vec3::cross(up, backward, &right);
right.normalize();
}
2015-03-02 13:07:32 +08:00
Vec3 halfwidth = particle->width * 0.5f * right;
Vec3 halfheight = particle->height * 0.5f * up;
2015-02-11 18:14:22 +08:00
//transform.transformPoint(particle->position, &position);
2015-03-02 13:07:32 +08:00
position = particle->position;
2015-02-11 18:14:22 +08:00
if (_rotateType == TEXTURE_COORDS){
float costheta = cosf(-particle->zRotation);
float sintheta = sinf(-particle->zRotation);
Vec2 texOffset = particle->lb_uv + 0.5f * (particle->rt_uv - particle->lb_uv);
Vec2 val;
val.set((particle->lb_uv.x - texOffset.x), (particle->lb_uv.y - texOffset.y));
val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
2015-02-11 18:14:22 +08:00
fillVertex(vertexindex, (position + (- halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y));
val.set(particle->rt_uv.x - texOffset.x, particle->lb_uv.y - texOffset.y);
val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
2015-02-11 18:14:22 +08:00
fillVertex(vertexindex + 1, (position + (halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y));
val.set(particle->lb_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
2015-02-11 18:14:22 +08:00
fillVertex(vertexindex + 2, (position + (- halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y));
val.set(particle->rt_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
2015-02-11 18:14:22 +08:00
fillVertex(vertexindex + 3, (position + (halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(val.x + texOffset.x, val.y + texOffset.y));
}else{
Mat4::createRotation(backward, -particle->zRotation, &pRotMat);
fillVertex(vertexindex , (position + pRotMat * (- halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, particle->lb_uv);
fillVertex(vertexindex + 1, (position + pRotMat * (halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(particle->rt_uv.x, particle->lb_uv.y));
fillVertex(vertexindex + 2, (position + pRotMat * (- halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, Vec2(particle->lb_uv.x, particle->rt_uv.y));
fillVertex(vertexindex + 3, (position + pRotMat * (halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY)), particle->color, particle->rt_uv);
}
fillTriangle(index, vertexindex, vertexindex + 1, vertexindex + 3);
fillTriangle(index + 3, vertexindex, vertexindex + 3, vertexindex + 2);
//_posuvcolors[vertexindex].position = (position + (- halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY));
//_posuvcolors[vertexindex].color = particle->color;
//_posuvcolors[vertexindex].uv.set(val.x + texOffset.x, val.y + texOffset.y);
2015-02-11 18:14:22 +08:00
//val.set(particle->rt_uv.x - texOffset.x, particle->lb_uv.y - texOffset.y);
//val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
2015-02-11 18:14:22 +08:00
//_posuvcolors[vertexindex + 1].position = (position + (halfwidth - halfheight + halfwidth * offsetX + halfheight * offsetY));
//_posuvcolors[vertexindex + 1].color = particle->color;
//_posuvcolors[vertexindex + 1].uv.set(val.x + texOffset.x, val.y + texOffset.y);
2015-02-11 18:14:22 +08:00
//
//val.set(particle->lb_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
//val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
2015-02-11 18:14:22 +08:00
//_posuvcolors[vertexindex + 2].position = (position + (- halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY));
//_posuvcolors[vertexindex + 2].color = particle->color;
//_posuvcolors[vertexindex + 2].uv.set(val.x + texOffset.x, val.y + texOffset.y);
2015-02-11 18:14:22 +08:00
//
//val.set(particle->rt_uv.x - texOffset.x, particle->rt_uv.y - texOffset.y);
//val.set(val.x * costheta - val.y * sintheta, val.x * sintheta + val.y * costheta);
2015-02-11 18:14:22 +08:00
//_posuvcolors[vertexindex + 3].position = (position + (halfwidth + halfheight + halfwidth * offsetX + halfheight * offsetY));
//_posuvcolors[vertexindex + 3].color = particle->color;
//_posuvcolors[vertexindex + 3].uv.set(val.x + texOffset.x, val.y + texOffset.y);
2015-02-11 18:14:22 +08:00
//
//
//_indexData[index] = vertexindex;
//_indexData[index + 1] = vertexindex + 1;
//_indexData[index + 2] = vertexindex + 3;
//_indexData[index + 3] = vertexindex;
//_indexData[index + 4] = vertexindex + 3;
//_indexData[index + 5] = vertexindex + 2;
index += 6;
vertexindex += 4;
2015-03-02 13:07:32 +08:00
2015-02-11 18:14:22 +08:00
}
2015-03-02 13:07:32 +08:00
_vertices.erase(_vertices.begin() + vertexindex, _vertices.end());
_indices.erase(_indices.begin() + index, _indices.end());
2015-02-11 18:14:22 +08:00
2015-03-02 13:07:32 +08:00
if (!_vertices.empty() && !_indices.empty()){
_vertexBuffer->updateVertices(&_vertices[0], vertexindex/* * sizeof(_posuvcolors[0])*/, 0);
_indexBuffer->updateIndices(&_indices[0], index/* * sizeof(unsigned short)*/, 0);
GLuint texId = (_texture ? _texture->getName() : 0);
2015-03-04 09:57:42 +08:00
_meshCommand->init(0, texId, _glProgramState, particleSystem->getBlendFunc(), _vertexBuffer->getVBO(), _indexBuffer->getVBO(), GL_TRIANGLES, GL_UNSIGNED_SHORT, index, transform, Node::FLAGS_RENDER_AS_3D);
_meshCommand->setTransparent(true);
Squashed commit of the following: commit 3676fd8b4fe09be74fe10a6e2b8d6043cd016a2a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 11:46:57 2015 -0700 compiles on win32 commit 0b8d30a3f8b2656e714846a62ca8a94b303efbdc Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 11:01:04 2015 -0700 compiles on windows! commit 8cad22273ec2d9b74ef22196afcb8aa2f2bd8a6c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 10:20:13 2015 -0700 windows fix CALLBACK is defined in windows. Use CALLBACK_FN instead commit 33eff5c09c30e5ba6c8e61a69d1be0696d0b5d15 Merge: 17c5102 f843466 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 09:51:02 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 17c5102215e60c9e9b8b69ceb6b61b84b657ec91 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 17:05:49 2015 -0700 Material system works Ok. Deftaul states are being applyied to RenderState::StateBlock::_default state as well! commit 3f5285102ef95c77c505d0f2174f8f77b9bd86e1 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 15:52:09 2015 -0700 more fixes for material blending works as expected commit 347eaea42248eb07bc77844dcee56dcbcf0fbcb2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 12:14:00 2015 -0700 compiles on Android compiles on Android commit 5feef67410a6e8408414230887c177a5cc3d8c35 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 11:01:46 2015 -0700 Cmakefiles works with Cmake again commit 1366da20efd4f63f683ac9264e18aa71d84bcc71 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sat May 2 18:17:50 2015 -0700 Particle3D working Ok with its own uniforms commit c6cfa32e1f693e6d71d00e0cd9dd9610ca1e7663 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 1 17:32:00 2015 -0700 MeshCommand now works 100% on Material! commit 92d641e29675ffc58daba48fcdcc5ec6459be02f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 1 15:49:14 2015 -0700 multiple meshes work Ok commit 842927d18b5605b2fd1bd3a679fc25418c7eeab8 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 1 13:43:56 2015 -0700 Adds `clone` to GLProgramState commit c4b8e222f8e852254b1f23f0e17c16dfca7cc5ca Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 18:54:34 2015 -0700 adds comment about the glprogramstate bug commit 2d008ec90557025507e0b17284e60b39fc9b42d3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 18:28:39 2015 -0700 some uniforms moved to Material commit 11f59f87079a6cb698c7e9b5a55735f6d51cf420 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 16:52:07 2015 -0700 depth test moved to Material! commit 4dabb53641c293bfe8c417fe3491ec33b33ffc4e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 13:12:28 2015 -0700 Material/Technique/Pass subclass of RenderState Inheritance of RenderState. Code from GamePlay3D commit a8b888dc30cf7ab4fae186acec2a366dfb967116 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 12:05:26 2015 -0700 same as v3 commit c026de5318a2a03beed1de6d7a0efda431569a5c Merge: 4561e3f 254a4b0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 11:37:40 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 4561e3f5763849872d888a3be9ebbdcfb1a7bf9d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 18:02:21 2015 -0700 fixes on blending commit 1b4cd8fd1c7b2a489b6a52ab6d42548eb7c7fac0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 17:51:05 2015 -0700 better defaults for StateBlock commit 3a661c35908aa075754d7b9dfac45be1af3b38e9 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 17:46:36 2015 -0700 RenderState::bind() binds lots of states commit 074d5fb4a485e4ac32996c345e314594806e3cf0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 16:40:07 2015 -0700 Adds REnderState parsing in .material commit 7c0f098b7e2e198aa4a821bfbdec661eeba2587e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 16:06:31 2015 -0700 RenderState added into RenderState Code based on GamePlay3D. Adds GamePlay3d License. commit 04a6295ca5839e2e1202881b8a10733685c113d6 Merge: 52c916f 5671818 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 11:27:55 2015 -0700 Merge branch 'v3' into material_system commit 52c916fb4df04558433b1370102a5e9269f73607 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 18:15:12 2015 -0700 order files alphabetically order files alphabetically commit a5f54f0c1ca5d997a87e0231ce1b28d3c8d9ca64 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 17:46:07 2015 -0700 Adds cmake and android support commit 2432b1dd2ec3c7db78d4d9e5e7b9fbe491b95884 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 16:33:50 2015 -0700 for some reason the callback was crashing ... bug in the callback code? in any case, we didn't need it and it was making the code slower. commit 7844d32d04cb411ddae139d9598adcb04b899606 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 14:00:24 2015 -0700 more little fixes commit 2992a5e0f4a8dfac87d6aab37e101154f8b41519 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 12:11:28 2015 -0700 MeshCommand using Material internally works commit 67a435d66b4e554b4d24e462ca2ad42408157e69 Merge: 6dee7ca b9a994f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 10:34:03 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 6dee7cac6a51b4c123aabb111b0f8951082b1507 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 27 17:41:27 2015 -0700 improved readebility of MeshCommand code commit 3a57eb200f7cba4a17f512060dd3f121d83e32fd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 27 15:41:07 2015 -0700 mesh supports Material `Mesh` supports `Material` Now `MeshCommand` needs to implement it correctly. commit 2fc745c787555fbd5c6b100b0a2833ef0e65ad73 Merge: 05b16f5 bd5f4e0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 27 11:23:28 2015 -0700 Merge branch 'v3' into material_system commit 05b16f5c6f783ff38b4ae54528f9b949d8bb39a4 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 17:40:48 2015 -0700 Adding Material into Mesh WIP. commit bc62f1a146ff9ad9864d8ff317f6a9540760066a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 16:39:54 2015 -0700 cosmetic commit 2f86d50cee15c6af20abb512368aa36dc4ed3ccf Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 16:26:41 2015 -0700 moves even more code form Sprite3D to Mesh commit 04643bed3c277f0a775e962a5c87f550b1a59e74 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 16:15:21 2015 -0700 Moves "draw" from `Sprite3D` to `Mesh` commit 4bf884cdcb1a8df7522adeab364368493aba11e0 Merge: 2f305fc 2199bf1 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 15:00:50 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 2f305fc68ad847fd4bdf855611c6f6f6a4bf63d2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 14:46:28 2015 -0700 cosmetic commit a697b43a96e5f9440787aa2a1c4e178d98b2e5bc Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 23 16:44:21 2015 -0700 revert my changes... ...actually the GLProgramState code was Ok... ouch commit 36323c62eae2f8dbdcd7e13075758752cce44132 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 23 15:40:54 2015 -0700 parsing GLProgramState validates the attributes commit a406d6236a78244f73e81ded0b4148199a8677e5 Merge: 3be7fde cf177bb Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 23 12:10:31 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 3be7fdee9d88a14916b4f25b1c0b6f50cb619c04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 17:45:34 2015 -0700 little progress on Sprite3D + Material GLProgramState needs to decouple Uniforms from Attributes in `applyGLProgram`. binding the attributes is something that needs to be done at a different order. Perhaps the attributes are part of a VAO or something else. the method `applyAttributes()` has a variable to avoid that... but everything looks very hackish. commit f82496c61c9cb5a0787f883a4fb2d475889fa711 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 15:46:02 2015 -0700 doesn't crash :) but doesn't show anything either commit 0593fb09dc987aa2dd22af3a6c3aa8241fedfe5f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 13:35:45 2015 -0700 adding sprit3d test commit e716da63fe053b48db06f2aed9e0280256dd5f1b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 12:10:32 2015 -0700 MeshCommand: initial draw with Material commit d758041d81c3e6275997205e6395c46006bcc4ca Merge: 8cdc99f ca1a95f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 10:41:05 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 8cdc99fca664b0c9c2a536d431ffcc7844d69b3e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 21 21:57:28 2015 -0700 adding Material to MeshCommand commit 0121872709c5e584b9b9f102e0f8dfc9c836841b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 21 19:39:09 2015 -0700 pre commit before merging MeshCommand commit 06c0ac2a67e303bde98dff75ac436ec22de59263 Merge: 736feb1 0287b42 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 21 18:19:00 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 736feb1b6495b7411525afb130015bdb31b5c471 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 20 17:22:03 2015 -0700 Pass conforms to create()/init() pattern commit 6103ffbb8479681b6665e81f0572bc3287919d07 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 20 17:04:19 2015 -0700 defines are strings better error checking when creating objects autorelase added in Pass, Material, Technique commit 1efcbab63c7ca4259d50825144184baee1b577ac Merge: 5b233bc fd3e38b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 20 11:23:47 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 5b233bc879bd65123092d366257843465ec1d306 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 17 15:31:37 2015 -0700 blur effect works with alpha commit 836d3c4a0dcc3a363e1b0290e628b7ac2a973c89 Merge: e4c1dd2 425b2b6 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 17 15:04:35 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit e4c1dd23d8b28f2631efe30f6cc9da9eda4501bb Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 17 15:04:07 2015 -0700 Material, Technique, Pass: they have parent commit 7c3f258a1c9e4ff319db4e3eebfd39006d673d91 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 21:48:06 2015 -0700 multipass works commit b73ede73b72d8305f6f9d7898b4a5aa2336e9e32 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 17:31:04 2015 -0700 yeah! more materials... a lot to do yet commit d54d24ed185071ce1350bbf71914a64c9f6f228e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 17:06:46 2015 -0700 yeah! works! commit 1e70cb553148e6c136df42a789bf85184e73762d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 16:43:54 2015 -0700 simple test of material system works!!! commit c8581dfe9e970a3004254987416d75cccc644ccd Merge: 83aeec4 5d5fa3d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 13:51:45 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 83aeec41c7933ee46f5763ad64dcdc71a50885dc Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 15 18:04:23 2015 -0700 JSON file curated fixes minor bugs commit 35f669e7fad6257ff6e60023e95ec757fdfe23f5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 15 17:22:36 2015 -0700 parsers shaders! including uniforms commit 3f58bad0b2bc7ebbcfcf74e1eb02048f9d574340 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 14 23:24:18 2015 -0700 Material parses texture commit 1f678faf9d6c25f6405591f052da511281be8768 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 14 18:22:33 2015 -0700 material parsing almost working commit 9a79c45fe4d735a772d5e6d9e1f8bcb02546560d Merge: d0ff296 d54ddbd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 14 09:23:23 2015 -0700 Merge branch 'v3' into material_system commit d0ff2960f4f9edc4714f9d3edf921f3365d305c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 13 18:42:42 2015 -0700 json parsing broken ha... I need to parse the content of the file, to the name of the file. to be fixed tomorrow commit e5aab39e5774d997f848155fc7209e9fbbd03bbc Merge: 81e93fa bc34554 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 13 10:19:11 2015 -0700 Merge branch 'v3' into material_system commit 81e93faac9d80888e975ee19d7412c54daf439a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 17:41:12 2015 -0700 Adds more dummy files for material commit 5552a1e099bcf960d962c5369973ea663f802895 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 17:01:16 2015 -0700 adds empty test commit 7027c85fb24109f1ed4c50877dbec35618b5b39c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 15:36:24 2015 -0700 more material fixes multiple passes added in renderer commit db6745ead9879c6ce66b1921f32bf927421c54d9 Merge: 58d2412 8a160d7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 11:52:30 2015 -0700 Merge branch 'v3' into material_system commit 58d241266bdbd88162bb7ae9a7e868af173e6375 Merge: 0eccb23 b409f20 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 15:42:35 2015 -0700 Merge branch 'v3' into material_system commit 0eccb236aa933eb471416258c5bb55a7ca3a24f0 Merge: 83494de 967f35a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 15:18:34 2015 -0700 Merge branch 'cpp_compiles_on_mac' into material_system commit 83494dedd0f4e7092f0267187cf07bd7de7723c2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 15:09:59 2015 -0700 compiles on Mac commit cca5b060164182b67df21fa330dce938e17fb324 Merge: dfc3740 09c50c4 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 13:54:59 2015 -0700 Merge branch 'v3' into material_system commit dfc374099ca02e547478d24fa8fd61817a85862c Merge: fa2152b 64c45fa Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 8 14:16:27 2015 -0700 Merge branch 'v3' into material_system commit fa2152b3402e3519d35f98309c4acc03b6790370 Merge: 90b7b6f b648d1f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 3 10:15:28 2015 +0800 Merge branch 'v3' into material_system commit 90b7b6f6540edff156e22fdf38021a5c83194deb Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 3 10:13:24 2015 +0800 little changes to pass commit 7f8b83017f03572a3698f431b6af497d62fcfa25 Merge: 7460614 0779d05 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 2 08:36:43 2015 +0800 Merge branch 'v3' into material_system commit 7460614dd8b7eff5d8c759be54dd205333b26033 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 2 08:23:17 2015 +0800 small changes commit fa0354e74983795adafad3bedc9c50f6e8e328c9 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Mar 26 18:20:46 2015 -0700 initial Material system
2015-05-06 04:07:32 +08:00
_glProgramState->setUniformVec4("u_color", Vec4(1,1,1,1));
2015-03-02 13:07:32 +08:00
renderer->addCommand(_meshCommand);
}
2015-02-11 18:14:22 +08:00
}
PUParticle3DQuadRender::PUParticle3DQuadRender()
: _type(POINT)
, _origin(CENTER)
, _rotateType(TEXTURE_COORDS)
, _commonDir(Vec3(0.0f, 0.0f, 1.0f))
, _commonUp(Vec3(0.0f, 1.0f, 0.0f))
, _textureCoordsRows(1)
, _textureCoordsColumns(1)
, _textureCoordsRowStep(1.0f)
, _textureCoordsColStep(1.0f)
{
2015-03-02 13:07:32 +08:00
autoRotate = false;
2015-02-11 18:14:22 +08:00
}
PUParticle3DQuadRender::~PUParticle3DQuadRender()
{
}
void PUParticle3DQuadRender::getOriginOffset( int &offsetX, int &offsetY )
{
switch (_origin)
{
case TOP_LEFT:
{
offsetX = 1;
offsetY = -1;
}
break;
case TOP_CENTER:
{
offsetX = 0;
offsetY = -1;
}
break;
case TOP_RIGHT:
{
offsetX = -1;
offsetY = -1;
}
break;
case CENTER_LEFT:
{
offsetX = 1;
offsetY = 0;
}
break;
case CENTER:
{
offsetX = 0;
offsetY = 0;
}
break;
case CENTER_RIGHT:
{
offsetX = -1;
offsetY = 0;
}
break;
case BOTTOM_LEFT:
{
offsetX = 1;
offsetY = 1;
}
break;
case BOTTOM_CENTER:
{
offsetX = 0;
offsetY = 1;
}
break;
case BOTTOM_RIGHT:
{
offsetX = -1;
offsetY = 1;
}
break;
}
}
unsigned short PUParticle3DQuadRender::getTextureCoordsRows() const
{
return _textureCoordsRows;
}
void PUParticle3DQuadRender::setTextureCoordsRows( unsigned short textureCoordsRows )
{
_textureCoordsRows = textureCoordsRows;
_textureCoordsRowStep = 1.0f / (float)_textureCoordsRows;
}
unsigned short PUParticle3DQuadRender::getTextureCoordsColumns() const
{
return _textureCoordsColumns;
}
void PUParticle3DQuadRender::setTextureCoordsColumns( unsigned short textureCoordsColumns )
{
_textureCoordsColumns = textureCoordsColumns;
_textureCoordsColStep = 1.0f / (float)_textureCoordsColumns;
}
unsigned int PUParticle3DQuadRender::getNumTextureCoords()
{
return _textureCoordsColumns * _textureCoordsRows;
}
void PUParticle3DQuadRender::determineUVCoords( PUParticle3D *particle )
{
if (_textureCoordsColumns == 1 && _textureCoordsRows == 1) return;
unsigned short currentRow = particle->textureCoordsCurrent / _textureCoordsColumns;
unsigned short currentCol = particle->textureCoordsCurrent - _textureCoordsColumns * currentRow;
currentRow = _textureCoordsRows - currentRow - 1;
particle->lb_uv.set(_textureCoordsColStep * currentCol, _textureCoordsRowStep * currentRow);
2015-02-11 18:14:22 +08:00
particle->rt_uv = particle->lb_uv + Vec2(_textureCoordsColStep, _textureCoordsRowStep);
}
void PUParticle3DQuadRender::fillVertex( unsigned short index, const Vec3 &pos, const Vec4 &color, const Vec2 &uv )
2015-02-11 18:14:22 +08:00
{
2015-03-02 13:07:32 +08:00
_vertices[index].position = pos;
_vertices[index].color = color;
_vertices[index].uv = uv;
2015-02-11 18:14:22 +08:00
}
void PUParticle3DQuadRender::fillTriangle( unsigned short index, unsigned short v0, unsigned short v1, unsigned short v2 )
{
2015-03-02 13:07:32 +08:00
_indices[index] = v0;
_indices[index + 1] = v1;
_indices[index + 2] = v2;
2015-02-11 18:14:22 +08:00
}
void PUParticle3DQuadRender::setType( Type type )
{
_type = type;
if (_type == PERPENDICULAR_COMMON || _type == PERPENDICULAR_SELF){
_meshCommand->setCullFaceEnabled(false);
}else{
_meshCommand->setCullFaceEnabled(true);
}
}
2015-03-05 13:24:06 +08:00
void PUParticle3DQuadRender::copyAttributesTo( PURender *render )
2015-03-02 13:07:32 +08:00
{
2015-03-05 13:24:06 +08:00
PURender::copyAttributesTo(render);
2015-03-02 13:07:32 +08:00
PUParticle3DQuadRender *quadRender = static_cast<PUParticle3DQuadRender *>(render);
quadRender->_type = _type;
quadRender->_origin = _origin;
quadRender->_rotateType = _rotateType;
quadRender->_commonDir = _commonDir;
quadRender->_commonUp = _commonUp;
quadRender->_textureCoordsRows = _textureCoordsRows;
quadRender->_textureCoordsColumns = _textureCoordsColumns;
quadRender->_textureCoordsRowStep = _textureCoordsRowStep;
quadRender->_textureCoordsColStep = _textureCoordsColStep;
}
PUParticle3DQuadRender* PUParticle3DQuadRender::clone()
{
auto render = PUParticle3DQuadRender::create(_texFile);
copyAttributesTo(render);
return render;
}
2015-02-11 18:14:22 +08:00
PUParticle3DModelRender* PUParticle3DModelRender::create( const std::string& modelFile, const std::string &texFile /*= ""*/ )
{
2015-03-02 16:05:26 +08:00
auto ret = new (std::nothrow) PUParticle3DModelRender();
2015-02-11 18:14:22 +08:00
ret->_modelFile = modelFile;
ret->_texFile = texFile;
return ret;
}
void PUParticle3DModelRender::render( Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem )
{
if (!_isVisible)
return;
if (_spriteList.empty()){
for (unsigned int i = 0; i < particleSystem->getParticleQuota(); ++i){
2015-03-02 13:07:32 +08:00
Sprite3D *sprite = Sprite3D::create(_modelFile);
if (sprite == nullptr)
{
CCLOG("failed to load file %s", _modelFile.c_str());
continue;
}
2015-02-11 18:14:22 +08:00
sprite->setTexture(_texFile);
sprite->retain();
_spriteList.push_back(sprite);
}
if (!_spriteList.empty()){
const AABB &aabb = _spriteList[0]->getAABB();
Vec3 corners[8];
aabb.getCorners(corners);
_spriteSize = corners[3] - corners[6];
2015-03-04 13:19:42 +08:00
}else{
_isVisible = false;
return;
2015-02-11 18:14:22 +08:00
}
}
const ParticlePool& particlePool = particleSystem->getParticlePool();
2015-03-02 13:07:32 +08:00
ParticlePool::PoolList activeParticleList = particlePool.getActiveDataList();
2015-02-11 18:14:22 +08:00
Mat4 mat;
Mat4 rotMat;
Mat4 sclMat;
Quaternion q;
transform.decompose(nullptr, &q, nullptr);
2015-03-02 13:07:32 +08:00
unsigned int index = 0;
for (auto iter : activeParticleList)
2015-02-11 18:14:22 +08:00
{
2015-03-02 13:07:32 +08:00
auto particle = static_cast<PUParticle3D *>(iter);
2015-04-03 12:43:14 +08:00
Mat4::createRotation(q * particle->orientation, &rotMat);
2015-03-02 13:07:32 +08:00
sclMat.m[0] = particle->width / _spriteSize.x;
sclMat.m[5] = particle->height / _spriteSize.y;
sclMat.m[10] = particle->depth / _spriteSize.z;
2015-02-11 18:14:22 +08:00
mat = rotMat * sclMat;
2015-03-02 13:07:32 +08:00
mat.m[12] = particle->position.x;
mat.m[13] = particle->position.y;
mat.m[14] = particle->position.z;
_spriteList[index]->setColor(Color3B(particle->color.x * 255, particle->color.y * 255, particle->color.z * 255));
_spriteList[index]->setOpacity(particle->color.w * 255);
_spriteList[index]->draw(renderer, mat, 0);
++index;
2015-02-11 18:14:22 +08:00
}
}
PUParticle3DModelRender::PUParticle3DModelRender()
{
2015-03-02 13:07:32 +08:00
autoRotate = true;
2015-02-11 18:14:22 +08:00
}
PUParticle3DModelRender::~PUParticle3DModelRender()
{
for (auto iter : _spriteList){
iter->release();
}
2015-03-02 13:07:32 +08:00
}
2015-03-05 13:24:06 +08:00
void PUParticle3DModelRender::copyAttributesTo( PURender *render )
2015-03-02 13:07:32 +08:00
{
2015-03-05 13:24:06 +08:00
PURender::copyAttributesTo(render);
2015-03-02 13:07:32 +08:00
}
PUParticle3DModelRender* PUParticle3DModelRender::clone()
{
auto mr = PUParticle3DModelRender::create(_modelFile, _texFile);
copyAttributesTo(mr);
return mr;
}
PUParticle3DEntityRender::PUParticle3DEntityRender()
: _meshCommand(nullptr)
, _texture(nullptr)
, _glProgramState(nullptr)
, _indexBuffer(nullptr)
, _vertexBuffer(nullptr)
2015-03-02 13:07:32 +08:00
{
}
PUParticle3DEntityRender::~PUParticle3DEntityRender()
{
CC_SAFE_DELETE(_meshCommand);
//CC_SAFE_RELEASE(_texture);
CC_SAFE_RELEASE(_glProgramState);
CC_SAFE_RELEASE(_vertexBuffer);
CC_SAFE_RELEASE(_indexBuffer);
}
2015-03-02 17:47:26 +08:00
bool PUParticle3DEntityRender::initRender( const std::string &texFile )
2015-03-02 13:07:32 +08:00
{
GLProgram* glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_PARTICLE_COLOR);
if (!texFile.empty())
{
auto tex = Director::getInstance()->getTextureCache()->addImage(texFile);
if (tex)
{
_texture = tex;
_texFile = texFile;
glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_3D_PARTICLE_TEXTURE);
}
}
2015-03-02 13:07:32 +08:00
auto glProgramState = GLProgramState::create(glProgram);
glProgramState->retain();
GLsizei stride = sizeof(VertexInfo);
glProgramState->setVertexAttribPointer(s_attributeNames[GLProgram::VERTEX_ATTRIB_POSITION], 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)offsetof(VertexInfo, position));
glProgramState->setVertexAttribPointer(s_attributeNames[GLProgram::VERTEX_ATTRIB_TEX_COORD], 2, GL_FLOAT, GL_FALSE, stride, (GLvoid*)offsetof(VertexInfo, uv));
glProgramState->setVertexAttribPointer(s_attributeNames[GLProgram::VERTEX_ATTRIB_COLOR], 4, GL_FLOAT, GL_FALSE, stride, (GLvoid*)offsetof(VertexInfo, color));
_glProgramState = glProgramState;
2015-03-02 16:05:26 +08:00
_meshCommand = new (std::nothrow) MeshCommand();
2015-03-02 13:07:32 +08:00
_meshCommand->setTransparent(true);
_meshCommand->setDepthTestEnabled(_depthTest);
_meshCommand->setDepthWriteEnabled(_depthWrite);
_meshCommand->setCullFace(GL_BACK);
_meshCommand->setCullFaceEnabled(true);
2015-03-02 17:47:26 +08:00
return true;
2015-03-02 13:07:32 +08:00
}
void PUParticle3DEntityRender::setDepthTest( bool isDepthTest )
{
Particle3DRender::setDepthTest(isDepthTest);
_meshCommand->setDepthTestEnabled(_depthTest);
}
void PUParticle3DEntityRender::setDepthWrite( bool isDepthWrite )
{
Particle3DRender::setDepthWrite(isDepthWrite);
_meshCommand->setDepthWriteEnabled(_depthWrite);
}
2015-03-05 13:24:06 +08:00
void PUParticle3DEntityRender::copyAttributesTo( PURender *render )
2015-03-02 13:07:32 +08:00
{
2015-03-05 13:24:06 +08:00
PURender::copyAttributesTo(render);
2015-03-02 13:07:32 +08:00
}
PUParticle3DBoxRender::PUParticle3DBoxRender()
{
autoRotate = false;
}
PUParticle3DBoxRender::~PUParticle3DBoxRender()
{
}
PUParticle3DBoxRender* PUParticle3DBoxRender::create( const std::string &texFile )
{
2015-03-02 17:47:26 +08:00
auto ret = new (std::nothrow) PUParticle3DBoxRender();
if (ret && ret->initRender(texFile))
{
ret->autorelease();
}
else
{
CC_SAFE_DELETE(ret);
}
return ret;
2015-03-02 13:07:32 +08:00
}
void PUParticle3DBoxRender::render( Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem )
{
//batch and generate draw
const ParticlePool &particlePool = particleSystem->getParticlePool();
if (!_isVisible || particlePool.empty())
return;
auto camera = Camera::getVisitingCamera();
auto cameraMat = camera->getNodeToWorldTransform();
Vec3 backward(cameraMat.m[8], cameraMat.m[9], cameraMat.m[10]);
if (_vertexBuffer == nullptr && _indexBuffer == nullptr){
GLsizei stride = sizeof(VertexInfo);
_vertexBuffer = VertexBuffer::create(stride, 8 * particleSystem->getParticleQuota());
2015-03-03 11:42:15 +08:00
if (_vertexBuffer == nullptr)
{
CCLOG("PUParticle3DBoxRender::render create vertex buffer failed");
return;
}
2015-03-02 13:07:32 +08:00
_vertexBuffer->retain();
_vertices.resize(8 * particleSystem->getParticleQuota());
_indexBuffer = IndexBuffer::create(IndexBuffer::IndexType::INDEX_TYPE_SHORT_16, 36 * particleSystem->getParticleQuota());
2015-03-03 11:42:15 +08:00
if (_indexBuffer == nullptr)
{
CCLOG("PUParticle3DBoxRender::render create index buffer failed");
return;
}
2015-03-02 13:07:32 +08:00
_indexBuffer->retain();
_indices.resize(36 * particleSystem->getParticleQuota());
reBuildIndices(particleSystem->getParticleQuota());
}
unsigned int vertexindex = 0;
unsigned int index = 0;
Mat4 texRot;
Vec3 val;
for (auto iter : particlePool.getActiveDataList())
{
auto particle = static_cast<PUParticle3D *>(iter);
float halfHeight = particle->height * 0.5f;
float halfWidth = particle->width * 0.5f;
float halfDepth = particle->depth * 0.5f;
Mat4::createRotation(backward, particle->zRotation, &texRot);
val = texRot * Vec3(0.0f, 0.75f, 0.0);
_vertices[vertexindex + 0].position = particle->position + Vec3(-halfWidth, -halfHeight, halfDepth);
_vertices[vertexindex + 0].color = particle->color;
_vertices[vertexindex + 0].uv.x = val.x; _vertices[vertexindex + 0].uv.y = val.y;
val = texRot * Vec3(0.0f, 0.25f, 0.0);
_vertices[vertexindex + 1].position = particle->position + Vec3(halfWidth, -halfHeight, halfDepth);
_vertices[vertexindex + 1].color = particle->color;
_vertices[vertexindex + 1].uv.x = val.x; _vertices[vertexindex + 1].uv.y = val.y;
val = texRot * Vec3(0.5f, 0.25f, 0.0);
_vertices[vertexindex + 2].position = particle->position + Vec3(halfWidth, halfHeight, halfDepth);
_vertices[vertexindex + 2].color = particle->color;
_vertices[vertexindex + 2].uv.x = val.x; _vertices[vertexindex + 2].uv.y = val.y;
val = texRot * Vec3(0.5f, 0.75f, 0.0);
_vertices[vertexindex + 3].position = particle->position + Vec3(-halfWidth, halfHeight, halfDepth);
_vertices[vertexindex + 3].color = particle->color;
_vertices[vertexindex + 3].uv.x = val.x; _vertices[vertexindex + 3].uv.y = val.y;
val = texRot * Vec3(0.0f, 0.0f, 0.0);
_vertices[vertexindex + 4].position = particle->position + Vec3(halfWidth, -halfHeight, -halfDepth);
_vertices[vertexindex + 4].color = particle->color;
_vertices[vertexindex + 4].uv.x = val.x; _vertices[vertexindex + 4].uv.y = val.y;
val = texRot * Vec3(0.0f, 1.0f, 0.0);
_vertices[vertexindex + 5].position = particle->position + Vec3(-halfWidth, -halfHeight, -halfDepth);
_vertices[vertexindex + 5].color = particle->color;
_vertices[vertexindex + 5].uv.x = val.x; _vertices[vertexindex + 5].uv.y = val.y;
val = texRot * Vec3(0.5f, 1.0f, 0.0);
_vertices[vertexindex + 6].position = particle->position + Vec3(-halfWidth, halfHeight, -halfDepth);
_vertices[vertexindex + 6].color = particle->color;
_vertices[vertexindex + 6].uv.x = val.x; _vertices[vertexindex + 6].uv.y = val.y;
val = texRot * Vec3(0.5f, 0.0f, 0.0);
_vertices[vertexindex + 7].position = particle->position + Vec3(halfWidth, halfHeight, -halfDepth);
_vertices[vertexindex + 7].color = particle->color;
_vertices[vertexindex + 7].uv.x = val.x; _vertices[vertexindex + 7].uv.y = val.y;
vertexindex += 8;
index += 36;
}
if (!_vertices.empty() && !_indices.empty()){
_vertexBuffer->updateVertices(&_vertices[0], vertexindex/* * sizeof(_posuvcolors[0])*/, 0);
_indexBuffer->updateIndices(&_indices[0], index/* * sizeof(unsigned short)*/, 0);
GLuint texId = (_texture ? _texture->getName() : 0);
2015-03-04 10:10:33 +08:00
_meshCommand->init(0, texId, _glProgramState, particleSystem->getBlendFunc(), _vertexBuffer->getVBO(), _indexBuffer->getVBO(), GL_TRIANGLES, GL_UNSIGNED_SHORT, index, transform, Node::FLAGS_RENDER_AS_3D);
_meshCommand->setTransparent(true);
Squashed commit of the following: commit 3676fd8b4fe09be74fe10a6e2b8d6043cd016a2a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 11:46:57 2015 -0700 compiles on win32 commit 0b8d30a3f8b2656e714846a62ca8a94b303efbdc Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 11:01:04 2015 -0700 compiles on windows! commit 8cad22273ec2d9b74ef22196afcb8aa2f2bd8a6c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 10:20:13 2015 -0700 windows fix CALLBACK is defined in windows. Use CALLBACK_FN instead commit 33eff5c09c30e5ba6c8e61a69d1be0696d0b5d15 Merge: 17c5102 f843466 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 09:51:02 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 17c5102215e60c9e9b8b69ceb6b61b84b657ec91 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 17:05:49 2015 -0700 Material system works Ok. Deftaul states are being applyied to RenderState::StateBlock::_default state as well! commit 3f5285102ef95c77c505d0f2174f8f77b9bd86e1 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 15:52:09 2015 -0700 more fixes for material blending works as expected commit 347eaea42248eb07bc77844dcee56dcbcf0fbcb2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 12:14:00 2015 -0700 compiles on Android compiles on Android commit 5feef67410a6e8408414230887c177a5cc3d8c35 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 11:01:46 2015 -0700 Cmakefiles works with Cmake again commit 1366da20efd4f63f683ac9264e18aa71d84bcc71 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sat May 2 18:17:50 2015 -0700 Particle3D working Ok with its own uniforms commit c6cfa32e1f693e6d71d00e0cd9dd9610ca1e7663 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 1 17:32:00 2015 -0700 MeshCommand now works 100% on Material! commit 92d641e29675ffc58daba48fcdcc5ec6459be02f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 1 15:49:14 2015 -0700 multiple meshes work Ok commit 842927d18b5605b2fd1bd3a679fc25418c7eeab8 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 1 13:43:56 2015 -0700 Adds `clone` to GLProgramState commit c4b8e222f8e852254b1f23f0e17c16dfca7cc5ca Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 18:54:34 2015 -0700 adds comment about the glprogramstate bug commit 2d008ec90557025507e0b17284e60b39fc9b42d3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 18:28:39 2015 -0700 some uniforms moved to Material commit 11f59f87079a6cb698c7e9b5a55735f6d51cf420 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 16:52:07 2015 -0700 depth test moved to Material! commit 4dabb53641c293bfe8c417fe3491ec33b33ffc4e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 13:12:28 2015 -0700 Material/Technique/Pass subclass of RenderState Inheritance of RenderState. Code from GamePlay3D commit a8b888dc30cf7ab4fae186acec2a366dfb967116 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 12:05:26 2015 -0700 same as v3 commit c026de5318a2a03beed1de6d7a0efda431569a5c Merge: 4561e3f 254a4b0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 11:37:40 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 4561e3f5763849872d888a3be9ebbdcfb1a7bf9d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 18:02:21 2015 -0700 fixes on blending commit 1b4cd8fd1c7b2a489b6a52ab6d42548eb7c7fac0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 17:51:05 2015 -0700 better defaults for StateBlock commit 3a661c35908aa075754d7b9dfac45be1af3b38e9 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 17:46:36 2015 -0700 RenderState::bind() binds lots of states commit 074d5fb4a485e4ac32996c345e314594806e3cf0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 16:40:07 2015 -0700 Adds REnderState parsing in .material commit 7c0f098b7e2e198aa4a821bfbdec661eeba2587e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 16:06:31 2015 -0700 RenderState added into RenderState Code based on GamePlay3D. Adds GamePlay3d License. commit 04a6295ca5839e2e1202881b8a10733685c113d6 Merge: 52c916f 5671818 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 11:27:55 2015 -0700 Merge branch 'v3' into material_system commit 52c916fb4df04558433b1370102a5e9269f73607 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 18:15:12 2015 -0700 order files alphabetically order files alphabetically commit a5f54f0c1ca5d997a87e0231ce1b28d3c8d9ca64 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 17:46:07 2015 -0700 Adds cmake and android support commit 2432b1dd2ec3c7db78d4d9e5e7b9fbe491b95884 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 16:33:50 2015 -0700 for some reason the callback was crashing ... bug in the callback code? in any case, we didn't need it and it was making the code slower. commit 7844d32d04cb411ddae139d9598adcb04b899606 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 14:00:24 2015 -0700 more little fixes commit 2992a5e0f4a8dfac87d6aab37e101154f8b41519 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 12:11:28 2015 -0700 MeshCommand using Material internally works commit 67a435d66b4e554b4d24e462ca2ad42408157e69 Merge: 6dee7ca b9a994f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 10:34:03 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 6dee7cac6a51b4c123aabb111b0f8951082b1507 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 27 17:41:27 2015 -0700 improved readebility of MeshCommand code commit 3a57eb200f7cba4a17f512060dd3f121d83e32fd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 27 15:41:07 2015 -0700 mesh supports Material `Mesh` supports `Material` Now `MeshCommand` needs to implement it correctly. commit 2fc745c787555fbd5c6b100b0a2833ef0e65ad73 Merge: 05b16f5 bd5f4e0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 27 11:23:28 2015 -0700 Merge branch 'v3' into material_system commit 05b16f5c6f783ff38b4ae54528f9b949d8bb39a4 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 17:40:48 2015 -0700 Adding Material into Mesh WIP. commit bc62f1a146ff9ad9864d8ff317f6a9540760066a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 16:39:54 2015 -0700 cosmetic commit 2f86d50cee15c6af20abb512368aa36dc4ed3ccf Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 16:26:41 2015 -0700 moves even more code form Sprite3D to Mesh commit 04643bed3c277f0a775e962a5c87f550b1a59e74 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 16:15:21 2015 -0700 Moves "draw" from `Sprite3D` to `Mesh` commit 4bf884cdcb1a8df7522adeab364368493aba11e0 Merge: 2f305fc 2199bf1 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 15:00:50 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 2f305fc68ad847fd4bdf855611c6f6f6a4bf63d2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 14:46:28 2015 -0700 cosmetic commit a697b43a96e5f9440787aa2a1c4e178d98b2e5bc Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 23 16:44:21 2015 -0700 revert my changes... ...actually the GLProgramState code was Ok... ouch commit 36323c62eae2f8dbdcd7e13075758752cce44132 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 23 15:40:54 2015 -0700 parsing GLProgramState validates the attributes commit a406d6236a78244f73e81ded0b4148199a8677e5 Merge: 3be7fde cf177bb Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 23 12:10:31 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 3be7fdee9d88a14916b4f25b1c0b6f50cb619c04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 17:45:34 2015 -0700 little progress on Sprite3D + Material GLProgramState needs to decouple Uniforms from Attributes in `applyGLProgram`. binding the attributes is something that needs to be done at a different order. Perhaps the attributes are part of a VAO or something else. the method `applyAttributes()` has a variable to avoid that... but everything looks very hackish. commit f82496c61c9cb5a0787f883a4fb2d475889fa711 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 15:46:02 2015 -0700 doesn't crash :) but doesn't show anything either commit 0593fb09dc987aa2dd22af3a6c3aa8241fedfe5f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 13:35:45 2015 -0700 adding sprit3d test commit e716da63fe053b48db06f2aed9e0280256dd5f1b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 12:10:32 2015 -0700 MeshCommand: initial draw with Material commit d758041d81c3e6275997205e6395c46006bcc4ca Merge: 8cdc99f ca1a95f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 10:41:05 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 8cdc99fca664b0c9c2a536d431ffcc7844d69b3e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 21 21:57:28 2015 -0700 adding Material to MeshCommand commit 0121872709c5e584b9b9f102e0f8dfc9c836841b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 21 19:39:09 2015 -0700 pre commit before merging MeshCommand commit 06c0ac2a67e303bde98dff75ac436ec22de59263 Merge: 736feb1 0287b42 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 21 18:19:00 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 736feb1b6495b7411525afb130015bdb31b5c471 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 20 17:22:03 2015 -0700 Pass conforms to create()/init() pattern commit 6103ffbb8479681b6665e81f0572bc3287919d07 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 20 17:04:19 2015 -0700 defines are strings better error checking when creating objects autorelase added in Pass, Material, Technique commit 1efcbab63c7ca4259d50825144184baee1b577ac Merge: 5b233bc fd3e38b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 20 11:23:47 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 5b233bc879bd65123092d366257843465ec1d306 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 17 15:31:37 2015 -0700 blur effect works with alpha commit 836d3c4a0dcc3a363e1b0290e628b7ac2a973c89 Merge: e4c1dd2 425b2b6 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 17 15:04:35 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit e4c1dd23d8b28f2631efe30f6cc9da9eda4501bb Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 17 15:04:07 2015 -0700 Material, Technique, Pass: they have parent commit 7c3f258a1c9e4ff319db4e3eebfd39006d673d91 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 21:48:06 2015 -0700 multipass works commit b73ede73b72d8305f6f9d7898b4a5aa2336e9e32 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 17:31:04 2015 -0700 yeah! more materials... a lot to do yet commit d54d24ed185071ce1350bbf71914a64c9f6f228e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 17:06:46 2015 -0700 yeah! works! commit 1e70cb553148e6c136df42a789bf85184e73762d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 16:43:54 2015 -0700 simple test of material system works!!! commit c8581dfe9e970a3004254987416d75cccc644ccd Merge: 83aeec4 5d5fa3d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 13:51:45 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 83aeec41c7933ee46f5763ad64dcdc71a50885dc Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 15 18:04:23 2015 -0700 JSON file curated fixes minor bugs commit 35f669e7fad6257ff6e60023e95ec757fdfe23f5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 15 17:22:36 2015 -0700 parsers shaders! including uniforms commit 3f58bad0b2bc7ebbcfcf74e1eb02048f9d574340 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 14 23:24:18 2015 -0700 Material parses texture commit 1f678faf9d6c25f6405591f052da511281be8768 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 14 18:22:33 2015 -0700 material parsing almost working commit 9a79c45fe4d735a772d5e6d9e1f8bcb02546560d Merge: d0ff296 d54ddbd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 14 09:23:23 2015 -0700 Merge branch 'v3' into material_system commit d0ff2960f4f9edc4714f9d3edf921f3365d305c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 13 18:42:42 2015 -0700 json parsing broken ha... I need to parse the content of the file, to the name of the file. to be fixed tomorrow commit e5aab39e5774d997f848155fc7209e9fbbd03bbc Merge: 81e93fa bc34554 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 13 10:19:11 2015 -0700 Merge branch 'v3' into material_system commit 81e93faac9d80888e975ee19d7412c54daf439a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 17:41:12 2015 -0700 Adds more dummy files for material commit 5552a1e099bcf960d962c5369973ea663f802895 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 17:01:16 2015 -0700 adds empty test commit 7027c85fb24109f1ed4c50877dbec35618b5b39c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 15:36:24 2015 -0700 more material fixes multiple passes added in renderer commit db6745ead9879c6ce66b1921f32bf927421c54d9 Merge: 58d2412 8a160d7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 11:52:30 2015 -0700 Merge branch 'v3' into material_system commit 58d241266bdbd88162bb7ae9a7e868af173e6375 Merge: 0eccb23 b409f20 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 15:42:35 2015 -0700 Merge branch 'v3' into material_system commit 0eccb236aa933eb471416258c5bb55a7ca3a24f0 Merge: 83494de 967f35a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 15:18:34 2015 -0700 Merge branch 'cpp_compiles_on_mac' into material_system commit 83494dedd0f4e7092f0267187cf07bd7de7723c2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 15:09:59 2015 -0700 compiles on Mac commit cca5b060164182b67df21fa330dce938e17fb324 Merge: dfc3740 09c50c4 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 13:54:59 2015 -0700 Merge branch 'v3' into material_system commit dfc374099ca02e547478d24fa8fd61817a85862c Merge: fa2152b 64c45fa Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 8 14:16:27 2015 -0700 Merge branch 'v3' into material_system commit fa2152b3402e3519d35f98309c4acc03b6790370 Merge: 90b7b6f b648d1f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 3 10:15:28 2015 +0800 Merge branch 'v3' into material_system commit 90b7b6f6540edff156e22fdf38021a5c83194deb Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 3 10:13:24 2015 +0800 little changes to pass commit 7f8b83017f03572a3698f431b6af497d62fcfa25 Merge: 7460614 0779d05 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 2 08:36:43 2015 +0800 Merge branch 'v3' into material_system commit 7460614dd8b7eff5d8c759be54dd205333b26033 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 2 08:23:17 2015 +0800 small changes commit fa0354e74983795adafad3bedc9c50f6e8e328c9 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Mar 26 18:20:46 2015 -0700 initial Material system
2015-05-06 04:07:32 +08:00
_glProgramState->setUniformVec4("u_color", Vec4(1,1,1,1));
2015-03-02 13:07:32 +08:00
renderer->addCommand(_meshCommand);
}
}
void PUParticle3DBoxRender::reBuildIndices(unsigned short count)
{
unsigned short vertexIndex = 0;
for (unsigned short i = 0; i < 36 * count;){
//front
_indices[i++] = vertexIndex + 0;
_indices[i++] = vertexIndex + 2;
_indices[i++] = vertexIndex + 3;
_indices[i++] = vertexIndex + 0;
_indices[i++] = vertexIndex + 1;
_indices[i++] = vertexIndex + 2;
//right
_indices[i++] = vertexIndex + 1;
_indices[i++] = vertexIndex + 7;
_indices[i++] = vertexIndex + 2;
_indices[i++] = vertexIndex + 1;
_indices[i++] = vertexIndex + 4;
_indices[i++] = vertexIndex + 7;
//back
_indices[i++] = vertexIndex + 4;
_indices[i++] = vertexIndex + 6;
_indices[i++] = vertexIndex + 7;
_indices[i++] = vertexIndex + 4;
_indices[i++] = vertexIndex + 5;
_indices[i++] = vertexIndex + 6;
//left
_indices[i++] = vertexIndex + 5;
_indices[i++] = vertexIndex + 3;
_indices[i++] = vertexIndex + 6;
_indices[i++] = vertexIndex + 5;
_indices[i++] = vertexIndex + 0;
_indices[i++] = vertexIndex + 3;
//top
_indices[i++] = vertexIndex + 3;
_indices[i++] = vertexIndex + 7;
_indices[i++] = vertexIndex + 6;
_indices[i++] = vertexIndex + 3;
_indices[i++] = vertexIndex + 2;
_indices[i++] = vertexIndex + 7;
//bottom
_indices[i++] = vertexIndex + 5;
_indices[i++] = vertexIndex + 1;
_indices[i++] = vertexIndex + 0;
_indices[i++] = vertexIndex + 5;
_indices[i++] = vertexIndex + 4;
_indices[i++] = vertexIndex + 1;
vertexIndex += 8;
}
}
PUParticle3DBoxRender* PUParticle3DBoxRender::clone()
{
auto render = PUParticle3DBoxRender::create(_texFile);
copyAttributesTo(render);
return render;
}
2015-03-05 13:24:06 +08:00
PUSphereRender* PUSphereRender::create( const std::string &texFile)
2015-03-02 13:07:32 +08:00
{
2015-03-05 13:24:06 +08:00
auto ret = new (std::nothrow) PUSphereRender();
2015-03-02 17:47:26 +08:00
if (ret && ret->initRender(texFile))
{
ret->autorelease();
}
else
{
CC_SAFE_DELETE(ret);
}
return ret;
2015-03-02 13:07:32 +08:00
}
2015-03-05 13:24:06 +08:00
void PUSphereRender::render( Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem )
2015-03-02 13:07:32 +08:00
{
//batch and generate draw
const ParticlePool &particlePool = particleSystem->getParticlePool();
if (!_isVisible || particlePool.empty())
return;
auto camera = Camera::getVisitingCamera();
auto cameraMat = camera->getNodeToWorldTransform();
Vec3 backward(cameraMat.m[8], cameraMat.m[9], cameraMat.m[10]);
unsigned int vertexCount = (_numberOfRings + 1) * (_numberOfSegments + 1);
unsigned int indexCount = 6 * _numberOfRings * (_numberOfSegments + 1);
if (_vertexBuffer == nullptr && _indexBuffer == nullptr){
GLsizei stride = sizeof(VertexInfo);
_vertexBuffer = VertexBuffer::create(stride, vertexCount * particleSystem->getParticleQuota());
2015-03-03 11:42:15 +08:00
if (_vertexBuffer == nullptr)
{
2015-03-05 13:24:06 +08:00
CCLOG("PUSphereRender::render create vertex buffer failed");
2015-03-03 11:42:15 +08:00
return;
}
2015-03-02 13:07:32 +08:00
_vertexBuffer->retain();
_vertices.resize(vertexCount * particleSystem->getParticleQuota());
_indexBuffer = IndexBuffer::create(IndexBuffer::IndexType::INDEX_TYPE_SHORT_16, indexCount * particleSystem->getParticleQuota());
2015-03-03 11:42:15 +08:00
if (_indexBuffer == nullptr)
{
2015-03-05 13:24:06 +08:00
CCLOG("PUSphereRender::render create index buffer failed");
2015-03-03 11:42:15 +08:00
return;
}
2015-03-02 13:07:32 +08:00
_indexBuffer->retain();
_indices.resize(indexCount * particleSystem->getParticleQuota());
buildBuffers(particleSystem->getParticleQuota());
}
unsigned int vertexindex = 0;
unsigned int index = 0;
Mat4 mat;
Mat4 rotMat;
Mat4 sclMat;
Mat4 texRot;
Vec3 val;
for (auto iter : particlePool.getActiveDataList())
{
auto particle = static_cast<PUParticle3D *>(iter);
float radius = particle->width * 0.5f;
Mat4::createRotation(particle->orientation, &rotMat);
Mat4::createScale(radius, radius, radius, &sclMat);
Mat4::createRotation(backward, particle->zRotation, &texRot);
mat = rotMat * sclMat;
mat.m[12] = particle->position.x;
mat.m[13] = particle->position.y;
mat.m[14] = particle->position.z;
for (unsigned int i = 0; i < vertexCount; ++i){
val = texRot * Vec3(_vertexTemplate[vertexindex + i].uv.x, _vertexTemplate[vertexindex + i].uv.y, 0.0f);
mat.transformPoint(_vertexTemplate[vertexindex + i].position, &_vertices[vertexindex + i].position);
_vertices[vertexindex + i].color = particle->color;
_vertices[vertexindex + i].uv.x = val.x; _vertices[vertexindex + i].uv.y = val.y;
}
vertexindex += vertexCount;
index += indexCount;
}
if (!_vertices.empty() && !_indices.empty()){
_vertexBuffer->updateVertices(&_vertices[0], vertexindex/* * sizeof(_posuvcolors[0])*/, 0);
_indexBuffer->updateIndices(&_indices[0], index/* * sizeof(unsigned short)*/, 0);
GLuint texId = (_texture ? _texture->getName() : 0);
2015-03-04 10:10:33 +08:00
_meshCommand->init(0, texId, _glProgramState, particleSystem->getBlendFunc(), _vertexBuffer->getVBO(), _indexBuffer->getVBO(), GL_TRIANGLES, GL_UNSIGNED_SHORT, index, transform, Node::FLAGS_RENDER_AS_3D);
_meshCommand->setTransparent(true);
Squashed commit of the following: commit 3676fd8b4fe09be74fe10a6e2b8d6043cd016a2a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 11:46:57 2015 -0700 compiles on win32 commit 0b8d30a3f8b2656e714846a62ca8a94b303efbdc Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 11:01:04 2015 -0700 compiles on windows! commit 8cad22273ec2d9b74ef22196afcb8aa2f2bd8a6c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 10:20:13 2015 -0700 windows fix CALLBACK is defined in windows. Use CALLBACK_FN instead commit 33eff5c09c30e5ba6c8e61a69d1be0696d0b5d15 Merge: 17c5102 f843466 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue May 5 09:51:02 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 17c5102215e60c9e9b8b69ceb6b61b84b657ec91 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 17:05:49 2015 -0700 Material system works Ok. Deftaul states are being applyied to RenderState::StateBlock::_default state as well! commit 3f5285102ef95c77c505d0f2174f8f77b9bd86e1 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 15:52:09 2015 -0700 more fixes for material blending works as expected commit 347eaea42248eb07bc77844dcee56dcbcf0fbcb2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 12:14:00 2015 -0700 compiles on Android compiles on Android commit 5feef67410a6e8408414230887c177a5cc3d8c35 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon May 4 11:01:46 2015 -0700 Cmakefiles works with Cmake again commit 1366da20efd4f63f683ac9264e18aa71d84bcc71 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sat May 2 18:17:50 2015 -0700 Particle3D working Ok with its own uniforms commit c6cfa32e1f693e6d71d00e0cd9dd9610ca1e7663 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 1 17:32:00 2015 -0700 MeshCommand now works 100% on Material! commit 92d641e29675ffc58daba48fcdcc5ec6459be02f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 1 15:49:14 2015 -0700 multiple meshes work Ok commit 842927d18b5605b2fd1bd3a679fc25418c7eeab8 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri May 1 13:43:56 2015 -0700 Adds `clone` to GLProgramState commit c4b8e222f8e852254b1f23f0e17c16dfca7cc5ca Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 18:54:34 2015 -0700 adds comment about the glprogramstate bug commit 2d008ec90557025507e0b17284e60b39fc9b42d3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 18:28:39 2015 -0700 some uniforms moved to Material commit 11f59f87079a6cb698c7e9b5a55735f6d51cf420 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 16:52:07 2015 -0700 depth test moved to Material! commit 4dabb53641c293bfe8c417fe3491ec33b33ffc4e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 13:12:28 2015 -0700 Material/Technique/Pass subclass of RenderState Inheritance of RenderState. Code from GamePlay3D commit a8b888dc30cf7ab4fae186acec2a366dfb967116 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 12:05:26 2015 -0700 same as v3 commit c026de5318a2a03beed1de6d7a0efda431569a5c Merge: 4561e3f 254a4b0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 30 11:37:40 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 4561e3f5763849872d888a3be9ebbdcfb1a7bf9d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 18:02:21 2015 -0700 fixes on blending commit 1b4cd8fd1c7b2a489b6a52ab6d42548eb7c7fac0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 17:51:05 2015 -0700 better defaults for StateBlock commit 3a661c35908aa075754d7b9dfac45be1af3b38e9 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 17:46:36 2015 -0700 RenderState::bind() binds lots of states commit 074d5fb4a485e4ac32996c345e314594806e3cf0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 16:40:07 2015 -0700 Adds REnderState parsing in .material commit 7c0f098b7e2e198aa4a821bfbdec661eeba2587e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 16:06:31 2015 -0700 RenderState added into RenderState Code based on GamePlay3D. Adds GamePlay3d License. commit 04a6295ca5839e2e1202881b8a10733685c113d6 Merge: 52c916f 5671818 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 29 11:27:55 2015 -0700 Merge branch 'v3' into material_system commit 52c916fb4df04558433b1370102a5e9269f73607 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 18:15:12 2015 -0700 order files alphabetically order files alphabetically commit a5f54f0c1ca5d997a87e0231ce1b28d3c8d9ca64 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 17:46:07 2015 -0700 Adds cmake and android support commit 2432b1dd2ec3c7db78d4d9e5e7b9fbe491b95884 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 16:33:50 2015 -0700 for some reason the callback was crashing ... bug in the callback code? in any case, we didn't need it and it was making the code slower. commit 7844d32d04cb411ddae139d9598adcb04b899606 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 14:00:24 2015 -0700 more little fixes commit 2992a5e0f4a8dfac87d6aab37e101154f8b41519 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 12:11:28 2015 -0700 MeshCommand using Material internally works commit 67a435d66b4e554b4d24e462ca2ad42408157e69 Merge: 6dee7ca b9a994f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 28 10:34:03 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 6dee7cac6a51b4c123aabb111b0f8951082b1507 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 27 17:41:27 2015 -0700 improved readebility of MeshCommand code commit 3a57eb200f7cba4a17f512060dd3f121d83e32fd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 27 15:41:07 2015 -0700 mesh supports Material `Mesh` supports `Material` Now `MeshCommand` needs to implement it correctly. commit 2fc745c787555fbd5c6b100b0a2833ef0e65ad73 Merge: 05b16f5 bd5f4e0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 27 11:23:28 2015 -0700 Merge branch 'v3' into material_system commit 05b16f5c6f783ff38b4ae54528f9b949d8bb39a4 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 17:40:48 2015 -0700 Adding Material into Mesh WIP. commit bc62f1a146ff9ad9864d8ff317f6a9540760066a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 16:39:54 2015 -0700 cosmetic commit 2f86d50cee15c6af20abb512368aa36dc4ed3ccf Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 16:26:41 2015 -0700 moves even more code form Sprite3D to Mesh commit 04643bed3c277f0a775e962a5c87f550b1a59e74 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 16:15:21 2015 -0700 Moves "draw" from `Sprite3D` to `Mesh` commit 4bf884cdcb1a8df7522adeab364368493aba11e0 Merge: 2f305fc 2199bf1 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 15:00:50 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 2f305fc68ad847fd4bdf855611c6f6f6a4bf63d2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 24 14:46:28 2015 -0700 cosmetic commit a697b43a96e5f9440787aa2a1c4e178d98b2e5bc Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 23 16:44:21 2015 -0700 revert my changes... ...actually the GLProgramState code was Ok... ouch commit 36323c62eae2f8dbdcd7e13075758752cce44132 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 23 15:40:54 2015 -0700 parsing GLProgramState validates the attributes commit a406d6236a78244f73e81ded0b4148199a8677e5 Merge: 3be7fde cf177bb Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 23 12:10:31 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 3be7fdee9d88a14916b4f25b1c0b6f50cb619c04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 17:45:34 2015 -0700 little progress on Sprite3D + Material GLProgramState needs to decouple Uniforms from Attributes in `applyGLProgram`. binding the attributes is something that needs to be done at a different order. Perhaps the attributes are part of a VAO or something else. the method `applyAttributes()` has a variable to avoid that... but everything looks very hackish. commit f82496c61c9cb5a0787f883a4fb2d475889fa711 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 15:46:02 2015 -0700 doesn't crash :) but doesn't show anything either commit 0593fb09dc987aa2dd22af3a6c3aa8241fedfe5f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 13:35:45 2015 -0700 adding sprit3d test commit e716da63fe053b48db06f2aed9e0280256dd5f1b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 12:10:32 2015 -0700 MeshCommand: initial draw with Material commit d758041d81c3e6275997205e6395c46006bcc4ca Merge: 8cdc99f ca1a95f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 22 10:41:05 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 8cdc99fca664b0c9c2a536d431ffcc7844d69b3e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 21 21:57:28 2015 -0700 adding Material to MeshCommand commit 0121872709c5e584b9b9f102e0f8dfc9c836841b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 21 19:39:09 2015 -0700 pre commit before merging MeshCommand commit 06c0ac2a67e303bde98dff75ac436ec22de59263 Merge: 736feb1 0287b42 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 21 18:19:00 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 736feb1b6495b7411525afb130015bdb31b5c471 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 20 17:22:03 2015 -0700 Pass conforms to create()/init() pattern commit 6103ffbb8479681b6665e81f0572bc3287919d07 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 20 17:04:19 2015 -0700 defines are strings better error checking when creating objects autorelase added in Pass, Material, Technique commit 1efcbab63c7ca4259d50825144184baee1b577ac Merge: 5b233bc fd3e38b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 20 11:23:47 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 5b233bc879bd65123092d366257843465ec1d306 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 17 15:31:37 2015 -0700 blur effect works with alpha commit 836d3c4a0dcc3a363e1b0290e628b7ac2a973c89 Merge: e4c1dd2 425b2b6 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 17 15:04:35 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit e4c1dd23d8b28f2631efe30f6cc9da9eda4501bb Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 17 15:04:07 2015 -0700 Material, Technique, Pass: they have parent commit 7c3f258a1c9e4ff319db4e3eebfd39006d673d91 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 21:48:06 2015 -0700 multipass works commit b73ede73b72d8305f6f9d7898b4a5aa2336e9e32 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 17:31:04 2015 -0700 yeah! more materials... a lot to do yet commit d54d24ed185071ce1350bbf71914a64c9f6f228e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 17:06:46 2015 -0700 yeah! works! commit 1e70cb553148e6c136df42a789bf85184e73762d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 16:43:54 2015 -0700 simple test of material system works!!! commit c8581dfe9e970a3004254987416d75cccc644ccd Merge: 83aeec4 5d5fa3d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 16 13:51:45 2015 -0700 Merge remote-tracking branch 'cocos2d/v3' into material_system commit 83aeec41c7933ee46f5763ad64dcdc71a50885dc Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 15 18:04:23 2015 -0700 JSON file curated fixes minor bugs commit 35f669e7fad6257ff6e60023e95ec757fdfe23f5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 15 17:22:36 2015 -0700 parsers shaders! including uniforms commit 3f58bad0b2bc7ebbcfcf74e1eb02048f9d574340 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 14 23:24:18 2015 -0700 Material parses texture commit 1f678faf9d6c25f6405591f052da511281be8768 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 14 18:22:33 2015 -0700 material parsing almost working commit 9a79c45fe4d735a772d5e6d9e1f8bcb02546560d Merge: d0ff296 d54ddbd Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Apr 14 09:23:23 2015 -0700 Merge branch 'v3' into material_system commit d0ff2960f4f9edc4714f9d3edf921f3365d305c7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 13 18:42:42 2015 -0700 json parsing broken ha... I need to parse the content of the file, to the name of the file. to be fixed tomorrow commit e5aab39e5774d997f848155fc7209e9fbbd03bbc Merge: 81e93fa bc34554 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Apr 13 10:19:11 2015 -0700 Merge branch 'v3' into material_system commit 81e93faac9d80888e975ee19d7412c54daf439a0 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 17:41:12 2015 -0700 Adds more dummy files for material commit 5552a1e099bcf960d962c5369973ea663f802895 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 17:01:16 2015 -0700 adds empty test commit 7027c85fb24109f1ed4c50877dbec35618b5b39c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 15:36:24 2015 -0700 more material fixes multiple passes added in renderer commit db6745ead9879c6ce66b1921f32bf927421c54d9 Merge: 58d2412 8a160d7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 10 11:52:30 2015 -0700 Merge branch 'v3' into material_system commit 58d241266bdbd88162bb7ae9a7e868af173e6375 Merge: 0eccb23 b409f20 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 15:42:35 2015 -0700 Merge branch 'v3' into material_system commit 0eccb236aa933eb471416258c5bb55a7ca3a24f0 Merge: 83494de 967f35a Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 15:18:34 2015 -0700 Merge branch 'cpp_compiles_on_mac' into material_system commit 83494dedd0f4e7092f0267187cf07bd7de7723c2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 15:09:59 2015 -0700 compiles on Mac commit cca5b060164182b67df21fa330dce938e17fb324 Merge: dfc3740 09c50c4 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 9 13:54:59 2015 -0700 Merge branch 'v3' into material_system commit dfc374099ca02e547478d24fa8fd61817a85862c Merge: fa2152b 64c45fa Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Apr 8 14:16:27 2015 -0700 Merge branch 'v3' into material_system commit fa2152b3402e3519d35f98309c4acc03b6790370 Merge: 90b7b6f b648d1f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 3 10:15:28 2015 +0800 Merge branch 'v3' into material_system commit 90b7b6f6540edff156e22fdf38021a5c83194deb Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Apr 3 10:13:24 2015 +0800 little changes to pass commit 7f8b83017f03572a3698f431b6af497d62fcfa25 Merge: 7460614 0779d05 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 2 08:36:43 2015 +0800 Merge branch 'v3' into material_system commit 7460614dd8b7eff5d8c759be54dd205333b26033 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Apr 2 08:23:17 2015 +0800 small changes commit fa0354e74983795adafad3bedc9c50f6e8e328c9 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Mar 26 18:20:46 2015 -0700 initial Material system
2015-05-06 04:07:32 +08:00
_glProgramState->setUniformVec4("u_color", Vec4(1,1,1,1));
2015-03-02 13:07:32 +08:00
renderer->addCommand(_meshCommand);
}
}
2015-03-05 13:24:06 +08:00
void PUSphereRender::buildBuffers( unsigned short count )
2015-03-02 13:07:32 +08:00
{
float stepRingAngle = (M_PI / _numberOfRings);
float stepSegmentAngle = (2.0 * M_PI / _numberOfSegments);
unsigned short vertexIndex = 0;
unsigned short index = 0;
for (unsigned short i = 0; i < count; ++i){
for(unsigned int ring = 0; ring <= _numberOfRings; ring++)
{
float r0 = sinf (ring * stepRingAngle);
float y0 = cosf (ring * stepRingAngle);
for(unsigned int segment = 0; segment <= _numberOfSegments; segment++)
{
VertexInfo vi;
float x0 = r0 * sinf(segment * stepSegmentAngle);
float z0 = r0 * cosf(segment * stepSegmentAngle);
// Vertex
vi.position.set(x0, y0, z0);
2015-03-02 13:07:32 +08:00
// Colour
vi.color = Vec4::ONE;
// Texture Coordinates
vi.uv.x = (float) segment / (float) _numberOfSegments;
vi.uv.y = 1.0f - (float) ring / (float) _numberOfRings;
if (ring != _numberOfRings)
{
// each vertex (except the last) has six indices pointing to it
_indices[index++] = vertexIndex + _numberOfSegments + 1;
_indices[index++] = vertexIndex;
_indices[index++] = vertexIndex + _numberOfSegments;
_indices[index++] = vertexIndex + _numberOfSegments + 1;
_indices[index++] = vertexIndex + 1;
_indices[index++] = vertexIndex;
}
++vertexIndex;
_vertexTemplate.push_back(vi);
}
}
}
}
2015-03-05 13:24:06 +08:00
PUSphereRender::PUSphereRender()
2015-03-02 13:07:32 +08:00
: _numberOfRings(16)
, _numberOfSegments(16)
{
autoRotate = false;
}
2015-03-05 13:24:06 +08:00
PUSphereRender::~PUSphereRender()
2015-03-02 13:07:32 +08:00
{
}
2015-03-05 13:24:06 +08:00
void PUSphereRender::copyAttributesTo( PURender *render )
2015-03-02 13:07:32 +08:00
{
2015-03-05 13:24:06 +08:00
PURender::copyAttributesTo(render);
PUSphereRender *sphereRender = static_cast<PUSphereRender *>(render);
2015-03-02 13:07:32 +08:00
sphereRender->_numberOfRings = _numberOfRings;
sphereRender->_numberOfSegments = _numberOfSegments;
}
2015-03-05 13:24:06 +08:00
PUSphereRender* PUSphereRender::clone()
2015-03-02 13:07:32 +08:00
{
2015-03-05 13:24:06 +08:00
auto render = PUSphereRender::create(_texFile);
2015-03-02 13:07:32 +08:00
copyAttributesTo(render);
return render;
2015-02-11 18:14:22 +08:00
}
NS_CC_END