Started making lighting more efficient

This commit is contained in:
jsrobson10 2020-06-23 16:56:32 +10:00
parent ecfb03d62d
commit 0ee4243011
2 changed files with 18 additions and 18 deletions

View File

@ -147,7 +147,7 @@ public class DisplayWindow implements IMainloopTask
// Bind the lightmap
GL33.glActiveTexture(GL33.GL_TEXTURE1);
GL33.glBindTexture(GL33.GL_TEXTURE_2D, TileLighting.lightmap);
GL33.glBindTexture(GL33.GL_TEXTURE_2D, TileLighting.lightmap_src);
// Render everything
DisplayRender.render(w[0], h[0]);

View File

@ -22,17 +22,19 @@ import projectzombie.world.layer.Layer;
public class TileLighting
{
private static class Lighting {
float[] p;
float[] p_src;
float[] p_day;
int w, h;
int x, y;
private int getID(int x, int y) {
return (x + y * w) * 3 + 1;
return x + y * w;
}
}
private static boolean lighting_dirty = false;
public static int lightmap;
public static int lightmap_src;
public static int lightmap_day;
private static Lighting lighting;
@ -49,7 +51,7 @@ public class TileLighting
}
public TileLighting() {
lightmap = GL33.glGenTextures();
lightmap_src = GL33.glGenTextures();
}
public static void update()
@ -171,9 +173,9 @@ public class TileLighting
Lighting lighting = getLighting();
// Copy the pixels
float[] pixels = new float[lighting.p.length];
float[] pixels = new float[lighting.p_src.length];
for(int i=0;i<pixels.length;i++) {
pixels[i] = lighting.p[i];
pixels[i] = lighting.p_src[i];
}
Layer layer = Main.world.getLayer();
@ -227,8 +229,13 @@ public class TileLighting
}
// Update the texture
GL33.glBindTexture(GL33.GL_TEXTURE_2D, lightmap);
GL33.glTexImage2D(GL33.GL_TEXTURE_2D, 0, GL33.GL_RGB, lighting.w, lighting.h, 0, GL33.GL_RGB, GL33.GL_FLOAT, pixels);
GL33.glBindTexture(GL33.GL_TEXTURE_2D, lightmap_src);
GL33.glTexImage2D(
GL33.GL_TEXTURE_2D, 0, GL33.GL_LUMINANCE,
lighting.w, lighting.h, 0, GL33.GL_LUMINANCE,
GL33.GL_FLOAT, pixels);
GL33.glGenerateMipmap(GL33.GL_TEXTURE_2D);
// Set the texture location data
@ -239,7 +246,7 @@ public class TileLighting
public static void clearLighting()
{
Lighting lighting = new Lighting();
lighting.p = new float[3];
lighting.p_src = new float[2];
lighting.w = 1;
lighting.h = 1;
lighting.x = 0;
@ -257,15 +264,8 @@ public class TileLighting
int x = nl.get("x").getInteger();
int y = nl.get("y").getInteger();
float[] pixels = new float[width*height*3];
for(int i=0;i<width*height;i++) {
pixels[i*3+0] = light[i*2+0];
pixels[i*3+1] = light[i*2+1];
}
Lighting lighting = new Lighting();
lighting.p = pixels;
lighting.p_src = light;
lighting.w = width;
lighting.h = height;
lighting.x = x;