Finished mapping out texture variables (int only)

This commit is contained in:
Speiger 2024-04-06 12:16:14 +02:00
parent 7a87adb695
commit 480615de7a
8 changed files with 270 additions and 8 deletions

View File

@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx2G
lwjglVersion = 3.3.2
lwjglVersion = 3.3.3
lwjglNatives = natives-windows

View File

@ -1,9 +1,112 @@
package speiger.src.coreengine.rendering.textures.base;
import org.lwjgl.opengl.GL45;
import speiger.src.collections.longs.lists.LongArrayList;
import speiger.src.collections.longs.lists.LongList;
import speiger.src.coreengine.math.BitUtil;
import speiger.src.coreengine.rendering.utils.values.IGLValue;
import speiger.src.coreengine.rendering.utils.values.IGLValue.IGLDataType;
import speiger.src.coreengine.rendering.utils.values.IGLValue.ITextureFormatType;
import speiger.src.coreengine.rendering.utils.values.IGLValue.ITextureParameter;
public class TextureMetadata {
int textureType;
int internalFormat;
int externalFormat;
int dataFormat;
int textureFormat;
LongList arguments = new LongArrayList();
private TextureMetadata() {}
public void applyArguments(int texture) {
for(int i = 0,m=arguments.size();i<m;i++) {
long value = arguments.getLong(i);
GL45.glTextureParameteri(texture, BitUtil.toFirstInt(value), BitUtil.toSecondInt(value));
}
}
public LongList getArguments() {
return arguments.unmodifiable();
}
public int getInternalFormat() { return internalFormat; }
public int getExternalFormat() { return externalFormat; }
public int getDataFormat() { return dataFormat; }
public Builder copy() { return new Builder(this); }
public static Builder builder() { return new Builder(); }
public static class Builder {
TextureMetadata metadata = new TextureMetadata();
private Builder() {}
private Builder(TextureMetadata data) {
metadata.internalFormat = data.internalFormat;
metadata.externalFormat = data.externalFormat;
metadata.dataFormat = data.dataFormat;
metadata.arguments.addAll(data.arguments);
}
public Builder internalFormat(ITextureFormatType type) {
if(!type.internal()) throw new IllegalArgumentException("The GL_Type ["+type.glMode()+"] isn't supported in the internal format");
return internalFormat(type.glMode());
}
public Builder internalFormat(int glValue) {
metadata.internalFormat = glValue;
return this;
}
public Builder externalFormat(ITextureFormatType type) {
return externalFormat(type.glMode());
}
public Builder externalFormat(int glValue) {
metadata.externalFormat = glValue;
return this;
}
public Builder dataFormat(IGLDataType type) {
return dataFormat(type.glMode());
}
public Builder dataFormat(int glValue) {
metadata.dataFormat = glValue;
return this;
}
public Builder removeArgument(ITextureParameter id) {
return removeArgument(id.glMode());
}
public Builder removeArgument(int id) {
LongList list = metadata.arguments;
for(int i = 0,m=list.size();i<m;i++) {
if(BitUtil.toFirstInt(list.getLong(i)) == id) {
list.removeLong(i--);
}
}
return this;
}
public Builder arguement(ITextureParameter parameter, IGLValue value) {
return argument(parameter, value.glMode());
}
public Builder argument(ITextureParameter parameter, int value) {
if(!parameter.isValid(value)) throw new IllegalArgumentException("Value ["+value+"] isn't supported for GL Function ["+parameter.glMode()+"], only int functions are supported with this");
return argument(parameter.glMode(), value);
}
public Builder argument(int id, int value) {
metadata.arguments.add(BitUtil.toLong(id, value));
return this;
}
public TextureMetadata build() {
TextureMetadata meta = metadata;
metadata = null;
return meta;
}
}
}

View File

@ -0,0 +1,25 @@
package speiger.src.coreengine.rendering.utils.values;
import org.lwjgl.opengl.GL11;
public enum GLAlphaFunction implements IGLValue {
NEVER(GL11.GL_NEVER),
LESS(GL11.GL_LESS),
EQUAL(GL11.GL_EQUAL),
LEQUAL(GL11.GL_LEQUAL),
GREATER(GL11.GL_GREATER),
NOTEQUAL(GL11.GL_NOTEQUAL),
GEQUAL(GL11.GL_GEQUAL),
ALWAYS(GL11.GL_ALWAYS);
int glValue;
private GLAlphaFunction(int glValue) {
this.glValue = glValue;
}
@Override
public int glMode() {
return glValue;
}
}

View File

@ -1,5 +0,0 @@
package speiger.src.coreengine.rendering.utils.values;
public enum GLTextureType {
}

View File

@ -16,4 +16,10 @@ public interface IGLValue {
public boolean supportsIBO();
}
public static interface IShaderType extends IGLValue {};
public static interface ITextureFormatType extends IGLValue {
public boolean internal();
}
public static interface ITextureParameter extends IGLValue {
public boolean isValid(int value);
}
}

View File

@ -0,0 +1,28 @@
package speiger.src.coreengine.rendering.utils.values.textures;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL30;
import speiger.src.coreengine.rendering.utils.values.IGLValue.ITextureFormatType;
public enum GLTextureFormat implements ITextureFormatType {
R(GL11.GL_RED, true),
RG(GL30.GL_RG, true),
RGB(GL11.GL_RGB, true),
RGBA(GL11.GL_RGBA, true),
DEPTH(GL11.GL_DEPTH_COMPONENT, true),
DEPTH_STENCIL(GL30.GL_DEPTH_STENCIL, true);
int glMode;
boolean internal;
private GLTextureFormat(int glMode, boolean internal) {
this.glMode = glMode;
this.internal = internal;
}
@Override
public int glMode() { return glMode; }
@Override
public boolean internal() { return internal; }
}

View File

@ -0,0 +1,60 @@
package speiger.src.coreengine.rendering.utils.values.textures;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL14;
import org.lwjgl.opengl.GL33;
import org.lwjgl.opengl.GL43;
import speiger.src.collections.ints.sets.IntOpenHashSet;
import speiger.src.collections.ints.sets.IntSet;
import speiger.src.collections.ints.utils.IntSets;
import speiger.src.coreengine.rendering.utils.values.GLAlphaFunction;
import speiger.src.coreengine.rendering.utils.values.GLBlendFactor;
import speiger.src.coreengine.rendering.utils.values.IGLValue;
import speiger.src.coreengine.rendering.utils.values.IGLValue.ITextureParameter;
public enum GLTextureParameter implements ITextureParameter {
DEPTH_STENCIL(GL43.GL_DEPTH_STENCIL_TEXTURE_MODE, GLTextureValue.DEPTH_COMPONENT, GLTextureValue.STENCIL_INDEX),
BASE_LEVEL(GL12.GL_TEXTURE_BASE_LEVEL, true),
MAX_LEVEL(GL12.GL_TEXTURE_MAX_LEVEL, true),
MIN_LOD(GL12.GL_TEXTURE_MIN_LOD, false),
MAX_LOD(GL12.GL_TEXTURE_MAX_LOD, false),
BORDER_COLOR(GL11.GL_TEXTURE_BORDER_COLOR, false),
COMPARE_FUNCTION(GL14.GL_TEXTURE_COMPARE_FUNC, GLAlphaFunction.values()),
COMPARE_MODE(GL14.GL_TEXTURE_COMPARE_MODE, GLTextureValue.COMPARE_REF_TO_TEXTURE, GLTextureValue.NONE),
MIN_FILTER(GL11.GL_TEXTURE_MIN_FILTER, GLTextureValue.NEAREST, GLTextureValue.LINEAR, GLTextureValue.NEAREST_MIPMAP_NEAREST, GLTextureValue.LINEAR_MIPMAP_NEAREST, GLTextureValue.NEAREST_MIPMAP_LINEAR, GLTextureValue.LINEAR_MIPMAP_LINEAR),
MAG_FILTER(GL11.GL_TEXTURE_MAG_FILTER, GLTextureValue.NEAREST, GLTextureValue.LINEAR),
SWIZZLE_R(GL33.GL_TEXTURE_SWIZZLE_R, GLTextureValue.RED, GLTextureValue.GREEN, GLTextureValue.BLUE, GLTextureValue.ALPHA, GLBlendFactor.ZERO, GLBlendFactor.ONE),
SWIZZLE_G(GL33.GL_TEXTURE_SWIZZLE_G, GLTextureValue.RED, GLTextureValue.GREEN, GLTextureValue.BLUE, GLTextureValue.ALPHA, GLBlendFactor.ZERO, GLBlendFactor.ONE),
SWIZZLE_B(GL33.GL_TEXTURE_SWIZZLE_B, GLTextureValue.RED, GLTextureValue.GREEN, GLTextureValue.BLUE, GLTextureValue.ALPHA, GLBlendFactor.ZERO, GLBlendFactor.ONE),
SWIZZLE_A(GL33.GL_TEXTURE_SWIZZLE_A, GLTextureValue.RED, GLTextureValue.GREEN, GLTextureValue.BLUE, GLTextureValue.ALPHA, GLBlendFactor.ZERO, GLBlendFactor.ONE),
SWIZZLE_RGBA(GL33.GL_TEXTURE_SWIZZLE_RGBA, false),
WRAP_S(GL11.GL_TEXTURE_WRAP_S, GLTextureValue.CLAMP_TO_EDGE, GLTextureValue.CLAMP_TO_BORDER, GLTextureValue.MIRRORED_REPEAT, GLTextureValue.REPEAT, GLTextureValue.MIRROR_CLAMP_TO_EDGE),
WRAP_T(GL11.GL_TEXTURE_WRAP_T, GLTextureValue.CLAMP_TO_EDGE, GLTextureValue.CLAMP_TO_BORDER, GLTextureValue.MIRRORED_REPEAT, GLTextureValue.REPEAT, GLTextureValue.MIRROR_CLAMP_TO_EDGE),
WRAP_R(GL12.GL_TEXTURE_WRAP_R, GLTextureValue.CLAMP_TO_EDGE, GLTextureValue.CLAMP_TO_BORDER, GLTextureValue.MIRRORED_REPEAT, GLTextureValue.REPEAT, GLTextureValue.MIRROR_CLAMP_TO_EDGE);
int glValue;
IntSet validValues;
private GLTextureParameter(int glValue, IGLValue... validValues) {
this.glValue = glValue;
this.validValues = new IntOpenHashSet(validValues.length);
for(int i = 0,m=validValues.length;i<m;this.validValues.add(validValues[i++].glMode()));
}
private GLTextureParameter(int glValue, boolean any) {
this.glValue = glValue;
this.validValues = any ? IntSets.empty() : IntSets.singleton(-1);
}
@Override
public int glMode() {
return glValue;
}
@Override
public boolean isValid(int value) {
return validValues.isEmpty() || validValues.contains(value);
}
}

