Wrecked the last commit. Async loading works now.

This commit is contained in:
William Moberg
2016-01-13 18:51:45 +01:00
parent a143ae7c85
commit 9f185a1e35
11 changed files with 194 additions and 199 deletions
+16 -11
View File
@@ -2,39 +2,44 @@
Texture::Texture(std::string path)
{
PNG image(path);
m_Image = new PNG(path);
if (image.Width == 0 && image.Height == 0 || image.Format == Image::ImageFormat::Unknown) {
image = PNG("Textures/Core/ErrorTexture.png");
if (image.Width == 0 && image.Height == 0 || image.Format == Image::ImageFormat::Unknown) {
if (m_Image->Width == 0 && m_Image->Height == 0 || m_Image->Format == Image::ImageFormat::Unknown) {
delete m_Image;
m_Image = new PNG("Textures/Core/ErrorTexture.png");
if (m_Image->Width == 0 && m_Image->Height == 0 || m_Image->Format == Image::ImageFormat::Unknown) {
LOG_ERROR("Couldn't even load the error texture. This is a dark day indeed.");
return;
}
}
this->Width = image.Width;
this->Height = image.Height;
this->Width = m_Image->Width;
this->Height = m_Image->Height;
GLint format;
switch (image.Format) {
switch (m_Image->Format) {
case Image::ImageFormat::RGB:
format = GL_RGB;
m_Format = GL_RGB;
break;
case Image::ImageFormat::RGBA:
format = GL_RGBA;
m_Format = GL_RGBA;
break;
}
}
void Texture::GlCommands()
{
// Construct the OpenGL texture
glGenTextures(1, &m_Texture);
glBindTexture(GL_TEXTURE_2D, m_Texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, format, image.Width, image.Height, 0, format, GL_UNSIGNED_BYTE, image.Data);
glTexImage2D(GL_TEXTURE_2D, 0, m_Format, Width, Height, 0, m_Format, GL_UNSIGNED_BYTE, m_Image->Data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLERROR("Texture load");
delete m_Image;
m_Image = nullptr;
}
Texture::~Texture()