CoriEngine
Loading...
Searching...
No Matches
Texture.cpp
Go to the documentation of this file.
1#include "Texture.hpp"
4
5namespace Cori {
6 namespace Graphics {
7 std::shared_ptr<Texture2D> Texture2D::Create(const std::shared_ptr<Image>& image) {
8 image->FlipVertically();
9 const Params params { .m_HasSemiTransparency = image->HasSemiTransparency() };
10 return Create(image->GetPixelData(), image->GetWidth(), image->GetHeight(), params);
11 }
12
13 std::shared_ptr<Texture2D> Texture2D::Create(const void* pixelData, const uint32_t width, const uint32_t height, const Params& params) {
16 {
17 auto texture = std::make_shared<Internal::OpenGLTexture2D>();
18 texture->Upload(pixelData, width, height, params);
19 CORI_CORE_ASSERT(texture->GetStatus() == AssetStatus::READY, "Failed to create Texture2D for API: {}. Check registrations and API validity.", APIEnumToName(Core::Window::GetCurrentAPI()));
20 return texture;
21 break;
22 }
24 {
25 CORI_CORE_ASSERT(false, "Unsupported Graphics API.");
26 }
28 {
29 break;
30 }
31 }
32
33 return nullptr;
34 }
35
36 std::shared_ptr<Texture2D> Texture2D::Create(const Descriptor& descriptor) {
37 const auto image = Image::Create(descriptor.m_ImagePath);
38 return Create(image);
39 }
40 }
41}
#define CORI_CORE_ASSERT(x,...)
Definition Logger.hpp:1029
static Graphics::GraphicsAPIs GetCurrentAPI()
Returns the graphical API used by this window.
Definition Window.hpp:63
static std::shared_ptr< Image > Create(const std::filesystem::path &path)
Creates an Image from the picture at the specified path.
Definition Image.cpp:189
static std::shared_ptr< Texture2D > Create(const std::shared_ptr< Image > &image)
Creates a Texture2D from the Image.
Definition Texture.cpp:7
Almost everything connected to graphics is in this namespace.
Definition Window.hpp:7
@ Vulkan
I want to support vulkan, BUT later-later.
@ None
Invalid enumerator.
@ OpenGL
The only one available for now.
static const char * APIEnumToName(const GraphicsAPIs api)
Global engine namespace.
Params to use when creating a texture.
Definition Texture.hpp:45