light/modules/renderer/src/texture.cpp

54 lines
1.3 KiB
C++
Raw Normal View History

#include <logger/logger.hpp>
#include <renderer/gl/texture.hpp>
#include <renderer/texture.hpp>
2025-07-05 13:28:41 +03:30
#ifdef LIGHT_PLATFORM_WINDOWS
#include <renderer/dx/shared_context.hpp>
#include <renderer/dx/texture.hpp>
2025-07-05 13:28:41 +03:30
#endif
#include <renderer/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,
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