2 * Fixed function pipeline replacement using GL_ATI_fragment_shader
4 * Copyright 2008 Stefan Dösinger(for CodeWeavers)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wined3d_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader
);
30 /* Some private defines, Constant associations, etc.
31 * Env bump matrix and per stage constant should be independent,
32 * a stage that bump maps can't read the per state constant
34 #define ATI_FFP_CONST_BUMPMAT(i) (GL_CON_0_ATI + i)
35 #define ATI_FFP_CONST_CONSTANT0 GL_CON_0_ATI
36 #define ATI_FFP_CONST_CONSTANT1 GL_CON_1_ATI
37 #define ATI_FFP_CONST_CONSTANT2 GL_CON_2_ATI
38 #define ATI_FFP_CONST_CONSTANT3 GL_CON_3_ATI
39 #define ATI_FFP_CONST_CONSTANT4 GL_CON_4_ATI
40 #define ATI_FFP_CONST_CONSTANT5 GL_CON_5_ATI
41 #define ATI_FFP_CONST_TFACTOR GL_CON_6_ATI
43 /* GL_ATI_fragment_shader specific fixed function pipeline description. "Inherits" from the common one */
46 struct ffp_desc parent
;
48 unsigned int num_textures_used
;
51 struct atifs_private_data
53 struct shader_arb_priv parent
;
54 struct list fragment_shaders
; /* A linked list to track fragment pipeline replacement shaders */
58 static const char *debug_dstmod(GLuint mod
) {
60 case GL_NONE
: return "GL_NONE";
61 case GL_2X_BIT_ATI
: return "GL_2X_BIT_ATI";
62 case GL_4X_BIT_ATI
: return "GL_4X_BIT_ATI";
63 case GL_8X_BIT_ATI
: return "GL_8X_BIT_ATI";
64 case GL_HALF_BIT_ATI
: return "GL_HALF_BIT_ATI";
65 case GL_QUARTER_BIT_ATI
: return "GL_QUARTER_BIT_ATI";
66 case GL_EIGHTH_BIT_ATI
: return "GL_EIGHTH_BIT_ATI";
67 case GL_SATURATE_BIT_ATI
: return "GL_SATURATE_BIT_ATI";
68 default: return "Unexpected modifier\n";
72 static const char *debug_argmod(GLuint mod
) {
78 return "GL_2X_BIT_ATI";
80 return "GL_COMP_BIT_ATI";
81 case GL_NEGATE_BIT_ATI
:
82 return "GL_NEGATE_BIT_ATI";
84 return "GL_BIAS_BIT_ATI";
86 case GL_2X_BIT_ATI
| GL_COMP_BIT_ATI
:
87 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI";
88 case GL_2X_BIT_ATI
| GL_NEGATE_BIT_ATI
:
89 return "GL_2X_BIT_ATI | GL_NEGATE_BIT_ATI";
90 case GL_2X_BIT_ATI
| GL_BIAS_BIT_ATI
:
91 return "GL_2X_BIT_ATI | GL_BIAS_BIT_ATI";
92 case GL_COMP_BIT_ATI
| GL_NEGATE_BIT_ATI
:
93 return "GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI";
94 case GL_COMP_BIT_ATI
| GL_BIAS_BIT_ATI
:
95 return "GL_COMP_BIT_ATI | GL_BIAS_BIT_ATI";
96 case GL_NEGATE_BIT_ATI
| GL_BIAS_BIT_ATI
:
97 return "GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
99 case GL_COMP_BIT_ATI
| GL_NEGATE_BIT_ATI
| GL_BIAS_BIT_ATI
:
100 return "GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
101 case GL_2X_BIT_ATI
| GL_NEGATE_BIT_ATI
| GL_BIAS_BIT_ATI
:
102 return "GL_2X_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
103 case GL_2X_BIT_ATI
| GL_COMP_BIT_ATI
| GL_BIAS_BIT_ATI
:
104 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_BIAS_BIT_ATI";
105 case GL_2X_BIT_ATI
| GL_COMP_BIT_ATI
| GL_NEGATE_BIT_ATI
:
106 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI";
108 case GL_2X_BIT_ATI
| GL_COMP_BIT_ATI
| GL_NEGATE_BIT_ATI
| GL_BIAS_BIT_ATI
:
109 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
112 return "Unexpected argmod combination\n";
115 static const char *debug_register(GLuint reg
) {
117 case GL_REG_0_ATI
: return "GL_REG_0_ATI";
118 case GL_REG_1_ATI
: return "GL_REG_1_ATI";
119 case GL_REG_2_ATI
: return "GL_REG_2_ATI";
120 case GL_REG_3_ATI
: return "GL_REG_3_ATI";
121 case GL_REG_4_ATI
: return "GL_REG_4_ATI";
122 case GL_REG_5_ATI
: return "GL_REG_5_ATI";
124 case GL_CON_0_ATI
: return "GL_CON_0_ATI";
125 case GL_CON_1_ATI
: return "GL_CON_1_ATI";
126 case GL_CON_2_ATI
: return "GL_CON_2_ATI";
127 case GL_CON_3_ATI
: return "GL_CON_3_ATI";
128 case GL_CON_4_ATI
: return "GL_CON_4_ATI";
129 case GL_CON_5_ATI
: return "GL_CON_5_ATI";
130 case GL_CON_6_ATI
: return "GL_CON_6_ATI";
131 case GL_CON_7_ATI
: return "GL_CON_7_ATI";
133 case GL_ZERO
: return "GL_ZERO";
134 case GL_ONE
: return "GL_ONE";
135 case GL_PRIMARY_COLOR
: return "GL_PRIMARY_COLOR";
136 case GL_SECONDARY_INTERPOLATOR_ATI
: return "GL_SECONDARY_INTERPOLATOR_ATI";
138 default: return "Unknown register\n";
142 static const char *debug_swizzle(GLuint swizzle
) {
144 case GL_SWIZZLE_STR_ATI
: return "GL_SWIZZLE_STR_ATI";
145 case GL_SWIZZLE_STQ_ATI
: return "GL_SWIZZLE_STQ_ATI";
146 case GL_SWIZZLE_STR_DR_ATI
: return "GL_SWIZZLE_STR_DR_ATI";
147 case GL_SWIZZLE_STQ_DQ_ATI
: return "GL_SWIZZLE_STQ_DQ_ATI";
148 default: return "unknown swizzle";
152 #define GLINFO_LOCATION (*gl_info)
153 static GLuint
register_for_arg(DWORD arg
, WineD3D_GL_Info
*gl_info
, unsigned int stage
, GLuint
*mod
, GLuint tmparg
) {
156 if(mod
) *mod
= GL_NONE
;
157 if(arg
== 0xFFFFFFFF) return -1; /* This is the marker for unused registers */
159 switch(arg
& WINED3DTA_SELECTMASK
) {
160 case WINED3DTA_DIFFUSE
:
161 ret
= GL_PRIMARY_COLOR
;
164 case WINED3DTA_CURRENT
:
165 /* Note that using GL_REG_0_ATI for the passed on register is safe because
166 * texture0 is read at stage0, so in the worst case it is read in the
167 * instruction writing to reg0. Afterwards texture0 is not used any longer.
168 * If we're reading from current
171 ret
= GL_PRIMARY_COLOR
;
177 case WINED3DTA_TEXTURE
:
178 ret
= GL_REG_0_ATI
+ stage
;
181 case WINED3DTA_TFACTOR
:
182 ret
= ATI_FFP_CONST_TFACTOR
;
185 case WINED3DTA_SPECULAR
:
186 ret
= GL_SECONDARY_INTERPOLATOR_ATI
;
193 case WINED3DTA_CONSTANT
:
194 FIXME("Unhandled source argument WINED3DTA_TEMP\n");
199 FIXME("Unknown source argument %d\n", arg
);
203 if(arg
& WINED3DTA_COMPLEMENT
) {
204 if(mod
) *mod
|= GL_COMP_BIT_ATI
;
206 if(arg
& WINED3DTA_ALPHAREPLICATE
) {
207 FIXME("Unhandled read modifier WINED3DTA_ALPHAREPLICATE\n");
212 static GLuint
find_tmpreg(struct texture_stage_op op
[MAX_TEXTURES
]) {
213 int lowest_read
= -1;
214 int lowest_write
= -1;
216 BOOL tex_used
[MAX_TEXTURES
];
218 memset(tex_used
, 0, sizeof(tex_used
));
219 for(i
= 0; i
< MAX_TEXTURES
; i
++) {
220 if(op
[i
].cop
== WINED3DTOP_DISABLE
) {
224 if(lowest_read
== -1 &&
225 (op
[i
].carg1
== WINED3DTA_TEMP
|| op
[i
].carg2
== WINED3DTA_TEMP
|| op
[i
].carg0
== WINED3DTA_TEMP
||
226 op
[i
].aarg1
== WINED3DTA_TEMP
|| op
[i
].aarg2
== WINED3DTA_TEMP
|| op
[i
].aarg0
== WINED3DTA_TEMP
)) {
230 if(lowest_write
== -1 && op
[i
].dst
== WINED3DTA_TEMP
) {
234 if(op
[i
].carg1
== WINED3DTA_TEXTURE
|| op
[i
].carg2
== WINED3DTA_TEXTURE
|| op
[i
].carg0
== WINED3DTA_TEXTURE
||
235 op
[i
].aarg1
== WINED3DTA_TEXTURE
|| op
[i
].aarg2
== WINED3DTA_TEXTURE
|| op
[i
].aarg0
== WINED3DTA_TEXTURE
) {
240 /* Temp reg not read? We don't need it, return GL_NONE */
241 if(lowest_read
== -1) return GL_NONE
;
243 if(lowest_write
>= lowest_read
) {
244 FIXME("Temp register read before being written\n");
247 if(lowest_write
== -1) {
248 /* This needs a test. Maybe we are supposed to return 0.0/0.0/0.0/0.0, or fail drawprim, or whatever */
249 FIXME("Temp register read without being written\n");
251 } else if(lowest_write
>= 1) {
252 /* If we're writing to the temp reg at earliest in stage 1, we can use register 1 for the temp result.
253 * there may be texture data stored in reg 1, but we do not need it any longer since stage 1 already
258 /* Search for a free texture register. We have 6 registers available. GL_REG_0_ATI is already used
259 * for the regular result
261 for(i
= 1; i
< 6; i
++) {
263 return GL_REG_0_ATI
+ i
;
266 /* What to do here? Report it in ValidateDevice? */
267 FIXME("Could not find a register for the temporary register\n");
272 static GLuint
gen_ati_shader(struct texture_stage_op op
[MAX_TEXTURES
], WineD3D_GL_Info
*gl_info
) {
273 GLuint ret
= GL_EXTCALL(glGenFragmentShadersATI(1));
275 GLuint arg0
, arg1
, arg2
, extrarg
;
276 GLuint dstmod
, argmod0
, argmod1
, argmod2
, argmodextra
;
278 GLuint tmparg
= find_tmpreg(op
);
282 ERR("Failed to generate a GL_ATI_fragment_shader shader id\n");
285 GL_EXTCALL(glBindFragmentShaderATI(ret
));
286 checkGLcall("GL_EXTCALL(glBindFragmentShaderATI(ret))");
288 TRACE("glBeginFragmentShaderATI()\n");
289 GL_EXTCALL(glBeginFragmentShaderATI());
290 checkGLcall("GL_EXTCALL(glBeginFragmentShaderATI())");
292 /* Pass 1: Generate sampling instructions for perturbation maps */
293 for(stage
= 0; stage
< GL_LIMITS(textures
); stage
++) {
294 if(op
[stage
].cop
== WINED3DTOP_DISABLE
) break;
295 if(op
[stage
].cop
!= WINED3DTOP_BUMPENVMAP
&&
296 op
[stage
].cop
!= WINED3DTOP_BUMPENVMAPLUMINANCE
) continue;
298 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, GL_SWIZZLE_STR_ATI)\n",
300 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI
+ stage
,
301 GL_TEXTURE0_ARB
+ stage
,
302 GL_SWIZZLE_STR_ATI
));
303 TRACE("glPassTexCoordATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, GL_SWIZZLE_STR_ATI)\n",
304 stage
+ 1, stage
+ 1);
305 GL_EXTCALL(glPassTexCoordATI(GL_REG_0_ATI
+ stage
+ 1,
306 GL_TEXTURE0_ARB
+ stage
+ 1,
307 GL_SWIZZLE_STR_ATI
));
309 /* We need GL_REG_5_ATI as a temporary register to swizzle the bump matrix. So we run into
310 * issues if we're bump mapping on stage 4 or 5
313 FIXME("Bump mapping in stage %d\n", stage
);
317 /* Pass 2: Generate perturbation calculations */
318 for(stage
= 0; stage
< GL_LIMITS(textures
); stage
++) {
319 if(op
[stage
].cop
== WINED3DTOP_DISABLE
) break;
320 if(op
[stage
].cop
!= WINED3DTOP_BUMPENVMAP
&&
321 op
[stage
].cop
!= WINED3DTOP_BUMPENVMAPLUMINANCE
) continue;
323 /* Nice thing, we get the color correction for free :-) */
324 if(op
[stage
].color_correction
== WINED3DFMT_V8U8
) {
325 argmodextra
= GL_2X_BIT_ATI
| GL_BIAS_BIT_ATI
;
330 TRACE("glColorFragmentOp3ATI(GL_DOT2_ADD_ATI, GL_REG_%d_ATI, GL_RED_BIT_ATI, GL_NONE, GL_REG_%d_ATI, GL_NONE, %s, ATI_FFP_CONST_BUMPMAT(%d), GL_NONE, GL_NONE, GL_REG_%d_ATI, GL_RED, GL_NONE)\n",
331 stage
+ 1, stage
, debug_argmod(argmodextra
), stage
, stage
+ 1);
332 GL_EXTCALL(glColorFragmentOp3ATI(GL_DOT2_ADD_ATI
, GL_REG_0_ATI
+ stage
+ 1, GL_RED_BIT_ATI
, GL_NONE
,
333 GL_REG_0_ATI
+ stage
, GL_NONE
, argmodextra
,
334 ATI_FFP_CONST_BUMPMAT(stage
), GL_NONE
, GL_2X_BIT_ATI
| GL_BIAS_BIT_ATI
,
335 GL_REG_0_ATI
+ stage
+ 1, GL_RED
, GL_NONE
));
337 /* FIXME: How can I make GL_DOT2_ADD_ATI read the factors from blue and alpha? It defaults to red and green,
338 * and it is fairly easy to make it read GL_BLUE or BL_ALPHA, but I can't get an R * B + G * A. So we're wasting
339 * one register and two instructions in this pass for a simple swizzling operation.
340 * For starters it might be good enough to merge the two movs into one, but even that isn't possible :-(
342 * NOTE: GL_BLUE | GL_ALPHA is not possible. It doesn't throw a compilation error, but an OR operation on the
343 * constants doesn't make sense, considering their values.
345 TRACE("glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_5_ATI, GL_RED_BIT_ATI, GL_NONE, ATI_FFP_CONST_BUMPMAT(%d), GL_BLUE, GL_NONE)\n", stage
);
346 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI
, GL_REG_5_ATI
, GL_RED_BIT_ATI
, GL_NONE
,
347 ATI_FFP_CONST_BUMPMAT(stage
), GL_BLUE
, GL_NONE
));
348 TRACE("glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_5_ATI, GL_GREEN_BIT_ATI, GL_NONE, ATI_FFP_CONST_BUMPMAT(%d), GL_ALPHA, GL_NONE)\n", stage
);
349 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI
, GL_REG_5_ATI
, GL_GREEN_BIT_ATI
, GL_NONE
,
350 ATI_FFP_CONST_BUMPMAT(stage
), GL_ALPHA
, GL_NONE
));
351 TRACE("glColorFragmentOp3ATI(GL_DOT2_ADD_ATI, GL_REG_%d_ATI, GL_GREEN_BIT_ATI, GL_NONE, GL_REG_%d_ATI, GL_NONE, %s, GL_REG_5_ATI, GL_NONE, GL_NONE, GL_REG_%d_ATI, GL_GREEN, GL_NONE)\n",
352 stage
+ 1, stage
, debug_argmod(argmodextra
), stage
+ 1);
353 GL_EXTCALL(glColorFragmentOp3ATI(GL_DOT2_ADD_ATI
, GL_REG_0_ATI
+ stage
+ 1, GL_GREEN_BIT_ATI
, GL_NONE
,
354 GL_REG_0_ATI
+ stage
, GL_NONE
, argmodextra
,
355 GL_REG_5_ATI
, GL_NONE
, GL_2X_BIT_ATI
| GL_BIAS_BIT_ATI
,
356 GL_REG_0_ATI
+ stage
+ 1, GL_GREEN
, GL_NONE
));
359 /* Pass 3: Generate sampling instructions for regular textures */
360 for(stage
= 0; stage
< GL_LIMITS(textures
); stage
++) {
361 if(op
[stage
].cop
== WINED3DTOP_DISABLE
) {
365 if(op
[stage
].projected
== proj_none
) {
366 swizzle
= GL_SWIZZLE_STR_ATI
;
367 } else if(op
[stage
].projected
== proj_count3
) {
368 /* TODO: D3DTTFF_COUNT3 | D3DTTFF_PROJECTED would be GL_SWIZZLE_STR_DR_ATI.
369 * However, the FFP vertex processing texture transform matrix handler does
370 * some transformations in the texture matrix which makes the 3rd coordinate
371 * arrive in Q, not R in that case. This is needed for opengl fixed function
372 * fragment processing which always divides by Q. In this backend we can
373 * handle that properly and be compatible with vertex shader output and avoid
374 * side effects of the texture matrix games
376 swizzle
= GL_SWIZZLE_STQ_DQ_ATI
;
378 swizzle
= GL_SWIZZLE_STQ_DQ_ATI
;
381 if((op
[stage
].carg0
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
||
382 (op
[stage
].carg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
||
383 (op
[stage
].carg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
||
384 (op
[stage
].aarg0
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
||
385 (op
[stage
].aarg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
||
386 (op
[stage
].aarg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
||
387 op
[stage
].cop
== WINED3DTOP_BLENDTEXTUREALPHA
) {
390 (op
[stage
- 1].cop
== WINED3DTOP_BUMPENVMAP
||
391 op
[stage
- 1].cop
== WINED3DTOP_BUMPENVMAPLUMINANCE
)) {
392 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_REG_%d_ATI, GL_SWIZZLE_STR_ATI)\n",
394 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI
+ stage
,
395 GL_REG_0_ATI
+ stage
,
396 GL_SWIZZLE_STR_ATI
));
398 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, %s)\n",
399 stage
, stage
, debug_swizzle(swizzle
));
400 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI
+ stage
,
401 GL_TEXTURE0_ARB
+ stage
,
407 /* Pass 4: Generate the arithmetic instructions */
408 for(stage
= 0; stage
< MAX_TEXTURES
; stage
++) {
409 if(op
[stage
].cop
== WINED3DTOP_DISABLE
) {
411 /* Handle complete texture disabling gracefully */
412 TRACE("glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, GL_PRIMARY_COLOR, GL_NONE, GL_NONE)\n");
413 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI
, GL_REG_0_ATI
, GL_NONE
, GL_NONE
,
414 GL_PRIMARY_COLOR
, GL_NONE
, GL_NONE
));
415 TRACE("glAlphaFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_PRIMARY_COLOR, GL_NONE, GL_NONE)\n");
416 GL_EXTCALL(glAlphaFragmentOp1ATI(GL_MOV_ATI
, GL_REG_0_ATI
, GL_NONE
,
417 GL_PRIMARY_COLOR
, GL_NONE
, GL_NONE
));
422 if(op
[stage
].dst
== WINED3DTA_TEMP
) {
423 /* If we're writing to D3DTA_TEMP, but never reading from it we don't have to write there in the first place.
424 * skip the entire stage, this saves some GPU time
426 if(tmparg
== GL_NONE
) continue;
430 dstreg
= GL_REG_0_ATI
;
433 arg0
= register_for_arg(op
[stage
].carg0
, gl_info
, stage
, &argmod0
, tmparg
);
434 arg1
= register_for_arg(op
[stage
].carg1
, gl_info
, stage
, &argmod1
, tmparg
);
435 arg2
= register_for_arg(op
[stage
].carg2
, gl_info
, stage
, &argmod2
, tmparg
);
437 argmodextra
= GL_NONE
;
440 switch(op
[stage
].cop
) {
441 case WINED3DTOP_SELECTARG2
:
444 case WINED3DTOP_SELECTARG1
:
445 TRACE("glColorFragmentOp1ATI(GL_MOV_ATI, %s, GL_NONE, GL_NONE, %s, GL_NONE, %s)\n",
446 debug_register(dstreg
), debug_register(arg1
), debug_argmod(argmod1
));
447 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI
, dstreg
, GL_NONE
, GL_NONE
,
448 arg1
, GL_NONE
, argmod1
));
451 case WINED3DTOP_MODULATE4X
:
452 if(dstmod
== GL_NONE
) dstmod
= GL_4X_BIT_ATI
;
453 case WINED3DTOP_MODULATE2X
:
454 if(dstmod
== GL_NONE
) dstmod
= GL_2X_BIT_ATI
;
455 case WINED3DTOP_MODULATE
:
456 TRACE("glColorFragmentOp2ATI(GL_MUL_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
457 debug_register(dstreg
), debug_dstmod(dstmod
),
458 debug_register(arg1
), debug_argmod(argmod1
),
459 debug_register(arg2
), debug_argmod(argmod2
));
460 GL_EXTCALL(glColorFragmentOp2ATI(GL_MUL_ATI
, dstreg
, GL_NONE
, dstmod
,
461 arg1
, GL_NONE
, argmod1
,
462 arg2
, GL_NONE
, argmod2
));
465 case WINED3DTOP_ADDSIGNED2X
:
466 dstmod
= GL_2X_BIT_ATI
;
467 case WINED3DTOP_ADDSIGNED
:
468 argmodextra
= GL_BIAS_BIT_ATI
;
470 TRACE("glColorFragmentOp2ATI(GL_ADD_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
471 debug_register(dstreg
), debug_dstmod(dstmod
),
472 debug_register(arg1
), debug_argmod(argmod1
),
473 debug_register(arg2
), debug_argmod(argmodextra
| argmod2
));
474 GL_EXTCALL(glColorFragmentOp2ATI(GL_ADD_ATI
, GL_REG_0_ATI
, GL_NONE
, dstmod
,
475 arg1
, GL_NONE
, argmod1
,
476 arg2
, GL_NONE
, argmodextra
| argmod2
));
479 case WINED3DTOP_SUBTRACT
:
480 TRACE("glColorFragmentOp2ATI(GL_SUB_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
481 debug_register(dstreg
), debug_dstmod(dstmod
),
482 debug_register(arg1
), debug_argmod(argmod1
),
483 debug_register(arg2
), debug_argmod(argmod2
));
484 GL_EXTCALL(glColorFragmentOp2ATI(GL_SUB_ATI
, dstreg
, GL_NONE
, dstmod
,
485 arg1
, GL_NONE
, argmod1
,
486 arg2
, GL_NONE
, argmod2
));
489 case WINED3DTOP_ADDSMOOTH
:
490 argmodextra
= argmod1
& GL_COMP_BIT_ATI
? argmod1
& ~GL_COMP_BIT_ATI
: argmod1
| GL_COMP_BIT_ATI
;
491 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_NONE, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
492 debug_register(dstreg
),
493 debug_register(arg2
), debug_argmod(argmod2
),
494 debug_register(arg1
), debug_argmod(argmodextra
),
495 debug_register(arg1
), debug_argmod(argmod1
));
496 /* Dst = arg1 + * arg2(1 -arg 1)
497 * = arg2 * (1 - arg1) + arg1
499 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI
, dstreg
, GL_NONE
, GL_NONE
,
500 arg2
, GL_NONE
, argmod2
,
501 arg1
, GL_NONE
, argmodextra
,
502 arg1
, GL_NONE
, argmod1
));
505 case WINED3DTOP_BLENDCURRENTALPHA
:
506 if(extrarg
== GL_NONE
) extrarg
= register_for_arg(WINED3DTA_CURRENT
, gl_info
, stage
, NULL
, -1);
507 case WINED3DTOP_BLENDFACTORALPHA
:
508 if(extrarg
== GL_NONE
) extrarg
= register_for_arg(WINED3DTA_TFACTOR
, gl_info
, stage
, NULL
, -1);
509 case WINED3DTOP_BLENDTEXTUREALPHA
:
510 if(extrarg
== GL_NONE
) extrarg
= register_for_arg(WINED3DTA_TEXTURE
, gl_info
, stage
, NULL
, -1);
511 case WINED3DTOP_BLENDDIFFUSEALPHA
:
512 if(extrarg
== GL_NONE
) extrarg
= register_for_arg(WINED3DTA_DIFFUSE
, gl_info
, stage
, NULL
, -1);
513 TRACE("glColorFragmentOp3ATI(GL_LERP_ATI, %s, GL_NONE, GL_NONE, %s, GL_ALPHA, GL_NONE, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
514 debug_register(dstreg
),
515 debug_register(extrarg
),
516 debug_register(arg1
), debug_argmod(argmod1
),
517 debug_register(arg2
), debug_argmod(argmod2
));
518 GL_EXTCALL(glColorFragmentOp3ATI(GL_LERP_ATI
, dstreg
, GL_NONE
, GL_NONE
,
519 extrarg
, GL_ALPHA
, GL_NONE
,
520 arg1
, GL_NONE
, argmod1
,
521 arg2
, GL_NONE
, argmod2
));
524 case WINED3DTOP_BLENDTEXTUREALPHAPM
:
525 arg0
= register_for_arg(WINED3DTA_TEXTURE
, gl_info
, stage
, NULL
, -1);
526 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_NONE, %s, GL_NONE, %s, %s, GL_ALPHA, GL_COMP_BIT_ATI, %s, GL_NONE, %s)\n",
527 debug_register(dstreg
),
528 debug_register(arg2
), debug_argmod(argmod2
),
529 debug_register(arg0
),
530 debug_register(arg1
), debug_argmod(argmod1
));
531 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI
, dstreg
, GL_NONE
, GL_NONE
,
532 arg2
, GL_NONE
, argmod2
,
533 arg0
, GL_ALPHA
, GL_COMP_BIT_ATI
,
534 arg1
, GL_NONE
, argmod1
));
537 /* D3DTOP_PREMODULATE ???? */
539 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR
:
540 argmodextra
= argmod1
& GL_COMP_BIT_ATI
? argmod1
& ~GL_COMP_BIT_ATI
: argmod1
| GL_COMP_BIT_ATI
;
541 case WINED3DTOP_MODULATEALPHA_ADDCOLOR
:
542 if(!argmodextra
) argmodextra
= argmod1
;
543 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_NONE, %s, GL_NONE, %s, %s, GL_ALPHA, %s, %s, GL_NONE, %s)\n",
544 debug_register(dstreg
),
545 debug_register(arg2
), debug_argmod(argmod2
),
546 debug_register(arg1
), debug_argmod(argmodextra
), debug_register(arg1
), debug_argmod(arg1
));
547 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI
, dstreg
, GL_NONE
, GL_NONE
,
548 arg2
, GL_NONE
, argmod2
,
549 arg1
, GL_ALPHA
, argmodextra
,
550 arg1
, GL_NONE
, argmod1
));
553 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA
:
554 argmodextra
= argmod1
& GL_COMP_BIT_ATI
? argmod1
& ~GL_COMP_BIT_ATI
: argmod1
| GL_COMP_BIT_ATI
;
555 case WINED3DTOP_MODULATECOLOR_ADDALPHA
:
556 if(!argmodextra
) argmodextra
= argmod1
;
557 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_NONE, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_ALPHA, %s)\n",
558 debug_register(dstreg
),
559 debug_register(arg2
), debug_argmod(argmod2
),
560 debug_register(arg1
), debug_argmod(argmodextra
),
561 debug_register(arg1
), debug_argmod(argmod1
));
562 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI
, dstreg
, GL_NONE
, GL_NONE
,
563 arg2
, GL_NONE
, argmod2
,
564 arg1
, GL_NONE
, argmodextra
,
565 arg1
, GL_ALPHA
, argmod1
));
568 case WINED3DTOP_DOTPRODUCT3
:
569 TRACE("glColorFragmentOp2ATI(GL_DOT3_ATI, %s, GL_NONE, GL_4X_BIT_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
570 debug_register(dstreg
),
571 debug_register(arg1
), debug_argmod(argmod1
| GL_BIAS_BIT_ATI
),
572 debug_register(arg2
), debug_argmod(argmod2
| GL_BIAS_BIT_ATI
));
573 GL_EXTCALL(glColorFragmentOp2ATI(GL_DOT3_ATI
, dstreg
, GL_NONE
, GL_4X_BIT_ATI
,
574 arg1
, GL_NONE
, argmod1
| GL_BIAS_BIT_ATI
,
575 arg2
, GL_NONE
, argmod2
| GL_BIAS_BIT_ATI
));
578 case WINED3DTOP_MULTIPLYADD
:
579 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_NONE, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
580 debug_register(dstreg
),
581 debug_register(arg0
), debug_argmod(argmod0
),
582 debug_register(arg2
), debug_argmod(argmod2
),
583 debug_register(arg1
), debug_argmod(argmod1
));
584 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI
, dstreg
, GL_NONE
, GL_NONE
,
585 arg0
, GL_NONE
, argmod0
,
586 arg2
, GL_NONE
, argmod2
,
587 arg1
, GL_NONE
, argmod1
));
590 case WINED3DTOP_LERP
:
591 TRACE("glColorFragmentOp3ATI(GL_LERP_ATI, %s, GL_NONE, GL_NONE, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
592 debug_register(dstreg
),
593 debug_register(arg1
), debug_argmod(argmod1
),
594 debug_register(arg2
), debug_argmod(argmod2
),
595 debug_register(arg0
), debug_argmod(argmod0
));
596 GL_EXTCALL(glColorFragmentOp3ATI(GL_LERP_ATI
, dstreg
, GL_NONE
, GL_NONE
,
597 arg1
, GL_NONE
, argmod1
,
598 arg2
, GL_NONE
, argmod2
,
599 arg0
, GL_NONE
, argmod0
));
602 case WINED3DTOP_BUMPENVMAP
:
603 case WINED3DTOP_BUMPENVMAPLUMINANCE
:
604 /* Those are handled in the first pass of the shader(generation pass 1 and 2) already */
607 default: FIXME("Unhandled color operation %d on stage %d\n", op
[stage
].cop
, stage
);
610 arg0
= register_for_arg(op
[stage
].aarg0
, gl_info
, stage
, &argmod0
, tmparg
);
611 arg1
= register_for_arg(op
[stage
].aarg1
, gl_info
, stage
, &argmod1
, tmparg
);
612 arg2
= register_for_arg(op
[stage
].aarg2
, gl_info
, stage
, &argmod2
, tmparg
);
614 argmodextra
= GL_NONE
;
617 switch(op
[stage
].aop
) {
618 case WINED3DTOP_DISABLE
:
619 /* Get the primary color to the output if on stage 0, otherwise leave register 0 untouched */
621 TRACE("glAlphaFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_PRIMARY_COLOR, GL_NONE, GL_NONE)\n");
622 GL_EXTCALL(glAlphaFragmentOp1ATI(GL_MOV_ATI
, GL_REG_0_ATI
, GL_NONE
,
623 GL_PRIMARY_COLOR
, GL_NONE
, GL_NONE
));
627 case WINED3DTOP_SELECTARG2
:
630 case WINED3DTOP_SELECTARG1
:
631 TRACE("glAlphaFragmentOp1ATI(GL_MOV_ATI, %s, GL_NONE, %s, GL_NONE, %s)\n",
632 debug_register(dstreg
),
633 debug_register(arg1
), debug_argmod(argmod1
));
634 GL_EXTCALL(glAlphaFragmentOp1ATI(GL_MOV_ATI
, dstreg
, GL_NONE
,
635 arg1
, GL_NONE
, argmod1
));
638 case WINED3DTOP_MODULATE4X
:
639 if(dstmod
== GL_NONE
) dstmod
= GL_4X_BIT_ATI
;
640 case WINED3DTOP_MODULATE2X
:
641 if(dstmod
== GL_NONE
) dstmod
= GL_2X_BIT_ATI
;
642 case WINED3DTOP_MODULATE
:
643 TRACE("glAlphaFragmentOp2ATI(GL_MUL_ATI, %s, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
644 debug_register(dstreg
), debug_dstmod(dstmod
),
645 debug_register(arg1
), debug_argmod(argmod1
),
646 debug_register(arg2
), debug_argmod(argmod2
));
647 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_MUL_ATI
, dstreg
, dstmod
,
648 arg1
, GL_NONE
, argmod1
,
649 arg2
, GL_NONE
, argmod2
));
652 case WINED3DTOP_ADDSIGNED2X
:
653 dstmod
= GL_2X_BIT_ATI
;
654 case WINED3DTOP_ADDSIGNED
:
655 argmodextra
= GL_BIAS_BIT_ATI
;
657 TRACE("glAlphaFragmentOp2ATI(GL_ADD_ATI, %s, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
658 debug_register(dstreg
), debug_dstmod(dstmod
),
659 debug_register(arg1
), debug_argmod(argmod1
),
660 debug_register(arg2
), debug_argmod(argmodextra
| argmod2
));
661 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_ADD_ATI
, dstreg
, dstmod
,
662 arg1
, GL_NONE
, argmod1
,
663 arg2
, GL_NONE
, argmodextra
| argmod2
));
666 case WINED3DTOP_SUBTRACT
:
667 TRACE("glAlphaFragmentOp2ATI(GL_SUB_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
668 debug_register(dstreg
), debug_dstmod(dstmod
),
669 debug_register(arg1
), debug_argmod(argmod1
),
670 debug_register(arg2
), debug_argmod(argmod2
));
671 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_SUB_ATI
, dstreg
, dstmod
,
672 arg1
, GL_NONE
, argmod1
,
673 arg2
, GL_NONE
, argmod2
));
676 case WINED3DTOP_ADDSMOOTH
:
677 argmodextra
= argmod1
& GL_COMP_BIT_ATI
? argmod1
& ~GL_COMP_BIT_ATI
: argmod1
| GL_COMP_BIT_ATI
;
678 TRACE("glAlphaFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
679 debug_register(dstreg
),
680 debug_register(arg2
), debug_argmod(argmod2
),
681 debug_register(arg1
), debug_argmod(argmodextra
),
682 debug_register(arg1
), debug_argmod(argmod1
));
683 /* Dst = arg1 + * arg2(1 -arg 1)
684 * = arg2 * (1 - arg1) + arg1
686 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_MAD_ATI
, dstreg
, GL_NONE
,
687 arg2
, GL_NONE
, argmod2
,
688 arg1
, GL_NONE
, argmodextra
,
689 arg1
, GL_NONE
, argmod1
));
692 case WINED3DTOP_BLENDCURRENTALPHA
:
693 if(extrarg
== GL_NONE
) extrarg
= register_for_arg(WINED3DTA_CURRENT
, gl_info
, stage
, NULL
, -1);
694 case WINED3DTOP_BLENDFACTORALPHA
:
695 if(extrarg
== GL_NONE
) extrarg
= register_for_arg(WINED3DTA_TFACTOR
, gl_info
, stage
, NULL
, -1);
696 case WINED3DTOP_BLENDTEXTUREALPHA
:
697 if(extrarg
== GL_NONE
) extrarg
= register_for_arg(WINED3DTA_TEXTURE
, gl_info
, stage
, NULL
, -1);
698 case WINED3DTOP_BLENDDIFFUSEALPHA
:
699 if(extrarg
== GL_NONE
) extrarg
= register_for_arg(WINED3DTA_DIFFUSE
, gl_info
, stage
, NULL
, -1);
700 TRACE("glAlphaFragmentOp3ATI(GL_LERP_ATI, %s, GL_NONE, %s, GL_ALPHA, GL_NONE, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
701 debug_register(dstreg
),
702 debug_register(extrarg
),
703 debug_register(arg1
), debug_argmod(argmod1
),
704 debug_register(arg2
), debug_argmod(argmod2
));
705 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_LERP_ATI
, dstreg
, GL_NONE
,
706 extrarg
, GL_ALPHA
, GL_NONE
,
707 arg1
, GL_NONE
, argmod1
,
708 arg2
, GL_NONE
, argmod2
));
711 case WINED3DTOP_BLENDTEXTUREALPHAPM
:
712 arg0
= register_for_arg(WINED3DTA_TEXTURE
, gl_info
, stage
, NULL
, -1);
713 TRACE("glAlphaFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, %s, GL_NONE, %s, %s, GL_ALPHA, GL_COMP_BIT_ATI, %s, GL_NONE, %s)\n",
714 debug_register(dstreg
),
715 debug_register(arg2
), debug_argmod(argmod2
),
716 debug_register(arg0
),
717 debug_register(arg1
), debug_argmod(argmod1
));
718 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_MAD_ATI
, dstreg
, GL_NONE
,
719 arg2
, GL_NONE
, argmod2
,
720 arg0
, GL_ALPHA
, GL_COMP_BIT_ATI
,
721 arg1
, GL_NONE
, argmod1
));
724 /* D3DTOP_PREMODULATE ???? */
726 case WINED3DTOP_DOTPRODUCT3
:
727 TRACE("glAlphaFragmentOp2ATI(GL_DOT3_ATI, %s, GL_NONE, GL_4X_BIT_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
728 debug_register(dstreg
),
729 debug_register(arg1
), debug_argmod(argmod1
| GL_BIAS_BIT_ATI
),
730 debug_register(arg2
), debug_argmod(argmod2
| GL_BIAS_BIT_ATI
));
731 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_DOT3_ATI
, dstreg
, GL_4X_BIT_ATI
,
732 arg1
, GL_NONE
, argmod1
| GL_BIAS_BIT_ATI
,
733 arg2
, GL_NONE
, argmod2
| GL_BIAS_BIT_ATI
));
736 case WINED3DTOP_MULTIPLYADD
:
737 TRACE("glAlphaFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
738 debug_register(dstreg
),
739 debug_register(arg0
), debug_argmod(argmod0
),
740 debug_register(arg2
), debug_argmod(argmod2
),
741 debug_register(arg1
), debug_argmod(argmod1
));
742 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_MAD_ATI
, dstreg
, GL_NONE
,
743 arg0
, GL_NONE
, argmod0
,
744 arg2
, GL_NONE
, argmod2
,
745 arg1
, GL_NONE
, argmod1
));
748 case WINED3DTOP_LERP
:
749 TRACE("glAlphaFragmentOp3ATI(GL_LERP_ATI, %s, GL_NONE, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
750 debug_register(dstreg
),
751 debug_register(arg1
), debug_argmod(argmod1
),
752 debug_register(arg2
), debug_argmod(argmod2
),
753 debug_register(arg0
), debug_argmod(argmod0
));
754 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_LERP_ATI
, dstreg
, GL_NONE
,
755 arg1
, GL_NONE
, argmod1
,
756 arg2
, GL_NONE
, argmod2
,
757 arg0
, GL_NONE
, argmod0
));
760 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR
:
761 case WINED3DTOP_MODULATEALPHA_ADDCOLOR
:
762 case WINED3DTOP_MODULATECOLOR_ADDALPHA
:
763 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA
:
764 case WINED3DTOP_BUMPENVMAP
:
765 case WINED3DTOP_BUMPENVMAPLUMINANCE
:
766 ERR("Application uses an invalid alpha operation\n");
769 default: FIXME("Unhandled alpha operation %d on stage %d\n", op
[stage
].aop
, stage
);
773 TRACE("glEndFragmentShaderATI()\n");
774 GL_EXTCALL(glEndFragmentShaderATI());
775 checkGLcall("GL_EXTCALL(glEndFragmentShaderATI())");
778 #undef GLINFO_LOCATION
780 #define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
781 static void set_tex_op_atifs(DWORD state
, IWineD3DStateBlockImpl
*stateblock
, WineD3DContext
*context
) {
782 IWineD3DDeviceImpl
*This
= stateblock
->wineD3DDevice
;
783 struct atifs_ffp_desc
*desc
;
784 struct texture_stage_op op
[MAX_TEXTURES
];
785 struct atifs_private_data
*priv
= (struct atifs_private_data
*) This
->shader_priv
;
789 gen_ffp_op(stateblock
, op
);
790 desc
= (struct atifs_ffp_desc
*) find_ffp_shader(&priv
->fragment_shaders
, op
);
792 desc
= HeapAlloc(GetProcessHeap(), 0, sizeof(*desc
));
794 ERR("Out of memory\n");
797 desc
->num_textures_used
= 0;
798 for(i
= 0; i
< GL_LIMITS(texture_stages
); i
++) {
799 if(op
[i
].cop
== WINED3DTOP_DISABLE
) break;
800 desc
->num_textures_used
= i
;
803 memcpy(desc
->parent
.op
, op
, sizeof(op
));
804 desc
->shader
= gen_ati_shader(op
, &GLINFO_LOCATION
);
805 add_ffp_shader(&priv
->fragment_shaders
, &desc
->parent
);
806 TRACE("Allocated fixed function replacement shader descriptor %p\n", desc
);
809 /* GL_ATI_fragment_shader depends on the GL_TEXTURE_xD enable settings. Update the texture stages
810 * used by this shader
812 for(i
= 0; i
< desc
->num_textures_used
; i
++) {
813 mapped_stage
= This
->texUnitMap
[i
];
814 if(mapped_stage
!= -1) {
815 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB
+ mapped_stage
));
816 checkGLcall("glActiveTextureARB");
817 texture_activate_dimensions(i
, stateblock
, context
);
821 GL_EXTCALL(glBindFragmentShaderATI(desc
->shader
));
824 static void state_texfactor_atifs(DWORD state
, IWineD3DStateBlockImpl
*stateblock
, WineD3DContext
*context
) {
826 D3DCOLORTOGLFLOAT4(stateblock
->renderState
[WINED3DRS_TEXTUREFACTOR
], col
);
828 GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR
, col
));
829 checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col)");
832 static void set_bumpmat(DWORD state
, IWineD3DStateBlockImpl
*stateblock
, WineD3DContext
*context
) {
833 DWORD stage
= (state
- STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE
;
836 mat
[0][0] = *((float *) &stateblock
->textureState
[stage
][WINED3DTSS_BUMPENVMAT00
]);
837 mat
[1][0] = *((float *) &stateblock
->textureState
[stage
][WINED3DTSS_BUMPENVMAT01
]);
838 mat
[0][1] = *((float *) &stateblock
->textureState
[stage
][WINED3DTSS_BUMPENVMAT10
]);
839 mat
[1][1] = *((float *) &stateblock
->textureState
[stage
][WINED3DTSS_BUMPENVMAT11
]);
840 /* GL_ATI_fragment_shader allows only constants from 0.0 to 1.0, but the bumpmat
841 * constants can be in any range. While they should stay between [-1.0 and 1.0] because
842 * Shader Model 1.x pixel shaders are clamped to that range negative values are used occasionally,
843 * for example by our d3d9 test. So to get negative values scale -1;1 to 0;1 and undo that in the
844 * shader(it is free). This might potentially reduce precision. However, if the hardware does
845 * support proper floats it shouldn't, and if it doesn't we can't get anything better anyway
847 mat
[0][0] = (mat
[0][0] + 1.0) * 0.5;
848 mat
[1][0] = (mat
[1][0] + 1.0) * 0.5;
849 mat
[0][1] = (mat
[0][1] + 1.0) * 0.5;
850 mat
[1][1] = (mat
[1][1] + 1.0) * 0.5;
851 GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage
), (float *) mat
));
852 checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), mat)");
854 /* FIXME: This should go away
855 * This is currently needed because atifs borrows a pixel shader implementation
856 * from somewhere else, but consumes bump map matrix change events. The other pixel
857 * shader implementation may need notification about the change to update the texbem
858 * constants. Once ATIFS supports real shaders on its own, and GLSL/ARB have a replacement
859 * pipeline this call can go away
861 * FIXME2: Even considering this workaround calling FFPStateTable directly isn't nice
862 * as well. Better would be to call the model's table we inherit from, but currently
863 * it is always the FFP table, and as soon as this changes we can remove the call anyway
865 FFPStateTable
[state
].apply(state
, stateblock
, context
);
867 #undef GLINFO_LOCATION
869 /* our state table. Borrows lots of stuff from the base implementation */
870 struct StateEntry ATIFSStateTable
[STATE_HIGHEST
+ 1];
872 static void init_state_table() {
874 const DWORD rep
= STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP
);
875 memcpy(ATIFSStateTable
, arb_program_shader_backend
.StateTable
, sizeof(ATIFSStateTable
));
877 for(i
= 0; i
< MAX_TEXTURES
; i
++) {
878 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_COLOROP
)].apply
= set_tex_op_atifs
;
879 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_COLOROP
)].representative
= rep
;
880 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_COLORARG1
)].apply
= set_tex_op_atifs
;
881 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_COLORARG1
)].representative
= rep
;
882 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_COLORARG2
)].apply
= set_tex_op_atifs
;
883 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_COLORARG2
)].representative
= rep
;
884 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_COLORARG0
)].apply
= set_tex_op_atifs
;
885 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_COLORARG0
)].representative
= rep
;
887 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_ALPHAOP
)].apply
= set_tex_op_atifs
;
888 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_ALPHAOP
)].representative
= rep
;
889 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_ALPHAARG1
)].apply
= set_tex_op_atifs
;
890 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_ALPHAARG1
)].representative
= rep
;
891 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_ALPHAARG2
)].apply
= set_tex_op_atifs
;
892 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_ALPHAARG2
)].representative
= rep
;
893 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_ALPHAARG0
)].apply
= set_tex_op_atifs
;
894 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_ALPHAARG0
)].representative
= rep
;
896 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_RESULTARG
)].apply
= set_tex_op_atifs
;
897 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_RESULTARG
)].representative
= rep
;
899 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_BUMPENVMAT00
)].apply
= set_bumpmat
;
900 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_BUMPENVMAT01
)].apply
= set_bumpmat
;
901 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_BUMPENVMAT10
)].apply
= set_bumpmat
;
902 ATIFSStateTable
[STATE_TEXTURESTAGE(i
, WINED3DTSS_BUMPENVMAT11
)].apply
= set_bumpmat
;
905 ATIFSStateTable
[STATE_RENDER(WINED3DRS_TEXTUREFACTOR
)].apply
= state_texfactor_atifs
;
906 ATIFSStateTable
[STATE_RENDER(WINED3DRS_TEXTUREFACTOR
)].representative
= STATE_RENDER(WINED3DRS_TEXTUREFACTOR
);
909 /* GL_ATI_fragment_shader backend.It borrows a lot from a the
910 * ARB shader backend, currently the whole vertex processing
911 * code. This code would also forward pixel shaders, but if
912 * GL_ARB_fragment_program is supported, the atifs shader backend
915 static void shader_atifs_select(IWineD3DDevice
*iface
, BOOL usePS
, BOOL useVS
) {
916 arb_program_shader_backend
.shader_select(iface
, usePS
, useVS
);
919 static void shader_atifs_select_depth_blt(IWineD3DDevice
*iface
) {
920 arb_program_shader_backend
.shader_select_depth_blt(iface
);
923 static void shader_atifs_destroy_depth_blt(IWineD3DDevice
*iface
) {
924 arb_program_shader_backend
.shader_destroy_depth_blt(iface
);
927 static void shader_atifs_load_constants(IWineD3DDevice
*iface
, char usePS
, char useVS
) {
928 arb_program_shader_backend
.shader_load_constants(iface
, usePS
, useVS
);
931 static void shader_atifs_cleanup(IWineD3DDevice
*iface
) {
932 arb_program_shader_backend
.shader_cleanup(iface
);
935 static void shader_atifs_color_correction(SHADER_OPCODE_ARG
* arg
) {
936 arb_program_shader_backend
.shader_color_correction(arg
);
939 static void shader_atifs_destroy(IWineD3DBaseShader
*iface
) {
940 arb_program_shader_backend
.shader_destroy(iface
);
943 static HRESULT
shader_atifs_alloc(IWineD3DDevice
*iface
) {
944 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*) iface
;
946 struct atifs_private_data
*priv
;
947 hr
= arb_program_shader_backend
.shader_alloc_private(iface
);
948 if(FAILED(hr
)) return hr
;
950 This
->shader_priv
= HeapReAlloc(GetProcessHeap(), 0, This
->shader_priv
,
951 sizeof(struct atifs_private_data
));
952 priv
= (struct atifs_private_data
*) This
->shader_priv
;
953 list_init(&priv
->fragment_shaders
);
957 #define GLINFO_LOCATION This->adapter->gl_info
958 static void shader_atifs_free(IWineD3DDevice
*iface
) {
959 IWineD3DDeviceImpl
*This
= (IWineD3DDeviceImpl
*) iface
;
960 struct atifs_private_data
*priv
= (struct atifs_private_data
*) This
->shader_priv
;
961 struct ffp_desc
*entry
, *entry2
;
962 struct atifs_ffp_desc
*entry_ati
;
965 LIST_FOR_EACH_ENTRY_SAFE(entry
, entry2
, &priv
->fragment_shaders
, struct ffp_desc
, entry
) {
966 entry_ati
= (struct atifs_ffp_desc
*) entry
;
967 GL_EXTCALL(glDeleteFragmentShaderATI(entry_ati
->shader
));
968 checkGLcall("glDeleteFragmentShaderATI(entry->shader)");
969 list_remove(&entry
->entry
);
970 HeapFree(GetProcessHeap(), 0, entry
);
974 /* Not actually needed, but revert what we've done before */
975 This
->shader_priv
= HeapReAlloc(GetProcessHeap(), 0, This
->shader_priv
,
976 sizeof(struct shader_arb_priv
));
977 arb_program_shader_backend
.shader_free_private(iface
);
979 #undef GLINFO_LOCATION
981 static BOOL
shader_atifs_dirty_const(IWineD3DDevice
*iface
) {
982 return arb_program_shader_backend
.shader_dirtifyable_constants(iface
);
985 static void shader_atifs_load_init(void) {
986 arb_program_shader_backend
.shader_dll_load_init();
990 static void shader_atifs_get_caps(WINED3DDEVTYPE devtype
, WineD3D_GL_Info
*gl_info
, struct shader_caps
*caps
) {
991 arb_program_shader_backend
.shader_get_caps(devtype
, gl_info
, caps
);
993 caps
->TextureOpCaps
= WINED3DTEXOPCAPS_DISABLE
|
994 WINED3DTEXOPCAPS_SELECTARG1
|
995 WINED3DTEXOPCAPS_SELECTARG2
|
996 WINED3DTEXOPCAPS_MODULATE4X
|
997 WINED3DTEXOPCAPS_MODULATE2X
|
998 WINED3DTEXOPCAPS_MODULATE
|
999 WINED3DTEXOPCAPS_ADDSIGNED2X
|
1000 WINED3DTEXOPCAPS_ADDSIGNED
|
1001 WINED3DTEXOPCAPS_ADD
|
1002 WINED3DTEXOPCAPS_SUBTRACT
|
1003 WINED3DTEXOPCAPS_ADDSMOOTH
|
1004 WINED3DTEXOPCAPS_BLENDCURRENTALPHA
|
1005 WINED3DTEXOPCAPS_BLENDFACTORALPHA
|
1006 WINED3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1007 WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA
|
1008 WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM
|
1009 WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
|
1010 WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1011 WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
|
1012 WINED3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
|
1013 WINED3DTEXOPCAPS_DOTPRODUCT3
|
1014 WINED3DTEXOPCAPS_MULTIPLYADD
|
1015 WINED3DTEXOPCAPS_LERP
|
1016 WINED3DTEXOPCAPS_BUMPENVMAP
;
1018 /* TODO: Implement WINED3DTEXOPCAPS_BUMPENVMAPLUMINANCE
1019 and WINED3DTEXOPCAPS_PREMODULATE */
1021 /* GL_ATI_fragment_shader only supports up to 6 textures, which was the limit on r200 cards
1022 * which this extension is exclusively focused on(later cards have GL_ARB_fragment_program).
1023 * If the current card has more than 8 fixed function textures in OpenGL's regular fixed
1024 * function pipeline then the ATI_fragment_shader backend imposes a stricter limit. This
1025 * shouldn't be too hard since Nvidia cards have a limit of 4 textures with the default ffp
1026 * pipeline, and almost all games are happy with that. We can however support up to 8
1027 * texture stages because we have a 2nd pass limit of 8 instructions, and per stage we use
1028 * only 1 instruction.
1030 * The proper fix for this is not to use GL_ATI_fragment_shader on cards newer than the
1031 * r200 series and use an ARB or GLSL shader instead
1033 if(caps
->MaxSimultaneousTextures
> 6) {
1034 WARN("OpenGL fixed function supports %d simultaneous textures,\n", caps
->MaxSimultaneousTextures
);
1035 WARN("but GL_ATI_fragment_shader limits this to 6\n");
1036 caps
->MaxSimultaneousTextures
= 6;
1039 caps
->PrimitiveMiscCaps
|= WINED3DPMISCCAPS_TSSARGTEMP
;
1042 static void shader_atifs_generate_pshader(IWineD3DPixelShader
*iface
, SHADER_BUFFER
*buffer
) {
1043 ERR("Should not get here\n");
1046 static void shader_atifs_generate_vshader(IWineD3DVertexShader
*iface
, SHADER_BUFFER
*buffer
) {
1047 arb_program_shader_backend
.shader_generate_vshader(iface
, buffer
);
1050 static void shader_atifs_fragment_enable(IWineD3DDevice
*iface
, BOOL enable
) {
1052 glEnable(GL_FRAGMENT_SHADER_ATI
);
1053 checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)");
1055 glDisable(GL_FRAGMENT_SHADER_ATI
);
1056 checkGLcall("glDisable(GL_FRAGMENT_SHADER_ATI)");
1060 const shader_backend_t atifs_shader_backend
= {
1061 shader_atifs_select
,
1062 shader_atifs_select_depth_blt
,
1063 shader_atifs_destroy_depth_blt
,
1064 shader_atifs_load_constants
,
1065 shader_atifs_cleanup
,
1066 shader_atifs_color_correction
,
1067 shader_atifs_destroy
,
1070 shader_atifs_dirty_const
,
1071 shader_atifs_generate_pshader
,
1072 shader_atifs_generate_vshader
,
1073 shader_atifs_get_caps
,
1074 shader_atifs_load_init
,
1075 shader_atifs_fragment_enable
,