diff --git a/Apps/Liquefied/LiquefiedApp.cpp b/Apps/Liquefied/LiquefiedApp.cpp index 91b7b91..c2524a8 100644 --- a/Apps/Liquefied/LiquefiedApp.cpp +++ b/Apps/Liquefied/LiquefiedApp.cpp @@ -15,7 +15,7 @@ namespace Liq //Textures // Engine::ResourceManager::LoadTextureBuffer("TurbineTexBuf", "../Res/Assets/Textures/Liquefied/Turbine_512.png"); // Engine::ResourceManager::LoadTextureBuffer("ObstacleTexBuf", "../Res/Assets/Textures/Liquefied/Box_512.png"); - Engine::ResourceManager::LoadTextureBuffer("TestTexBuf", "../Res/Assets/Textures/Liquefied/Test_1C_1G_8Px.png"); + Engine::ResourceManager::LoadTextureBuffer("TestTexBuf", "../Res/Assets/Textures/Liquefied/Test_1C_4Px.png"); } void LiquefiedApp::AddBorderCells() const @@ -110,12 +110,16 @@ namespace Liq _spriteRenderer = new Engine::SpriteRenderer(); Engine::RenderManager::Submit(_spriteRenderer); - Engine::ResourceManager::CreateGLTextureFromBuffer("TestTexture", Engine::ResourceManager::GetTextureBuffer("TestTexBuf")); + auto* tex = Engine::ResourceManager::CreateGLTextureFromBuffer("TestTexture", Engine::ResourceManager::GetTextureBuffer("TestTexBuf")); + tex->Bind(); + tex->AddMinFilterNearest(); + tex->AddMaxFilterNearest(); + tex->Unbind(); _spriteRenderer->AddSprite ( - glm::vec2(200.0f, 200.0f), - glm::vec2(10.0f, 800.0f), + glm::vec2(64.0f, 64.0f), + glm::vec2(10.0f, 700.0f), Engine::ResourceManager::GetGLTexture("TestTexture"), Engine::ResourceManager::GetShader("SpriteShader") ); diff --git a/Engine/Debug/Logger.cpp b/Engine/Debug/Logger.cpp index 25e275c..a313290 100644 --- a/Engine/Debug/Logger.cpp +++ b/Engine/Debug/Logger.cpp @@ -20,28 +20,28 @@ namespace Engine void Logger::Info(const std::string& action, const std::string& obj, const std::string& params) { LOG(INFO) << " | " << FileManager::PadString(action, 8) - << " | " << FileManager::PadString(obj, 12) + << " | " << FileManager::PadString(obj, 13) << " | " << params; } void Logger::Warn(const std::string& action, const std::string&obj, const std::string& params) { LOG(WARNING) << " | " << FileManager::PadString(action, 8) - << " | " << FileManager::PadString(obj, 12) + << " | " << FileManager::PadString(obj, 13) << " | " << params; } void Logger::Error(const std::string& action, const std::string& obj, const std::string& params) { LOG(ERROR) << "| " << FileManager::PadString(action, 8) - << " | " << FileManager::PadString(obj, 12) + << " | " << FileManager::PadString(obj, 13) << " | " << params; } void Logger::Trace(const std::string& action, const std::string& obj, const std::string& params) { LOG(TRACE) << "| " << FileManager::PadString(action, 8) - << " | " << FileManager::PadString(obj, 12) + << " | " << FileManager::PadString(obj, 13) << " | " << params; } diff --git a/Engine/Rendering/Renderer/GridRenderer.cpp b/Engine/Rendering/Renderer/GridRenderer.cpp index d7ed31f..0a42557 100644 --- a/Engine/Rendering/Renderer/GridRenderer.cpp +++ b/Engine/Rendering/Renderer/GridRenderer.cpp @@ -113,7 +113,7 @@ namespace Engine void GridRenderer::Set(const uint32 x, const uint32 y, const glm::vec3& color) { - _colorStorage.at(x * _gridHeight + y) = glm::vec4(color, 0.0f); + _colorStorage.at(x * _gridHeight + y) = glm::vec3(color); } void GridRenderer::Reset(const uint32 x, const uint32 y) diff --git a/Engine/Rendering/Resources/GLTexture.cpp b/Engine/Rendering/Resources/GLTexture.cpp index 8d4f560..b48f273 100644 --- a/Engine/Rendering/Resources/GLTexture.cpp +++ b/Engine/Rendering/Resources/GLTexture.cpp @@ -28,22 +28,14 @@ namespace Engine _format, GL_UNSIGNED_BYTE, _textureBuffer->GetRawData())) - - // Generate mip map - GLCall(glGenerateMipmap(GL_TEXTURE_2D)) - - //Activate anisotropic filtering - GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, 0)) - GLCall(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4.0f)) - Unbind(); - Logger::Info("Created", "GLTexture", "ID: " + std::to_string(_textureID)); + Logger::Info("Created", "GLTexture", _name + " (Texture-ID: " + std::to_string(_textureID) + ")"); initStatus = EXIT_SUCCESS; } else { - Logger::Error("Failed", "TextureBuffer", "ID: " + std::to_string(_textureID)); + Logger::Error("Failed", "GLTexture", _name + " (Texture-ID: " + std::to_string(_textureID) + ")"); } return initStatus; @@ -56,33 +48,33 @@ namespace Engine GLCall(glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, _width, _height, 0, _format, type, nullptr)) Unbind(); - std::string texInfo = "( X: " + std::to_string(_width) + + std::string texInfo = " (X: " + std::to_string(_width) + ", Y: " + std::to_string(_height) + - ", Channels: " + std::to_string(_channels) + " )"; - Logger::Info("Created", "GLTexture", texInfo); + ", Channels: " + std::to_string(_channels) + ")"; + Logger::Info("Created", "GLTexture", _name + texInfo); return EXIT_SUCCESS; } // ----- Public ----- - GLTexture::GLTexture(const TextureBuffer* texBuffer) - : _initStatus(EXIT_FAILURE), _width(0), _height(0), _channels(0), _textureID(0), + GLTexture::GLTexture(std::string name, const TextureBuffer* texBuffer) + : _name(std::move(name)), _initStatus(EXIT_FAILURE), _width(0), _height(0), _channels(0), _textureID(0), _numberOfRows(0), _format(0), _ownsTexBufPointer(false), _textureBuffer(texBuffer) { _initStatus = Init(); } - GLTexture::GLTexture(const std::string& filepath, bool saveBackup, uint32 numberOfRows) - : _initStatus(EXIT_FAILURE), _width(0), _height(0), _channels(0), _textureID(0), + GLTexture::GLTexture(std::string name, const std::string& filepath, bool saveBackup, uint32 numberOfRows) + : _name(std::move(name)), _initStatus(EXIT_FAILURE), _width(0), _height(0), _channels(0), _textureID(0), _numberOfRows(numberOfRows), _format(0), _ownsTexBufPointer(true), _textureBuffer(nullptr) { _textureBuffer = new TextureBuffer(filepath, saveBackup); _initStatus = Init(); } - GLTexture::GLTexture(uint32 width, uint32 height, GLint internalFormat, GLenum format, GLenum type) - : _initStatus(EXIT_FAILURE), _width(width), _height(height), _channels(0), _textureID(0), + GLTexture::GLTexture(std::string name, uint32 width, uint32 height, GLint internalFormat, GLenum format, GLenum type) + : _name(std::move(name)), _initStatus(EXIT_FAILURE), _width(width), _height(height), _channels(0), _textureID(0), _numberOfRows(0), _format(format), _ownsTexBufPointer(false), _textureBuffer(nullptr) { _initStatus = Create(internalFormat, type); @@ -115,9 +107,19 @@ namespace Engine GLCall(glBindTexture(GL_TEXTURE_2D, 0)) } - void GLTexture::AddMinFilterMipmapLinear() const + void GLTexture::AddMipmapLinear() const { + GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, 0)) GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)) + GLCall(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)) + GLCall(glGenerateMipmap(GL_TEXTURE_2D)) + + Logger::Info("Added", "Mipmap", "Texture-ID: " + std::to_string(_textureID)); + } + + void GLTexture::AddAnisotropicFilter(const float strength) const + { + GLCall(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, strength)) } void GLTexture::AddMinFilterNearest() const diff --git a/Engine/Rendering/Resources/GLTexture.hpp b/Engine/Rendering/Resources/GLTexture.hpp index 2772476..16635d2 100644 --- a/Engine/Rendering/Resources/GLTexture.hpp +++ b/Engine/Rendering/Resources/GLTexture.hpp @@ -11,6 +11,7 @@ namespace Engine class GLTexture { private: + const std::string _name; uint32 _initStatus, _width, _height, _channels, _textureID, _numberOfRows; GLenum _format; bool _ownsTexBufPointer; @@ -20,16 +21,25 @@ namespace Engine [[nodiscard]] uint32 Create(GLint internalFormat, GLenum type); public: - explicit GLTexture(const TextureBuffer* texBuffer); - explicit GLTexture(const std::string& filepath, bool saveBackup, uint32 numberOfRows = 0); - GLTexture(uint32 width, uint32 height, GLint internalFormat, GLenum format, GLenum type); + explicit GLTexture(std::string name, const TextureBuffer* texBuffer); + explicit GLTexture(std::string name, + const std::string& filepath, + bool saveBackup, + uint32 numberOfRows = 0); + GLTexture(std::string name, + uint32 width, + uint32 height, + GLint internalFormat, + GLenum format, + GLenum type); ~GLTexture(); void Bind() const; void BindToSlot(uint32 slot) const; void Unbind() const; - void AddMinFilterMipmapLinear() const; + void AddMipmapLinear() const; + void AddAnisotropicFilter(float strength) const; void AddMinFilterNearest() const; void AddMaxFilterNearest() const; void AddMinFilterLinear() const; diff --git a/Engine/Rendering/Resources/ResourceManager.cpp b/Engine/Rendering/Resources/ResourceManager.cpp index c05694c..fcdece0 100644 --- a/Engine/Rendering/Resources/ResourceManager.cpp +++ b/Engine/Rendering/Resources/ResourceManager.cpp @@ -6,35 +6,43 @@ namespace Engine GLTexture* ResourceManager::LoadGLTexture(const std::string& name, const std::string& filepath) { - auto* glTexture = new GLTexture(filepath, false); + auto* glTexture = new GLTexture(name, filepath, false); + glTexture->Bind(); + glTexture->AddMipmapLinear(); + glTexture->AddAnisotropicFilter(4.0f); + glTexture->Unbind(); _glTextureStorage[name] = glTexture; return glTexture ; } GLTexture* ResourceManager::LoadGLTextureAtlas(const std::string& name, const std::string& filepath, uint32 numberOfRows) { - auto* glTexture = new GLTexture(filepath, false, numberOfRows); + auto* glTexture = new GLTexture(name, filepath, false, numberOfRows); + glTexture->Bind(); + glTexture->AddMipmapLinear(); + glTexture->AddAnisotropicFilter(4.0f); + glTexture->Unbind(); _glTextureStorage[name] = glTexture; return glTexture ; } GLTexture* ResourceManager::LoadGLTextureWithBackup(const std::string& name, const std::string& filepath) { - auto* glTexture = new GLTexture(filepath, true); + auto* glTexture = new GLTexture(name, filepath, true); _glTextureStorage[name] = glTexture; return glTexture ; } GLTexture* ResourceManager::CreateGLTexture(const std::string& name, const uint32 width, const uint32 height, GLint internalFormat, GLenum format, GLenum type) { - auto* glTexture = new GLTexture(width, height, internalFormat, format, type); + auto* glTexture = new GLTexture(name, width, height, internalFormat, format, type); _glTextureStorage[name] = glTexture; return glTexture; } GLTexture* ResourceManager::CreateGLTextureFromBuffer(const std::string& name, const TextureBuffer* texBuffer) { - auto* glTexture = new GLTexture(texBuffer); + auto* glTexture = new GLTexture(name, texBuffer); _glTextureStorage[name] = glTexture; return glTexture; } diff --git a/Engine/Rendering/Resources/TextureBuffer.cpp b/Engine/Rendering/Resources/TextureBuffer.cpp index fefdc16..678f21d 100644 --- a/Engine/Rendering/Resources/TextureBuffer.cpp +++ b/Engine/Rendering/Resources/TextureBuffer.cpp @@ -33,7 +33,7 @@ namespace Engine } else { - Logger::Error("Failed", "malloc", filepath); + Logger::Error("Failed", "Texturebuffer", "malloc (" + filepath + ")"); } } @@ -52,19 +52,20 @@ namespace Engine else { _format = 0; - Logger::Error("Failed", "Texture-Format", filepath); + Logger::Error("Failed", "Texturebuffer", "Format (" + filepath + ")"); } - Logger::Info("Loaded", "Texture", filepath); - std::string texInfo = "( X: " + std::to_string(_width) + + Logger::Info("Loaded", "Texturebuffer", filepath); + std::string texInfo = "(X: " + std::to_string(_width) + ", Y: " + std::to_string(_height) + - ", Channels: " + std::to_string(_channels) + " )"; + ", Channels: " + std::to_string(_channels) + + ", Format: " + std::to_string(_format) + ")"; Logger::Info("", "", texInfo); initStatus = EXIT_SUCCESS; } else { - Logger::Error("Failed", "Texture-Load", filepath); + Logger::Error("Failed", "Texturebuffer", "Loading (" + filepath + ")"); } return initStatus; @@ -122,9 +123,9 @@ namespace Engine { if(x < _width && y < _height) { - colorOut->r = *(_pxBuffer + (y * _width * 3) + (x * 3) + 0); - colorOut->g = *(_pxBuffer + (y * _width * 3) + (x * 3) + 1); - colorOut->b = *(_pxBuffer + (y * _width * 3) + (x * 3) + 2); + colorOut->r = *(_pxBuffer + (y * _width * _channels) + (x * _channels) + 0); + colorOut->g = *(_pxBuffer + (y * _width * _channels) + (x * _channels) + 1); + colorOut->b = *(_pxBuffer + (y * _width * _channels) + (x * _channels) + 2); return true; } @@ -136,9 +137,9 @@ namespace Engine { if(x < _width && y < _height) { - *(_pxBuffer + (y * _width * 3) + (x * 3) + 0) = color.r; - *(_pxBuffer + (y * _width * 3) + (x * 3) + 1) = color.g; - *(_pxBuffer + (y * _width * 3) + (x * 3) + 2) = color.b; + *(_pxBuffer + (y * _width * _channels) + (x * _channels) + 0) = color.r; + *(_pxBuffer + (y * _width * _channels) + (x * _channels) + 1) = color.g; + *(_pxBuffer + (y * _width * _channels) + (x * _channels) + 2) = color.b; return true; } @@ -210,4 +211,23 @@ namespace Engine return success; } -} + + void TextureBuffer::PrintAllValues() const + { + for(uint32 x = 0; x < _width; x++) + { + for(uint32 y = 0; y < _height; y++) + { + PxColor color = {0, 0, 0}; + if(GetPxColor(x, y, &color)) + { + Logger::Print("Color (" + std::to_string(x) + ", " + + std::to_string(y) + ") : " + + std::to_string(color.r) + ", " + + std::to_string(color.g) + ", " + + std::to_string(color.b)); + } + } + } + } +} // namespace Engine diff --git a/Engine/Rendering/Resources/TextureBuffer.hpp b/Engine/Rendering/Resources/TextureBuffer.hpp index 9618558..3efa60a 100644 --- a/Engine/Rendering/Resources/TextureBuffer.hpp +++ b/Engine/Rendering/Resources/TextureBuffer.hpp @@ -36,5 +36,7 @@ namespace Engine [[nodiscard]] bool SetPxColor(uint32 x, uint32 y, const PxColor& color) const; [[nodiscard]] bool ResetPxColor(uint32 x, uint32 y) const; [[nodiscard]] bool SubsampleArea(uint32 xpos, uint32 ypos, uint32 sampleAmount, glm::uvec3* colorOut) const; + + void PrintAllValues() const; }; } diff --git a/Res/Assets/Textures/Liquefied/Test_1C_1G_8Px.png b/Res/Assets/Textures/Liquefied/Test_1C_4Px.png similarity index 69% rename from Res/Assets/Textures/Liquefied/Test_1C_1G_8Px.png rename to Res/Assets/Textures/Liquefied/Test_1C_4Px.png index d51034b..5e05469 100644 Binary files a/Res/Assets/Textures/Liquefied/Test_1C_1G_8Px.png and b/Res/Assets/Textures/Liquefied/Test_1C_4Px.png differ