light/modules/renderer/src/buffers.cpp

99 lines
2.4 KiB
C++
Raw Normal View History

2025-07-10 13:43:04 +03:30
#include <debug/assertions.hpp>
#include <renderer/buffers.hpp>
#include <renderer/gl/buffers.hpp>
#include <renderer/shared_context.hpp>
2025-07-05 13:28:41 +03:30
#ifdef LIGHT_PLATFORM_WINDOWS
#include <renderer/dx/buffers.hpp>
#include <renderer/dx/shared_context.hpp>
2025-07-05 13:28:41 +03:30
#endif
#include <renderer/graphics_context.hpp>
2025-07-05 13:28:41 +03:30
2025-07-11 00:05:48 +03:30
namespace lt {
2025-07-05 13:28:41 +03:30
2025-07-06 14:02:50 +03:30
auto ConstantBuffer::create(
2025-07-05 13:28:41 +03:30
ConstantBufferIndex index,
unsigned int size,
const Ref<SharedContext> & /*sharedContext*/
2025-07-06 14:02:50 +03:30
) -> Scope<ConstantBuffer>
2025-07-05 13:28:41 +03:30
{
switch (GraphicsContext::get_graphics_api())
2025-07-05 13:28:41 +03:30
{
case GraphicsAPI::OpenGL: return create_scope<glConstantBuffer>(index, size);
2025-07-05 13:28:41 +03:30
case GraphicsAPI::DirectX:
lt_win(return create_scope<dxConstantBuffer>(
2025-07-05 13:28:41 +03:30
index,
size,
std::static_pointer_cast<dxSharedContext>(sharedContext)
);)
2025-07-06 14:02:50 +03:30
default
2025-07-11 02:12:55 +03:30
: ensure(
2025-07-06 14:02:50 +03:30
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
);
2025-07-05 13:28:41 +03:30
return nullptr;
}
}
2025-07-06 14:02:50 +03:30
auto VertexBuffer::create(
2025-07-05 13:28:41 +03:30
float *vertices,
unsigned int stride,
unsigned int count,
const Ref<SharedContext> & /*sharedContext*/
2025-07-06 14:02:50 +03:30
) -> Ref<VertexBuffer>
2025-07-05 13:28:41 +03:30
{
switch (GraphicsContext::get_graphics_api())
2025-07-05 13:28:41 +03:30
{
case GraphicsAPI::OpenGL: return create_ref<glVertexBuffer>(vertices, stride, count);
2025-07-05 13:28:41 +03:30
case GraphicsAPI::DirectX:
lt_win(return create_ref<dxVertexBuffer>(
2025-07-05 13:28:41 +03:30
vertices,
stride,
count,
std::static_pointer_cast<dxSharedContext>(sharedContext)
);)
2025-07-06 14:02:50 +03:30
default
2025-07-11 02:12:55 +03:30
: ensure(
2025-07-06 14:02:50 +03:30
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
);
2025-07-05 13:28:41 +03:30
return nullptr;
}
}
2025-07-06 14:02:50 +03:30
auto IndexBuffer::create(
2025-07-05 13:28:41 +03:30
unsigned int *indices,
unsigned int count,
const Ref<SharedContext> & /*sharedContext*/
2025-07-06 14:02:50 +03:30
) -> Ref<IndexBuffer>
2025-07-05 13:28:41 +03:30
{
switch (GraphicsContext::get_graphics_api())
2025-07-05 13:28:41 +03:30
{
case GraphicsAPI::OpenGL: return create_ref<glIndexBuffer>(indices, count);
2025-07-05 13:28:41 +03:30
case GraphicsAPI::DirectX:
lt_win(return create_ref<dxIndexBuffer>(
2025-07-05 13:28:41 +03:30
indices,
count,
std::dynamic_pointer_cast<dxSharedContext>(sharedContext)
);)
2025-07-06 14:02:50 +03:30
default
2025-07-11 02:12:55 +03:30
: ensure(
2025-07-06 14:02:50 +03:30
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
);
2025-07-05 13:28:41 +03:30
return nullptr;
}
}
2025-07-11 00:05:48 +03:30
} // namespace lt