Ejemplo n.º 1
0
void QuadModel::init(int w, int h, glm::vec3 c1, glm::vec3 c2, glm::vec3 c3, glm::vec3 c4)
{
    /// assigning a quad for rendering textures


    std::vector<unsigned int> indices;
    std::vector<EG_VertexData> vertices;
    EG_VertexData tmp;

    //1.
    tmp.m_position = glm::vec3(0.0, h, 0.0);
    tmp.m_color = c1;
    vertices.push_back(tmp);
    //2.
    tmp.m_position = glm::vec3(0.0, 0.0, 0.0);
    tmp.m_color = c2;
    vertices.push_back(tmp);

    //3.
    tmp.m_position = glm::vec3(w, 0.0, 0.0);
    tmp.m_color = c3;
    vertices.push_back(tmp);
    //4.
    tmp.m_position = glm::vec3(w, h, 0.0);
    tmp.m_color = c4;
    vertices.push_back(tmp);

    initIndices(indices);

    EG_Mesh m(vertices, indices);
    m_meshes.push_back(m);
}
//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;
}
Ejemplo n.º 3
0
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;
        }

        initIndices();
#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 EG_QuadModelABS::init(int w, int h, float cx, float cy, float cw)
{
    /// assigning a quad for rendering textures
    std::vector<unsigned int> indices;
    std::vector<EG_VertexData> vertices;
    EG_VertexData tmp;

    float cx1 = cx;  float cx2 = cx+1;
    float cy1 = cy;  float cy2 = cy+1;
    //1.
    tmp.m_position = glm::vec3(0.0, h, 0.0);
    tmp.m_UV = glm::vec2(cx1 * cw, cy1 * cw);
    vertices.push_back(tmp);
    //2.
    tmp.m_position = glm::vec3(0.0, 0.0, 0.0);
    tmp.m_UV = glm::vec2(cx1 * cw, cy2 * cw);
    vertices.push_back(tmp);

    //3.
    tmp.m_position = glm::vec3(w, 0.0, 0.0);
    tmp.m_UV = glm::vec2(cx2 * cw, cy2 * cw);
    vertices.push_back(tmp);
    //4.
    tmp.m_position = glm::vec3(w, h, 0.0);
    tmp.m_UV = glm::vec2(cx2 * cw, cy1 * cw);
    vertices.push_back(tmp);

    initIndices(indices);

    EG_Mesh m(vertices, indices);
    m_meshes.push_back(m);
}
Ejemplo n.º 5
0
QuadModel::QuadModel(int w, int h, float uv_x, float uv_y, float uv_w)
{
    /// assigning a quad for rendering textures
    std::vector<unsigned int> indices;
    std::vector<EG_VertexData> vertices;
    EG_VertexData tmp;

    float uv_x0 = uv_x;  float uv_x1 = uv_x + 1;
    float uv_y0 = uv_y;  float uv_y1 = uv_y + 1;


    /// 0. bot left
    tmp.m_position = glm::vec3(0.0, 0.0, 0.0);
    tmp.m_UV = glm::vec2(uv_x0 * uv_w, uv_y0 * uv_w);
    vertices.push_back(tmp);
    /// 1. bot right
    tmp.m_position = glm::vec3(w, 0.0, 0.0);
    tmp.m_UV = glm::vec2(uv_x1 * uv_w, uv_y0 * uv_w);
    vertices.push_back(tmp);

    /// 2. top right
    tmp.m_position = glm::vec3(w, h, 0.0);
    tmp.m_UV = glm::vec2(uv_x1 * uv_w, uv_y1 * uv_w);
    vertices.push_back(tmp);
    /// 3. top left
    tmp.m_position = glm::vec3(0.0, h, 0.0);
    tmp.m_UV = glm::vec2(uv_x0 * uv_w, uv_y1 * uv_w);
    vertices.push_back(tmp);

    initIndices(indices);

    EG_Mesh m(vertices, indices);
    m_meshes.push_back(m);
}
Ejemplo n.º 6
0
/* precomputes the context indices */
void SkipCTS::initContexts() {

    // generate contexts
    m_skip_contexts.clear();
    genBoundedSkipContexts("", m_depth, m_skips);

    initIndices();

    m_skip_contexts.clear();
}
Ejemplo n.º 7
0
    ParticleSystemQuad::ParticleSystemQuad(fzUInt number, Texture2D *texture)
    : ParticleSystem(number, texture)
    {
        // allo cating quads
        p_quads = new fzC4_T2_V2_Quad[getTotalParticles()];
        
        // initialize only once the texCoords and the indices
        initTexCoordsWithRect(fzRect(FZPointZero, p_texture->getContentSize()));
        initIndices();
        
#if FZ_GL_SHADERS
        setGLProgram(kFZShader_mat_aC4_TEX);
#endif  
    }
