Пример #1
0
void ShaderSprite::onDraw(const kmMat4 &transform, bool transformUpdated)
{
    auto shader = getShaderProgram();
    shader->use();
    shader->setUniformsForBuiltins(transform);

    setCustomUniforms();
    
    GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX );
    GL::blendFunc(_blendFunc.src, _blendFunc.dst);
    GL::bindTexture2D( getTexture()->getName());
    
    //
    // Attributes
    //
    #define kQuadSize sizeof(_quad.bl)
    size_t offset = (size_t)&_quad;
    
    // vertex
    int diff = offsetof( V3F_C4B_T2F, vertices);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));
    
    // texCoods
    diff = offsetof( V3F_C4B_T2F, texCoords);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));
    
    // color
    diff = offsetof( V3F_C4B_T2F, colors);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));
    
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4);
}
Пример #2
0
void MGRDrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags)
{
    auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR_TEXASPOINTSIZE);
    glProgram->use();
    glProgram->setUniformsForBuiltins(transform);

    GL::blendFunc(_blendFunc.src, _blendFunc.dst);

    if (_dirtyGLPoint)
    {
        glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
        glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW);

        _dirtyGLPoint = false;
    }

    glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
    // vertex
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid*)offsetof(V2F_C4B_T2F, vertices));
    // color
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid*)offsetof(V2F_C4B_T2F, colors));
    // texcoord
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid*)offsetof(V2F_C4B_T2F, texCoords));

    glDrawArrays(GL_POINTS, 0, _bufferCountGLPoint);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _bufferCountGLPoint);
    CHECK_GL_ERROR_DEBUG();
}
Пример #3
0
void LayerRadialGradient::onDraw(const Mat4& transform, uint32_t /*flags*/)
{
    auto program = getGLProgram();
    program->use();
    program->setUniformsForBuiltins(transform);
    program->setUniformLocationWith4f(_uniformLocationStartColor, _startColorRend.r,
                                      _startColorRend.g, _startColorRend.b, _startColorRend.a);
    program->setUniformLocationWith4f(_uniformLocationEndColor, _endColorRend.r,
                                      _endColorRend.g, _endColorRend.b, _endColorRend.a);
    program->setUniformLocationWith2f(_uniformLocationCenter, _center.x, _center.y);
    program->setUniformLocationWith1f(_uniformLocationRadius, _radius);
    program->setUniformLocationWith1f(_uniformLocationExpand, _expand);
    
    
    GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION);
    
    //
    // Attributes
    //
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, _vertices);
    
    GL::blendFunc(_blendFunc.src, _blendFunc.dst);
    
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,4);
}
Пример #4
0
void RawStencilBufferTest::onBeforeDrawSprite(int planeIndex, const Vec2& pt)
{
    this->setupStencilForDrawingOnPlane(planeIndex);
    CHECK_GL_ERROR_DEBUG();

    Vec2 vertices[] = {
        Vec2::ZERO,
        Vec2(pt.x, 0),
        pt,
        Vec2(0, pt.y)
    };

    auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);

    int colorLocation = glProgram->getUniformLocation("u_color");
    CHECK_GL_ERROR_DEBUG();

    Color4F color = _planeColor[planeIndex];
    glProgram->use();
    glProgram->setUniformsForBuiltins();
    glProgram->setUniformLocationWith4fv(colorLocation, (GLfloat*) &color.r, 1);

    GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );

    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4);
}
void DrawTextureScene::onDraw(){
    Director::getInstance()->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    Director::getInstance()->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    Director::getInstance()->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
    Director::getInstance()->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
    
    auto glProgram=getGLProgram();
    glProgram->use();
    //更新CC_MVPMatrix
    glProgram->setUniformsForBuiltins();
    
    
    GLuint textureLocation = glGetUniformLocation(glProgram->getProgram(), "CC_Texture0");
    // Set our sampler to user Texture Unit 0
    glUniform1i(textureLocation, 0);

//    GLuint uColorLocation = glGetUniformLocation(glProgram->getProgram(), "u_color");
//    GLfloat uColor[]={1.0,1.0,1.0,1.0};
//    glUniform4fv(uColorLocation, 1, uColor);
    
    glBindVertexArray(vao);
    
    //在调用draw call之前,我们需要绑定纹理
    
    GL::bindTexture2D(textureID);//activeTexture(GL_TEXTURE0); //glBindTexture(GL_TEXTURE_2D, textureID);
    
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, (GLvoid*)0);
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 6);
    CHECK_GL_ERROR_DEBUG();
    
    
    Director::getInstance()->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
    Director::getInstance()->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    
}
Пример #6
0
void Triangle::onDraw(const Mat4 &transform, uint32_t flags)
{
    auto glProgram = getGLProgram();
    glProgram->use();
    glProgram->setUniformsForBuiltins(transform);
    
    glEnable(GL_DEPTH_TEST);
    GL::blendFunc(_blendFunc.src, _blendFunc.dst);
    
    if (_dirty)
    {
        glBindBuffer(GL_ARRAY_BUFFER, _vbo);
        glBufferData(GL_ARRAY_BUFFER, sizeof(Vec3)*_bufferCapacity, _buffer, GL_STREAM_DRAW);
        _dirty = false;
    }
    
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(_vao);
    }
    
    GL::bindTexture2D(_textureWall->getName());
    
    glDrawArrays(_drawMode, 0, _bufferCount);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCount);
    glDisable(GL_DEPTH_TEST);
    CHECK_GL_ERROR_DEBUG();
}
Пример #7
0
void Label::onDraw(const Mat4& transform, bool transformUpdated)
{
    CC_PROFILER_START("Label - draw");

    // Optimization: Fast Dispatch
    if( _batchNodes.size() == 1 && _textureAtlas->getTotalQuads() == 0 )
    {
        return;
    }

    auto glprogram = getGLProgram();
    glprogram->use();
    GL::blendFunc( _blendFunc.src, _blendFunc.dst );

    if(_shadowEnabled && _shadowBlurRadius <= 0)
    {
        glprogram->setUniformLocationWith4f(_uniformTextColor,
            _shadowColor.r, _shadowColor.g, _shadowColor.b, _shadowColor.a);
        glprogram->setUniformLocationWith4f(_uniformEffectColor,
            _shadowColor.r, _shadowColor.g, _shadowColor.b, _shadowColor.a);

        getGLProgram()->setUniformsForBuiltins(_shadowTransform);
        for (const auto &child : _children)
        {
            child->updateTransform();
        }
        for (const auto& batchNode : _batchNodes)
        {
            batchNode->getTextureAtlas()->drawQuads();
        }
    }

    if (_currentLabelType == LabelType::TTF)
    {
        glprogram->setUniformLocationWith4f(_uniformTextColor,
            _textColorF.r, _textColorF.g, _textColorF.b, _textColorF.a);
    }

    if (_currLabelEffect == LabelEffect::OUTLINE || _currLabelEffect == LabelEffect::GLOW)
    {
        glprogram->setUniformLocationWith4f(_uniformEffectColor,
            _effectColorF.r, _effectColorF.g, _effectColorF.b, _effectColorF.a);
    }

    glprogram->setUniformsForBuiltins(transform);

    for(const auto &child: _children)
    {
        if(child->getTag() >= 0)
            child->updateTransform();
    }

    for (const auto& batchNode:_batchNodes)
    {
        batchNode->getTextureAtlas()->drawQuads();
    }

    CC_PROFILER_STOP("Label - draw");
}
Пример #8
0
void SimplePixelNode::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
{

    auto glProgram = _programState->getGLProgram();
    glProgram->use();

    glProgram->setUniformsForBuiltins(transform);

    glBindBuffer(GL_ARRAY_BUFFER, _vbo);
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(_vao);
    }
    else
    {
        // TODO
    }
