Skip to content

Mipmaps are not used with linear filtering #93

Description

@KyrietS

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)
 	{

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions