//implementation ParticleSystemQuad // overriding the init method bool ParticleSystemQuad::initWithTotalParticles(int numberOfParticles) { // base initialization if( ParticleSystem::initWithTotalParticles(numberOfParticles) ) { // allocating data space if( ! this->allocMemory() ) { this->release(); return false; } initIndices(); if (Configuration::getInstance()->supportsShareableVAO()) { setupVBOandVAO(); } else { setupVBO(); } setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); #if CC_ENABLE_CACHE_TEXTURE_DATA // Need to listen the event only when not use batchnode, because it will use VBO auto listener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, CC_CALLBACK_1(ParticleSystemQuad::listenRendererRecreated, this)); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); #endif return true; } return false; }
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 CCParticleSystemQuad::listenBackToForeground(CCObject *obj) { #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif }
//procedura inicjuj¹ca ró¿ne sprawy zwi¹zane z rysowaniem w OpenGL void initOpenGL() { tex0 = readTexture("metal.tga"); tex1 = readTexture("stones2.tga"); tex2 = readTexture("latarka.tga"); setupShaders(); setupVBO(); setupVAO(); glEnable(GL_DEPTH_TEST); }
void Polyhedron::init(GLuint program) { //Generate the vertices needed for VBO and VAO draw(); //Setup the VBO setupVBO(); //Setup the VAO setupVAO(program); }
void TextureAtlas::listenBackToForeground(Object *obj) { #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif // set _dirty to true to force it rebinding buffer _dirty = true; }
KDvoid CCTextureAtlas::listenBackToForeground ( CCObject* pObject ) { #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO ( ); #else setupVBO ( ); #endif // set m_bDirty to true to force it rebinding buffer m_bDirty = KD_TRUE; }
void ParticleSystemQuad::listenRendererRecreated(EventCustom* event) { if (Configuration::getInstance()->supportsShareableVAO()) { setupVBOandVAO(); } else { setupVBO(); } }
void Renderer::setupBuffer() { if(Configuration::getInstance()->supportsShareableVAO()) { setupVBOAndVAO(); } else { setupVBO(); } }
bool TextureAtlas::initWithTexture(Texture2D *texture, ssize_t capacity) { CCASSERT(capacity>=0, "Capacity must be >= 0"); // CCASSERT(texture != nullptr, "texture should not be null"); _capacity = capacity; _totalQuads = 0; // retained in property this->_texture = texture; CC_SAFE_RETAIN(_texture); // Re-initialization is not allowed CCASSERT(_quads == nullptr && _indices == nullptr, ""); _quads = (V3F_C4B_T2F_Quad*)malloc( _capacity * sizeof(V3F_C4B_T2F_Quad) ); _indices = (GLushort *)malloc( _capacity * 6 * sizeof(GLushort) ); if( ! ( _quads && _indices) && _capacity > 0) { //CCLOG("cocos2d: TextureAtlas: not enough memory"); CC_SAFE_FREE(_quads); CC_SAFE_FREE(_indices); // release texture, should set it to null, because the destruction will // release it too. see cocos2d-x issue #484 CC_SAFE_RELEASE_NULL(_texture); return false; } memset( _quads, 0, _capacity * sizeof(V3F_C4B_T2F_Quad) ); memset( _indices, 0, _capacity * 6 * sizeof(GLushort) ); #if CC_ENABLE_CACHE_TEXTURE_DATA /** listen the event that renderer was recreated on Android/WP8 */ _rendererRecreatedListener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, CC_CALLBACK_1(TextureAtlas::listenRendererRecreated, this)); Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_rendererRecreatedListener, -1); #endif this->setupIndices(); if (Configuration::getInstance()->supportsShareableVAO()) { setupVBOandVAO(); } else { setupVBO(); } _dirty = true; return true; }
void CCTextureAtlas::listenBackToForeground(const char* noteName, CCDictionary* params) { #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif // set m_bDirty to true to force it rebinding buffer m_bDirty = true; }
bool TextureAtlas::initWithTexture(Texture2D *texture, int capacity) { CCASSERT(capacity>=0, "Capacity must be >= 0"); // CCASSERT(texture != NULL, "texture should not be null"); _capacity = capacity; _totalQuads = 0; // retained in property this->_texture = texture; CC_SAFE_RETAIN(_texture); // Re-initialization is not allowed CCASSERT(_quads == NULL && _indices == NULL, ""); _quads = (V3F_C4B_T2F_Quad*)malloc( _capacity * sizeof(V3F_C4B_T2F_Quad) ); _indices = (GLushort *)malloc( _capacity * 6 * sizeof(GLushort) ); if( ! ( _quads && _indices) && _capacity > 0) { //CCLOG("cocos2d: TextureAtlas: not enough memory"); CC_SAFE_FREE(_quads); CC_SAFE_FREE(_indices); // release texture, should set it to null, because the destruction will // release it too. see cocos2d-x issue #484 CC_SAFE_RELEASE_NULL(_texture); return false; } memset( _quads, 0, _capacity * sizeof(V3F_C4B_T2F_Quad) ); memset( _indices, 0, _capacity * 6 * sizeof(GLushort) ); #if CC_ENABLE_CACHE_TEXTURE_DATA // listen the event when app go to background NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(TextureAtlas::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); #endif this->setupIndices(); #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif _dirty = true; return true; }
KDbool CCTextureAtlas::initWithTexture ( CCTexture2D* pTexture, KDuint uCapacity ) { // CCAssert ( pTexture != KD_NULL, "texture should not be null" ); m_uCapacity = uCapacity; m_uTotalQuads = 0; // retained in property m_pTexture = pTexture; CC_SAFE_RETAIN ( m_pTexture ); // Re-initialization is not allowed CCAssert ( m_pQuads == KD_NULL && m_pIndices == KD_NULL, "" ); m_pQuads = (ccV3F_C4B_T2F_Quad *) kdCalloc ( 1, sizeof ( ccV3F_C4B_T2F_Quad ) * m_uCapacity ); m_pIndices = (GLushort *) kdCalloc ( 1, sizeof ( GLushort ) * m_uCapacity * 6 ); if ( !( m_pQuads && m_pIndices ) && m_uCapacity > 0 ) { //CCLOG ( "XMCocos2D : CCTextureAtlas: not enough memory" ); CC_SAFE_FREE ( m_pQuads ); CC_SAFE_FREE ( m_pIndices ); // release texture, should set it to null, because the destruction will // release it too. see cocos2d-x issue #484 CC_SAFE_RELEASE ( m_pTexture ); return KD_FALSE; } #if CC_ENABLE_CACHE_TEXTURE_DATA // listen the event when app go to background CCNotificationCenter::sharedNotificationCenter ( )->addObserver ( this, callfuncO_selector ( CCTextureAtlas::listenBackToForeground ), EVENT_COME_TO_FOREGROUND, KD_NULL ); #endif this->setupIndices ( ); #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO ( ); #else setupVBO ( ); #endif m_bDirty = KD_TRUE; return KD_TRUE; }
void TextureAtlas::listenRendererRecreated(EventCustom* event) { if (Configuration::getInstance()->supportsShareableVAO()) { setupVBOandVAO(); } else { setupVBO(); } // set _dirty to true to force it rebinding buffer _dirty = true; }
void init() { glClearColor(0.5, 0.5, 0.5, 1.0); glShadeModel(GL_SMOOTH); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHT2); glLightfv(GL_LIGHT0, GL_AMBIENT, red_light); glLightfv(GL_LIGHT0, GL_DIFFUSE, red_light); glLightfv(GL_LIGHT0, GL_SPECULAR, red_light); glLightfv(GL_LIGHT1, GL_AMBIENT, white_light); glLightfv(GL_LIGHT1, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT1, GL_SPECULAR, white_light); glLightfv(GL_LIGHT2, GL_AMBIENT, white_light); glLightfv(GL_LIGHT2, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT2, GL_SPECULAR, white_light); glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 10.0); glLightf(GL_LIGHT2, GL_SPOT_EXPONENT, 5.0); angle = 0.0f; ye = 5.0; xe = 0.0f; ze = 0.0f; setupShaders( (char*)"pointlight.vert", (char*)"pointlight.frag", &ProgramA, &vertexShaderObjectA, &fragmentShaderObjectA); setupShaders( (char*)"dirLightAmbDiffSpecPix.vert", (char*)"dirLightAmbDiffSpecPix.frag", &ProgramA, &vertexShaderObjectA, &fragmentShaderObjectA); setupVBO(); setupVBOfromObj((char*)"rev2.obj"); glUseProgram(ProgramA); }
bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity) { // CCAssert(texture != NULL, "texture should not be null"); m_uCapacity = capacity; m_uTotalQuads = 0; // retained in property this->m_pTexture = texture; CC_SAFE_RETAIN(m_pTexture); // Re-initialization is not allowed CCAssert(m_pQuads == NULL && m_pIndices == NULL, ""); m_pQuads = (ccV3F_C4B_T2F_Quad*)malloc( m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) ); m_pIndices = (GLushort *)malloc( m_uCapacity * 6 * sizeof(GLushort) ); if( ! ( m_pQuads && m_pIndices) && m_uCapacity > 0) { //CCLOG("cocos2d: CCTextureAtlas: not enough memory"); CC_SAFE_FREE(m_pQuads); CC_SAFE_FREE(m_pIndices); // release texture, should set it to null, because the destruction will // release it too. see cocos2d-x issue #484 CC_SAFE_RELEASE_NULL(m_pTexture); return false; } memset( m_pQuads, 0, m_uCapacity * sizeof(ccV3F_C4B_T2F_Quad) ); memset( m_pIndices, 0, m_uCapacity * 6 * sizeof(GLushort) ); // listen the event when app go to background extension::CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(CCTextureAtlas::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); this->setupIndices(); #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif m_bDirty = true; return true; }
void ParticleSystemQuad::listenRendererRecreated(EventCustom* event) { //when comes to foreground in android, _buffersVBO and _VAOname is a wild handle //before recreating, we need to reset them to 0 memset(_buffersVBO, 0, sizeof(_buffersVBO)); if (Configuration::getInstance()->supportsShareableVAO()) { _VAOname = 0; setupVBOandVAO(); } else { setupVBO(); } }
void ParticleSystemQuad::setBatchNode(ParticleBatchNode * batchNode) { if( _batchNode != batchNode ) { ParticleBatchNode* oldBatch = _batchNode; ParticleSystem::setBatchNode(batchNode); // NEW: is self render ? if( ! batchNode ) { allocMemory(); initIndices(); setTexture(oldBatch->getTexture()); if (Configuration::getInstance()->supportsShareableVAO()) { setupVBOandVAO(); } else { setupVBO(); } } // OLD: was it self render ? cleanup else if( !oldBatch ) { // copy current state to batch V3F_C4B_T2F_Quad *batchQuads = _batchNode->getTextureAtlas()->getQuads(); V3F_C4B_T2F_Quad *quad = &(batchQuads[_atlasIndex] ); memcpy( quad, _quads, _totalParticles * sizeof(_quads[0]) ); CC_SAFE_FREE(_quads); CC_SAFE_FREE(_indices); glDeleteBuffers(2, &_buffersVBO[0]); memset(_buffersVBO, 0, sizeof(_buffersVBO)); if (Configuration::getInstance()->supportsShareableVAO()) { glDeleteVertexArrays(1, &_VAOname); GL::bindVAO(0); _VAOname = 0; } } } }
void CCParticleSystemQuad::setBatchNode(CCParticleBatchNode * batchNode) { if( m_pBatchNode != batchNode ) { CCParticleBatchNode* oldBatch = m_pBatchNode; CCParticleSystem::setBatchNode(batchNode); // NEW: is self render ? if( ! batchNode ) { allocMemory(); initIndices(); 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 } } }
NS_CC_BEGIN //implementation ParticleSystemQuad // overriding the init method bool ParticleSystemQuad::initWithTotalParticles(unsigned int numberOfParticles) { // base initialization if( ParticleSystem::initWithTotalParticles(numberOfParticles) ) { // allocating data space if( ! this->allocMemory() ) { this->release(); return false; } initIndices(); #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif setShaderProgram(ShaderCache::getInstance()->programForKey(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR)); #if CC_ENABLE_CACHE_TEXTURE_DATA // Need to listen the event only when not use batchnode, because it will use VBO NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(ParticleSystemQuad::listenBackToForeground), EVNET_COME_TO_FOREGROUND, NULL); #endif return true; } return false; }
void BillboardParticleSystem::setTotalParticles(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 > _allocatedParticles ) { // Allocate new memory size_t particlesSize = tp * sizeof(tParticle); size_t quadsSize = sizeof(_quads[0]) * tp * 1; size_t indicesSize = sizeof(_indices[0]) * tp * 6 * 1; sBillboardParticle* particlesNew = (sBillboardParticle*)realloc(_particles, particlesSize); V3F_C4B_T2F_Quad* quadsNew = (V3F_C4B_T2F_Quad*)realloc(_quads, quadsSize); GLushort* indicesNew = (GLushort*)realloc(_indices, indicesSize); if (particlesNew && quadsNew && indicesNew) { // Assign pointers _particles = particlesNew; _quads = quadsNew; _indices = indicesNew; // Clear the memory memset(_particles, 0, particlesSize); memset(_quads, 0, quadsSize); memset(_indices, 0, indicesSize); _allocatedParticles = tp; } else { // Out of memory, failed to resize some array if (particlesNew) _particles = particlesNew; if (quadsNew) _quads = quadsNew; if (indicesNew) _indices = indicesNew; CCLOG("Particle system: out of memory"); return; } _totalParticles = tp; initIndices(); if (Configuration::getInstance()->supportsShareableVAO()) { setupVBOandVAO(); } else { setupVBO(); } // fixed http://www.cocos2d-x.org/issues/3990 // Updates texture coords. updateTexCoords(); } else { _totalParticles = tp; } // fixed issue #5762 // reset the emission rate setEmissionRate(_totalParticles / _life); resetSystem(); }
bool BillboardParticleSystem::initWithTotalParticles(int numberOfParticles) { _totalParticles = numberOfParticles; CC_SAFE_FREE(_particles); _particles = (sBillboardParticle*)calloc(_totalParticles, sizeof(sBillboardParticle)); if( ! _particles ) { CCLOG("Particle system: not enough memory"); this->release(); return false; } _allocatedParticles = numberOfParticles; // default, active _isActive = true; // default blend function _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; // default movement type; _positionType = PositionType::FREE; // by default be in mode A: _emitterMode = Mode::GRAVITY; // default: modulate // XXX: not used // colorModulate = YES; _isAutoRemoveOnFinish = false; // Optimization: compile updateParticle method //updateParticleSel = @selector(updateQuadWithParticle:newPosition:); //updateParticleImp = (CC_UPDATE_PARTICLE_IMP) [self methodForSelector:updateParticleSel]; //for batchNode _transformSystemDirty = false; // allocating data space if( ! this->allocMemory() ) { this->release(); return false; } initIndices(); if (Configuration::getInstance()->supportsShareableVAO()) { setupVBOandVAO(); } else { setupVBO(); } setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); #if CC_ENABLE_CACHE_TEXTURE_DATA // Need to listen the event only when not use batchnode, because it will use VBO auto listener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, CC_CALLBACK_1(ParticleSystemQuad::listenRendererRecreated, this)); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); #endif return true; }
void ParticleSystemQuad::setTotalParticles(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 > _allocatedParticles ) { // Allocate new memory size_t quadsSize = sizeof(_quads[0]) * tp * 1; size_t indicesSize = sizeof(_indices[0]) * tp * 6 * 1; _particleData.release(); if (!_particleData.init(tp)) { CCLOG("Particle system: not enough memory"); return; } V3F_C4B_T2F_Quad* quadsNew = (V3F_C4B_T2F_Quad*)realloc(_quads, quadsSize); GLushort* indicesNew = (GLushort*)realloc(_indices, indicesSize); if (quadsNew && indicesNew) { // Assign pointers _quads = quadsNew; _indices = indicesNew; // Clear the memory memset(_quads, 0, quadsSize); memset(_indices, 0, indicesSize); _allocatedParticles = tp; } else { // Out of memory, failed to resize some array if (quadsNew) _quads = quadsNew; if (indicesNew) _indices = indicesNew; CCLOG("Particle system: out of memory"); return; } _totalParticles = tp; // Init particles if (_batchNode) { for (int i = 0; i < _totalParticles; i++) { _particleData.atlasIndex[i] = i; } } initIndices(); if (Configuration::getInstance()->supportsShareableVAO()) { setupVBOandVAO(); } else { setupVBO(); } // fixed http://www.cocos2d-x.org/issues/3990 // Updates texture coords. updateTexCoords(); } else { _totalParticles = tp; } // fixed issue #5762 // reset the emission rate setEmissionRate(_totalParticles / _life); resetSystem(); }
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 // XXX: Bug? If the quads are cleared, then drawing doesn't work... WHY??? XXX 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; } } initIndices(); #if CC_TEXTURE_ATLAS_USE_VAO setupVBOandVAO(); #else setupVBO(); #endif } else { m_uTotalParticles = tp; } resetSystem(); }
void initOpenGL() { setupShaders(); setupVBO(); setupVAO(); glEnable(GL_DEPTH_TEST); }
void Renderer::setupBuffer() { setupVBO(); }