//    glEnable (GL_BLEND);
//    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_BLEND);
    glEnable(GL_CULL_FACE);
    // shadow cover打开depth test同时在fsh中对a为0的进行discard,以保证重合交叠处不会交叠而加深。
    glEnable(GL_DEPTH_TEST);
    glDepthMask(true);
    if (_stencil) {

        glEnable(GL_STENCIL_TEST);
        // Draw floor
        glStencilFunc(GL_ALWAYS, 1, 0xFF); // Set any stencil to 1
        glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
        glStencilMask(0xFF); // Write to stencil buffer
        glDepthMask(GL_FALSE); // Don't write to depth buffer
        glClear(GL_STENCIL_BUFFER_BIT); // Clear stencil buffer (0 by default)
    }
    if (_stenciled) {

        glEnable(GL_STENCIL_TEST);
        glStencilFunc(GL_EQUAL, 1, 0xFF); // Pass test if stencil value is 1
        glStencilMask(0x00); // Don't write anything to stencil buffer
        glDepthMask(GL_TRUE); // Write to depth buffer
    }

    glDrawArrays(GL_TRIANGLES, 0, _count);


    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(0);
    }
    glDisable(GL_STENCIL_TEST);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glDisable(GL_DEPTH_TEST);
    glDepthMask(false);
    glEnable (GL_BLEND);

    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_count);
    CHECK_GL_ERROR_DEBUG();
}
Пример #9
0
void BattleLowNode::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
{

    auto glProgram = _programState->getGLProgram();
    glProgram->use();

    //    auto loc = glProgram->getUniformLocation("u_color");
    //    glProgram->setUniformLocationWith4fv(loc, &_color.r, 1);
    //    loc = glProgram->getUniformLocation("u_factor");
    //    glProgram->setUniformLocationWith1f(loc, _factor);

    //    loc = glProgram->getUniformLocation("u_texture_shadow");
    //    glProgram->setUniformLocationWith1i(loc, 1);
    //    loc = glProgram->getUniformLocation("u_light_color");
    //    glProgram->setUniformLocationWith3fv(loc, &_lightColor.r, 1);
    //    loc = glProgram->getUniformLocation("u_light_direction");
    //    glProgram->setUniformLocationWith3fv(loc, &_lightDirection.x, 1);
    //    loc = glProgram->getUniformLocation("u_speed");
    //    glProgram->setUniformLocationWith1f(loc, _speed*25);
    //    GL::bindTexture2DN(1, _textureShadow->getName());
    auto loc = glProgram->getUniformLocation("u_texture_fieldbg");
    glProgram->setUniformLocationWith1i(loc, 0);
    GL::bindTexture2DN(0, _textureFieldBg->getName());

    loc = glProgram->getUniformLocation("u_texture_buildingbg");
    glProgram->setUniformLocationWith1i(loc, 1);
    GL::bindTexture2DN(1, _textureBuildingBg->getName());

    glProgram->setUniformsForBuiltins(transform);

    glBindBuffer(GL_ARRAY_BUFFER, _vbo);
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(_vao);
    }
    else
    {
        // TODO
    }
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    /*2D的,都在同一Z位置,开启depth test会导致后画的不再绘制。
     glEnable(GL_DEPTH_TEST);
     glDepthMask(true);
     */

    glDrawArrays(GL_TRIANGLES, 0, 6);

    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(0);
    }

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,6);
    CHECK_GL_ERROR_DEBUG();
}
Пример #10
0
void Label::onDraw(const Mat4& transform, bool transformUpdated)
{
    auto glprogram = getGLProgram();
    glprogram->use();
    GL::blendFunc(_blendFunc.src, _blendFunc.dst);

    if (_shadowEnabled)
    {
        onDrawShadow(glprogram);
    }

    glprogram->setUniformsForBuiltins(transform);
    for (auto&& it : _letters)
    {
        it.second->updateTransform();
    }

    if (_currentLabelType == LabelType::TTF)
    {
        switch (_currLabelEffect) {
        case LabelEffect::OUTLINE:
            //draw text with outline
            glprogram->setUniformLocationWith4f(_uniformTextColor,
                _textColorF.r, _textColorF.g, _textColorF.b, _textColorF.a);
            glprogram->setUniformLocationWith4f(_uniformEffectColor,
                _effectColorF.r, _effectColorF.g, _effectColorF.b, _effectColorF.a);
            for (auto&& batchNode : _batchNodes)
            {
                batchNode->getTextureAtlas()->drawQuads();
            }

            //draw text without outline
            glprogram->setUniformLocationWith4f(_uniformEffectColor,
                _effectColorF.r, _effectColorF.g, _effectColorF.b, 0.f);
            break;
        case LabelEffect::GLOW:
            glprogram->setUniformLocationWith4f(_uniformEffectColor,
                _effectColorF.r, _effectColorF.g, _effectColorF.b, _effectColorF.a);
        case LabelEffect::NORMAL:
            glprogram->setUniformLocationWith4f(_uniformTextColor,
                _textColorF.r, _textColorF.g, _textColorF.b, _textColorF.a);
            break;
        default:
            break;
        }
    }

    for (auto&& batchNode : _batchNodes)
    {
        batchNode->getTextureAtlas()->drawQuads();
    }
}
Пример #11
0
bool Fish::init(int type)
{
	srand(time(NULL));
	//精灵鱼
	if(type < 25)
	{
		sprintf(fish_tmp_char,"fish_%d_0.png",type);
		fish_type = type;
	}else if(type == 25)
	{
		sprintf(fish_tmp_char,"fish_24_%d_0.png",StaticFunc::roomType + 1);
		fish_type = 25 + StaticFunc::roomType;
	}

	yy_pianyi = Vec2(yy_fish_distance * sin(0) , yy_fish_distance * - cos(0) );

	_fishSprite = Sprite::createWithSpriteFrameName(fish_tmp_char);
	_fishSprite_yy = Sprite::createWithSpriteFrameName(fish_tmp_char);
	_fishSprite_yy->setPosition((Vec2)_fishSprite->getContentSize()/2 + yy_pianyi);
	_fishSprite->addChild(_fishSprite_yy,-1);
	this->addChild(_fishSprite);
 
	sprintf(fish_tmp_char,"fish_animation_%d",fish_type);
	_fishSprite->runAction(RepeatForever::create( Animate::create(AnimationCache::getInstance()->getAnimation(fish_tmp_char))));
  
	//鱼的阴影
	auto shader_program = GLProgram::createWithFilenames("shadow.vsh", "shadow.fsh");
	shader_program->use();
	shader_program->setUniformsForBuiltins();
	_fishSprite_yy->setGLProgram(shader_program);
	_fishSprite_yy->runAction(RepeatForever::create( Animate::create(AnimationCache::getInstance()->getAnimation(fish_tmp_char))));
 
 
	//初始化数据
	bDead = false;
	fish_cur_frame = 0;

	m_iX = 0;
	m_iY = 0;
	m_iXMov = 0;
	m_iYMov = 0;

	sprintf(fish_tmp_char,"weight%d",type);
	fish_width = STATIC_DATA_INT(fish_tmp_char);

	sprintf(fish_tmp_char,"height%d",type);
	fish_hight = STATIC_DATA_INT(fish_tmp_char);
 
	return true;
}
Пример #12
0
void RoadNode::onDraw(const Mat4 &transform, uint32_t flags)
{
    auto glProgram = _roadProgram;
    glProgram->use();
    Color4F color = _roadColor;
    color.a = color.a *_opacity /255.f;
    auto loc = glProgram->getUniformLocation("u_color");
    glProgram->setUniformLocationWith4fv(loc, &color.r, 1);
    loc = glProgram->getUniformLocation("u_texture");
    glProgram->setUniformLocationWith1i(loc, 0);
    GL::bindTexture2DN(0, _roadTexture->getName());
    glProgram->setUniformsForBuiltins(transform);

    GL::blendFunc(_roadBlendFunc.src, _roadBlendFunc.dst);

    if (_dirty)
    {
        glBindBuffer(GL_ARRAY_BUFFER, _vbo);
        glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B_T2F)*_bufferCapacity, _buffer, GL_STREAM_DRAW);

        _dirty = false;
    }
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(_vao);
    }
    else
    {
        GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);

        glBindBuffer(GL_ARRAY_BUFFER, _vbo);
        // vertex
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid *)offsetof(V3F_C4B_T2F, vertices));
        // color
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B_T2F), (GLvoid *)offsetof(V3F_C4B_T2F, colors));
        // texcood
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (GLvoid *)offsetof(V3F_C4B_T2F, texCoords));
    }

    glDrawArrays(GL_TRIANGLES, 0, _bufferCount);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(0);
    }

    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _bufferCount);
    CHECK_GL_ERROR_DEBUG();
}
Пример #13
0
void HelloWorld::onDraw(const Mat4 &transform, uint32_t flags)
{

    Size visibleSize=Director::getInstance()->getVisibleSize();
    float vertices[] = {
        visibleSize.width/2, visibleSize.height/2, 0,
        visibleSize.width-100, visibleSize.height-100,0,
        100, visibleSize.height-100, 0,
        100, 100, 0,
        visibleSize.width-100, 100, 0, };
    
    float colors[] = {
        1, 1, 0, 0,// 黄
        1, 1, 1, 0,// 白
        0, 1, 0, 0,// 绿
        1, 1, 1, 0,// 白
        1, 1, 0, 0,// 黄
    };
    
    auto program=this->getGLProgram();
    program->use();
    program->setUniformsForBuiltins();
    glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, 0, vertices);
    
    glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, colors);
    glLineWidth( 5.0f );
    switch (tag) {
        case 1000:
            glDrawArrays(GL_POINTS, 0, 5);
            break;
        case 1001:
            glDrawArrays(GL_LINE_STRIP, 0, 5);
            break;
        case 1002:
            glDrawArrays(GL_LINES, 0, 5);
            break;
        case  1003:
            glDrawArrays(GL_LINE_LOOP, 0, 5);
            break;
        default:
            break;
    }
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 5);

    CHECK_GL_ERROR_DEBUG();
}
Пример #14
0
void RoadNode::onDrawGLLine(const cocos2d::Mat4 &transform, uint32_t flags)
{
    auto glProgram = _lineProgram;
    glProgram->use();
    Color4F color = _lineColor;
    color.a = color.a *_opacity /255.f;
    auto loc = glProgram->getUniformLocation("u_color");
    glProgram->setUniformLocationWith4fv(loc, &color.r, 1);
    glProgram->setUniformsForBuiltins(transform);

    if (_dirtyGLLine)
    {
        glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
        glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_T2F)*_bufferCapacityGLLine, _bufferGLLine, GL_STREAM_DRAW);
        _dirtyGLLine = false;
    }
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(_vaoGLLine);
    }
    else
    {
        glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
        GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
        // vertex
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_T2F), (GLvoid *)offsetof(V3F_T2F, vertices));
        // texcood
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V3F_T2F), (GLvoid *)offsetof(V3F_T2F, texCoords));
    }

    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glLineWidth(_lineWidth);
    glEnable(GL_DEPTH_TEST);
    glDepthMask(true);
    glDrawArrays(GL_LINES, 0, _bufferCountGLLine);

    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(0);
    }

    glBindBuffer(GL_ARRAY_BUFFER, 0);

    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLLine);
    CHECK_GL_ERROR_DEBUG();
}
Пример #15
0
void RawStencilBufferTest6::setupStencilForClippingOnPlane(GLint plane)
{
    GLint planeMask = 0x1 << plane;
    glStencilMask(planeMask);
    glStencilFunc(GL_NEVER, 0, planeMask);
    glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);
  
    Vec2 pt = Director::getInstance()->getWinSize();
    Vec2 vertices[] = {
        Vec2::ZERO,
        Vec2(pt.x, 0),
        pt,
        Vec2(0, pt.y)
    };

    auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);

    int colorLocation = glProgram->getUniformLocation("u_color");
    CHECK_GL_ERROR_DEBUG();

    Color4F color(1, 1, 1, 1);

    glProgram->use();
    glProgram->setUniformsForBuiltins();
    glProgram->setUniformLocationWith4fv(colorLocation, (GLfloat*) &color.r, 1);

    GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );

    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4);
    
    glStencilFunc(GL_NEVER, planeMask, planeMask);
    glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);
    glDisable(GL_DEPTH_TEST);
    glDepthMask(GL_FALSE);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER, _alphaThreshold);
#else
    auto program = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST_NO_MV);
    GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
    program->use();
    program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
#endif
    glFlush();
}
Пример #16
0
void AcceEffectSpace::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
{

    auto glProgram = _programState->getGLProgram();
    glProgram->use();
    auto loc = glProgram->getUniformLocation("u_color");
    glProgram->setUniformLocationWith4fv(loc, &_color.r, 1);
    loc = glProgram->getUniformLocation("u_time");
    glProgram->setUniformLocationWith1f(loc, _time);
    loc = glProgram->getUniformLocation("u_percent");
    glProgram->setUniformLocationWith1f(loc, _percent);
    loc = glProgram->getUniformLocation("u_length");
    glProgram->setUniformLocationWith1f(loc, _length);
    glProgram->setUniformsForBuiltins(transform);

    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(_vao);
    }
    else
    {
        // TODO
//        glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
//        GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
//        // vertex
//        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_T2F), (GLvoid *)offsetof(V3F_T2F, vertices));
//        // texcood
//        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V3F_T2F), (GLvoid *)offsetof(V3F_T2F, texCoords));
    }
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glDepthMask(true);

    glDrawArrays(GL_TRIANGLES, 0, _count);

    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(0);
    }

    glBindBuffer(GL_ARRAY_BUFFER, 0);

    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_count);
    CHECK_GL_ERROR_DEBUG();
}
Пример #17
0
void DrawNode::onDraw(const Mat4 &transform, uint32_t flags)
{
    auto glProgram = getGLProgram();
    glProgram->use();
    glProgram->setUniformsForBuiltins(transform);
    
    GL::blendFunc(_blendFunc.src, _blendFunc.dst);

    if (_dirty)
    {
        glBindBuffer(GL_ARRAY_BUFFER, _vbo);
        glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacity, _buffer, GL_STREAM_DRAW);
        
        _dirty = false;
    }
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(_vao);
    }
    else
    {
        GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);

        glBindBuffer(GL_ARRAY_BUFFER, _vbo);
        // vertex
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
        // color
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
        // texcood
        glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
    }

    glDrawArrays(GL_TRIANGLES, 0, _bufferCount);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(0);
    }
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _bufferCount);
    CHECK_GL_ERROR_DEBUG();
}
Пример #18
0
void Ball::onDraw(const Mat4 &transform, uint32_t flags)
{
    auto glProgram = getGLProgram();
    glProgram->use();
    glProgram->setUniformsForBuiltins(transform);
    
    glEnable(GL_CULL_FACE);
//    glCullFace(GL_FRONT);
    glEnable(GL_DEPTH_TEST);
    GL::blendFunc(_blendFunc.src, _blendFunc.dst);
    
    if (_dirty)
    {
        glBindBuffer(GL_ARRAY_BUFFER, _vbo);
        glBufferData(GL_ARRAY_BUFFER, sizeof(Vec3)*_bufferCapacity, _buffer, GL_STREAM_DRAW);
        _dirty = false;
    }
    
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(_vao);
    }
    
    GLint location1 = glProgram->getUniformLocation("u_radius");
    glProgram->setUniformLocationWith1f(location1, _radius);
    
    GLint location2 = glProgram->getUniformLocation("u_lightLocation");
    glProgram->setUniformLocationWith3f(location2, _lightLocation.x, _lightLocation.y, _lightLocation.z);
    
    GLint location3 = glProgram->getUniformLocation("u_camera");
    glProgram->setUniformLocationWith3f(location3, _cameraLocation.x, _cameraLocation.y, _cameraLocation.z);
    
    glDrawArrays(_drawMode, 0, _bufferCount);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCount);
    glDisable(GL_DEPTH_TEST);
