texture state caching fix
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-08-14 08:53:00 -04:00
parent bd297df672
commit 9750091a49
11 changed files with 78 additions and 107 deletions

View File

@ -19,5 +19,4 @@
Strafing walking animation Strafing walking animation
+ bug fixes + bug fixes
Rendering pipelines are broken when the katana is not drawn
Fix grass rendering distance Fix grass rendering distance

View File

@ -560,6 +560,9 @@ Update frame data for first person 2h sword swing to align with third person bet
Fix katana is frustum culled incorrectly Fix katana is frustum culled incorrectly
- This is because the data is incorrect (blender has an animation already applied, need to push down) - This is because the data is incorrect (blender has an animation already applied, need to push down)
(08/14/2024)
Fix rendering pipelines being broken when the katana is not drawn
# TODO # TODO

View File

@ -475,7 +475,7 @@ public class ClientFoliageManager {
buffer.position(0); buffer.position(0);
buffer.limit(TARGET_FOLIAGE_SPACING * TARGET_FOLIAGE_SPACING * SINGLE_FOLIAGE_DATA_SIZE_BYTES); buffer.limit(TARGET_FOLIAGE_SPACING * TARGET_FOLIAGE_SPACING * SINGLE_FOLIAGE_DATA_SIZE_BYTES);
//construct data texture //construct data texture
Texture dataTexture = new Texture(buffer,SINGLE_FOLIAGE_DATA_SIZE_BYTES / 4,TARGET_FOLIAGE_SPACING * TARGET_FOLIAGE_SPACING); Texture dataTexture = new Texture(Globals.renderingEngine.getOpenGLState(),buffer,SINGLE_FOLIAGE_DATA_SIZE_BYTES / 4,TARGET_FOLIAGE_SPACING * TARGET_FOLIAGE_SPACING);
//create entity //create entity
Entity grassEntity = EntityCreationUtils.createClientSpatialEntity(); Entity grassEntity = EntityCreationUtils.createClientSpatialEntity();

View File

@ -471,7 +471,6 @@ public class Main {
LoggerInterface.loggerStartup.INFO("Initialize control handler"); LoggerInterface.loggerStartup.INFO("Initialize control handler");
Globals.controlHandler = ControlHandler.generateExampleControlsMap(); Globals.controlHandler = ControlHandler.generateExampleControlsMap();
Globals.controlHandler.setCallbacks(); Globals.controlHandler.setCallbacks();
// Globals.controlHandler = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/keybinds.json",ControlHandler.class);
} }
/** /**
@ -485,29 +484,4 @@ public class Main {
// public static void updateMouseVariables(){
// glfwGetCursorPos(Globals.window, mouse_X_Buffer, mouse_Y_Buffer);
// xpos = mouse_X_Buffer[0];
// ypos = mouse_Y_Buffer[0];
// float xoffset = (float) (xpos - mouse_lastX) * mouseSensitivity;
// float yoffset = (float) (mouse_lastY - ypos) * mouseSensitivity;
// mouse_lastX = (float) xpos;
// mouse_lastY = (float) ypos;
// if(Globals.controlHandler != null && !Globals.controlHandler.isMouseVisible()){
// yaw = yaw + xoffset;
// pitch = pitch - yoffset;
// if (pitch > 100.0f) {
// pitch = 100.0f;
// }
// if (pitch < -99.0f) {
// pitch = -99.0f;
// }
// }
// }
} }

View File

@ -104,7 +104,7 @@ public class AssetManager {
//textures from disk to gpu //textures from disk to gpu
for(String currentPath : texturesInQueue){ for(String currentPath : texturesInQueue){
texturesInQueue.remove(currentPath); texturesInQueue.remove(currentPath);
texturesLoadedIntoMemory.put(currentPath, new Texture(currentPath)); texturesLoadedIntoMemory.put(currentPath, new Texture(Globals.renderingEngine.getOpenGLState(), currentPath));
} }
//audio from disk //audio from disk
if(Globals.audioEngine != null && Globals.audioEngine.initialized()){ if(Globals.audioEngine != null && Globals.audioEngine.initialized()){

View File

@ -2,6 +2,7 @@ package electrosphere.engine.assetmanager.queue;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import electrosphere.engine.Globals;
import electrosphere.renderer.texture.Texture; import electrosphere.renderer.texture.Texture;
/** /**
@ -29,7 +30,7 @@ public class QueuedTexture implements QueuedAsset {
@Override @Override
public void load() { public void load() {
texture = new Texture(data); texture = new Texture(Globals.renderingEngine.getOpenGLState(), data);
hasLoaded = true; hasLoaded = true;
} }

View File

@ -36,10 +36,6 @@ public class OpenGLState {
//the key that contains the value of glBlendFunc (which would affect all buffers) //the key that contains the value of glBlendFunc (which would affect all buffers)
static final int ALL_BUFFERS_KEY = -1; static final int ALL_BUFFERS_KEY = -1;
//the currently bound texture
int boundTexturePointer = 0;
int boundTextureType = 0;
//the currently active texture //the currently active texture
int activeTexture = 0; int activeTexture = 0;
@ -133,11 +129,7 @@ public class OpenGLState {
* @param textureValue The texture pointer * @param textureValue The texture pointer
*/ */
public void glBindTexture(int textureType, int texturePointer){ public void glBindTexture(int textureType, int texturePointer){
if(this.boundTexturePointer != texturePointer || this.boundTextureType != textureType){ this.glBindTextureUnit(this.activeTexture, texturePointer, textureType);
this.boundTextureType = textureType;
this.boundTexturePointer = texturePointer;
GL40.glBindTexture(this.boundTextureType,this.boundTexturePointer);
}
} }
/** /**
@ -149,7 +141,7 @@ public class OpenGLState {
public void glBindTextureUnit(int textureUnit, int texturePointer, int textureType){ public void glBindTextureUnit(int textureUnit, int texturePointer, int textureType){
if(!unitToPointerMap.containsKey(textureUnit) || unitToPointerMap.get(textureUnit)!=texturePointer){ if(!unitToPointerMap.containsKey(textureUnit) || unitToPointerMap.get(textureUnit)!=texturePointer){
unitToPointerMap.put(textureUnit,texturePointer); unitToPointerMap.put(textureUnit,texturePointer);
GL40.glActiveTexture(textureUnit); this.glActiveTexture(textureUnit);
GL40.glBindTexture(textureType,texturePointer); GL40.glBindTexture(textureType,texturePointer);
} }
} }

View File

@ -45,11 +45,11 @@ public class FramebufferUtils {
public static Texture generateScreenTextureColor(OpenGLState openGLState, int width, int height){ public static Texture generateScreenTextureColor(OpenGLState openGLState, int width, int height){
Texture texture = new Texture(); Texture texture = new Texture();
texture.glTexImage2D(openGLState, width, height, GL_RGB, GL_UNSIGNED_BYTE); texture.glTexImage2D(openGLState, width, height, GL_RGB, GL_UNSIGNED_BYTE);
texture.setMinFilter(GL_LINEAR); texture.setMinFilter(openGLState, GL_LINEAR);
texture.setMagFilter(GL_LINEAR); texture.setMagFilter(openGLState, GL_LINEAR);
//these make sure the texture actually clamps to the borders of the quad //these make sure the texture actually clamps to the borders of the quad
texture.setWrap(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
texture.setWrap(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
return texture; return texture;
@ -58,11 +58,11 @@ public class FramebufferUtils {
public static Texture generateScreenTextureColorAlpha(OpenGLState openGLState, int width, int height){ public static Texture generateScreenTextureColorAlpha(OpenGLState openGLState, int width, int height){
Texture texture = new Texture(); Texture texture = new Texture();
texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL_UNSIGNED_BYTE); texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL_UNSIGNED_BYTE);
texture.setMinFilter(GL_LINEAR); texture.setMinFilter(openGLState, GL_LINEAR);
texture.setMagFilter(GL_LINEAR); texture.setMagFilter(openGLState, GL_LINEAR);
//these make sure the texture actually clamps to the borders of the quad //these make sure the texture actually clamps to the borders of the quad
texture.setWrap(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
texture.setWrap(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
return texture; return texture;
@ -122,11 +122,11 @@ public class FramebufferUtils {
//texture //texture
Texture texture = new Texture(); Texture texture = new Texture();
texture.glTexImage2D(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE); texture.glTexImage2D(openGLState, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE);
texture.setMinFilter(GL_LINEAR); texture.setMinFilter(openGLState, GL_LINEAR);
texture.setMagFilter(GL_LINEAR); texture.setMagFilter(openGLState, GL_LINEAR);
//these make sure the texture actually clamps to the borders of the quad //these make sure the texture actually clamps to the borders of the quad
texture.setWrap(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
texture.setWrap(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
//bind texture to fbo //bind texture to fbo
buffer.setMipMapLevel(0); buffer.setMipMapLevel(0);
@ -148,11 +148,11 @@ public class FramebufferUtils {
//texture //texture
Texture texture = new Texture(); Texture texture = new Texture();
texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL_UNSIGNED_BYTE); texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL_UNSIGNED_BYTE);
texture.setMinFilter(GL_LINEAR); texture.setMinFilter(openGLState, GL_LINEAR);
texture.setMagFilter(GL_LINEAR); texture.setMagFilter(openGLState, GL_LINEAR);
//these make sure the texture actually clamps to the borders of the quad //these make sure the texture actually clamps to the borders of the quad
texture.setWrap(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
texture.setWrap(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
//bind texture to fbo //bind texture to fbo
buffer.setMipMapLevel(0); buffer.setMipMapLevel(0);
@ -192,11 +192,11 @@ public class FramebufferUtils {
//texture //texture
Texture texture = new Texture(); Texture texture = new Texture();
texture.glTexImage2D(openGLState, depthMapWidth, depthMapHeight, GL_DEPTH_COMPONENT, GL_FLOAT); texture.glTexImage2D(openGLState, depthMapWidth, depthMapHeight, GL_DEPTH_COMPONENT, GL_FLOAT);
texture.setMinFilter(GL_NEAREST); texture.setMinFilter(openGLState, GL_NEAREST);
texture.setMagFilter(GL_NEAREST); texture.setMagFilter(openGLState, GL_NEAREST);
texture.setWrap(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
texture.setWrap(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
texture.setBorderColor(new float[]{ 1.0f, 1.0f, 1.0f, 1.0f }); texture.setBorderColor(openGLState, new float[]{ 1.0f, 1.0f, 1.0f, 1.0f });
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
//bind texture to fbo //bind texture to fbo
@ -216,11 +216,11 @@ public class FramebufferUtils {
public static Texture generateDepthBufferTexture(OpenGLState openGLState, int width, int height){ public static Texture generateDepthBufferTexture(OpenGLState openGLState, int width, int height){
Texture texture = new Texture(); Texture texture = new Texture();
texture.glTexImage2D(openGLState, width, height, GL_DEPTH_COMPONENT, GL_SHORT); texture.glTexImage2D(openGLState, width, height, GL_DEPTH_COMPONENT, GL_SHORT);
texture.setMinFilter(GL_NEAREST); texture.setMinFilter(openGLState, GL_NEAREST);
texture.setMagFilter(GL_NEAREST); texture.setMagFilter(openGLState, GL_NEAREST);
texture.setWrap(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); texture.setWrap(openGLState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
texture.setWrap(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); texture.setWrap(openGLState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
texture.setBorderColor(new float[]{ 1.0f, 1.0f, 1.0f, 1.0f }); texture.setBorderColor(openGLState, new float[]{ 1.0f, 1.0f, 1.0f, 1.0f });
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
return texture; return texture;
} }
@ -245,8 +245,8 @@ public class FramebufferUtils {
public static Texture generateOITAccumulatorTexture(OpenGLState openGLState, int width, int height){ public static Texture generateOITAccumulatorTexture(OpenGLState openGLState, int width, int height){
Texture texture = new Texture(); Texture texture = new Texture();
texture.setMinFilter(GL_LINEAR); texture.setMinFilter(openGLState, GL_LINEAR);
texture.setMagFilter(GL_LINEAR); texture.setMagFilter(openGLState, GL_LINEAR);
texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL_HALF_FLOAT); texture.glTexImage2D(openGLState, width, height, GL_RGBA, GL_HALF_FLOAT);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
return texture; return texture;
@ -254,8 +254,8 @@ public class FramebufferUtils {
public static Texture generateOITRevealageTexture(OpenGLState openGLState, int width, int height){ public static Texture generateOITRevealageTexture(OpenGLState openGLState, int width, int height){
Texture texture = new Texture(); Texture texture = new Texture();
texture.setMinFilter(GL_LINEAR); texture.setMinFilter(openGLState, GL_LINEAR);
texture.setMagFilter(GL_LINEAR); texture.setMagFilter(openGLState, GL_LINEAR);
texture.glTexImage2D(openGLState, width, height, GL_RED, GL_FLOAT); texture.glTexImage2D(openGLState, width, height, GL_RED, GL_FLOAT);
texture.checkStatus(openGLState); texture.checkStatus(openGLState);
return texture; return texture;

View File

@ -67,18 +67,18 @@ public class Texture {
* Creates an in engine texture object from a java bufferedimage object * Creates an in engine texture object from a java bufferedimage object
* @param bufferedImage The java bufferedimage object * @param bufferedImage The java bufferedimage object
*/ */
public Texture(BufferedImage bufferedImage){ public Texture(OpenGLState openGlState, BufferedImage bufferedImage){
this.texturePointer = glGenTextures(); this.texturePointer = glGenTextures();
//bind the new texture //bind the new texture
glBindTexture(GL_TEXTURE_2D, texturePointer); openGlState.glBindTexture(GL_TEXTURE_2D, texturePointer);
//how are we gonna wrap the texture?? //how are we gonna wrap the texture??
this.setWrap(GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); this.setWrap(openGlState, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
this.setWrap(GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); this.setWrap(openGlState, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
//set the border color to black //set the border color to black
this.setBorderColor(new float[]{ 0.0f, 0.0f, 0.0f, 1.0f }); this.setBorderColor(openGlState, new float[]{ 0.0f, 0.0f, 0.0f, 1.0f });
//set magnification and minification operation sampling strategies //set magnification and minification operation sampling strategies
this.setMinFilter(GL_LINEAR); this.setMinFilter(openGlState, GL_LINEAR);
this.setMagFilter(GL_LINEAR); this.setMagFilter(openGlState, GL_LINEAR);
//load the image here //load the image here
ByteBuffer data; ByteBuffer data;
width = 1; width = 1;
@ -123,11 +123,11 @@ public class Texture {
if(hasTransparency){ if(hasTransparency){
this.pixelFormat = GL_RGBA; this.pixelFormat = GL_RGBA;
this.datatype = GL_UNSIGNED_BYTE; this.datatype = GL_UNSIGNED_BYTE;
this.glTexImage2D(width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); this.glTexImage2D(openGlState, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
} else { } else {
this.pixelFormat = GL_RGB; this.pixelFormat = GL_RGB;
this.datatype = GL_UNSIGNED_BYTE; this.datatype = GL_UNSIGNED_BYTE;
this.glTexImage2D(width, height, GL_RGB, GL_UNSIGNED_BYTE, data); this.glTexImage2D(openGlState, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
} }
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
//check build status //check build status
@ -135,28 +135,28 @@ public class Texture {
if(errorMessage != null){ if(errorMessage != null){
LoggerInterface.loggerRenderer.ERROR(new IllegalStateException("Texture Constructor[from bufferedimage]: " + errorMessage)); LoggerInterface.loggerRenderer.ERROR(new IllegalStateException("Texture Constructor[from bufferedimage]: " + errorMessage));
} }
glBindTexture(GL_TEXTURE_2D, 0); openGlState.glBindTexture(GL_TEXTURE_2D, 0);
} }
/** /**
* Creates a texture from an existing file * Creates a texture from an existing file
* @param path The path to the image file * @param path The path to the image file
*/ */
public Texture(String path){ public Texture(OpenGLState openGlState, String path){
this.path = path; this.path = path;
if(!Globals.HEADLESS){ if(!Globals.HEADLESS){
//generate the texture object on gpu //generate the texture object on gpu
this.texturePointer = glGenTextures(); this.texturePointer = glGenTextures();
//bind the new texture //bind the new texture
glBindTexture(GL_TEXTURE_2D, texturePointer); openGlState.glBindTexture(GL_TEXTURE_2D, texturePointer);
//how are we gonna wrap the texture?? //how are we gonna wrap the texture??
this.setWrap(GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); this.setWrap(openGlState, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
this.setWrap(GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); this.setWrap(openGlState, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
//set the border color to black //set the border color to black
this.setBorderColor(new float[]{ 0.0f, 0.0f, 0.0f, 1.0f }); this.setBorderColor(openGlState, new float[]{ 0.0f, 0.0f, 0.0f, 1.0f });
//set magnification and minification operation sampling strategies //set magnification and minification operation sampling strategies
this.setMinFilter(GL_LINEAR); this.setMinFilter(openGlState, GL_LINEAR);
this.setMagFilter(GL_LINEAR); this.setMagFilter(openGlState, GL_LINEAR);
//load the image here //load the image here
ByteBuffer data; ByteBuffer data;
width = 1; width = 1;
@ -226,11 +226,11 @@ public class Texture {
if(hasTransparency){ if(hasTransparency){
this.pixelFormat = GL_RGBA; this.pixelFormat = GL_RGBA;
this.datatype = GL_UNSIGNED_BYTE; this.datatype = GL_UNSIGNED_BYTE;
this.glTexImage2D(width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); this.glTexImage2D(openGlState, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
} else { } else {
this.pixelFormat = GL_RGB; this.pixelFormat = GL_RGB;
this.datatype = GL_UNSIGNED_BYTE; this.datatype = GL_UNSIGNED_BYTE;
this.glTexImage2D(width, height, GL_RGB, GL_UNSIGNED_BYTE, data); this.glTexImage2D(openGlState, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
} }
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
//OPTIONAL free the original image data now that it's on the gpu //OPTIONAL free the original image data now that it's on the gpu
@ -249,17 +249,17 @@ public class Texture {
* @param width the 'width' of the 'texture' * @param width the 'width' of the 'texture'
* @param height the 'height' of the 'texture' * @param height the 'height' of the 'texture'
*/ */
public Texture(ByteBuffer buffer, int width, int height){ public Texture(OpenGLState openGlState, ByteBuffer buffer, int width, int height){
if(!Globals.HEADLESS){ if(!Globals.HEADLESS){
//generate the texture object on gpu //generate the texture object on gpu
this.texturePointer = glGenTextures(); this.texturePointer = glGenTextures();
//bind the new texture //bind the new texture
glBindTexture(GL_TEXTURE_2D, texturePointer); openGlState.glBindTexture(GL_TEXTURE_2D, texturePointer);
//how are we gonna wrap the texture?? //how are we gonna wrap the texture??
this.setWrap(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); this.setWrap(openGlState, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
this.setWrap(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); this.setWrap(openGlState, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//disable mipmap //disable mipmap
this.setMinFilter(GL_LINEAR); this.setMinFilter(openGlState, GL_LINEAR);
//call if width != height so opengl figures out how to unpack it properly //call if width != height so opengl figures out how to unpack it properly
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
//GL_RED = 32bit r value //GL_RED = 32bit r value
@ -337,9 +337,9 @@ public class Texture {
* @param wrapDir The direction to wrap * @param wrapDir The direction to wrap
* @param wrapType The type of wrapping to perform * @param wrapType The type of wrapping to perform
*/ */
public void setWrap(int wrapDir, int wrapType){ public void setWrap(OpenGLState openGlState, int wrapDir, int wrapType){
//TODO: store wrap type for the direction in this object //TODO: store wrap type for the direction in this object
glBindTexture(GL_TEXTURE_2D,texturePointer); openGlState.glBindTexture(GL_TEXTURE_2D,texturePointer);
glTexParameteri(GL_TEXTURE_2D, wrapDir, wrapType); glTexParameteri(GL_TEXTURE_2D, wrapDir, wrapType);
} }
@ -347,9 +347,9 @@ public class Texture {
* Sets the border color * Sets the border color
* @param borderColor The color (must be 4 floats) * @param borderColor The color (must be 4 floats)
*/ */
public void setBorderColor(float borderColor[]){ public void setBorderColor(OpenGLState openGlState, float borderColor[]){
this.borderColor = borderColor; this.borderColor = borderColor;
glBindTexture(GL_TEXTURE_2D,texturePointer); openGlState.glBindTexture(GL_TEXTURE_2D,texturePointer);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
} }
@ -357,9 +357,9 @@ public class Texture {
* Sets the min filter * Sets the min filter
* @param minFilter The min filter * @param minFilter The min filter
*/ */
public void setMinFilter(int minFilter){ public void setMinFilter(OpenGLState openGlState, int minFilter){
this.minFilter = minFilter; this.minFilter = minFilter;
glBindTexture(GL_TEXTURE_2D,texturePointer); openGlState.glBindTexture(GL_TEXTURE_2D,texturePointer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter);
} }
@ -367,9 +367,9 @@ public class Texture {
* Sets the max filter * Sets the max filter
* @param maxFilter The max filter * @param maxFilter The max filter
*/ */
public void setMagFilter(int maxFilter){ public void setMagFilter(OpenGLState openGlState, int maxFilter){
this.maxFilter = maxFilter; this.maxFilter = maxFilter;
glBindTexture(GL_TEXTURE_2D,texturePointer); openGlState.glBindTexture(GL_TEXTURE_2D,texturePointer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, maxFilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, maxFilter);
} }
@ -402,7 +402,7 @@ public class Texture {
* @param datatype The data type of a single component of a pixel (ie GL_BYTE, GL_UNSIGNED_INT, etc) * @param datatype The data type of a single component of a pixel (ie GL_BYTE, GL_UNSIGNED_INT, etc)
* @param data The data to populate the image with * @param data The data to populate the image with
*/ */
public void glTexImage2D(int width, int height, int format, int datatype, ByteBuffer data){ public void glTexImage2D(OpenGLState openGLState, int width, int height, int format, int datatype, ByteBuffer data){
//store provided values //store provided values
this.width = width; this.width = width;
this.height = height; this.height = height;
@ -411,7 +411,7 @@ public class Texture {
//static values going into call //static values going into call
int level = 0; int level = 0;
int border = 0; //this must be 0 according to docs int border = 0; //this must be 0 according to docs
glBindTexture(GL_TEXTURE_2D,texturePointer); openGLState.glBindTexture(GL_TEXTURE_2D,texturePointer);
GL40.glTexImage2D(GL_TEXTURE_2D, level, format, width, height, border, format, datatype, data); GL40.glTexImage2D(GL_TEXTURE_2D, level, format, width, height, border, format, datatype, data);
} }

View File

@ -5,6 +5,7 @@ import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.util.FileUtils; import electrosphere.util.FileUtils;
@ -46,7 +47,7 @@ public class FontManager {
font = new java.awt.Font(java.awt.Font.MONOSPACED, java.awt.Font.PLAIN, 16); font = new java.awt.Font(java.awt.Font.MONOSPACED, java.awt.Font.PLAIN, 16);
} }
if(font!=null){ if(font!=null){
defaultFont = FontUtils.loadFont(font, false); defaultFont = FontUtils.loadFont(Globals.renderingEngine.getOpenGLState(), font, false);
fontMap.put("default",defaultFont); fontMap.put("default",defaultFont);
} }
} }

View File

@ -1,5 +1,6 @@
package electrosphere.renderer.ui.font; package electrosphere.renderer.ui.font;
import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.model.Material; import electrosphere.renderer.model.Material;
import electrosphere.renderer.texture.Texture; import electrosphere.renderer.texture.Texture;
@ -68,7 +69,7 @@ public class FontUtils {
* @param antiAlias if true, antialias, otherwise dont * @param antiAlias if true, antialias, otherwise dont
* @return The engine font object * @return The engine font object
*/ */
protected static Font loadFont(java.awt.Font font, boolean antiAlias) { protected static Font loadFont(OpenGLState openGLState, java.awt.Font font, boolean antiAlias) {
int imageWidth = 0; int imageWidth = 0;
int imageHeight = 0; int imageHeight = 0;
@ -152,7 +153,7 @@ public class FontUtils {
//create material with new font image //create material with new font image
Material uiMat = new Material(); Material uiMat = new Material();
Texture texture = new Texture(image); Texture texture = new Texture(openGLState, image);
uiMat.setTexturePointer(texture.getTexturePointer()); uiMat.setTexturePointer(texture.getTexturePointer());