diff --git a/Nuake/src/Rendering/Textures/Texture.cpp b/Nuake/src/Rendering/Textures/Texture.cpp index 217e740a..06b06bd1 100644 --- a/Nuake/src/Rendering/Textures/Texture.cpp +++ b/Nuake/src/Rendering/Textures/Texture.cpp @@ -41,7 +41,7 @@ namespace Nuake } } - Texture::Texture(glm::vec2 size, GLenum format, GLenum format2, GLenum format3, void* data) + Texture::Texture(Vector2 size, GLenum format, GLenum format2, GLenum format3, void* data) { m_RendererId = 0; m_Format = format; @@ -67,24 +67,20 @@ namespace Nuake //glGenerateMipmap(GL_TEXTURE_2D); } - Texture::Texture(Vector2 size, unsigned char* data, int len) + Texture::Texture(unsigned char* data, int len) { m_RendererId = 0; - m_Width = size.x; - m_Height = size.y; int channels = 0; m_LocalBuffer = stbi_load_from_memory(data, len, &m_Width, &m_Height, &channels, 0); glGenTextures(1, &m_RendererId); glBindTexture(GL_TEXTURE_2D, m_RendererId); glGenerateMipmap(GL_TEXTURE_2D); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 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_LOD_BIAS, -1.0f); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_Width, m_Height, 0, GL_RGB, GL_UNSIGNED_BYTE, m_LocalBuffer); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_LocalBuffer); glGenerateMipmap(GL_TEXTURE_2D); if (m_LocalBuffer) @@ -93,12 +89,12 @@ namespace Nuake } else { - const std::string msg = "failed to load texture buffer"; + const std::string msg = "Failed to load texture from buffer"; Logger::Log(msg, "texture", WARNING); } } - Texture::Texture(glm::vec2 size, msdfgen::BitmapConstRef& bitmap, bool t) + Texture::Texture(Vector2 size, msdfgen::BitmapConstRef& bitmap, bool t) { m_RendererId = 0; m_Width = size.x; @@ -110,7 +106,6 @@ namespace Nuake glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - auto pixel = bitmap(0, bitmap.height - 0 - 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)bitmap.pixels); } diff --git a/Nuake/src/Rendering/Textures/Texture.h b/Nuake/src/Rendering/Textures/Texture.h index 5654da0b..8654ca4e 100644 --- a/Nuake/src/Rendering/Textures/Texture.h +++ b/Nuake/src/Rendering/Textures/Texture.h @@ -28,10 +28,11 @@ namespace Nuake int m_BPP; // byte per pixel. public: - Texture(const std::string& path); - Texture(glm::vec2 size, msdfgen::BitmapConstRef& bitmap, bool t); - Texture(glm::vec2 size, GLenum format, GLenum format2 = 0, GLenum format3 = 0, void* data = NULL); - Texture(Vector2 size, unsigned char* data, int len); + Texture(const std::string& path); // Load texture from file + Texture(unsigned char* data, int len); // Used to load texture from a memory buffer + + Texture(Vector2 size, GLenum format, GLenum format2 = 0, GLenum format3 = 0, void* data = 0); // Used to load texture from memeory with known size + Texture(Vector2 size, msdfgen::BitmapConstRef& bitmap, bool t); // Used internally for MSDF fonts ~Texture(); void Resize(glm::vec2 size); diff --git a/Nuake/src/Resource/ModelLoader.cpp b/Nuake/src/Resource/ModelLoader.cpp index d9ab3048..7aece8b2 100644 --- a/Nuake/src/Resource/ModelLoader.cpp +++ b/Nuake/src/Resource/ModelLoader.cpp @@ -522,9 +522,19 @@ namespace Nuake uint32_t textureIndex = std::atoi(String::Split(path, '*')[1].c_str()); const aiTexture* aitexture = scene->GetEmbeddedTexture(path.c_str()); - Vector2 textureSize = Vector2(aitexture->mWidth, aitexture->mHeight); - auto texture = CreateRef(textureSize, (unsigned char*)aitexture->pcData, textureSize.x); - return texture; + Ref nuakeTexture; + if (aitexture->mHeight == 0) + { + // We are using a compression like jpeg, where width is the size of the buffer in bytes. + nuakeTexture = CreateRef((unsigned char*)aitexture->pcData, aitexture->mWidth); + } + else + { + Vector2 textureSize = Vector2(aitexture->mWidth, aitexture->mHeight); + nuakeTexture = CreateRef((unsigned char*)aitexture->pcData, textureSize.x); + } + + return nuakeTexture; } std::string texturePath = modelDir + path;