12 #ifdef ALLEGRO_WINDOWS    19 #include <allegro/internal/aintern.h>    21 #include <OpenGL/glu.h>    27 static GFX_VTABLE allegro_gl_screen_vtable;
    28 static GLuint __allegro_gl_pool_texture = 0;
    30 static GLuint __allegro_gl_dummy_texture = 0; 
    32 static int __agl_owning_drawing_pattern_tex = FALSE;
    33 GLuint __agl_drawing_pattern_tex = 0;
    34 BITMAP *__agl_drawing_pattern_bmp = 0;
    35 static int __agl_drawing_mode = DRAW_MODE_SOLID;
    61 int __allegro_gl_make_power_of_2(
int x) {
    77 void allegro_gl_drawing_mode(
void) {
    78     if (__agl_drawing_mode == _drawing_mode)
    81     switch (__agl_drawing_mode) {
    86             glDisable(GL_COLOR_LOGIC_OP);
    88         case DRAW_MODE_COPY_PATTERN:
    89             glDisable(GL_TEXTURE_2D);
    90             glBindTexture(GL_TEXTURE_2D, 0);
    91             if (__agl_owning_drawing_pattern_tex && __agl_drawing_pattern_tex)
    92                 glDeleteTextures(1, &__agl_drawing_pattern_tex);
    93             __agl_drawing_pattern_tex = 0;
    94             __agl_drawing_pattern_bmp = 0;
    98     __agl_drawing_mode = _drawing_mode;
   100     switch (_drawing_mode) {
   101         case DRAW_MODE_TRANS:
   106             glEnable(GL_COLOR_LOGIC_OP);
   110         case DRAW_MODE_COPY_PATTERN:
   111             if (is_memory_bitmap(_drawing_pattern)) {
   112                 __agl_drawing_pattern_tex =
   114                 __agl_drawing_pattern_bmp = _drawing_pattern;
   115                 __agl_owning_drawing_pattern_tex = TRUE;
   117             else if (is_video_bitmap(_drawing_pattern)) {
   118                 AGL_VIDEO_BITMAP *bmp = _drawing_pattern->extra;
   119                 __agl_drawing_pattern_tex = bmp->tex;
   120                 __agl_drawing_pattern_bmp = bmp->memory_copy;
   121                 __agl_owning_drawing_pattern_tex = FALSE;
   124             glEnable(GL_TEXTURE_2D);
   125             glBindTexture(GL_TEXTURE_2D, __agl_drawing_pattern_tex);
   132 void split_color(
int color, GLubyte *r, GLubyte *g, GLubyte *b, GLubyte *a,
   135     AGL_LOG(2, 
"glvtable.c:split_color\n");
   136     *r = getr_depth(color_depth, color);
   137     *g = getg_depth(color_depth, color);
   138     *b = getb_depth(color_depth, color);
   139     if (color_depth == 32)
   140         *a = geta_depth(color_depth, color);
   148 void allegro_gl_created_sub_bitmap(BITMAP *bmp, BITMAP *parent)
   174 static int allegro_gl_screen_getpixel(
struct BITMAP *bmp, 
int x, 
int y)
   177     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_getpixel\n");
   178     if (bmp->clip && (x < bmp->cl || x >= bmp->cr
   179                                               || y < bmp->ct || y >= bmp->cb)) {
   182     if (is_sub_bitmap(bmp)) {
   186     glReadPixels(x, bmp->h - y - 1, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel);
   188     return makecol_depth(bitmap_color_depth(screen),
   189                                                   pixel[0], pixel[1], pixel[2]);
   194 static void allegro_gl_screen_putpixel(
struct BITMAP *bmp, 
int x, 
int y,
   198     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_putpixel\n");
   199     split_color(color, &r, &g, &b, &a, bitmap_color_depth(bmp));
   200     if (bmp->clip && (x < bmp->cl || x >= bmp->cr
   201                                               || y < bmp->ct || y >= bmp->cb)) {
   205     if (is_sub_bitmap(bmp)) {
   210     glColor4ub(r, g, b, a);
   218 static void allegro_gl_screen_vline(
struct BITMAP *bmp, 
int x, 
int y1, 
int y2,
   222     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_vline\n");
   231         if ((x < bmp->cl) || (x >= bmp->cr)) {
   234         if ((y1 >= bmp->cb) || (y2 < bmp->ct)) {
   245     if (is_sub_bitmap(bmp)) {
   251     split_color(color, &r, &g, &b, &a, bitmap_color_depth(bmp));
   253     glColor4ub(r, g, b, a);
   256         glVertex2f(x, y2 + 0.325 * 3);
   264 static void allegro_gl_screen_hline(
struct BITMAP *bmp, 
int x1, 
int y, 
int x2,
   268     AGL_LOG(2, 
"glvtable.c:allegro_gl_hline\n");
   276         if ((y < bmp->ct) || (y >= bmp->cb)) {
   279         if ((x1 >= bmp->cr) || (x2 < bmp->cl)) {
   289     if (is_sub_bitmap(bmp)) {
   295     split_color(color, &r, &g, &b, &a, bitmap_color_depth(bmp));
   297     glColor4ub(r, g, b, a);
   299         glVertex2f(x1 - 0.325, y);
   300         glVertex2f(x2 + 0.325 * 2, y);
   308 static void allegro_gl_screen_line(
struct BITMAP *bmp, 
int x1, 
int y1, 
int x2,
   312     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_line\n");
   315         glPushAttrib(GL_SCISSOR_BIT);
   316         glEnable(GL_SCISSOR_TEST);
   317         glScissor(bmp->x_ofs + bmp->cl, bmp->h + bmp->y_ofs - bmp->cb,
   318                                           bmp->cr - bmp->cl, bmp->cb - bmp->ct);
   320     if (is_sub_bitmap(bmp)) {
   327     split_color(color, &r, &g, &b, &a, bitmap_color_depth(bmp));
   329     glColor4ub(r, g, b, a);
   331         glVertex2f(x1 + 0.1625, y1 + 0.1625);
   332         glVertex2f(x2 + 0.1625, y2 + 0.1625);
   337         glVertex2f(x2 + 0.1625, y2 + 0.1625);
   348 #define SET_TEX_COORDS(x, y)  \   350         if (__agl_drawing_pattern_tex) {  \   352                 (x - _drawing_x_anchor) / (float)__agl_drawing_pattern_bmp->w,\   353                 (y - _drawing_y_anchor) / (float)__agl_drawing_pattern_bmp->h \   359 void allegro_gl_screen_rectfill(
struct BITMAP *bmp, 
int x1, 
int y1,
   360                                                       int x2, 
int y2, 
int color)
   364     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_rectfill\n");
   379         if ((x1 > bmp->cr) || (x2 < bmp->cl)) {
   388         if ((y1 > bmp->cb) || (y2 < bmp->ct)) {
   398     if (is_sub_bitmap(bmp)) {
   405     glGetFloatv(GL_CURRENT_COLOR, old_col);
   406     split_color(color, &r, &g, &b, &a, bitmap_color_depth(bmp));
   407     glColor4ub(r, g, b, a);
   410         SET_TEX_COORDS(x1, y1);
   412         SET_TEX_COORDS(x2, y1);
   414         SET_TEX_COORDS(x2, y2);
   416         SET_TEX_COORDS(x1, y2);
   427 static void allegro_gl_screen_triangle(
struct BITMAP *bmp, 
int x1, 
int y1,
   428                                       int x2, 
int y2, 
int x3, 
int y3, 
int color)
   431     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_triangle\n");
   433     split_color(color, &r, &g, &b, &a, bitmap_color_depth(bmp));
   436         glPushAttrib(GL_SCISSOR_BIT);
   437         glEnable(GL_SCISSOR_TEST);
   438         glScissor(bmp->x_ofs + bmp->cl, bmp->h + bmp->y_ofs - bmp->cb,
   439                                          bmp->cr - bmp->cl, bmp->cb - bmp->ct);
   441     if (is_sub_bitmap(bmp)) {
   450     glColor4ub(r, g, b, a);
   451     glBegin(GL_TRIANGLES);
   452         SET_TEX_COORDS(x1, y1);
   454         SET_TEX_COORDS(x2, y2);
   456         SET_TEX_COORDS(x3, y3);
   467 #define BITMAP_BLIT_CLIP(source, dest, source_x, source_y, dest_x, dest_y, \   470         if ((dest_x >= dest->cr) || (dest_y >= dest->cb)                   \   471          || (dest_x + width < dest->cl) || (dest_y + height < dest->ct)) { \   474         if (dest_x < dest->cl) {                                           \   475             width += dest_x - dest->cl;                                    \   476             source_x -= dest_x - dest->cl;                                 \   479         if (dest_y < dest->ct) {                                           \   480             height += dest_y - dest->ct;                                   \   481             source_y -= dest_y - dest->ct;                                 \   484         if (dest_x + width > dest->cr) {                                   \   485             width = dest->cr - dest_x;                                     \   487         if (dest_y + height > dest->cb) {                                  \   488             height = dest->cb - dest_y;                                    \   491     if (source->clip) {                                                    \   492         if ((source_x >= source->cr) || (source_y >= source->cb)           \   493          || (source_x + width < source->cl)                                \   494          || (source_y + height < source->ct)) {                            \   497         if (source_x < source->cl) {                                       \   498             width += source_x - source->cl;                                \   499             dest_x -= source_x - source->cl;                               \   500             source_x = source->cl;                                         \   502         if (source_y < source->ct) {                                       \   503             height += source_y - source->ct;                               \   504             dest_y -= source_y - source->ct;                               \   505             source_y = source->ct;                                         \   507         if (source_x + width > source->cr) {                               \   508             width = source->cr - source_x;                                 \   510         if (source_y + height > source->cb) {                              \   511             height = source->cb - source_y;                                \   519 static void allegro_gl_screen_blit_from_memory(
   520     struct BITMAP *source, 
struct BITMAP *dest,
   521     int source_x, 
int source_y, 
int dest_x, 
int dest_y, 
int width, 
int height)
   523     GLfloat saved_zoom_x, saved_zoom_y;
   524     GLint saved_row_length;
   527     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_blit_from_memory\n");
   529     BITMAP_BLIT_CLIP(source, dest, source_x, source_y, dest_x, dest_y,
   532     if (width <= 0 || height <= 0) {
   537     if (is_sub_bitmap(dest)) {
   538         dest_x += dest->x_ofs;
   539         dest_y += dest->y_ofs;
   546     data = source->line[source_y]
   547          + source_x * BYTES_PER_PIXEL(bitmap_color_depth(source));
   553                                            && bitmap_color_depth(source) < 24) {
   554         temp = create_bitmap_ex(24, width, height);
   557             blit(source, temp, source_x, source_y, 0, 0, width, height);
   560             data = temp->line[0];
   571     glGetFloatv(GL_ZOOM_X, &saved_zoom_x);
   572     glGetFloatv(GL_ZOOM_Y, &saved_zoom_y);
   573     glGetIntegerv(GL_UNPACK_ROW_LENGTH, &saved_row_length);
   575     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   577     glRasterPos2i(dest_x, dest_y);
   582     glPixelZoom (1.0, -1.0);
   583     glPixelStorei(GL_UNPACK_ROW_LENGTH,
   584                     (source->line[1] - source->line[0])
   585                     / BYTES_PER_PIXEL(source->vtable->color_depth));
   587     glDrawPixels(width, height, __allegro_gl_get_bitmap_color_format(source, 0),
   588         __allegro_gl_get_bitmap_type(source, 0), data);
   591     glPixelZoom(saved_zoom_x, saved_zoom_y);
   592     glPixelStorei(GL_UNPACK_ROW_LENGTH, saved_row_length);
   595         destroy_bitmap(temp);
   602 static void allegro_gl_screen_blit_to_memory(
   603       struct BITMAP *source, 
struct BITMAP *dest,
   604       int source_x, 
int source_y, 
int dest_x, 
int dest_y, 
int width, 
int height)
   606     GLint saved_row_length;
   607     GLint saved_alignment;
   608     GLint saved_pack_invert;
   612     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_blit_to_memory\n");
   614     BITMAP_BLIT_CLIP(source, dest, source_x, source_y, dest_x, dest_y,
   617     if (is_sub_bitmap(source)) {
   618         source_x += source->x_ofs;
   619         source_y += source->y_ofs;
   621     if (is_sub_bitmap(dest)) {
   622         dest_x += dest->x_ofs;
   623         dest_y += dest->y_ofs;
   626     if (width <= 0 || height <= 0) {
   641        && bitmap_color_depth(dest) < 24)) {
   647            && bitmap_color_depth(dest) < 24)) {
   648             bmp = create_bitmap_ex(24, width, height);
   651             bmp = create_bitmap_ex(bitmap_color_depth(dest), width, height);
   657     glGetIntegerv(GL_PACK_ROW_LENGTH, &saved_row_length);
   658     glGetIntegerv(GL_PACK_ALIGNMENT,  &saved_alignment);
   659     glPixelStorei(GL_PACK_ROW_LENGTH, 0);
   660     glPixelStorei(GL_PACK_ALIGNMENT,  1);
   664         glReadPixels(source_x, source->h - source_y - height, width, height,
   665             __allegro_gl_get_bitmap_color_format(bmp, 0),
   666             __allegro_gl_get_bitmap_type(bmp, 0), bmp->dat);
   669         glGetIntegerv(GL_PACK_INVERT_MESA, &saved_pack_invert);
   670         glPixelStorei(GL_PACK_INVERT_MESA, TRUE);
   671         glPixelStorei(GL_PACK_ROW_LENGTH,
   672                       (dest->line[1] - dest->line[0])
   673                        / BYTES_PER_PIXEL(dest->vtable->color_depth));
   675         glReadPixels(source_x, source->h - source_y - height, width, height,
   676             __allegro_gl_get_bitmap_color_format(dest, 0),
   677             __allegro_gl_get_bitmap_type(dest, 0), dest->line[0]);
   679         glPixelStorei(GL_PACK_INVERT_MESA, saved_pack_invert);
   682     glPixelStorei(GL_PACK_ROW_LENGTH, saved_row_length);
   683     glPixelStorei(GL_PACK_ALIGNMENT,  saved_alignment);
   690         for (y = 0, dy = dest_y + height - 1; y < height; y++, dy--) {
   691             blit(bmp, dest, 0, y, dest_x, dy, width, 1);
   703 void allegro_gl_screen_blit_to_self (
   704      struct BITMAP *source, 
struct BITMAP *dest,
   705      int source_x, 
int source_y, 
int dest_x, 
int dest_y, 
int width, 
int height)
   707     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_blit_to_self\n");
   709     BITMAP_BLIT_CLIP(source, dest, source_x, source_y, dest_x, dest_y,
   712     if (is_sub_bitmap(source)) {
   713         source_x += source->x_ofs;
   714         source_y += source->y_ofs;
   716     if (is_sub_bitmap(dest)) {
   717         dest_x += dest->x_ofs;
   718         dest_y += dest->y_ofs;
   721     if (width <= 0 || height <= 0) {
   726     if (is_screen_bitmap(source) && is_screen_bitmap(dest)) {
   727         glRasterPos2i(dest_x, dest_y + height - 1);
   728         glCopyPixels(source_x, SCREEN_H - source_y - height, width, height,
   732     else if (is_screen_bitmap(dest) && is_video_bitmap(source)) {
   733         AGL_VIDEO_BITMAP *vid;
   734         BITMAP *source_parent = source;
   735         GLfloat current_color[4];
   737         while (source_parent->id & BMP_ID_SUB) {
   738             source_parent = (BITMAP *)source_parent->extra;
   740         vid = source_parent->extra;
   742         glGetFloatv(GL_CURRENT_COLOR, current_color);
   743         glColor4ub(255, 255, 255, 255);
   750             if (source_x >= vid->x_ofs + vid->memory_copy->w ||
   751                 source_y >= vid->y_ofs + vid->memory_copy->h ||
   752                 vid->x_ofs >= source_x + width ||
   753                 vid->y_ofs >= source_y + height) {
   758             sx = MAX(vid->x_ofs, source_x) - vid->x_ofs;
   759             w = MIN(vid->x_ofs + vid->memory_copy->w, source_x + width)
   761             sy = MAX(vid->y_ofs, source_y) - vid->y_ofs;
   762             h = MIN(vid->y_ofs + vid->memory_copy->h, source_y + height)
   765             dx = dest_x + vid->x_ofs + sx - source_x;
   766             dy = dest_y + vid->y_ofs + sy - source_y;
   768             glEnable(vid->target);
   769             glBindTexture(vid->target, vid->tex);
   771             if (vid->target == GL_TEXTURE_2D) {
   772                 float tx = sx / (float)vid->memory_copy->w;
   773                 float ty = sy / (
float)vid->memory_copy->h;
   774                 float tw = w / (float)vid->memory_copy->w;
   775                 float th = h / (
float)vid->memory_copy->h;
   778                     glTexCoord2f(tx, ty);
   780                     glTexCoord2f(tx, ty + th);
   781                     glVertex2f(dx, dy + h);
   782                     glTexCoord2f(tx + tw, ty + th);
   783                     glVertex2f(dx + w, dy + h);
   784                     glTexCoord2f(tx + tw, ty);
   785                     glVertex2f(dx + w, dy);
   790                     glTexCoord2i(sx, sy);
   792                     glTexCoord2i(sx, sy + h);
   793                     glVertex2f(dx, dy + h);
   794                     glTexCoord2i(sx + w, sy + h);
   795                     glVertex2f(dx + w, dy + h);
   796                     glTexCoord2i(sx + w, sy);
   797                     glVertex2f(dx + w, dy);
   801             glBindTexture(vid->target, 0);
   802             glDisable(vid->target);
   807         glColor4fv(current_color);
   810     else if (is_screen_bitmap(source) && is_video_bitmap(dest)) {
   812         AGL_VIDEO_BITMAP *vid;
   813         BITMAP *source_parent = source;
   815         while (source_parent->id & BMP_ID_SUB) {
   816             source_parent = (BITMAP *)source_parent->extra;
   826             if (dest_x >= vid->x_ofs + vid->memory_copy->w ||
   827                 dest_y >= vid->y_ofs + vid->memory_copy->h ||
   828                 vid->x_ofs >= dest_x + width ||
   829                 vid->y_ofs >= dest_y + height) {
   834             dx = MAX(vid->x_ofs, dest_x) - vid->x_ofs;
   835             w = MIN(vid->x_ofs + vid->memory_copy->w, dest_x + width)
   837             dy = MAX(vid->y_ofs, dest_y) - vid->y_ofs;
   838             h = MIN(vid->y_ofs + vid->memory_copy->h, dest_y + height)
   841             sx = source_x + vid->x_ofs + dx - dest_x;
   842             sy = source_y + vid->y_ofs + dy - dest_y;
   845             allegro_gl_screen_blit_to_memory(source, vid->memory_copy,
   846                                              sx, sy, dx, dy, w, h);
   848             allegro_gl_video_blit_from_memory(vid->memory_copy, dest, 0, 0,
   849                 vid->x_ofs, vid->y_ofs, vid->memory_copy->w, vid->memory_copy->h);
   854     else if (is_video_bitmap(source) && is_video_bitmap(dest)) {
   855         allegro_gl_video_blit_to_self(source, dest, source_x, source_y,
   856                                       dest_x, dest_y, width, height);
   862 void allegro_gl_upload_and_display_texture(
struct BITMAP *source,
   863      int source_x, 
int source_y, 
int dest_x, 
int dest_y, 
int width, 
int height,
   864      int flip_dir, GLint format, GLint type)
   867     GLint saved_row_length;
   868     int bytes_per_pixel = BYTES_PER_PIXEL(bitmap_color_depth(source));
   871     glEnable(GL_ALPHA_TEST);
   872     glAlphaFunc(GL_GREATER, 0.0f);
   874     glEnable(GL_TEXTURE_2D);
   875     glBindTexture(GL_TEXTURE_2D, __allegro_gl_pool_texture);
   877     glGetIntegerv(GL_UNPACK_ROW_LENGTH, &saved_row_length);
   878     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   880     glPixelStorei(GL_UNPACK_ROW_LENGTH,
   881                          (source->line[1] - source->line[0]) / bytes_per_pixel);
   883     for (i = 0; i <= abs(width) / 256; i++) {
   884         for (j = 0; j <= abs(height) / 256; j++) {
   886             void *data = source->line[source_y + j * 256]
   887                                        + (source_x + i * 256) * bytes_per_pixel;
   888             int w = abs(width)  - i * 256;
   889             int h = abs(height) - j * 256;
   890             int dx = dest_x + i * 256;
   891             int dy = dest_y + j * 256;
   893             w = (w & -256) ? 256 : w;
   894             h = (h & -256) ? 256 : h;
   896             glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, format, type, data);
   898             tx = (float)w / 256.;
   899             ty = (float)h / 256.;
   901             if (flip_dir & AGL_H_FLIP) {
   902                 dx = 2*dest_x + width - dx;
   906             if (flip_dir & AGL_V_FLIP) {
   907                 dy = 2*dest_y + height - dy;
   911             if (width < 0)  w = -w;
   912             if (height < 0) h = -h;
   915                 glTexCoord2f(0., 0.);
   917                 glTexCoord2f(0., ty);
   918                 glVertex2i(dx, dy + h);
   919                 glTexCoord2f(tx, ty);
   920                 glVertex2i(dx + w, dy + h);
   921                 glTexCoord2f(tx, 0.);
   922                 glVertex2i(dx + w, dy);
   928     glPixelStorei(GL_UNPACK_ROW_LENGTH, saved_row_length);
   929     glBindTexture(GL_TEXTURE_2D, 0);
   930     glDisable(GL_TEXTURE_2D);
   931     glDisable(GL_ALPHA_TEST);
   938 static void do_screen_masked_blit_standard(GLint format, GLint type, 
struct BITMAP *temp, 
int source_x, 
int source_y, 
int dest_x, 
int dest_y, 
int width, 
int height, 
int flip_dir, 
int blit_type)
   940     glPushAttrib(GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
   942     if (blit_type & AGL_NO_ROTATION) {
   943         GLint saved_row_length;
   944         float dx = dest_x, dy = dest_y;
   945         GLfloat zoom_x, zoom_y, old_zoom_x, old_zoom_y;
   947         glEnable(GL_ALPHA_TEST);
   948         glAlphaFunc(GL_GREATER, 0.0f);
   950         glGetIntegerv(GL_UNPACK_ROW_LENGTH, &saved_row_length);
   951         glGetFloatv(GL_ZOOM_X, &old_zoom_x);
   952         glGetFloatv(GL_ZOOM_Y, &old_zoom_y);
   954         if (flip_dir & AGL_H_FLIP) {
   958             dx += abs(width) - 0.5;
   961             zoom_x = (float) width / abs(width);
   964         if (flip_dir & AGL_V_FLIP) {
   966             dy += abs(height) - 0.5;
   969             zoom_y = -1.0f * width / abs(width);
   972         glRasterPos2f(dx, dy);
   973         glPixelZoom(zoom_x, zoom_y);
   974         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   975         glPixelStorei(GL_UNPACK_ROW_LENGTH,
   976                 (temp->line[1] - temp->line[0])
   977                 / BYTES_PER_PIXEL(bitmap_color_depth(temp)));
   979         glDrawPixels(abs(width), abs(height), format, type, temp->line[0]);
   981         glPixelStorei(GL_UNPACK_ROW_LENGTH, saved_row_length);
   982         glPixelZoom(old_zoom_x, old_zoom_y);
   985         allegro_gl_upload_and_display_texture(temp, 0, 0, dest_x, dest_y, width, height,
   986                                    flip_dir, format, type);
   994 static void screen_masked_blit_standard(
struct BITMAP *source,
   995     int source_x, 
int source_y, 
int dest_x, 
int dest_y, 
int width, 
int height,
   996     int flip_dir, 
int blit_type)
  1006                             source_x, source_y, abs(width), abs(height),
  1013     do_screen_masked_blit_standard(format, type, source, source_x, source_y,
  1014         dest_x, dest_y, width, height, flip_dir, blit_type);
  1017         destroy_bitmap(temp);
  1025 static void __allegro_gl_init_nv_register_combiners(BITMAP *bmp)
  1027     GLfloat mask_color[4];
  1028     int depth = bitmap_color_depth(bmp);
  1029     int color = bitmap_mask_color(bmp);
  1031     mask_color[0] = getr_depth(depth, color) / 255.;
  1032     mask_color[1] = getg_depth(depth, color) / 255.;
  1033     mask_color[2] = getb_depth(depth, color) / 255.;
  1036     glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, mask_color);
  1037     glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 2);
  1038     glEnable(GL_REGISTER_COMBINERS_NV);
  1040     glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV,
  1041         GL_TEXTURE0_ARB, GL_SIGNED_IDENTITY_NV, GL_RGB);
  1042     glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV,
  1043         GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB);
  1044     glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV,
  1045         GL_CONSTANT_COLOR0_NV, GL_SIGNED_IDENTITY_NV, GL_RGB);
  1046     glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV,
  1047         GL_ZERO, GL_EXPAND_NORMAL_NV, GL_RGB);
  1048     glCombinerOutputNV(GL_COMBINER0_NV, GL_RGB, GL_DISCARD_NV,
  1049         GL_DISCARD_NV, GL_SPARE0_NV, GL_NONE, GL_NONE,
  1050         GL_FALSE, GL_FALSE, GL_FALSE);
  1052     glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_A_NV,
  1053         GL_SPARE0_NV, GL_SIGNED_IDENTITY_NV, GL_RGB);
  1054     glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_B_NV,
  1055         GL_SPARE0_NV, GL_SIGNED_IDENTITY_NV, GL_RGB);
  1056     glCombinerOutputNV(GL_COMBINER1_NV, GL_RGB, GL_SPARE1_NV,
  1057         GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE,
  1058         GL_TRUE, GL_FALSE, GL_FALSE);
  1060     glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_TEXTURE0_ARB,
  1061         GL_UNSIGNED_IDENTITY_NV, GL_RGB);
  1062     glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_ZERO,
  1063         GL_UNSIGNED_INVERT_NV, GL_RGB);
  1064     glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO,
  1065         GL_UNSIGNED_IDENTITY_NV, GL_RGB);
  1066     glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_ZERO,
  1067         GL_UNSIGNED_IDENTITY_NV, GL_RGB);
  1068     glFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_SPARE1_NV,
  1069         GL_UNSIGNED_IDENTITY_NV, GL_BLUE);
  1076 static void screen_masked_blit_nv_register(
struct BITMAP *source,
  1077     int source_x, 
int source_y, 
int dest_x, 
int dest_y, 
int width, 
int height,
  1078     int flip_dir, 
int blit_type)
  1080     BITMAP *temp = NULL;
  1081     GLint type   = __allegro_gl_get_bitmap_type(source, 0);
  1082     GLint format = __allegro_gl_get_bitmap_color_format(source, 0);
  1085         temp = create_bitmap_ex(24, width, height);
  1089         blit(source, temp, source_x, source_y, 0, 0, width, height);
  1094         type   = __allegro_gl_get_bitmap_type(source, 0);
  1095         format = __allegro_gl_get_bitmap_color_format(source, 0);
  1098     glPushAttrib(GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
  1099     __allegro_gl_init_nv_register_combiners(source);
  1101     allegro_gl_upload_and_display_texture(source, source_x, source_y, dest_x, dest_y,
  1102                                width, height, flip_dir, format, type);
  1107         destroy_bitmap(temp);
  1114 static void __allegro_gl_init_combine_textures(BITMAP *bmp)
  1116     GLubyte mask_color[4];
  1118     split_color(bitmap_mask_color(bmp), &mask_color[0], &mask_color[1],
  1119         &mask_color[2], &mask_color[3], bitmap_color_depth(bmp));
  1120     glColor4ubv(mask_color);
  1122     glActiveTexture(GL_TEXTURE0);
  1123     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
  1124     glEnable(GL_TEXTURE_2D);
  1125     glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD_SIGNED_ARB);
  1126     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
  1127     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR);
  1128     glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_ONE_MINUS_SRC_COLOR);
  1134     glActiveTexture(GL_TEXTURE1);
  1135     glEnable(GL_TEXTURE_2D);
  1136     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
  1137     glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGBA_ARB);
  1138     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
  1139     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB);
  1143     glActiveTexture(GL_TEXTURE2);
  1144     glEnable(GL_TEXTURE_2D);
  1145     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
  1146     glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
  1147     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
  1148     glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
  1149     glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB);
  1151     glActiveTexture(GL_TEXTURE0);
  1158 static void screen_masked_blit_combine_tex(
struct BITMAP *source,
  1159     int source_x, 
int source_y, 
int dest_x, 
int dest_y, 
int width, 
int height,
  1160     int flip_dir, 
int blit_type)
  1163     BITMAP *temp = NULL;
  1164     GLint saved_row_length;
  1165     GLint type   = __allegro_gl_get_bitmap_type(source, 0);
  1166     GLint format = __allegro_gl_get_bitmap_color_format(source, 0);
  1167     int bytes_per_pixel;
  1169     GLfloat current_color[4];
  1172         temp = create_bitmap_ex(24, width, height);
  1175         blit(source, temp, source_x, source_y, 0, 0, width, height);
  1180         type   = __allegro_gl_get_bitmap_type(source, 0);
  1181         format = __allegro_gl_get_bitmap_color_format(source, 0);
  1184     glEnable(GL_TEXTURE_2D);
  1185     glBindTexture(GL_TEXTURE_2D, __allegro_gl_pool_texture);
  1187     glPushAttrib(GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT);
  1188     glGetFloatv(GL_CURRENT_COLOR, current_color);
  1189     __allegro_gl_init_combine_textures(source);
  1191     glActiveTexture(GL_TEXTURE0);
  1192     glBindTexture(GL_TEXTURE_2D, __allegro_gl_pool_texture);
  1193     glActiveTexture(GL_TEXTURE1);
  1194     glBindTexture(GL_TEXTURE_2D, __allegro_gl_pool_texture);
  1195     glActiveTexture(GL_TEXTURE2);
  1196     glBindTexture(GL_TEXTURE_2D, __allegro_gl_pool_texture);
  1197     glActiveTexture(GL_TEXTURE0);
  1199     bytes_per_pixel = BYTES_PER_PIXEL(bitmap_color_depth(source));
  1201     glEnable(GL_ALPHA_TEST);
  1202     glAlphaFunc(GL_GREATER, 0.0f);
  1204     glGetIntegerv(GL_UNPACK_ROW_LENGTH, &saved_row_length);
  1205     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  1207     glPixelStorei(GL_UNPACK_ROW_LENGTH,
  1208                          (source->line[1] - source->line[0]) / bytes_per_pixel);
  1210     for (i = 0; i <= width / 256; i++) {
  1211         for (j = 0; j <= height / 256; j++) {
  1213             void *data = source->line[source_y + j * 256]
  1214                                        + (source_x + i * 256) * bytes_per_pixel;
  1215             int w = width - i * 256;
  1216             int h = height - j * 256;
  1217             int dx = dest_x + i * 256;
  1218             int dy = dest_y + j * 256;
  1220             w = (w & -256) ? 256 : w;
  1221             h = (h & -256) ? 256 : h;
  1223             glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, format, type, data);
  1225             tx = (float)w / 256.;
  1226             ty = (float)h / 256.;
  1228             if (flip_dir & AGL_H_FLIP) {
  1229                 dx = 2*dest_x + width - dx;
  1233             if (flip_dir & AGL_V_FLIP) {
  1234                 dy = 2*dest_y + height - dy;
  1239                 glMultiTexCoord2f(GL_TEXTURE0, 0., 0.);
  1240                 glMultiTexCoord2f(GL_TEXTURE1, 0., 0.);
  1241                 glMultiTexCoord2f(GL_TEXTURE2, 0., 0.);
  1243                 glMultiTexCoord2f(GL_TEXTURE0, 0., ty);
  1244                 glMultiTexCoord2f(GL_TEXTURE1, 0., ty);
  1245                 glMultiTexCoord2f(GL_TEXTURE2, 0., ty);
  1246                 glVertex2f(dx, dy + h);
  1247                 glMultiTexCoord2f(GL_TEXTURE0, tx, ty);
  1248                 glMultiTexCoord2f(GL_TEXTURE1, tx, ty);
  1249                 glMultiTexCoord2f(GL_TEXTURE2, tx, ty);
  1250                 glVertex2f(dx + w, dy + h);
  1251                 glMultiTexCoord2f(GL_TEXTURE0, tx, 0.);
  1252                 glMultiTexCoord2f(GL_TEXTURE1, tx, 0.);
  1253                 glMultiTexCoord2f(GL_TEXTURE2, tx, 0.);
  1254                 glVertex2f(dx + w, dy);
  1260     glPixelStorei(GL_UNPACK_ROW_LENGTH, saved_row_length);
  1261     glBindTexture(GL_TEXTURE_2D, 0);
  1262     glDisable(GL_TEXTURE_2D);
  1264     glColor4fv(current_color);
  1267         destroy_bitmap(temp);
  1275 void do_masked_blit_screen(
struct BITMAP *source, 
struct BITMAP *dest,
  1276      int source_x, 
int source_y, 
int dest_x, 
int dest_y, 
int width, 
int height,
  1277      int flip_dir, 
int blit_type)
  1285     if (dest->clip && (blit_type & AGL_NO_ROTATION)) {
  1286         if ((dest_x >= dest->cr) || (dest_y >= dest->cb)
  1287          || (dest_x + width < dest->cl) || (dest_y + height < dest->ct)) {
  1290         if (flip_dir & AGL_H_FLIP) {
  1291             if (dest_x < dest->cl) {
  1292                 width += dest_x - dest->cl;
  1295             if (dest_x + width > dest->cr) {
  1296                 source_x += dest_x + width - dest->cr;
  1297                 width = dest->cr - dest_x;
  1301             if (dest_x < dest->cl) {
  1302                 width += dest_x - dest->cl;
  1303                 source_x -= dest_x - dest->cl;
  1306             if (dest_x + width > dest->cr) {
  1307                 width = dest->cr - dest_x;
  1310         if (flip_dir & AGL_V_FLIP) {
  1311             if (dest_y < dest->ct) {
  1312                 height += dest_y - dest->ct;
  1315             if (dest_y + height > dest->cb) {
  1316                 source_y += dest_y + height - dest->cb;
  1317                 height = dest->cb - dest_y;
  1321             if (dest_y < dest->ct) {
  1322                 height += dest_y - dest->ct;
  1323                 source_y -= dest_y - dest->ct;
  1326             if (dest_y + height > dest->cb) {
  1327                 height = dest->cb - dest_y;
  1333     if (source->clip && (blit_type & AGL_REGULAR_BMP)) {
  1334         if ((source_x >= source->cr) || (source_y >= source->cb)
  1335          || (source_x + width < source->cl)
  1336          || (source_y + height < source->ct)) {
  1339         if (source_x < source->cl) {
  1340             width += source_x - source->cl;
  1341             dest_x -= source_x - source->cl;
  1342             source_x = source->cl;
  1344         if (source_y < source->ct) {
  1345             height += source_y - source->ct;
  1346             dest_y -= source_y - source->ct;
  1347             source_y = source->ct;
  1349         if (source_x + width > source->cr) {
  1350             width = source->cr - source_x;
  1352         if (source_y + height > source->cb) {
  1353             height = source->cb - source_y;
  1356     if (is_sub_bitmap(dest)) {
  1357         dest_x += dest->x_ofs;
  1358         dest_y += dest->y_ofs;
  1360     if (width <= 0 || height <= 0)
  1364     if (!is_video_bitmap(source) && !is_screen_bitmap(source)) {
  1366         __allegro_gl_driver->screen_masked_blit(source, source_x, source_y,
  1367                             dest_x, dest_y, width, height, flip_dir, blit_type);
  1370     else if (is_video_bitmap(source)) {
  1371         AGL_VIDEO_BITMAP *vid;
  1372         BITMAP *source_parent = source;
  1374         int use_combiners = 0;
  1378          || allegro_gl_info.num_texture_units >= 3) {
  1382             glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT);
  1385                 __allegro_gl_init_nv_register_combiners(source);
  1388                 __allegro_gl_init_combine_textures(source);
  1391             glEnable(GL_ALPHA_TEST);
  1392             glAlphaFunc(GL_GREATER, 0.0f);
  1395         while (source_parent->id & BMP_ID_SUB) {
  1396             source_parent = (BITMAP *)source_parent->extra;
  1398         vid = source_parent->extra;
  1405             if (source_x >= vid->x_ofs + vid->memory_copy->w ||
  1406                 source_y >= vid->y_ofs + vid->memory_copy->h ||
  1407                 vid->x_ofs >= source_x + width ||
  1408                 vid->y_ofs >= source_y + height) {
  1413             sx = MAX (vid->x_ofs, source_x) - vid->x_ofs;
  1414             w = MIN (vid->x_ofs + vid->memory_copy->w, source_x + width)
  1416             sy = MAX (vid->y_ofs, source_y) - vid->y_ofs;
  1417             h = MIN (vid->y_ofs + vid->memory_copy->h, source_y + height)
  1420             dx = dest_x + vid->x_ofs + sx - source_x;
  1421             dy = dest_y + vid->y_ofs + sy - source_y;
  1423             if (flip_dir & AGL_H_FLIP) {
  1424                 dx = 2*dest_x + width - dx;
  1428             if (flip_dir & AGL_V_FLIP) {
  1429                 dy = 2*dest_y + height - dy;
  1433             if (use_combiners) {
  1435                     glEnable(vid->target);
  1436                     glBindTexture(vid->target, vid->tex);
  1437                     glTexParameteri(vid->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  1438                     glTexParameteri(vid->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  1440                     if (vid->target == GL_TEXTURE_2D) {
  1441                         float tx = sx / (float)vid->memory_copy->w;
  1442                         float ty = sy / (
float)vid->memory_copy->h;
  1443                         float tw = abs(w) / (float)vid->memory_copy->w;
  1444                         float th = abs(h) / (float)vid->memory_copy->h;
  1447                             glTexCoord2f(tx, ty);
  1449                             glTexCoord2f(tx, ty + th);
  1450                             glVertex2f(dx, dy + h);
  1451                             glTexCoord2f(tx + tw, ty + th);
  1452                             glVertex2f(dx + w, dy + h);
  1453                             glTexCoord2f(tx + tw, ty);
  1454                             glVertex2f(dx + w, dy);
  1459                             glTexCoord2i(sx, sy);
  1461                             glTexCoord2i(sx, sy + h);
  1462                             glVertex2f(dx, dy + h);
  1463                             glTexCoord2i(sx + w, sy + h);
  1464                             glVertex2f(dx + w, dy + h);
  1465                             glTexCoord2i(sx + w, sy);
  1466                             glVertex2f(dx + w, dy);
  1470                     glBindTexture(vid->target, 0);
  1471                     glDisable(vid->target);
  1474                     glEnable(vid->target);
  1475                     glActiveTexture(GL_TEXTURE0);
  1476                     glBindTexture(vid->target, vid->tex);
  1477                     glActiveTexture(GL_TEXTURE1);
  1478                     glBindTexture(vid->target, vid->tex);
  1479                     glActiveTexture(GL_TEXTURE2);
  1480                     glBindTexture(vid->target, vid->tex);
  1481                     glActiveTexture(GL_TEXTURE0);
  1482                     glTexParameteri(vid->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  1483                     glTexParameteri(vid->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  1485                     if (vid->target == GL_TEXTURE_2D) {
  1486                         float tx, ty, tw, th; 
  1487                         tx = sx / (float)vid->memory_copy->w;
  1488                         ty = sy / (
float)vid->memory_copy->h;
  1489                         tw = abs(w) / (float)vid->memory_copy->w;
  1490                         th = abs(h) / (float)vid->memory_copy->h;
  1493                             glMultiTexCoord2f(GL_TEXTURE0, tx, ty);
  1494                             glMultiTexCoord2f(GL_TEXTURE1, tx, ty);
  1495                             glMultiTexCoord2f(GL_TEXTURE2, tx, ty);
  1497                             glMultiTexCoord2f(GL_TEXTURE0, tx, ty + th);
  1498                             glMultiTexCoord2f(GL_TEXTURE1, tx, ty + th);
  1499                             glMultiTexCoord2f(GL_TEXTURE2, tx, ty + th);
  1500                             glVertex2f(dx, dy + h);
  1501                             glMultiTexCoord2f(GL_TEXTURE0, tx + tw, ty + th);
  1502                             glMultiTexCoord2f(GL_TEXTURE1, tx + tw, ty + th);
  1503                             glMultiTexCoord2f(GL_TEXTURE2, tx + tw, ty + th);
  1504                             glVertex2f(dx + w, dy + h);
  1505                             glMultiTexCoord2f(GL_TEXTURE0, tx + tw, ty);
  1506                             glMultiTexCoord2f(GL_TEXTURE1, tx + tw, ty);
  1507                             glMultiTexCoord2f(GL_TEXTURE2, tx + tw, ty);
  1508                             glVertex2f(dx + w, dy);
  1513                             glMultiTexCoord2i(GL_TEXTURE0, dx, dy);
  1514                             glMultiTexCoord2i(GL_TEXTURE1, dx, dy);
  1515                             glMultiTexCoord2i(GL_TEXTURE2, dx, dy);
  1517                             glMultiTexCoord2i(GL_TEXTURE0, dx, dy + h);
  1518                             glMultiTexCoord2i(GL_TEXTURE1, dx, dy + h);
  1519                             glMultiTexCoord2i(GL_TEXTURE2, dx, dy + h);
  1520                             glVertex2f(dx, dy + h);
  1521                             glMultiTexCoord2i(GL_TEXTURE0, dx + w, dy + h);
  1522                             glMultiTexCoord2i(GL_TEXTURE1, dx + w, dy + h);
  1523                             glMultiTexCoord2i(GL_TEXTURE2, dx + w, dy + h);
  1524                             glVertex2f(dx + w, dy + h);
  1525                             glMultiTexCoord2i(GL_TEXTURE0, dx + w, dy);
  1526                             glMultiTexCoord2i(GL_TEXTURE1, dx + w, dy);
  1527                             glMultiTexCoord2i(GL_TEXTURE2, dx + w, dy);
  1528                             glVertex2f(dx + w, dy);
  1532                     glBindTexture(vid->target, 0);
  1533                     glDisable(vid->target);
  1537                 screen_masked_blit_standard(vid->memory_copy, sx, sy, dx, dy,
  1538                                             w, h, FALSE, blit_type);
  1544         if (use_combiners) {
  1553 static BITMAP* __allegro_gl_convert_rle_sprite(AL_CONST 
struct RLE_SPRITE *sprite, 
int trans)
  1555     BITMAP *temp = NULL;
  1556     int y, x, src_depth;
  1557     signed long src_mask;
  1559     #define DRAW_RLE_8888(bits)                 \  1561         for (y = 0; y < sprite->h; y++) {           \  1562             signed long c = *s++;               \  1563             for (x = 0; x < sprite->w;) {           \  1564                 if (c == src_mask)          \  1568                     for (c--; c>=0; c--) {      \  1569                         unsigned long col = *s++;       \  1570                         if (bits == 32 && trans)        \  1571                             _putpixel32(temp, x++, y, makeacol32(getr32(col), getg32(col), getb32(col), geta32(col))); \  1573                             _putpixel32(temp, x++, y, makeacol32(getr##bits(col), getg##bits(col), getb##bits(col), 255)); \  1578                     hline(temp, x, y, x-c+1, 0);    \  1586     src_depth = sprite->color_depth;
  1590         src_mask = makecol_depth(src_depth, 255, 0, 255);
  1592     temp = create_bitmap_ex(32, sprite->w, sprite->h);
  1593     if (!temp) 
return NULL;
  1599             signed char *s = (
signed char*)sprite->dat;
  1605             int16_t *s = (int16_t*)sprite->dat;
  1611             int16_t *s = (int16_t*)sprite->dat;
  1617             int32_t *s = (int32_t*)sprite->dat;
  1623             int32_t *s = (int32_t*)sprite->dat;
  1634 void allegro_gl_screen_draw_rle_sprite(
struct BITMAP *bmp, AL_CONST 
struct RLE_SPRITE *sprite, 
int x, 
int y)
  1636     BITMAP *temp = NULL, *temp2 = NULL;
  1637     int source_x = 0, source_y = 0;
  1638     int width = sprite->w, height = sprite->h;
  1640     temp = __allegro_gl_convert_rle_sprite(sprite, FALSE);
  1644     BITMAP_BLIT_CLIP(temp, bmp, source_x, source_y, x, y, width, height);
  1646     if (is_sub_bitmap(bmp)) {
  1651     if (width <= 0 || height <= 0) {
  1652         destroy_bitmap(temp);
  1656     temp2 = create_sub_bitmap(temp, source_x, source_y, width, height);
  1658         destroy_bitmap(temp);
  1662     do_screen_masked_blit_standard(GL_RGBA, 
  1664         0, 0, x, y, width, height, FALSE, AGL_NO_ROTATION);
  1666     destroy_bitmap(temp2);
  1667     destroy_bitmap(temp);
  1671 static void allegro_gl_screen_draw_trans_rgba_rle_sprite(
struct BITMAP *bmp,
  1672                             AL_CONST 
struct RLE_SPRITE *sprite, 
int x, 
int y) {
  1673     BITMAP *temp = NULL, *temp2 = NULL;
  1674     int source_x = 0, source_y = 0;
  1675     int width = sprite->w, height = sprite->h;
  1677     temp = __allegro_gl_convert_rle_sprite(sprite, TRUE);
  1681     BITMAP_BLIT_CLIP(temp, bmp, source_x, source_y, x, y, width, height);
  1683     if (is_sub_bitmap(bmp)) {
  1688     if (width <= 0 || height <= 0) {
  1689         destroy_bitmap(temp);
  1693     temp2 = create_sub_bitmap(temp, source_x, source_y, width, height);
  1695         destroy_bitmap(temp);
  1699     if (__allegro_gl_blit_operation == AGL_OP_LOGIC_OP)
  1700         glEnable(GL_COLOR_LOGIC_OP);
  1704     allegro_gl_upload_and_display_texture(temp2, 0, 0, x, y, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE);
  1706     if (__allegro_gl_blit_operation == AGL_OP_LOGIC_OP)
  1707         glDisable(GL_COLOR_LOGIC_OP);
  1709         glDisable(GL_BLEND);
  1711     destroy_bitmap(temp2);
  1712     destroy_bitmap(temp);
  1717 static void allegro_gl_screen_masked_blit(
struct BITMAP *source,
  1718     struct BITMAP *dest, 
int source_x, 
int source_y, 
int dest_x, 
int dest_y,
  1719     int width, 
int height)
  1721     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_masked_blit\n");
  1722     do_masked_blit_screen(source, dest, source_x, source_y, dest_x, dest_y,
  1723                           width, height, FALSE, AGL_REGULAR_BMP | AGL_NO_ROTATION);
  1728 static void allegro_gl_screen_draw_sprite(
struct BITMAP *bmp,
  1729     struct BITMAP *sprite, 
int x, 
int y)
  1731     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_draw_sprite\n");
  1732     do_masked_blit_screen(sprite, bmp, 0, 0, x, y, sprite->w, sprite->h,
  1733                           FALSE, AGL_NO_ROTATION);
  1738 static void allegro_gl_screen_draw_sprite_v_flip(
struct BITMAP *bmp,
  1739     struct BITMAP *sprite, 
int x, 
int y)
  1741     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_draw_sprite_v_flip\n");
  1742     do_masked_blit_screen(sprite, bmp, 0, 0, x, y, sprite->w, sprite->h,
  1743                           AGL_V_FLIP, AGL_NO_ROTATION);
  1748 static void allegro_gl_screen_draw_sprite_h_flip(
struct BITMAP *bmp,
  1749     struct BITMAP *sprite, 
int x, 
int y)
  1751     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_draw_sprite_h_flip\n");
  1752     do_masked_blit_screen(sprite, bmp, 0, 0, x, y, sprite->w, sprite->h,
  1753                           AGL_H_FLIP, AGL_NO_ROTATION);
  1758 static void allegro_gl_screen_draw_sprite_vh_flip(
struct BITMAP *bmp,
  1759     struct BITMAP *sprite, 
int x, 
int y)
  1761     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_draw_sprite_vh_flip\n");
  1762     do_masked_blit_screen(sprite, bmp, 0, 0, x, y, sprite->w, sprite->h,
  1763                           AGL_V_FLIP | AGL_H_FLIP, AGL_NO_ROTATION);
  1768 static void allegro_gl_screen_pivot_scaled_sprite_flip(
struct BITMAP *bmp,
  1769     struct BITMAP *sprite, fixed x, fixed y, fixed cx, fixed cy, fixed angle,
  1770     fixed scale, 
int v_flip)
  1772     double dscale = fixtof(scale);
  1774     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_pivot_scaled_sprite_flip\n");
  1776 #define BIN_2_DEG(x) (-(x) * 180.0 / 128)  1778     glGetIntegerv(GL_MATRIX_MODE, &matrix_mode);
  1779     glMatrixMode(GL_MODELVIEW);
  1781     glTranslated(fixtof(x), fixtof(y), 0.);
  1782     glRotated(BIN_2_DEG(fixtof(angle)), 0., 0., -1.);
  1783     glScaled(dscale, dscale, dscale);
  1784     glTranslated(-fixtof(x+cx), -fixtof(y+cy), 0.);
  1786     do_masked_blit_screen(sprite, bmp, 0, 0, fixtoi(x), fixtoi(y),
  1787                           sprite->w, sprite->h, v_flip ? AGL_V_FLIP : FALSE, FALSE);
  1789     glMatrixMode(matrix_mode);
  1798 static void allegro_gl_screen_draw_trans_rgba_sprite(
struct BITMAP *bmp,
  1799     struct BITMAP *sprite, 
int x, 
int y) {
  1801     if (__allegro_gl_blit_operation == AGL_OP_LOGIC_OP)
  1802         glEnable(GL_COLOR_LOGIC_OP);
  1807     if (is_video_bitmap(sprite)) {
  1808         allegro_gl_screen_blit_to_self(sprite, bmp, 0, 0, x, y, sprite->w, sprite->h);
  1811     else if (is_memory_bitmap(sprite)) {
  1813         GLint type = __allegro_gl_get_bitmap_type(sprite, 0);
  1814         allegro_gl_upload_and_display_texture(sprite, 0, 0, x, y, sprite->w, sprite->h, 0, format, type);
  1817     if (__allegro_gl_blit_operation == AGL_OP_LOGIC_OP)
  1818         glDisable(GL_COLOR_LOGIC_OP);
  1820         glDisable(GL_BLEND);
  1827 static void allegro_gl_screen_draw_sprite_ex(
struct BITMAP *bmp,
  1828     struct BITMAP *sprite, 
int x, 
int y, 
int mode, 
int flip)
  1832     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_draw_sprite_ex\n");
  1836         case DRAW_SPRITE_NO_FLIP:
  1839         case DRAW_SPRITE_V_FLIP:
  1842         case DRAW_SPRITE_H_FLIP:
  1845         case DRAW_SPRITE_VH_FLIP:
  1846             lflip = AGL_V_FLIP | AGL_H_FLIP;
  1851         case DRAW_SPRITE_NORMAL:
  1852             do_masked_blit_screen(sprite, bmp, 0, 0, x, y, sprite->w, sprite->h,
  1853                 lflip, AGL_NO_ROTATION);
  1855         case DRAW_SPRITE_TRANS:
  1857                 glGetIntegerv(GL_MATRIX_MODE, &matrix_mode);
  1858                 glMatrixMode(GL_MODELVIEW);
  1861                 glTranslatef(x, y, 0.f);
  1862                 glScalef((lflip&AGL_H_FLIP) ? -1 : 1, (lflip&AGL_V_FLIP)? -1 : 1, 1);
  1863                 glTranslatef(-x, -y, 0);
  1864                 glTranslatef((lflip&AGL_H_FLIP) ? -sprite->w : 0,
  1865                              (lflip&AGL_V_FLIP) ? -sprite->h : 0, 0);
  1868             allegro_gl_screen_draw_trans_rgba_sprite(bmp, sprite, x, y);
  1872                 glMatrixMode(matrix_mode);
  1875         case DRAW_SPRITE_LIT:
  1883 void allegro_gl_screen_draw_glyph_ex(
struct BITMAP *bmp,
  1884                                   AL_CONST 
struct FONT_GLYPH *glyph, 
int x, 
int y,
  1885                                   int color, 
int bg, 
int flip)
  1891     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_draw_glyph_ex\n");
  1894         glPushAttrib(GL_SCISSOR_BIT);
  1895         glEnable(GL_SCISSOR_TEST);
  1896         glScissor(bmp->x_ofs + bmp->cl, bmp->h + bmp->y_ofs - bmp->cb,
  1897                   bmp->cr - bmp->cl, bmp->cb - bmp->ct);
  1900             x_offs -= x - bmp->cl;
  1904     if (is_sub_bitmap(bmp)) {
  1910         split_color(bg, &r, &g, &b, &a, bitmap_color_depth(bmp));
  1911         glColor4ub(r, g, b, a);
  1912         glRecti(x, y, x + glyph->w, y + glyph->h);              
  1915     split_color(color, &r, &g, &b, &a, bitmap_color_depth(bmp));
  1916     glColor4ub(r, g, b, a);
  1917     glRasterPos2i(x, y);
  1918     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  1919     glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
  1922         for (i = 0; i < glyph->h; i++) {
  1923             glBitmap(glyph->w, 1, x_offs, i, 0, 2,
  1924                                          glyph->dat + i * ((glyph->w + 7) / 8));
  1928         for (i = 0; i < glyph->h; i++) {
  1929             glBitmap(glyph->w, 1, x_offs, i, 0, 0,
  1930                                          glyph->dat + i * ((glyph->w + 7) / 8));
  1943 static void allegro_gl_screen_draw_glyph(
struct BITMAP *bmp,
  1944                                   AL_CONST 
struct FONT_GLYPH *glyph, 
int x, 
int y,
  1945                                   int color, 
int bg) {
  1946     allegro_gl_screen_draw_glyph_ex(bmp, glyph, x, y, color, bg, 0);
  1951 void allegro_gl_screen_draw_color_glyph_ex(
struct BITMAP *bmp,
  1952     struct BITMAP *sprite, 
int x, 
int y, 
int color, 
int bg, 
int flip)
  1958     static GLfloat red_map[256];
  1959     static GLfloat green_map[256];
  1960     static GLfloat blue_map[256];
  1961     static GLfloat alpha_map[256];
  1964     GLint saved_row_length;
  1965     GLint width, height;
  1966     int sprite_x = 0, sprite_y = 0;
  1974         if ((x >= bmp->cr) || (y >= bmp->cb) || (x + width < bmp->cl)
  1975          || (y + height < bmp->ct)) {
  1979             width += x - bmp->cl;
  1980             sprite_x -= (x - bmp->cl);
  1984             height += y - bmp->ct;
  1985             sprite_y -= (y - bmp->ct);
  1988         if (x + width > bmp->cr) {
  1989             width = bmp->cr - x;
  1991         if (y + height > bmp->cb) {
  1992             height = bmp->cb - y;
  1995     if (is_sub_bitmap(bmp)) {
  2000     data = sprite->line[sprite_y]
  2001          + sprite_x * BYTES_PER_PIXEL(bitmap_color_depth(sprite));
  2004         glAlphaFunc(GL_GREATER, 0.0f);
  2005         glEnable(GL_ALPHA_TEST);
  2009         split_color(bg, &r, &g, &b, &a, bitmap_color_depth(bmp));
  2010         red_map[0] = r / 255.;
  2011         green_map[0] = g / 255.;
  2012         blue_map[0] = b / 255.;
  2017         table = _palette_expansion_table(bitmap_color_depth(bmp));
  2019         for(i = 1; i < 255; i++) {
  2020             split_color(table[i], &r, &g, &b, &a, bitmap_color_depth(bmp));
  2021             red_map[i] = r / 255.;
  2022             green_map[i] = g / 255.;
  2023             blue_map[i] = b / 255.;
  2028         split_color(color, &r, &g, &b, &a, bitmap_color_depth(bmp));
  2030         for(i = 1; i < 255; i++) {
  2031             red_map[i] = r / 255.;
  2032             green_map[i] = g / 255.;
  2033             blue_map[i] = b / 255.;
  2038     glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, red_map);
  2039     glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, green_map);
  2040     glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, blue_map);
  2041     glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 256, alpha_map);
  2043     glRasterPos2i(x, y);
  2044     glPushAttrib(GL_PIXEL_MODE_BIT);
  2045     glGetIntegerv(GL_UNPACK_ROW_LENGTH, &saved_row_length);
  2047     glPixelZoom(1.0, flip ? -1.0 : 1.0);
  2048     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  2049     glPixelStorei(GL_UNPACK_ROW_LENGTH, sprite->w);
  2050     glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
  2052     glDrawPixels(width, height, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data);
  2053     glPixelStorei(GL_UNPACK_ROW_LENGTH, saved_row_length);
  2056         glDisable(GL_ALPHA_TEST);
  2064 static void allegro_gl_screen_draw_color_glyph(
struct BITMAP *bmp,
  2065     struct BITMAP *sprite, 
int x, 
int y, 
int color, 
int bg) {
  2066     allegro_gl_screen_draw_color_glyph_ex(bmp, sprite, x, y, color, bg, 1);
  2071 static void allegro_gl_screen_draw_character(
struct BITMAP *bmp,
  2072                          struct BITMAP *sprite, 
int x, 
int y, 
int color, 
int bg)
  2074     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_draw_character\n");
  2075     allegro_gl_screen_draw_color_glyph(bmp, sprite, x, y, color, bg);
  2080 static void allegro_gl_screen_draw_256_sprite(
struct BITMAP *bmp,
  2081                                             struct BITMAP *sprite, 
int x, 
int y)
  2083     AGL_LOG(2, 
"glvtable.c:allegro_gl_screen_draw_256_sprite\n");
  2084     allegro_gl_screen_draw_color_glyph(bmp, sprite, x, y, -1, -1);
  2089 void allegro_gl_screen_clear_to_color(
struct BITMAP *bmp, 
int color)
  2091     if (__agl_drawing_pattern_tex || bmp->clip) {
  2092         allegro_gl_screen_rectfill(bmp, 0, 0, bmp->w, bmp->h, color);
  2098         split_color(color, &r, &g, &b, &a, bitmap_color_depth(bmp));
  2100         glGetFloatv(GL_COLOR_CLEAR_VALUE, old_col);
  2101         glClearColor(((
float) r / 255), ((
float) g / 255), ((
float) b / 255),
  2104         glClear(GL_COLOR_BUFFER_BIT);
  2105         glClearColor(old_col[0], old_col[1], old_col[2], old_col[3]);
  2114 static void allegro_gl_screen_polygon(
struct BITMAP *bmp, 
int vertices,
  2115                                       AL_CONST 
int *points, 
int color) {
  2119     split_color(color, &r, &g, &b, &a, bitmap_color_depth(bmp));
  2120     glColor4ub(r, g, b, a);
  2122     glPushAttrib(GL_SCISSOR_BIT);
  2125         glEnable(GL_SCISSOR_TEST);
  2126         glScissor(bmp->x_ofs + bmp->cl, bmp->h + bmp->y_ofs - bmp->cb,
  2127                   bmp->cr - bmp->cl, bmp->cb - bmp->ct);
  2130         glScissor(0, 0, bmp->w, bmp->h);
  2133     glBegin(GL_POLYGON);
  2134         for (i = 0; i < vertices*2-1; i+=2) {
  2135             SET_TEX_COORDS(points[i], points[i+1]);
  2136             if (is_sub_bitmap(bmp)) {
  2137                 glVertex2f(points[i] + bmp->x_ofs, points[i+1] + bmp->y_ofs);
  2140                 glVertex2f(points[i], points[i+1]);
  2150 static void allegro_gl_screen_rect(
struct BITMAP *bmp,
  2151                                    int x1, 
int y1, 
int x2, 
int y2, 
int color) {
  2154     split_color(color, &r, &g, &b, &a, bitmap_color_depth(bmp));
  2155     glColor4ub(r, g, b, a);
  2157     glPushAttrib(GL_SCISSOR_BIT);
  2160         glEnable(GL_SCISSOR_TEST);
  2161         glScissor(bmp->x_ofs + bmp->cl, bmp->h + bmp->y_ofs - bmp->cb,
  2162                   bmp->cr - bmp->cl, bmp->cb - bmp->ct);
  2165         glScissor(0, 0, bmp->w, bmp->h);
  2167     if (is_sub_bitmap(bmp)) {
  2174     glBegin(GL_LINE_STRIP);
  2187 void allegro_gl_screen_polygon3d_f(
struct BITMAP *bmp, 
int type,
  2188                                    struct BITMAP *texture, 
int vc,
  2193     if (type & POLYTYPE_ZBUF) {
  2195         type &= ~POLYTYPE_ZBUF;
  2198     if (type == POLYTYPE_PTEX || type == POLYTYPE_PTEX_TRANS)
  2202         glPushAttrib(GL_SCISSOR_BIT);
  2203         glEnable(GL_SCISSOR_TEST);
  2204         glScissor(bmp->x_ofs + bmp->cl, bmp->h + bmp->y_ofs - bmp->cb,
  2205                   bmp->cr - bmp->cl, bmp->cb - bmp->ct);
  2207     if (is_sub_bitmap(bmp)) {
  2208         for (i = 0; i < vc*2-1; i+=2) {
  2209             vtx[i] += bmp->x_ofs;
  2210             vtx[i+1] += bmp->y_ofs;
  2215         glEnable(GL_DEPTH_TEST);
  2216         glDepthFunc(GL_LESS);
  2217         glDepthMask(GL_TRUE);
  2220     glColor4ub(255, 255, 255, 255);
  2222     if (type == POLYTYPE_ATEX || type == POLYTYPE_PTEX
  2223      || type == POLYTYPE_ATEX_TRANS || type == POLYTYPE_PTEX_TRANS) {
  2224         drawing_mode(DRAW_MODE_COPY_PATTERN, texture, 0, 0);
  2227     if (type == POLYTYPE_ATEX_TRANS || type == POLYTYPE_PTEX_TRANS) {
  2231     glBegin(GL_POLYGON);
  2232         for (i = 0; i < vc; i++) {
  2233             if (type == POLYTYPE_FLAT)
  2234                 glColor3ub(getr(vtx[0]->c), getg(vtx[0]->c), getb(vtx[0]->c));
  2235             else if (type == POLYTYPE_GRGB)
  2236                 glColor3ub(getr24(vtx[i]->c), getg24(vtx[i]->c), getb24(vtx[i]->c));
  2237             else if (type == POLYTYPE_GCOL)
  2238                 glColor3ub(getr(vtx[i]->c), getg(vtx[i]->c), getb(vtx[i]->c));
  2239             else if (type == POLYTYPE_ATEX || type == POLYTYPE_PTEX
  2240                   || type == POLYTYPE_ATEX_TRANS || type == POLYTYPE_PTEX_TRANS) {
  2241                     SET_TEX_COORDS(vtx[i]->u, vtx[i]->v);
  2245                 glVertex3f(vtx[i]->x, vtx[i]->y, 1.f / vtx[i]->z);
  2247                 glVertex2f(vtx[i]->x, vtx[i]->y);
  2255         glDisable(GL_DEPTH_TEST);
  2256         glDepthMask(GL_FALSE);
  2259     if (type == POLYTYPE_ATEX || type == POLYTYPE_PTEX
  2260      || type == POLYTYPE_ATEX_TRANS || type == POLYTYPE_PTEX_TRANS) {
  2264     if (type == POLYTYPE_ATEX_TRANS || type == POLYTYPE_PTEX_TRANS)
  2265         glDisable(GL_BLEND);
  2270 static void allegro_gl_screen_polygon3d(
struct BITMAP *bmp, 
int type,
  2271                                         struct BITMAP *texture, 
int vc,
  2274     V3D_f **vtx_f = malloc(vc * 
sizeof(
struct V3D_f*));
  2278     for (i = 0; i < vc; i++) {
  2279         vtx_f[i] = malloc(
sizeof(
struct V3D_f));
  2282             for (k = 0; k < i; k++)
  2287         vtx_f[i]->c = vtx[i]->c;
  2288         vtx_f[i]->u = fixtof(vtx[i]->u);
  2289         vtx_f[i]->v = fixtof(vtx[i]->v);
  2290         vtx_f[i]->x = fixtof(vtx[i]->x);
  2291         vtx_f[i]->y = fixtof(vtx[i]->y);
  2292         vtx_f[i]->z = fixtof(vtx[i]->z);
  2295     allegro_gl_screen_polygon3d_f(bmp, type, texture, vc, vtx_f);
  2296     for (i = 0; i < vc; i++)
  2302 static void allegro_gl_screen_quad3d_f(
struct BITMAP *bmp, 
int type,
  2303                                        struct BITMAP *texture,
  2304                                        V3D_f *v1, V3D_f *v2, V3D_f *v3, V3D_f *v4) {
  2312     allegro_gl_screen_polygon3d_f(bmp, type, texture, 4, vtx_f);
  2317 static void allegro_gl_screen_quad3d(
struct BITMAP *bmp, 
int type,
  2318             struct BITMAP *texture, V3D *v1, V3D *v2, V3D *v3, V3D *v4) {
  2326     allegro_gl_screen_polygon3d(bmp, type, texture, 4, vtx);
  2331 static void allegro_gl_screen_triangle3d(
struct BITMAP *bmp, 
int type,
  2332                                          struct BITMAP *texture,
  2333                                          V3D *v1, V3D *v2, V3D *v3) {
  2339     allegro_gl_screen_polygon3d(bmp, type, texture, 3, vtx);
  2344 static void allegro_gl_screen_triangle3d_f(
struct BITMAP *bmp, 
int type,
  2345                                            struct BITMAP *texture,
  2346                                            V3D_f *v1, V3D_f *v2, V3D_f *v3) {
  2352     allegro_gl_screen_polygon3d_f(bmp, type, texture, 3, vtx_f);
  2357 void __allegro_gl__glvtable_update_vtable(GFX_VTABLE ** vtable)
  2359     int maskcolor = (*vtable)->mask_color;
  2360     int depth = (*vtable)->color_depth;
  2362     AGL_LOG(2, 
"glvtable.c:__allegro_gl__glvtable_update_vtable\n");
  2363     allegro_gl_screen_vtable.color_depth = depth;
  2368     allegro_gl_screen_vtable.mask_color =
  2369         makecol_depth(depth, getr(maskcolor), getg(maskcolor), getb(maskcolor));
  2371     *vtable = &allegro_gl_screen_vtable;
  2373     __allegro_gl_driver->screen_masked_blit = screen_masked_blit_standard;
  2375         __allegro_gl_driver->screen_masked_blit
  2376                                                = screen_masked_blit_nv_register;
  2378     else if (allegro_gl_info.num_texture_units >= 3) {
  2379         __allegro_gl_driver->screen_masked_blit =
  2380                                                  screen_masked_blit_combine_tex;
  2387 static double allegro_gl_projection_matrix[16];
  2388 static double allegro_gl_modelview_matrix[16];
  2424     AGL_LOG(2, 
"glvtable.c:allegro_gl_set_allegro_mode\n");
  2427     glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_TRANSFORM_BIT
  2428                | GL_POINT_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  2429     glDisable(GL_DEPTH_TEST);
  2430     glDisable(GL_CULL_FACE);
  2432     glDisable(GL_LIGHTING);
  2433     glDisable(GL_BLEND);
  2434     glDisable(GL_ALPHA_TEST);
  2435     glDepthMask(GL_FALSE);
  2436     glEnable(GL_TEXTURE_2D);
  2437     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  2441     if (!__allegro_gl_pool_texture) {
  2442         glGenTextures(1, &__allegro_gl_pool_texture);
  2445     glBindTexture(GL_TEXTURE_2D, __allegro_gl_pool_texture);
  2447     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0,
  2448                  GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  2449     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  2450     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  2452     glBindTexture(GL_TEXTURE_2D, 0);
  2458     if (allegro_gl_info.is_ati_rage_pro) {
  2459         if (!__allegro_gl_dummy_texture) {
  2460             GLubyte tex[4] = {255, 255, 255, 255};
  2461             glGenTextures(1, &__allegro_gl_dummy_texture);
  2462             glBindTexture(GL_TEXTURE_2D, __allegro_gl_dummy_texture);
  2463             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0,
  2464                          GL_RGBA, GL_UNSIGNED_BYTE, tex);
  2466         glBindTexture(GL_TEXTURE_2D, __allegro_gl_dummy_texture);
  2468 #ifdef ALLEGRO_MACOSX  2493     AGL_LOG(2, 
"glvtable.c:allegro_gl_unset_allegro_mode\n");
  2495     switch(allegro_gl_display_info.vidmem_policy) {
  2499             if (__allegro_gl_pool_texture) {
  2500                 glDeleteTextures(1, &__allegro_gl_pool_texture);
  2501                 __allegro_gl_pool_texture = 0;
  2543     AGL_LOG(2, 
"glvtable.c:allegro_gl_set_projection\n");
  2546     glGetIntegerv(GL_VIEWPORT, &v[0]);
  2547     glMatrixMode(GL_MODELVIEW);
  2548     glGetDoublev(GL_MODELVIEW_MATRIX, allegro_gl_modelview_matrix);
  2550     glMatrixMode(GL_PROJECTION);
  2551     glGetDoublev(GL_PROJECTION_MATRIX, allegro_gl_projection_matrix);
  2553     gluOrtho2D(v[0] - 0.325, v[0] + v[2] - 0.325, v[1] + v[3] - 0.325, v[1] - 0.325);
  2569     AGL_LOG(2, 
"glvtable.c:allegro_gl_unset_projection\n");
  2570     glMatrixMode(GL_PROJECTION);
  2571     glLoadMatrixd(allegro_gl_projection_matrix);
  2572     glMatrixMode(GL_MODELVIEW);
  2573     glLoadMatrixd(allegro_gl_modelview_matrix);
  2578 void allegro_gl_memory_blit_between_formats(
struct BITMAP *src,
  2579     struct BITMAP *dest, 
int source_x, 
int source_y, 
int dest_x, 
int dest_y,
  2580     int width, 
int height)
  2582     AGL_LOG(2, 
"AGL::blit_between_formats\n");
  2585     if (is_screen_bitmap(src)) {
  2586         allegro_gl_screen_blit_to_memory(src, dest, source_x, source_y,
  2587                                          dest_x, dest_y, width, height);
  2592     if (is_video_bitmap(src)) {
  2593         allegro_gl_video_blit_to_memory(src, dest, source_x, source_y,
  2594                                         dest_x, dest_y, width, height);
  2599     if (is_screen_bitmap(dest)) {
  2600         allegro_gl_screen_blit_from_memory(src, dest, source_x, source_y,
  2601                                            dest_x, dest_y, width, height);
  2606     if (is_video_bitmap(dest)) {
  2607         allegro_gl_video_blit_from_memory(src, dest, source_x, source_y,
  2608                                           dest_x, dest_y, width, height);
  2612     switch(bitmap_color_depth(dest)) {
  2613         #ifdef ALLEGRO_COLOR8  2615             __blit_between_formats8(src, dest, source_x, source_y,
  2616                                     dest_x, dest_y, width, height);
  2619         #ifdef ALLEGRO_COLOR16  2621             __blit_between_formats15(src, dest, source_x, source_y,
  2622                                      dest_x, dest_y, width, height);
  2625             __blit_between_formats16(src, dest, source_x, source_y,
  2626                                      dest_x, dest_y, width, height);
  2629         #ifdef ALLEGRO_COLOR24  2631             __blit_between_formats24(src, dest, source_x, source_y,
  2632                                      dest_x, dest_y, width, height);
  2635         #ifdef ALLEGRO_COLOR32  2637             __blit_between_formats32(src, dest, source_x, source_y,
  2638                                      dest_x, dest_y, width, height);
  2642             TRACE(
"--== ERROR ==-- AGL::blit_between_formats : %i -> %i bpp\n",
  2643                   bitmap_color_depth(src), bitmap_color_depth(dest));
  2650 static void dummy_unwrite_bank(
void)
  2656 static GFX_VTABLE allegro_gl_screen_vtable = {
  2665     allegro_gl_screen_getpixel,
  2666     allegro_gl_screen_putpixel,
  2667     allegro_gl_screen_vline,
  2668     allegro_gl_screen_hline,
  2669     allegro_gl_screen_hline,
  2670     allegro_gl_screen_line,
  2671     allegro_gl_screen_line,
  2672     allegro_gl_screen_rectfill,
  2673     allegro_gl_screen_triangle,
  2674     allegro_gl_screen_draw_sprite,
  2675     allegro_gl_screen_draw_256_sprite,
  2676     allegro_gl_screen_draw_sprite_v_flip,
  2677     allegro_gl_screen_draw_sprite_h_flip,
  2678     allegro_gl_screen_draw_sprite_vh_flip,
  2679     allegro_gl_screen_draw_trans_rgba_sprite,
  2680     allegro_gl_screen_draw_trans_rgba_sprite,
  2682     allegro_gl_screen_draw_rle_sprite,
  2683     allegro_gl_screen_draw_trans_rgba_rle_sprite,
  2684     allegro_gl_screen_draw_trans_rgba_rle_sprite,
  2686     allegro_gl_screen_draw_character,
  2687     allegro_gl_screen_draw_glyph,
  2688     allegro_gl_screen_blit_from_memory,
  2689     allegro_gl_screen_blit_to_memory,
  2692     allegro_gl_screen_blit_to_self,
  2693     allegro_gl_screen_blit_to_self, 
  2694     allegro_gl_screen_blit_to_self, 
  2695     allegro_gl_memory_blit_between_formats,
  2696     allegro_gl_screen_masked_blit,
  2697     allegro_gl_screen_clear_to_color,
  2698     allegro_gl_screen_pivot_scaled_sprite_flip,
  2703     allegro_gl_screen_polygon,
  2704     allegro_gl_screen_rect,
  2712     allegro_gl_screen_polygon3d,
  2713     allegro_gl_screen_polygon3d_f,
  2714     allegro_gl_screen_triangle3d,
  2715     allegro_gl_screen_triangle3d_f,
  2716     allegro_gl_screen_quad3d,
  2717     allegro_gl_screen_quad3d_f,
  2718     allegro_gl_screen_draw_sprite_ex
 #define AGL_KEEP
Keep internal texture in video memory. 
void allegro_gl_unset_projection(void)
Restores previously saved projection. 
#define AGL_TEXTURE_MASKED
Generate an alpha channel for this texture, based on the Allegro mask color. 
void allegro_gl_unset_allegro_mode(void)
Restores previous OpenGL settings. 
static void allegro_gl_screen_acquire(struct BITMAP *bmp)
acquire_bitmap(screen) overload. 
void allegro_gl_set_projection(void)
Prepares for Allegro drawing to the screen. 
struct AGL_EXTENSION_LIST_GL allegro_gl_extensions_GL
List of OpenGL extensions supported by AllegroGL. 
Main header file for AllegroGL. 
void allegro_gl_set_allegro_mode(void)
Prepares for Allegro drawing to the screen. 
GLuint allegro_gl_make_texture(BITMAP *bmp)
Uploads an Allegro BITMAP to the GL driver as a texture. 
#define AGL_TEXTURE_HAS_ALPHA
Tell AllegroGL that the bitmap had an alpha channel, so it should be preserved when generating the te...
#define AGL_RELEASE
Release video memory occupied by internal texture. 
static void allegro_gl_screen_release(struct BITMAP *bmp)
release_bitmap(screen) overload.