DEADSOFTWARE

sdl2allegro loads custom palette from PLAYPAL.LMP
[d2df-sdl.git] / src / nogl / noGLALSW.inc
1 implementation
3 uses Allegro, Math, SDL2, e_Log;
5 const
6 GL_INVALID_ENUM = $0500;
8 const
9 ValPerVertex = 2;
10 ValPerColor = 1; (* colors stored in one integer *)
11 ValPerCoord = 2;
12 StackSize = 16;
14 BLEND_BLEND = 0;
15 BLEND_DARKER = 1;
16 BLEND_FILTER = 2;
17 BLEND_INVERT = 3;
18 BLEND_DEFAULT = 5;
20 type
21 TArrayFloat = array of GLfloat;
22 TArrayInteger = array of Integer;
24 TCmds = record
25 mode: GLenum;
26 v: TArrayInteger;
27 c: TArrayInteger;
28 t: TArrayFloat;
29 end;
31 TArrayTexture = array of record
32 used: Boolean;
33 bmp: PBITMAP;
34 end;
36 var
37 cmds: TCmds;
38 tex: TArrayTexture;
39 ctex: Integer;
40 ccol: Integer;
41 clearColor: cint;
42 stack: array [0..StackSize - 1] of record
43 x, y, a: Integer;
44 end;
45 stack_ptr: Integer;
46 vpx, vpy: Integer;
47 pointSize: Integer;
48 matrixMode: GLenum;
49 blendMode: Integer;
51 vram_usage, xram_usage: Integer;
53 function AddTexture: Integer;
54 var i: Integer;
55 begin
56 for i := 1 to High(tex) do
57 if not tex[i].used then
58 begin
59 tex[i].used := true;
60 tex[i].bmp := nil;
61 result := i;
62 exit
63 end;
64 i := Length(tex);
65 SetLength(tex, i + 1);
66 tex[i].used := true;
67 tex[i].bmp := nil;
68 result := i
69 end;
71 procedure RemoveTexture(i: Integer);
72 begin
73 assert(i >= 0);
74 assert(i <= High(tex));
75 assert((i = 0) or tex[i].used); (* free unallocated texture *)
76 tex[i].used := false;
77 if tex[i].bmp <> nil then
78 destroy_bitmap(tex[i].bmp);
79 tex[i].bmp := nil
80 end;
82 procedure Addi (var x: TArrayInteger; f: Integer);
83 var i: Integer;
84 begin
85 i := Length(x);
86 SetLength(x, i + 1);
87 x[i] := f;
88 end;
90 procedure Addf (var x: TArrayFloat; f: GLfloat);
91 var i: Integer;
92 begin
93 i := Length(x);
94 SetLength(x, i + 1);
95 x[i] := f;
96 end;
98 (** Open GL **)
100 procedure glEnable(cap: GLenum);
101 begin
102 end;
104 procedure glDisable(cap: GLenum);
105 begin
106 end;
108 function glIsEnabled(cap: GLenum): GLboolean;
109 begin
110 result := 0
111 end;
113 function glGetString(name: GLenum): PChar;
114 begin
115 if name = GL_EXTENSIONS then (* separated by space *)
116 result := 'GL_ARB_texture_non_power_of_two'
117 else
118 result := nil
119 end;
121 procedure glClearColor(red, green, blue, alpha: GLclampf);
122 begin
123 clearColor := makeacol(floor(red * 255), floor(green * 255), floor(blue * 255), floor(alpha * 255));
124 end;
126 procedure glClear(mask: GLbitfield);
127 begin
128 if (mask and GL_COLOR_BUFFER_BIT) <> 0 then
129 clear_to_color(sdl2allegro_screen, clearColor)
130 end;
132 procedure glAlphaFunc(func: GLenum; ref: GLclampf);
133 begin
134 end;
136 procedure glBlendFunc(sfactor, dfactor: GLenum);
137 begin
138 if (sfactor = GL_SRC_ALPHA) and (dfactor = GL_ONE) then blendMode := BLEND_BLEND
139 else if (sfactor = GL_ZERO) and (dfactor = GL_SRC_ALPHA) then blendMode := BLEND_DARKER
140 else if (sfactor = GL_DST_COLOR) and (dfactor = GL_SRC_COLOR) then blendMode := BLEND_FILTER
141 else if (sfactor = GL_ONE_MINUS_DST_COLOR) and (dfactor = GL_ZERO) then blendMode := BLEND_INVERT
142 else if (sfactor = GL_SRC_ALPHA) and (dfactor = GL_ONE_MINUS_SRC_ALPHA) then blendMode := BLEND_DEFAULT
143 else ASSERT(FALSE)
144 end;
146 procedure SetupBlendColor (col: cint);
147 var r, g, b, a: cint;
148 begin
149 //set_trans_blender(r, g, b, a);
150 //set_add_blender(r, g, b, a);
151 //set_burn_blender(r, g, b, a);
152 //set_color_blender(r, g, b, a);
153 //set_difference_blender(r, g, b, a);
154 //set_dissolve_blender(r, g, b, a);
155 //set_dodge_blender(r, g, b, a);
156 //set_hue_blender(r, g, b, a);
157 //set_invert_blender(r, g, b, a);
158 //set_luminance_blender(r, g, b, a);
159 //set_multiply_blender(r, g, b, a);
160 //set_saturation_blender(r, g, b, a);
161 //set_screen_blender(r, g, b, a);
162 r := getr(col);
163 g := getg(col);
164 b := getb(col);
165 a := geta(col);
166 color_map := @globalTransTable;
167 case blendMode of
168 BLEND_BLEND:
169 begin
170 color_map := @lightTransTable;
171 set_add_blender(r, g, b, a);
172 drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
173 end;
174 BLEND_DARKER:
175 begin
176 color_map := @darkTransTable;
177 set_multiply_blender(0, 0, 0, 255 - a);
178 drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
179 end;
180 BLEND_FILTER:
181 begin
182 set_luminance_blender(0, 0, 0, 255);
183 if r <> 0 then
184 color_map := @redTransTable
185 else if g <> 0 then
186 color_map := @greenTransTable
187 else if b <> 0 then
188 color_map := @blueTransTable;
189 drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
190 end;
191 BLEND_INVERT:
192 begin
193 drawing_mode(DRAW_MODE_XOR, nil, 0, 0)
194 end;
195 BLEND_DEFAULT:
196 begin
197 (* FIX texture colorize *)
198 if sdl2allegro_bpp <= 8 then
199 begin
200 drawing_mode(DRAW_MODE_SOLID, nil, 0, 0)
201 end
202 else
203 begin
204 set_color_blender(0, 0, 0, 0);
205 drawing_mode(DRAW_MODE_TRANS, nil, 0, 0)
206 end
207 end
208 else
209 ASSERT(FALSE)
210 end
211 end;
213 procedure glPointSize(size: GLfloat);
214 begin
215 ASSERT(size >= 0);
216 if size <= 1.0 then pointSize := ceil(size)
217 else pointSize := floor(size)
218 end;
220 procedure glLineWidth(width: GLfloat);
221 begin
222 (* width > 1 used in rare cases, not critical *)
223 end;
225 procedure glGetIntegerv(pname: GLenum; params: PGLint);
226 begin
227 params^ := 0
228 end;
230 procedure glFlush;
231 begin
232 end;
234 procedure glFinish;
235 begin
236 end;
238 procedure glBegin(mode: GLenum);
239 begin
240 assert(cmds.mode = GL_INVALID_ENUM);
241 assert((mode = GL_POINTS) or (mode = GL_LINES) or (mode = GL_QUADS));
242 cmds.mode := mode;
243 SetLength(cmds.v, 0);
244 SetLength(cmds.c, 0);
245 SetLength(cmds.t, 0);
246 end;
248 procedure glEnd;
249 var
250 i, j, k, w, h, x0, y0, x1, y1, offx, offy, tmp, s0, t0, s1, t1, angle: Integer;
251 oldx0, oldy0, oldx1, oldy1: cint;
252 flipv, fliph: Boolean;
253 draw_sprite_proc: procedure (bmp, sprite: Allegro.PBITMAP; x, y: cint); cdecl;
254 rotate_sprite_proc: procedure (bmp, sprite: Allegro.PBITMAP; x, y: cint; a: cint32); cdecl;
255 begin
256 assert(cmds.mode <> GL_INVALID_ENUM);
257 assert(Length(cmds.v) mod ValPerVertex = 0);
258 assert(Length(cmds.c) mod ValPerColor = 0);
259 assert(Length(cmds.t) mod ValPerCoord = 0);
261 offx := vpx + stack[stack_ptr].x;
262 offy := vpy + stack[stack_ptr].y;
263 angle := stack[stack_ptr].a;
265 drawing_mode(DRAW_MODE_SOLID, nil, 0, 0);
267 case cmds.mode of
268 GL_POINTS:
269 begin
270 (* implement case for texture coords? *)
271 if pointSize = 1 then
272 begin
273 if Length(cmds.c) <> 0 then
274 begin
275 assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
276 for i := 0 to Length(cmds.v) div 2 - 1 do
277 putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], cmds.c[i])
278 end
279 else
280 begin
281 for i := 0 to Length(cmds.v) div 2 - 1 do
282 putpixel(sdl2allegro_screen, offx + cmds.v[i * 2], offy + cmds.v[i * 2 + 1], ccol)
283 end
284 end
285 else if pointSize > 1 then
286 begin
287 x0 := offx - pointSize div 2;
288 y0 := offy - pointSize div 2;
289 x1 := offx - (pointSize - 1) div 2;
290 y1 := offy - (pointSize - 1) div 2;
291 if Length(cmds.c) <> 0 then
292 begin
293 assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
294 for i := 0 to Length(cmds.v) div 2 - 1 do
295 begin
296 w := cmds.v[i * 2 + 0];
297 h := cmds.v[i * 2 + 1];
298 rectfill(sdl2allegro_screen, x0 + w, y0 + h, x1 + w, y1 + h, cmds.c[i])
299 end
300 end
301 else
302 begin
303 for i := 0 to Length(cmds.v) div 2 - 1 do
304 begin
305 w := cmds.v[i * 2 + 0];
306 h := cmds.v[i * 2 + 1];
307 rectfill(sdl2allegro_screen, x0 + w, y0 + h, x1 + w, y1 + h, ccol)
308 end
309 end
310 end
311 end;
312 GL_LINES:
313 begin
314 assert(Length(cmds.v) mod 4 = 0); (* broken line *)
315 (* implement case for texture coords? *)
316 if Length(cmds.c) <> 0 then
317 begin
318 assert(Length(cmds.c) * 2 = Length(cmds.v));
319 for i := 0 to Length(cmds.v) div 4 - 1 do
320 fastline(sdl2allegro_screen, offx + cmds.v[i * 4], offy + cmds.v[i * 4 + 1], offx + cmds.v[i * 4 + 2], offy + cmds.v[i * 4 + 3], cmds.c[i * 2])
321 end
322 else
323 begin
324 for i := 0 to Length(cmds.v) div 4 - 1 do
325 fastline(sdl2allegro_screen, offx + cmds.v[i * 4], offy + cmds.v[i * 4 + 1], offx + cmds.v[i * 4 + 2], offy + cmds.v[i * 4 + 3], ccol)
326 end
327 end;
328 GL_QUADS:
329 begin
330 ASSERT(Length(cmds.v) mod 8 = 0); (* broken quad *)
331 if Length(cmds.t) <> 0 then
332 begin
333 ASSERT(Length(cmds.t) = Length(cmds.v)); (* not enough texture coords *)
334 ASSERT(ctex >= 0);
335 ASSERT(ctex <= High(tex));
336 ASSERT(tex[ctex].bmp <> nil);
337 for i := 0 to Length(cmds.v) div 8 - 1 do
338 begin
339 flipv := False; fliph := False;
340 x0 := cmds.v[i * 8 + 0]; y0 := cmds.v[i * 8 + 1];
341 x1 := cmds.v[i * 8 + 4]; y1 := cmds.v[i * 8 + 5];
342 if x1 < x0 then
343 begin
344 tmp := x0;
345 x0 := x1;
346 x1 := tmp;
347 fliph := not fliph
348 end;
349 if y1 < y0 then
350 begin
351 tmp := y0;
352 y0 := y1;
353 y1 := tmp;
354 flipv := not flipv
355 end;
357 w := tex[ctex].bmp.w;
358 h := tex[ctex].bmp.h;
359 s0 := Trunc(cmds.t[i * 8 + 0] * w);
360 t0 := Trunc(cmds.t[i * 8 + 1] * h);
361 s1 := Trunc(cmds.t[i * 8 + 4] * w);
362 t1 := Trunc(cmds.t[i * 8 + 5] * h);
364 if s1 < s0 then
365 begin
366 tmp := s0;
367 s0 := s1;
368 s1 := tmp;
369 fliph := not fliph;
370 end;
371 if t1 < t0 then
372 begin
373 tmp := t0;
374 t0 := t1;
375 t1 := tmp;
376 flipv := not flipv;
377 end;
379 if fliph then
380 begin
381 tmp := s0;
382 s0 := w - s1;
383 s1 := w - tmp;
384 end;
385 if flipv then
386 begin
387 tmp := t0;
388 t0 := h - t1;
389 t1 := h - tmp;
390 end;
392 s0 := s0 mod w;
393 t0 := t0 mod h;
394 s1 := s1 mod w;
395 t1 := t1 mod h;
397 if flipv and fliph then
398 draw_sprite_proc := Allegro.draw_sprite_vh_flip
399 else if flipv then
400 draw_sprite_proc := Allegro.draw_sprite_v_flip
401 else if fliph then
402 draw_sprite_proc := Allegro.draw_sprite_h_flip
403 else
404 draw_sprite_proc := Allegro.draw_sprite;
406 if flipv and fliph then
407 rotate_sprite_proc := Allegro.rotate_sprite_v_flip (* ??? *)
408 else if flipv then
409 rotate_sprite_proc := Allegro.rotate_sprite_v_flip
410 else if fliph then
411 rotate_sprite_proc := Allegro.rotate_sprite (* ??? *)
412 else
413 rotate_sprite_proc := Allegro.rotate_sprite;
415 oldx0 := 0; oldy0 := 0; oldx1 := 0; oldy1 := 0;
416 get_clip_rect(sdl2allegro_screen, oldx0, oldy0, oldx1, oldy1);
417 set_clip_rect(sdl2allegro_screen, max(oldx0, offx + x0), max(oldy0, offy + y0), min(oldx1, offx + x1), min(oldy1, offy + y1));
419 SetupBlendColor(ccol);
420 if angle = 0 then
421 for j := 0 to (y1 - y0 + h - 1) div h - 1 do
422 for k := 0 to (x1 - x0 + w - 1) div w - 1 do
423 draw_sprite_proc(sdl2allegro_screen, tex[ctex].bmp, offx + x0 + k * w - s0, offy + y0 + j * h - t0)
424 else
425 for j := 0 to (y1 - y0 + h - 1) div h - 1 do
426 for k := 0 to (x1 - x0 + w - 1) div w - 1 do
427 rotate_sprite_proc(sdl2allegro_screen, tex[ctex].bmp, offx + x0 + k * w - s0, offy + y0 + j * h - t0, angle);
429 set_clip_rect(sdl2allegro_screen, oldx0, oldy0, oldx1, oldy1);
431 //rect(sdl2allegro_screen, offx + x0, offy + y0, offx + x1, offy + y1, makecol(255, 0, 0));
432 //rect(sdl2allegro_screen, offx + oldx0, offy + oldy0, offx + oldx1, offy + oldx1, makecol(0, 255, 0));
433 end
434 end
435 else if Length(cmds.c) <> 0 then
436 begin
437 assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
438 for i := 0 to Length(cmds.v) div 8 - 1 do
439 begin
440 SetupBlendColor(cmds.c[i * 4]);
441 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])
442 end
443 end
444 else
445 begin
446 SetupBlendColor(ccol);
447 for i := 0 to Length(cmds.v) div 8 - 1 do
448 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)
449 end
450 end;
451 else
452 assert(false)
453 end;
455 SetLength(cmds.v, 0);
456 SetLength(cmds.c, 0);
457 SetLength(cmds.t, 0);
458 cmds.mode := GL_INVALID_ENUM;
459 end;
461 procedure glVertex2f(x, y: GLfloat);
462 begin
463 Addi(cmds.v, ceil(x));
464 Addi(cmds.v, ceil(y))
465 end;
467 procedure glVertex2i(x, y: GLint);
468 begin
469 Addi(cmds.v, x);
470 Addi(cmds.v, y)
471 end;
473 procedure glColor4f(red, green, blue, alpha: GLfloat);
474 begin
475 ccol := makeacol(floor(red * 255), floor(green * 255), floor(blue * 255), floor(alpha * 255));
476 Addi(cmds.c, ccol)
477 end;
479 procedure glColor4ub(red, green, blue, alpha: GLubyte);
480 begin
481 ccol := makeacol(red, green, blue, alpha);
482 Addi(cmds.c, ccol)
483 end;
485 procedure glColor3ub(red, green, blue: GLubyte);
486 begin
487 ccol := makecol(red, green, blue);
488 Addi(cmds.c, ccol)
489 end;
491 procedure glTexCoord2f(s, t: GLfloat);
492 begin
493 Addf(cmds.t, s);
494 Addf(cmds.t, t);
495 end;
497 procedure glTexCoord2i(s, t: GLint);
498 begin
499 Addf(cmds.t, s);
500 Addf(cmds.t, t);
501 end;
503 procedure glReadPixels(x, y: GLint; width, height: GLsizei; format, atype: GLenum; pixels: Pointer);
504 begin
505 end;
507 procedure glLoadIdentity;
508 begin
509 if matrixMode <> GL_MODELVIEW then Exit;
510 with stack[stack_ptr] do
511 begin
512 x := 0;
513 y := 0;
514 (* TODO Rotation and scale *)
515 end
516 end;
518 procedure glMatrixMode(mode: GLenum);
519 begin
520 (* GL_PROJECTION -> verify or ignore *)
521 (* GL_MODELVIEW -> apply *)
522 ASSERT((mode = GL_PROJECTION) or (mode = GL_MODELVIEW));
523 matrixMode := mode;
524 end;
526 procedure glLoadMatrixd(const m: PGLdouble);
527 begin
528 if matrixMode <> GL_MODELVIEW then Exit;
530 (*
531 e_LogWritefln('glLoadMatrix:', []);
532 e_LogWritefln('| %s %s %s %s |', [m[0], m[1], m[2], m[3]]);
533 e_LogWritefln('| %s %s %s %s |', [m[4], m[5], m[6], m[7]]);
534 e_LogWritefln('| %s %s %s %s |', [m[8], m[9], m[10], m[11]]);
535 e_LogWritefln('| %s %s %s %s |', [m[12], m[13], m[14], m[15]]);
536 *)
537 with stack[stack_ptr] do
538 begin
539 x := Trunc(m[3]);
540 y := Trunc(m[7]);
541 ASSERT(m[11] = 0);
542 (* TODO Rotation and Scale *)
543 end
544 end;
546 procedure glPushMatrix;
547 begin
548 if matrixMode <> GL_MODELVIEW then Exit;
549 stack[stack_ptr + 1] := stack[stack_ptr];
550 INC(stack_ptr);
551 end;
553 procedure glPopMatrix;
554 begin
555 if matrixMode <> GL_MODELVIEW then Exit;
556 DEC(stack_ptr)
557 end;
559 procedure glTranslatef(x, y, z: GLfloat);
560 begin
561 if matrixMode <> GL_MODELVIEW then Exit;
562 ASSERT(z = 0); (* 3D not supported *)
563 stack[stack_ptr].x += Trunc(x);
564 stack[stack_ptr].y += Trunc(y);
565 end;
567 procedure glRotatef(angle, x, y, z: GLfloat);
568 begin
569 if matrixMode <> GL_MODELVIEW then Exit;
570 ASSERT(x = 0); (* 3D not supported *)
571 ASSERT(y = 0); (* 3D not supported *)
572 // angle 360deg == 256 with conversion to fixed point 16.16
573 stack[stack_ptr].a += floor(angle * z * 0.71111) * 65536
574 end;
576 procedure glScalef(x, y, z: GLfloat);
577 begin
578 if matrixMode <> GL_MODELVIEW then Exit;
579 (* 3D not supported, but z can be any *)
580 (* TODO Scale *)
581 end;
583 procedure glViewport(x, y: GLint; width, height: GLsizei);
584 begin
585 vpx := x; vpy := y;
586 set_clip_rect(sdl2allegro_screen, x, y, x + width, y + height);
587 end;
589 procedure glScissor(x, y: GLint; width, height: GLsizei);
590 begin
591 //set_clip_rect(sdl2allegro_screen, x, y, width, height)
592 end;
594 procedure glStencilMask(mask: GLuint);
595 begin
596 end;
598 procedure glStencilFunc(func: GLenum; ref: GLint; mask: GLuint);
599 begin
600 end;
602 procedure glStencilOp(fail, zfail, zpass: GLenum);
603 begin
604 end;
606 procedure glColorMask(red, green, blue, alpha: GLboolean);
607 begin
608 end;
610 procedure glBindTexture(target: GLenum; texture: GLuint);
611 begin
612 assert(target = GL_TEXTURE_2D);
613 ctex := texture;
614 end;
616 procedure glGenTextures(n: GLsizei; textures: PGLuint);
617 var i: Integer;
618 begin
619 for i := 0 to n - 1 do
620 textures[i] := AddTexture
621 end;
623 procedure glTexEnvi(target: GLenum; pname: GLenum; param: GLint);
624 begin
625 end;
627 procedure glTexParameterf(target: GLenum; pname: GLenum; param: GLfloat);
628 begin
629 end;
631 procedure glTexParameteri(target: GLenum; pname: GLenum; param: GLint);
632 begin
633 end;
635 procedure glTexImage2D(target: GLenum; level, internalformat: GLint; width, height: GLsizei; border: GLint; format, atype: GLenum; const pixels: Pointer);
636 var i, j, adr: Integer; p: PByte; color, trans: cint;
637 begin
638 assert(target = GL_TEXTURE_2D);
639 assert(level = 0);
640 assert((internalformat = GL_RGBA) or (internalformat = GL_RGB));
641 assert((format = GL_RGBA) or (format = GL_RGB));
642 assert(border = 0);
643 assert(atype = GL_UNSIGNED_BYTE);
645 assert(ctex >= 0);
646 assert(ctex <= High(tex));
647 assert(tex[ctex].used);
649 if tex[ctex].bmp <> nil then
650 destroy_bitmap(tex[ctex].bmp);
651 tex[ctex].bmp := create_system_bitmap(width, height);
652 if tex[ctex].bmp = nil then
653 tex[ctex].bmp := create_bitmap(width, height);
654 assert(tex[ctex].bmp <> nil);
656 vram_usage += width * height;
657 if pixels = nil then exit;
659 p := pixels;
660 if format = GL_RGBA then
661 begin
662 xram_usage += width * height * 4;
663 if sdl2allegro_bpp <= 8 then
664 trans := 0
665 else
666 trans := makeacol(255, 0, 255, 0);
668 for j := 0 to height - 1 do
669 for i := 0 to width - 1 do
670 begin
671 adr := j * width * 4 + i * 4;
672 if p[adr + 3] = 0 then
673 color := trans
674 else
675 color := makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]);
676 putpixel(tex[ctex].bmp, i, j, color)
677 end
678 end
679 else
680 begin
681 xram_usage += width * height * 3;
682 for j := 0 to height - 1 do
683 for i := 0 to width - 1 do
684 begin
685 adr := j * width * 3 + i * 3;
686 putpixel(tex[ctex].bmp, i, j, makecol(p[adr], p[adr + 1], p[adr + 2]))
687 end
688 end
689 end;
691 procedure glTexSubImage2D(target: GLenum; level, xoffset, yoffset: GLint; width, height: GLsizei; format, atype: GLenum; const pixels: Pointer);
692 var i, j, adr: Integer; p: PByte; color, trans: Cint;
693 begin
694 assert(target = GL_TEXTURE_2D);
695 assert(level = 0);
696 assert((format = GL_RGBA) or (format = GL_RGB));
697 assert(atype = GL_UNSIGNED_BYTE);
699 assert(ctex >= 0);
700 assert(ctex <= High(tex));
701 assert(tex[ctex].used);
703 assert(xoffset = 0);
704 assert(yoffset = 0);
706 if pixels = nil then exit;
708 p := pixels;
709 if format = GL_RGBA then
710 begin
711 xram_usage += width * height * 4;
712 if sdl2allegro_bpp <= 8 then
713 trans := 0
714 else
715 trans := makeacol(255, 0, 255, 0);
717 for j := 0 to height - 1 do
718 for i := 0 to width - 1 do
719 begin
720 adr := j * width * 4 + i * 4;
721 if p[adr + 3] = 0 then
722 color := trans
723 else
724 color := makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]);
725 putpixel(tex[ctex].bmp, i, j, color)
726 end
727 end
728 else
729 begin
730 xram_usage += width * height * 4;
731 for j := 0 to height - 1 do
732 for i := 0 to width - 1 do
733 begin
734 adr := j * width * 3 + i * 3;
735 putpixel(tex[ctex].bmp, i, j, makecol(p[adr], p[adr + 1], p[adr + 2]))
736 end
737 end
738 end;
740 procedure glDeleteTextures(n: GLsizei; const textures: PGLuint);
741 var i: Integer;
742 begin
743 for i := 0 to n - 1 do
744 RemoveTexture(textures[i])
745 end;
747 procedure nogl_Init;
748 begin
749 cmds.mode := GL_INVALID_ENUM;
750 end;
752 procedure nogl_Quit;
753 begin
754 e_LogWritefln('vram=%s xram=%s', [vram_usage, xram_usage]);
755 end;
757 initialization