summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/d3d/D3DCAPS.CPP
blob: cd95ef0f1eecb55f3c7ee6ecad2d2010d9b4682e (plain)
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
/*===========================================================================*/
/*                                                                           */
/* Mesa-3.0 DirectX 6 Driver                                       Build 5   */
/*                                                                           */
/* By Leigh McRae                                                            */
/*                                                                           */
/* http://www.altsoftware.com/                                               */
/*                                                                           */
/* Copyright (c) 1999-1998  alt.software inc.  All Rights Reserved           */
/*===========================================================================*/
#include "D3DHAL.h"
/*===========================================================================*/
/* Macros.                                                                   */
/*===========================================================================*/
#define SRCBLEND_MAP(gl,d3d,fall)	if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwSrcBlendCaps & d3d ) \
                                   { \
					            sprintf( buffer, "SRC Blend: %s -> %s", # gl, # d3d ); \
                                     DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \
                                     pShared->dwSrcBlendCaps[index] = d3d; \
						     } \
							else \
                                   { \
					            sprintf( buffer, "SRC Blend: %s -> %s", # gl, # fall ); \
                                     DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \
                                     pShared->dwSrcBlendCaps[index] = fall; \
							}
#define DSTBLEND_MAP(gl,d3d,fall)	if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwDestBlendCaps & d3d ) \
                                   { \
					            sprintf( buffer, "DST Blend: %s -> %s", # gl, # d3d ); \
                                     DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \
                                     pShared->dwDestBlendCaps[index] = d3d; \
						     } \
							else \
                                   { \
					            sprintf( buffer, "DST Blend: %s -> %s", # gl, # fall ); \
                                     DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), buffer )); \
                                     pShared->dwDestBlendCaps[index] = fall; \
							}

/*===========================================================================*/
/*  I use this function to handle the fact that the D3D texture blending and */
/* OpenGL texture blending functions don't map one to one.  Also there is the*/
/* problem with cards not supporting all the D3D functions. So I use the CAPS*/
/* of the card to make a table of functions that will have defaults for the  */
/* unsupported functions.                                                    */
/*  So first I fill the table with the fallback function then I check to see */
/* if the card supports the requested function.  If it does I replace the    */
/* default thats already in the array.  Now order does matter as I used an   */
/* enum type in D3DShared.h so that the mapping would be a little easier.    */
/*===========================================================================*/
/* RETURN:                                                                   */
/*===========================================================================*/
void AlphaBlendTableHAL( PMESAD3DHAL pHAL )
{
  PMESAD3DSHARED	pShared = &pHAL->shared;
  int			index;
  char			buffer[128];

  DPF(( DBG_FUNC, "AlphaBlendTableHAL();" ));

  /* Make the fallback for the Source blend. */
  for( index = 0; index < 14; index++ )
  {
    switch( index )
    {
      case s_zero:
        SRCBLEND_MAP( GL_ZERO, D3DBLEND_ZERO, D3DBLEND_ONE );
	   break;
      case s_one:
        SRCBLEND_MAP( GL_ONE, D3DBLEND_ONE, D3DBLEND_ONE );
	   break;
      case s_dst_color:
        SRCBLEND_MAP( GL_DST_COLOR, D3DBLEND_DESTCOLOR, D3DBLEND_ONE );
	   break;
      case s_one_minus_dst_color:
        SRCBLEND_MAP( GL_ONE_MINUS_DST_COLOR, D3DBLEND_INVDESTCOLOR, D3DBLEND_ONE );
	   break;
      case s_src_alpha:
        SRCBLEND_MAP( GL_SRC_ALPHA, D3DBLEND_SRCALPHA, D3DBLEND_ONE );
	   break;
      case s_one_minus_src_alpha:
        SRCBLEND_MAP( GL_ONE_MINUS_SRC_ALPHA, D3DBLEND_INVSRCALPHA, D3DBLEND_ONE );
	   break;
      case s_dst_alpha:
        SRCBLEND_MAP( GL_DST_ALPHA, D3DBLEND_DESTALPHA, D3DBLEND_ONE );
	   break;
      case s_one_minus_dst_alpha:
        SRCBLEND_MAP( GL_ONE_MINUS_DST_ALPHA, D3DBLEND_INVDESTALPHA, D3DBLEND_ONE );
	   break;
      case s_src_alpha_saturate:
        SRCBLEND_MAP( GL_SRC_ALPHA_SATURATE, D3DBLEND_SRCALPHASAT, D3DBLEND_ONE );
	   break;
      case s_constant_color:
        SRCBLEND_MAP( GL_CONSTANT_COLOR, D3DBLEND_SRCCOLOR, D3DBLEND_ONE );
	   break;
      case s_one_minus_constant_color:
        SRCBLEND_MAP( GL_ONE_MINUS_CONSTANT_COLOR, D3DBLEND_INVSRCCOLOR, D3DBLEND_ONE );
	   break;
      case s_constant_alpha:
        SRCBLEND_MAP( GL_CONSTANT_ALPHA, D3DBLEND_BOTHSRCALPHA, D3DBLEND_ONE );
	   break;
      case s_one_minus_constant_alpha:
        SRCBLEND_MAP( GL_ONE_MINUS_CONSTANT_ALPHA, D3DBLEND_BOTHINVSRCALPHA, D3DBLEND_ONE );
	   break;
    }
  }

  /* Make the fallback for the Destination blend. */
  for( index = 0; index < 14; index++ )
  {
    switch( index )
    {
      case d_zero:
        DSTBLEND_MAP( GL_ZERO, D3DBLEND_ZERO, D3DBLEND_ONE );
	   break;
      case d_one:
        DSTBLEND_MAP( GL_ONE, D3DBLEND_ONE, D3DBLEND_ONE );
	   break;
      case d_src_color:
        DSTBLEND_MAP( GL_SRC_COLOR, D3DBLEND_SRCCOLOR, D3DBLEND_ONE );
	   break;
      case d_one_minus_src_color:
        DSTBLEND_MAP( GL_ONE_MINUS_SRC_COLOR, D3DBLEND_INVSRCCOLOR, D3DBLEND_ONE );
	   break;
      case d_src_alpha:
        DSTBLEND_MAP( GL_SRC_ALPHA, D3DBLEND_SRCALPHA, D3DBLEND_ONE );
	   break;
      case d_one_minus_src_alpha:
        DSTBLEND_MAP( GL_ONE_MINUS_SRC_ALPHA, D3DBLEND_INVSRCALPHA, D3DBLEND_ONE );
	   break;
      case d_dst_alpha:
        DSTBLEND_MAP( GL_DST_ALPHA, D3DBLEND_DESTALPHA, D3DBLEND_ONE );
	   break;
      case d_one_minus_dst_alpha:
        DSTBLEND_MAP( GL_ONE_MINUS_DST_ALPHA, D3DBLEND_INVDESTALPHA, D3DBLEND_ONE );
	   break;
      case d_constant_color:
        DSTBLEND_MAP( GL_CONSTANT_COLOR, D3DBLEND_DESTCOLOR, D3DBLEND_ONE );
	   break;
      case d_one_minus_constant_color:
        DSTBLEND_MAP( GL_ONE_MINUS_CONSTANT_COLOR, D3DBLEND_INVDESTCOLOR, D3DBLEND_ONE );
	   break;
      case d_constant_alpha:
        DSTBLEND_MAP( GL_CONSTANT_ALPHAR, D3DBLEND_BOTHSRCALPHA, D3DBLEND_ONE );
	   break;
      case d_one_minus_constant_alpha:
        DSTBLEND_MAP( GL_ONE_MINUS_CONSTANT_ALPHA, D3DBLEND_BOTHINVSRCALPHA, D3DBLEND_ONE );
	   break;
    }
  }

  /* Make the fallbacks for the texture functions. */
  for( index = 0; index < 4; index++ )
  {
    switch( index )
    {
      case d3dtblend_decal:
	   if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL )
	   {
		DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECAL -> D3DTBLEND_DECAL" )); 
		pShared->dwTexFunc[index] = D3DTBLEND_DECAL; 
	   }
        else
	   {
		if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATE )
		{
		  DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECAL -> D3DTBLEND_MODULATE" )); 
		  pShared->dwTexFunc[index] = D3DTBLEND_MODULATE; 
		}
		else
		{
		  DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECAL -> D3DTBLEND_ADD" )); 
		  pShared->dwTexFunc[index] = D3DTBLEND_ADD; 
		}
	   }
	   break;
      case d3dtblend_decalalpha:
	   if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECALALPHA )
	   {
		DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECALALPHA -> D3DTBLEND_DECALALPHA" )); 
		pShared->dwTexFunc[index] = D3DTBLEND_DECALALPHA; 
	   }
        else
	   {
		if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL )
		{
		  DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECALALPA -> D3DTBLEND_DECAL" )); 
		  pShared->dwTexFunc[index] = D3DTBLEND_DECAL; 
		}
		else
		{
		  DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_DECALALPHA -> D3DTBLEND_ADD" )); 
		  pShared->dwTexFunc[index] = D3DTBLEND_ADD; 
		}
	   }
	   break;
    case d3dtblend_modulate:
	   if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATE )
	   {
		DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_MODULATE" )); 
		pShared->dwTexFunc[index] = D3DTBLEND_MODULATE; 
	   }
        else
	   {
		if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATEALPHA )
		{
		  DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_MODULATEALPHA" )); 
		  pShared->dwTexFunc[index] = D3DTBLEND_MODULATEALPHA; 
		}
		else	if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL )
		{
		  DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_DECAL" )); 
		  pShared->dwTexFunc[index] = D3DTBLEND_DECAL; 
		}
		else
		{
		  DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATE -> D3DTBLEND_ADD" )); 
		  pShared->dwTexFunc[index] = D3DTBLEND_ADD; 
		}
	   }
	   break;
    case d3dtblend_modulatealpha:
	   if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATEALPHA )
	   {
		DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_MODULATEALPHA" )); 
		pShared->dwTexFunc[index] = D3DTBLEND_MODULATEALPHA; 
	   }
        else
	   {
		if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_MODULATE )
		{
		  DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_MODULATE" )); 
		  pShared->dwTexFunc[index] = D3DTBLEND_MODULATE;
		}
		else	if ( pHAL->D3DHWDevDesc.dpcTriCaps.dwTextureBlendCaps & D3DTBLEND_DECAL )
		{
		  DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_DECALE" )); 
		  pShared->dwTexFunc[index] = D3DTBLEND_DECAL; 
		}
		else
		{
		  DPF(( (DBG_CNTX_INFO|DBG_TXT_INFO), "D3DTBLEND_MODULATEALPHA -> D3DTBLEND_ADD" )); 
		  pShared->dwTexFunc[index] = D3DTBLEND_ADD; 
		}
	   }
	   break;
    }
  }
}