Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mipmaps are not used with linear filtering #93

Open
KyrietS opened this issue Aug 18, 2024 · 0 comments
Open

Mipmaps are not used with linear filtering #93

KyrietS opened this issue Aug 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@KyrietS
Copy link
Owner

KyrietS commented Aug 18, 2024

Dirty solution below. In general, TextureId is not enough to manipulate textures. I need to reconsider storing more data about texture once they are loaded.

diff --git a/src/Render/Renderer.cpp b/src/Render/Renderer.cpp
index c3aaec8..2055bed 100644
--- a/src/Render/Renderer.cpp
+++ b/src/Render/Renderer.cpp
@@ -292,6 +292,8 @@ int Renderer::GetBaselineHeight(float fontSize, unsigned int fontId)
 	return metrics.height;
 }
 
+static std::unordered_map<TextureId, int> s_TextureMipmaps;
+
 std::shared_ptr<TextureId> Renderer::LoadTextureFromBytes(std::span<const uint8_t> data, int width, int height)
 {
 	assert(data.size() == width * height * 4);
@@ -306,6 +308,11 @@ std::shared_ptr<TextureId> Renderer::LoadTextureFromBytes(std::span<const uint8_
         delete id;
     });
 
+	Texture2D tex{ .id = id, .width = width, .height = height, .mipmaps = 1, .format = format };
+	::GenTextureMipmaps(&tex);
+	s_TextureMipmaps[ id ] = tex.mipmaps;
+	LOG_DEBUG("Mimpams: {}", tex.mipmaps);
+
     return textureId;
 }
 
@@ -339,11 +346,14 @@ void Renderer::UnloadImage(TextureId imageId)
 {
 	Texture texture{ imageId };
 	UnloadTexture(texture);
+	s_TextureMipmaps.erase(imageId);
 }
 
 void Renderer::SetImageFilter(TextureId imageId, ImageFilter imageFilter)
 {
 	Texture texture{ imageId };
+	texture.mipmaps = s_TextureMipmaps[ imageId ];
+
 	auto rayFilter = TEXTURE_FILTER_POINT;
 	switch (imageFilter)
 	{
@KyrietS KyrietS added the bug Something isn't working label Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant