diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index d7c4fb9b..761e8b12 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -72,6 +72,7 @@ import client.renderer.entity.RenderManager; import client.renderer.texture.EntityTexManager; import client.renderer.texture.TextureManager; import client.renderer.texture.TextureMap; +import client.renderer.texture.TextureUtil; import client.util.FileUtils; import client.util.Message; import client.util.PerfSection; @@ -177,9 +178,11 @@ import common.util.IntHashMap; import common.util.LongHashMap; import common.util.ParticleType; import common.util.Color; +import common.util.Displayable; import common.util.Util; import common.util.Var; import common.util.HitPosition.ObjectType; +import common.util.Identifyable; import common.vars.Vars; import common.world.Chunk; import common.world.State; @@ -208,6 +211,28 @@ import common.world.World; */ public class Client implements IThreadListener { + public static enum MipmapType implements Identifyable, Displayable { + NONE("off", "Keine"), + NEAREST("nearest", "Nächster nachbar"), + LINEAR("linear", "Linear interpoliert"); + + private final String name; + private final String display; + + private MipmapType(String name, String display) { + this.name = name; + this.display = display; + } + + public String getName() { + return this.name; + } + + public String getDisplay() { + return this.display; + } + } + public static class SyncFunction implements IntFunction { public void apply(IntVar cv, int value) { Client.CLIENT.sync(value); @@ -293,6 +318,24 @@ public class Client implements IThreadListener { } } + public static class TextureBoolFunction implements BoolFunction { + public void apply(BoolVar cv, boolean value) { + Client.CLIENT.updateTexture(); + } + } + + public static class TextureFloatFunction implements FloatFunction { + public void apply(FloatVar cv, float value) { + Client.CLIENT.updateTexture(); + } + } + + public static class MipmapFunction implements EnumFunction { + public void apply(EnumVar cv, MipmapType value) { + Client.CLIENT.updateTexture(); + } + } + private interface DebugRunner { void execute(Keysym key); } @@ -497,6 +540,7 @@ public class Client implements IThreadListener { private long tick_update; private long syncLimit; + private float anisotropyMax; private float deltaX; private float deltaY; private float framerate; @@ -672,20 +716,12 @@ public class Client implements IThreadListener { public int lightMaximum = 64; @Variable(name = "gl_dynlight_chunkrange", category = CVarCategory.RENDER, min = 0, max = 64, display = "Lichtq. Sichtweite") public int lightDistance = 8; - -// int ldist_chunk_xz; -// int ldist_chunk_y; - -// "gl_tex_filter", "Texturfilterung", tex_filter, true -// "gl_tex_mipmaps", "Mipmaps", tex_miptype, MIP_NONE, MIP_NEAREST, MIP_LINEAR, "off", "nearest", "linear", "Keine", "Nächster nachbar", "Linear interpoliert", MIP_LINEAR -// "gl_tex_anisotropic", "Anisotrope Filterung", tex_aniso, 1.0f (1.0f - 16.0f) - -// float aniso_max; -// float tex_aniso; -// -// byte tex_miptype; -// byte tex_miplevel; -// byte tex_filter; + @Variable(name = "gl_tex_anisotropic", category = CVarCategory.RENDER, min = 1.0f, max = 16.0f, precision = 1, display = "Anisotrope Filterung", callback = TextureFloatFunction.class) + private float anisotopicFiltering = 16.0f; + @Variable(name = "gl_tex_mipmaps", category = CVarCategory.RENDER, display = "Mipmaps", callback = MipmapFunction.class) + private MipmapType mipmapType = MipmapType.LINEAR; + @Variable(name = "gl_tex_filter", category = CVarCategory.RENDER, display = "Texturfilterung", callback = TextureBoolFunction.class) + private boolean textureFiltering = true; public static final Client CLIENT = new Client(); @@ -837,6 +873,7 @@ public class Client implements IThreadListener { this.textureManager = new TextureManager(); this.textureManager.onReload(); this.soundManager = new SoundManager(this); + this.anisotropyMax = GL46.glGetFloat(GL46.GL_MAX_TEXTURE_MAX_ANISOTROPY); GlState.enableTexture2D(); GlState.shadeModel(GL46.GL_SMOOTH); GL46.glClearDepth(1.0D); @@ -851,9 +888,7 @@ public class Client implements IThreadListener { GL46.glMatrixMode(GL46.GL_MODELVIEW); this.textureMap = new TextureMap(); this.textureManager.loadTexture(TextureMap.BLOCKS, this.textureMap); - this.textureManager.bindTexture(TextureMap.BLOCKS); - GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MIN_FILTER, GL46.GL_NEAREST); - GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MAG_FILTER, GL46.GL_NEAREST); + this.updateTexture(); this.modelManager = new ModelManager(this.textureMap); this.modelManager.onReload(); this.renderItem = new RenderItem(this.textureManager, this.modelManager); @@ -3817,6 +3852,11 @@ public class Client implements IThreadListener { // light_calc(win->world); // } } + + public void updateTexture() { + this.textureManager.bindTexture(TextureMap.BLOCKS); + TextureUtil.setParams(this.textureFiltering, this.mipmapType != MipmapType.NONE, this.mipmapType == MipmapType.LINEAR, Math.min(this.anisotopicFiltering, this.anisotropyMax)); + } private static byte[] genTriwave(int w, int h, int color1, int color2, int color3, int color4, int color5, int color6) { byte[] data = new byte[w * h * 4]; diff --git a/client/src/main/java/client/gui/options/GuiGraphics.java b/client/src/main/java/client/gui/options/GuiGraphics.java index 25b0b450..c442ecfc 100644 --- a/client/src/main/java/client/gui/options/GuiGraphics.java +++ b/client/src/main/java/client/gui/options/GuiGraphics.java @@ -20,6 +20,19 @@ public class GuiGraphics extends GuiOptions { this.addSelector("crosshair_color_target", 242, 100, 240, 0); this.addSelector("hud_margin", 0, 140, 240, 0); + + this.addSelector("gl_dynlight_max", 0, 180, 240, 0); + this.addSelector("gl_dynlight_chunkrange", 242, 180, 240, 0); + + this.addSelector("gl_dynlight_viewdist", 0, 200, 240, 0); + this.addSelector("gl_dynlight_maxdist", 242, 200, 240, 0); + + this.addSelector("gl_light_blend", 0, 220, 240, 0); + + this.addSelector("gl_tex_filter", 0, 240, 240, 0); + this.addSelector("gl_tex_mipmaps", 242, 240, 240, 0); + + this.addSelector("gl_tex_anisotropic", 0, 260, 240, 0); super.init(width, height); } diff --git a/client/src/main/java/client/renderer/texture/DynamicTexture.java b/client/src/main/java/client/renderer/texture/DynamicTexture.java index dfa42678..298a3b05 100755 --- a/client/src/main/java/client/renderer/texture/DynamicTexture.java +++ b/client/src/main/java/client/renderer/texture/DynamicTexture.java @@ -28,7 +28,7 @@ public class DynamicTexture extends Texture { public void updateTexture() { GlState.bindTexture(this.getGlTextureId()); - TextureUtil.uploadTexture(this.data, this.width, this.height, 0, 0); + TextureUtil.uploadTexture(this.data, this.width, this.height, 0, 0, true); } public int[] getData() { diff --git a/client/src/main/java/client/renderer/texture/Sprite.java b/client/src/main/java/client/renderer/texture/Sprite.java index 135eafb5..a7bc9aa4 100755 --- a/client/src/main/java/client/renderer/texture/Sprite.java +++ b/client/src/main/java/client/renderer/texture/Sprite.java @@ -121,7 +121,7 @@ public class Sprite if(this.tickedTexture != null) { int[] data = this.framesTextureData.get(0); this.tickedTexture.renderStep(data); - TextureUtil.uploadTexture(data, this.width, this.height, this.originX, this.originY); + TextureUtil.uploadTexture(data, this.width, this.height, this.originX, this.originY, false); return; } @@ -135,7 +135,7 @@ public class Sprite if (i != k && k >= 0 && k < this.framesTextureData.size()) { - TextureUtil.uploadTexture(this.framesTextureData.get(k), this.width, this.height, this.originX, this.originY); + TextureUtil.uploadTexture(this.framesTextureData.get(k), this.width, this.height, this.originX, this.originY, false); } } } diff --git a/client/src/main/java/client/renderer/texture/TextureMap.java b/client/src/main/java/client/renderer/texture/TextureMap.java index eaf5450b..18c9c9d6 100755 --- a/client/src/main/java/client/renderer/texture/TextureMap.java +++ b/client/src/main/java/client/renderer/texture/TextureMap.java @@ -6,6 +6,9 @@ import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Set; + +import org.lwjgl.opengl.GL46; + import java.util.Map.Entry; import client.init.RenderRegistry; @@ -152,7 +155,7 @@ public class TextureMap extends Texture map.remove(s); this.mapUploadedSprites.put(s, textureatlassprite2); - TextureUtil.uploadTexture(textureatlassprite2.getFrameTextureData(0), textureatlassprite2.getIconWidth(), textureatlassprite2.getIconHeight(), textureatlassprite2.getOriginX(), textureatlassprite2.getOriginY()); + TextureUtil.uploadTexture(textureatlassprite2.getFrameTextureData(0), textureatlassprite2.getIconWidth(), textureatlassprite2.getIconHeight(), textureatlassprite2.getOriginX(), textureatlassprite2.getOriginY(), false); if (textureatlassprite2.isAnimated()) { @@ -186,6 +189,8 @@ public class TextureMap extends Texture { textureatlassprite.updateAnimation(); } + + GL46.glGenerateMipmap(GL46.GL_TEXTURE_2D); } private Sprite registerSprite(String location) diff --git a/client/src/main/java/client/renderer/texture/TextureUtil.java b/client/src/main/java/client/renderer/texture/TextureUtil.java index 9cf8a60f..ebc0b435 100755 --- a/client/src/main/java/client/renderer/texture/TextureUtil.java +++ b/client/src/main/java/client/renderer/texture/TextureUtil.java @@ -21,14 +21,20 @@ public class TextureUtil private static final IntBuffer BUFFER = ByteBuffer.allocateDirect(4194304 << 2).order(ByteOrder.nativeOrder()).asIntBuffer(); public static final DynamicTexture MISSING = new DynamicTexture(16, 16); public static final int[] MISSING_DATA = MISSING.getData(); - - public static void uploadTexture(int[] data, int w, int h, int x, int y) - { - int i = 4194304 / w; - GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MIN_FILTER, GL46.GL_NEAREST); - GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MAG_FILTER, GL46.GL_NEAREST); + + public static void setParams(boolean filter, boolean mips, boolean linear, float aniso) { + GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MIN_FILTER, filter ? (mips ? (linear ? GL46.GL_LINEAR_MIPMAP_LINEAR : GL46.GL_LINEAR_MIPMAP_NEAREST) : GL46.GL_LINEAR) : (mips ? (linear ? GL46.GL_NEAREST_MIPMAP_LINEAR : GL46.GL_NEAREST_MIPMAP_NEAREST) : GL46.GL_NEAREST)); + GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MAG_FILTER, filter ? GL46.GL_LINEAR : GL46.GL_NEAREST); GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_WRAP_S, GL46.GL_REPEAT); GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_WRAP_T, GL46.GL_REPEAT); + GL46.glTexParameterf(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MAX_ANISOTROPY, aniso); + } + + public static void uploadTexture(int[] data, int w, int h, int x, int y, boolean params) + { + int i = 4194304 / w; + if(params) + setParams(false, false, false, 1.0f); int l; for (int j = 0; j < w * h; j += w * l) @@ -51,10 +57,7 @@ public class TextureUtil int h = img.getHeight(); int k = 4194304 / w; int[] data = new int[k * w]; - GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MIN_FILTER, GL46.GL_NEAREST); - GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MAG_FILTER, GL46.GL_NEAREST); - GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_WRAP_S, GL46.GL_REPEAT); - GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_WRAP_T, GL46.GL_REPEAT); + setParams(false, false, false, 1.0f); for (int l = 0; l < w * h; l += w * k) { diff --git a/client/src/main/resources/textures/blocks/grass_top.png b/client/src/main/resources/textures/blocks/grass_top.png old mode 100755 new mode 100644 index b3342633..c15842df Binary files a/client/src/main/resources/textures/blocks/grass_top.png and b/client/src/main/resources/textures/blocks/grass_top.png differ diff --git a/client/src/main/resources/textures/blocks/grass_top_2.png b/client/src/main/resources/textures/blocks/grass_top_2.png new file mode 100755 index 00000000..b3342633 Binary files /dev/null and b/client/src/main/resources/textures/blocks/grass_top_2.png differ