Elevate Engine 1
Loading...
Searching...
No Matches
Elevate::Texture Class Referenceabstract

#include <Texture.h>

Inheritance diagram for Elevate::Texture:
Elevate::OpenGLTexture

Public Member Functions

virtual ~Texture ()=default
 
void SetData (unsigned char *data, TextureMetadata &meta)
 
virtual void * GetNativeHandle () const =0
 
bool IsTextureLoaded () const
 
bool MatchesPath (std::string pathToMatch)
 
const std::string & GetName () const
 
const std::string & GetPath () const
 
const uint32_t GetWidth () const
 
const uint32_t GetHeight () const
 
const TextureType GetUsage () const
 
const TextureMetadataGetMetadata () const
 

Static Public Member Functions

static TexturePtr CreateFromFile (const std::string &path, TextureType usage=TextureType::Diffuse)
 
static TexturePtr CreateFromColor (const glm::vec3 &color, const std::string &name, uint32_t width=1, uint32_t height=1)
 
static TexturePtr CreateFromColor (const glm::vec4 &color, const std::string &name, uint32_t width=1, uint32_t height=1)
 
static TexturePtr CreateFromData (unsigned char *data, TextureMetadata &meta)
 

Protected Member Functions

 Texture ()=default
 
 Texture (TextureMetadata meta)
 
virtual void SetDataImpl (unsigned char *data)=0
 

Protected Attributes

TextureMetadata m_meta
 

Friends

class Renderer
 

Detailed Description

Definition at line 93 of file Texture.h.

Constructor & Destructor Documentation

◆ ~Texture()

virtual Elevate::Texture::~Texture ( )
virtualdefault

◆ Texture() [1/2]

Elevate::Texture::Texture ( )
protecteddefault

◆ Texture() [2/2]

Elevate::Texture::Texture ( TextureMetadata  meta)
inlineprotected

Definition at line 124 of file Texture.h.

124: m_meta(meta) {}
TextureMetadata m_meta
Definition Texture.h:133

Member Function Documentation

◆ CreateFromColor() [1/2]

TexturePtr Elevate::Texture::CreateFromColor ( const glm::vec3 &  color,
const std::string &  name,
uint32_t  width = 1,
uint32_t  height = 1 
)
static

Definition at line 27 of file Texture.cpp.

28 {
29 size_t size = 3 * width * height;
30 std::vector<unsigned char> pixels(size);
31
32 unsigned char r = static_cast<unsigned char>(color.r);
33 unsigned char g = static_cast<unsigned char>(color.g);
34 unsigned char b = static_cast<unsigned char>(color.b);
35
36 for (int i = 0; i < size; i += 3)
37 {
38 pixels[i + 0] = r;
39 pixels[i + 1] = g;
40 pixels[i + 2] = b;
41 }
42
43 TextureMetadata meta = TextureMetadataBuilder()
44 .Name(name)
45 .Path("")
46 .size(width, height)
47 .Format(TextureFormat::RGB)
51 .Build();
52
53 return CreateFromData(pixels.data(), meta);
54 }
static TexturePtr CreateFromData(unsigned char *data, TextureMetadata &meta)
Definition Texture.cpp:87

◆ CreateFromColor() [2/2]

TexturePtr Elevate::Texture::CreateFromColor ( const glm::vec4 &  color,
const std::string &  name,
uint32_t  width = 1,
uint32_t  height = 1 
)
static

Definition at line 56 of file Texture.cpp.

57 {
58 size_t size = 4 * width * height;
59 std::vector<unsigned char> pixels(size);
60
61 unsigned char r = static_cast<unsigned char>(glm::clamp(color.r, 0.0f, 1.0f) * 255.0f);
62 unsigned char g = static_cast<unsigned char>(glm::clamp(color.g, 0.0f, 1.0f) * 255.0f);
63 unsigned char b = static_cast<unsigned char>(glm::clamp(color.b, 0.0f, 1.0f) * 255.0f);
64 unsigned char a = static_cast<unsigned char>(glm::clamp(color.a, 0.0f, 1.0f) * 255.0f);
65
66 for (int i = 0; i < size; i += 4)
67 {
68 pixels[i + 0] = r;
69 pixels[i + 1] = g;
70 pixels[i + 2] = b;
71 pixels[i + 3] = a;
72 }
73
74 TextureMetadata meta = TextureMetadataBuilder()
75 .Name(name)
76 .Path("")
77 .size(width, height)
78 .Format(TextureFormat::RGBA)
82 .Build();
83
84 return CreateFromData(pixels.data(), meta);
85 }

