[PATCH] primitives: Replace set_blender call by _al_d3d_set_blender.

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


The set_blender function did not update the cached blender state, so the
cached state would no longer match the true state.
This fixes http://www.allegro.cc/forums/thread/605937/898164#target
---
 addons/primitives/prim_directx.c             |   70 ++------------------------
 include/allegro5/internal/aintern_direct3d.h |   20 +++++++
 src/win/d3d.h                                |    2 +-
 3 files changed, 25 insertions(+), 67 deletions(-)
 create mode 100644 include/allegro5/internal/aintern_direct3d.h

diff --git a/addons/primitives/prim_directx.c b/addons/primitives/prim_directx.c
index 1754c93..8ea268b 100644
--- a/addons/primitives/prim_directx.c
+++ b/addons/primitives/prim_directx.c
@@ -29,6 +29,7 @@
 #ifdef ALLEGRO_CFG_D3D
 
 #include "allegro5/allegro_direct3d.h"
+#include "allegro5/internal/aintern_direct3d.h"
 
 static ALLEGRO_MUTEX *d3d_mutex;
 /*
@@ -191,70 +192,6 @@ void _al_shutdown_d3d_driver(void)
 
 #ifdef ALLEGRO_CFG_D3D
 
-static int al_blender_to_d3d(int al_mode)
-{
-   int num_modes = 4;
-
-   int allegro_modes[] = {
-      ALLEGRO_ZERO,
-      ALLEGRO_ONE,
-      ALLEGRO_ALPHA,
-      ALLEGRO_INVERSE_ALPHA
-   };
-
-   int d3d_modes[] = {
-      D3DBLEND_ZERO,
-      D3DBLEND_ONE,
-      D3DBLEND_SRCALPHA,
-      D3DBLEND_INVSRCALPHA
-   };
-
-   int i;
-
-   for (i = 0; i < num_modes; i++) {
-      if (al_mode == allegro_modes[i]) {
-         return d3d_modes[i];
-      }
-   }
-
-   return D3DBLEND_ONE;
-}
-
-static void set_blender(LPDIRECT3DDEVICE9 device)
-{
-   int op, src, dst, alpha_op, alpha_src, alpha_dst;
-   DWORD d3d_op, d3d_alpha_op;
-   DWORD allegro_to_d3d_blendop[ALLEGRO_NUM_BLEND_OPERATIONS] = {
-      D3DBLENDOP_ADD,
-      D3DBLENDOP_SUBTRACT,
-      D3DBLENDOP_REVSUBTRACT
-   };
-
-   al_get_separate_blender(&op, &src, &dst, &alpha_op, &alpha_src, &alpha_dst);
-
-   src = al_blender_to_d3d(src);
-   dst = al_blender_to_d3d(dst);
-   alpha_src = al_blender_to_d3d(alpha_src);
-   alpha_dst = al_blender_to_d3d(alpha_dst);
-   d3d_op = allegro_to_d3d_blendop[op];
-   d3d_alpha_op = allegro_to_d3d_blendop[alpha_op];
-
-   /* These may not be supported but they will always fall back to ADD
-    * in that case.
-    */
-   IDirect3DDevice9_SetRenderState(device, D3DRS_BLENDOP, d3d_op);
-   IDirect3DDevice9_SetRenderState(device, D3DRS_BLENDOPALPHA, d3d_alpha_op);
-
-   IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLEND, src);
-   IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLEND, dst);
-
-   IDirect3DDevice9_SetRenderState(device, D3DRS_SEPARATEALPHABLENDENABLE, true);
-   IDirect3DDevice9_SetRenderState(device, D3DRS_SRCBLENDALPHA, alpha_src);
-   IDirect3DDevice9_SetRenderState(device, D3DRS_DESTBLENDALPHA, alpha_dst);
-
-   IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
-}
-
 static void* convert_to_legacy_vertices(const void* vtxs, int num_vertices, const int* indices, bool loop)
 {
    const ALLEGRO_VERTEX* vtx = vtxs;
@@ -352,8 +289,9 @@ static int _al_draw_prim_raw(ALLEGRO_BITMAP* target, ALLEGRO_BITMAP* texture,
          return _al_draw_prim_indexed_soft(texture, vtx, decl, indices, num_vtx, type);
    }
 
-   if(!old_pix_shader)
-      set_blender(device);
+   if(!old_pix_shader) {
+      _al_d3d_set_blender((struct ALLEGRO_DISPLAY_D3D *)target->display);
+   }
       
    if(!old_vtx_shader) {
       /* Prepare the default shader */
diff --git a/include/allegro5/internal/aintern_direct3d.h b/include/allegro5/internal/aintern_direct3d.h
new file mode 100644
index 0000000..1f48cf1
--- /dev/null
+++ b/include/allegro5/internal/aintern_direct3d.h
@@ -0,0 +1,20 @@
+#ifndef __al_included_allegro5_aintern_direct3d_h
+#define __al_included_allegro5_aintern_direct3d_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+struct ALLEGRO_DISPLAY_D3D;
+
+AL_FUNC(void, _al_d3d_set_blender, (struct ALLEGRO_DISPLAY_D3D *disp));
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/* vim: set sts=3 sw=3 et: */
diff --git a/src/win/d3d.h b/src/win/d3d.h
index 2eaff89..282b8d0 100644
--- a/src/win/d3d.h
+++ b/src/win/d3d.h
@@ -2,6 +2,7 @@
 #include "allegro5/internal/aintern_system.h"
 #include "allegro5/internal/aintern_display.h"
 #include "allegro5/internal/aintern_bitmap.h"
+#include "allegro5/internal/aintern_direct3d.h"
 #include "allegro5/platform/aintwin.h"
 
 #include <windows.h>
@@ -124,7 +125,6 @@ AL_FUNC(ALLEGRO_BITMAP *, _al_d3d_create_bitmap,
 //void _al_d3d_unlock_device();
 int _al_format_to_d3d(int format);
 int _al_d3d_format_to_allegro(int d3d_fmt);
-void _al_d3d_set_blender(ALLEGRO_DISPLAY_D3D *disp);
 bool _al_d3d_render_to_texture_supported(void);
 void _al_d3d_set_bitmap_clip(ALLEGRO_BITMAP *bitmap);
 
-- 
1.7.3.2


--/NkBOFFp2J2Af1nK--




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/