diff --git a/src/nogl/noGLALSW.inc b/src/nogl/noGLALSW.inc
index b9f1ddd960d79fb4dfc274ec739ead974103bc94..d18ff9923e81023e8acfaf1eb9277b2a86e08349 100644 (file)
--- a/src/nogl/noGLALSW.inc
+++ b/src/nogl/noGLALSW.inc
ValPerCoord = 2;
StackSize = 16;
+ BLEND_BLEND = 0;
+ BLEND_DARKER = 1;
+ BLEND_FILTER = 2;
+ BLEND_INVERT = 3;
+ BLEND_DEFAULT = 5;
+
type
TArrayFloat = array of GLfloat;
TArrayInteger = array of Integer;
ccol: Integer;
clearColor: cint;
stack: array [0..StackSize - 1] of record
- x, y: Integer;
+ x, y, a: Integer;
end;
stack_ptr: Integer;
vpx, vpy: Integer;
pointSize: Integer;
matrixMode: GLenum;
+ blendMode: Integer;
+
+ vram_usage, xram_usage: Integer;
function AddTexture: Integer;
var i: Integer;
procedure glBlendFunc(sfactor, dfactor: GLenum);
begin
+ if (sfactor = GL_SRC_ALPHA) and (dfactor = GL_ONE) then blendMode := BLEND_BLEND
+ else if (sfactor = GL_ZERO) and (dfactor = GL_SRC_ALPHA) then blendMode := BLEND_DARKER
+ else if (sfactor = GL_DST_COLOR) and (dfactor = GL_SRC_COLOR) then blendMode := BLEND_FILTER
+ else if (sfactor = GL_ONE_MINUS_DST_COLOR) and (dfactor = GL_ZERO) then blendMode := BLEND_INVERT
+ else if (sfactor = GL_SRC_ALPHA) and (dfactor = GL_ONE_MINUS_SRC_ALPHA) then blendMode := BLEND_DEFAULT
+ else ASSERT(FALSE)
+ end;
+
+ procedure SetupBlendColor (col: cint);
+ var r, g, b, a: cint;
+ begin
+ //set_trans_blender(r, g, b, a);
+ //set_add_blender(r, g, b, a);
+ //set_burn_blender(r, g, b, a);
+ //set_color_blender(r, g, b, a);
+ //set_difference_blender(r, g, b, a);
+ //set_dissolve_blender(r, g, b, a);
+ //set_dodge_blender(r, g, b, a);
+ //set_hue_blender(r, g, b, a);
+ //set_invert_blender(r, g, b, a);
+ //set_luminance_blender(r, g, b, a);
+ //set_multiply_blender(r, g, b, a);
+ //set_saturation_blender(r, g, b, a);
+ //set_screen_blender(r, g, b, a);
+ r := getr(col);
+ g := getg(col);
+ b := getb(col);
+ a := geta(col);
+ color_map := @globalTransTable;
+ case blendMode of
+ BLEND_BLEND:
+ begin
+ color_map := @lightTransTable;
+ set_add_blender(r, g, b, a);
+ drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
+ end;
+ BLEND_DARKER:
+ begin
+ color_map := @darkTransTable;
+ set_multiply_blender(0, 0, 0, 255 - a);
+ drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
+ end;
+ BLEND_FILTER:
+ begin
+ set_luminance_blender(0, 0, 0, 255);
+ if r <> 0 then
+ color_map := @redTransTable
+ else if g <> 0 then
+ color_map := @greenTransTable
+ else if b <> 0 then
+ color_map := @blueTransTable;
+ drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
+ end;
+ BLEND_INVERT:
+ begin
+ drawing_mode(DRAW_MODE_XOR, nil, 0, 0)
+ end;
+ BLEND_DEFAULT:
+ begin
+ (* FIX texture colorize *)
+ if sdl2allegro_bpp <= 8 then
+ begin
+ drawing_mode(DRAW_MODE_SOLID, nil, 0, 0)
+ end
+ else
+ begin
+ set_color_blender(0, 0, 0, 0);
+ drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
+ end
+ end
+ else
+ ASSERT(FALSE)
+ end
end;
procedure glPointSize(size: GLfloat);
procedure glEnd;
var
- i, j, k, w, h, x0, y0, x1, y1, offx, offy, tmp, s0, t0, s1, t1: Integer;
+ i, j, k, w, h, x0, y0, x1, y1, offx, offy, tmp, s0, t0, s1, t1, angle: Integer;
oldx0, oldy0, oldx1, oldy1: cint;
flipv, fliph: Boolean;
draw_sprite_proc: procedure (bmp, sprite: Allegro.PBITMAP; x, y: cint); cdecl;
+ rotate_sprite_proc: procedure (bmp, sprite: Allegro.PBITMAP; x, y: cint; a: cint32); cdecl;
begin
assert(cmds.mode <> GL_INVALID_ENUM);
assert(Length(cmds.v) mod ValPerVertex = 0);
offx := vpx + stack[stack_ptr].x;
offy := vpy + stack[stack_ptr].y;
+ angle := stack[stack_ptr].a;
+
+ drawing_mode(DRAW_MODE_SOLID, nil, 0, 0);
case cmds.mode of
GL_POINTS:
else
draw_sprite_proc := Allegro.draw_sprite;
+ if flipv and fliph then
+ rotate_sprite_proc := Allegro.rotate_sprite_v_flip (* ??? *)
+ else if flipv then
+ rotate_sprite_proc := Allegro.rotate_sprite_v_flip
+ else if fliph then
+ rotate_sprite_proc := Allegro.rotate_sprite (* ??? *)
+ else
+ rotate_sprite_proc := Allegro.rotate_sprite;
+
oldx0 := 0; oldy0 := 0; oldx1 := 0; oldy1 := 0;
get_clip_rect(sdl2allegro_screen, oldx0, oldy0, oldx1, oldy1);
set_clip_rect(sdl2allegro_screen, max(oldx0, offx + x0), max(oldy0, offy + y0), min(oldx1, offx + x1), min(oldy1, offy + y1));
- for j := 0 to (y1 - y0 + h - 1) div h - 1 do
- for k := 0 to (x1 - x0 + w - 1) div w - 1 do
- draw_sprite_proc(sdl2allegro_screen, tex[ctex].bmp, offx + x0 + k * w - s0, offy + y0 + j * h - t0);
+ SetupBlendColor(ccol);
+ if angle = 0 then
+ for j := 0 to (y1 - y0 + h - 1) div h - 1 do
+ for k := 0 to (x1 - x0 + w - 1) div w - 1 do
+ draw_sprite_proc(sdl2allegro_screen, tex[ctex].bmp, offx + x0 + k * w - s0, offy + y0 + j * h - t0)
+ else
+ for j := 0 to (y1 - y0 + h - 1) div h - 1 do
+ for k := 0 to (x1 - x0 + w - 1) div w - 1 do
+ rotate_sprite_proc(sdl2allegro_screen, tex[ctex].bmp, offx + x0 + k * w - s0, offy + y0 + j * h - t0, angle);
set_clip_rect(sdl2allegro_screen, oldx0, oldy0, oldx1, oldy1);
begin
assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
for i := 0 to Length(cmds.v) div 8 - 1 do
+ begin
+ SetupBlendColor(cmds.c[i * 4]);
rectfill(sdl2allegro_screen, offx + cmds.v[i * 8], offy + cmds.v[i * 8 + 1], offx + cmds.v[i * 8 + 4], offy + cmds.v[i * 8 + 5], cmds.c[i * 4])
+ end
end
else
begin
+ SetupBlendColor(ccol);
for i := 0 to Length(cmds.v) div 8 - 1 do
rectfill(sdl2allegro_screen, offx + cmds.v[i * 8], offy + cmds.v[i * 8 + 1], offx + cmds.v[i * 8 + 4], offy + cmds.v[i * 8 + 5], ccol)
end
if matrixMode <> GL_MODELVIEW then Exit;
ASSERT(x = 0); (* 3D not supported *)
ASSERT(y = 0); (* 3D not supported *)
- (* TODO a := deg(angle * z) *)
+ // angle 360deg == 256 with conversion to fixed point 16.16
+ stack[stack_ptr].a += floor(angle * z * 0.71111) * 65536
end;
procedure glScalef(x, y, z: GLfloat);
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
- if DEFAULT_DEPTH <= 8 then
+ xram_usage += width * height * 4;
+ if sdl2allegro_bpp <= 8 then
trans := 0
else
trans := makeacol(255, 0, 255, 0);
end
else
begin
+ xram_usage += width * height * 3;
for j := 0 to height - 1 do
for i := 0 to width - 1 do
begin
p := pixels;
if format = GL_RGBA then
begin
- if DEFAULT_DEPTH <= 8 then
+ xram_usage += width * height * 4;
+ if sdl2allegro_bpp <= 8 then
trans := 0
else
trans := makeacol(255, 0, 255, 0);
end
else
begin
+ xram_usage += width * height * 4;
for j := 0 to height - 1 do
for i := 0 to width - 1 do
begin
procedure nogl_Init;
begin
- cmds.mode := GL_INVALID_ENUM
+ cmds.mode := GL_INVALID_ENUM;
end;
procedure nogl_Quit;
begin
+ e_LogWritefln('vram=%s xram=%s', [vram_usage, xram_usage]);
end;
initialization