Testing + fixing

This commit is contained in:
Jozufozu 2021-09-26 21:15:02 -07:00
parent 7c5e02d2e8
commit 79ac9e96e4
9 changed files with 124 additions and 15 deletions

View file

@ -2,7 +2,7 @@ package com.jozufozu.flywheel.backend.gl.attrib;
public interface IAttribSpec {
void vertexAttribPointer(int stride, int index, int pointer);
void vertexAttribPointer(int stride, int index, int offset);
int getSize();

View file

@ -18,9 +18,9 @@ public enum MatrixAttributes implements IAttribSpec {
}
@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++) {
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);
}
}

View file

@ -25,8 +25,8 @@ public class VertexAttribSpec implements IAttribSpec {
}
@Override
public void vertexAttribPointer(int stride, int index, int pointer) {
GL20.glVertexAttribPointer(index, count, type.getGlEnum(), normalized, stride, pointer);
public void vertexAttribPointer(int stride, int index, int offset) {
GL20.glVertexAttribPointer(index, count, type.getGlEnum(), normalized, stride, offset);
}
@Override

View file

@ -19,6 +19,8 @@ import net.minecraft.resources.ResourceLocation;
import com.mojang.math.Matrix4f;
public abstract class GlProgram extends GlObject {
private static final FloatBuffer floatBuffer = MemoryStack.stackGet()
.mallocFloat(16);
public final ResourceLocation name;
@ -70,8 +72,6 @@ public abstract class GlProgram extends GlObject {
}
protected static void uploadMatrixUniform(int uniform, Matrix4f mat) {
FloatBuffer floatBuffer = MemoryStack.stackGet()
.mallocFloat(16);
mat.store(floatBuffer);
glUniformMatrix4fv(uniform, false, floatBuffer);
}

View file

@ -4,20 +4,20 @@ import java.nio.FloatBuffer;
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
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;
public class ModelData extends BasicData {
private static final float[] empty = new float[25];
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) {
this.buf.reset();
this.wrap.position(0);
stack.last().pose().store(this.buf);
stack.last().normal().store(this.buf);
((Attribute)(Object) stack.last().pose()).append(this.wrap);
((Attribute)(Object) stack.last().normal()).append(this.wrap);
markDirty();
return this;
}
@ -30,8 +30,8 @@ public class ModelData extends BasicData {
* </p>
*/
public ModelData setEmptyTransform() {
this.buf.reset();
this.buf.put(empty);
this.wrap.position(0)
.put(empty);
markDirty();
return this;
}
@ -39,6 +39,6 @@ public class ModelData extends BasicData {
@Override
public void write(VecBuffer buf) {
super.write(buf);
buf.put(this.buf);
buf.putFloatArray(matrices);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View 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);
}

View file

@ -20,6 +20,10 @@
"LeakChunkStorageArrayMixin",
"PausedPartialTickAccessor"
],
"mixins": [
"matrix.Matrix3fMixin",
"matrix.Matrix4fMixin"
],
"injectors": {
"defaultRequire": 1
}