Re: [AD] DO_PARALLELOGRAM_MAP again |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On 2010-09-11, Pavel Sountsov <slabode@xxxxxxxxxx> wrote:
>
> Anyway, it's not like the drawer from the primitives addon is fatally
> slower... it is slow for two reasons: it uses function pointers instead
> of macro inlining; it uses al_put_pixel calls instead of direct memory
> writes. Both can be fixed in short order, but as you can imagine they
> make the development of those functions harder... (which is the very
> problem of parallelogram_map) so I did not do them. If that drawer
> becomes used for all bitmap drawing, it won't be a problem to speed it
> up via some macro work.
Yes, I see. With this quick hack `ex_blend_bench 3' is nearly as fast
as `ex_blend_bench 2' on my machine. Restoring the commented out lines
in fix_var makes it about twice as slow.
Peter
diff --git a/addons/primitives/tri_soft.c b/addons/primitives/tri_soft.c
index 2c17f3f..5ba84dd 100644
--- a/addons/primitives/tri_soft.c
+++ b/addons/primitives/tri_soft.c
@@ -245,11 +245,12 @@ static void shader_grad_any_step(uintptr_t state, int minor)
static int fix_var(float var, int max_var)
{
const int ivar = (int)floorf(var);
- const int ret = ivar % max_var;
- if(ret >= 0)
- return ret;
- else
- return ret + max_var;
+// const int ret = ivar % max_var;
+// if(ret >= 0)
+// return ret;
+// else
+// return ret + max_var;
+ return ivar;
}
#define SHADE_COLORS(A, B) \
@@ -277,6 +278,9 @@ typedef struct {
int w, h;
} state_texture_solid_any_2d;
+#include <allegro5/internal/aintern_bitmap.h>
+#include <allegro5/internal/aintern_pixels.h>
+
static void shader_texture_solid_any_draw_shade(uintptr_t state, int x1, int y, int x2)
{
state_texture_solid_any_2d* s = (state_texture_solid_any_2d*)state;
@@ -303,9 +307,39 @@ static void shader_texture_solid_any_draw_shade_white(uintptr_t state, int x1, i
int x;
ALLEGRO_COLOR color;
- for (x = x1; x <= x2; x++) {
- color = al_get_pixel(s->texture, fix_var(u, s->w), fix_var(v, s->h));
- al_put_blended_pixel(x, y - 1, color);
+ ALLEGRO_BITMAP *target = al_get_target_bitmap();
+
+ if (y < target->lock_y || y >= target->lock_y + target->lock_h)
+ return;
+
+ for (x = x1; x <= target->lock_x; x++) {
+ u += s->du_dx;
+ v += s->dv_dx;
+ }
+
+ const ALLEGRO_LOCKED_REGION *lr = &target->locked_region;
+ const int format = lr->format;
+ unsigned char *data = lr->data;
+ data += (y-1 - target->lock_y) * lr->pitch;
+ data += x * al_get_pixel_size(lr->format);
+
+ const int src_format = s->texture->locked_region.format;
+ const int src_size = al_get_pixel_size(src_format);
+
+ x -= target->lock_x;
+ x2 -= target->lock_x;
+ if (x2 > target->lock_w)
+ x2 = target->lock_w;
+
+ for (; x <= x2; x++) {
+ //color = al_get_pixel(s->texture, fix_var(u, s->w), fix_var(v, s->h));
+ unsigned char *src_data = s->texture->locked_region.data;
+ src_data += s->texture->locked_region.pitch * fix_var(v, s->h);
+ src_data += src_size * fix_var(u, s->w);
+ _AL_INLINE_GET_PIXEL(src_format, src_data, color, false);
+
+ // al_put_blended_pixel(x, y - 1, color);
+ _AL_INLINE_PUT_PIXEL(format, data, color, true);
u += s->du_dx;
v += s->dv_dx;