Refactor/rename VertexAttribute -> AbstractVertexAttribute
This commit is contained in:
+6
-5
@@ -24,7 +24,8 @@ import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||
import com.seibel.distanthorizons.core.render.glObject.GLState;
|
||||
import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
|
||||
import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttribute;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -38,19 +39,19 @@ public class OpenGLConfigScreen extends AbstractScreen
|
||||
ShaderProgram basicShader;
|
||||
GLVertexBuffer sameContextBuffer;
|
||||
GLVertexBuffer sharedContextBuffer;
|
||||
VertexAttribute va;
|
||||
AbstractVertexAttribute va;
|
||||
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
System.out.println("init");
|
||||
|
||||
va = VertexAttribute.create();
|
||||
va = AbstractVertexAttribute.create();
|
||||
va.bind();
|
||||
// Pos
|
||||
va.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addVec2Pointer(false));
|
||||
va.setVertexAttribute(0, 0, VertexPointer.addVec2Pointer(false));
|
||||
// Color
|
||||
va.setVertexAttribute(0, 1, VertexAttribute.VertexPointer.addVec4Pointer(false));
|
||||
va.setVertexAttribute(0, 1, VertexPointer.addVec4Pointer(false));
|
||||
va.completeAndCheck(Float.BYTES * 6);
|
||||
basicShader = new ShaderProgram("shaders/test/vert.vert", "shaders/test/frag.frag",
|
||||
"fragColor", new String[]{"vPosition", "color"});
|
||||
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2023 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.core.render.glObject.vertexAttribute;
|
||||
|
||||
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
/**
|
||||
* Base for binding/unbinding Vertex Attribute objects (VAO's).
|
||||
*
|
||||
* @see VertexAttributePostGL43
|
||||
* @see VertexAttributePreGL43
|
||||
*/
|
||||
public abstract class AbstractVertexAttribute
|
||||
{
|
||||
/** Stores the handle of the AbstractVertexAttribute. */
|
||||
public final int id;
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// constructors //
|
||||
//==============//
|
||||
|
||||
// This will bind AbstractVertexAttribute
|
||||
protected AbstractVertexAttribute()
|
||||
{
|
||||
this.id = GL32.glGenVertexArrays();
|
||||
GL32.glBindVertexArray(this.id);
|
||||
}
|
||||
|
||||
public static AbstractVertexAttribute create()
|
||||
{
|
||||
if (GLProxy.getInstance().VertexAttributeBufferBindingSupported)
|
||||
{
|
||||
return new VertexAttributePostGL43();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new VertexAttributePreGL43();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
// binding //
|
||||
//=========//
|
||||
|
||||
public void bind() { GL32.glBindVertexArray(this.id); }
|
||||
public void unbind() { GL32.glBindVertexArray(0); }
|
||||
|
||||
/** Always remember to always free your resources! */
|
||||
public void free() { GL32.glDeleteVertexArrays(this.id); }
|
||||
|
||||
|
||||
|
||||
//==================//
|
||||
// abstract methods //
|
||||
//==================//
|
||||
|
||||
/** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
|
||||
public abstract void bindBufferToAllBindingPoints(int buffer);
|
||||
/** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
|
||||
public abstract void bindBufferToBindingPoint(int buffer, int bindingPoint);
|
||||
/** Requires both AbstractVertexAttribute to be bound */
|
||||
public abstract void unbindBuffersFromAllBindingPoint();
|
||||
/** Requires both AbstractVertexAttribute to be bound */
|
||||
public abstract void unbindBuffersFromBindingPoint(int bindingPoint);
|
||||
/** Requires both AbstractVertexAttribute to be bound */
|
||||
public abstract void setVertexAttribute(int bindingPoint, int attributeIndex, VertexPointer attribute);
|
||||
/** Requires both AbstractVertexAttribute to be bound */
|
||||
public abstract void completeAndCheck(int expectedStrideSize);
|
||||
|
||||
}
|
||||
-158
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2023 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.core.render.glObject.vertexAttribute;
|
||||
|
||||
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
public abstract class VertexAttribute
|
||||
{
|
||||
|
||||
public static final class VertexPointer
|
||||
{
|
||||
public final int elementCount;
|
||||
public final int glType;
|
||||
public final boolean normalized;
|
||||
public final int byteSize;
|
||||
public final boolean useInteger;
|
||||
public VertexPointer(int elementCount, int glType, boolean normalized, int byteSize, boolean useInteger)
|
||||
{
|
||||
this.elementCount = elementCount;
|
||||
this.glType = glType;
|
||||
this.normalized = normalized;
|
||||
this.byteSize = byteSize;
|
||||
this.useInteger = useInteger;
|
||||
}
|
||||
public VertexPointer(int elementCount, int glType, boolean normalized, int byteSize)
|
||||
{
|
||||
this(elementCount, glType, normalized, byteSize, false);
|
||||
}
|
||||
private static int _align(int bytes)
|
||||
{
|
||||
return MathUtil.ceilDiv(bytes, 4) * 4;
|
||||
}
|
||||
|
||||
public static VertexPointer addFloatPointer(boolean normalized)
|
||||
{
|
||||
return new VertexPointer(1, GL32.GL_FLOAT, normalized, 4);
|
||||
}
|
||||
public static VertexPointer addVec2Pointer(boolean normalized)
|
||||
{
|
||||
return new VertexPointer(2, GL32.GL_FLOAT, normalized, 8);
|
||||
}
|
||||
public static VertexPointer addVec3Pointer(boolean normalized)
|
||||
{
|
||||
return new VertexPointer(3, GL32.GL_FLOAT, normalized, 12);
|
||||
}
|
||||
public static VertexPointer addVec4Pointer(boolean normalized)
|
||||
{
|
||||
return new VertexPointer(4, GL32.GL_FLOAT, normalized, 16);
|
||||
}
|
||||
public static VertexPointer addUnsignedBytePointer(boolean normalized, boolean useInteger)
|
||||
{
|
||||
return new VertexPointer(1, GL32.GL_UNSIGNED_BYTE, normalized, 4, useInteger); // Always aligned to 4 bytes
|
||||
}
|
||||
public static VertexPointer addUnsignedBytesPointer(int elementCount, boolean normalized, boolean useInteger)
|
||||
{
|
||||
return new VertexPointer(elementCount, GL32.GL_UNSIGNED_BYTE, normalized, _align(elementCount), useInteger); // aligned to 4 bytes
|
||||
}
|
||||
public static VertexPointer addUnsignedShortsPointer(int elementCount, boolean normalized, boolean useInteger)
|
||||
{
|
||||
return new VertexPointer(elementCount, GL32.GL_UNSIGNED_SHORT, normalized, _align(elementCount * 2), useInteger);
|
||||
}
|
||||
public static VertexPointer addShortsPointer(int elementCount, boolean normalized, boolean useInteger)
|
||||
{
|
||||
return new VertexPointer(elementCount, GL32.GL_SHORT, normalized, _align(elementCount * 2), useInteger);
|
||||
}
|
||||
public static VertexPointer addIntPointer(boolean normalized, boolean useInteger)
|
||||
{
|
||||
return new VertexPointer(1, GL32.GL_INT, normalized, 4, useInteger);
|
||||
}
|
||||
public static VertexPointer addIvec2Pointer(boolean normalized, boolean useInteger)
|
||||
{
|
||||
return new VertexPointer(2, GL32.GL_INT, normalized, 8, useInteger);
|
||||
}
|
||||
public static VertexPointer addIvec3Pointer(boolean normalized, boolean useInteger)
|
||||
{
|
||||
return new VertexPointer(3, GL32.GL_INT, normalized, 12, useInteger);
|
||||
}
|
||||
public static VertexPointer addIvec4Pointer(boolean normalized, boolean useInteger)
|
||||
{
|
||||
return new VertexPointer(4, GL32.GL_INT, normalized, 16, useInteger);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** Stores the handle of the VertexAttribute. */
|
||||
public final int id;
|
||||
|
||||
// This will bind VertexAttribute
|
||||
protected VertexAttribute()
|
||||
{
|
||||
id = GL32.glGenVertexArrays();
|
||||
GL32.glBindVertexArray(id);
|
||||
}
|
||||
|
||||
public static VertexAttribute create()
|
||||
{
|
||||
if (GLProxy.getInstance().VertexAttributeBufferBindingSupported)
|
||||
{
|
||||
return new VertexAttributePostGL43();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new VertexAttributePreGL43();
|
||||
}
|
||||
}
|
||||
|
||||
// This will bind VertexAttribute
|
||||
public void bind()
|
||||
{
|
||||
GL32.glBindVertexArray(id);
|
||||
}
|
||||
|
||||
// This will unbind VertexAttribute
|
||||
public void unbind()
|
||||
{
|
||||
GL32.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
// REMEMBER to always free the resource!
|
||||
public void free()
|
||||
{
|
||||
GL32.glDeleteVertexArrays(id);
|
||||
}
|
||||
|
||||
// Requires VertexAttribute binded, VertexBuffer binded
|
||||
public abstract void bindBufferToAllBindingPoints(int buffer);
|
||||
// Requires VertexAttribute binded, VertexBuffer binded
|
||||
public abstract void bindBufferToBindingPoint(int buffer, int bindingPoint);
|
||||
// Requires VertexAttribute binded
|
||||
public abstract void unbindBuffersFromAllBindingPoint();
|
||||
// Requires VertexAttribute binded
|
||||
public abstract void unbindBuffersFromBindingPoint(int bindingPoint);
|
||||
// Requires VertexAttribute binded
|
||||
public abstract void setVertexAttribute(int bindingPoint, int attributeIndex, VertexPointer attribute);
|
||||
// Requires VertexAttribute binded
|
||||
public abstract void completeAndCheck(int expectedStrideSize);
|
||||
|
||||
}
|
||||
+11
-11
@@ -25,13 +25,13 @@ import org.lwjgl.opengl.GL43;
|
||||
/**
|
||||
* In OpenGL 4.3 and later, Vertex Attribute got a make-over.
|
||||
* Now it provides support for buffer binding points natively.
|
||||
* This means that setting up the VAO just use ONE native call when
|
||||
* This means that setting up the VAO is just use ONE native call when
|
||||
* binding to a buffer. <br><br>
|
||||
*
|
||||
* Since I no longer needs to implement binding points, I also no
|
||||
* Since I no longer need to implement binding points, I also no
|
||||
* longer needs to keep track of Pointers.
|
||||
*/
|
||||
public final class VertexAttributePostGL43 extends VertexAttribute
|
||||
public final class VertexAttributePostGL43 extends AbstractVertexAttribute
|
||||
{
|
||||
int numberOfBindingPoints = 0;
|
||||
int strideSize = 0;
|
||||
@@ -42,10 +42,10 @@ public final class VertexAttributePostGL43 extends VertexAttribute
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
/** This will bind the {@link VertexAttribute} */
|
||||
/** This will bind the {@link AbstractVertexAttribute} */
|
||||
public VertexAttributePostGL43()
|
||||
{
|
||||
super(); // also bind VertexAttribute
|
||||
super(); // also bind AbstractVertexAttribute
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class VertexAttributePostGL43 extends VertexAttribute
|
||||
// binding //
|
||||
//=========//
|
||||
|
||||
/** Requires both VertexAttribute and VertexBuffer to be bound */
|
||||
/** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
|
||||
@Override
|
||||
public void bindBufferToAllBindingPoints(int buffer)
|
||||
{
|
||||
@@ -64,7 +64,7 @@ public final class VertexAttributePostGL43 extends VertexAttribute
|
||||
}
|
||||
}
|
||||
|
||||
/** Requires both VertexAttribute and VertexBuffer to be bound */
|
||||
/** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
|
||||
@Override
|
||||
public void bindBufferToBindingPoint(int buffer, int bindingPoint)
|
||||
{
|
||||
@@ -77,7 +77,7 @@ public final class VertexAttributePostGL43 extends VertexAttribute
|
||||
// unbinding //
|
||||
//===========//
|
||||
|
||||
/** Requires VertexAttribute to be bound */
|
||||
/** Requires AbstractVertexAttribute to be bound */
|
||||
@Override
|
||||
public void unbindBuffersFromAllBindingPoint()
|
||||
{
|
||||
@@ -87,7 +87,7 @@ public final class VertexAttributePostGL43 extends VertexAttribute
|
||||
}
|
||||
}
|
||||
|
||||
/** Requires VertexAttribute to be bound */
|
||||
/** Requires AbstractVertexAttribute to be bound */
|
||||
@Override
|
||||
public void unbindBuffersFromBindingPoint(int bindingPoint)
|
||||
{
|
||||
@@ -100,7 +100,7 @@ public final class VertexAttributePostGL43 extends VertexAttribute
|
||||
// manual attribute setting //
|
||||
//==========================//
|
||||
|
||||
/** Requires VertexAttribute to be bound */
|
||||
/** Requires AbstractVertexAttribute to be bound */
|
||||
@Override
|
||||
public void setVertexAttribute(int bindingPoint, int attributeIndex, VertexPointer attribute)
|
||||
{
|
||||
@@ -129,7 +129,7 @@ public final class VertexAttributePostGL43 extends VertexAttribute
|
||||
// validation //
|
||||
//============//
|
||||
|
||||
/** Requires VertexAttribute to be bound */
|
||||
/** Requires AbstractVertexAttribute to be bound */
|
||||
@Override
|
||||
public void completeAndCheck(int expectedStrideSize)
|
||||
{
|
||||
|
||||
+10
-10
@@ -28,10 +28,10 @@ import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
|
||||
public final class VertexAttributePreGL43 extends VertexAttribute
|
||||
public final class VertexAttributePreGL43 extends AbstractVertexAttribute
|
||||
{
|
||||
// I tried to use raw arrays as much as possible since those lookups
|
||||
// happens every frame, and the speed directly affects fps
|
||||
// happen every frame, and the speed directly affects fps
|
||||
int strideSize = 0;
|
||||
int[][] bindingPointsToIndex;
|
||||
VertexPointer[] pointers;
|
||||
@@ -46,10 +46,10 @@ public final class VertexAttributePreGL43 extends VertexAttribute
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
/** This will bind the {@link VertexAttribute} */
|
||||
/** This will bind the {@link AbstractVertexAttribute} */
|
||||
public VertexAttributePreGL43()
|
||||
{
|
||||
super(); // also bind VertexAttribute
|
||||
super(); // also bind AbstractVertexAttribute
|
||||
this.bindingPointsToIndexBuilder = new TreeMap<>();
|
||||
this.pointersBuilder = new ArrayList<>();
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public final class VertexAttributePreGL43 extends VertexAttribute
|
||||
// binding //
|
||||
//=========//
|
||||
|
||||
/** Requires both VertexAttribute and VertexBuffer to be bound */
|
||||
/** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
|
||||
@Override
|
||||
public void bindBufferToAllBindingPoints(int buffer)
|
||||
{
|
||||
@@ -90,7 +90,7 @@ public final class VertexAttributePreGL43 extends VertexAttribute
|
||||
}
|
||||
}
|
||||
|
||||
/** Requires both VertexAttribute and VertexBuffer to be bound */
|
||||
/** Requires both AbstractVertexAttribute and VertexBuffer to be bound */
|
||||
@Override
|
||||
public void bindBufferToBindingPoint(int buffer, int bindingPoint)
|
||||
{
|
||||
@@ -129,7 +129,7 @@ public final class VertexAttributePreGL43 extends VertexAttribute
|
||||
// unbinding //
|
||||
//===========//
|
||||
|
||||
/** Requires VertexAttribute to be bound */
|
||||
/** Requires AbstractVertexAttribute to be bound */
|
||||
@Override
|
||||
public void unbindBuffersFromAllBindingPoint()
|
||||
{
|
||||
@@ -139,7 +139,7 @@ public final class VertexAttributePreGL43 extends VertexAttribute
|
||||
}
|
||||
}
|
||||
|
||||
/** Requires VertexAttribute to be bound */
|
||||
/** Requires AbstractVertexAttribute to be bound */
|
||||
@Override
|
||||
public void unbindBuffersFromBindingPoint(int bindingPoint)
|
||||
{
|
||||
@@ -156,7 +156,7 @@ public final class VertexAttributePreGL43 extends VertexAttribute
|
||||
// manual attribute setting //
|
||||
//==========================//
|
||||
|
||||
/** Requires VertexAttribute to be bound */
|
||||
/** Requires AbstractVertexAttribute to be bound */
|
||||
@Override
|
||||
public void setVertexAttribute(int bindingPoint, int attributeIndex, VertexPointer attribute)
|
||||
{
|
||||
@@ -178,7 +178,7 @@ public final class VertexAttributePreGL43 extends VertexAttribute
|
||||
// validation //
|
||||
//============//
|
||||
|
||||
/** Requires VertexAttribute to be bound */
|
||||
/** Requires AbstractVertexAttribute to be bound */
|
||||
@Override
|
||||
public void completeAndCheck(int expectedStrideSize)
|
||||
{
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2023 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.core.render.glObject.vertexAttribute;
|
||||
|
||||
import com.seibel.distanthorizons.coreapi.util.MathUtil;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
public final class VertexPointer
|
||||
{
|
||||
public final int elementCount;
|
||||
public final int glType;
|
||||
public final boolean normalized;
|
||||
public final int byteSize;
|
||||
public final boolean useInteger;
|
||||
|
||||
|
||||
|
||||
// basic constructors //
|
||||
|
||||
public VertexPointer(int elementCount, int glType, boolean normalized, int byteSize, boolean useInteger)
|
||||
{
|
||||
this.elementCount = elementCount;
|
||||
this.glType = glType;
|
||||
this.normalized = normalized;
|
||||
this.byteSize = byteSize;
|
||||
this.useInteger = useInteger;
|
||||
}
|
||||
public VertexPointer(int elementCount, int glType, boolean normalized, int byteSize)
|
||||
{
|
||||
this(elementCount, glType, normalized, byteSize, false);
|
||||
}
|
||||
private static int _align(int bytes) { return MathUtil.ceilDiv(bytes, 4) * 4; }
|
||||
|
||||
|
||||
|
||||
// named constructors //
|
||||
|
||||
public static VertexPointer addFloatPointer(boolean normalized) { return new VertexPointer(1, GL32.GL_FLOAT, normalized, Float.BYTES); }
|
||||
public static VertexPointer addVec2Pointer(boolean normalized) { return new VertexPointer(2, GL32.GL_FLOAT, normalized, Float.BYTES * 2); }
|
||||
public static VertexPointer addVec3Pointer(boolean normalized) { return new VertexPointer(3, GL32.GL_FLOAT, normalized, Float.BYTES * 3); }
|
||||
public static VertexPointer addVec4Pointer(boolean normalized) { return new VertexPointer(4, GL32.GL_FLOAT, normalized, Float.BYTES * 4); }
|
||||
/** Always aligned to 4 bytes */
|
||||
public static VertexPointer addUnsignedBytePointer(boolean normalized, boolean useInteger) { return new VertexPointer(1, GL32.GL_UNSIGNED_BYTE, normalized, 4, useInteger); }
|
||||
/** aligned to 4 bytes */
|
||||
public static VertexPointer addUnsignedBytesPointer(int elementCount, boolean normalized, boolean useInteger) { return new VertexPointer(elementCount, GL32.GL_UNSIGNED_BYTE, normalized, _align(elementCount), useInteger); }
|
||||
public static VertexPointer addUnsignedShortsPointer(int elementCount, boolean normalized, boolean useInteger) { return new VertexPointer(elementCount, GL32.GL_UNSIGNED_SHORT, normalized, _align(elementCount * 2), useInteger); }
|
||||
public static VertexPointer addShortsPointer(int elementCount, boolean normalized, boolean useInteger) { return new VertexPointer(elementCount, GL32.GL_SHORT, normalized, _align(elementCount * 2), useInteger); }
|
||||
public static VertexPointer addIntPointer(boolean normalized, boolean useInteger) { return new VertexPointer(1, GL32.GL_INT, normalized, 4, useInteger); }
|
||||
public static VertexPointer addIVec2Pointer(boolean normalized, boolean useInteger) { return new VertexPointer(2, GL32.GL_INT, normalized, 8, useInteger); }
|
||||
public static VertexPointer addIVec3Pointer(boolean normalized, boolean useInteger) { return new VertexPointer(3, GL32.GL_INT, normalized, 12, useInteger); }
|
||||
public static VertexPointer addIVec4Pointer(boolean normalized, boolean useInteger) { return new VertexPointer(4, GL32.GL_INT, normalized, 16, useInteger); }
|
||||
|
||||
}
|
||||
+5
-4
@@ -33,7 +33,8 @@ import com.seibel.distanthorizons.core.render.glObject.GLState;
|
||||
import com.seibel.distanthorizons.core.render.glObject.buffer.GLElementBuffer;
|
||||
import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
|
||||
import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttribute;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
|
||||
import com.seibel.distanthorizons.coreapi.util.math.Vec3d;
|
||||
@@ -66,7 +67,7 @@ public class DebugRenderer
|
||||
private ShaderProgram basicShader;
|
||||
private GLVertexBuffer boxBuffer;
|
||||
private GLElementBuffer boxOutlineBuffer;
|
||||
private VertexAttribute va;
|
||||
private AbstractVertexAttribute va;
|
||||
private boolean init = false;
|
||||
|
||||
// used when rendering
|
||||
@@ -155,10 +156,10 @@ public class DebugRenderer
|
||||
}
|
||||
|
||||
this.init = true;
|
||||
this.va = VertexAttribute.create();
|
||||
this.va = AbstractVertexAttribute.create();
|
||||
this.va.bind();
|
||||
// Pos
|
||||
this.va.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addVec3Pointer(false));
|
||||
this.va.setVertexAttribute(0, 0, VertexPointer.addVec3Pointer(false));
|
||||
this.va.completeAndCheck(Float.BYTES * 3);
|
||||
this.basicShader = new ShaderProgram("shaders/debug/vert.vert", "shaders/debug/frag.frag",
|
||||
"fragColor", new String[]{"vPosition"});
|
||||
|
||||
+8
-9
@@ -24,9 +24,10 @@ import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||
import com.seibel.distanthorizons.core.render.glObject.shader.Shader;
|
||||
import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttribute;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttributePostGL43;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttributePreGL43;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.render.fog.LodFogConfig;
|
||||
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
|
||||
@@ -40,7 +41,7 @@ public class LodRenderProgram extends ShaderProgram
|
||||
public static final String FRAGMENT_SHADER_PATH = "shaders/flat_shaded.frag";
|
||||
private static final IVersionConstants VERSION_CONSTANTS = SingletonInjector.INSTANCE.get(IVersionConstants.class);
|
||||
|
||||
public final VertexAttribute vao;
|
||||
public final AbstractVertexAttribute vao;
|
||||
|
||||
// Uniforms
|
||||
public final int combinedMatUniform;
|
||||
@@ -66,7 +67,7 @@ public class LodRenderProgram extends ShaderProgram
|
||||
|
||||
private final LodFogConfig fogConfig;
|
||||
|
||||
// This will bind VertexAttribute
|
||||
// This will bind AbstractVertexAttribute
|
||||
public LodRenderProgram(LodFogConfig fogConfig)
|
||||
{
|
||||
super(() -> Shader.loadFile(fogConfig.earthCurveRatio != 0 ? VERTEX_CURVE_SHADER_PATH : VERTEX_SHADER_PATH,
|
||||
@@ -97,15 +98,13 @@ public class LodRenderProgram extends ShaderProgram
|
||||
// TODO: Add better use of the LODFormat thing
|
||||
int vertexByteCount = LodUtil.LOD_VERTEX_FORMAT.getByteSize();
|
||||
if (GLProxy.getInstance().VertexAttributeBufferBindingSupported)
|
||||
vao = new VertexAttributePostGL43(); // also binds VertexAttribute
|
||||
vao = new VertexAttributePostGL43(); // also binds AbstractVertexAttribute
|
||||
else
|
||||
vao = new VertexAttributePreGL43(); // also binds VertexAttribute
|
||||
vao = new VertexAttributePreGL43(); // also binds AbstractVertexAttribute
|
||||
vao.bind();
|
||||
// Now a pos+light.
|
||||
vao.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addUnsignedShortsPointer(4, false, true)); // 2+2+2+2
|
||||
//vao.setVertexAttribute(0, posAttrib, VertexAttribute.VertexPointer.addVec3Pointer(false)); // 4+4+4
|
||||
vao.setVertexAttribute(0, 1, VertexAttribute.VertexPointer.addUnsignedBytesPointer(4, true, false)); // +4
|
||||
//vao.setVertexAttribute(0, lightAttrib, VertexAttribute.VertexPointer.addUnsignedBytesPointer(2, false)); // +4 due to how it aligns
|
||||
vao.setVertexAttribute(0, 0, VertexPointer.addUnsignedShortsPointer(4, false, true)); // 2+2+2+2
|
||||
vao.setVertexAttribute(0, 1, VertexPointer.addUnsignedBytesPointer(4, true, false)); // +4
|
||||
try
|
||||
{
|
||||
vao.completeAndCheck(vertexByteCount);
|
||||
|
||||
@@ -21,7 +21,8 @@ package com.seibel.distanthorizons.core.render.renderer;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.config.EGpuUploadMethod;
|
||||
import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttribute;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
|
||||
import org.lwjgl.opengl.GL32;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -45,7 +46,7 @@ public class ScreenQuad
|
||||
};
|
||||
|
||||
private GLVertexBuffer boxBuffer;
|
||||
private VertexAttribute va;
|
||||
private AbstractVertexAttribute va;
|
||||
private boolean init = false;
|
||||
|
||||
|
||||
@@ -60,11 +61,11 @@ public class ScreenQuad
|
||||
if (this.init) return;
|
||||
this.init = true;
|
||||
|
||||
this.va = VertexAttribute.create();
|
||||
this.va = AbstractVertexAttribute.create();
|
||||
this.va.bind();
|
||||
|
||||
// Pos
|
||||
this.va.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addVec2Pointer(false));
|
||||
this.va.setVertexAttribute(0, 0, VertexPointer.addVec2Pointer(false));
|
||||
this.va.completeAndCheck(Float.BYTES * 2);
|
||||
|
||||
// Framebuffer
|
||||
|
||||
+6
-5
@@ -28,7 +28,8 @@ import com.seibel.distanthorizons.core.render.glObject.GLProxy;
|
||||
import com.seibel.distanthorizons.core.render.glObject.GLState;
|
||||
import com.seibel.distanthorizons.core.render.glObject.buffer.GLVertexBuffer;
|
||||
import com.seibel.distanthorizons.core.render.glObject.shader.ShaderProgram;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexAttribute;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.AbstractVertexAttribute;
|
||||
import com.seibel.distanthorizons.core.render.glObject.vertexAttribute.VertexPointer;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -52,7 +53,7 @@ public class TestRenderer
|
||||
ShaderProgram basicShader;
|
||||
GLVertexBuffer sameContextBuffer;
|
||||
GLVertexBuffer sharedContextBuffer;
|
||||
VertexAttribute va;
|
||||
AbstractVertexAttribute va;
|
||||
boolean init = false;
|
||||
|
||||
public void init()
|
||||
@@ -60,12 +61,12 @@ public class TestRenderer
|
||||
if (init) return;
|
||||
logger.info("init");
|
||||
init = true;
|
||||
va = VertexAttribute.create();
|
||||
va = AbstractVertexAttribute.create();
|
||||
va.bind();
|
||||
// Pos
|
||||
va.setVertexAttribute(0, 0, VertexAttribute.VertexPointer.addVec2Pointer(false));
|
||||
va.setVertexAttribute(0, 0, VertexPointer.addVec2Pointer(false));
|
||||
// Color
|
||||
va.setVertexAttribute(0, 1, VertexAttribute.VertexPointer.addVec4Pointer(false));
|
||||
va.setVertexAttribute(0, 1, VertexPointer.addVec4Pointer(false));
|
||||
va.completeAndCheck(Float.BYTES * 6);
|
||||
basicShader = new ShaderProgram("shaders/test/vert.vert", "shaders/test/frag.frag",
|
||||
"fragColor", new String[]{"vPosition", "color"});
|
||||
|
||||
Reference in New Issue
Block a user