Exemplo n.º 1
0
void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type)
{
#if CC_PLATFORM_IOS_METAL
    switch (type) {
        case kShaderType_PositionTextureColor_noMVP:
            p->initWithName("texturedQuadVertex", "texturedQuadFragment");
            break;
        default:
            CCLOG("not implement %d", type);
            //CC_ASSERT(false);
            break;
    }
#else//CC_PLATFORM_IOS_METAL
    switch (type) {
        case kShaderType_PositionTextureColor:
            p->initWithByteArrays(ccPositionTextureColor_vert, ccPositionTextureColor_frag);
            break;
        case kShaderType_PositionTextureColor_noMVP:
            p->initWithByteArrays(ccPositionTextureColor_noMVP_vert, ccPositionTextureColor_noMVP_frag);
            break;

        case kShaderType_PositionTextureColorAlphaTest:
            p->initWithByteArrays(ccPositionTextureColor_vert, ccPositionTextureColorAlphaTest_frag);
            break;
        case kShaderType_PositionTextureColorAlphaTestNoMV:
            p->initWithByteArrays(ccPositionTextureColor_noMVP_vert, ccPositionTextureColorAlphaTest_frag);
            break;
        case kShaderType_PositionColor:  
            p->initWithByteArrays(ccPositionColor_vert ,ccPositionColor_frag);
            break;
        case kShaderType_PositionColor_noMVP:
            p->initWithByteArrays(ccPositionTextureColor_noMVP_vert ,ccPositionColor_frag);
            break;
        case kShaderType_PositionTexture:
            p->initWithByteArrays(ccPositionTexture_vert ,ccPositionTexture_frag);
            break;
        case kShaderType_PositionTexture_uColor:
            p->initWithByteArrays(ccPositionTexture_uColor_vert, ccPositionTexture_uColor_frag);
            break;
        case kShaderType_PositionTextureA8Color:
            p->initWithByteArrays(ccPositionTextureA8Color_vert, ccPositionTextureA8Color_frag);
            break;
        case kShaderType_Position_uColor:
            p->initWithByteArrays(ccPosition_uColor_vert, ccPosition_uColor_frag);
            p->bindAttribLocation("aVertex", GLProgram::VERTEX_ATTRIB_POSITION);
            break;
        case kShaderType_PositionLengthTexureColor:
            p->initWithByteArrays(ccPositionColorLengthTexture_vert, ccPositionColorLengthTexture_frag);
            break;
        case kShaderType_LabelDistanceFieldNormal:
            p->initWithByteArrays(ccLabel_vert, ccLabelDistanceFieldNormal_frag);
            break;
        case kShaderType_LabelDistanceFieldGlow:
            p->initWithByteArrays(ccLabel_vert, ccLabelDistanceFieldGlow_frag);
            break;
        case kShaderType_LabelNormal:
            p->initWithByteArrays(ccLabel_vert, ccLabelNormal_frag);
            break;
        case kShaderType_LabelOutline:
            p->initWithByteArrays(ccLabel_vert, ccLabelOutline_frag);
            break;
        case kShaderType_3DPosition:
            p->initWithByteArrays(cc3D_PositionTex_vert, cc3D_Color_frag);
            break;
        case kShaderType_3DPositionTex:
            p->initWithByteArrays(cc3D_PositionTex_vert, cc3D_ColorTex_frag);
            break;
        case kShaderType_3DSkinPositionTex:
            p->initWithByteArrays(cc3D_SkinPositionTex_vert, cc3D_ColorTex_frag);
            break;
        case kShaderType_3DPositionNormal:
            {
                std::string def = getShaderMacrosForLight();
                p->initWithByteArrays((def + std::string(cc3D_PositionNormalTex_vert)).c_str(), (def + std::string(cc3D_ColorNormal_frag)).c_str());
            }
            break;
        case kShaderType_3DPositionNormalTex:
            {
                std::string def = getShaderMacrosForLight();
                p->initWithByteArrays((def + std::string(cc3D_PositionNormalTex_vert)).c_str(), (def + std::string(cc3D_ColorNormalTex_frag)).c_str());
            }
            break;
        case kShaderType_3DSkinPositionNormalTex:
            {
                std::string def = getShaderMacrosForLight();
                p->initWithByteArrays((def + std::string(cc3D_SkinPositionNormalTex_vert)).c_str(), (def + std::string(cc3D_ColorNormalTex_frag)).c_str());
            }
            break;
        default:
            CCLOG("cocos2d: %s:%d, error shader type", __FUNCTION__, __LINE__);
            return;
    }
#endif//CC_PLATFORM_IOS_METAL
    
    p->link();
    p->updateUniforms();
    
    CHECK_GL_ERROR_DEBUG();
}
Exemplo n.º 2
0
void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type)
{
    switch (type) {
        case kShaderType_PositionTextureColor:
            p->initWithByteArrays(ccPositionTextureColor_vert, ccPositionTextureColor_frag);
            break;
        case kShaderType_PositionTextureColor_noMVP:
            p->initWithByteArrays(ccPositionTextureColor_noMVP_vert, ccPositionTextureColor_noMVP_frag); 
            break;
        case kShaderType_PositionTextureColorAlphaTest:
            p->initWithByteArrays(ccPositionTextureColor_vert, ccPositionTextureColorAlphaTest_frag);
            break;
        case kShaderType_PositionTextureColorAlphaTestNoMV:
            p->initWithByteArrays(ccPositionTextureColor_noMVP_vert, ccPositionTextureColorAlphaTest_frag);
            break;
        case kShaderType_PositionColor:
            p->initWithByteArrays(ccPositionColor_vert ,ccPositionColor_frag);
            break;
        case kShaderType_PositionColorTextureAsPointsize:
            p->initWithByteArrays(ccPositionColorTextureAsPointsize_vert ,ccPositionColor_frag);
            break;
        case kShaderType_PositionColor_noMVP:
            p->initWithByteArrays(ccPositionTextureColor_noMVP_vert ,ccPositionColor_frag);
            break;
        case kShaderType_PositionTexture:
            p->initWithByteArrays(ccPositionTexture_vert ,ccPositionTexture_frag);
            break;
        case kShaderType_PositionTexture_uColor:
            p->initWithByteArrays(ccPositionTexture_uColor_vert, ccPositionTexture_uColor_frag);
            break;
        case kShaderType_PositionTextureA8Color:
            p->initWithByteArrays(ccPositionTextureA8Color_vert, ccPositionTextureA8Color_frag);
            break;
        case kShaderType_Position_uColor:
            p->initWithByteArrays(ccPosition_uColor_vert, ccPosition_uColor_frag);
            p->bindAttribLocation("aVertex", GLProgram::VERTEX_ATTRIB_POSITION);
            break;
        case kShaderType_PositionLengthTexureColor:
            p->initWithByteArrays(ccPositionColorLengthTexture_vert, ccPositionColorLengthTexture_frag);
            break;
        case kShaderType_LabelDistanceFieldNormal:
            p->initWithByteArrays(ccLabel_vert, ccLabelDistanceFieldNormal_frag);
            break;
        case kShaderType_LabelDistanceFieldGlow:
            p->initWithByteArrays(ccLabel_vert, ccLabelDistanceFieldGlow_frag);
            break;
        case kShaderType_UIGrayScale:
            p->initWithByteArrays(ccPositionTextureColor_noMVP_vert,
                                  ccPositionTexture_GrayScale_frag);
            break;
        case kShaderType_LabelNormal:
            p->initWithByteArrays(ccLabel_vert, ccLabelNormal_frag);
            break;
        case kShaderType_LabelOutline:
            p->initWithByteArrays(ccLabel_vert, ccLabelOutline_frag);
            break;
        case kShaderType_3DPosition:
            p->initWithByteArrays(cc3D_PositionTex_vert, cc3D_Color_frag);
            break;
        case kShaderType_3DPositionTex:
            p->initWithByteArrays(cc3D_PositionTex_vert, cc3D_ColorTex_frag);
            break;
        case kShaderType_3DSkinPositionTex:
            p->initWithByteArrays(cc3D_SkinPositionTex_vert, cc3D_ColorTex_frag);
            break;
        case kShaderType_3DPositionNormal:
            {
                std::string def = getShaderMacrosForLight();
                p->initWithByteArrays((def + std::string(cc3D_PositionNormalTex_vert)).c_str(), (def + std::string(cc3D_ColorNormal_frag)).c_str());
            }
            break;
        case kShaderType_3DPositionNormalTex:
            {
                std::string def = getShaderMacrosForLight();
                p->initWithByteArrays((def + std::string(cc3D_PositionNormalTex_vert)).c_str(), (def + std::string(cc3D_ColorNormalTex_frag)).c_str());
            }
            break;
        case kShaderType_3DSkinPositionNormalTex:
            {
                std::string def = getShaderMacrosForLight();
                p->initWithByteArrays((def + std::string(cc3D_SkinPositionNormalTex_vert)).c_str(), (def + std::string(cc3D_ColorNormalTex_frag)).c_str());
            }
            break;
        case kShaderType_3DParticleTex:
           {
                p->initWithByteArrays(cc3D_Particle_vert, cc3D_Particle_tex_frag);
           }
            break;
        case kShaderType_3DParticleColor:
            p->initWithByteArrays(cc3D_Particle_vert, cc3D_Particle_color_frag);
            break;
        case kShaderType_3DSkyBox:
            p->initWithByteArrays(cc3D_Skybox_vert, cc3D_Skybox_frag);
            break;
        case kShaderType_3DTerrain:
            p->initWithByteArrays(cc3D_Terrain_vert, cc3D_Terrain_frag);
            break;
        case kShaderType_CameraClear:
            p->initWithByteArrays(ccCameraClearVert, ccCameraClearFrag);
            break;
        default:
            CCLOG("cocos2d: %s:%d, error shader type", __FUNCTION__, __LINE__);
            return;
    }

    p->link();
    p->updateUniforms();

    CHECK_GL_ERROR_DEBUG();
}
void GLProgramCache::loadDefaultGLProgram(GLProgram *p, int type)
{
    switch (type) {
    case kShaderType_PositionTextureColor:
        p->initWithByteArrays(ccPositionTextureColor_vert, ccPositionTextureColor_frag);
        break;
    case kShaderType_PositionTextureColor_noMVP:
        p->initWithByteArrays(ccPositionTextureColor_noMVP_vert, ccPositionTextureColor_noMVP_frag);
        break;
    case kShaderType_PositionTextureColorAlphaTest:
        p->initWithByteArrays(ccPositionTextureColor_vert, ccPositionTextureColorAlphaTest_frag);
        break;
    case kShaderType_PositionTextureColorAlphaTestNoMV:
        p->initWithByteArrays(ccPositionTextureColor_noMVP_vert, ccPositionTextureColorAlphaTest_frag);
        break;
    case kShaderType_PositionColor:
        p->initWithByteArrays(ccPositionColor_vert ,ccPositionColor_frag);
        break;
    case kShaderType_PositionColorTextureAsPointsize:
        p->initWithByteArrays(ccPositionColorTextureAsPointsize_vert ,ccPositionColor_frag);
        break;
    case kShaderType_PositionColor_noMVP:
        p->initWithByteArrays(ccPositionTextureColor_noMVP_vert ,ccPositionColor_frag);
        break;
    case kShaderType_PositionTexture:
        p->initWithByteArrays(ccPositionTexture_vert ,ccPositionTexture_frag);
        break;
    case kShaderType_PositionTexture_uColor:
        p->initWithByteArrays(ccPositionTexture_uColor_vert, ccPositionTexture_uColor_frag);
        break;
    case kShaderType_PositionTextureA8Color:
        p->initWithByteArrays(ccPositionTextureA8Color_vert, ccPositionTextureA8Color_frag);
        break;
    case kShaderType_Position_uColor:
        p->initWithByteArrays(ccPosition_uColor_vert, ccPosition_uColor_frag);
        p->bindAttribLocation("aVertex", GLProgram::VERTEX_ATTRIB_POSITION);
        break;
    case kShaderType_PositionLengthTexureColor:
        p->initWithByteArrays(ccPositionColorLengthTexture_vert, ccPositionColorLengthTexture_frag);
        break;
#if CC_TARGET_PLATFORM != CC_PLATFORM_WP8
    case kShaderType_LabelDistanceFieldNormal:
        p->initWithByteArrays(ccLabel_vert, ccLabelDistanceFieldNormal_frag);
        break;
    case kShaderType_LabelDistanceFieldGlow:
        p->initWithByteArrays(ccLabel_vert, ccLabelDistanceFieldGlow_frag);
        break;
#endif
    case kShaderType_LabelNormal:
        p->initWithByteArrays(ccLabel_vert, ccLabelNormal_frag);
        break;
    case kShaderType_LabelOutline:
        p->initWithByteArrays(ccLabel_vert, ccLabelOutline_frag);
        break;
    case kShaderType_3DPosition:
        p->initWithByteArrays(cc3D_PositionTex_vert, cc3D_Color_frag);
        break;
    case kShaderType_3DPositionTex:
        p->initWithByteArrays(cc3D_PositionTex_vert, cc3D_ColorTex_frag);
        break;
    case kShaderType_3DSkinPositionTex:
        p->initWithByteArrays(cc3D_SkinPositionTex_vert, cc3D_ColorTex_frag);
        break;
    case kShaderType_3DPositionNormal:
    {
        std::string def = getShaderMacrosForLight();
        p->initWithByteArrays((def + std::string(cc3D_PositionNormalTex_vert)).c_str(), (def + std::string(cc3D_ColorNormal_frag)).c_str());
    }
    break;
    case kShaderType_3DPositionNormalTex:
    {
        std::string def = getShaderMacrosForLight();
        p->initWithByteArrays((def + std::string(cc3D_PositionNormalTex_vert)).c_str(), (def + std::string(cc3D_ColorNormalTex_frag)).c_str());
    }
    break;
    case kShaderType_3DSkinPositionNormalTex:
    {
        std::string def = getShaderMacrosForLight();
        p->initWithByteArrays((def + std::string(cc3D_SkinPositionNormalTex_vert)).c_str(), (def + std::string(cc3D_ColorNormalTex_frag)).c_str());
    }
    break;
#if CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || defined(WP8_SHADER_COMPILER)
    case kShaderType_PositionColor_noMVP_GrayScale:
        p->initWithByteArrays(ccPositionTextureColor_noMVP_vert, ccUIGrayScale_frag);
        break;
#endif
    default:
        CCLOG("cocos2d: %s:%d, error shader type", __FUNCTION__, __LINE__);
        return;
    }

    p->link();
    p->updateUniforms();

    CHECK_GL_ERROR_DEBUG();
}