View File

@ -0,0 +1,45 @@
package speiger.src.coreengine.rendering.utils.values.textures;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL14;
import org.lwjgl.opengl.GL30;
import org.lwjgl.opengl.GL44;
import speiger.src.coreengine.rendering.utils.values.IGLValue;
public enum GLTextureValue implements IGLValue {
DEPTH_COMPONENT(GL11.GL_DEPTH_COMPONENT),
STENCIL_INDEX(GL11.GL_STENCIL_INDEX),
COMPARE_REF_TO_TEXTURE(GL30.GL_COMPARE_REF_TO_TEXTURE),
NONE(GL11.GL_NONE),
NEAREST(GL11.GL_NEAREST),
LINEAR(GL11.GL_LINEAR),
NEAREST_MIPMAP_NEAREST(GL11.GL_NEAREST_MIPMAP_NEAREST),
LINEAR_MIPMAP_NEAREST(GL11.GL_LINEAR_MIPMAP_NEAREST),
NEAREST_MIPMAP_LINEAR(GL11.GL_NEAREST_MIPMAP_LINEAR),
LINEAR_MIPMAP_LINEAR(GL11.GL_LINEAR_MIPMAP_LINEAR),
RED(GL11.GL_RED),
GREEN(GL11.GL_GREEN),
BLUE(GL11.GL_BLUE),
ALPHA(GL11.GL_ALPHA),
CLAMP_TO_EDGE(GL12.GL_CLAMP_TO_EDGE),
CLAMP_TO_BORDER(GL13.GL_CLAMP_TO_BORDER),
MIRRORED_REPEAT(GL14.GL_MIRRORED_REPEAT),
REPEAT(GL11.GL_REPEAT),
MIRROR_CLAMP_TO_EDGE(GL44.GL_MIRROR_CLAMP_TO_EDGE),
;
int glValue;
private GLTextureValue(int glValue) {
this.glValue = glValue;
}
@Override
public int glMode() {
return glValue;
}
}