1.Graphics/GraphicsPlatformInterface.h
#pragma once
#include "CommonHeaders.h"
#include "Renderer.h"
#include "Platform\Window.h"
namespace primal::graphics
{
struct platform_interface
{
bool(*initialize)(void);
void(*shutdown)(void);
struct {
surface(*create)(platform::window);
void(*remove)(surface_id);
void(*resize)(surface_id, u32, u32);
u32(*width)(surface_id);
u32(*height)(surface_id);
void(*render)(surface_id);
}surface;
};
}
2.Renderer.h
#pragma once
#include "CommonHeaders.h"
#include "..\Platform\Window.h"
namespace primal::graphics
{
DEFINE_TYPED_ID(surface_id);
class surface {
public:
constexpr explicit surface(surface_id id) : _id{ id } {}
constexpr surface() = default;
constexpr surface_id get_id() const { return _id; }
constexpr bool is_valid() const { return id::is_valid(_id); }
void resize(u32 width, u32 height) const;
u32 width() const;
u32 height() const;
void render() const;
private:
surface_id _id{ id::invalid_id };
};
struct render_surface {
platform::window window{};
surface surface{};
};
enum class graphics_platform :u32
{
direct3d12 = 0,
};
bool initialize(graphics_platform platform);
void shutdown();
//void render();
surface create_surface(platform::window window);
void remove_surface(surface_id id);
}
3.Renderer.cpp
#include "Renderer.h"
#include "GraphicsPlatformInterface.h"
#include "Direct3D12/D3D12Interface.h"
namespace primal::graphics
{
namespace
{
platform_interface gfx{};
bool set_platform_interface(graphics_platform platform)
{
switch (platform)
{
case graphics_platform::direct3d12:
d3d12::get_platform_interface(gfx);
break;
default:
return false;
}
return true;
}
}
bool initialize(graphics_platform platform)
{
return set_platform_interface(platform) && gfx.initialize();
}
void shutdown()
{
gfx.shutdown();
}
surface
create_surface(platform::window window)
{
return gfx.surface.create(window);
}
void
remove_surface(surface_id id)
{
assert(id::is_valid(id));
gfx.surface.remove(id);
}
void surface::resize(u32 width, u32 height) const
{
assert(is_valid());
gfx.surface.resize(_id, width, height);
}
u32 surface::width() const
{
assert(is_valid());
return gfx.surface.width(_id);
}
u32 surface::height() const
{
assert(is_valid());
return gfx.surface.height(_id);
}
void surface::render() const
{
}
}