//    glCullFace(GL_BACK);
    glDisable(GL_CULL_FACE);
    CHECK_GL_ERROR_DEBUG();
}
Пример #19
0
void StencilStateManager::drawFullScreenQuadClearStencil()
{
    Director* director = Director::getInstance();
    CCASSERT(nullptr != director, "Director is null when setting matrix stack");
    
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
    director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
    
    Vec2 vertices[] = {
        Vec2(-1.0f, -1.0f),
        Vec2(1.0f, -1.0f),
        Vec2(1.0f, 1.0f),
        Vec2(-1.0f, 1.0f)
    };
    
    auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);
    
    int colorLocation = glProgram->getUniformLocation("u_color");
    CHECK_GL_ERROR_DEBUG();
    
    Color4F color(1, 1, 1, 1);
    
    glProgram->use();
    glProgram->setUniformsForBuiltins();
    glProgram->setUniformLocationWith4fv(colorLocation, (GLfloat*) &color.r, 1);
    
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4);
    
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
Пример #20
0
// draw
void Sprite::ManualDraw()
{
    Mat4 parentTransform;
    kmGLGetMatrix(KM_GL_MODELVIEW, &parentTransform);
    _modelViewTransform = this->transform(parentTransform);
    
    auto shader = getShaderProgram();
    shader->use();
    shader->setUniformsForBuiltins(_modelViewTransform);
    kmGLPushMatrix();
    kmGLLoadMatrix(&_modelViewTransform);
    
    GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX );
    GL::blendFunc(_blendFunc.src, _blendFunc.dst);
    GL::bindTexture2D( getTexture()->getName());
    
    //
    // Attributes
    //