Ejemplo n.º 8
0
	void CScutFrame::calQuads()
	{
		if (getTileCount() == 0)
		{
			return;
		}

		int nCount = getTileCount();

		calTextureTileCount(nCount);

		initQuads(nCount);

		initIndices(nCount);
	}
Ejemplo n.º 9
0
Water::Water(const DTM *dtm):
    m_dtm(dtm),
    m_ncols(dtm->ncols()),
    m_nrows(dtm->nrows()),
    m_values(new float[m_nrows * m_ncols])
{
    for(index_t i = 0; i < m_nrows; ++i)
        for(index_t j = 0; j < m_ncols; ++j) {
            const index_t k = i * m_ncols + j;
            m_values[k] = 0;
        }

    initVertices();
    initIndices();
    initVBO();
    free();
}
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;
            }
        }
    }
}
Ejemplo n.º 11
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
        }
    }
}
Ejemplo n.º 12
0
void QuadModel::init(float l, float r,
                           float b, float t,
                           float cx, float cy, float cw)
{
/// assigning a quad for rendering textures
    m_modelGeometry = GL_TRIANGLES;

    std::vector<unsigned int> indices;
    std::vector<EG_VertexData> vertices;
    EG_VertexData tmp;

    float cx0 = cx;  float cx1 = cx+1;
    float cy0 = cy;  float cy1 = cy+1;

    ///1. left-top
    tmp.m_position = glm::vec3(l, t, 0.0);
    tmp.m_UV = glm::vec2(cx0 * cw, cy0 * cw);
    vertices.push_back(tmp);

    ///2. left-bottom
    tmp.m_position = glm::vec3(l, b, 0.0);
    tmp.m_UV = glm::vec2(cx0 * cw, cy1 * cw);
    vertices.push_back(tmp);

    ///3. right-bottom
    tmp.m_position = glm::vec3(r, b, 0.0);
    tmp.m_UV = glm::vec2(cx1 * cw, cy1 * cw);
    vertices.push_back(tmp);

    ///4. right-top
    tmp.m_position = glm::vec3(r, t, 0.0);
    tmp.m_UV = glm::vec2(cx1 * cw, cy0 * cw);
    vertices.push_back(tmp);

    initIndices(indices);

    EG_Mesh m(vertices, indices);
    m_meshes.push_back(m);
}
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;
}
Ejemplo n.º 14
0
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 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 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();
}
///////////////////////////////////////////////////////////
// uses particles, variance, ind
// uses newPoints, newIndices, trees, Ndens
void gibbs2(unsigned int _Ndens, const BallTreeDensity* _trees, 
            unsigned long Np, unsigned int Niter,
            double *_pts, BallTree::index *_ind,
            double *_randU, double* _randN)
{
  unsigned int i,j,l;
  unsigned long s, maxNp;

  Ndens = _Ndens;                       // SET UP GLOBALS
  trees = _trees;
  newPoints = _pts; newIndices = _ind;
  randU = _randU; randN = _randN;
  Ndim  = trees[0].Ndim();              // dimension of densities    
  maxNp = 0;                            // largest # of particles we deal with
  for (unsigned int j=0; j<Ndens; j++)  // compute Max Np over all densities
    if (maxNp < trees[j].Npts()) maxNp = trees[j].Npts();

  ind = new BallTree::index[Ndens];     // ALLOCATE GLOBALS
  p = new double[maxNp];
  
  Nlevels = (unsigned int) (log((double)maxNp)/log((double)2))+1;          // how many levels to a balanced binary tree?

  particles = new double[Ndim*Ndens];
  variance  = new double[Ndim*Ndens];

  dNpts = new unsigned long[Ndens];
  levelList = new BallTree::index*[Ndens];
  levelListNew = new BallTree::index*[Ndens];
  for (j=0;j<Ndens;j++) { 
    levelList[j] = new BallTree::index[maxNp];
    levelListNew[j] = new BallTree::index[maxNp];
  }

  for (s=0; s<Np; s++) {                       

    levelInit();
    initIndices();
    calcIndices();

    ///////////////////////////////////////////////////////////////
    // Perform Gibbs sampling only if multiple densities in product
    ///////////////////////////////////////////////////////////////
    samplePoint(newPoints);
    for (l=0;l<Nlevels;l++) {
      levelDown();
      for (i=0;i<Niter;i++) {
        sampleIndices(newPoints);
        samplePoint(newPoints);
    }}

    for (unsigned int j=0; j<Ndens; j++)              // save and
      newIndices[j] = trees[j].getIndexOf(ind[j])+1;  // return particle label
    newIndices += Ndens;                              // move pointers to next sample
    newPoints  += Ndim;
  }

  for (j=0;j<Ndens;j++) { delete[] levelList[j];  delete[] levelListNew[j]; }
  delete[] levelList; delete[] levelListNew;
  delete[] dNpts;

  delete[] ind; delete[] p; delete[] particles; delete[] variance;
};
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;
}