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"/>
</attributes>
</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="output" path="bin/default"/>
</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 {
mavenCentral()

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
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
zipStorePath=wrapper/dists

View File

@ -1,6 +1,5 @@
package speiger.src.coreengine.assets.reloader;
import java.util.ServiceLoader;
import java.util.Set;
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 isShaderActive(ShaderProgram program) { return activeShaderId == shaderId(program); }
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) {
return program == null ? 0 : program.id();

View File

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

View File

@ -1,7 +1,5 @@
package speiger.src.coreengine.rendering.shader.uniform;
import speiger.src.coreengine.rendering.shader.ShaderProgram;
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;
public interface IUniform {
public String getName();
public void registerShader(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.interfaces.Int2IntMap;
import speiger.src.coreengine.rendering.shader.ShaderProgram;
import speiger.src.coreengine.rendering.utils.GLStateTracker;
import speiger.src.coreengine.utils.io.GameLog;
public abstract class Uniform implements IUniform {
@ -16,9 +17,8 @@ public abstract class Uniform implements IUniform {
positions.setDefaultReturnValue(-1);
}
@Override
public String getName() {
return name;
protected boolean contains(int shaderId) {
return positions.containsKey(shaderId);
}
protected int getPosition(ShaderProgram program) {
@ -45,6 +45,10 @@ public abstract class Uniform implements IUniform {
protected void update() {
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) {

View File

@ -84,7 +84,7 @@ public class UniformManager {
public void bind() {
if(autoUniforms.isEmpty()) return;
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 speiger.src.coreengine.rendering.shader.ShaderProgram;
import speiger.src.coreengine.rendering.shader.uniform.IAutoUniform;
import speiger.src.coreengine.rendering.shader.uniform.Uniform;
import speiger.src.coreengine.rendering.utils.AllocationTracker;
@ -32,7 +31,7 @@ public class TextureUniform extends Uniform implements IAutoUniform {
}
@Override
public void bind(ShaderProgram program) {
public void bind(int programId) {
GLStateTracker.TEXTURES.bind(unit, value);
}
}