material and mesh cleanup work

This commit is contained in:
austin 2025-05-18 23:00:45 -04:00
parent 4e84f1c516
commit 85bba23cef
4 changed files with 45 additions and 22 deletions

View File

@ -1888,6 +1888,7 @@ More block types
New door furniture item New door furniture item
Commenting rendering classes Commenting rendering classes
Convert Mesh.java to only use GL45 Convert Mesh.java to only use GL45
Material and Mesh cleanup work

View File

@ -159,7 +159,7 @@ public class TextureInstancedActor {
openGLState.setActiveShader(renderPipelineState, shader); openGLState.setActiveShader(renderPipelineState, shader);
shader.setUniform(openGLState, uniformRowSize, rowSize); shader.setUniform(openGLState, uniformRowSize, rowSize);
this.material.apply_material(openGLState); this.material.applyMaterial(openGLState);
//apply uniform overrides //apply uniform overrides
if(this.uniformMap.getMeshes() != null && this.uniformMap.getMeshes().size() > 0){ if(this.uniformMap.getMeshes() != null && this.uniformMap.getMeshes().size() > 0){

View File

@ -13,10 +13,7 @@ import org.lwjgl.assimp.AIScene;
import org.lwjgl.assimp.AIString; import org.lwjgl.assimp.AIString;
import org.lwjgl.assimp.AITexture; import org.lwjgl.assimp.AITexture;
import org.lwjgl.assimp.Assimp; import org.lwjgl.assimp.Assimp;
import org.lwjgl.opengl.GL40; import org.lwjgl.opengl.GL45;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;
import java.io.File; import java.io.File;
import java.nio.IntBuffer; import java.nio.IntBuffer;
@ -277,7 +274,7 @@ public class Material {
/** /**
* Applies the material * Applies the material
*/ */
public void apply_material(OpenGLState openGLState){ public void applyMaterial(OpenGLState openGLState){
//Controls whether the texturePointer should be resolved by looking up the diffuse in asset manager or using the texture pointer already set in this material //Controls whether the texturePointer should be resolved by looking up the diffuse in asset manager or using the texture pointer already set in this material
if(usesFetch){ if(usesFetch){
if(diffuse != null){ if(diffuse != null){
@ -299,7 +296,7 @@ public class Material {
} }
} }
} else { } else {
openGLState.glBindTextureUnit(GL_TEXTURE0, texturePointer, GL_TEXTURE_2D); openGLState.glBindTextureUnit(GL45.GL_TEXTURE0, texturePointer, GL45.GL_TEXTURE_2D);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
} }
} }
@ -325,7 +322,7 @@ public class Material {
* Frees the material * Frees the material
*/ */
public void free(){ public void free(){
GL40.glDeleteTextures(new int[]{ GL45.glDeleteTextures(new int[]{
this.texturePointer, this.texturePointer,
this.normalPointer, this.normalPointer,
}); });

View File

@ -34,6 +34,31 @@ import org.lwjgl.system.MemoryStack;
*/ */
public class Mesh { public class Mesh {
/**
* The default index for the vertex attribute
*/
public static final int DEFAULT_VERTEX_ATTRIB_INDEX = 0;
/**
* The default index for the normal attribute
*/
public static final int DEFAULT_NORMAL_ATTRIB_INDEX = 1;
/**
* The default index for the bone weights attribute
*/
public static final int DEFAULT_BONE_WEIGHTS_ATTRIB_INDEX = 2;
/**
* The default index for the bone indices attribute
*/
public static final int DEFAULT_BONE_INDICES_ATTRIB_INDEX = 3;
/**
* The default index for the texture attribute
*/
public static final int DEFAULT_TEXTURE_ATTRIB_INDEX = 4;
/** /**
* The name of this mesh * The name of this mesh
*/ */
@ -177,7 +202,7 @@ public class Mesh {
*/ */
public void bufferVertices(FloatBuffer verticies, int vertexDimension){ public void bufferVertices(FloatBuffer verticies, int vertexDimension){
if(!EngineState.EngineFlags.HEADLESS){ if(!EngineState.EngineFlags.HEADLESS){
vertexBuffer = bufferCustomFloatAttribArray(verticies,vertexDimension,0); vertexBuffer = this.bufferCustomFloatAttribArray(verticies,vertexDimension,Mesh.DEFAULT_VERTEX_ATTRIB_INDEX);
} }
} }
@ -188,7 +213,7 @@ public class Mesh {
*/ */
public void bufferNormals(FloatBuffer normals, int normalDimension){ public void bufferNormals(FloatBuffer normals, int normalDimension){
if(!EngineState.EngineFlags.HEADLESS){ if(!EngineState.EngineFlags.HEADLESS){
normalBuffer = bufferCustomFloatAttribArray(normals,normalDimension,1); normalBuffer = this.bufferCustomFloatAttribArray(normals,normalDimension,Mesh.DEFAULT_NORMAL_ATTRIB_INDEX);
} }
} }
@ -221,7 +246,7 @@ public class Mesh {
*/ */
public void bufferTextureCoords(FloatBuffer coords, int textureDimension){ public void bufferTextureCoords(FloatBuffer coords, int textureDimension){
if(!EngineState.EngineFlags.HEADLESS){ if(!EngineState.EngineFlags.HEADLESS){
textureCoordBuffer = bufferCustomFloatAttribArray(coords, textureDimension, 4); textureCoordBuffer = this.bufferCustomFloatAttribArray(coords, textureDimension, Mesh.DEFAULT_TEXTURE_ATTRIB_INDEX);
} }
} }
@ -233,7 +258,7 @@ public class Mesh {
boneIndexBuffer = GL45.glGenBuffers(); boneIndexBuffer = GL45.glGenBuffers();
GL45.glBindBuffer(GL45.GL_ARRAY_BUFFER, boneIndexBuffer); GL45.glBindBuffer(GL45.GL_ARRAY_BUFFER, boneIndexBuffer);
GL45.glBufferData(GL45.GL_ARRAY_BUFFER, buffer, GL45.GL_STATIC_DRAW); GL45.glBufferData(GL45.GL_ARRAY_BUFFER, buffer, GL45.GL_STATIC_DRAW);
GL45.glVertexAttribPointer(3, 4, GL45.GL_FLOAT, false, 0, 0); GL45.glVertexAttribPointer(Mesh.DEFAULT_BONE_INDICES_ATTRIB_INDEX, 4, GL45.GL_FLOAT, false, 0, 0);
GL45.glEnableVertexAttribArray(3); GL45.glEnableVertexAttribArray(3);
} }
@ -245,7 +270,7 @@ public class Mesh {
boneWeightBuffer = GL45.glGenBuffers(); boneWeightBuffer = GL45.glGenBuffers();
GL45.glBindBuffer(GL45.GL_ARRAY_BUFFER, boneWeightBuffer); GL45.glBindBuffer(GL45.GL_ARRAY_BUFFER, boneWeightBuffer);
GL45.glBufferData(GL45.GL_ARRAY_BUFFER, buffer, GL45.GL_STATIC_DRAW); GL45.glBufferData(GL45.GL_ARRAY_BUFFER, buffer, GL45.GL_STATIC_DRAW);
GL45.glVertexAttribPointer(2, 4, GL45.GL_FLOAT, false, 0, 0); GL45.glVertexAttribPointer(Mesh.DEFAULT_BONE_WEIGHTS_ATTRIB_INDEX, 4, GL45.GL_FLOAT, false, 0, 0);
GL45.glEnableVertexAttribArray(2); GL45.glEnableVertexAttribArray(2);
} }
@ -437,10 +462,10 @@ public class Mesh {
if(renderPipelineState.getUseMaterial() && textureMask == null){ if(renderPipelineState.getUseMaterial() && textureMask == null){
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
if(material == null){ if(material == null){
Globals.renderingEngine.getDefaultMaterial().apply_material(openGLState); Globals.renderingEngine.getDefaultMaterial().applyMaterial(openGLState);
openGLState.getActiveShader().setUniform(openGLState, "hasTransparency", 0); openGLState.getActiveShader().setUniform(openGLState, "hasTransparency", 0);
} else { } else {
material.apply_material(openGLState); material.applyMaterial(openGLState);
if(material.hasTransparency){ if(material.hasTransparency){
openGLState.getActiveShader().setUniform(openGLState, "hasTransparency", 1); openGLState.getActiveShader().setUniform(openGLState, "hasTransparency", 1);
} else { } else {
@ -552,19 +577,19 @@ public class Mesh {
if(renderPipelineState.getInstanced()){ if(renderPipelineState.getInstanced()){
if(elementCount > 0 ){ if(this.elementCount > 0 ){
GL45.glDrawElementsInstanced(GL45.GL_TRIANGLES, elementCount, GL45.GL_UNSIGNED_INT, 0, renderPipelineState.getInstanceCount()); GL45.glDrawElementsInstanced(GL45.GL_TRIANGLES, this.elementCount, GL45.GL_UNSIGNED_INT, 0, renderPipelineState.getInstanceCount());
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
} }
} else { } else {
if(useElementArray){ if(this.useElementArray){
if(elementCount > 0){ if(this.elementCount > 0){
GL45.glDrawElements(GL45.GL_TRIANGLES, elementCount, GL45.GL_UNSIGNED_INT, 0); GL45.glDrawElements(GL45.GL_TRIANGLES, this.elementCount, GL45.GL_UNSIGNED_INT, 0);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
} }
} else { } else {
if(elementCount > 0){ if(this.elementCount > 0){
GL45.glDrawArrays(GL45.GL_TRIANGLES, 0, elementCount); GL45.glDrawArrays(GL45.GL_TRIANGLES, 0, this.elementCount);
Globals.renderingEngine.checkError(); Globals.renderingEngine.checkError();
} }
} }