◆ CreateFromData()

TexturePtr Elevate::Texture::CreateFromData ( unsigned char *  data,
TextureMetadata meta 
)
static

Definition at line 87 of file Texture.cpp.

88 {
89 TexturePtr texture;
90 switch (Renderer::GetAPI())
91 {
93 texture = nullptr;
94 break;
96 texture = std::make_shared<OpenGLTexture>(data, meta);
97 break;
98 default:
99 EE_CORE_ASSERT(false, "A supported RendererAPI needs to be supported!");
100 return nullptr;
101 break;
102 }
103
104 return TextureManager::RegisterTexture(texture);
105 }
static RendererAPI::GraphicAPI GetAPI()
Definition Renderer.h:24
static TexturePtr RegisterTexture(TexturePtr texture)
std::shared_ptr< Texture > TexturePtr
Definition Texture.h:13

◆ CreateFromFile()

TexturePtr Elevate::Texture::CreateFromFile ( const std::string &  path,
TextureType  usage = TextureType::Diffuse 
)
static

Definition at line 22 of file Texture.cpp.

23 {
24 return TextureManager::LoadTextureAsync(path, usage);
25 }
static TexturePtr LoadTextureAsync(const std::string &path, TextureType usage=TextureType::Diffuse)

◆ GetHeight()

const uint32_t Elevate::Texture::GetHeight ( ) const
inline

Definition at line 117 of file Texture.h.

117{ return m_meta.Height; }

◆ GetMetadata()

const TextureMetadata & Elevate::Texture::GetMetadata ( ) const
inline

Definition at line 120 of file Texture.h.

120{ return m_meta; }

◆ GetName()

const std::string & Elevate::Texture::GetName ( ) const
inline

Definition at line 114 of file Texture.h.

114{ return m_meta.Name; }

◆ GetNativeHandle()

virtual void * Elevate::Texture::GetNativeHandle ( ) const
pure virtual

Implemented in Elevate::OpenGLTexture.

◆ GetPath()

const std::string & Elevate::Texture::GetPath ( ) const
inline

Definition at line 115 of file Texture.h.

115{ return m_meta.Path; }

◆ GetUsage()

const TextureType Elevate::Texture::GetUsage ( ) const
inline

Definition at line 118 of file Texture.h.

118{ return m_meta.Usage; }

◆ GetWidth()

const uint32_t Elevate::Texture::GetWidth ( ) const
inline

Definition at line 116 of file Texture.h.

116{ return m_meta.Width; }

◆ IsTextureLoaded()

bool Elevate::Texture::IsTextureLoaded ( ) const
inline

Definition at line 105 of file Texture.h.

105{ return m_meta.State == TextureState::Loaded; }
TextureState State
Definition Texture.h:61

◆ MatchesPath()

bool Elevate::Texture::MatchesPath ( std::string  pathToMatch)

Definition at line 15 of file Texture.cpp.

16 {
17 std::filesystem::path currentPath = std::filesystem::absolute(m_meta.Path).lexically_normal();
18 std::filesystem::path otherPath = std::filesystem::absolute(pathToMatch).lexically_normal();
19 return currentPath == otherPath;
20 }

◆ SetData()

void Elevate::Texture::SetData ( unsigned char *  data,
TextureMetadata meta 
)
inline

Definition at line 98 of file Texture.h.

98 {
99 m_meta = meta;
100 SetDataImpl(data);
101 }
virtual void SetDataImpl(unsigned char *data)=0

◆ SetDataImpl()

virtual void Elevate::Texture::SetDataImpl ( unsigned char *  data)
protectedpure virtual

Implemented in Elevate::OpenGLTexture.

Friends And Related Symbol Documentation

◆ Renderer

friend class Renderer
friend

Definition at line 135 of file Texture.h.

Member Data Documentation

◆ m_meta

TextureMetadata Elevate::Texture::m_meta
protected

Definition at line 133 of file Texture.h.


The documentation for this class was generated from the following files: