-
-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,362 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
common/src/main/java/net/irisshaders/iris/gl/uniform/FloatArrayUniform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package net.irisshaders.iris.gl.uniform; | ||
|
||
import net.irisshaders.iris.gl.IrisRenderSystem; | ||
import net.irisshaders.iris.gl.state.ValueUpdateNotifier; | ||
import org.lwjgl.opengl.GL46C; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.Supplier; | ||
|
||
public class FloatArrayUniform extends Uniform { | ||
private final Supplier<float[]> value; | ||
private float[] cachedValue; | ||
|
||
FloatArrayUniform(int location, int count, Supplier<float[]> value) { | ||
this(location, value, count, null); | ||
} | ||
|
||
FloatArrayUniform(int location, Supplier<float[]> value, int count, ValueUpdateNotifier notifier) { | ||
super(location, notifier); | ||
|
||
this.cachedValue = new float[count]; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public void update() { | ||
updateValue(); | ||
|
||
if (notifier != null) { | ||
notifier.setListener(this::updateValue); | ||
} | ||
} | ||
|
||
private void updateValue() { | ||
float[] newValue = value.get(); | ||
|
||
if (!Arrays.equals(newValue, cachedValue)) { | ||
System.arraycopy(newValue, 0, cachedValue, 0, newValue.length); | ||
GL46C.glUniform1fv(location, newValue); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
common/src/main/java/net/irisshaders/iris/gl/uniform/MatrixArrayUniform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package net.irisshaders.iris.gl.uniform; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.irisshaders.iris.gl.state.ValueUpdateNotifier; | ||
import org.joml.Matrix4f; | ||
import org.joml.Matrix4fc; | ||
import org.lwjgl.BufferUtils; | ||
import org.lwjgl.opengl.GL46C; | ||
import org.lwjgl.system.MemoryStack; | ||
|
||
import java.nio.FloatBuffer; | ||
import java.util.Arrays; | ||
import java.util.function.Supplier; | ||
|
||
public class MatrixArrayUniform extends Uniform { | ||
private final Supplier<Matrix4fc[]> value; | ||
private final int count; | ||
private Matrix4fc[] cachedValue; | ||
|
||
MatrixArrayUniform(int location, int count, Supplier<Matrix4fc[]> value) { | ||
super(location); | ||
|
||
this.count = count; | ||
this.value = value; | ||
} | ||
|
||
MatrixArrayUniform(int location, int count, Supplier<Matrix4fc[]> value, ValueUpdateNotifier notifier) { | ||
super(location, notifier); | ||
|
||
this.count = count; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public void update() { | ||
updateValue(); | ||
|
||
if (notifier != null) { | ||
notifier.setListener(this::updateValue); | ||
} | ||
} | ||
|
||
public void updateValue() { | ||
Matrix4fc[] values = value.get(); | ||
|
||
if (Arrays.equals(cachedValue, values)) { | ||
return; | ||
} else { | ||
System.arraycopy(values, 0, cachedValue, 0, values.length); | ||
} | ||
|
||
try (MemoryStack stack = MemoryStack.stackPush()) { | ||
long buffer = stack.nmalloc(64 * count); | ||
|
||
int offset = 0; | ||
|
||
for (Matrix4fc matrix : values) { | ||
matrix.getToAddress(buffer + offset); | ||
offset += 64; | ||
} | ||
|
||
GL46C.nglUniformMatrix4fv(location, count, false, buffer); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.