texture class cleanup work
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
85bba23cef
commit
7c8bc871e1
@ -1889,6 +1889,7 @@ New door furniture item
|
||||
Commenting rendering classes
|
||||
Convert Mesh.java to only use GL45
|
||||
Material and Mesh cleanup work
|
||||
Texture class cleanup work
|
||||
|
||||
|
||||
|
||||
|
||||
@ -13,18 +13,11 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL40;
|
||||
import org.lwjgl.opengl.GL45;
|
||||
import org.lwjgl.stb.STBImage;
|
||||
import org.lwjgl.system.MemoryStack;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE;
|
||||
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;
|
||||
import static org.lwjgl.opengl.GL14.*;
|
||||
import static org.lwjgl.opengl.GL30.*;
|
||||
|
||||
/**
|
||||
* A opengl in texture
|
||||
*/
|
||||
@ -74,7 +67,7 @@ public class Texture {
|
||||
* Creates a texture with a new opengl texture object
|
||||
*/
|
||||
public Texture(){
|
||||
this.texturePointer = GL40.glGenTextures();
|
||||
this.texturePointer = GL45.glGenTextures();
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
@ -84,18 +77,18 @@ public class Texture {
|
||||
* @param data The pre-parsed buffer of data from the buffered image
|
||||
*/
|
||||
public Texture(OpenGLState openGlState, BufferedImage bufferedImage, ByteBuffer data){
|
||||
this.texturePointer = GL40.glGenTextures();
|
||||
this.texturePointer = GL45.glGenTextures();
|
||||
Globals.renderingEngine.checkError();
|
||||
//bind the new texture
|
||||
openGlState.glBindTexture(GL_TEXTURE_2D, texturePointer);
|
||||
openGlState.glBindTexture(GL45.GL_TEXTURE_2D, texturePointer);
|
||||
//how are we gonna wrap the texture??
|
||||
this.setWrap(openGlState, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
|
||||
this.setWrap(openGlState, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
||||
this.setWrap(openGlState, GL45.GL_TEXTURE_WRAP_S, GL45.GL_MIRRORED_REPEAT);
|
||||
this.setWrap(openGlState, GL45.GL_TEXTURE_WRAP_T, GL45.GL_MIRRORED_REPEAT);
|
||||
//set the border color to black
|
||||
this.setBorderColor(openGlState, new float[]{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
//set magnification and minification operation sampling strategies
|
||||
this.setMinFilter(openGlState, GL_LINEAR);
|
||||
this.setMagFilter(openGlState, GL_LINEAR);
|
||||
this.setMinFilter(openGlState, GL45.GL_LINEAR);
|
||||
this.setMagFilter(openGlState, GL45.GL_LINEAR);
|
||||
//load the image here
|
||||
BufferedImage image_data = bufferedImage;
|
||||
if (
|
||||
@ -113,25 +106,25 @@ public class Texture {
|
||||
height = image_data.getHeight();
|
||||
//call if width != height so opengl figures out how to unpack it properly
|
||||
if(width != height){
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
GL45.glPixelStorei(GL45.GL_UNPACK_ALIGNMENT, 1);
|
||||
}
|
||||
//buffer the texture information
|
||||
if(hasTransparency){
|
||||
this.pixelFormat = GL_RGBA;
|
||||
this.datatype = GL_UNSIGNED_BYTE;
|
||||
this.glTexImage2D(openGlState, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
this.pixelFormat = GL45.GL_RGBA;
|
||||
this.datatype = GL45.GL_UNSIGNED_BYTE;
|
||||
this.glTexImage2D(openGlState, width, height, GL45.GL_RGBA, GL45.GL_UNSIGNED_BYTE, data);
|
||||
} else {
|
||||
this.pixelFormat = GL_RGB;
|
||||
this.datatype = GL_UNSIGNED_BYTE;
|
||||
this.glTexImage2D(openGlState, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
this.pixelFormat = GL45.GL_RGB;
|
||||
this.datatype = GL45.GL_UNSIGNED_BYTE;
|
||||
this.glTexImage2D(openGlState, width, height, GL45.GL_RGB, GL45.GL_UNSIGNED_BYTE, data);
|
||||
}
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
GL45.glGenerateMipmap(GL45.GL_TEXTURE_2D);
|
||||
//check build status
|
||||
String errorMessage = RenderingEngine.getErrorInEnglish(Globals.renderingEngine.getError());
|
||||
if(errorMessage != null){
|
||||
LoggerInterface.loggerRenderer.ERROR(new IllegalStateException("Texture Constructor[from bufferedimage]: " + errorMessage));
|
||||
}
|
||||
openGlState.glBindTexture(GL_TEXTURE_2D, 0);
|
||||
openGlState.glBindTexture(GL45.GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,18 +143,18 @@ public class Texture {
|
||||
if(!EngineState.EngineFlags.HEADLESS){
|
||||
LoggerInterface.loggerRenderer.DEBUG("Setup texture object");
|
||||
//generate the texture object on gpu
|
||||
this.texturePointer = GL40.glGenTextures();
|
||||
this.texturePointer = GL45.glGenTextures();
|
||||
Globals.renderingEngine.checkError();
|
||||
//bind the new texture
|
||||
openGlState.glBindTexture(GL_TEXTURE_2D, texturePointer);
|
||||
openGlState.glBindTexture(GL45.GL_TEXTURE_2D, texturePointer);
|
||||
//how are we gonna wrap the texture??
|
||||
this.setWrap(openGlState, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
|
||||
this.setWrap(openGlState, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
||||
this.setWrap(openGlState, GL45.GL_TEXTURE_WRAP_S, GL45.GL_MIRRORED_REPEAT);
|
||||
this.setWrap(openGlState, GL45.GL_TEXTURE_WRAP_T, GL45.GL_MIRRORED_REPEAT);
|
||||
//set the border color to black
|
||||
this.setBorderColor(openGlState, new float[]{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
//set magnification and minification operation sampling strategies
|
||||
this.setMinFilter(openGlState, GL_LINEAR);
|
||||
this.setMagFilter(openGlState, GL_LINEAR);
|
||||
this.setMinFilter(openGlState, GL45.GL_LINEAR);
|
||||
this.setMagFilter(openGlState, GL45.GL_LINEAR);
|
||||
|
||||
LoggerInterface.loggerRenderer.DEBUG("Create texture data buffers");
|
||||
//load the image here
|
||||
@ -199,23 +192,23 @@ public class Texture {
|
||||
|
||||
//call if width != height so opengl figures out how to unpack it properly
|
||||
if(width != height){
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
GL45.glPixelStorei(GL45.GL_UNPACK_ALIGNMENT, 1);
|
||||
}
|
||||
|
||||
LoggerInterface.loggerRenderer.DEBUG("Upload texture buffer");
|
||||
//buffer the texture information
|
||||
if(hasTransparency){
|
||||
this.pixelFormat = GL_RGBA;
|
||||
this.datatype = GL_UNSIGNED_BYTE;
|
||||
this.glTexImage2D(openGlState, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
this.pixelFormat = GL45.GL_RGBA;
|
||||
this.datatype = GL45.GL_UNSIGNED_BYTE;
|
||||
this.glTexImage2D(openGlState, width, height, GL45.GL_RGBA, GL45.GL_UNSIGNED_BYTE, data);
|
||||
} else {
|
||||
this.pixelFormat = GL_RGB;
|
||||
this.datatype = GL_UNSIGNED_BYTE;
|
||||
this.glTexImage2D(openGlState, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
this.pixelFormat = GL45.GL_RGB;
|
||||
this.datatype = GL45.GL_UNSIGNED_BYTE;
|
||||
this.glTexImage2D(openGlState, width, height, GL45.GL_RGB, GL45.GL_UNSIGNED_BYTE, data);
|
||||
}
|
||||
|
||||
LoggerInterface.loggerRenderer.DEBUG("Generate Mipmap");
|
||||
GL40.glGenerateMipmap(GL_TEXTURE_2D);
|
||||
GL45.glGenerateMipmap(GL45.GL_TEXTURE_2D);
|
||||
Globals.renderingEngine.checkError();
|
||||
//OPTIONAL free the original image data now that it's on the gpu
|
||||
// System.gc();
|
||||
@ -236,22 +229,22 @@ public class Texture {
|
||||
public Texture(OpenGLState openGlState, ByteBuffer buffer, int width, int height){
|
||||
if(!EngineState.EngineFlags.HEADLESS){
|
||||
//generate the texture object on gpu
|
||||
this.texturePointer = GL40.glGenTextures();
|
||||
this.texturePointer = GL45.glGenTextures();
|
||||
Globals.renderingEngine.checkError();
|
||||
//bind the new texture
|
||||
openGlState.glBindTexture(GL_TEXTURE_2D, texturePointer);
|
||||
openGlState.glBindTexture(GL45.GL_TEXTURE_2D, texturePointer);
|
||||
//how are we gonna wrap the texture??
|
||||
this.setWrap(openGlState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
this.setWrap(openGlState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
this.setWrap(openGlState, GL45.GL_TEXTURE_WRAP_S, GL45.GL_CLAMP_TO_EDGE);
|
||||
this.setWrap(openGlState, GL45.GL_TEXTURE_WRAP_T, GL45.GL_CLAMP_TO_EDGE);
|
||||
//disable mipmap
|
||||
this.setMinFilter(openGlState, GL_LINEAR);
|
||||
this.setMinFilter(openGlState, GL45.GL_LINEAR);
|
||||
//call if width != height so opengl figures out how to unpack it properly
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
GL45.glPixelStorei(GL45.GL_UNPACK_ALIGNMENT, 4);
|
||||
//GL_RED = 32bit r value
|
||||
//buffer the texture information
|
||||
this.pixelFormat = GL_RED;
|
||||
this.datatype = GL_FLOAT;
|
||||
this.glTexImage2D(openGlState, GL_R32F, width, height, GL_RED, GL_FLOAT, buffer);
|
||||
this.pixelFormat = GL45.GL_RED;
|
||||
this.datatype = GL45.GL_FLOAT;
|
||||
this.glTexImage2D(openGlState, GL45.GL_R32F, width, height, GL45.GL_RED, GL45.GL_FLOAT, buffer);
|
||||
//check build status
|
||||
String errorMessage = RenderingEngine.getErrorInEnglish(Globals.renderingEngine.getError());
|
||||
if(errorMessage != null){
|
||||
@ -272,23 +265,23 @@ public class Texture {
|
||||
if(!EngineState.EngineFlags.HEADLESS){
|
||||
rVal = new Texture();
|
||||
//generate the texture object on gpu
|
||||
rVal.texturePointer = GL40.glGenTextures();
|
||||
rVal.texturePointer = GL45.glGenTextures();
|
||||
Globals.renderingEngine.checkError();
|
||||
//bind the new texture
|
||||
openGlState.glBindTexture(GL_TEXTURE_2D, rVal.getTexturePointer());
|
||||
openGlState.glBindTexture(GL45.GL_TEXTURE_2D, rVal.getTexturePointer());
|
||||
//how are we gonna wrap the texture??
|
||||
rVal.setWrap(openGlState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
rVal.setWrap(openGlState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
rVal.setWrap(openGlState, GL45.GL_TEXTURE_WRAP_S, GL45.GL_CLAMP_TO_EDGE);
|
||||
rVal.setWrap(openGlState, GL45.GL_TEXTURE_WRAP_T, GL45.GL_CLAMP_TO_EDGE);
|
||||
//disable mipmap
|
||||
rVal.setMinFilter(openGlState, GL_LINEAR);
|
||||
rVal.setMagFilter(openGlState, GL_LINEAR);
|
||||
rVal.setMinFilter(openGlState, GL45.GL_LINEAR);
|
||||
rVal.setMagFilter(openGlState, GL45.GL_LINEAR);
|
||||
//call if width != height so opengl figures out how to unpack it properly
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
GL45.glPixelStorei(GL45.GL_UNPACK_ALIGNMENT, 4);
|
||||
//GL_RED = 32bit r value
|
||||
//buffer the texture information
|
||||
rVal.pixelFormat = GL_RED;
|
||||
rVal.datatype = GL_FLOAT;
|
||||
rVal.glTexImage2D(openGlState, GL40.GL_RED, width, height, GL40.GL_RED, GL40.GL_UNSIGNED_BYTE, buffer);
|
||||
rVal.pixelFormat = GL45.GL_RED;
|
||||
rVal.datatype = GL45.GL_FLOAT;
|
||||
rVal.glTexImage2D(openGlState, GL45.GL_RED, width, height, GL45.GL_RED, GL45.GL_UNSIGNED_BYTE, buffer);
|
||||
//check build status
|
||||
String errorMessage = RenderingEngine.getErrorInEnglish(Globals.renderingEngine.getError());
|
||||
if(errorMessage != null){
|
||||
@ -311,7 +304,7 @@ public class Texture {
|
||||
}
|
||||
// openGLState.glActiveTexture(GL_TEXTURE0);
|
||||
// openGLState.glBindTexture(GL_TEXTURE_2D, texturePointer);
|
||||
openGLState.glBindTextureUnit(GL_TEXTURE0,this.texturePointer,GL_TEXTURE_2D);
|
||||
openGLState.glBindTextureUnit(GL45.GL_TEXTURE0,this.texturePointer,GL45.GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -326,7 +319,7 @@ public class Texture {
|
||||
if(texturePointer == 0){
|
||||
LoggerInterface.loggerRenderer.ERROR(new IllegalStateException("Trying to bind texture object that has texturepointer of 0"));
|
||||
}
|
||||
openGLState.glBindTextureUnit(GL_TEXTURE0 + attrib_val,this.texturePointer,GL_TEXTURE_2D);
|
||||
openGLState.glBindTextureUnit(GL45.GL_TEXTURE0 + attrib_val,this.texturePointer,GL45.GL_TEXTURE_2D);
|
||||
Globals.renderingEngine.checkError();
|
||||
// openGLState.glActiveTexture(GL_TEXTURE0 + attrib_val);
|
||||
// openGLState.glBindTexture(GL_TEXTURE_2D, texturePointer);
|
||||
@ -363,9 +356,9 @@ public class Texture {
|
||||
*/
|
||||
public void setWrap(OpenGLState openGlState, int wrapDir, int wrapType){
|
||||
//TODO: store wrap type for the direction in this object
|
||||
openGlState.glBindTexture(GL_TEXTURE_2D,texturePointer);
|
||||
openGlState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer);
|
||||
Globals.renderingEngine.checkError();
|
||||
glTexParameteri(GL_TEXTURE_2D, wrapDir, wrapType);
|
||||
GL45.glTexParameteri(GL45.GL_TEXTURE_2D, wrapDir, wrapType);
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
@ -375,9 +368,9 @@ public class Texture {
|
||||
*/
|
||||
public void setBorderColor(OpenGLState openGlState, float borderColor[]){
|
||||
this.borderColor = borderColor;
|
||||
openGlState.glBindTexture(GL_TEXTURE_2D,texturePointer);
|
||||
openGlState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer);
|
||||
Globals.renderingEngine.checkError();
|
||||
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
|
||||
GL45.glTexParameterfv(GL45.GL_TEXTURE_2D, GL45.GL_TEXTURE_BORDER_COLOR, borderColor);
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
@ -387,9 +380,9 @@ public class Texture {
|
||||
*/
|
||||
public void setMinFilter(OpenGLState openGlState, int minFilter){
|
||||
this.minFilter = minFilter;
|
||||
openGlState.glBindTexture(GL_TEXTURE_2D,texturePointer);
|
||||
openGlState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer);
|
||||
Globals.renderingEngine.checkError();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
|
||||
GL45.glTexParameteri(GL45.GL_TEXTURE_2D, GL45.GL_TEXTURE_MIN_FILTER, minFilter);
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
@ -399,9 +392,9 @@ public class Texture {
|
||||
*/
|
||||
public void setMagFilter(OpenGLState openGlState, int maxFilter){
|
||||
this.maxFilter = maxFilter;
|
||||
openGlState.glBindTexture(GL_TEXTURE_2D,texturePointer);
|
||||
openGlState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer);
|
||||
Globals.renderingEngine.checkError();
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, maxFilter);
|
||||
GL45.glTexParameteri(GL45.GL_TEXTURE_2D, GL45.GL_TEXTURE_MAG_FILTER, maxFilter);
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
@ -432,9 +425,9 @@ public class Texture {
|
||||
//static values going into call
|
||||
int level = 0;
|
||||
int border = 0; //this must be 0 according to docs
|
||||
openGLState.glBindTexture(GL_TEXTURE_2D,texturePointer);
|
||||
openGLState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer);
|
||||
Globals.renderingEngine.checkError();
|
||||
GL40.glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, border, format, datatype, MemoryUtil.NULL);
|
||||
GL45.glTexImage2D(GL45.GL_TEXTURE_2D, level, internalFormat, width, height, border, format, datatype, MemoryUtil.NULL);
|
||||
Globals.renderingEngine.checkError();
|
||||
int[] storage = new int[1];
|
||||
int discoveredWidth = 0;
|
||||
@ -493,9 +486,9 @@ public class Texture {
|
||||
int level = 0;
|
||||
int border = 0; //this must be 0 according to docs
|
||||
int internalFormat = format;
|
||||
openGLState.glBindTexture(GL_TEXTURE_2D,texturePointer);
|
||||
openGLState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer);
|
||||
Globals.renderingEngine.checkError();
|
||||
GL40.glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, border, format, datatype, data);
|
||||
GL45.glTexImage2D(GL45.GL_TEXTURE_2D, level, internalFormat, width, height, border, format, datatype, data);
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
@ -522,9 +515,9 @@ public class Texture {
|
||||
//static values going into call
|
||||
int level = 0;
|
||||
int border = 0; //this must be 0 according to docs
|
||||
openGLState.glBindTexture(GL_TEXTURE_2D,texturePointer);
|
||||
openGLState.glBindTexture(GL45.GL_TEXTURE_2D,texturePointer);
|
||||
Globals.renderingEngine.checkError();
|
||||
GL40.glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, border, format, datatype, data);
|
||||
GL45.glTexImage2D(GL45.GL_TEXTURE_2D, level, internalFormat, width, height, border, format, datatype, data);
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
@ -592,9 +585,9 @@ public class Texture {
|
||||
//try bind approach
|
||||
this.bind(state);
|
||||
int errorCode = Globals.renderingEngine.getError();
|
||||
if(errorCode != GL40.GL_NO_ERROR){
|
||||
if(errorCode != GL45.GL_NO_ERROR){
|
||||
switch(errorCode){
|
||||
case GL40.GL_INVALID_VALUE: {
|
||||
case GL45.GL_INVALID_VALUE: {
|
||||
if(this.width < 0){
|
||||
LoggerInterface.loggerRenderer.ERROR("Texture has width less than 0", new IllegalStateException("Texture has width less than 0"));
|
||||
}
|
||||
@ -602,7 +595,7 @@ public class Texture {
|
||||
LoggerInterface.loggerRenderer.ERROR("Texture is greater width than environment allows", new IllegalStateException("Texture is greater width than environment allows"));
|
||||
}
|
||||
} break;
|
||||
case GL40.GL_INVALID_ENUM: {
|
||||
case GL45.GL_INVALID_ENUM: {
|
||||
|
||||
} break;
|
||||
default: {
|
||||
@ -612,7 +605,7 @@ public class Texture {
|
||||
}
|
||||
}
|
||||
//try dedicated approach
|
||||
boolean isTexture = GL40.glIsTexture(this.texturePointer);
|
||||
boolean isTexture = GL45.glIsTexture(this.texturePointer);
|
||||
if(!isTexture){
|
||||
String message = "Texture is not complete!";
|
||||
LoggerInterface.loggerRenderer.ERROR(new IllegalStateException(message));
|
||||
@ -623,7 +616,7 @@ public class Texture {
|
||||
* Frees the texture
|
||||
*/
|
||||
public void free(){
|
||||
GL40.glDeleteTextures(this.texturePointer);
|
||||
GL45.glDeleteTextures(this.texturePointer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user