Skip to content

Commit

Permalink
Add GetPresentationParameters() to get back buffer format
Browse files Browse the repository at this point in the history
  • Loading branch information
mogemimi committed Aug 7, 2018
1 parent 3c4f69f commit e1f5fbf
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 162 deletions.
5 changes: 0 additions & 5 deletions include/Pomdog/Application/GameHost.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#pragma once

#include "Pomdog/Basic/Export.hpp"
#include "Pomdog/Graphics/detail/ForwardDeclarations.hpp"
#include <memory>

namespace Pomdog {
Expand Down Expand Up @@ -45,10 +44,6 @@ class POMDOG_EXPORT GameHost : public std::enable_shared_from_this<GameHost> {
virtual std::shared_ptr<Mouse> GetMouse() = 0;

virtual std::shared_ptr<Gamepad> GetGamepad() = 0;

virtual SurfaceFormat GetBackBufferSurfaceFormat() const = 0;

virtual DepthFormat GetBackBufferDepthStencilFormat() const = 0;
};

} // namespace Pomdog
2 changes: 2 additions & 0 deletions include/Pomdog/Graphics/GraphicsDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class POMDOG_EXPORT GraphicsDevice final {

ShaderLanguage GetSupportedLanguage() const noexcept;

PresentationParameters GetPresentationParameters() const noexcept;

Detail::NativeGraphicsDevice* GetNativeGraphicsDevice();

private:
Expand Down
7 changes: 7 additions & 0 deletions src/Graphics/GraphicsDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Pomdog/Graphics/GraphicsDevice.hpp"
#include "../RenderSystem/NativeGraphicsDevice.hpp"
#include "Pomdog/Graphics/PresentationParameters.hpp"
#include "Pomdog/Utility/Assert.hpp"
#include <utility>

Expand All @@ -21,6 +22,12 @@ ShaderLanguage GraphicsDevice::GetSupportedLanguage() const noexcept
return nativeGraphicsDevice->GetSupportedLanguage();
}

PresentationParameters GraphicsDevice::GetPresentationParameters() const noexcept
{
POMDOG_ASSERT(nativeGraphicsDevice);
return nativeGraphicsDevice->GetPresentationParameters();
}

