mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-29 08:26:37 +01:00
Testing + fixing
This commit is contained in:
parent
ef48504caa
commit
57b67cddcf
9 changed files with 124 additions and 15 deletions
|
@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.gl.attrib;
|
||||||
|
|
||||||
public interface IAttribSpec {
|
public interface IAttribSpec {
|
||||||
|
|
||||||
void vertexAttribPointer(int stride, int index, int pointer);
|
void vertexAttribPointer(int stride, int index, int offset);
|
||||||
|
|
||||||
int getSize();
|
int getSize();
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@ public enum MatrixAttributes implements IAttribSpec {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void vertexAttribPointer(int stride, int index, int pointer) {
|
public void vertexAttribPointer(int stride, int index, int offset) {
|
||||||
for (int i = 0; i < rows; i++) {
|
for (int i = 0; i < rows; i++) {
|
||||||
long attribPointer = pointer + (long) i * cols * GlNumericType.FLOAT.getByteWidth();
|
long attribPointer = offset + (long) i * cols * GlNumericType.FLOAT.getByteWidth();
|
||||||
GL20.glVertexAttribPointer(index + i, cols, GlNumericType.FLOAT.getGlEnum(), false, stride, attribPointer);
|
GL20.glVertexAttribPointer(index + i, cols, GlNumericType.FLOAT.getGlEnum(), false, stride, attribPointer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ public class VertexAttribSpec implements IAttribSpec {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void vertexAttribPointer(int stride, int index, int pointer) {
|
public void vertexAttribPointer(int stride, int index, int offset) {
|
||||||
GL20.glVertexAttribPointer(index, count, type.getGlEnum(), normalized, stride, pointer);
|
GL20.glVertexAttribPointer(index, count, type.getGlEnum(), normalized, stride, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,6 +19,8 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import com.mojang.math.Matrix4f;
|
import com.mojang.math.Matrix4f;
|
||||||
|
|
||||||
public abstract class GlProgram extends GlObject {
|
public abstract class GlProgram extends GlObject {
|
||||||
|
private static final FloatBuffer floatBuffer = MemoryStack.stackGet()
|
||||||
|
.mallocFloat(16);
|
||||||
|
|
||||||
public final ResourceLocation name;
|
public final ResourceLocation name;
|
||||||
|
|
||||||
|
@ -70,8 +72,6 @@ public abstract class GlProgram extends GlObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void uploadMatrixUniform(int uniform, Matrix4f mat) {
|
protected static void uploadMatrixUniform(int uniform, Matrix4f mat) {
|
||||||
FloatBuffer floatBuffer = MemoryStack.stackGet()
|
|
||||||
.mallocFloat(16);
|
|
||||||
mat.store(floatBuffer);
|
mat.store(floatBuffer);
|
||||||
glUniformMatrix4fv(uniform, false, floatBuffer);
|
glUniformMatrix4fv(uniform, false, floatBuffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,20 +4,20 @@ import java.nio.FloatBuffer;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||||
import com.jozufozu.flywheel.core.materials.BasicData;
|
import com.jozufozu.flywheel.core.materials.BasicData;
|
||||||
import com.jozufozu.flywheel.util.RenderUtil;
|
import com.jozufozu.flywheel.util.Attribute;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
|
||||||
public class ModelData extends BasicData {
|
public class ModelData extends BasicData {
|
||||||
private static final float[] empty = new float[25];
|
private static final float[] empty = new float[25];
|
||||||
|
|
||||||
public final float[] matrices = empty.clone();
|
public final float[] matrices = empty.clone();
|
||||||
private final FloatBuffer buf = FloatBuffer.wrap(matrices);
|
private final FloatBuffer wrap = FloatBuffer.wrap(matrices);
|
||||||
|
|
||||||
public ModelData setTransform(PoseStack stack) {
|
public ModelData setTransform(PoseStack stack) {
|
||||||
this.buf.reset();
|
this.wrap.position(0);
|
||||||
|
|
||||||
stack.last().pose().store(this.buf);
|
((Attribute)(Object) stack.last().pose()).append(this.wrap);
|
||||||
stack.last().normal().store(this.buf);
|
((Attribute)(Object) stack.last().normal()).append(this.wrap);
|
||||||
markDirty();
|
markDirty();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ public class ModelData extends BasicData {
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public ModelData setEmptyTransform() {
|
public ModelData setEmptyTransform() {
|
||||||
this.buf.reset();
|
this.wrap.position(0)
|
||||||
this.buf.put(empty);
|
.put(empty);
|
||||||
markDirty();
|
markDirty();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,6 @@ public class ModelData extends BasicData {
|
||||||
@Override
|
@Override
|
||||||
public void write(VecBuffer buf) {
|
public void write(VecBuffer buf) {
|
||||||
super.write(buf);
|
super.write(buf);
|
||||||
buf.put(this.buf);
|
buf.putFloatArray(matrices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.jozufozu.flywheel.mixin.matrix;
|
||||||
|
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.util.Attribute;
|
||||||
|
import com.mojang.math.Matrix3f;
|
||||||
|
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
@Mixin(Matrix3f.class)
|
||||||
|
public abstract class Matrix3fMixin implements Attribute {
|
||||||
|
|
||||||
|
@Shadow protected float m00;
|
||||||
|
@Shadow protected float m01;
|
||||||
|
@Shadow protected float m02;
|
||||||
|
@Shadow protected float m10;
|
||||||
|
@Shadow protected float m11;
|
||||||
|
@Shadow protected float m12;
|
||||||
|
@Shadow protected float m20;
|
||||||
|
@Shadow protected float m21;
|
||||||
|
@Shadow protected float m22;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void append(FloatBuffer buffer) {
|
||||||
|
buffer.put(m00);
|
||||||
|
buffer.put(m10);
|
||||||
|
buffer.put(m20);
|
||||||
|
buffer.put(m01);
|
||||||
|
buffer.put(m11);
|
||||||
|
buffer.put(m21);
|
||||||
|
buffer.put(m02);
|
||||||
|
buffer.put(m12);
|
||||||
|
buffer.put(m22);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.jozufozu.flywheel.mixin.matrix;
|
||||||
|
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.util.Attribute;
|
||||||
|
import com.mojang.math.Matrix4f;
|
||||||
|
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
@Mixin(Matrix4f.class)
|
||||||
|
public abstract class Matrix4fMixin implements Attribute {
|
||||||
|
|
||||||
|
@Shadow protected float m00;
|
||||||
|
@Shadow protected float m01;
|
||||||
|
@Shadow protected float m02;
|
||||||
|
@Shadow protected float m03;
|
||||||
|
@Shadow protected float m10;
|
||||||
|
@Shadow protected float m11;
|
||||||
|
@Shadow protected float m12;
|
||||||
|
@Shadow protected float m13;
|
||||||
|
@Shadow protected float m20;
|
||||||
|
@Shadow protected float m21;
|
||||||
|
@Shadow protected float m22;
|
||||||
|
@Shadow protected float m23;
|
||||||
|
@Shadow protected float m30;
|
||||||
|
@Shadow protected float m31;
|
||||||
|
@Shadow protected float m32;
|
||||||
|
@Shadow protected float m33;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void append(FloatBuffer buffer) {
|
||||||
|
buffer.put(m00);
|
||||||
|
buffer.put(m10);
|
||||||
|
buffer.put(m20);
|
||||||
|
buffer.put(m30);
|
||||||
|
buffer.put(m01);
|
||||||
|
buffer.put(m11);
|
||||||
|
buffer.put(m21);
|
||||||
|
buffer.put(m31);
|
||||||
|
buffer.put(m02);
|
||||||
|
buffer.put(m12);
|
||||||
|
buffer.put(m22);
|
||||||
|
buffer.put(m32);
|
||||||
|
buffer.put(m03);
|
||||||
|
buffer.put(m13);
|
||||||
|
buffer.put(m23);
|
||||||
|
buffer.put(m33);
|
||||||
|
}
|
||||||
|
}
|
11
src/main/java/com/jozufozu/flywheel/util/Attribute.java
Normal file
11
src/main/java/com/jozufozu/flywheel/util/Attribute.java
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package com.jozufozu.flywheel.util;
|
||||||
|
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
|
public interface Attribute {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append the contents of this object to the given FloatBuffer.
|
||||||
|
*/
|
||||||
|
void append(FloatBuffer buffer);
|
||||||
|
}
|
|
@ -20,6 +20,10 @@
|
||||||
"LeakChunkStorageArrayMixin",
|
"LeakChunkStorageArrayMixin",
|
||||||
"PausedPartialTickAccessor"
|
"PausedPartialTickAccessor"
|
||||||
],
|
],
|
||||||
|
"mixins": [
|
||||||
|
"matrix.Matrix3fMixin",
|
||||||
|
"matrix.Matrix4fMixin"
|
||||||
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue