0

TextureManager: palette load

This commit is contained in:
2019-05-28 23:00:03 +03:00
parent ff42101649
commit 7b7bed22c4
3 changed files with 43 additions and 31 deletions

View File

@@ -1,10 +1,48 @@
package dmx.lwjake2.render; package dmx.lwjake2.render;
import dmx.lwjake2.UnpackLoader;
import lombok.extern.slf4j.Slf4j;
import static lwjake2.render.lwjgl.Main.d_8to24table;
@Slf4j
public class TextureManager { public class TextureManager {
private static int[] colorTable = new int[256]; private static final String $PALETTE_PATH = "pics/colormap.pcx";
private static int[] colorTable;
public static void setColorPalette(int[] palette) { public static void LoadPalette() {
byte[] raw = UnpackLoader.loadFile($PALETTE_PATH);
if (raw == null) {
log.error("Error load palette");
return;
}
byte[] pal = new byte[768];
System.arraycopy(raw, raw.length - 768, pal, 0, 768);
int r, g, b;
int j = 0;
for (int i = 0; i < 256; i++) {
r = pal[j++] & 0xFF;
g = pal[j++] & 0xFF;
b = pal[j++] & 0xFF;
d_8to24table[i] = (255 << 24) | (b << 16) | (g << 8) | (r);
}
d_8to24table[255] &= 0x00FFFFFF; // 255 is transparent
setColorPalette(d_8to24table);
}
private static void setColorPalette(int[] palette) {
if (colorTable != null) {
return;
}
colorTable = new int[256];
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
colorTable[i] = palette[i] & 0x00FFFFFF; colorTable[i] = palette[i] & 0x00FFFFFF;
} }

View File

@@ -35,11 +35,6 @@ public class particle_t {
public static FloatBuffer vertexArray = Lib.newFloatBuffer(Defines.MAX_PARTICLES * 3); public static FloatBuffer vertexArray = Lib.newFloatBuffer(Defines.MAX_PARTICLES * 3);
public static IntBuffer colorArray = colorByteArray.asIntBuffer(); public static IntBuffer colorArray = colorByteArray.asIntBuffer();
@Deprecated
public static void setColorPalette(int[] palette) {
TextureManager.setColorPalette(palette);
}
public static ByteBuffer getColorAsByteBuffer() { public static ByteBuffer getColorAsByteBuffer() {
return colorByteArray; return colorByteArray;
} }

View File

@@ -19,6 +19,7 @@
package lwjake2.render.lwjgl; package lwjake2.render.lwjgl;
import dmx.lwjake2.render.PcxTexture; import dmx.lwjake2.render.PcxTexture;
import dmx.lwjake2.render.TextureManager;
import lwjake2.Defines; import lwjake2.Defines;
import lwjake2.ErrorCode; import lwjake2.ErrorCode;
import dmx.lwjake2.UnpackLoader; import dmx.lwjake2.UnpackLoader;
@@ -1523,31 +1524,9 @@ public abstract class Image extends Main {
Draw_GetPalette Draw_GetPalette
=============== ===============
*/ */
@Deprecated
protected void Draw_GetPalette() { protected void Draw_GetPalette() {
int r, g, b; TextureManager.LoadPalette();
byte[][] palette = new byte[1][]; //new byte[768];
// get the palette
LoadPCX("pics/colormap.pcx", palette, new Dimension());
if (palette[0] == null || palette[0].length != 768)
Com.Error(ErrorCode.ERR_FATAL, "Couldn't load pics/colormap.pcx");
byte[] pal = palette[0];
int j = 0;
for (int i = 0; i < 256; i++) {
r = pal[j++] & 0xFF;
g = pal[j++] & 0xFF;
b = pal[j++] & 0xFF;
d_8to24table[i] = (255 << 24) | (b << 16) | (g << 8) | (r);
}
d_8to24table[255] &= 0x00FFFFFF; // 255 is transparent
particle_t.setColorPalette(d_8to24table);
} }
/* /*