1
0
Fork 0

Graphics/Image: dont store PixelFormat, instead define a new enum for number of channels.

The image class has a strict internal representation so we dont need "format".
PixelFormat enum can be passed to functions that modify the pixel data (like setPixels()) so that a proper convertion can be done.
This commit is contained in:
Henrik Hautakoski 2020-10-22 13:05:41 +02:00
parent 6f9b33be8f
commit f7fcc2633c
4 changed files with 53 additions and 86 deletions

View file

@ -89,11 +89,7 @@ void Texture::create(const Image& image)
enable();
if (image.getBpp() == 32) {
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
} else {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
glPixelStorei(GL_UNPACK_ALIGNMENT, image.getNumChannels());
srcFormat = pixelFormatToGL(image.getFormat());
glFormat = pixelFormatToInternal(image.getFormat());
@ -149,11 +145,7 @@ void Texture::update(vec2u pos, const Image& image)
enable();
if (image.getFormat() == PixelFormat::PF_RGBA) {
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
} else {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
glPixelStorei(GL_UNPACK_ALIGNMENT, image.getNumChannels());
format = pixelFormatToGL(image.getFormat());
@ -185,7 +177,7 @@ Image Texture::copyToImage() const
GL_UNSIGNED_BYTE,
&pixels[0]);
img.create(m_format, m_size.x, m_size.y, &pixels[0]);
img.create(m_size.x, m_size.y, &pixels[0], m_format);
disable();
}