/
line_soft.c
647 lines (537 loc) · 19.6 KB
/
line_soft.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
/* ______ ___ ___
* /\ _ \ /\_ \ /\_ \
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
* \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
* /\____/
* \_/__/
*
* Software line implementation functions.
*
*
* By Pavel Sountsov.
*
* See readme.txt for copyright information.
*/
#define ALLEGRO_INTERNAL_UNSTABLE
#define _AL_NO_BLEND_INLINE_FUNC
#include "allegro5/allegro.h"
#include "allegro5/allegro_primitives.h"
#include "allegro5/internal/aintern_blend.h"
#include "allegro5/internal/aintern_bitmap.h"
#include "allegro5/internal/aintern_pixels.h"
#include "allegro5/internal/aintern_prim.h"
#include "allegro5/internal/aintern_prim_soft.h"
#include <math.h>
/*
Nomenclature
shader_{texture}_{grad,solid}_{any,rgb888,rgba8888,etc}_{draw_{shade,opaque},step,first}
*/
typedef void (*shader_draw)(uintptr_t, int, int);
typedef void (*shader_first)(uintptr_t, int, int, ALLEGRO_VERTEX*, ALLEGRO_VERTEX*);
typedef void (*shader_step)(uintptr_t, int);
typedef struct {
ALLEGRO_COLOR color;
} state_solid_any_2d;
static void shader_solid_any_draw_shade(uintptr_t state, int x, int y)
{
state_solid_any_2d* s = (state_solid_any_2d*)state;
al_put_blended_pixel(x, y, s->color);
}
static void shader_solid_any_draw_opaque(uintptr_t state, int x, int y)
{
state_solid_any_2d* s = (state_solid_any_2d*)state;
al_put_pixel(x, y, s->color);
}
static void shader_solid_any_first(uintptr_t state, int start_x, int start_y, ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2)
{
state_solid_any_2d* s = (state_solid_any_2d*)state;
s->color = v1->color;
(void)start_x;
(void)start_y;
(void)v2;
}
static void shader_solid_any_step(uintptr_t state, int minor_step)
{
(void)state;
(void)minor_step;
}
/*----------------------------------------------------*/
typedef struct {
state_solid_any_2d solid;
ALLEGRO_COLOR minor_color;
ALLEGRO_COLOR major_color;
} state_grad_any_2d;
static void get_interpolation_parameters(int start_x, int start_y, ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2, float* param, float* minor_delta_param, float* major_delta_param)
{
float dx = v2->x - v1->x;
float dy = v2->y - v1->y;
float lensq = dx * dx + dy * dy;
if (lensq == 0) {
lensq = 0.0001f;
*param = 0;
} else {
*param = ((float)start_x - v1->x) * dx + ((float)start_y - v1->y) * dy;
*param /= lensq;
}
dx = fabsf(dx);
dy = fabsf(dy);
if (dx > dy)
*minor_delta_param = dx / lensq;
else
*minor_delta_param = dy / lensq;
*major_delta_param = (dx + dy) / lensq;
}
static void shader_grad_any_first(uintptr_t state, int start_x, int start_y, ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2)
{
float param;
float minor_delta_param;
float major_delta_param;
state_grad_any_2d* st = (state_grad_any_2d*)state;
ALLEGRO_COLOR diff, v1c, v2c;
v1c = v1->color;
v2c = v2->color;
get_interpolation_parameters(start_x, start_y, v1, v2, ¶m, &minor_delta_param, &major_delta_param);
diff.a = v2c.a - v1c.a;
diff.r = v2c.r - v1c.r;
diff.g = v2c.g - v1c.g;
diff.b = v2c.b - v1c.b;
st->solid.color.a = v1c.a + diff.a * param;
st->solid.color.r = v1c.r + diff.r * param;
st->solid.color.g = v1c.g + diff.g * param;
st->solid.color.b = v1c.b + diff.b * param;
st->minor_color.a = diff.a * minor_delta_param;
st->minor_color.r = diff.r * minor_delta_param;
st->minor_color.g = diff.g * minor_delta_param;
st->minor_color.b = diff.b * minor_delta_param;
st->major_color.a = diff.a * major_delta_param;
st->major_color.r = diff.r * major_delta_param;
st->major_color.g = diff.g * major_delta_param;
st->major_color.b = diff.b * major_delta_param;
}
static void shader_grad_any_step(uintptr_t state, int minor_step)
{
state_grad_any_2d* s = (state_grad_any_2d*)state;
if (minor_step) {
s->solid.color.a += s->minor_color.a;
s->solid.color.r += s->minor_color.r;
s->solid.color.g += s->minor_color.g;
s->solid.color.b += s->minor_color.b;
} else {
s->solid.color.a += s->major_color.a;
s->solid.color.r += s->major_color.r;
s->solid.color.g += s->major_color.g;
s->solid.color.b += s->major_color.b;
}
}
/*===================== Texture Shaders =======================*/
#define SHADE_COLORS(A, B) \
A.r = B.r * A.r; \
A.g = B.g * A.g; \
A.b = B.b * A.b; \
A.a = B.a * A.a;
typedef struct {
ALLEGRO_COLOR color;
ALLEGRO_BITMAP* texture;
int w, h;
float u, v;
float minor_du;
float minor_dv;
float major_du;
float major_dv;
} state_texture_solid_any_2d;
static void get_texcoords(state_texture_solid_any_2d *s, int *u, int *v)
{
ALLEGRO_BITMAP_WRAP wrap_u, wrap_v;
_al_get_bitmap_wrap(s->texture, &wrap_u, &wrap_v);
*u = _al_fix_texcoord(s->u, s->w, wrap_u);
*v = _al_fix_texcoord(s->v, s->h, wrap_v);
}
#define GET_UV int u, v; get_texcoords((state_texture_solid_any_2d*)s, &u, &v);
static void shader_texture_solid_any_draw_shade(uintptr_t state, int x, int y)
{
state_texture_solid_any_2d* s = (state_texture_solid_any_2d*)state;
GET_UV
ALLEGRO_COLOR color = al_get_pixel(s->texture, u, v);
SHADE_COLORS(color, s->color)
al_put_blended_pixel(x, y, color);
}
static void shader_texture_solid_any_draw_shade_white(uintptr_t state, int x, int y)
{
state_texture_solid_any_2d* s = (state_texture_solid_any_2d*)state;
GET_UV
al_put_blended_pixel(x, y, al_get_pixel(s->texture, u, v));
}
static void shader_texture_solid_any_draw_opaque(uintptr_t state, int x, int y)
{
state_texture_solid_any_2d* s = (state_texture_solid_any_2d*)state;
GET_UV
ALLEGRO_COLOR color = al_get_pixel(s->texture, u, v);
SHADE_COLORS(color, s->color)
al_put_pixel(x, y, color);
}
static void shader_texture_solid_any_draw_opaque_white(uintptr_t state, int x, int y)
{
state_texture_solid_any_2d* s = (state_texture_solid_any_2d*)state;
GET_UV
al_put_pixel(x, y, al_get_pixel(s->texture, u, v));
}
static void shader_texture_solid_any_first(uintptr_t state, int start_x, int start_y, ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2)
{
float param;
float minor_delta_param;
float major_delta_param;
state_texture_solid_any_2d* st = (state_texture_solid_any_2d*)state;
float du, dv;
ALLEGRO_COLOR v1c;
v1c = v1->color;
get_interpolation_parameters(start_x, start_y, v1, v2, ¶m, &minor_delta_param, &major_delta_param);
st->w = al_get_bitmap_width(st->texture);
st->h = al_get_bitmap_height(st->texture);
du = v2->u - v1->u;
dv = v2->v - v1->v;
st->color.r = v1c.r;
st->color.g = v1c.g;
st->color.b = v1c.b;
st->color.a = v1c.a;
st->u = v1->u + du * param;
st->v = v1->v + dv * param;
st->minor_du = du * minor_delta_param;
st->minor_dv = dv * minor_delta_param;
st->major_du = du * major_delta_param;
st->major_dv = dv * major_delta_param;
}
static void shader_texture_solid_any_step(uintptr_t state, int minor_step)
{
state_texture_solid_any_2d* s = (state_texture_solid_any_2d*)state;
if (minor_step) {
s->u += s->minor_du;
s->v += s->minor_dv;
} else {
s->u += s->major_du;
s->v += s->major_dv;
}
}
/*----------------------------------------------------*/
typedef struct {
state_texture_solid_any_2d solid;
ALLEGRO_COLOR minor_color;
ALLEGRO_COLOR major_color;
} state_texture_grad_any_2d;
static void shader_texture_grad_any_first(uintptr_t state, int start_x, int start_y, ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2)
{
float param;
float minor_delta_param;
float major_delta_param;
state_texture_grad_any_2d* st = (state_texture_grad_any_2d*)state;
float du, dv;
ALLEGRO_COLOR diff, v1c, v2c;
v1c = v1->color;
v2c = v2->color;
get_interpolation_parameters(start_x, start_y, v1, v2, ¶m, &minor_delta_param, &major_delta_param);
st->solid.w = al_get_bitmap_width(st->solid.texture);
st->solid.h = al_get_bitmap_height(st->solid.texture);
du = v2->u - v1->u;
dv = v2->v - v1->v;
st->solid.color.r = v1c.r;
st->solid.color.g = v1c.g;
st->solid.color.b = v1c.b;
st->solid.color.a = v1c.a;
st->solid.u = v1->u + du * param;
st->solid.v = v1->v + dv * param;
st->solid.minor_du = du * minor_delta_param;
st->solid.minor_dv = dv * minor_delta_param;
st->solid.major_du = du * major_delta_param;
st->solid.major_dv = dv * major_delta_param;
diff.a = v2c.a - v1c.a;
diff.r = v2c.r - v1c.r;
diff.g = v2c.g - v1c.g;
diff.b = v2c.b - v1c.b;
st->solid.color.a = v1c.a + diff.a * param;
st->solid.color.r = v1c.r + diff.r * param;
st->solid.color.g = v1c.g + diff.g * param;
st->solid.color.b = v1c.b + diff.b * param;
st->minor_color.a = diff.a * minor_delta_param;
st->minor_color.r = diff.r * minor_delta_param;
st->minor_color.g = diff.g * minor_delta_param;
st->minor_color.b = diff.b * minor_delta_param;
st->major_color.a = diff.a * major_delta_param;
st->major_color.r = diff.r * major_delta_param;
st->major_color.g = diff.g * major_delta_param;
st->major_color.b = diff.b * major_delta_param;
}
static void shader_texture_grad_any_step(uintptr_t state, int minor_step)
{
state_texture_grad_any_2d* s = (state_texture_grad_any_2d*)state;
shader_texture_solid_any_step(state, minor_step);
if (minor_step) {
s->solid.color.a += s->minor_color.a;
s->solid.color.r += s->minor_color.r;
s->solid.color.g += s->minor_color.g;
s->solid.color.b += s->minor_color.b;
} else {
s->solid.color.a += s->major_color.a;
s->solid.color.r += s->major_color.r;
s->solid.color.g += s->major_color.g;
s->solid.color.b += s->major_color.b;
}
}
static void line_stepper(uintptr_t state, shader_first first, shader_step step, shader_draw draw, ALLEGRO_VERTEX* vtx1, ALLEGRO_VERTEX* vtx2)
{
float x1, y1, x2, y2;
float dx, dy;
int end_x, end_y;
if (vtx2->y < vtx1->y) {
ALLEGRO_VERTEX* t;
t = vtx1;
vtx1 = vtx2;
vtx2 = t;
}
vtx1->x -= 0.5001f;
vtx1->y -= 0.5001f;
vtx2->x -= 0.5001f;
vtx2->y -= 0.5001f;
x1 = vtx1->x;
y1 = vtx1->y;
x2 = vtx2->x;
y2 = vtx2->y;
dx = x2 - x1;
dy = y2 - y1;
end_x = floorf(x2 + 0.5f);
end_y = floorf(y2 + 0.5f);
#define FIRST \
first(state, x, y, vtx1, vtx2); \
if((x2 - x1) * ((float)x - x1) + (y2 - y1) * ((float)y - y1) >= 0) \
draw(state, x, y); \
(void)minor;
#define STEP \
step(state, minor); \
draw(state, x, y);
#define LAST \
step(state, minor); \
if((x1 - x2) * ((float)x - x2) + (y1 - y2) * ((float)y - y2) > 0) \
draw(state, x, y);
#define WORKER(var1, var2, comp, dvar1, dvar2, derr1, derr2, func) \
{ \
int minor = 1; \
if(err comp) \
{ \
var1 += dvar1; \
err += derr1; \
minor = 0; \
} \
\
func \
\
var2 += dvar2; \
err += derr2; \
}
if (dx > 0) {
if (dx > dy) {
int x = floorf(x1 + 0.5f);
int y = floorf(y1);
float err = (y1 - (float)y) * dx - (x1 - (float)x) * dy;
if (x < end_x) {
WORKER(y, x, > 0.5f * dx, 1, 1, -dx, dy, FIRST)
}
while (x < end_x) {
WORKER(y, x, > 0.5f * dx, 1, 1, -dx, dy, STEP)
}
if (x <= end_x) {
WORKER(y, x, > 0.5f * dx, 1, 1, -dx, dy, LAST)
}
} else {
int x = floorf(x1);
int y = floorf(y1 + 0.5f);
float err = (x1 - (float)x) * dy - (y1 - (float)y) * dx;
if (y < end_y) {
WORKER(x, y, > 0.5f * dy, 1, 1, -dy, dx, FIRST)
}
while (y < end_y) {
WORKER(x, y, > 0.5f * dy, 1, 1, -dy, dx, STEP)
}
if (y <= end_y) {
WORKER(x, y, > 0.5f * dy, 1, 1, -dy, dx, LAST)
}
}
} else {
if (-dx > dy) {
int x = floorf(x1 + 0.5f);
int y = floorf(y1);
float err = (y1 - (float)y) * dx - (x1 - (float)x) * dy;
if (x > end_x) {
WORKER(y, x, <= 0.5f * dx, 1, -1, -dx, -dy, FIRST)
}
while (x > end_x) {
WORKER(y, x, <= 0.5f * dx, 1, -1, -dx, -dy, STEP)
}
if (x >= end_x) {
WORKER(y, x, <= 0.5f * dx, 1, -1, -dx, -dy, LAST)
}
} else {
int x = floorf(x1);
int y = floorf(y1 + 0.5f);
float err = (x1 - (float)x) * dy - (y1 - (float)y) * dx;
/*
This is the only correction that needs to be made in the opposite direction of dy (or dx)
*/
if (err > 0.5f * dy) {
x += 1;
err -= dy;
}
if (y < end_y) {
WORKER(x, y, <= -0.5f * dy, -1, 1, dy, dx, FIRST)
}
while (y < end_y) {
WORKER(x, y, <= -0.5f * dy, -1, 1, dy, dx, STEP)
}
if (y <= end_y) {
WORKER(x, y, <= -0.5f * dy, -1, 1, dy, dx, LAST)
}
}
}
#undef FIRST
#undef LAST
#undef STEP
#undef WORKER
}
/*
This one will check to see what exactly we need to draw...
I.e. this will call all of the actual renderers and set the appropriate callbacks
*/
void _al_line_2d(ALLEGRO_BITMAP* texture, ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2)
{
int shade = 1;
int grad = 1;
int op, src_mode, dst_mode, op_alpha, src_alpha, dst_alpha;
ALLEGRO_COLOR v1c, v2c;
v1c = v1->color;
v2c = v2->color;
al_get_separate_blender(&op, &src_mode, &dst_mode, &op_alpha, &src_alpha, &dst_alpha);
if (_AL_DEST_IS_ZERO && _AL_SRC_NOT_MODIFIED) {
shade = 0;
}
if (v1c.r == v2c.r && v1c.g == v2c.g && v1c.b == v2c.b && v1c.a == v2c.a) {
grad = 0;
}
if (texture) {
if (grad) {
state_texture_grad_any_2d state;
state.solid.texture = texture;
if (shade) {
al_draw_soft_line(v1, v2, (uintptr_t)&state, shader_texture_grad_any_first, shader_texture_grad_any_step, shader_texture_solid_any_draw_shade);
} else {
al_draw_soft_line(v1, v2, (uintptr_t)&state, shader_texture_grad_any_first, shader_texture_grad_any_step, shader_texture_solid_any_draw_opaque);
}
} else {
int white = 0;
state_texture_solid_any_2d state;
if (v1c.r == 1 && v1c.g == 1 && v1c.b == 1 && v1c.a == 1) {
white = 1;
}
state.texture = texture;
if (shade) {
if(white) {
al_draw_soft_line(v1, v2, (uintptr_t)&state, shader_texture_solid_any_first, shader_texture_solid_any_step, shader_texture_solid_any_draw_shade_white);
} else {
al_draw_soft_line(v1, v2, (uintptr_t)&state, shader_texture_solid_any_first, shader_texture_solid_any_step, shader_texture_solid_any_draw_shade);
}
} else {
if(white) {
al_draw_soft_line(v1, v2, (uintptr_t)&state, shader_texture_solid_any_first, shader_texture_solid_any_step, shader_texture_solid_any_draw_opaque_white);
} else {
al_draw_soft_line(v1, v2, (uintptr_t)&state, shader_texture_solid_any_first, shader_texture_solid_any_step, shader_texture_solid_any_draw_opaque);
}
}
}
} else {
if (grad) {
state_grad_any_2d state;
if (shade) {
al_draw_soft_line(v1, v2, (uintptr_t)&state, shader_grad_any_first, shader_grad_any_step, shader_solid_any_draw_shade);
} else {
al_draw_soft_line(v1, v2, (uintptr_t)&state, shader_grad_any_first, shader_grad_any_step, shader_solid_any_draw_opaque);
}
} else {
state_solid_any_2d state;
if (shade) {
al_draw_soft_line(v1, v2, (uintptr_t)&state, shader_solid_any_first, shader_solid_any_step, shader_solid_any_draw_shade);
} else {
al_draw_soft_line(v1, v2, (uintptr_t)&state, shader_solid_any_first, shader_solid_any_step, shader_solid_any_draw_opaque);
}
}
}
}
/* Function: al_draw_soft_line
*/
void al_draw_soft_line(ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2, uintptr_t state,
void (*first)(uintptr_t, int, int, ALLEGRO_VERTEX*, ALLEGRO_VERTEX*),
void (*step)(uintptr_t, int),
void (*draw)(uintptr_t, int, int))
{
/*
Copy the vertices, because we need to alter them a bit before drawing.
*/
ALLEGRO_VERTEX vtx1 = *v1;
ALLEGRO_VERTEX vtx2 = *v2;
ALLEGRO_BITMAP *target = al_get_target_bitmap();
int need_unlock = 0;
ALLEGRO_LOCKED_REGION *lr;
int min_x, max_x, min_y, max_y;
int clip_min_x, clip_min_y, clip_max_x, clip_max_y;
al_get_clipping_rectangle(&clip_min_x, &clip_min_y, &clip_max_x, &clip_max_y);
clip_max_x += clip_min_x;
clip_max_y += clip_min_y;
/*
TODO: Need to clip them first, make a copy of the vertices first then
*/
/*
Lock the region we are drawing to. We are choosing the minimum and maximum
possible pixels touched from the formula (easily verified by following the
above algorithm).
*/
if (vtx1.x >= vtx2.x) {
max_x = (int)ceilf(vtx1.x) + 1;
min_x = (int)floorf(vtx2.x) - 1;
} else {
max_x = (int)ceilf(vtx2.x) + 1;
min_x = (int)floorf(vtx1.x) - 1;
}
if (vtx1.y >= vtx2.y) {
max_y = (int)ceilf(vtx1.y) + 1;
min_y = (int)floorf(vtx2.y) - 1;
} else {
max_y = (int)ceilf(vtx2.y) + 1;
min_y = (int)floorf(vtx1.y) - 1;
}
/*
TODO: This bit is temporary, the min max's will be guaranteed to be within the bitmap
once clipping is implemented
*/
if (min_x >= clip_max_x || min_y >= clip_max_y)
return;
if (max_x >= clip_max_x)
max_x = clip_max_x;
if (max_y >= clip_max_y)
max_y = clip_max_y;
if (max_x < clip_min_x || max_y < clip_min_y)
return;
if (min_x < clip_min_x)
min_x = clip_min_x;
if (min_y < clip_min_y)
min_y = clip_min_y;
if (al_is_bitmap_locked(target)) {
if (!_al_bitmap_region_is_locked(target, min_x, min_y, max_x - min_x, max_y - min_y) ||
_al_pixel_format_is_video_only(target->locked_region.format))
return;
} else {
if (!(lr = al_lock_bitmap_region(target, min_x, min_y, max_x - min_x, max_y - min_y, ALLEGRO_PIXEL_FORMAT_ANY, 0)))
return;
need_unlock = 1;
}
line_stepper(state, first, step, draw, &vtx1, &vtx2);
if (need_unlock)
al_unlock_bitmap(target);
}