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

53 lines
1.3 KiB
C++
Raw Normal View History

2025-07-05 13:28:41 +03:30
#include <engine/graphics/texture.hpp>
#include <engine/platform/graphics/opengl/texture.hpp>
#ifdef LIGHT_PLATFORM_WINDOWS
#include <engine/platform/graphics/directx/shared_context.hpp>
#include <engine/platform/graphics/directx/texture.hpp>
#endif
#include <engine/graphics/graphics_context.hpp>
2025-07-06 16:52:50 +03:30
#include <utility>
2025-07-05 13:28:41 +03:30
namespace Light {
2025-07-06 14:02:50 +03:30
auto Texture::create(
2025-07-05 13:28:41 +03:30
unsigned int width,
unsigned int height,
unsigned int components,
unsigned char *pixels,
2025-07-06 16:52:50 +03:30
const Ref<SharedContext>& /*sharedContext*/,
2025-07-05 13:28:41 +03:30
const std::string &filePath
2025-07-06 14:02:50 +03:30
) -> Ref<Texture>
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<glTexture>(width, height, components, pixels, filePath);
2025-07-05 13:28:41 +03:30
case GraphicsAPI::DirectX:
lt_win(return create_ref<dxTexture>(
2025-07-05 13:28:41 +03:30
width,
height,
components,
pixels,
std::static_pointer_cast<dxSharedContext>(sharedContext),
filePath
);)
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 16:52:50 +03:30
Texture::Texture(std::string filePath): m_file_path(std::move(filePath))
2025-07-05 13:28:41 +03:30
{
}
} // namespace Light