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

108 lines
3 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 {
//================================================== CONSTANT_BUFFER
//==================================================//
Scope<ConstantBuffer> ConstantBuffer::create(
2025-07-05 13:28:41 +03:30
ConstantBufferIndex index,
unsigned int size,
Ref<SharedContext> sharedContext
)
{
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)
);)
default:
lt_assert(
2025-07-05 13:28:41 +03:30
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
2025-07-05 13:28:41 +03:30
);
return nullptr;
}
}
//================================================== CONSTANT_BUFFER
//==================================================//
//================================================== VERTEX_BUFFER
//==================================================//
Ref<VertexBuffer> VertexBuffer::create(
2025-07-05 13:28:41 +03:30
float *vertices,
unsigned int stride,
unsigned int count,
Ref<SharedContext> sharedContext
)
{
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)
);)
default:
lt_assert(
2025-07-05 13:28:41 +03:30
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
2025-07-05 13:28:41 +03:30
);
return nullptr;
}
}
//================================================== VERTEX_BUFFER
//==================================================//
//======================================== INDEX_BUFFER ========================================//
Ref<IndexBuffer> IndexBuffer::create(
2025-07-05 13:28:41 +03:30
unsigned int *indices,
unsigned int count,
Ref<SharedContext> sharedContext
)
{
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)
);)
default:
lt_assert(
2025-07-05 13:28:41 +03:30
false,
"Invalid/unsupported 'GraphicsAPI' {}",
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
2025-07-05 13:28:41 +03:30
);
return nullptr;
}
}
//======================================== INDEX_BUFFER ========================================//
} // namespace Light