#define kQuadSize sizeof(_quad.bl)
    size_t offset = (size_t)&_quad;
    
    // vertex
    int diff = offsetof( V3F_C4B_T2F, vertices);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));
    
    // texCoods
    diff = offsetof( V3F_C4B_T2F, texCoords);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));
    
    // color
    diff = offsetof( V3F_C4B_T2F, colors);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));
    
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4);
    kmGLPopMatrix();
}
Пример #21
0
void ShaderNode::onDraw(const kmMat4 &transform, bool transformUpdated)
 {
    auto shader = getShaderProgram();
    shader->use();
    shader->setUniformsForBuiltins(transform);
    shader->setUniformLocationWith2f(_uniformResolution, _resolution.x, _resolution.y);
    
     //glUniform1f(_uniformTime, _time); // We uses the build-in @CC_Time[4]

	this->setCustomUniforms();
    
    GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION );

	/* Draw viewport with two triangles */
	GLfloat vertices[12] = {0, 0, _resolution.x, 0, _resolution.x, _resolution.y,
							0, 0, 0, _resolution.y, _resolution.x,_resolution.y};

    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
    
    glDrawArrays(GL_TRIANGLES, 0, 6);
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,6);
}
Пример #22
0
void Hills::onDraw(const Mat4 &transform) {
    auto glProgram = getGLProgram();
    glProgram->use();
    glProgram->setUniformsForBuiltins(transform);
    
    GL::bindTexture2D(groundTexture->getName());
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
    
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, groundVertices);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, 0, groundTexCoords);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)NumVerticies);
    
    GL::bindTexture2D(grassTexture->getName());
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
    
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, grassVertices);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, 0, grassTexCoords);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)NumVerticies);
}
Пример #23
0
void GLProgram::setUniformsForBuiltins()
{
    setUniformsForBuiltins(_director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW));
}
Пример #24
0
void Label::onDraw(const Mat4& transform, bool transformUpdated)
{
    // Optimization: Fast Dispatch
    if( _textureAtlas == NULL || (_batchNodes.size() == 1 && _textureAtlas->getTotalQuads() == 0) )
    {
        return;
    }

    auto glprogram = getGLProgram();
    glprogram->use();
    GL::blendFunc( _blendFunc.src, _blendFunc.dst );

    if (_shadowEnabled)
    {
        if (_currentLabelType == LabelType::TTF)
        {
            glprogram->setUniformLocationWith4f(_uniformTextColor,
                _shadowColor4F.r, _shadowColor4F.g, _shadowColor4F.b, _shadowColor4F.a);
            if (_currLabelEffect == LabelEffect::OUTLINE || _currLabelEffect == LabelEffect::GLOW)
            {
                glprogram->setUniformLocationWith4f(_uniformEffectColor,
                    _shadowColor4F.r, _shadowColor4F.g, _shadowColor4F.b, _shadowColor4F.a);
            }

            getGLProgram()->setUniformsForBuiltins(_shadowTransform);
            for (const auto &child : _children)
            {
                child->updateTransform();
            }
            for (const auto& batchNode : _batchNodes)
            {
                batchNode->getTextureAtlas()->drawQuads();
            }
        }
        else
        {
            Color3B oldColor = _realColor;
            GLubyte oldOPacity = _displayedOpacity;
            _displayedOpacity = _shadowOpacity;
            setColor(_shadowColor3B);

            getGLProgram()->setUniformsForBuiltins(_shadowTransform);
            for (const auto &child : _children)
            {
                child->updateTransform();
            }
            for (const auto& batchNode : _batchNodes)
            {
                batchNode->getTextureAtlas()->drawQuads();
            }

            _displayedOpacity = oldOPacity;
            setColor(oldColor);
        }
    }

    glprogram->setUniformsForBuiltins(transform);
    for(const auto &child: _children)
    {
        child->updateTransform();
    }
    
    if (_currentLabelType == LabelType::TTF)
    {
        switch (_currLabelEffect) {
            case LabelEffect::OUTLINE:
                //draw text with outline
                glprogram->setUniformLocationWith4f(_uniformTextColor,
                                                    _textColorF.r,_textColorF.g,_textColorF.b,_textColorF.a);
                glprogram->setUniformLocationWith4f(_uniformEffectColor,
                                                    _effectColorF.r, _effectColorF.g, _effectColorF.b, _effectColorF.a);
                for (const auto& batchNode:_batchNodes)
                {
                    batchNode->getTextureAtlas()->drawQuads();
                }
                
                //draw text without outline
                glprogram->setUniformLocationWith4f(_uniformEffectColor,
                                                    _effectColorF.r, _effectColorF.g, _effectColorF.b, 0.f);
                break;
            case LabelEffect::GLOW:
                glprogram->setUniformLocationWith4f(_uniformEffectColor,
                                                    _effectColorF.r, _effectColorF.g, _effectColorF.b, _effectColorF.a);
            case LabelEffect::NORMAL:
                glprogram->setUniformLocationWith4f(_uniformTextColor,
                                                    _textColorF.r,_textColorF.g,_textColorF.b,_textColorF.a);
                break;
            default:
                break;
        }
    }

    for (const auto& batchNode:_batchNodes)
    {
        batchNode->getTextureAtlas()->drawQuads();
    }
}
Пример #25
0
void ShadowCover::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
{

    auto glProgram = _programState->getGLProgram();
    glProgram->use();

    //    auto loc = glProgram->getUniformLocation("u_color");
    //    glProgram->setUniformLocationWith4fv(loc, &_color.r, 1);
    //    loc = glProgram->getUniformLocation("u_factor");
    //    glProgram->setUniformLocationWith1f(loc, _factor);

    //    loc = glProgram->getUniformLocation("u_texture_shadow");
    //    glProgram->setUniformLocationWith1i(loc, 1);
    //    loc = glProgram->getUniformLocation("u_light_color");
    //    glProgram->setUniformLocationWith3fv(loc, &_lightColor.r, 1);
    //    loc = glProgram->getUniformLocation("u_light_direction");
    //    glProgram->setUniformLocationWith3fv(loc, &_lightDirection.x, 1);
    //    loc = glProgram->getUniformLocation("u_speed");
    //    glProgram->setUniformLocationWith1f(loc, _speed*25);
    //    GL::bindTexture2DN(1, _textureShadow->getName());
    auto loc = glProgram->getUniformLocation("u_texture_shadow");
    glProgram->setUniformLocationWith1i(loc, 0);
    GL::bindTexture2DN(0, _textureShadow->getName());
/*
    loc = glProgram->getUniformLocation("u_texture_building_normalmap");
    glProgram->setUniformLocationWith1i(loc, 1);
    GL::bindTexture2DN(1, _textureBuildingNormalMap->getName());

    loc = glProgram->getUniformLocation("u_texture_be_attacked");
    glProgram->setUniformLocationWith1i(loc, 2);
    GL::bindTexture2DN(2, _textureBeAttacked->getName());

    loc = glProgram->getUniformLocation("u_texture_be_cured");
    glProgram->setUniformLocationWith1i(loc, 3);
    GL::bindTexture2DN(3, _textureBeCured->getName());

    loc = glProgram->getUniformLocation("u_para_ambient_color");
    glProgram->setUniformLocationWith4fv(loc, &_paraAmbientColor.x, 1);
    loc = glProgram->getUniformLocation("u_para_attacked_cured");
    glProgram->setUniformLocationWith4fv(loc, &_paraAttackedCured.x, 1);

    loc = glProgram->getUniformLocation("u_lights");
    glProgram->setUniformLocationWith4fv(loc, &_lights[0].x, DDConfig::NUM_LIGHT);
    loc = glProgram->getUniformLocation("u_lights_color");
    glProgram->setUniformLocationWith4fv(loc, &_lightsColor[0].x, DDConfig::NUM_LIGHT);

    loc = glProgram->getUniformLocation("u_building_animation_index");
    glProgram->setUniformLocationWith1i(loc, _buildingAnimationIndex);
*/
    glProgram->setUniformsForBuiltins(transform);

    glBindBuffer(GL_ARRAY_BUFFER, _vbo);
    if (_dirty) {
        _dirty = false;
        glBufferData(GL_ARRAY_BUFFER, sizeof(ShadowCoverVertexFormat)*DDConfig::BATTLE_NUM*DDConfig::BATTLE_NUM*6, _vertexData, GL_STREAM_DRAW);
    }
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(_vao);
    }
    else
    {
        // TODO
    }
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    // shadow cover打开depth test同时在fsh中对a为0的进行discard,以保证重合交叠处不会交叠而加深。
    glEnable(GL_DEPTH_TEST);
    glDepthMask(true);


    glDrawArrays(GL_TRIANGLES, 0, DDConfig::BATTLE_NUM*DDConfig::BATTLE_NUM*6);

    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(0);
    }

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glDisable(GL_DEPTH_TEST);
    glDepthMask(false);
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,DDConfig::BATTLE_NUM*DDConfig::BATTLE_NUM*6);
    CHECK_GL_ERROR_DEBUG();
}
Пример #26
0
void OpenGL1::onDraw(){
    Size visibleSize = Director::getInstance()->getVisibleSize();
    
    // add your codes here...
    /*!
     *  @author wuxingogo, 15-04-06 00:04:09
     *
     *  @brief  获得当前的着色器程序
     *
     *  @return nil
     */
    auto glProgram = getGLProgram();
    
    glProgram->use();
    /*!
     *  @author wuxingogo, 15-04-06 00:04:17
     *
     *  @brief  set cocos2dx default shader
     */
    glProgram->setUniformsForBuiltins();
    
    auto size = Director::getInstance()->getWinSize();
    /*!
     *  @author wuxingogo, 15-04-06 00:04:48
     *
     *  @brief  triangle vertex
     */
    float vertex[] = {
        0,0,
        size.width , 0,
        size.width / 2, size.height
    };
    /*!
     *  @author wuxingogo, 15-04-06 00:04:27
     *
     *  @brief  color vertex
     */
    float color[] = {
        0,1,0,1,
        1,0,0,1,
        0,0,1,1
    };
    /*!
     *  @author wuxingogo, 15-04-06 00:04:40
     *
     *  @brief  set addtive GL Enable, the color and vertex.
     */
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR);
    
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertex);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, color);

    
    glDrawArrays(GL_TRIANGLES, 0, 3);
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 3);
    
    CHECK_GL_ERROR_DEBUG();
    
    
}
Пример #27
0
void BattleHighNode::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
{

    auto glProgram = _programState->getGLProgram();
    glProgram->use();

    //    auto loc = glProgram->getUniformLocation("u_color");
    //    glProgram->setUniformLocationWith4fv(loc, &_color.r, 1);
    //    loc = glProgram->getUniformLocation("u_factor");
    //    glProgram->setUniformLocationWith1f(loc, _factor);

    //    loc = glProgram->getUniformLocation("u_texture_shadow");
    //    glProgram->setUniformLocationWith1i(loc, 1);
    //    loc = glProgram->getUniformLocation("u_light_color");
    //    glProgram->setUniformLocationWith3fv(loc, &_lightColor.r, 1);
    //    loc = glProgram->getUniformLocation("u_light_direction");
    //    glProgram->setUniformLocationWith3fv(loc, &_lightDirection.x, 1);
    //    loc = glProgram->getUniformLocation("u_speed");
    //    glProgram->setUniformLocationWith1f(loc, _speed*25);
    //    GL::bindTexture2DN(1, _textureShadow->getName());
    auto loc = glProgram->getUniformLocation("u_texture_building_animation");
    glProgram->setUniformLocationWith1i(loc, 0);
    GL::bindTexture2DN(0, _textureBuildingAnimation->getName());

    loc = glProgram->getUniformLocation("u_texture_building_normalmap");
    glProgram->setUniformLocationWith1i(loc, 1);
    GL::bindTexture2DN(1, _textureBuildingNormalMap->getName());

    loc = glProgram->getUniformLocation("u_texture_be_attacked");
    glProgram->setUniformLocationWith1i(loc, 2);
    GL::bindTexture2DN(2, _textureBeAttacked->getName());

    loc = glProgram->getUniformLocation("u_texture_be_cured");
    glProgram->setUniformLocationWith1i(loc, 3);
    GL::bindTexture2DN(3, _textureBeCured->getName());

    loc = glProgram->getUniformLocation("u_para_ambient_color");
    glProgram->setUniformLocationWith4fv(loc, &_paraAmbientColor.x, 1);
    loc = glProgram->getUniformLocation("u_para_attacked_cured");
    glProgram->setUniformLocationWith4fv(loc, &_paraAttackedCured.x, 1);

    loc = glProgram->getUniformLocation("u_lights");
    glProgram->setUniformLocationWith4fv(loc, &_lights[0].x, DDConfig::NUM_LIGHT);
    loc = glProgram->getUniformLocation("u_lights_color");
    glProgram->setUniformLocationWith4fv(loc, &_lightsColor[0].x, DDConfig::NUM_LIGHT);

    loc = glProgram->getUniformLocation("u_building_animation_index");
    glProgram->setUniformLocationWith1i(loc, _buildingAnimationIndex);

    glProgram->setUniformsForBuiltins(transform);

    glBindBuffer(GL_ARRAY_BUFFER, _vbo);
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(_vao);
    }
    else
    {
        // TODO
    }
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    /*2D的,都在同一Z位置,开启depth test会导致后画的不再绘制。
    glEnable(GL_DEPTH_TEST);
    glDepthMask(true);
    */

    glDrawArrays(GL_TRIANGLES, 0, 6);

    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(0);
    }

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,6);
    CHECK_GL_ERROR_DEBUG();
}