Detail::NativeGraphicsDevice* GraphicsDevice::GetNativeGraphicsDevice()
{
POMDOG_ASSERT(nativeGraphicsDevice);
Expand Down
4 changes: 0 additions & 4 deletions src/Platform.Cocoa/GameHostCocoa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ class GameHostCocoa final : public GameHost {

std::shared_ptr<Gamepad> GetGamepad() override;

SurfaceFormat GetBackBufferSurfaceFormat() const override;

DepthFormat GetBackBufferDepthStencilFormat() const override;

private:
class Impl;
std::unique_ptr<Impl> impl;
Expand Down
53 changes: 15 additions & 38 deletions src/Platform.Cocoa/GameHostCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ void Run(const std::weak_ptr<Game>& game,

std::shared_ptr<Gamepad> GetGamepad();

SurfaceFormat GetBackBufferSurfaceFormat() const noexcept;

DepthFormat GetBackBufferDepthStencilFormat() const noexcept;

private:
void GameLoop();

Expand Down Expand Up @@ -131,8 +127,6 @@ static CVReturn DisplayLinkCallback(

__weak PomdogOpenGLView* openGLView;
Duration presentationInterval;
SurfaceFormat backBufferSurfaceFormat;
DepthFormat backBufferDepthStencilFormat;
bool exitRequest;
bool displayLinkEnabled;
};
Expand All @@ -148,8 +142,6 @@ static CVReturn DisplayLinkCallback(
, window(windowIn)
, openGLView(openGLViewIn)
, presentationInterval(Duration(1) / 60)
, backBufferSurfaceFormat(presentationParameters.BackBufferFormat)
, backBufferDepthStencilFormat(presentationParameters.DepthStencilFormat)
, exitRequest(false)
, displayLinkEnabled(true)
{
Expand All @@ -168,10 +160,11 @@ static CVReturn DisplayLinkCallback(
openGLContext->SetView(openGLView);
openGLContext->MakeCurrent();

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

graphicsContext = std::make_shared<GraphicsContextGL4>(openGLContext, window);
graphicsCommandQueue = std::make_shared<Pomdog::GraphicsCommandQueue>(
graphicsCommandQueue = std::make_shared<GraphicsCommandQueue>(
std::make_unique<GraphicsCommandQueueImmediate>(graphicsContext));
openGLContext->Unlock();

Expand Down Expand Up @@ -416,13 +409,19 @@ static CVReturn DisplayLinkCallback(
{
openGLContext->Lock();
openGLContext->MakeCurrent();
{
POMDOG_ASSERT(openGLContext->NativeOpenGLContext() != nil);
[openGLContext->NativeOpenGLContext() update];

auto bounds = window->GetClientBounds();
window->ClientSizeChanged(bounds.Width, bounds.Height);
}
POMDOG_ASSERT(openGLContext->NativeOpenGLContext() != nil);
[openGLContext->NativeOpenGLContext() update];

POMDOG_ASSERT(graphicsDevice);
POMDOG_ASSERT(graphicsDevice->GetNativeGraphicsDevice());

auto nativeDevice = static_cast<GraphicsDeviceGL4*>(graphicsDevice->GetNativeGraphicsDevice());
auto bounds = window->GetClientBounds();

nativeDevice->ClientSizeChanged(bounds.Width, bounds.Height);
window->ClientSizeChanged(bounds.Width, bounds.Height);

openGLContext->Unlock();
}

Expand Down Expand Up @@ -473,16 +472,6 @@ static CVReturn DisplayLinkCallback(
return gamepad;
}

SurfaceFormat GameHostCocoa::Impl::GetBackBufferSurfaceFormat() const noexcept
{
return backBufferSurfaceFormat;
}

DepthFormat GameHostCocoa::Impl::GetBackBufferDepthStencilFormat() const noexcept
{
return backBufferDepthStencilFormat;
}

// MARK: - GameHostCocoa

GameHostCocoa::GameHostCocoa(
Expand Down Expand Up @@ -564,18 +553,6 @@ static CVReturn DisplayLinkCallback(
return impl->GetGamepad();
}

SurfaceFormat GameHostCocoa::GetBackBufferSurfaceFormat() const
{
POMDOG_ASSERT(impl);
return impl->GetBackBufferSurfaceFormat();
}

DepthFormat GameHostCocoa::GetBackBufferDepthStencilFormat() const
{
POMDOG_ASSERT(impl);
return impl->GetBackBufferDepthStencilFormat();
}

} // namespace Cocoa
} // namespace Detail
} // namespace Pomdog
4 changes: 0 additions & 4 deletions src/Platform.Cocoa/GameHostMetal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ class GameHostMetal final : public GameHost {

std::shared_ptr<Gamepad> GetGamepad() override;

SurfaceFormat GetBackBufferSurfaceFormat() const override;

DepthFormat GetBackBufferDepthStencilFormat() const override;

private:
class Impl;
std::unique_ptr<Impl> impl;
Expand Down
38 changes: 7 additions & 31 deletions src/Platform.Cocoa/GameHostMetal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ void InitializeGame(

std::shared_ptr<Gamepad> GetGamepad();

SurfaceFormat GetBackBufferSurfaceFormat() const noexcept;

DepthFormat GetBackBufferDepthStencilFormat() const noexcept;

private:
void RenderFrame();

Expand Down Expand Up @@ -135,8 +131,6 @@ void InitializeGame(

__weak MTKView* metalView;
Duration presentationInterval;
SurfaceFormat backBufferSurfaceFormat;
DepthFormat backBufferDepthStencilFormat;
bool exitRequest;
};

Expand All @@ -150,8 +144,6 @@ void InitializeGame(
, window(windowIn)
, metalView(metalViewIn)
, presentationInterval(Duration(1) / 60)
, backBufferSurfaceFormat(presentationParameters.BackBufferFormat)
, backBufferDepthStencilFormat(presentationParameters.DepthStencilFormat)
, exitRequest(false)
{
POMDOG_ASSERT(window);
Expand All @@ -161,7 +153,7 @@ void InitializeGame(

// Create graphics device
graphicsDevice = std::make_shared<GraphicsDevice>(
std::make_unique<GraphicsDeviceMetal>());
std::make_unique<GraphicsDeviceMetal>(presentationParameters));

// Get MTLDevice object
POMDOG_ASSERT(graphicsDevice);
Expand Down Expand Up @@ -369,7 +361,13 @@ void InitializeGame(

void GameHostMetal::Impl::ClientSizeChanged()
{
POMDOG_ASSERT(graphicsDevice);
POMDOG_ASSERT(graphicsDevice->GetNativeGraphicsDevice());

auto nativeDevice = static_cast<GraphicsDeviceMetal*>(graphicsDevice->GetNativeGraphicsDevice());
auto bounds = window->GetClientBounds();

nativeDevice->ClientSizeChanged(bounds.Width, bounds.Height);
window->ClientSizeChanged(bounds.Width, bounds.Height);
}

Expand Down Expand Up @@ -420,16 +418,6 @@ void InitializeGame(
return gamepad;
}

SurfaceFormat GameHostMetal::Impl::GetBackBufferSurfaceFormat() const noexcept
{
return backBufferSurfaceFormat;
}

DepthFormat GameHostMetal::Impl::GetBackBufferDepthStencilFormat() const noexcept
{
return backBufferDepthStencilFormat;
}

// MARK: GameHostMetal

GameHostMetal::GameHostMetal(
Expand Down Expand Up @@ -523,18 +511,6 @@ void InitializeGame(
return impl->GetGamepad();
}

SurfaceFormat GameHostMetal::GetBackBufferSurfaceFormat() const
{
POMDOG_ASSERT(impl);
return impl->GetBackBufferSurfaceFormat();
}

DepthFormat GameHostMetal::GetBackBufferDepthStencilFormat() const
{
POMDOG_ASSERT(impl);
return impl->GetBackBufferDepthStencilFormat();
}

} // namespace Cocoa
} // namespace Detail
} // namespace Pomdog
59 changes: 28 additions & 31 deletions src/Platform.Win32/GameHostWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,19 @@ using CreateGraphicsDeviceResult = std::tuple<
#if !defined(POMDOG_DISABLE_GL4)

class GraphicsBridgeWin32GL4 final : public GraphicsBridgeWin32 {
private:
std::shared_ptr<GraphicsDeviceGL4> graphicsDevice;

public:
void OnClientSizeChanged(int, int)
explicit GraphicsBridgeWin32GL4(const std::shared_ptr<GraphicsDeviceGL4>& graphicsDeviceIn)
: graphicsDevice(graphicsDeviceIn)
{
}

void OnClientSizeChanged(int width, int height)
{
POMDOG_ASSERT(graphicsDevice);
graphicsDevice->ClientSizeChanged(width, height);
}
};

Expand All @@ -95,18 +105,28 @@ CreateGraphicsDeviceResult CreateGraphicsDeviceGL4(

openGLContext->MakeCurrent();

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

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

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

POMDOG_ASSERT(graphicsDevice);
POMDOG_ASSERT(graphicsContext);
POMDOG_ASSERT(graphicsCommandQueue);

auto sharedNativeDevice = std::shared_ptr<GraphicsDeviceGL4>(
graphicsDevice,
static_cast<GraphicsDeviceGL4*>(graphicsDevice->GetNativeGraphicsDevice()));

POMDOG_ASSERT(sharedNativeDevice);

return CreateGraphicsDeviceResult{
std::move(graphicsDevice),
std::move(graphicsCommandQueue),
std::make_unique<GraphicsBridgeWin32GL4>(),
std::make_unique<GraphicsBridgeWin32GL4>(std::move(sharedNativeDevice)),
};
}
#endif
Expand All @@ -129,16 +149,19 @@ class GraphicsBridgeWin32Direct3D11 final : public GraphicsBridgeWin32 {

void OnClientSizeChanged(int width, int height)
{
POMDOG_ASSERT(graphicsDevice);
POMDOG_ASSERT(graphicsContext);
auto device = graphicsDevice->GetDevice();
graphicsContext->ResizeBackBuffers(device.Get(), width, height);
graphicsDevice->ClientSizeChanged(width, height);
}
};

CreateGraphicsDeviceResult CreateGraphicsDeviceDirect3D11(
const std::shared_ptr<GameWindowWin32>& window,
const PresentationParameters& presentationParameters)
{
auto nativeGraphicsDevice = std::make_unique<GraphicsDeviceDirect3D11>();
auto nativeGraphicsDevice = std::make_unique<GraphicsDeviceDirect3D11>(presentationParameters);
auto device = nativeGraphicsDevice->GetDevice();
auto deviceContext = nativeGraphicsDevice->GetDeviceContext();
auto dxgiFactory = nativeGraphicsDevice->GetDXGIFactory();
Expand Down Expand Up @@ -211,10 +234,6 @@ class GameHostWin32::Impl final {

std::shared_ptr<Gamepad> GetGamepad();

SurfaceFormat GetBackBufferSurfaceFormat() const noexcept;

DepthFormat GetBackBufferDepthStencilFormat() const noexcept;

private:
void RenderFrame(Game & game);

Expand Down Expand Up @@ -455,16 +474,6 @@ std::shared_ptr<Gamepad> GameHostWin32::Impl::GetGamepad()
return gamepad;
}

SurfaceFormat GameHostWin32::Impl::GetBackBufferSurfaceFormat() const noexcept
{
return backBufferSurfaceFormat;
}

DepthFormat GameHostWin32::Impl::GetBackBufferDepthStencilFormat() const noexcept
{
return backBufferDepthStencilFormat;
}

GameHostWin32::GameHostWin32(
const std::shared_ptr<GameWindowWin32>& window,
const std::shared_ptr<EventQueue>& eventQueue,
Expand Down Expand Up @@ -548,18 +557,6 @@ std::shared_ptr<Gamepad> GameHostWin32::GetGamepad()
return impl->GetGamepad();
}

SurfaceFormat GameHostWin32::GetBackBufferSurfaceFormat() const
{
POMDOG_ASSERT(impl);
return impl->GetBackBufferSurfaceFormat();
}

DepthFormat GameHostWin32::GetBackBufferDepthStencilFormat() const
{
POMDOG_ASSERT(impl);
return impl->GetBackBufferDepthStencilFormat();
}

} // namespace Win32
} // namespace Detail
} // namespace Pomdog
4 changes: 0 additions & 4 deletions src/Platform.Win32/GameHostWin32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ class GameHostWin32 final : public GameHost {

std::shared_ptr<Gamepad> GetGamepad() override;

SurfaceFormat GetBackBufferSurfaceFormat() const override;

DepthFormat GetBackBufferDepthStencilFormat() const override;

private:
class Impl;
std::unique_ptr<Impl> impl;
Expand Down
Loading

0 comments on commit e1f5fbf

Please sign in to comment.