forked from Shell4026/ShellEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextureLoader.cpp
More file actions
40 lines (29 loc) · 906 Bytes
/
Copy pathTextureLoader.cpp
File metadata and controls
40 lines (29 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "PCH.h"
#define STB_IMAGE_IMPLEMENTATION
#include "TextureLoader.h"
#include "Core/SObject.h"
#include <glm/ext.hpp>
namespace sh::game
{
TextureLoader::TextureLoader(render::Renderer& renderer) :
renderer(renderer)
{
}
auto TextureLoader::Load(std::string_view filename, bool bGenerateMipmap) -> render::Texture*
{
int width, height, channel;
int info = stbi_info(filename.data(), &width, &height, &channel);
if (!info)
return nullptr;
stbi_uc* pixels = stbi_load(filename.data(), &width, &height, &channel, STBI_rgb_alpha);
render::Texture::TextureFormat format;
if (channel == 3)
format = render::Texture::TextureFormat::SRGB24;
//int mip = glm::log2
render::Texture* texture = core::SObject::Create<render::Texture>(format, width, height);
texture->SetPixelData(pixels);
stbi_image_free(pixels);
texture->Build(renderer);
return texture;
}
}