defer texture atlas update to start of frame
This commit is contained in:
parent
1316ee560b
commit
2448143454
|
@ -13,6 +13,7 @@ import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
class GLTextureAtlas {
|
class GLTextureAtlas {
|
||||||
private Image img;
|
private Image img;
|
||||||
|
boolean shouldUpdate;
|
||||||
private int textureID;
|
private int textureID;
|
||||||
private List<GLTexture> textures;
|
private List<GLTexture> textures;
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ class GLTextureAtlas {
|
||||||
img = new Image(new Vec2i(32, 32));
|
img = new Image(new Vec2i(32, 32));
|
||||||
textureID = glGenTextures();
|
textureID = glGenTextures();
|
||||||
textures = new ArrayList<>();
|
textures = new ArrayList<>();
|
||||||
|
shouldUpdate = false;
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
@ -32,9 +34,7 @@ class GLTextureAtlas {
|
||||||
//this.img = img;
|
//this.img = img;
|
||||||
var texture = new GLTexture(new Recti(new Vec2i(0, 0), img.getSize()), img);
|
var texture = new GLTexture(new Recti(new Vec2i(0, 0), img.getSize()), img);
|
||||||
textures.add(texture);
|
textures.add(texture);
|
||||||
repack();
|
shouldUpdate = true;
|
||||||
updateImage();
|
|
||||||
uploadToGpu();
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,14 @@ class GLTextureAtlas {
|
||||||
System.out.printf("Resized atlas to %dx%d\n", img.getSize().getX(), img.getSize().getY());
|
System.out.printf("Resized atlas to %dx%d\n", img.getSize().getX(), img.getSize().getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
if(shouldUpdate) {
|
||||||
|
repack();
|
||||||
|
updateImage();
|
||||||
|
uploadToGpu();
|
||||||
|
shouldUpdate = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
void repack() {
|
void repack() {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
|
|
|
@ -92,6 +92,7 @@ public class GLWindow implements IWindow {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IRenderContext renderStart() {
|
public IRenderContext renderStart() {
|
||||||
|
textureAtlas.update();
|
||||||
glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
|
|
Loading…
Reference in New Issue