light/modules/engine/src/graphics/buffers.cpp

98 lines
2.5 KiB
C++
Raw Normal View History

2025-07-05 13:28:41 +03:30
#include <engine/graphics/buffers.hpp>
#include <engine/graphics/shared_context.hpp>
#include <engine/platform/graphics/opengl/buffers.hpp>
#ifdef LIGHT_PLATFORM_WINDOWS
#include <engine/platform/graphicsdirectx/buffers.hpp>
#include <engine/platform/graphicsdirectx/shared_context.hpp>
#endif
#include <engine/graphics/graphics_context.hpp>
namespace Light {
2025-07-06 14:02:50 +03:30
auto ConstantBuffer::create(
2025-07-05 13:28:41 +03:30
ConstantBufferIndex index,
unsigned int size,
2025-07-06 16:52:50 +03:30
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
: lt_assert(
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,
2025-07-06 16:52:50 +03:30
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
: lt_assert(
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,
2025-07-06 16:52:50 +03:30
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
: lt_assert(
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
);
2025-07-05 13:28:41 +03:30
return nullptr;
}
}
} // namespace Light