From 9cdcaa197fc2ad55a382ba5c96273a94538922dc Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Wed, 6 Feb 2019 02:42:09 +0300 Subject: [PATCH] sdl2allegro loads custom palette from PLAYPAL.LMP --- src/lib/allegro4/allegro.pas | 6 ++++ src/nogl/noGLALSW.inc | 20 ++++------- src/wrappers/sdl2/sdl2allegro.inc | 58 +++++++++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 16 deletions(-) diff --git a/src/lib/allegro4/allegro.pas b/src/lib/allegro4/allegro.pas index 0560035..d248352 100644 --- a/src/lib/allegro4/allegro.pas +++ b/src/lib/allegro4/allegro.pas @@ -269,6 +269,7 @@ interface windowed: cint; end; + PRGB = ^RGB; RGB = record r, g, b, filler: cuchar; end; @@ -300,6 +301,7 @@ interface key_shifts: cint; LibraryLibAllegroVar; color_map: PCOLOR_MAP_T; LibraryLibAllegroVar; gfx_driver: PGFX_DRIVER_T; LibraryLibAllegroVar; + palette_color: array [0..255] of cint; LibraryLibAllegroVar; function get_desktop_resolution (width, height: Pcint): cint; LibraryLibAllegroImp; function get_gfx_mode_list (card: cint): PGFX_MODE_LIST; LibraryLibAllegroImp; @@ -386,6 +388,10 @@ interface procedure vsync; LibraryLibAllegroImp; function desktop_color_depth: cint; LibraryLibAllegroImp; + procedure select_palette (const p: PALETTE); LibraryLibAllegroImp; + procedure unselect_palette; LibraryLibAllegroImp; + procedure set_color (index: cint; const p: PRGB); LibraryLibAllegroImp; + (* MACRO *) function install_allegro (system_id: cint; errno_ptr: Pcint; atexit_ptr: AtExitFunction): cint; inline; function allegro_init: cint; inline; diff --git a/src/nogl/noGLALSW.inc b/src/nogl/noGLALSW.inc index e06b9c3..d18ff99 100644 --- a/src/nogl/noGLALSW.inc +++ b/src/nogl/noGLALSW.inc @@ -48,12 +48,7 @@ implementation matrixMode: GLenum; blendMode: Integer; - globalTransTable: COLOR_MAP_T; - redTransTable: COLOR_MAP_T; - greenTransTable: COLOR_MAP_T; - blueTransTable: COLOR_MAP_T; - darkTransTable: COLOR_MAP_T; - lightTransTable: COLOR_MAP_T; + vram_usage, xram_usage: Integer; function AddTexture: Integer; var i: Integer; @@ -658,11 +653,13 @@ implementation tex[ctex].bmp := create_bitmap(width, height); assert(tex[ctex].bmp <> nil); + vram_usage += width * height; if pixels = nil then exit; p := pixels; if format = GL_RGBA then begin + xram_usage += width * height * 4; if sdl2allegro_bpp <= 8 then trans := 0 else @@ -681,6 +678,7 @@ implementation end else begin + xram_usage += width * height * 3; for j := 0 to height - 1 do for i := 0 to width - 1 do begin @@ -710,6 +708,7 @@ implementation p := pixels; if format = GL_RGBA then begin + xram_usage += width * height * 4; if sdl2allegro_bpp <= 8 then trans := 0 else @@ -728,6 +727,7 @@ implementation end else begin + xram_usage += width * height * 4; for j := 0 to height - 1 do for i := 0 to width - 1 do begin @@ -747,17 +747,11 @@ implementation procedure nogl_Init; begin cmds.mode := GL_INVALID_ENUM; - create_trans_table(@globalTransTable, default_palette, 255, 255, 255, nil); - create_trans_table(@redTransTable, default_palette, 0, 255, 255, nil); - create_trans_table(@greenTransTable, default_palette, 255, 0, 255, nil); - create_trans_table(@blueTransTable, default_palette, 255, 255, 0, nil); - create_trans_table(@darkTransTable, default_palette, 191, 191, 191, nil); - create_trans_table(@lightTransTable, default_palette, 64, 64, 64, nil); - color_map := @globalTransTable; end; procedure nogl_Quit; begin + e_LogWritefln('vram=%s xram=%s', [vram_usage, xram_usage]); end; initialization diff --git a/src/wrappers/sdl2/sdl2allegro.inc b/src/wrappers/sdl2/sdl2allegro.inc index 8cbe419..a5de6da 100644 --- a/src/wrappers/sdl2/sdl2allegro.inc +++ b/src/wrappers/sdl2/sdl2allegro.inc @@ -296,6 +296,13 @@ interface var sdl2allegro_screen: PBITMAP; sdl2allegro_bpp: Integer; + globalTransTable: COLOR_MAP_T; + redTransTable: COLOR_MAP_T; + greenTransTable: COLOR_MAP_T; + blueTransTable: COLOR_MAP_T; + darkTransTable: COLOR_MAP_T; + lightTransTable: COLOR_MAP_T; + /// FUNCTIONS /// @@ -367,7 +374,7 @@ implementation {$IFDEF GO32V2} go32, {$ENDIF} - e_Log, g_options, SysUtils, Math, ctypes; + e_Log, g_options, SysUtils, Math, Classes, ctypes; const maxKeyBuffer = 64; @@ -381,6 +388,7 @@ implementation useVsync: Boolean; ticks: UInt32; quit: Boolean; + custompal: PALETTE; s2lc: array [0..KEY_MAX] of char = ( #00, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', @@ -533,6 +541,48 @@ implementation SDL_SCANCODE_UNKNOWN (* KEY_MAX *) ); + procedure LoadCustomPalette (const name: String); + var f: TFileStream; i: Integer; + begin + try + f := TFileStream.Create(name, fmOpenRead); + e_LogWriteLn('Load custom palette ' + name); + for i := 0 to 255 do + begin + custompal[i].r := f.ReadByte(); + custompal[i].g := f.ReadByte(); + custompal[i].b := f.ReadByte(); + custompal[i].filler := $FF; + end; + f.Destroy + except + e_LogWriteLn('Fallback to default palette'); + custompal := default_palette; +(* + for i := 0 to 255 do + begin + custompal[i].r := i div 4; + custompal[i].g := i div 4; + custompal[i].b := i div 4; + custompal[i].filler := $FF; + end; +*) + end + end; + + procedure UpdatePalette; + begin + set_palette(custompal); + select_palette(custompal); + create_trans_table(@globalTransTable, custompal, 255, 255, 255, nil); + create_trans_table(@redTransTable, custompal, 0, 255, 255, nil); + create_trans_table(@greenTransTable, custompal, 255, 0, 255, nil); + create_trans_table(@blueTransTable, custompal, 255, 255, 0, nil); + create_trans_table(@darkTransTable, custompal, 191, 191, 191, nil); + create_trans_table(@lightTransTable, custompal, 64, 64, 64, nil); + color_map := @globalTransTable; + end; + function IsEmptyKeyboard: Boolean; begin result := keybeg = keyend @@ -995,6 +1045,7 @@ implementation window.w := w; window.h := h; window.mode := mode; + UpdatePalette; result := window end end; @@ -1023,7 +1074,7 @@ implementation if sdl2allegro_screen = nil then sdl2allegro_screen := create_bitmap(window.w, window.h); ASSERT(sdl2allegro_screen <> nil); - set_palette(desktop_palette); + UpdatePalette; window.mode := mode; result := 0 end @@ -1041,7 +1092,7 @@ implementation if sdl2allegro_screen = nil then sdl2allegro_screen := create_bitmap(w, h); ASSERT(sdl2allegro_screen <> nil); - set_palette(desktop_palette); + UpdatePalette; window.w := w; window.h := h end @@ -1292,6 +1343,7 @@ implementation deskw := 640; deskh := 480 end; + LoadCustomPalette('PLAYPAL.LMP'); result := 0 end end; -- 2.29.2