From: <sie...@us...> - 2010-03-29 18:07:39
|
Revision: 13149 http://alleg.svn.sourceforge.net/alleg/?rev=13149&view=rev Author: siegelord Date: 2010-03-29 18:07:32 +0000 (Mon, 29 Mar 2010) Log Message: ----------- Transformations now work properly when the target bitmap is a sub-bitmap in OpenGL (still broken in D3D). Also fixed OpenGL bitmap drawing in the same scenario (it used to always revert to software drawing). Modified Paths: -------------- allegro/branches/4.9/addons/primitives/prim_opengl.c allegro/branches/4.9/addons/primitives/primitives.c allegro/branches/4.9/examples/CMakeLists.txt allegro/branches/4.9/examples/ex_transform.c allegro/branches/4.9/src/opengl/ogl_bitmap.c allegro/branches/4.9/src/opengl/ogl_draw.c Modified: allegro/branches/4.9/addons/primitives/prim_opengl.c =================================================================== --- allegro/branches/4.9/addons/primitives/prim_opengl.c 2010-03-29 12:26:12 UTC (rev 13148) +++ allegro/branches/4.9/addons/primitives/prim_opengl.c 2010-03-29 18:07:32 UTC (rev 13149) @@ -215,19 +215,28 @@ int num_primitives = 0; ALLEGRO_DISPLAY *ogl_disp = al_get_current_display(); ALLEGRO_BITMAP *target = al_get_target_bitmap(); - ALLEGRO_BITMAP_OGL *ogl_target; + ALLEGRO_BITMAP_OGL *ogl_target = (ALLEGRO_BITMAP_OGL *)target; const void* vtx; int stride = decl ? decl->stride : (int)sizeof(ALLEGRO_VERTEX); int num_vtx; - if (target->parent) target = target->parent; - - ogl_target = (void *)target; + if (target->parent) { + ogl_target = (ALLEGRO_BITMAP_OGL *)target->parent; + } if ((!ogl_target->is_backbuffer && ogl_disp->ogl_extras->opengl_target != ogl_target) || al_is_bitmap_locked(target)) { return _al_draw_prim_soft(texture, vtxs, decl, start, end, type); } + /* For sub bitmaps. */ + if(target->parent) { + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glTranslatef(target->xofs, target->yofs, 0); + glMultMatrixf((float*)al_get_current_transform()->m); + } + vtx = (const char*)vtxs + start * stride; num_vtx = end - start; @@ -288,6 +297,11 @@ glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); + + if(target->parent) { + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + } return num_primitives; #else @@ -309,7 +323,7 @@ int num_primitives = 0; ALLEGRO_DISPLAY *ogl_disp = al_get_current_display(); ALLEGRO_BITMAP *target = al_get_target_bitmap(); - ALLEGRO_BITMAP_OGL *ogl_target = (void *)target; + ALLEGRO_BITMAP_OGL *ogl_target = (ALLEGRO_BITMAP_OGL *)target; const void* vtx; const void* idx = indices; GLenum idx_size; @@ -319,10 +333,23 @@ int ii; #endif + if (target->parent) { + ogl_target = (ALLEGRO_BITMAP_OGL *)target->parent; + } + if ((!ogl_target->is_backbuffer && ogl_disp->ogl_extras->opengl_target != ogl_target) || al_is_bitmap_locked(target)) { return _al_draw_prim_indexed_soft(texture, decl, vtxs, indices, num_vtx, type); } + /* For sub bitmaps. */ + if(target->parent) { + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glTranslatef(target->xofs, target->yofs, 0); + glMultMatrixf((float*)al_get_current_transform()->m); + } + vtx = vtxs; setup_blending(); @@ -392,6 +419,11 @@ glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); + + if(target->parent) { + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + } return num_primitives; #else Modified: allegro/branches/4.9/addons/primitives/primitives.c =================================================================== --- allegro/branches/4.9/addons/primitives/primitives.c 2010-03-29 12:26:12 UTC (rev 13148) +++ allegro/branches/4.9/addons/primitives/primitives.c 2010-03-29 18:07:32 UTC (rev 13149) @@ -44,14 +44,6 @@ #define ALLEGRO_DIRECT3D 8 #endif -static void temp_trans(float x, float y) -{ - ALLEGRO_TRANSFORM copy; - al_copy_transform(al_get_current_transform(), ©); - al_translate_transform(©, x, y); - al_use_transform(©); -} - /* Function: al_draw_prim */ int al_draw_prim(const void* vtxs, const ALLEGRO_VERTEX_DECL* decl, @@ -70,13 +62,6 @@ * view space should occur here */ - if (target->parent) { - /* - * For sub-bitmaps - */ - temp_trans((float)target->xofs, (float)target->yofs); - } - if (target->flags & ALLEGRO_MEMORY_BITMAP || (texture && texture->flags & ALLEGRO_MEMORY_BITMAP)) { ret = _al_draw_prim_soft(texture, vtxs, decl, start, end, type); } else { @@ -88,13 +73,6 @@ } } - if (target->parent) { - /* - * Move it back, if rounding errors become an issue we can do a copy-restore instead - */ - temp_trans(-(float)target->xofs, -(float)target->yofs); - } - return ret; } @@ -117,13 +95,6 @@ * view space should occur here */ - if (target->parent) { - /* - * For sub-bitmaps - */ - temp_trans((float)target->xofs, (float)target->yofs); - } - if (target->flags & ALLEGRO_MEMORY_BITMAP || (texture && texture->flags & ALLEGRO_MEMORY_BITMAP)) { ret = _al_draw_prim_indexed_soft(texture, vtxs, decl, indices, num_vtx, type); } else { @@ -135,13 +106,6 @@ } } - if (target->parent) { - /* - * Move it back, if rounding errors become an issue we can do a copy-restore instead - */ - temp_trans(-(float)target->xofs, -(float)target->yofs); - } - return ret; } Modified: allegro/branches/4.9/examples/CMakeLists.txt =================================================================== --- allegro/branches/4.9/examples/CMakeLists.txt 2010-03-29 12:26:12 UTC (rev 13148) +++ allegro/branches/4.9/examples/CMakeLists.txt 2010-03-29 18:07:32 UTC (rev 13149) @@ -123,7 +123,7 @@ example(ex_threads2) example(ex_timedwait) example(ex_timer ${FONT} ${PRIM}) -example(ex_transform ${FONT} ${IMAGE}) +example(ex_transform ${FONT} ${IMAGE} ${PRIM}) example(ex_vsync ${FONT}) example(ex_warp_mouse ${FONT} ${PRIM}) example(ex_windows ${FONT}) Modified: allegro/branches/4.9/examples/ex_transform.c =================================================================== --- allegro/branches/4.9/examples/ex_transform.c 2010-03-29 12:26:12 UTC (rev 13148) +++ allegro/branches/4.9/examples/ex_transform.c 2010-03-29 18:07:32 UTC (rev 13149) @@ -2,6 +2,7 @@ #include "allegro5/allegro5.h" #include "allegro5/allegro_image.h" #include "allegro5/allegro_font.h" +#include "allegro5/allegro_primitives.h" #include <math.h> #include "common.c" @@ -136,6 +137,7 @@ al_draw_rotated_scaled_bitmap(bitmap, w / 2, h / 2, w + w / 2, h + h / 2, 0.7, 0.7, 0.3, 0); al_draw_pixel(w + w / 2, h + h / 2, al_map_rgb_f(0, 1, 0)); al_put_pixel(w + w / 2 + 2, h + h / 2 + 2, al_map_rgb_f(0, 1, 1)); + al_draw_circle(w, h, 50, al_map_rgb_f(1, 0.5, 0), 3); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO, al_map_rgba_f(1, 1, 1, 1)); if(software) { Modified: allegro/branches/4.9/src/opengl/ogl_bitmap.c =================================================================== --- allegro/branches/4.9/src/opengl/ogl_bitmap.c 2010-03-29 12:26:12 UTC (rev 13148) +++ allegro/branches/4.9/src/opengl/ogl_bitmap.c 2010-03-29 18:07:32 UTC (rev 13149) @@ -352,6 +352,11 @@ ALLEGRO_BITMAP *target = al_get_target_bitmap(); ALLEGRO_BITMAP_OGL *ogl_target = (ALLEGRO_BITMAP_OGL *)target; ALLEGRO_DISPLAY *disp = al_get_current_display(); + + if(target->parent) { + ogl_target = (ALLEGRO_BITMAP_OGL *)target->parent; + } + if (disp->ogl_extras->opengl_target != ogl_target || !setup_blending(disp) || target->locked) { _al_draw_scaled_bitmap_memory(bitmap, sx, sy, sw, sh, dx, dy, dw, dh, @@ -359,12 +364,6 @@ return; } - /* For sub-bitmaps */ - if (target->parent) { - dx += target->xofs; - dy += target->yofs; - } - draw_quad(bitmap, sx, sy, sw, sh, 0, 0, dx, dy, dw, dh, 1, 1, 0, flags); } @@ -381,8 +380,6 @@ /* For sub-bitmaps */ if (target->parent) { - dx += target->xofs; - dy += target->yofs; target = target->parent; } @@ -393,6 +390,11 @@ ALLEGRO_BITMAP_OGL *ogl_source = (void *)bitmap; if (ogl_source->is_backbuffer) { float clip; + + if (target->parent) { + dx += target->xofs; + dy += target->yofs; + } /* Have to do our own clipping. */ clip = dx - target->cl; @@ -486,18 +488,17 @@ ALLEGRO_BITMAP *target = al_get_target_bitmap(); ALLEGRO_BITMAP_OGL *ogl_target = (ALLEGRO_BITMAP_OGL *)target; ALLEGRO_DISPLAY *disp = al_get_current_display(); + + if (target->parent) { + ogl_target = (ALLEGRO_BITMAP_OGL *)target->parent; + } + if (disp->ogl_extras->opengl_target != ogl_target || !setup_blending(disp) || target->locked) { _al_draw_rotated_bitmap_memory(bitmap, cx, cy, dx, dy, angle, flags); return; } - /* For sub-bitmaps */ - if (target->parent) { - dx += target->xofs; - dy += target->yofs; - } - draw_quad(bitmap, 0, 0, bitmap->w, bitmap->h, cx, cy, dx, dy, bitmap->w, bitmap->h, 1, 1, angle, flags); } @@ -513,6 +514,11 @@ ALLEGRO_BITMAP *target = al_get_target_bitmap(); ALLEGRO_BITMAP_OGL *ogl_target = (ALLEGRO_BITMAP_OGL *)target; ALLEGRO_DISPLAY *disp = al_get_current_display(); + + if (target->parent) { + ogl_target = (ALLEGRO_BITMAP_OGL *)target->parent; + } + if (disp->ogl_extras->opengl_target != ogl_target || !setup_blending(disp) || target->locked) { _al_draw_rotated_scaled_bitmap_memory(bitmap, cx, cy, dx, dy, @@ -520,12 +526,6 @@ return; } - /* For sub-bitmaps */ - if (target->parent) { - dx += target->xofs; - dy += target->yofs; - } - draw_quad(bitmap, 0, 0, bitmap->w, bitmap->h, cx, cy, dx, dy, bitmap->w, bitmap->h, xscale, yscale, angle, flags); } Modified: allegro/branches/4.9/src/opengl/ogl_draw.c =================================================================== --- allegro/branches/4.9/src/opengl/ogl_draw.c 2010-03-29 12:26:12 UTC (rev 13148) +++ allegro/branches/4.9/src/opengl/ogl_draw.c 2010-03-29 18:07:32 UTC (rev 13149) @@ -132,9 +132,12 @@ } /* For sub bitmaps. */ - if (target->parent) { - x += target->xofs; - y += target->yofs; + if(target->parent) { + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glTranslatef(target->xofs, target->yofs, 0); + glMultMatrixf((float*)(d->cur_transform.m)); } vert[0] = x; @@ -146,6 +149,10 @@ glDrawArrays(GL_POINTS, 0, 1); glDisableClientState(GL_VERTEX_ARRAY); + + if(target->parent) { + glPopMatrix(); + } } static void* ogl_prepare_vertex_cache(ALLEGRO_DISPLAY* disp, @@ -171,10 +178,20 @@ ALLEGRO_COLOR *bc; GLboolean on; GLuint current_texture; + ALLEGRO_BITMAP* target; if(!disp->vertex_cache) return; if(disp->num_cache_vertices == 0) return; + + target = al_get_target_bitmap(); + if(target->parent) { + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glTranslatef(target->xofs, target->yofs, 0); + glMultMatrixf((float*)(disp->cur_transform.m)); + } glGetBooleanv(GL_TEXTURE_2D, &on); if (!on) { @@ -204,6 +221,10 @@ glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); + if(target->parent) { + glPopMatrix(); + } + disp->num_cache_vertices = 0; if (!on) { glDisable(GL_TEXTURE_2D); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |