示例#1
0
ShaderVulkan::ShaderVulkan(
    ::VkDevice deviceIn,
    const ShaderBytecode& shaderBytecode,
    const ShaderCompileOptions& compileOptions)
    : device(deviceIn)
    , shaderModule(nullptr)
{
    VkShaderModuleCreateInfo moduleCreateInfo;
    moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
    moduleCreateInfo.pNext = nullptr;
    moduleCreateInfo.flags = 0;
    moduleCreateInfo.codeSize = shaderBytecode.ByteLength / sizeof(std::uint32_t);
    moduleCreateInfo.pCode = reinterpret_cast<const std::uint32_t*>(shaderBytecode.Code);

    auto result = vkCreateShaderModule(device, &moduleCreateInfo, nullptr, &shaderModule);
    if (result != VK_SUCCESS) {
        // FUS RO DAH!
        POMDOG_THROW_EXCEPTION(std::runtime_error,
            "Failed to create VkShaderModule");
    }

    ///@todo Not implemented

    // FUS RO DAH!
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
示例#2
0
OpenGLContextWin32::OpenGLContextWin32(
    HWND windowHandleIn,
    const PresentationParameters& presentationParameters)
    : windowHandle(windowHandleIn)
    , hdc(nullptr, [this](HDC hdcIn) {
        ReleaseDC(windowHandle, hdcIn);
    })
    , glrc(nullptr, [](HGLRC glrcIn) {
        if (wglGetCurrentContext() == glrcIn) {
            wglMakeCurrent(nullptr, nullptr);
        }
        wglDeleteContext(glrcIn);
    })
{
    hdc.reset(GetDC(windowHandle));

    auto formatDescriptor = ToPixelFormatDescriptor(presentationParameters);

    auto const pixelFormat = ChoosePixelFormat(hdc.get(), &formatDescriptor);

    if (0 == pixelFormat)
    {
        auto const errorCode = ::GetLastError();

        std::stringstream ss;
        ss << "Failed to call ChoosePixelFormat function."
            << "The calling thread's last-error code is "
            << std::hex << errorCode;

        POMDOG_THROW_EXCEPTION(std::runtime_error, ss.str());
    }

    if (!SetPixelFormat(hdc.get(), pixelFormat, &formatDescriptor))
    {
        auto const errorCode = ::GetLastError();

        std::stringstream ss;
        ss << "Failed to call SetPixelFormat function."
            << "The calling thread's last-error code is "
            << std::hex << errorCode;

        POMDOG_THROW_EXCEPTION(std::runtime_error, ss.str());
    }

    // Create gl context
    glrc.reset(wglCreateContext(hdc.get()));

    if (!wglMakeCurrent(hdc.get(), glrc.get()))
    {
        auto const errorCode = ::GetLastError();

        std::stringstream ss;
        ss << "Failed to call wglMakeCurrent function."
            << "The calling thread's last-error code is "
            << std::hex << errorCode;

        POMDOG_THROW_EXCEPTION(std::runtime_error, ss.str());
    }
}
示例#3
0
GameHostX11::Impl::Impl(const PresentationParameters& presentationParameters)
    : backBufferSurfaceFormat(presentationParameters.BackBufferFormat)
    , backBufferDepthStencilFormat(presentationParameters.DepthStencilFormat)
    , exitRequest(false)
{
    POMDOG_ASSERT(presentationParameters.PresentationInterval > 0);
    presentationInterval = Duration(1.0) / presentationParameters.PresentationInterval;

    x11Context = std::make_shared<X11Context>();

    auto framebufferConfig = ChooseFramebufferConfig(
        x11Context->Display, presentationParameters);

    window = std::make_shared<GameWindowX11>(
        x11Context,
        framebufferConfig,
        presentationParameters.BackBufferWidth,
        presentationParameters.BackBufferHeight);

    openGLContext = std::make_shared<OpenGLContextX11>(window, framebufferConfig);

    if (!openGLContext->IsOpenGL3Supported()) {
        POMDOG_THROW_EXCEPTION(std::runtime_error,
            "Pomdog doesn't support versions of OpenGL lower than 3.3/4.0.");
    }

    openGLContext->MakeCurrent();

    auto const errorCode = glewInit();
    if (GLEW_OK != errorCode) {
        auto description = reinterpret_cast<const char*>(glewGetErrorString(errorCode));
        POMDOG_THROW_EXCEPTION(std::runtime_error, description);
    }

    graphicsDevice = std::make_shared<GraphicsDevice>(
        std::make_unique<GraphicsDeviceGL4>(presentationParameters));

    graphicsContext = std::make_shared<GraphicsContextGL4>(openGLContext, window);

    graphicsCommandQueue = std::make_shared<GraphicsCommandQueue>(
        std::make_unique<GraphicsCommandQueueImmediate>(graphicsContext));

    audioEngine = std::make_shared<AudioEngine>();

    keyboard = std::make_unique<KeyboardX11>(x11Context->Display);
    gamepad = Detail::InputSystem::CreateGamepad();

    Detail::AssetLoaderContext loaderContext;
    loaderContext.RootDirectory = PathHelper::Join(FileSystem::GetResourceDirectoryPath(), "Content");
    loaderContext.GraphicsDevice = graphicsDevice;
    assetManager = std::make_unique<AssetManager>(std::move(loaderContext));
}
GraphicsCommandListVulkan::GraphicsCommandListVulkan()
{
    // TODO: Not implemented
    commandBuffer = nullptr;

    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
示例#5
0
std::shared_ptr<AudioClip> AssetLoader<AudioClip>::operator()(
    const AssetLoaderContext& loaderContext, const std::string& assetName)
{
    auto binaryStream = loaderContext.OpenStream(assetName);

    if (!binaryStream.Stream) {
        POMDOG_THROW_EXCEPTION(std::runtime_error,
            "Cannot open the wave file: " + assetName);
    }

    if (binaryStream.SizeInBytes < (sizeof(std::uint8_t) * 12)) {
        POMDOG_THROW_EXCEPTION(std::runtime_error,
            "The audio file is too small: " + assetName);
    }

    auto & stream = binaryStream.Stream;

    auto signature = BinaryReader::ReadArray<std::uint8_t, 12>(stream);
    if (stream.fail()) {
        POMDOG_THROW_EXCEPTION(std::runtime_error,
            "Failed to read the audio file.");
    }

    const auto fourCC = MakeFourCC(signature[0], signature[1], signature[2], signature[3]);

    if (fourCC == MakeFourCC('R', 'I', 'F', 'F')) {
        const auto fccType = MakeFourCC(signature[8], signature[9], signature[10], signature[11]);
        if (fccType == MakeFourCC('W', 'A', 'V', 'E')) {
            // This file format is RIFF waveform audio.
            auto audioClip = MSWaveAudioLoader::Load(std::move(binaryStream));
            return std::move(audioClip);
        }
    }
    else if (fourCC == MakeFourCC('O', 'g', 'g', 'S')) {
        // This file format is Ogg Vorbis.
        POMDOG_THROW_EXCEPTION(std::runtime_error,
            "Pomdog does not yet supported Ogg Vorbis format.");
    }

    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented.");
}
示例#6
0
//-----------------------------------------------------------------------
std::unique_ptr<Shader>
GraphicsDeviceGL4::CreateShader(ShaderBytecode const& shaderBytecode,
    ShaderCompileOptions const& compileOptions)
{
    switch (compileOptions.Profile.PipelineStage) {
    case ShaderPipelineStage::VertexShader: {
        return std::make_unique<VertexShaderGL4>(shaderBytecode);
    }
    case ShaderPipelineStage::PixelShader: {
        return std::make_unique<PixelShaderGL4>(shaderBytecode);
    }
    }

    POMDOG_THROW_EXCEPTION(std::domain_error, "Failed to create shader");
}
示例#7
0
X11Context::X11Context()
    : Display(nullptr)
{
    ::XInitThreads();

    Display = ::XOpenDisplay(nullptr);
    if (Display == nullptr) {
        POMDOG_THROW_EXCEPTION(std::runtime_error, "Error: XOpenDisplay");
    }

    //int screen = DefaultScreen(display);
    //::Window rootWindow = RootWindow(display, screen);

    InitializeAtoms(Display, Atoms);
}
示例#8
0
std::string FileSystem::GetAppDataDirectoryPath()
{
    TCHAR directoryName[MAX_PATH];

    auto hr = SHGetFolderPath(nullptr, CSIDL_APPDATA, nullptr, 0, directoryName);
    if (FAILED(hr)) {
        POMDOG_THROW_EXCEPTION(std::runtime_error,
            "Failed to get AppData path.");
    }

    ///@todo FIXME
    constexpr auto productName = "Pomdog";

    std::string appData(directoryName);
    return PathHelper::Join(appData, productName);
}
std::vector<EffectConstantDescription> EffectReflectionVulkan::GetConstantBuffers() const
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
示例#10
0
EffectReflectionVulkan::EffectReflectionVulkan()
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
void GraphicsCommandListVulkan::SetVertexBuffers(std::vector<VertexBufferBinding> && vertexBuffers)
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
void GraphicsCommandListVulkan::SetPipelineState(const std::shared_ptr<NativePipelineState>& pipelineState)
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
void GraphicsCommandListVulkan::SetPrimitiveTopology(PrimitiveTopology primitiveTopology)
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
示例#14
0
//-----------------------------------------------------------------------
void GraphicsContextGL4::SetRenderTargets(std::vector<std::shared_ptr<RenderTarget2D>> const& renderTargetsIn)
{
    POMDOG_ASSERT(!renderTargetsIn.empty());
    POMDOG_ASSERT(frameBuffer);

    // Bind framebuffer
    glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer->value);
    POMDOG_CHECK_ERROR_GL4("glBindFramebuffer");

    // Unbind render targets
    {
        std::size_t index = 0;
        for (auto const& renderTarget: renderTargets)
        {
            POMDOG_ASSERT(renderTarget);
            renderTarget->UnbindFromFramebuffer(ToColorAttachment(index));
            ++index;
        }
    }
    renderTargets.clear();

    // Unbind depth stencil buffer
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
    POMDOG_CHECK_ERROR_GL4("glFramebufferRenderbuffer");

    std::vector<GLenum> attachments;
    attachments.reserve(renderTargetsIn.size());
    renderTargets.reserve(renderTargetsIn.size());

    // Attach textures
    std::uint32_t index = 0;
    for (auto const& renderTarget: renderTargetsIn)
    {
        POMDOG_ASSERT(renderTarget);

        auto const nativeRenderTarget = static_cast<RenderTarget2DGL4*>(renderTarget->NativeRenderTarget2D());
        POMDOG_ASSERT(nativeRenderTarget != nullptr);
        POMDOG_ASSERT(nativeRenderTarget == dynamic_cast<RenderTarget2DGL4*>(renderTarget->NativeRenderTarget2D()));

        POMDOG_ASSERT(nativeRenderTarget);
        nativeRenderTarget->BindToFramebuffer(ToColorAttachment(index));

        renderTargets.emplace_back(renderTarget, nativeRenderTarget);

        attachments.push_back(ToColorAttachment(index));
        ++index;
    }

    // Attach depth stencil buffer
    {
        POMDOG_ASSERT(renderTargets.front());
        auto const& renderTarget = renderTargets.front();

        POMDOG_ASSERT(renderTarget);
        renderTarget->BindDepthStencilBuffer();
    }

    // Check framebuffer status
    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
        // FUS RO DAH!
        POMDOG_THROW_EXCEPTION(std::runtime_error,
                               "Failed to make complete framebuffer.");
    }

    POMDOG_ASSERT(!attachments.empty());
    POMDOG_ASSERT(attachments.size() <= static_cast<std::size_t>(std::numeric_limits<GLsizei>::max()));
    glDrawBuffers(static_cast<GLsizei>(attachments.size()), attachments.data());
    POMDOG_CHECK_ERROR_GL4("glDrawBuffers");
}
void GraphicsCommandListVulkan::SetTexture(int index, const std::shared_ptr<RenderTarget2D>& texture)
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
void GraphicsCommandListVulkan::SetTexture(int index)
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
void GraphicsCommandListVulkan::SetSampler(int index, std::shared_ptr<NativeSamplerState> && sampler)
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
void GraphicsCommandListVulkan::SetConstantBuffer(int index, const std::shared_ptr<NativeBuffer>& constantBuffer)
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
void GraphicsCommandListVulkan::SetBlendFactor(const Color& blendFactor)
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
std::size_t GraphicsCommandListVulkan::GetCount() const noexcept
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
void GraphicsCommandListVulkan::SetIndexBuffer(const std::shared_ptr<IndexBuffer>& indexBuffer)
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
void GraphicsCommandListVulkan::Reset()
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}
void GraphicsCommandListVulkan::SetRenderPass(RenderPass && renderPass)
{
    POMDOG_THROW_EXCEPTION(std::runtime_error, "Not implemented");
}