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 hash_table_t *fragment_shaders; /* A hashtable to track fragment pipeline replacement shaders */
57 static const char *debug_dstmod(GLuint mod) {
59 case GL_NONE: return "GL_NONE";
60 case GL_2X_BIT_ATI: return "GL_2X_BIT_ATI";
61 case GL_4X_BIT_ATI: return "GL_4X_BIT_ATI";
62 case GL_8X_BIT_ATI: return "GL_8X_BIT_ATI";
63 case GL_HALF_BIT_ATI: return "GL_HALF_BIT_ATI";
64 case GL_QUARTER_BIT_ATI: return "GL_QUARTER_BIT_ATI";
65 case GL_EIGHTH_BIT_ATI: return "GL_EIGHTH_BIT_ATI";
66 case GL_SATURATE_BIT_ATI: return "GL_SATURATE_BIT_ATI";
67 default: return "Unexpected modifier\n";
71 static const char *debug_argmod(GLuint mod) {
77 return "GL_2X_BIT_ATI";
79 return "GL_COMP_BIT_ATI";
80 case GL_NEGATE_BIT_ATI:
81 return "GL_NEGATE_BIT_ATI";
83 return "GL_BIAS_BIT_ATI";
85 case GL_2X_BIT_ATI | GL_COMP_BIT_ATI:
86 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI";
87 case GL_2X_BIT_ATI | GL_NEGATE_BIT_ATI:
88 return "GL_2X_BIT_ATI | GL_NEGATE_BIT_ATI";
89 case GL_2X_BIT_ATI | GL_BIAS_BIT_ATI:
90 return "GL_2X_BIT_ATI | GL_BIAS_BIT_ATI";
91 case GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI:
92 return "GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI";
93 case GL_COMP_BIT_ATI | GL_BIAS_BIT_ATI:
94 return "GL_COMP_BIT_ATI | GL_BIAS_BIT_ATI";
95 case GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI:
96 return "GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
98 case GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI:
99 return "GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
100 case GL_2X_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI:
101 return "GL_2X_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
102 case GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_BIAS_BIT_ATI:
103 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_BIAS_BIT_ATI";
104 case GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI:
105 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI";
107 case GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI:
108 return "GL_2X_BIT_ATI | GL_COMP_BIT_ATI | GL_NEGATE_BIT_ATI | GL_BIAS_BIT_ATI";
111 return "Unexpected argmod combination\n";
114 static const char *debug_register(GLuint reg) {
116 case GL_REG_0_ATI: return "GL_REG_0_ATI";
117 case GL_REG_1_ATI: return "GL_REG_1_ATI";
118 case GL_REG_2_ATI: return "GL_REG_2_ATI";
119 case GL_REG_3_ATI: return "GL_REG_3_ATI";
120 case GL_REG_4_ATI: return "GL_REG_4_ATI";
121 case GL_REG_5_ATI: return "GL_REG_5_ATI";
123 case GL_CON_0_ATI: return "GL_CON_0_ATI";
124 case GL_CON_1_ATI: return "GL_CON_1_ATI";
125 case GL_CON_2_ATI: return "GL_CON_2_ATI";
126 case GL_CON_3_ATI: return "GL_CON_3_ATI";
127 case GL_CON_4_ATI: return "GL_CON_4_ATI";
128 case GL_CON_5_ATI: return "GL_CON_5_ATI";
129 case GL_CON_6_ATI: return "GL_CON_6_ATI";
130 case GL_CON_7_ATI: return "GL_CON_7_ATI";
132 case GL_ZERO: return "GL_ZERO";
133 case GL_ONE: return "GL_ONE";
134 case GL_PRIMARY_COLOR: return "GL_PRIMARY_COLOR";
135 case GL_SECONDARY_INTERPOLATOR_ATI: return "GL_SECONDARY_INTERPOLATOR_ATI";
137 default: return "Unknown register\n";
141 static const char *debug_swizzle(GLuint swizzle) {
143 case GL_SWIZZLE_STR_ATI: return "GL_SWIZZLE_STR_ATI";
144 case GL_SWIZZLE_STQ_ATI: return "GL_SWIZZLE_STQ_ATI";
145 case GL_SWIZZLE_STR_DR_ATI: return "GL_SWIZZLE_STR_DR_ATI";
146 case GL_SWIZZLE_STQ_DQ_ATI: return "GL_SWIZZLE_STQ_DQ_ATI";
147 default: return "unknown swizzle";
151 static const char *debug_rep(GLuint rep) {
153 case GL_NONE: return "GL_NONE";
154 case GL_RED: return "GL_RED";
155 case GL_GREEN: return "GL_GREEN";
156 case GL_BLUE: return "GL_BLUE";
157 default: return "unknown argrep";
161 #define GLINFO_LOCATION (*gl_info)
162 static GLuint register_for_arg(DWORD arg, WineD3D_GL_Info *gl_info, unsigned int stage, GLuint *mod, GLuint *rep, GLuint tmparg) {
165 if(mod) *mod = GL_NONE;
166 if(arg == ARG_UNUSED) return -1; /* This is the marker for unused registers */
168 switch(arg & WINED3DTA_SELECTMASK) {
169 case WINED3DTA_DIFFUSE:
170 ret = GL_PRIMARY_COLOR;
173 case WINED3DTA_CURRENT:
174 /* Note that using GL_REG_0_ATI for the passed on register is safe because
175 * texture0 is read at stage0, so in the worst case it is read in the
176 * instruction writing to reg0. Afterwards texture0 is not used any longer.
177 * If we're reading from current
180 ret = GL_PRIMARY_COLOR;
186 case WINED3DTA_TEXTURE:
187 ret = GL_REG_0_ATI + stage;
190 case WINED3DTA_TFACTOR:
191 ret = ATI_FFP_CONST_TFACTOR;
194 case WINED3DTA_SPECULAR:
195 ret = GL_SECONDARY_INTERPOLATOR_ATI;
202 case WINED3DTA_CONSTANT:
203 FIXME("Unhandled source argument WINED3DTA_TEMP\n");
208 FIXME("Unknown source argument %d\n", arg);
212 if(arg & WINED3DTA_COMPLEMENT) {
213 if(mod) *mod |= GL_COMP_BIT_ATI;
215 if(arg & WINED3DTA_ALPHAREPLICATE) {
216 if(rep) *rep = GL_ALPHA;
218 if(rep) *rep = GL_NONE;
223 static GLuint find_tmpreg(struct texture_stage_op op[MAX_TEXTURES]) {
224 int lowest_read = -1;
225 int lowest_write = -1;
227 BOOL tex_used[MAX_TEXTURES];
229 memset(tex_used, 0, sizeof(tex_used));
230 for(i = 0; i < MAX_TEXTURES; i++) {
231 if(op[i].cop == WINED3DTOP_DISABLE) {
235 if(lowest_read == -1 &&
236 (op[i].carg1 == WINED3DTA_TEMP || op[i].carg2 == WINED3DTA_TEMP || op[i].carg0 == WINED3DTA_TEMP ||
237 op[i].aarg1 == WINED3DTA_TEMP || op[i].aarg2 == WINED3DTA_TEMP || op[i].aarg0 == WINED3DTA_TEMP)) {
241 if(lowest_write == -1 && op[i].dst == tempreg) {
245 if(op[i].carg1 == WINED3DTA_TEXTURE || op[i].carg2 == WINED3DTA_TEXTURE || op[i].carg0 == WINED3DTA_TEXTURE ||
246 op[i].aarg1 == WINED3DTA_TEXTURE || op[i].aarg2 == WINED3DTA_TEXTURE || op[i].aarg0 == WINED3DTA_TEXTURE) {
251 /* Temp reg not read? We don't need it, return GL_NONE */
252 if(lowest_read == -1) return GL_NONE;
254 if(lowest_write >= lowest_read) {
255 FIXME("Temp register read before being written\n");
258 if(lowest_write == -1) {
259 /* This needs a test. Maybe we are supposed to return 0.0/0.0/0.0/0.0, or fail drawprim, or whatever */
260 FIXME("Temp register read without being written\n");
262 } else if(lowest_write >= 1) {
263 /* If we're writing to the temp reg at earliest in stage 1, we can use register 1 for the temp result.
264 * there may be texture data stored in reg 1, but we do not need it any longer since stage 1 already
269 /* Search for a free texture register. We have 6 registers available. GL_REG_0_ATI is already used
270 * for the regular result
272 for(i = 1; i < 6; i++) {
274 return GL_REG_0_ATI + i;
277 /* What to do here? Report it in ValidateDevice? */
278 FIXME("Could not find a register for the temporary register\n");
283 static GLuint gen_ati_shader(struct texture_stage_op op[MAX_TEXTURES], WineD3D_GL_Info *gl_info) {
284 GLuint ret = GL_EXTCALL(glGenFragmentShadersATI(1));
286 GLuint arg0, arg1, arg2, extrarg;
287 GLuint dstmod, argmod0, argmod1, argmod2, argmodextra;
288 GLuint rep0, rep1, rep2;
290 GLuint tmparg = find_tmpreg(op);
294 ERR("Failed to generate a GL_ATI_fragment_shader shader id\n");
297 GL_EXTCALL(glBindFragmentShaderATI(ret));
298 checkGLcall("GL_EXTCALL(glBindFragmentShaderATI(ret))");
300 TRACE("glBeginFragmentShaderATI()\n");
301 GL_EXTCALL(glBeginFragmentShaderATI());
302 checkGLcall("GL_EXTCALL(glBeginFragmentShaderATI())");
304 /* Pass 1: Generate sampling instructions for perturbation maps */
305 for(stage = 0; stage < GL_LIMITS(textures); stage++) {
306 if(op[stage].cop == WINED3DTOP_DISABLE) break;
307 if(op[stage].cop != WINED3DTOP_BUMPENVMAP &&
308 op[stage].cop != WINED3DTOP_BUMPENVMAPLUMINANCE) continue;
310 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, GL_SWIZZLE_STR_ATI)\n",
312 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI + stage,
313 GL_TEXTURE0_ARB + stage,
314 GL_SWIZZLE_STR_ATI));
315 TRACE("glPassTexCoordATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, GL_SWIZZLE_STR_ATI)\n",
316 stage + 1, stage + 1);
317 GL_EXTCALL(glPassTexCoordATI(GL_REG_0_ATI + stage + 1,
318 GL_TEXTURE0_ARB + stage + 1,
319 GL_SWIZZLE_STR_ATI));
321 /* We need GL_REG_5_ATI as a temporary register to swizzle the bump matrix. So we run into
322 * issues if we're bump mapping on stage 4 or 5
325 FIXME("Bump mapping in stage %d\n", stage);
329 /* Pass 2: Generate perturbation calculations */
330 for(stage = 0; stage < GL_LIMITS(textures); stage++) {
331 if(op[stage].cop == WINED3DTOP_DISABLE) break;
332 if(op[stage].cop != WINED3DTOP_BUMPENVMAP &&
333 op[stage].cop != WINED3DTOP_BUMPENVMAPLUMINANCE) continue;
335 /* Nice thing, we get the color correction for free :-) */
336 if(op[stage].color_correction == WINED3DFMT_V8U8) {
337 argmodextra = GL_2X_BIT_ATI | GL_BIAS_BIT_ATI;
342 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",
343 stage + 1, stage, debug_argmod(argmodextra), stage, stage + 1);
344 GL_EXTCALL(glColorFragmentOp3ATI(GL_DOT2_ADD_ATI, GL_REG_0_ATI + stage + 1, GL_RED_BIT_ATI, GL_NONE,
345 GL_REG_0_ATI + stage, GL_NONE, argmodextra,
346 ATI_FFP_CONST_BUMPMAT(stage), GL_NONE, GL_2X_BIT_ATI | GL_BIAS_BIT_ATI,
347 GL_REG_0_ATI + stage + 1, GL_RED, GL_NONE));
349 /* FIXME: How can I make GL_DOT2_ADD_ATI read the factors from blue and alpha? It defaults to red and green,
350 * 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
351 * one register and two instructions in this pass for a simple swizzling operation.
352 * For starters it might be good enough to merge the two movs into one, but even that isn't possible :-(
354 * NOTE: GL_BLUE | GL_ALPHA is not possible. It doesn't throw a compilation error, but an OR operation on the
355 * constants doesn't make sense, considering their values.
357 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);
358 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_5_ATI, GL_RED_BIT_ATI, GL_NONE,
359 ATI_FFP_CONST_BUMPMAT(stage), GL_BLUE, GL_NONE));
360 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);
361 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_5_ATI, GL_GREEN_BIT_ATI, GL_NONE,
362 ATI_FFP_CONST_BUMPMAT(stage), GL_ALPHA, GL_NONE));
363 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",
364 stage + 1, stage, debug_argmod(argmodextra), stage + 1);
365 GL_EXTCALL(glColorFragmentOp3ATI(GL_DOT2_ADD_ATI, GL_REG_0_ATI + stage + 1, GL_GREEN_BIT_ATI, GL_NONE,
366 GL_REG_0_ATI + stage, GL_NONE, argmodextra,
367 GL_REG_5_ATI, GL_NONE, GL_2X_BIT_ATI | GL_BIAS_BIT_ATI,
368 GL_REG_0_ATI + stage + 1, GL_GREEN, GL_NONE));
371 /* Pass 3: Generate sampling instructions for regular textures */
372 for(stage = 0; stage < GL_LIMITS(textures); stage++) {
373 if(op[stage].cop == WINED3DTOP_DISABLE) {
377 if(op[stage].projected == proj_none) {
378 swizzle = GL_SWIZZLE_STR_ATI;
379 } else if(op[stage].projected == proj_count3) {
380 /* TODO: D3DTTFF_COUNT3 | D3DTTFF_PROJECTED would be GL_SWIZZLE_STR_DR_ATI.
381 * However, the FFP vertex processing texture transform matrix handler does
382 * some transformations in the texture matrix which makes the 3rd coordinate
383 * arrive in Q, not R in that case. This is needed for opengl fixed function
384 * fragment processing which always divides by Q. In this backend we can
385 * handle that properly and be compatible with vertex shader output and avoid
386 * side effects of the texture matrix games
388 swizzle = GL_SWIZZLE_STQ_DQ_ATI;
390 swizzle = GL_SWIZZLE_STQ_DQ_ATI;
393 if((op[stage].carg0 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
394 (op[stage].carg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
395 (op[stage].carg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
396 (op[stage].aarg0 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
397 (op[stage].aarg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
398 (op[stage].aarg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
399 op[stage].cop == WINED3DTOP_BLENDTEXTUREALPHA) {
402 (op[stage - 1].cop == WINED3DTOP_BUMPENVMAP ||
403 op[stage - 1].cop == WINED3DTOP_BUMPENVMAPLUMINANCE)) {
404 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_REG_%d_ATI, GL_SWIZZLE_STR_ATI)\n",
406 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI + stage,
407 GL_REG_0_ATI + stage,
408 GL_SWIZZLE_STR_ATI));
410 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, %s)\n",
411 stage, stage, debug_swizzle(swizzle));
412 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI + stage,
413 GL_TEXTURE0_ARB + stage,
419 /* Pass 4: Generate the arithmetic instructions */
420 for(stage = 0; stage < MAX_TEXTURES; stage++) {
421 if(op[stage].cop == WINED3DTOP_DISABLE) {
423 /* Handle complete texture disabling gracefully */
424 TRACE("glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, GL_PRIMARY_COLOR, GL_NONE, GL_NONE)\n");
425 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
426 GL_PRIMARY_COLOR, GL_NONE, GL_NONE));
427 TRACE("glAlphaFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_PRIMARY_COLOR, GL_NONE, GL_NONE)\n");
428 GL_EXTCALL(glAlphaFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE,
429 GL_PRIMARY_COLOR, GL_NONE, GL_NONE));
434 if(op[stage].dst == tempreg) {
435 /* If we're writing to D3DTA_TEMP, but never reading from it we don't have to write there in the first place.
436 * skip the entire stage, this saves some GPU time
438 if(tmparg == GL_NONE) continue;
442 dstreg = GL_REG_0_ATI;
445 arg0 = register_for_arg(op[stage].carg0, gl_info, stage, &argmod0, &rep0, tmparg);
446 arg1 = register_for_arg(op[stage].carg1, gl_info, stage, &argmod1, &rep1, tmparg);
447 arg2 = register_for_arg(op[stage].carg2, gl_info, stage, &argmod2, &rep2, tmparg);
449 argmodextra = GL_NONE;
452 switch(op[stage].cop) {
453 case WINED3DTOP_SELECTARG2:
457 case WINED3DTOP_SELECTARG1:
458 TRACE("glColorFragmentOp1ATI(GL_MOV_ATI, %s, GL_NONE, GL_NONE, %s, %s, %s)\n",
459 debug_register(dstreg), debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1));
460 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI, dstreg, GL_NONE, GL_NONE,
461 arg1, rep1, argmod1));
464 case WINED3DTOP_MODULATE4X:
465 if(dstmod == GL_NONE) dstmod = GL_4X_BIT_ATI;
466 case WINED3DTOP_MODULATE2X:
467 if(dstmod == GL_NONE) dstmod = GL_2X_BIT_ATI;
468 dstmod |= GL_SATURATE_BIT_ATI;
469 case WINED3DTOP_MODULATE:
470 TRACE("glColorFragmentOp2ATI(GL_MUL_ATI, %s, GL_NONE, %s, %s, %s, %s, %s, %s, %s)\n",
471 debug_register(dstreg), debug_dstmod(dstmod),
472 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
473 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2));
474 GL_EXTCALL(glColorFragmentOp2ATI(GL_MUL_ATI, dstreg, GL_NONE, dstmod,
476 arg2, rep2, argmod2));
479 case WINED3DTOP_ADDSIGNED2X:
480 dstmod = GL_2X_BIT_ATI;
481 case WINED3DTOP_ADDSIGNED:
482 argmodextra = GL_BIAS_BIT_ATI;
484 dstmod |= GL_SATURATE_BIT_ATI;
485 TRACE("glColorFragmentOp2ATI(GL_ADD_ATI, %s, GL_NONE, %s, %s, %s, %s, %s, %s, %s)\n",
486 debug_register(dstreg), debug_dstmod(dstmod),
487 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
488 debug_register(arg2), debug_rep(rep2), debug_argmod(argmodextra | argmod2));
489 GL_EXTCALL(glColorFragmentOp2ATI(GL_ADD_ATI, GL_REG_0_ATI, GL_NONE, dstmod,
491 arg2, rep2, argmodextra | argmod2));
494 case WINED3DTOP_SUBTRACT:
495 dstmod |= GL_SATURATE_BIT_ATI;
496 TRACE("glColorFragmentOp2ATI(GL_SUB_ATI, %s, GL_NONE, %s, %s, %s, %s, %s, %s, %s)\n",
497 debug_register(dstreg), debug_dstmod(dstmod),
498 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
499 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2));
500 GL_EXTCALL(glColorFragmentOp2ATI(GL_SUB_ATI, dstreg, GL_NONE, dstmod,
502 arg2, rep2, argmod2));
505 case WINED3DTOP_ADDSMOOTH:
506 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
507 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_SATURATE_BIT_ATI, %s, %s, %s, %s, %s, %s, %s, %s, %s)\n",
508 debug_register(dstreg),
509 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
510 debug_register(arg1), debug_rep(rep1), debug_argmod(argmodextra),
511 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1));
512 /* Dst = arg1 + * arg2(1 -arg 1)
513 * = arg2 * (1 - arg1) + arg1
515 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
517 arg1, rep1, argmodextra,
518 arg1, rep1, argmod1));
521 case WINED3DTOP_BLENDCURRENTALPHA:
522 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_CURRENT, gl_info, stage, NULL, NULL, -1);
523 case WINED3DTOP_BLENDFACTORALPHA:
524 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TFACTOR, gl_info, stage, NULL, NULL, -1);
525 case WINED3DTOP_BLENDTEXTUREALPHA:
526 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
527 case WINED3DTOP_BLENDDIFFUSEALPHA:
528 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_DIFFUSE, gl_info, stage, NULL, NULL, -1);
529 TRACE("glColorFragmentOp3ATI(GL_LERP_ATI, %s, GL_NONE, GL_NONE, %s, GL_ALPHA, GL_NONE, %s, %s, %s, %s, %s, %s)\n",
530 debug_register(dstreg),
531 debug_register(extrarg),
532 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
533 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2));
534 GL_EXTCALL(glColorFragmentOp3ATI(GL_LERP_ATI, dstreg, GL_NONE, GL_NONE,
535 extrarg, GL_ALPHA, GL_NONE,
537 arg2, rep2, argmod2));
540 case WINED3DTOP_BLENDTEXTUREALPHAPM:
541 arg0 = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
542 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_NONE, %s, %s, %s, %s, GL_ALPHA, GL_COMP_BIT_ATI, %s, %s, %s)\n",
543 debug_register(dstreg),
544 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
545 debug_register(arg0),
546 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1));
547 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE, GL_NONE,
549 arg0, GL_ALPHA, GL_COMP_BIT_ATI,
550 arg1, rep1, argmod1));
553 /* D3DTOP_PREMODULATE ???? */
555 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
556 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
557 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
558 if(!argmodextra) argmodextra = argmod1;
559 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_SATURATE_BIT_ATI, %s, %s, %s, %s, GL_ALPHA, %s, %s, %s, %s)\n",
560 debug_register(dstreg),
561 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
562 debug_register(arg1), debug_argmod(argmodextra), debug_register(arg1), debug_rep(rep1), debug_argmod(arg1));
563 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
565 arg1, GL_ALPHA, argmodextra,
566 arg1, rep1, argmod1));
569 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
570 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
571 case WINED3DTOP_MODULATECOLOR_ADDALPHA:
572 if(!argmodextra) argmodextra = argmod1;
573 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_SATURATE_BIT_ATI, %s, %s, %s, %s, %s, %s, %s, GL_ALPHA, %s)\n",
574 debug_register(dstreg),
575 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
576 debug_register(arg1), debug_rep(rep1), debug_argmod(argmodextra),
577 debug_register(arg1), debug_argmod(argmod1));
578 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
580 arg1, rep1, argmodextra,
581 arg1, GL_ALPHA, argmod1));
584 case WINED3DTOP_DOTPRODUCT3:
585 TRACE("glColorFragmentOp2ATI(GL_DOT3_ATI, %s, GL_NONE, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI, %s, %s, %s, %s, %s, %s)\n",
586 debug_register(dstreg),
587 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1 | GL_BIAS_BIT_ATI),
588 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2 | GL_BIAS_BIT_ATI));
589 GL_EXTCALL(glColorFragmentOp2ATI(GL_DOT3_ATI, dstreg, GL_NONE, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI,
590 arg1, rep1, argmod1 | GL_BIAS_BIT_ATI,
591 arg2, rep2, argmod2 | GL_BIAS_BIT_ATI));
594 case WINED3DTOP_MULTIPLYADD:
595 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_SATURATE_BIT_ATI, %s, %s, %s, %s, %s, %s, %s, %s, %s)\n",
596 debug_register(dstreg),
597 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
598 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
599 debug_register(arg0), debug_rep(rep0), debug_argmod(argmod0));
600 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
603 arg0, rep0, argmod0));
606 case WINED3DTOP_LERP:
607 TRACE("glColorFragmentOp3ATI(GL_LERP_ATI, %s, GL_NONE, GL_NONE, %s, %s, %s, %s, %s, %s, %s, %s, %s)\n",
608 debug_register(dstreg),
609 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
610 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
611 debug_register(arg0), debug_rep(rep0), debug_argmod(argmod0));
612 GL_EXTCALL(glColorFragmentOp3ATI(GL_LERP_ATI, dstreg, GL_NONE, GL_NONE,
615 arg2, rep2, argmod2));
618 case WINED3DTOP_BUMPENVMAP:
619 case WINED3DTOP_BUMPENVMAPLUMINANCE:
620 /* Those are handled in the first pass of the shader(generation pass 1 and 2) already */
623 default: FIXME("Unhandled color operation %d on stage %d\n", op[stage].cop, stage);
626 arg0 = register_for_arg(op[stage].aarg0, gl_info, stage, &argmod0, NULL, tmparg);
627 arg1 = register_for_arg(op[stage].aarg1, gl_info, stage, &argmod1, NULL, tmparg);
628 arg2 = register_for_arg(op[stage].aarg2, gl_info, stage, &argmod2, NULL, tmparg);
630 argmodextra = GL_NONE;
633 switch(op[stage].aop) {
634 case WINED3DTOP_DISABLE:
635 /* Get the primary color to the output if on stage 0, otherwise leave register 0 untouched */
637 TRACE("glAlphaFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_PRIMARY_COLOR, GL_NONE, GL_NONE)\n");
638 GL_EXTCALL(glAlphaFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE,
639 GL_PRIMARY_COLOR, GL_NONE, GL_NONE));
643 case WINED3DTOP_SELECTARG2:
646 case WINED3DTOP_SELECTARG1:
647 TRACE("glAlphaFragmentOp1ATI(GL_MOV_ATI, %s, GL_NONE, %s, GL_NONE, %s)\n",
648 debug_register(dstreg),
649 debug_register(arg1), debug_argmod(argmod1));
650 GL_EXTCALL(glAlphaFragmentOp1ATI(GL_MOV_ATI, dstreg, GL_NONE,
651 arg1, GL_NONE, argmod1));
654 case WINED3DTOP_MODULATE4X:
655 if(dstmod == GL_NONE) dstmod = GL_4X_BIT_ATI;
656 case WINED3DTOP_MODULATE2X:
657 if(dstmod == GL_NONE) dstmod = GL_2X_BIT_ATI;
658 dstmod |= GL_SATURATE_BIT_ATI;
659 case WINED3DTOP_MODULATE:
660 TRACE("glAlphaFragmentOp2ATI(GL_MUL_ATI, %s, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
661 debug_register(dstreg), debug_dstmod(dstmod),
662 debug_register(arg1), debug_argmod(argmod1),
663 debug_register(arg2), debug_argmod(argmod2));
664 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_MUL_ATI, dstreg, dstmod,
665 arg1, GL_NONE, argmod1,
666 arg2, GL_NONE, argmod2));
669 case WINED3DTOP_ADDSIGNED2X:
670 dstmod = GL_2X_BIT_ATI;
671 case WINED3DTOP_ADDSIGNED:
672 argmodextra = GL_BIAS_BIT_ATI;
674 dstmod |= GL_SATURATE_BIT_ATI;
675 TRACE("glAlphaFragmentOp2ATI(GL_ADD_ATI, %s, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
676 debug_register(dstreg), debug_dstmod(dstmod),
677 debug_register(arg1), debug_argmod(argmod1),
678 debug_register(arg2), debug_argmod(argmodextra | argmod2));
679 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_ADD_ATI, dstreg, dstmod,
680 arg1, GL_NONE, argmod1,
681 arg2, GL_NONE, argmodextra | argmod2));
684 case WINED3DTOP_SUBTRACT:
685 dstmod |= GL_SATURATE_BIT_ATI;
686 TRACE("glAlphaFragmentOp2ATI(GL_SUB_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
687 debug_register(dstreg), debug_dstmod(dstmod),
688 debug_register(arg1), debug_argmod(argmod1),
689 debug_register(arg2), debug_argmod(argmod2));
690 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_SUB_ATI, dstreg, dstmod,
691 arg1, GL_NONE, argmod1,
692 arg2, GL_NONE, argmod2));
695 case WINED3DTOP_ADDSMOOTH:
696 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
697 TRACE("glAlphaFragmentOp3ATI(GL_MAD_ATI, %s, GL_SATURATE_BIT_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
698 debug_register(dstreg),
699 debug_register(arg2), debug_argmod(argmod2),
700 debug_register(arg1), debug_argmod(argmodextra),
701 debug_register(arg1), debug_argmod(argmod1));
702 /* Dst = arg1 + * arg2(1 -arg 1)
703 * = arg2 * (1 - arg1) + arg1
705 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_SATURATE_BIT_ATI,
706 arg2, GL_NONE, argmod2,
707 arg1, GL_NONE, argmodextra,
708 arg1, GL_NONE, argmod1));
711 case WINED3DTOP_BLENDCURRENTALPHA:
712 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_CURRENT, gl_info, stage, NULL, NULL, -1);
713 case WINED3DTOP_BLENDFACTORALPHA:
714 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TFACTOR, gl_info, stage, NULL, NULL, -1);
715 case WINED3DTOP_BLENDTEXTUREALPHA:
716 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
717 case WINED3DTOP_BLENDDIFFUSEALPHA:
718 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_DIFFUSE, gl_info, stage, NULL, NULL, -1);
719 TRACE("glAlphaFragmentOp3ATI(GL_LERP_ATI, %s, GL_NONE, %s, GL_ALPHA, GL_NONE, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
720 debug_register(dstreg),
721 debug_register(extrarg),
722 debug_register(arg1), debug_argmod(argmod1),
723 debug_register(arg2), debug_argmod(argmod2));
724 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_LERP_ATI, dstreg, GL_NONE,
725 extrarg, GL_ALPHA, GL_NONE,
726 arg1, GL_NONE, argmod1,
727 arg2, GL_NONE, argmod2));
730 case WINED3DTOP_BLENDTEXTUREALPHAPM:
731 arg0 = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
732 TRACE("glAlphaFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, %s, GL_NONE, %s, %s, GL_ALPHA, GL_COMP_BIT_ATI, %s, GL_NONE, %s)\n",
733 debug_register(dstreg),
734 debug_register(arg2), debug_argmod(argmod2),
735 debug_register(arg0),
736 debug_register(arg1), debug_argmod(argmod1));
737 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE,
738 arg2, GL_NONE, argmod2,
739 arg0, GL_ALPHA, GL_COMP_BIT_ATI,
740 arg1, GL_NONE, argmod1));
743 /* D3DTOP_PREMODULATE ???? */
745 case WINED3DTOP_DOTPRODUCT3:
746 TRACE("glAlphaFragmentOp2ATI(GL_DOT3_ATI, %s, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
747 debug_register(dstreg),
748 debug_register(arg1), debug_argmod(argmod1 | GL_BIAS_BIT_ATI),
749 debug_register(arg2), debug_argmod(argmod2 | GL_BIAS_BIT_ATI));
750 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_DOT3_ATI, dstreg, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI,
751 arg1, GL_NONE, argmod1 | GL_BIAS_BIT_ATI,
752 arg2, GL_NONE, argmod2 | GL_BIAS_BIT_ATI));
755 case WINED3DTOP_MULTIPLYADD:
756 TRACE("glAlphaFragmentOp3ATI(GL_MAD_ATI, %s, GL_SATURATE_BIT_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
757 debug_register(dstreg),
758 debug_register(arg1), debug_argmod(argmod1),
759 debug_register(arg2), debug_argmod(argmod2),
760 debug_register(arg0), debug_argmod(argmod0));
761 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_SATURATE_BIT_ATI,
762 arg1, GL_NONE, argmod1,
763 arg2, GL_NONE, argmod2,
764 arg0, GL_NONE, argmod0));
767 case WINED3DTOP_LERP:
768 TRACE("glAlphaFragmentOp3ATI(GL_LERP_ATI, %s, GL_SATURATE_BIT_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
769 debug_register(dstreg),
770 debug_register(arg1), debug_argmod(argmod1),
771 debug_register(arg2), debug_argmod(argmod2),
772 debug_register(arg0), debug_argmod(argmod0));
773 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_LERP_ATI, dstreg, GL_SATURATE_BIT_ATI,
774 arg1, GL_NONE, argmod1,
775 arg2, GL_NONE, argmod2,
776 arg0, GL_NONE, argmod0));
779 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
780 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
781 case WINED3DTOP_MODULATECOLOR_ADDALPHA:
782 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
783 case WINED3DTOP_BUMPENVMAP:
784 case WINED3DTOP_BUMPENVMAPLUMINANCE:
785 ERR("Application uses an invalid alpha operation\n");
788 default: FIXME("Unhandled alpha operation %d on stage %d\n", op[stage].aop, stage);
792 TRACE("glEndFragmentShaderATI()\n");
793 GL_EXTCALL(glEndFragmentShaderATI());
794 checkGLcall("GL_EXTCALL(glEndFragmentShaderATI())");
797 #undef GLINFO_LOCATION
799 #define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
800 static void set_tex_op_atifs(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
801 IWineD3DDeviceImpl *This = stateblock->wineD3DDevice;
802 struct atifs_ffp_desc *desc;
803 struct ffp_settings settings;
804 struct atifs_private_data *priv = (struct atifs_private_data *) This->fragment_priv;
808 gen_ffp_op(stateblock, &settings, TRUE);
809 desc = (struct atifs_ffp_desc *) find_ffp_shader(priv->fragment_shaders, &settings);
811 desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
813 ERR("Out of memory\n");
816 desc->num_textures_used = 0;
817 for(i = 0; i < GL_LIMITS(texture_stages); i++) {
818 if(settings.op[i].cop == WINED3DTOP_DISABLE) break;
819 desc->num_textures_used = i;
822 memcpy(&desc->parent.settings, &settings, sizeof(settings));
823 desc->shader = gen_ati_shader(settings.op, &GLINFO_LOCATION);
824 add_ffp_shader(priv->fragment_shaders, &desc->parent);
825 TRACE("Allocated fixed function replacement shader descriptor %p\n", desc);
828 /* GL_ATI_fragment_shader depends on the GL_TEXTURE_xD enable settings. Update the texture stages
829 * used by this shader
831 for(i = 0; i < desc->num_textures_used; i++) {
832 mapped_stage = This->texUnitMap[i];
833 if(mapped_stage != -1) {
834 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
835 checkGLcall("glActiveTextureARB");
836 texture_activate_dimensions(i, stateblock, context);
840 GL_EXTCALL(glBindFragmentShaderATI(desc->shader));
843 static void state_texfactor_atifs(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
845 D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_TEXTUREFACTOR], col);
847 GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col));
848 checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col)");
851 static void set_bumpmat(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
852 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
855 mat[0][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT00]);
856 mat[1][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT01]);
857 mat[0][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT10]);
858 mat[1][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT11]);
859 /* GL_ATI_fragment_shader allows only constants from 0.0 to 1.0, but the bumpmat
860 * constants can be in any range. While they should stay between [-1.0 and 1.0] because
861 * Shader Model 1.x pixel shaders are clamped to that range negative values are used occasionally,
862 * for example by our d3d9 test. So to get negative values scale -1;1 to 0;1 and undo that in the
863 * shader(it is free). This might potentially reduce precision. However, if the hardware does
864 * support proper floats it shouldn't, and if it doesn't we can't get anything better anyway
866 mat[0][0] = (mat[0][0] + 1.0) * 0.5;
867 mat[1][0] = (mat[1][0] + 1.0) * 0.5;
868 mat[0][1] = (mat[0][1] + 1.0) * 0.5;
869 mat[1][1] = (mat[1][1] + 1.0) * 0.5;
870 GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), (float *) mat));
871 checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), mat)");
873 #undef GLINFO_LOCATION
875 static const struct StateEntryTemplate atifs_fragmentstate_template[] = {
876 {STATE_RENDER(WINED3DRS_TEXTUREFACTOR), { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), state_texfactor_atifs }, 0 },
877 {STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
878 {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
879 {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
880 {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
881 {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
882 {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
883 {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
884 {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
885 {STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
886 {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
887 {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
888 {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
889 {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
890 {STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
891 {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
892 {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
893 {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
894 {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
895 {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
896 {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
897 {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
898 {STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
899 {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
900 {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
901 {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
902 {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
903 {STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
904 {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
905 {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
906 {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
907 {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
908 {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
909 {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
910 {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
911 {STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
912 {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
913 {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
914 {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
915 {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
916 {STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
917 {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
918 {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
919 {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
920 {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
921 {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
922 {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
923 {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
924 {STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
925 {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
926 {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
927 {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
928 {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
929 {STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
930 {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
931 {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
932 {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
933 {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
934 {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
935 {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
936 {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
937 {STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
938 {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
939 {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
940 {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
941 {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
942 {STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
943 {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
944 {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
945 {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
946 {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
947 {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
948 {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
949 {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
950 {STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
951 {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
952 {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
953 {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
954 {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
955 {STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
956 {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
957 {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
958 {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
959 {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
960 {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
961 {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
962 {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
963 {STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
964 {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
965 {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
966 {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
967 {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
968 {STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
969 {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
970 {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
971 {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
972 {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
973 {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
974 {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
975 {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
976 {STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
977 {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
978 {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
979 {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
980 {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
981 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, 0 },
982 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, 0 },
983 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, 0 },
984 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texdim }, 0 },
985 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texdim }, 0 },
986 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texdim }, 0 },
987 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texdim }, 0 },
988 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texdim }, 0 },
989 {0 /* Terminate */, { 0, 0 }, 0 },
992 static void atifs_enable(IWineD3DDevice *iface, BOOL enable) {
994 glEnable(GL_FRAGMENT_SHADER_ATI);
995 checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)");
997 glDisable(GL_FRAGMENT_SHADER_ATI);
998 checkGLcall("glDisable(GL_FRAGMENT_SHADER_ATI)");
1002 static void atifs_get_caps(WINED3DDEVTYPE devtype, WineD3D_GL_Info *gl_info, struct fragment_caps *caps) {
1003 caps->TextureOpCaps = WINED3DTEXOPCAPS_DISABLE |
1004 WINED3DTEXOPCAPS_SELECTARG1 |
1005 WINED3DTEXOPCAPS_SELECTARG2 |
1006 WINED3DTEXOPCAPS_MODULATE4X |
1007 WINED3DTEXOPCAPS_MODULATE2X |
1008 WINED3DTEXOPCAPS_MODULATE |
1009 WINED3DTEXOPCAPS_ADDSIGNED2X |
1010 WINED3DTEXOPCAPS_ADDSIGNED |
1011 WINED3DTEXOPCAPS_ADD |
1012 WINED3DTEXOPCAPS_SUBTRACT |
1013 WINED3DTEXOPCAPS_ADDSMOOTH |
1014 WINED3DTEXOPCAPS_BLENDCURRENTALPHA |
1015 WINED3DTEXOPCAPS_BLENDFACTORALPHA |
1016 WINED3DTEXOPCAPS_BLENDTEXTUREALPHA |
1017 WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA |
1018 WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM |
1019 WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
1020 WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
1021 WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA |
1022 WINED3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
1023 WINED3DTEXOPCAPS_DOTPRODUCT3 |
1024 WINED3DTEXOPCAPS_MULTIPLYADD |
1025 WINED3DTEXOPCAPS_LERP |
1026 WINED3DTEXOPCAPS_BUMPENVMAP;
1028 /* TODO: Implement WINED3DTEXOPCAPS_BUMPENVMAPLUMINANCE
1029 and WINED3DTEXOPCAPS_PREMODULATE */
1031 /* GL_ATI_fragment_shader always supports 6 textures, which was the limit on r200 cards
1032 * which this extension is exclusively focused on(later cards have GL_ARB_fragment_program).
1033 * If the current card has more than 8 fixed function textures in OpenGL's regular fixed
1034 * function pipeline then the ATI_fragment_shader backend imposes a stricter limit. This
1035 * shouldn't be too hard since Nvidia cards have a limit of 4 textures with the default ffp
1036 * pipeline, and almost all games are happy with that. We can however support up to 8
1037 * texture stages because we have a 2nd pass limit of 8 instructions, and per stage we use
1038 * only 1 instruction.
1040 * The proper fix for this is not to use GL_ATI_fragment_shader on cards newer than the
1041 * r200 series and use an ARB or GLSL shader instead
1043 caps->MaxTextureBlendStages = 8;
1044 caps->MaxSimultaneousTextures = 6;
1046 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_TSSARGTEMP;
1049 static HRESULT atifs_alloc(IWineD3DDevice *iface) {
1050 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
1051 struct atifs_private_data *priv;
1053 This->fragment_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct atifs_private_data));
1054 if(!This->fragment_priv) {
1055 ERR("Out of memory\n");
1056 return E_OUTOFMEMORY;
1058 priv = (struct atifs_private_data *) This->fragment_priv;
1059 priv->fragment_shaders = hash_table_create(ffp_program_key_hash, ffp_program_key_compare);
1063 #define GLINFO_LOCATION This->adapter->gl_info
1064 static void atifs_free_ffpshader(void *value, void *device) {
1065 IWineD3DDeviceImpl *This = device;
1066 struct atifs_ffp_desc *entry_ati = value;
1069 GL_EXTCALL(glDeleteFragmentShaderATI(entry_ati->shader));
1070 checkGLcall("glDeleteFragmentShaderATI(entry->shader)");
1071 HeapFree(GetProcessHeap(), 0, entry_ati);
1075 static void atifs_free(IWineD3DDevice *iface) {
1076 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
1077 struct atifs_private_data *priv = (struct atifs_private_data *) This->fragment_priv;
1079 hash_table_destroy(priv->fragment_shaders, atifs_free_ffpshader, This);
1081 HeapFree(GetProcessHeap(), 0, priv);
1082 This->fragment_priv = NULL;
1084 #undef GLINFO_LOCATION
1086 static BOOL atifs_conv_supported(WINED3DFORMAT fmt) {
1087 TRACE("Checking shader format support for format %s:", debug_d3dformat(fmt));
1089 case WINED3DFMT_V8U8:
1090 case WINED3DFMT_V16U16:
1099 const struct fragment_pipeline atifs_fragment_pipeline = {
1104 atifs_conv_supported,
1105 atifs_fragmentstate_template