Started making lighting more efficient
This commit is contained in:
parent
ecfb03d62d
commit
0ee4243011
|
|
@ -147,7 +147,7 @@ public class DisplayWindow implements IMainloopTask
|
||||||
|
|
||||||
// Bind the lightmap
|
// Bind the lightmap
|
||||||
GL33.glActiveTexture(GL33.GL_TEXTURE1);
|
GL33.glActiveTexture(GL33.GL_TEXTURE1);
|
||||||
GL33.glBindTexture(GL33.GL_TEXTURE_2D, TileLighting.lightmap);
|
GL33.glBindTexture(GL33.GL_TEXTURE_2D, TileLighting.lightmap_src);
|
||||||
|
|
||||||
// Render everything
|
// Render everything
|
||||||
DisplayRender.render(w[0], h[0]);
|
DisplayRender.render(w[0], h[0]);
|
||||||
|
|
|
||||||
|
|
@ -22,17 +22,19 @@ import projectzombie.world.layer.Layer;
|
||||||
public class TileLighting
|
public class TileLighting
|
||||||
{
|
{
|
||||||
private static class Lighting {
|
private static class Lighting {
|
||||||
float[] p;
|
float[] p_src;
|
||||||
|
float[] p_day;
|
||||||
int w, h;
|
int w, h;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
private int getID(int x, int y) {
|
private int getID(int x, int y) {
|
||||||
return (x + y * w) * 3 + 1;
|
return x + y * w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean lighting_dirty = false;
|
private static boolean lighting_dirty = false;
|
||||||
public static int lightmap;
|
public static int lightmap_src;
|
||||||
|
public static int lightmap_day;
|
||||||
|
|
||||||
private static Lighting lighting;
|
private static Lighting lighting;
|
||||||
|
|
||||||
|
|
@ -49,7 +51,7 @@ public class TileLighting
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileLighting() {
|
public TileLighting() {
|
||||||
lightmap = GL33.glGenTextures();
|
lightmap_src = GL33.glGenTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void update()
|
public static void update()
|
||||||
|
|
@ -171,9 +173,9 @@ public class TileLighting
|
||||||
Lighting lighting = getLighting();
|
Lighting lighting = getLighting();
|
||||||
|
|
||||||
// Copy the pixels
|
// 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++) {
|
for(int i=0;i<pixels.length;i++) {
|
||||||
pixels[i] = lighting.p[i];
|
pixels[i] = lighting.p_src[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer layer = Main.world.getLayer();
|
Layer layer = Main.world.getLayer();
|
||||||
|
|
@ -227,8 +229,13 @@ public class TileLighting
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the texture
|
// Update the texture
|
||||||
GL33.glBindTexture(GL33.GL_TEXTURE_2D, lightmap);
|
GL33.glBindTexture(GL33.GL_TEXTURE_2D, lightmap_src);
|
||||||
GL33.glTexImage2D(GL33.GL_TEXTURE_2D, 0, GL33.GL_RGB, lighting.w, lighting.h, 0, GL33.GL_RGB, GL33.GL_FLOAT, pixels);
|
|
||||||
|
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);
|
GL33.glGenerateMipmap(GL33.GL_TEXTURE_2D);
|
||||||
|
|
||||||
// Set the texture location data
|
// Set the texture location data
|
||||||
|
|
@ -239,7 +246,7 @@ public class TileLighting
|
||||||
public static void clearLighting()
|
public static void clearLighting()
|
||||||
{
|
{
|
||||||
Lighting lighting = new Lighting();
|
Lighting lighting = new Lighting();
|
||||||
lighting.p = new float[3];
|
lighting.p_src = new float[2];
|
||||||
lighting.w = 1;
|
lighting.w = 1;
|
||||||
lighting.h = 1;
|
lighting.h = 1;
|
||||||
lighting.x = 0;
|
lighting.x = 0;
|
||||||
|
|
@ -257,15 +264,8 @@ public class TileLighting
|
||||||
int x = nl.get("x").getInteger();
|
int x = nl.get("x").getInteger();
|
||||||
int y = nl.get("y").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 lighting = new Lighting();
|
||||||
lighting.p = pixels;
|
lighting.p_src = light;
|
||||||
lighting.w = width;
|
lighting.w = width;
|
||||||
lighting.h = height;
|
lighting.h = height;
|
||||||
lighting.x = x;
|
lighting.x = x;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue