NS_CC_BEGIN //implementation CCParticleSystemQuad // overriding the init method bool CCParticleSystemQuad::initWithTotalParticles(unsigned int numberOfParticles) { // base initialization if( CCParticleSystem::initWithTotalParticles(numberOfParticles) ) { // allocating data space if( ! this->allocMemory() ) { this->release(); return false; } setupIndices(); #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); // Need to listen the event only when not use batchnode, because it will use VBO CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(CCParticleSystemQuad::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); return true; } return false; }
//-------------------------------------------------------------- void ofVboMesh::update(){ if(meshElement->haveVertsChanged()){ setupVertices(drawType); //vbo.updateVertexData(meshElement->getVerticesPointer(), meshElement->getNumVertices()); } if(meshElement->haveColorsChanged()){ setupColors(drawType); //vbo.updateColorData(meshElement->getColorsPointer(), meshElement->getNumColors()); } if(meshElement->haveNormalsChanged()){ setupNormals(drawType); //vbo.updateNormalData(meshElement->getNormalsPointer(), meshElement->getNumNormals()); } if(meshElement->haveTexCoordsChanged()){ setupTexCoords(drawType); //vbo.updateTexCoordData(meshElement->getTexCoordsPointer(), meshElement->getNumTexCoords()); } if(meshElement->haveIndicesChanged() && bUseIndices){ setupIndices(drawType); //vbo.setIndexData(meshElement->getIndexPointer(),meshElement->getNumIndices()); //vbo.updateIndexData(meshElement->getIndexPointer(),meshElement->getNumIndices()); } }
bool ICRA2009DynamicMovementPrimitive::add(const ICRA2009DynamicMovementPrimitive& icra2009_dmp, bool check_for_compatibiliy) { if(check_for_compatibiliy && !isCompatible(icra2009_dmp)) { return false; } transformation_systems_.insert(transformation_systems_.end(), icra2009_dmp.transformation_systems_.begin(), icra2009_dmp.transformation_systems_.end()); if(!setupIndices()) { return false; } return parameters_->changeType(*icra2009_dmp.parameters_); }
//----------------------------------------------------------------------- RenderOperation InstanceBatch::build( const SubMesh* baseSubMesh ) { if( checkSubMeshCompatibility( baseSubMesh ) ) { //Only triangle list at the moment mRenderOperation.operationType = RenderOperation::OT_TRIANGLE_LIST; mRenderOperation.srcRenderable = this; mRenderOperation.useIndexes = true; setupVertices( baseSubMesh ); setupIndices( baseSubMesh ); createAllInstancedEntities(); } return mRenderOperation; }
void Renderer::initGLView() { #if CC_ENABLE_CACHE_TEXTURE_DATA _cacheTextureListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom* event){ /** listen the event that renderer was recreated on Android/WP8 */ this->setupBuffer(); }); Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_cacheTextureListener, -1); #endif setupIndices(); setupBuffer(); _glViewAssigned = true; }
void Renderer::initGLView() { #if CC_ENABLE_CACHE_TEXTURE_DATA _cacheTextureListener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){ /** listen the event that coming to foreground on Android */ this->setupBuffer(); }); Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_cacheTextureListener, -1); #endif setupIndices(); setupBuffer(); _glViewAssigned = true; }
void CCParticleSystemQuad::setBatchNode(CCParticleBatchNode * batchNode) { if( m_pBatchNode != batchNode ) { CCParticleBatchNode* oldBatch = m_pBatchNode; CCParticleSystem::setBatchNode(batchNode); // NEW: is self render ? if( ! batchNode ) { allocMemory(); setupIndices(); setTexture(oldBatch->getTexture()); #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif } // OLD: was it self render ? cleanup else if( !oldBatch ) { // copy current state to batch ccV3F_C4B_T2F_Quad *batchQuads = m_pBatchNode->getTextureAtlas()->getQuads(); ccV3F_C4B_T2F_Quad *quad = &(batchQuads[m_uAtlasIndex] ); memcpy( quad, m_pQuads, m_uTotalParticles * sizeof(m_pQuads[0]) ); CC_SAFE_FREE(m_pQuads); CC_SAFE_FREE(m_pIndices); glDeleteBuffers(2, &m_pBuffersVBO[0]); memset(m_pBuffersVBO, 0, sizeof(m_pBuffersVBO)); #if CC_TEXTURE_ATLAS_USE_VAO glDeleteVertexArrays(1, &m_uVAOname); ccGLBindVAO(0); m_uVAOname = 0; #endif } } }
// TextureAtlas - Resize bool TextureAtlas::resizeCapacity(ssize_t newCapacity) { CCASSERT(newCapacity>=0, "capacity >= 0"); if( newCapacity == _capacity ) { return true; } auto oldCapactiy = _capacity; // update capacity and totolQuads _totalQuads = MIN(_totalQuads, newCapacity); _capacity = newCapacity; V3F_C4B_T2F_Quad* tmpQuads = nullptr; GLushort* tmpIndices = nullptr; // when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return nullptr, // so here must judge whether _quads and _indices is nullptr. if (_quads == nullptr) { tmpQuads = (V3F_C4B_T2F_Quad*)malloc( _capacity * sizeof(_quads[0]) ); if (tmpQuads != nullptr) { memset(tmpQuads, 0, _capacity * sizeof(_quads[0]) ); } } else { tmpQuads = (V3F_C4B_T2F_Quad*)realloc( _quads, sizeof(_quads[0]) * _capacity ); if (tmpQuads != nullptr && _capacity > oldCapactiy) { memset(tmpQuads+oldCapactiy, 0, (_capacity - oldCapactiy)*sizeof(_quads[0]) ); } _quads = nullptr; } if (_indices == nullptr) { tmpIndices = (GLushort*)malloc( _capacity * 6 * sizeof(_indices[0]) ); if (tmpIndices != nullptr) { memset( tmpIndices, 0, _capacity * 6 * sizeof(_indices[0]) ); } } else { tmpIndices = (GLushort*)realloc( _indices, sizeof(_indices[0]) * _capacity * 6 ); if (tmpIndices != nullptr && _capacity > oldCapactiy) { memset( tmpIndices+oldCapactiy, 0, (_capacity-oldCapactiy) * 6 * sizeof(_indices[0]) ); } _indices = nullptr; } if( ! ( tmpQuads && tmpIndices) ) { CCLOG("cocos2d: TextureAtlas: not enough memory"); CC_SAFE_FREE(tmpQuads); CC_SAFE_FREE(tmpIndices); CC_SAFE_FREE(_quads); CC_SAFE_FREE(_indices); _capacity = _totalQuads = 0; return false; } _quads = tmpQuads; _indices = tmpIndices; setupIndices(); mapBuffers(); _dirty = true; return true; }
void CCParticleSystemQuad::setTotalParticles(unsigned int tp) { // If we are setting the total number of particles to a number higher // than what is allocated, we need to allocate new arrays if( tp > m_uAllocatedParticles ) { // Allocate new memory size_t particlesSize = tp * sizeof(tCCParticle); size_t quadsSize = sizeof(m_pQuads[0]) * tp * 1; size_t indicesSize = sizeof(m_pIndices[0]) * tp * 6 * 1; tCCParticle* particlesNew = (tCCParticle*)realloc(m_pParticles, particlesSize); ccV3F_C4B_T2F_Quad* quadsNew = (ccV3F_C4B_T2F_Quad*)realloc(m_pQuads, quadsSize); GLushort* indicesNew = (GLushort*)realloc(m_pIndices, indicesSize); if (particlesNew && quadsNew && indicesNew) { // Assign pointers m_pParticles = particlesNew; m_pQuads = quadsNew; m_pIndices = indicesNew; // Clear the memory memset(m_pParticles, 0, particlesSize); memset(m_pQuads, 0, quadsSize); memset(m_pIndices, 0, indicesSize); m_uAllocatedParticles = tp; } else { // Out of memory, failed to resize some array if (particlesNew) m_pParticles = particlesNew; if (quadsNew) m_pQuads = quadsNew; if (indicesNew) m_pIndices = indicesNew; CCLOG("Particle system: out of memory"); return; } m_uTotalParticles = tp; // Init particles if (m_pBatchNode) { for (unsigned int i = 0; i < m_uTotalParticles; i++) { m_pParticles[i].atlasIndex=i; } } setupIndices(); #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif } else { m_uTotalParticles = tp; } }
// TextureAtlas - Resize bool CCTextureAtlas::resizeCapacity(unsigned int newCapacity) { if( newCapacity == m_uCapacity ) { return true; } unsigned int uOldCapactiy = m_uCapacity; // update capacity and totolQuads m_uTotalQuads = MIN(m_uTotalQuads, newCapacity); m_uCapacity = newCapacity; ccV3F_C4B_T2F_Quad* tmpQuads = NULL; GLushort* tmpIndices = NULL; // when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return NULL, // so here must judge whether m_pQuads and m_pIndices is NULL. if (m_pQuads == NULL) { tmpQuads = (ccV3F_C4B_T2F_Quad*)malloc( m_uCapacity * sizeof(m_pQuads[0]) ); if (tmpQuads != NULL) { memset(tmpQuads, 0, m_uCapacity * sizeof(m_pQuads[0]) ); } } else { tmpQuads = (ccV3F_C4B_T2F_Quad*)realloc( m_pQuads, sizeof(m_pQuads[0]) * m_uCapacity ); if (tmpQuads != NULL && m_uCapacity > uOldCapactiy) { memset(tmpQuads+uOldCapactiy, 0, (m_uCapacity - uOldCapactiy)*sizeof(m_pQuads[0]) ); } } if (m_pIndices == NULL) { tmpIndices = (GLushort*)malloc( m_uCapacity * 6 * sizeof(m_pIndices[0]) ); if (tmpIndices != NULL) { memset( tmpIndices, 0, m_uCapacity * 6 * sizeof(m_pIndices[0]) ); } } else { tmpIndices = (GLushort*)realloc( m_pIndices, sizeof(m_pIndices[0]) * m_uCapacity * 6 ); if (tmpIndices != NULL && m_uCapacity > uOldCapactiy) { memset( tmpIndices+uOldCapactiy, 0, (m_uCapacity-uOldCapactiy) * 6 * sizeof(m_pIndices[0]) ); } } if( ! ( tmpQuads && tmpIndices) ) { CCLOG("cocos2d: CCTextureAtlas: not enough memory"); CC_SAFE_FREE(tmpQuads); CC_SAFE_FREE(tmpIndices); CC_SAFE_FREE(m_pQuads); CC_SAFE_FREE(m_pIndices); m_uCapacity = m_uTotalQuads = 0; return false; } m_pQuads = tmpQuads; m_pIndices = tmpIndices; setupIndices(); mapBuffers(); m_bDirty = true; return true; }
// TextureAtlas - Resize KDbool CCTextureAtlas::resizeCapacity ( KDuint uNewCapacity ) { if ( uNewCapacity == m_uCapacity ) { return KD_TRUE; } KDuint uOldCapacity = m_uCapacity; // update capacity and totolQuads m_uTotalQuads = KD_MIN ( m_uTotalQuads, uNewCapacity ); m_uCapacity = uNewCapacity; ccV3F_C4B_T2F_Quad* pTempQuads = KD_NULL; GLushort* pTempIndices = KD_NULL; // when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return NULL, // so here must judge whether m_pQuads and m_pIndices is NULL. if ( m_pQuads == KD_NULL ) { pTempQuads = (ccV3F_C4B_T2F_Quad*) kdCalloc ( 1, m_uCapacity * sizeof ( m_pQuads[0] ) ); } else { pTempQuads = (ccV3F_C4B_T2F_Quad*) kdRealloc ( m_pQuads, sizeof ( m_pQuads[0] ) * m_uCapacity ); if ( pTempQuads != KD_NULL && m_uCapacity > uOldCapacity ) { kdMemset ( pTempQuads + uOldCapacity, 0, ( m_uCapacity - uOldCapacity ) * sizeof ( m_pQuads[0] ) ); } } if ( m_pIndices == KD_NULL ) { pTempIndices = (GLushort*) kdCalloc ( 1, m_uCapacity * 6 * sizeof ( m_pIndices[0] ) ); } else { pTempIndices = (GLushort*) kdRealloc ( m_pIndices, sizeof ( m_pIndices[0] ) * m_uCapacity * 6 ); if ( pTempIndices != KD_NULL && m_uCapacity > uOldCapacity ) { kdMemset ( pTempIndices + uOldCapacity, 0, ( m_uCapacity - uOldCapacity ) * 6 * sizeof ( m_pIndices[0] ) ); } } if ( !( pTempQuads && pTempIndices ) ) { CCLOG ( "XMCocos2D : CCTextureAtlas - not enough memory"); CC_SAFE_FREE ( pTempQuads ); CC_SAFE_FREE ( pTempIndices ); CC_SAFE_FREE ( m_pQuads ); CC_SAFE_FREE ( m_pIndices ); m_uCapacity = m_uTotalQuads = 0; return KD_FALSE; } m_pQuads = pTempQuads; m_pIndices = pTempIndices; setupIndices ( ); mapBuffers ( ); m_bDirty = KD_TRUE; return KD_TRUE; }
bool ICRA2009DynamicMovementPrimitive::initialize(const vector<string>& variable_names, lwr_lib::LWRParamPtr lwr_parameters, const double k_gain, const double d_gain) { assert(!variable_names.empty()); assert(lwr_parameters->isInitialized()); vector<ICRA2009TSPtr> icra2009_transformation_systems; for (int i = 0; i < (int)variable_names.size(); ++i) { ICRA2009TSParamPtr icra2009_transformation_system_parameters(new ICRA2009TransformationSystemParameters()); lwr_lib::LWRPtr lwr_model(new lwr_lib::LWR()); if (!lwr_model->initialize(lwr_parameters)) { Logger::logPrintf("Could not initialize LWR model with provide parameters.", Logger::ERROR); return false; } if (!icra2009_transformation_system_parameters->initialize(lwr_model, variable_names[i], k_gain, d_gain)) { Logger::logPrintf("Could not initialize transformation system parameters.", Logger::ERROR); return false; } // TODO: fix integration method !! ICRA2009TSStatePtr icra2009_transformation_system_state(new ICRA2009TransformationSystemState()); ICRA2009TSPtr icra2009_transformation_system(new ICRA2009TransformationSystem()); if (!icra2009_transformation_system->initialize(icra2009_transformation_system_parameters, icra2009_transformation_system_state, TransformationSystem::NORMAL)) { Logger::logPrintf("Could not initialize transformation system.", Logger::ERROR); return false; } icra2009_transformation_systems.push_back(icra2009_transformation_system); } ICRA2009CSParamPtr icra2009_canonical_system_parameters(new ICRA2009CanonicalSystemParameters()); ICRA2009CSStatePtr icra2009_canonical_system_state(new ICRA2009CanonicalSystemState()); ICRA2009CSPtr icra2009_canonical_system(new ICRA2009CanonicalSystem()); if (!icra2009_canonical_system->initialize(icra2009_canonical_system_parameters, icra2009_canonical_system_state)) { Logger::logPrintf("Could not initialize canonical system.", Logger::ERROR); return false; } ICRA2009DMPParamPtr dmp_parameters(new ICRA2009DynamicMovementPrimitiveParameters); if(!dmp_parameters->setCutoff(0.001)) { Logger::logPrintf("Could not set cutoff.", Logger::ERROR); return false; } ICRA2009DMPStatePtr state(new ICRA2009DynamicMovementPrimitiveState()); //Change because it fails, the same function it's done by the next lines /*if (!DynamicMovementPrimitive::initialize(dmp_parameters, icra2009_transformation_systems, icra2009_canonical_system)) { Logger::logPrintf("Could not initialize dmp.", Logger::ERROR); return false; }*/ if(initialize(dmp_parameters, state, icra2009_transformation_systems, icra2009_canonical_system)) { if(!setupIndices()) { return (initialized_ = false); } //zero_feedback_ = Eigen::VectorXd::Zero(indices_.size()); return (initialized_ = true); } return (initialized_ = false); }