i dont even know
This commit is contained in:
parent
3592ba18a0
commit
7b268efa6a
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <lol/util/Enums.hpp>
|
#include <lol/util/Enums.hpp>
|
||||||
|
#include <lol/util/NonCopyable.hpp>
|
||||||
|
|
||||||
namespace lol
|
namespace lol
|
||||||
{
|
{
|
||||||
|
@ -13,7 +14,7 @@ namespace lol
|
||||||
* This class is used to store image pixel- and metadata as well as load
|
* This class is used to store image pixel- and metadata as well as load
|
||||||
* image files from disk. It has no OpenGL equivalent
|
* image files from disk. It has no OpenGL equivalent
|
||||||
*/
|
*/
|
||||||
class Image
|
class Image : public NonCopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -42,24 +43,10 @@ namespace lol
|
||||||
*/
|
*/
|
||||||
Image(const std::string& filepath);
|
Image(const std::string& filepath);
|
||||||
|
|
||||||
|
Image(unsigned char* buffer, size_t len);
|
||||||
|
|
||||||
~Image();
|
~Image();
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Copy data of another Image
|
|
||||||
*
|
|
||||||
* @param other The Image to copy from
|
|
||||||
*/
|
|
||||||
Image(const Image& other);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Assign this Image data of another Image
|
|
||||||
*
|
|
||||||
* @param other The Image to assign from
|
|
||||||
* @return The modified Image
|
|
||||||
*/
|
|
||||||
Image& operator=(const Image& other);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the dimensions of the image
|
* @brief Get the dimensions of the image
|
||||||
*
|
*
|
||||||
|
|
|
@ -35,31 +35,28 @@ namespace lol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Image::Image(unsigned char* buffer, size_t len)
|
||||||
|
{
|
||||||
|
int width, height, channels;
|
||||||
|
pixels = stbi_load_from_memory(buffer, len, &width, &height, &channels, 0);
|
||||||
|
|
||||||
|
size = glm::uvec2(width, height);
|
||||||
|
type = PixelType::UByte;
|
||||||
|
switch (channels)
|
||||||
|
{
|
||||||
|
case 1: format = PixelFormat::R; break;
|
||||||
|
case 2: format = PixelFormat::RG; break;
|
||||||
|
case 3: format = PixelFormat::RGB; break;
|
||||||
|
case 4: format = PixelFormat::RGBA; break;
|
||||||
|
default:
|
||||||
|
format = PixelFormat::RGB;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Image::~Image()
|
Image::~Image()
|
||||||
{
|
{
|
||||||
if(pixels != nullptr)
|
if(pixels != nullptr)
|
||||||
stbi_image_free(pixels);
|
stbi_image_free(pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::Image(const Image& other)
|
|
||||||
{
|
|
||||||
size = other.size;
|
|
||||||
format = other.format;
|
|
||||||
type = other.type;
|
|
||||||
|
|
||||||
pixels = new uint8_t[size.x * size.y * SizeOf(type)];
|
|
||||||
*pixels = *other.pixels;
|
|
||||||
}
|
|
||||||
|
|
||||||
Image& Image::operator=(const Image& other)
|
|
||||||
{
|
|
||||||
size = other.size;
|
|
||||||
format = other.format;
|
|
||||||
type = other.type;
|
|
||||||
|
|
||||||
pixels = new uint8_t[size.x * size.y * SizeOf(type)];
|
|
||||||
*pixels = *other.pixels;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -52,7 +52,8 @@ namespace lol
|
||||||
Texture(TargetTexture::Texture2D)
|
Texture(TargetTexture::Texture2D)
|
||||||
{
|
{
|
||||||
glm::uvec2 imageSize = image.GetDimensions();
|
glm::uvec2 imageSize = image.GetDimensions();
|
||||||
glTexImage2D(NATIVE(target), 0, NATIVE(texFormat), imageSize.x, imageSize.y, 0, NATIVE(image.GetPixelFormat()), NATIVE(image.GetPixelType()), image.GetPixels());
|
uint8_t* pixels = image.GetPixels();
|
||||||
|
glTexImage2D(NATIVE(target), 0, NATIVE(texFormat), imageSize.x, imageSize.y, 0, NATIVE(image.GetPixelFormat()), NATIVE(image.GetPixelType()), pixels);
|
||||||
glGenerateMipmap(NATIVE(target));
|
glGenerateMipmap(NATIVE(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue