예제 #1
0
std::unique_ptr<Shader> HLSLCompiler::CreateShaderFromSource(
    GraphicsDevice & graphicsDevice,
    const void* shaderSource,
    std::size_t byteLength,
    const std::string& entryPoint,
    ShaderPipelineStage pipelineStage,
    const Optional<std::string>& currentDirectory)
{
    POMDOG_ASSERT(shaderSource != nullptr);
    POMDOG_ASSERT(byteLength > 0);
    POMDOG_ASSERT(graphicsDevice.GetSupportedLanguage() == ShaderLanguage::HLSL);

    auto nativeGraphicsDevice = graphicsDevice.GetNativeGraphicsDevice();

    ShaderBytecode shaderBytecode;
    shaderBytecode.Code = shaderSource;
    shaderBytecode.ByteLength = byteLength;

    ShaderCompileOptions compileOptions;
    compileOptions.EntryPoint = entryPoint;
    compileOptions.Profile.PipelineStage = pipelineStage;
    compileOptions.Profile.ShaderModel.Major = 4;
    compileOptions.Profile.ShaderModel.Minor = 0;
    compileOptions.Precompiled = false;

    if (currentDirectory) {
        compileOptions.CurrentDirectory = *currentDirectory;
    }

    return nativeGraphicsDevice->CreateShader(shaderBytecode, compileOptions);
}
예제 #2
0
VertexBuffer::VertexBuffer(
    GraphicsDevice & graphicsDevice,
    const void* vertices,
    std::size_t vertexCountIn,
    std::size_t strideInBytesIn,
    BufferUsage bufferUsageIn)
    : vertexCount(static_cast<decltype(vertexCount)>(vertexCountIn))
    , strideInBytes(static_cast<decltype(strideInBytes)>(strideInBytesIn))
    , bufferUsage(bufferUsageIn)
{
    POMDOG_ASSERT(vertices != nullptr);
    POMDOG_ASSERT(vertexCount > 0);
    POMDOG_ASSERT(strideInBytes > 0);

    auto sizeInBytes = vertexCount * strideInBytes;
    auto nativeDevice = graphicsDevice.GetNativeGraphicsDevice();

    POMDOG_ASSERT(nativeDevice != nullptr);
    using Detail::BufferBindMode;

    nativeVertexBuffer = nativeDevice->CreateBuffer(
        vertices, sizeInBytes, bufferUsage, BufferBindMode::VertexBuffer);

    POMDOG_ASSERT(nativeVertexBuffer);
}
예제 #3
0
std::unique_ptr<Shader> HLSLCompiler::CreateShaderFromBinary(
    GraphicsDevice & graphicsDevice,
    const void* shaderSource,
    std::size_t byteLength,
    ShaderPipelineStage pipelineStage)
{
    POMDOG_ASSERT(shaderSource != nullptr);
    POMDOG_ASSERT(byteLength > 0);
    POMDOG_ASSERT(graphicsDevice.GetSupportedLanguage() == ShaderLanguage::HLSL);

    auto nativeGraphicsDevice = graphicsDevice.GetNativeGraphicsDevice();

    ShaderBytecode shaderBytecode;
    shaderBytecode.Code = shaderSource;
    shaderBytecode.ByteLength = byteLength;

    ShaderCompileOptions compileOptions;
    compileOptions.Profile.PipelineStage = pipelineStage;
    compileOptions.Precompiled = true;

    return nativeGraphicsDevice->CreateShader(shaderBytecode, compileOptions);
}