示例#1
0
void RawStencilBufferTest6::setupStencilForClippingOnPlane(GLint plane)
{
    GLint planeMask = 0x1 << plane;
    glStencilMask(planeMask);
    glStencilFunc(GL_NEVER, 0, planeMask);
    glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);
    DrawPrimitives::drawSolidRect(Point::ZERO, Point(Director::getInstance()->getWinSize()), Color4F(1, 1, 1, 1));
    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 = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST);
    GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
    program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
    for(int i = 0; i < _planeCount; ++i)
    {
        _sprites.at(i)->setShaderProgram(program );
    }
#endif
    glFlush();
}
示例#2
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);
}
示例#3
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();
}
示例#4
0
void RawStencilBufferTest4::setupStencilForClippingOnPlane(GLint plane)
{
    RawStencilBufferTest::setupStencilForClippingOnPlane(plane);
    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
}
示例#5
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();
}
示例#6
0
void RawStencilBufferTest5::setupStencilForClippingOnPlane(GLint plane)
{
    RawStencilBufferTest::setupStencilForClippingOnPlane(plane);
    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 = ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_ALPHA_TEST);
    GLint alphaValueLocation = glGetUniformLocation(program->getProgram(), GLProgram::UNIFORM_NAME_ALPHA_TEST_VALUE);
    program->setUniformLocationWith1f(alphaValueLocation, _alphaThreshold);
    for(int i = 0; i < _planeCount; ++i)
    {
        _sprites.at(i)->setShaderProgram(program );
    }
#endif
}
示例#7
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();
}
示例#8
0
void PlanePixelNode::onDraw(const cocos2d::Mat4 &transform, uint32_t flags)
{

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


    auto loc = glProgram->getUniformLocation("u_move_line");
    glProgram->setUniformLocationWith1f(loc, _moveLine);
    loc = glProgram->getUniformLocation("u_move_width");
    glProgram->setUniformLocationWith1f(loc, _moveWidth);

    loc = glProgram->getUniformLocation("u_x_diff");
    glProgram->setUniformLocationWith1f(loc, _baseXDiff_current + _varyXDiff* (getOpacity()/255.f-0.5f));

    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 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_shadow_time");
    glProgram->setUniformLocationWith1f(loc, _time);

    loc = glProgram->getUniformLocation("u_unit_width");
    glProgram->setUniformLocationWith1f(loc, DDConfig::battleCubeWidth()*1.5);

    /*
    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+2)*(DDConfig::BATTLE_NUM+2), _vertexData, GL_STREAM_DRAW);
    }
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        GL::bindVAO(_vao);
    }
    else
    {
        // TODO
    }
//    glDisable(GL_BLEND);
    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);

    // TODO 画两次,第一次,较淡的色彩,且灰度,同时position 缩小一些,造成广泛的偏移,来作为迷雾的投影。 第二次,正常的画。


    glDrawArrays(GL_POINTS, 0, (DDConfig::BATTLE_NUM+2)*(DDConfig::BATTLE_NUM+2));

    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+2)*(DDConfig::BATTLE_NUM+2));
    CHECK_GL_ERROR_DEBUG();
}