diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 32e3238f..36af1927 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1888,6 +1888,7 @@ More block types New door furniture item Commenting rendering classes Convert Mesh.java to only use GL45 +Material and Mesh cleanup work diff --git a/src/main/java/electrosphere/renderer/actor/instance/TextureInstancedActor.java b/src/main/java/electrosphere/renderer/actor/instance/TextureInstancedActor.java index d7f17190..d7935572 100644 --- a/src/main/java/electrosphere/renderer/actor/instance/TextureInstancedActor.java +++ b/src/main/java/electrosphere/renderer/actor/instance/TextureInstancedActor.java @@ -159,7 +159,7 @@ public class TextureInstancedActor { openGLState.setActiveShader(renderPipelineState, shader); shader.setUniform(openGLState, uniformRowSize, rowSize); - this.material.apply_material(openGLState); + this.material.applyMaterial(openGLState); //apply uniform overrides if(this.uniformMap.getMeshes() != null && this.uniformMap.getMeshes().size() > 0){ diff --git a/src/main/java/electrosphere/renderer/model/Material.java b/src/main/java/electrosphere/renderer/model/Material.java index 77212d73..93f13b74 100644 --- a/src/main/java/electrosphere/renderer/model/Material.java +++ b/src/main/java/electrosphere/renderer/model/Material.java @@ -13,10 +13,7 @@ import org.lwjgl.assimp.AIScene; import org.lwjgl.assimp.AIString; import org.lwjgl.assimp.AITexture; import org.lwjgl.assimp.Assimp; -import org.lwjgl.opengl.GL40; - -import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D; -import static org.lwjgl.opengl.GL13.GL_TEXTURE0; +import org.lwjgl.opengl.GL45; import java.io.File; import java.nio.IntBuffer; @@ -277,7 +274,7 @@ public class 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 if(usesFetch){ if(diffuse != null){ @@ -299,7 +296,7 @@ public class Material { } } } else { - openGLState.glBindTextureUnit(GL_TEXTURE0, texturePointer, GL_TEXTURE_2D); + openGLState.glBindTextureUnit(GL45.GL_TEXTURE0, texturePointer, GL45.GL_TEXTURE_2D); Globals.renderingEngine.checkError(); } } @@ -325,7 +322,7 @@ public class Material { * Frees the material */ public void free(){ - GL40.glDeleteTextures(new int[]{ + GL45.glDeleteTextures(new int[]{ this.texturePointer, this.normalPointer, }); diff --git a/src/main/java/electrosphere/renderer/model/Mesh.java b/src/main/java/electrosphere/renderer/model/Mesh.java index 2f8ec92b..8b90f2ba 100644 --- a/src/main/java/electrosphere/renderer/model/Mesh.java +++ b/src/main/java/electrosphere/renderer/model/Mesh.java @@ -34,6 +34,31 @@ import org.lwjgl.system.MemoryStack; */ 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 */ @@ -177,7 +202,7 @@ public class Mesh { */ public void bufferVertices(FloatBuffer verticies, int vertexDimension){ 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){ 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){ 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(); GL45.glBindBuffer(GL45.GL_ARRAY_BUFFER, boneIndexBuffer); 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); } @@ -245,7 +270,7 @@ public class Mesh { boneWeightBuffer = GL45.glGenBuffers(); GL45.glBindBuffer(GL45.GL_ARRAY_BUFFER, boneWeightBuffer); 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); } @@ -437,10 +462,10 @@ public class Mesh { if(renderPipelineState.getUseMaterial() && textureMask == null){ Globals.renderingEngine.checkError(); if(material == null){ - Globals.renderingEngine.getDefaultMaterial().apply_material(openGLState); + Globals.renderingEngine.getDefaultMaterial().applyMaterial(openGLState); openGLState.getActiveShader().setUniform(openGLState, "hasTransparency", 0); } else { - material.apply_material(openGLState); + material.applyMaterial(openGLState); if(material.hasTransparency){ openGLState.getActiveShader().setUniform(openGLState, "hasTransparency", 1); } else { @@ -552,19 +577,19 @@ public class Mesh { if(renderPipelineState.getInstanced()){ - if(elementCount > 0 ){ - GL45.glDrawElementsInstanced(GL45.GL_TRIANGLES, elementCount, GL45.GL_UNSIGNED_INT, 0, renderPipelineState.getInstanceCount()); + if(this.elementCount > 0 ){ + GL45.glDrawElementsInstanced(GL45.GL_TRIANGLES, this.elementCount, GL45.GL_UNSIGNED_INT, 0, renderPipelineState.getInstanceCount()); Globals.renderingEngine.checkError(); } } else { - if(useElementArray){ - if(elementCount > 0){ - GL45.glDrawElements(GL45.GL_TRIANGLES, elementCount, GL45.GL_UNSIGNED_INT, 0); + if(this.useElementArray){ + if(this.elementCount > 0){ + GL45.glDrawElements(GL45.GL_TRIANGLES, this.elementCount, GL45.GL_UNSIGNED_INT, 0); Globals.renderingEngine.checkError(); } } else { - if(elementCount > 0){ - GL45.glDrawArrays(GL45.GL_TRIANGLES, 0, elementCount); + if(this.elementCount > 0){ + GL45.glDrawArrays(GL45.GL_TRIANGLES, 0, this.elementCount); Globals.renderingEngine.checkError(); } }