Пример #1
0
IShader* ResMgr::LoadShader(const std::string& vsh, const std::string& fsh)
{
    std::string key = vsh + fsh;
    std::map<std::string , IShader*>::iterator result = m_shaders.find(key);
    if(result!= m_shaders.end())
    {
        IShader* pRes = result->second;
        return pRes;
    }

    IShader* pShader = (IShader*)GetMgr()->Create("Shader");
    pShader->SetResMgr(this);
    pShader->Load(vsh.c_str(), fsh.c_str());
    m_shaders[key] = pShader;
    return pShader;
}
void XCShaderContainer::LoadShaders()
{
    IShader* binShader;

    FlatBuffersSystem& fbSystem = SystemLocator::GetInstance()->RequestSystem<FlatBuffersSystem>("FlatBuffersSystem");
    fbSystem.ParseAndLoadFile(SHADER_SCHEMA_FILEPATH, m_fbBuffer);
    fbSystem.ParseAndLoadFile(SHADER_DATA_FILEPATH, m_fbBuffer);

#if defined(LOAD_SHADERS_FROM_DATA)
    auto FBShadersRoot = GetFBRootShader(m_fbBuffer.GetBufferFromLoadedData());

    for (auto it = FBShadersRoot->FBShaders()->begin(); it != FBShadersRoot->FBShaders()->end(); ++it)
    {
        binShader = XCNEW(XCShaderHandle)();
        binShader->Load((void*) *it);
        m_Shaders[it->ShaderUsage()] = binShader;
    }
#else
    for (u32 shaderIndex = 0; shaderIndex < ShaderType_Max; shaderIndex++)
    {
        switch (shaderIndex)
        {
            case ShaderType_DEFAULT:
                {
                    binShader = new DefaultShader(m_device);

                    binShader->LoadShader();
                    binShader->CreateConstantBuffers();
                    m_Shaders[ShaderType_DEFAULT] = binShader;

                    break;
                }

            case ShaderType_SolidColor:
                {
                    binShader = new SolidColorShader(m_device);

                    binShader->LoadShader();
                    binShader->CreateConstantBuffers();
                    m_Shaders[ShaderType_SolidColor] = binShader;

                    break;
                }
            case ShaderType_LightTexture:
                {
                    binShader = new LightTextureShader(m_device);

                    binShader->LoadShader();
                    binShader->CreateConstantBuffers();
                    m_Shaders[ShaderType_LightTexture] = binShader;
                    break;
                }

            case ShaderType_REFELECTED_LIGHTTEXTURE:
                {
                    binShader = new XCShaderHandle(m_device);
                    binShader->LoadShader();
                    binShader->CreateConstantBuffers();
                    m_Shaders[ShaderType_REFELECTED_LIGHTTEXTURE] = binShader;
                    break;
                }

            case ShaderType_TerrainMultiTexture:
                {
                    binShader = new TerrainMultiTex(m_device);

                    binShader->LoadShader();
                    binShader->CreateConstantBuffers();
                    m_Shaders[ShaderType_TerrainMultiTexture] = binShader;
                    break;
                }

            case ShaderType_SimpleCubeMap:
                {
                    binShader = new CubeMapShader(m_device);

                    binShader->LoadShader();
                    binShader->CreateConstantBuffers();
                    m_Shaders[ShaderType_SimpleCubeMap] = binShader;
                    break;
                }

            case ShaderType_SkinnedCharacter:
                {
                    binShader = new SkinnedCharacterShader(m_device);

                    binShader->LoadShader();
                    binShader->CreateConstantBuffers();
                    m_Shaders[ShaderType_SkinnedCharacter] = binShader;
                    break;
                }

            case ShaderType_Max:
                break;

            default: 
                break;
        }
    }
#endif
}