Engine Upgrade

- Added: Texture Uniform
- Added: UniformManager
- Upgraded Shader implementations.
This commit is contained in:
Speiger 2024-01-25 18:34:58 +01:00
parent c464aaa271
commit 51afb9d82e
11 changed files with 44 additions and 34 deletions

View File

@ -12,7 +12,7 @@
<attribute name="gradle_used_by_scope" value="main,test"/> <attribute name="gradle_used_by_scope" value="main,test"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-19/"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/> <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/> <classpathentry kind="output" path="bin/default"/>
</classpath> </classpath>

View File

@ -12,7 +12,7 @@ eclipse {
} }
} }
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaLanguageVersion.of(19) sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaLanguageVersion.of(21)
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -1,6 +1,5 @@
package speiger.src.coreengine.assets.reloader; package speiger.src.coreengine.assets.reloader;
import java.util.ServiceLoader;
import java.util.Set; import java.util.Set;
import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet; import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet;

View File

@ -37,6 +37,17 @@ public class ShaderTracker implements ISimpleRealodableAsset, IManagedAsset {
public boolean isActive() { return activeShaderId != 0; } public boolean isActive() { return activeShaderId != 0; }
public boolean isShaderActive(ShaderProgram program) { return activeShaderId == shaderId(program); } public boolean isShaderActive(ShaderProgram program) { return activeShaderId == shaderId(program); }
public int getActiveShader() { return activeShaderId; } public int getActiveShader() { return activeShaderId; }
public ShaderProgram getActiveProgram() {
if(isActive()) {
for(int i = 0,m=shaders.size();i<m;i++) {
ShaderProgram program = shaders.get(i).get();
if(activeShaderId == shaderId(program)) {
return program;
}
}
}
return null;
}
private int shaderId(ShaderProgram program) { private int shaderId(ShaderProgram program) {
return program == null ? 0 : program.id(); return program == null ? 0 : program.id();

View File

@ -7,8 +7,8 @@ import speiger.src.collections.objects.maps.interfaces.Object2ObjectMap;
public class GlobalUniforms { public class GlobalUniforms {
private Object2ObjectMap<String, IUniform> uniforms = Object2ObjectMap.builder().map(); private Object2ObjectMap<String, IUniform> uniforms = Object2ObjectMap.builder().map();
public <T extends IUniform> T register(T uniform) { public <T extends IUniform> T register(String uniformId, T uniform) {
uniforms.putIfAbsent(Objects.requireNonNull(uniform.getName()), uniform); uniforms.putIfAbsent(Objects.requireNonNull(uniformId), Objects.requireNonNull(uniform));
return uniform; return uniform;
} }

View File

@ -1,7 +1,5 @@
package speiger.src.coreengine.rendering.shader.uniform; package speiger.src.coreengine.rendering.shader.uniform;
import speiger.src.coreengine.rendering.shader.ShaderProgram;
public interface IAutoUniform extends IUniform { public interface IAutoUniform extends IUniform {
public void bind(ShaderProgram program); public void bind(int programId);
} }

View File

@ -3,7 +3,6 @@ package speiger.src.coreengine.rendering.shader.uniform;
import speiger.src.coreengine.rendering.shader.ShaderProgram; import speiger.src.coreengine.rendering.shader.ShaderProgram;
public interface IUniform { public interface IUniform {
public String getName();
public void registerShader(ShaderProgram program); public void registerShader(ShaderProgram program);
public void removeShader(ShaderProgram program); public void removeShader(ShaderProgram program);
} }

View File

@ -5,6 +5,7 @@ import org.lwjgl.opengl.GL20;
import speiger.src.collections.ints.maps.impl.hash.Int2IntOpenHashMap; import speiger.src.collections.ints.maps.impl.hash.Int2IntOpenHashMap;
import speiger.src.collections.ints.maps.interfaces.Int2IntMap; import speiger.src.collections.ints.maps.interfaces.Int2IntMap;
import speiger.src.coreengine.rendering.shader.ShaderProgram; import speiger.src.coreengine.rendering.shader.ShaderProgram;
import speiger.src.coreengine.rendering.utils.GLStateTracker;
import speiger.src.coreengine.utils.io.GameLog; import speiger.src.coreengine.utils.io.GameLog;
public abstract class Uniform implements IUniform { public abstract class Uniform implements IUniform {
@ -16,9 +17,8 @@ public abstract class Uniform implements IUniform {
positions.setDefaultReturnValue(-1); positions.setDefaultReturnValue(-1);
} }
@Override protected boolean contains(int shaderId) {
public String getName() { return positions.containsKey(shaderId);
return name;
} }
protected int getPosition(ShaderProgram program) { protected int getPosition(ShaderProgram program) {
@ -45,6 +45,10 @@ public abstract class Uniform implements IUniform {
protected void update() { protected void update() {
positions.forEach(this::processChanges); positions.forEach(this::processChanges);
if(this instanceof IAutoUniform auto) {
int id = GLStateTracker.SHADERS.getActiveShader();
if(contains(id)) auto.bind(id);
}
} }
protected void processChanges(int programId, int location) { protected void processChanges(int programId, int location) {

View File

@ -84,7 +84,7 @@ public class UniformManager {
public void bind() { public void bind() {
if(autoUniforms.isEmpty()) return; if(autoUniforms.isEmpty()) return;
for(int i = 0,m=autoUniforms.size();i<m;i++) { for(int i = 0,m=autoUniforms.size();i<m;i++) {
autoUniforms.get(i).bind(owner); autoUniforms.get(i).bind(owner.id());
} }
} }

View File

@ -2,7 +2,6 @@ package speiger.src.coreengine.rendering.shader.uniform.base;
import org.lwjgl.opengl.GL41; import org.lwjgl.opengl.GL41;
import speiger.src.coreengine.rendering.shader.ShaderProgram;
import speiger.src.coreengine.rendering.shader.uniform.IAutoUniform; import speiger.src.coreengine.rendering.shader.uniform.IAutoUniform;
import speiger.src.coreengine.rendering.shader.uniform.Uniform; import speiger.src.coreengine.rendering.shader.uniform.Uniform;
import speiger.src.coreengine.rendering.utils.AllocationTracker; import speiger.src.coreengine.rendering.utils.AllocationTracker;
@ -32,7 +31,7 @@ public class TextureUniform extends Uniform implements IAutoUniform {
} }
@Override @Override
public void bind(ShaderProgram program) { public void bind(int programId) {
GLStateTracker.TEXTURES.bind(unit, value); GLStateTracker.TEXTURES.bind(unit, value);
} }
} }