当前位置: 首页>>代码示例>>C++>>正文


C++ ProgramFactory::CreateFromFiles方法代码示例

本文整理汇总了C++中ProgramFactory::CreateFromFiles方法的典型用法代码示例。如果您正苦于以下问题:C++ ProgramFactory::CreateFromFiles方法的具体用法?C++ ProgramFactory::CreateFromFiles怎么用?C++ ProgramFactory::CreateFromFiles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProgramFactory的用法示例。


在下文中一共展示了ProgramFactory::CreateFromFiles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mPVWMatrix

SimpleBumpMapEffect::SimpleBumpMapEffect(ProgramFactory& factory,
    Environment const& environment, bool& created)
    :
    mPVWMatrix(nullptr)
{
    created = false;

    // Load and compile the shaders.
    std::string path = environment.GetPath("SimpleBumpMap.hlsl");
#if !defined(GTE_DEV_OPENGL)
    // The flags are chosen to allow you to debug the shaders through MSVS.
    // The menu path is "Debug | Graphics | Start Diagnostics" (ALT+F5).
    factory.PushFlags();
    factory.flags =
        D3DCOMPILE_ENABLE_STRICTNESS |
        D3DCOMPILE_IEEE_STRICTNESS |
        D3DCOMPILE_DEBUG |
        D3DCOMPILE_SKIP_OPTIMIZATION;
#endif
    mProgram = factory.CreateFromFiles(path, path, "");
#if !defined(GTE_DEV_OPENGL)
    factory.PopFlags();
#endif
    if (!mProgram)
    {
        // The program factory will generate Log* messages.
        return;
    }

    // Load the textures.
    path = environment.GetPath("Bricks.png");
    mBaseTexture.reset(WICFileIO::Load(path, true));
    mBaseTexture->AutogenerateMipmaps();

    path = environment.GetPath("BricksNormal.png");
    mNormalTexture.reset(WICFileIO::Load(path, true));
    mNormalTexture->AutogenerateMipmaps();

    // Create the shader constants.
    mPVWMatrixConstant =
        std::make_shared<ConstantBuffer>(sizeof(Matrix4x4<float>), true);
    mPVWMatrix = mPVWMatrixConstant->Get<Matrix4x4<float>>();
    *mPVWMatrix = Matrix4x4<float>::Identity();

    // Create the texture sampler for mipmapping.
    mCommonSampler = std::make_shared<SamplerState>();
    mCommonSampler->filter = SamplerState::MIN_L_MAG_L_MIP_L;
    mCommonSampler->mode[0] = SamplerState::WRAP;
    mCommonSampler->mode[1] = SamplerState::WRAP;

    // Set the resources for the shaders.
    std::shared_ptr<VertexShader> vshader = mProgram->GetVShader();
    std::shared_ptr<PixelShader> pshader = mProgram->GetPShader();
    vshader->Set("PVWMatrix", mPVWMatrixConstant);
    pshader->Set("baseTexture", mBaseTexture);
    pshader->Set("normalTexture", mNormalTexture);
    pshader->Set("commonSampler", mCommonSampler);

    created = true;
}
开发者ID:c0g,项目名称:FaceWarpApp,代码行数:60,代码来源:SimpleBumpMapEffect.cpp

示例2: mPVWMatrix

BlendedTerrainEffect::BlendedTerrainEffect(ProgramFactory& factory,
    Environment const& environment, bool& created)
    :
    mPVWMatrix(nullptr),
    mFlowDirection(nullptr),
    mPowerFactor(nullptr)
{
    created = false;

    // Load and compile the shaders.
    std::string path = environment.GetPath("BlendedTerrain.hlsl");
#if !defined(GTE_DEV_OPENGL)
    // The flags are chosen to allow you to debug the shaders through MSVS.
    // The menu path is "Debug | Graphics | Start Diagnostics" (ALT+F5).
    factory.PushFlags();
    factory.flags = 
        D3DCOMPILE_ENABLE_STRICTNESS |
        D3DCOMPILE_IEEE_STRICTNESS |
        D3DCOMPILE_DEBUG |
        D3DCOMPILE_SKIP_OPTIMIZATION;
#endif
    mProgram = factory.CreateFromFiles(path, path, "");
#if !defined(GTE_DEV_OPENGL)
    factory.PopFlags();
#endif
    if (!mProgram)
    {
        // The program factory will generate Log* messages.
        return;
    }

    // Load the textures.
    path = environment.GetPath("BTGrass.png");
    mGrassTexture.reset(WICFileIO::Load(path, true));
    mGrassTexture->AutogenerateMipmaps();

    path = environment.GetPath("BTStone.png");
    mStoneTexture.reset(WICFileIO::Load(path, true));
    mStoneTexture->AutogenerateMipmaps();

    path = environment.GetPath("BTCloud.png");
    mCloudTexture.reset(WICFileIO::Load(path, true));
    mCloudTexture->AutogenerateMipmaps();

    // Create the shader constants.
    mPVWMatrixConstant = std::make_shared<ConstantBuffer>(sizeof(Matrix4x4<float>), true);
    mPVWMatrix = mPVWMatrixConstant->Get<Matrix4x4<float>>();
    *mPVWMatrix = Matrix4x4<float>::Identity();

    mFlowDirectionConstant = std::make_shared<ConstantBuffer>(sizeof(Vector2<float>), true);
    mFlowDirection = mFlowDirectionConstant->Get<Vector2<float>>();
    *mFlowDirection = { 0.0f, 0.0f };

    mPowerFactorConstant = std::make_shared<ConstantBuffer>(sizeof(float), true);
    mPowerFactor = mPowerFactorConstant->Get<float>();
    *mPowerFactor = 1.0f;

    // Create a 1-dimensional texture whose intensities are proportional to
    // height.
    unsigned int const numTexels = 256;
    mBlendTexture = std::make_shared<Texture1>(DF_R8_UNORM, numTexels);
    unsigned char* texels = mBlendTexture->Get<unsigned char>();
    for (unsigned int i = 0; i < numTexels; ++i, ++texels)
    {
        *texels = static_cast<unsigned char>(i);
    }

    // Create the texture samplers.  The common sampler uses trilinear
    // interpolation (mipmapping).  The blend sample uses bilinear
    // interpolation (no mipmapping).
    mCommonSampler = std::make_shared<SamplerState>();
    mCommonSampler->filter = SamplerState::MIN_L_MAG_L_MIP_L;
    mCommonSampler->mode[0] = SamplerState::WRAP;
    mCommonSampler->mode[1] = SamplerState::WRAP;
    mBlendSampler = std::make_shared<SamplerState>();
    mBlendSampler->filter = SamplerState::MIN_L_MAG_L_MIP_P;
    mBlendSampler->mode[0] = SamplerState::WRAP;

    // Set the resources for the shaders.
    std::shared_ptr<VertexShader> vshader = mProgram->GetVShader();
    std::shared_ptr<PixelShader> pshader = mProgram->GetPShader();
    vshader->Set("PVWMatrix", mPVWMatrixConstant);
    vshader->Set("FlowDirection", mFlowDirectionConstant);
    pshader->Set("PowerFactor", mPowerFactorConstant);
    pshader->Set("grassTexture", mGrassTexture);
    pshader->Set("stoneTexture", mStoneTexture);
    pshader->Set("blendTexture", mBlendTexture);
    pshader->Set("cloudTexture", mCloudTexture);
    pshader->Set("commonSampler", mCommonSampler);
    pshader->Set("blendSampler", mBlendSampler);

    created = true;
}
开发者ID:c0g,项目名称:FaceWarpApp,代码行数:93,代码来源:BlendedTerrainEffect.cpp


注:本文中的ProgramFactory::CreateFromFiles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。