advapi32/tests: test_enum_provider_types test cleanup.
[wine/multimedia.git] / dlls / wined3d / ati_fragment_shader.c
blob10100e2f9043a4922cd0469bfb5849e5655fd08f
1 /*
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
21 #include "config.h"
23 #include <math.h>
24 #include <stdio.h>
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 */
44 struct atifs_ffp_desc
46 struct ffp_desc parent;
47 GLuint shader;
48 unsigned int num_textures_used;
51 struct atifs_private_data
53 struct hash_table_t *fragment_shaders; /* A hashtable to track fragment pipeline replacement shaders */
57 static const char *debug_dstmod(GLuint mod) {
58 switch(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) {
72 switch(mod) {
73 case GL_NONE:
74 return "GL_NONE";
76 case GL_2X_BIT_ATI:
77 return "GL_2X_BIT_ATI";
78 case GL_COMP_BIT_ATI:
79 return "GL_COMP_BIT_ATI";
80 case GL_NEGATE_BIT_ATI:
81 return "GL_NEGATE_BIT_ATI";
82 case GL_BIAS_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";
110 default:
111 return "Unexpected argmod combination\n";
114 static const char *debug_register(GLuint reg) {
115 switch(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) {
142 switch(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) {
152 switch(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) {
163 GLenum ret;
165 if(mod) *mod = GL_NONE;
166 if(arg == ARG_UNUSED)
168 if (rep) *rep = GL_NONE;
169 return -1; /* This is the marker for unused registers */
172 switch(arg & WINED3DTA_SELECTMASK) {
173 case WINED3DTA_DIFFUSE:
174 ret = GL_PRIMARY_COLOR;
175 break;
177 case WINED3DTA_CURRENT:
178 /* Note that using GL_REG_0_ATI for the passed on register is safe because
179 * texture0 is read at stage0, so in the worst case it is read in the
180 * instruction writing to reg0. Afterwards texture0 is not used any longer.
181 * If we're reading from current
183 if(stage == 0) {
184 ret = GL_PRIMARY_COLOR;
185 } else {
186 ret = GL_REG_0_ATI;
188 break;
190 case WINED3DTA_TEXTURE:
191 ret = GL_REG_0_ATI + stage;
192 break;
194 case WINED3DTA_TFACTOR:
195 ret = ATI_FFP_CONST_TFACTOR;
196 break;
198 case WINED3DTA_SPECULAR:
199 ret = GL_SECONDARY_INTERPOLATOR_ATI;
200 break;
202 case WINED3DTA_TEMP:
203 ret = tmparg;
204 break;
206 case WINED3DTA_CONSTANT:
207 FIXME("Unhandled source argument WINED3DTA_TEMP\n");
208 ret = GL_CON_0_ATI;
209 break;
211 default:
212 FIXME("Unknown source argument %d\n", arg);
213 ret = GL_ZERO;
216 if(arg & WINED3DTA_COMPLEMENT) {
217 if(mod) *mod |= GL_COMP_BIT_ATI;
219 if(arg & WINED3DTA_ALPHAREPLICATE) {
220 if(rep) *rep = GL_ALPHA;
221 } else {
222 if(rep) *rep = GL_NONE;
224 return ret;
227 static GLuint find_tmpreg(struct texture_stage_op op[MAX_TEXTURES]) {
228 int lowest_read = -1;
229 int lowest_write = -1;
230 int i;
231 BOOL tex_used[MAX_TEXTURES];
233 memset(tex_used, 0, sizeof(tex_used));
234 for(i = 0; i < MAX_TEXTURES; i++) {
235 if(op[i].cop == WINED3DTOP_DISABLE) {
236 break;
239 if(lowest_read == -1 &&
240 (op[i].carg1 == WINED3DTA_TEMP || op[i].carg2 == WINED3DTA_TEMP || op[i].carg0 == WINED3DTA_TEMP ||
241 op[i].aarg1 == WINED3DTA_TEMP || op[i].aarg2 == WINED3DTA_TEMP || op[i].aarg0 == WINED3DTA_TEMP)) {
242 lowest_read = i;
245 if(lowest_write == -1 && op[i].dst == tempreg) {
246 lowest_write = i;
249 if(op[i].carg1 == WINED3DTA_TEXTURE || op[i].carg2 == WINED3DTA_TEXTURE || op[i].carg0 == WINED3DTA_TEXTURE ||
250 op[i].aarg1 == WINED3DTA_TEXTURE || op[i].aarg2 == WINED3DTA_TEXTURE || op[i].aarg0 == WINED3DTA_TEXTURE) {
251 tex_used[i] = TRUE;
255 /* Temp reg not read? We don't need it, return GL_NONE */
256 if(lowest_read == -1) return GL_NONE;
258 if(lowest_write >= lowest_read) {
259 FIXME("Temp register read before being written\n");
262 if(lowest_write == -1) {
263 /* This needs a test. Maybe we are supposed to return 0.0/0.0/0.0/0.0, or fail drawprim, or whatever */
264 FIXME("Temp register read without being written\n");
265 return GL_REG_1_ATI;
266 } else if(lowest_write >= 1) {
267 /* If we're writing to the temp reg at earliest in stage 1, we can use register 1 for the temp result.
268 * there may be texture data stored in reg 1, but we do not need it any longer since stage 1 already
269 * read it
271 return GL_REG_1_ATI;
272 } else {
273 /* Search for a free texture register. We have 6 registers available. GL_REG_0_ATI is already used
274 * for the regular result
276 for(i = 1; i < 6; i++) {
277 if(!tex_used[i]) {
278 return GL_REG_0_ATI + i;
281 /* What to do here? Report it in ValidateDevice? */
282 FIXME("Could not find a register for the temporary register\n");
283 return 0;
287 static GLuint gen_ati_shader(struct texture_stage_op op[MAX_TEXTURES], WineD3D_GL_Info *gl_info) {
288 GLuint ret = GL_EXTCALL(glGenFragmentShadersATI(1));
289 unsigned int stage;
290 GLuint arg0, arg1, arg2, extrarg;
291 GLuint dstmod, argmod0, argmod1, argmod2, argmodextra;
292 GLuint rep0, rep1, rep2;
293 GLuint swizzle;
294 GLuint tmparg = find_tmpreg(op);
295 GLuint dstreg;
297 if(!ret) {
298 ERR("Failed to generate a GL_ATI_fragment_shader shader id\n");
299 return 0;
301 GL_EXTCALL(glBindFragmentShaderATI(ret));
302 checkGLcall("GL_EXTCALL(glBindFragmentShaderATI(ret))");
304 TRACE("glBeginFragmentShaderATI()\n");
305 GL_EXTCALL(glBeginFragmentShaderATI());
306 checkGLcall("GL_EXTCALL(glBeginFragmentShaderATI())");
308 /* Pass 1: Generate sampling instructions for perturbation maps */
309 for(stage = 0; stage < GL_LIMITS(textures); stage++) {
310 if(op[stage].cop == WINED3DTOP_DISABLE) break;
311 if(op[stage].cop != WINED3DTOP_BUMPENVMAP &&
312 op[stage].cop != WINED3DTOP_BUMPENVMAPLUMINANCE) continue;
314 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, GL_SWIZZLE_STR_ATI)\n",
315 stage, stage);
316 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI + stage,
317 GL_TEXTURE0_ARB + stage,
318 GL_SWIZZLE_STR_ATI));
319 if(op[stage + 1].projected == proj_none) {
320 swizzle = GL_SWIZZLE_STR_ATI;
321 } else if(op[stage + 1].projected == proj_count4) {
322 swizzle = GL_SWIZZLE_STQ_DQ_ATI;
323 } else {
324 swizzle = GL_SWIZZLE_STR_DR_ATI;
326 TRACE("glPassTexCoordATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, %s)\n",
327 stage + 1, stage + 1, debug_swizzle(swizzle));
328 GL_EXTCALL(glPassTexCoordATI(GL_REG_0_ATI + stage + 1,
329 GL_TEXTURE0_ARB + stage + 1,
330 swizzle));
332 /* We need GL_REG_5_ATI as a temporary register to swizzle the bump matrix. So we run into
333 * issues if we're bump mapping on stage 4 or 5
335 if(stage >= 4) {
336 FIXME("Bump mapping in stage %d\n", stage);
340 /* Pass 2: Generate perturbation calculations */
341 for(stage = 0; stage < GL_LIMITS(textures); stage++) {
342 if(op[stage].cop == WINED3DTOP_DISABLE) break;
343 if(op[stage].cop != WINED3DTOP_BUMPENVMAP &&
344 op[stage].cop != WINED3DTOP_BUMPENVMAPLUMINANCE) continue;
346 /* Nice thing, we get the color correction for free :-) */
347 if(op[stage].color_correction == WINED3DFMT_V8U8) {
348 argmodextra = GL_2X_BIT_ATI | GL_BIAS_BIT_ATI;
349 } else {
350 argmodextra = 0;
353 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",
354 stage + 1, stage, debug_argmod(argmodextra), stage, stage + 1);
355 GL_EXTCALL(glColorFragmentOp3ATI(GL_DOT2_ADD_ATI, GL_REG_0_ATI + stage + 1, GL_RED_BIT_ATI, GL_NONE,
356 GL_REG_0_ATI + stage, GL_NONE, argmodextra,
357 ATI_FFP_CONST_BUMPMAT(stage), GL_NONE, GL_2X_BIT_ATI | GL_BIAS_BIT_ATI,
358 GL_REG_0_ATI + stage + 1, GL_RED, GL_NONE));
360 /* FIXME: How can I make GL_DOT2_ADD_ATI read the factors from blue and alpha? It defaults to red and green,
361 * 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
362 * one register and two instructions in this pass for a simple swizzling operation.
363 * For starters it might be good enough to merge the two movs into one, but even that isn't possible :-(
365 * NOTE: GL_BLUE | GL_ALPHA is not possible. It doesn't throw a compilation error, but an OR operation on the
366 * constants doesn't make sense, considering their values.
368 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);
369 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_5_ATI, GL_RED_BIT_ATI, GL_NONE,
370 ATI_FFP_CONST_BUMPMAT(stage), GL_BLUE, GL_NONE));
371 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);
372 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_5_ATI, GL_GREEN_BIT_ATI, GL_NONE,
373 ATI_FFP_CONST_BUMPMAT(stage), GL_ALPHA, GL_NONE));
374 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",
375 stage + 1, stage, debug_argmod(argmodextra), stage + 1);
376 GL_EXTCALL(glColorFragmentOp3ATI(GL_DOT2_ADD_ATI, GL_REG_0_ATI + stage + 1, GL_GREEN_BIT_ATI, GL_NONE,
377 GL_REG_0_ATI + stage, GL_NONE, argmodextra,
378 GL_REG_5_ATI, GL_NONE, GL_2X_BIT_ATI | GL_BIAS_BIT_ATI,
379 GL_REG_0_ATI + stage + 1, GL_GREEN, GL_NONE));
382 /* Pass 3: Generate sampling instructions for regular textures */
383 for(stage = 0; stage < GL_LIMITS(textures); stage++) {
384 if(op[stage].cop == WINED3DTOP_DISABLE) {
385 break;
388 if(op[stage].projected == proj_none) {
389 swizzle = GL_SWIZZLE_STR_ATI;
390 } else if(op[stage].projected == proj_count3) {
391 swizzle = GL_SWIZZLE_STR_DR_ATI;
392 } else {
393 swizzle = GL_SWIZZLE_STQ_DQ_ATI;
396 if((op[stage].carg0 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
397 (op[stage].carg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
398 (op[stage].carg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
399 (op[stage].aarg0 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
400 (op[stage].aarg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
401 (op[stage].aarg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE ||
402 op[stage].cop == WINED3DTOP_BLENDTEXTUREALPHA) {
404 if(stage > 0 &&
405 (op[stage - 1].cop == WINED3DTOP_BUMPENVMAP ||
406 op[stage - 1].cop == WINED3DTOP_BUMPENVMAPLUMINANCE)) {
407 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_REG_%d_ATI, GL_SWIZZLE_STR_ATI)\n",
408 stage, stage);
409 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI + stage,
410 GL_REG_0_ATI + stage,
411 GL_SWIZZLE_STR_ATI));
412 } else {
413 TRACE("glSampleMapATI(GL_REG_%d_ATI, GL_TEXTURE_%d_ARB, %s)\n",
414 stage, stage, debug_swizzle(swizzle));
415 GL_EXTCALL(glSampleMapATI(GL_REG_0_ATI + stage,
416 GL_TEXTURE0_ARB + stage,
417 swizzle));
422 /* Pass 4: Generate the arithmetic instructions */
423 for(stage = 0; stage < MAX_TEXTURES; stage++) {
424 if(op[stage].cop == WINED3DTOP_DISABLE) {
425 if(stage == 0) {
426 /* Handle complete texture disabling gracefully */
427 TRACE("glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, GL_PRIMARY_COLOR, GL_NONE, GL_NONE)\n");
428 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE,
429 GL_PRIMARY_COLOR, GL_NONE, GL_NONE));
430 TRACE("glAlphaFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_PRIMARY_COLOR, GL_NONE, GL_NONE)\n");
431 GL_EXTCALL(glAlphaFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE,
432 GL_PRIMARY_COLOR, GL_NONE, GL_NONE));
434 break;
437 if(op[stage].dst == tempreg) {
438 /* If we're writing to D3DTA_TEMP, but never reading from it we don't have to write there in the first place.
439 * skip the entire stage, this saves some GPU time
441 if(tmparg == GL_NONE) continue;
443 dstreg = tmparg;
444 } else {
445 dstreg = GL_REG_0_ATI;
448 arg0 = register_for_arg(op[stage].carg0, gl_info, stage, &argmod0, &rep0, tmparg);
449 arg1 = register_for_arg(op[stage].carg1, gl_info, stage, &argmod1, &rep1, tmparg);
450 arg2 = register_for_arg(op[stage].carg2, gl_info, stage, &argmod2, &rep2, tmparg);
451 dstmod = GL_NONE;
452 argmodextra = GL_NONE;
453 extrarg = GL_NONE;
455 switch(op[stage].cop) {
456 case WINED3DTOP_SELECTARG2:
457 arg1 = arg2;
458 argmod1 = argmod2;
459 rep1 = rep2;
460 case WINED3DTOP_SELECTARG1:
461 TRACE("glColorFragmentOp1ATI(GL_MOV_ATI, %s, GL_NONE, GL_NONE, %s, %s, %s)\n",
462 debug_register(dstreg), debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1));
463 GL_EXTCALL(glColorFragmentOp1ATI(GL_MOV_ATI, dstreg, GL_NONE, GL_NONE,
464 arg1, rep1, argmod1));
465 break;
467 case WINED3DTOP_MODULATE4X:
468 if(dstmod == GL_NONE) dstmod = GL_4X_BIT_ATI;
469 case WINED3DTOP_MODULATE2X:
470 if(dstmod == GL_NONE) dstmod = GL_2X_BIT_ATI;
471 dstmod |= GL_SATURATE_BIT_ATI;
472 case WINED3DTOP_MODULATE:
473 TRACE("glColorFragmentOp2ATI(GL_MUL_ATI, %s, GL_NONE, %s, %s, %s, %s, %s, %s, %s)\n",
474 debug_register(dstreg), debug_dstmod(dstmod),
475 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
476 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2));
477 GL_EXTCALL(glColorFragmentOp2ATI(GL_MUL_ATI, dstreg, GL_NONE, dstmod,
478 arg1, rep1, argmod1,
479 arg2, rep2, argmod2));
480 break;
482 case WINED3DTOP_ADDSIGNED2X:
483 dstmod = GL_2X_BIT_ATI;
484 case WINED3DTOP_ADDSIGNED:
485 argmodextra = GL_BIAS_BIT_ATI;
486 case WINED3DTOP_ADD:
487 dstmod |= GL_SATURATE_BIT_ATI;
488 TRACE("glColorFragmentOp2ATI(GL_ADD_ATI, %s, GL_NONE, %s, %s, %s, %s, %s, %s, %s)\n",
489 debug_register(dstreg), debug_dstmod(dstmod),
490 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
491 debug_register(arg2), debug_rep(rep2), debug_argmod(argmodextra | argmod2));
492 GL_EXTCALL(glColorFragmentOp2ATI(GL_ADD_ATI, GL_REG_0_ATI, GL_NONE, dstmod,
493 arg1, rep1, argmod1,
494 arg2, rep2, argmodextra | argmod2));
495 break;
497 case WINED3DTOP_SUBTRACT:
498 dstmod |= GL_SATURATE_BIT_ATI;
499 TRACE("glColorFragmentOp2ATI(GL_SUB_ATI, %s, GL_NONE, %s, %s, %s, %s, %s, %s, %s)\n",
500 debug_register(dstreg), debug_dstmod(dstmod),
501 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
502 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2));
503 GL_EXTCALL(glColorFragmentOp2ATI(GL_SUB_ATI, dstreg, GL_NONE, dstmod,
504 arg1, rep1, argmod1,
505 arg2, rep2, argmod2));
506 break;
508 case WINED3DTOP_ADDSMOOTH:
509 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
510 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_SATURATE_BIT_ATI, %s, %s, %s, %s, %s, %s, %s, %s, %s)\n",
511 debug_register(dstreg),
512 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
513 debug_register(arg1), debug_rep(rep1), debug_argmod(argmodextra),
514 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1));
515 /* Dst = arg1 + * arg2(1 -arg 1)
516 * = arg2 * (1 - arg1) + arg1
518 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
519 arg2, rep2, argmod2,
520 arg1, rep1, argmodextra,
521 arg1, rep1, argmod1));
522 break;
524 case WINED3DTOP_BLENDCURRENTALPHA:
525 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_CURRENT, gl_info, stage, NULL, NULL, -1);
526 case WINED3DTOP_BLENDFACTORALPHA:
527 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TFACTOR, gl_info, stage, NULL, NULL, -1);
528 case WINED3DTOP_BLENDTEXTUREALPHA:
529 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
530 case WINED3DTOP_BLENDDIFFUSEALPHA:
531 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_DIFFUSE, gl_info, stage, NULL, NULL, -1);
532 TRACE("glColorFragmentOp3ATI(GL_LERP_ATI, %s, GL_NONE, GL_NONE, %s, GL_ALPHA, GL_NONE, %s, %s, %s, %s, %s, %s)\n",
533 debug_register(dstreg),
534 debug_register(extrarg),
535 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
536 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2));
537 GL_EXTCALL(glColorFragmentOp3ATI(GL_LERP_ATI, dstreg, GL_NONE, GL_NONE,
538 extrarg, GL_ALPHA, GL_NONE,
539 arg1, rep1, argmod1,
540 arg2, rep2, argmod2));
541 break;
543 case WINED3DTOP_BLENDTEXTUREALPHAPM:
544 arg0 = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
545 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_NONE, %s, %s, %s, %s, GL_ALPHA, GL_COMP_BIT_ATI, %s, %s, %s)\n",
546 debug_register(dstreg),
547 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
548 debug_register(arg0),
549 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1));
550 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE, GL_NONE,
551 arg2, rep2, argmod2,
552 arg0, GL_ALPHA, GL_COMP_BIT_ATI,
553 arg1, rep1, argmod1));
554 break;
556 /* D3DTOP_PREMODULATE ???? */
558 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
559 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
560 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
561 if(!argmodextra) argmodextra = argmod1;
562 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_SATURATE_BIT_ATI, %s, %s, %s, %s, GL_ALPHA, %s, %s, %s, %s)\n",
563 debug_register(dstreg),
564 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
565 debug_register(arg1), debug_argmod(argmodextra), debug_register(arg1), debug_rep(rep1), debug_argmod(arg1));
566 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
567 arg2, rep2, argmod2,
568 arg1, GL_ALPHA, argmodextra,
569 arg1, rep1, argmod1));
570 break;
572 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
573 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
574 case WINED3DTOP_MODULATECOLOR_ADDALPHA:
575 if(!argmodextra) argmodextra = argmod1;
576 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_SATURATE_BIT_ATI, %s, %s, %s, %s, %s, %s, %s, GL_ALPHA, %s)\n",
577 debug_register(dstreg),
578 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
579 debug_register(arg1), debug_rep(rep1), debug_argmod(argmodextra),
580 debug_register(arg1), debug_argmod(argmod1));
581 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
582 arg2, rep2, argmod2,
583 arg1, rep1, argmodextra,
584 arg1, GL_ALPHA, argmod1));
585 break;
587 case WINED3DTOP_DOTPRODUCT3:
588 TRACE("glColorFragmentOp2ATI(GL_DOT3_ATI, %s, GL_NONE, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI, %s, %s, %s, %s, %s, %s)\n",
589 debug_register(dstreg),
590 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1 | GL_BIAS_BIT_ATI),
591 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2 | GL_BIAS_BIT_ATI));
592 GL_EXTCALL(glColorFragmentOp2ATI(GL_DOT3_ATI, dstreg, GL_NONE, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI,
593 arg1, rep1, argmod1 | GL_BIAS_BIT_ATI,
594 arg2, rep2, argmod2 | GL_BIAS_BIT_ATI));
595 break;
597 case WINED3DTOP_MULTIPLYADD:
598 TRACE("glColorFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, GL_SATURATE_BIT_ATI, %s, %s, %s, %s, %s, %s, %s, %s, %s)\n",
599 debug_register(dstreg),
600 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
601 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
602 debug_register(arg0), debug_rep(rep0), debug_argmod(argmod0));
603 GL_EXTCALL(glColorFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE, GL_SATURATE_BIT_ATI,
604 arg1, rep1, argmod1,
605 arg2, rep2, argmod2,
606 arg0, rep0, argmod0));
607 break;
609 case WINED3DTOP_LERP:
610 TRACE("glColorFragmentOp3ATI(GL_LERP_ATI, %s, GL_NONE, GL_NONE, %s, %s, %s, %s, %s, %s, %s, %s, %s)\n",
611 debug_register(dstreg),
612 debug_register(arg1), debug_rep(rep1), debug_argmod(argmod1),
613 debug_register(arg2), debug_rep(rep2), debug_argmod(argmod2),
614 debug_register(arg0), debug_rep(rep0), debug_argmod(argmod0));
615 GL_EXTCALL(glColorFragmentOp3ATI(GL_LERP_ATI, dstreg, GL_NONE, GL_NONE,
616 arg0, rep0, argmod0,
617 arg1, rep1, argmod1,
618 arg2, rep2, argmod2));
619 break;
621 case WINED3DTOP_BUMPENVMAP:
622 case WINED3DTOP_BUMPENVMAPLUMINANCE:
623 /* Those are handled in the first pass of the shader(generation pass 1 and 2) already */
624 break;
626 default: FIXME("Unhandled color operation %d on stage %d\n", op[stage].cop, stage);
629 arg0 = register_for_arg(op[stage].aarg0, gl_info, stage, &argmod0, NULL, tmparg);
630 arg1 = register_for_arg(op[stage].aarg1, gl_info, stage, &argmod1, NULL, tmparg);
631 arg2 = register_for_arg(op[stage].aarg2, gl_info, stage, &argmod2, NULL, tmparg);
632 dstmod = GL_NONE;
633 argmodextra = GL_NONE;
634 extrarg = GL_NONE;
636 switch(op[stage].aop) {
637 case WINED3DTOP_DISABLE:
638 /* Get the primary color to the output if on stage 0, otherwise leave register 0 untouched */
639 if(stage == 0) {
640 TRACE("glAlphaFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_PRIMARY_COLOR, GL_NONE, GL_NONE)\n");
641 GL_EXTCALL(glAlphaFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE,
642 GL_PRIMARY_COLOR, GL_NONE, GL_NONE));
644 break;
646 case WINED3DTOP_SELECTARG2:
647 arg1 = arg2;
648 argmod1 = argmod2;
649 case WINED3DTOP_SELECTARG1:
650 TRACE("glAlphaFragmentOp1ATI(GL_MOV_ATI, %s, GL_NONE, %s, GL_NONE, %s)\n",
651 debug_register(dstreg),
652 debug_register(arg1), debug_argmod(argmod1));
653 GL_EXTCALL(glAlphaFragmentOp1ATI(GL_MOV_ATI, dstreg, GL_NONE,
654 arg1, GL_NONE, argmod1));
655 break;
657 case WINED3DTOP_MODULATE4X:
658 if(dstmod == GL_NONE) dstmod = GL_4X_BIT_ATI;
659 case WINED3DTOP_MODULATE2X:
660 if(dstmod == GL_NONE) dstmod = GL_2X_BIT_ATI;
661 dstmod |= GL_SATURATE_BIT_ATI;
662 case WINED3DTOP_MODULATE:
663 TRACE("glAlphaFragmentOp2ATI(GL_MUL_ATI, %s, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
664 debug_register(dstreg), debug_dstmod(dstmod),
665 debug_register(arg1), debug_argmod(argmod1),
666 debug_register(arg2), debug_argmod(argmod2));
667 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_MUL_ATI, dstreg, dstmod,
668 arg1, GL_NONE, argmod1,
669 arg2, GL_NONE, argmod2));
670 break;
672 case WINED3DTOP_ADDSIGNED2X:
673 dstmod = GL_2X_BIT_ATI;
674 case WINED3DTOP_ADDSIGNED:
675 argmodextra = GL_BIAS_BIT_ATI;
676 case WINED3DTOP_ADD:
677 dstmod |= GL_SATURATE_BIT_ATI;
678 TRACE("glAlphaFragmentOp2ATI(GL_ADD_ATI, %s, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
679 debug_register(dstreg), debug_dstmod(dstmod),
680 debug_register(arg1), debug_argmod(argmod1),
681 debug_register(arg2), debug_argmod(argmodextra | argmod2));
682 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_ADD_ATI, dstreg, dstmod,
683 arg1, GL_NONE, argmod1,
684 arg2, GL_NONE, argmodextra | argmod2));
685 break;
687 case WINED3DTOP_SUBTRACT:
688 dstmod |= GL_SATURATE_BIT_ATI;
689 TRACE("glAlphaFragmentOp2ATI(GL_SUB_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
690 debug_register(dstreg), debug_dstmod(dstmod),
691 debug_register(arg1), debug_argmod(argmod1),
692 debug_register(arg2), debug_argmod(argmod2));
693 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_SUB_ATI, dstreg, dstmod,
694 arg1, GL_NONE, argmod1,
695 arg2, GL_NONE, argmod2));
696 break;
698 case WINED3DTOP_ADDSMOOTH:
699 argmodextra = argmod1 & GL_COMP_BIT_ATI ? argmod1 & ~GL_COMP_BIT_ATI : argmod1 | GL_COMP_BIT_ATI;
700 TRACE("glAlphaFragmentOp3ATI(GL_MAD_ATI, %s, GL_SATURATE_BIT_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
701 debug_register(dstreg),
702 debug_register(arg2), debug_argmod(argmod2),
703 debug_register(arg1), debug_argmod(argmodextra),
704 debug_register(arg1), debug_argmod(argmod1));
705 /* Dst = arg1 + * arg2(1 -arg 1)
706 * = arg2 * (1 - arg1) + arg1
708 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_SATURATE_BIT_ATI,
709 arg2, GL_NONE, argmod2,
710 arg1, GL_NONE, argmodextra,
711 arg1, GL_NONE, argmod1));
712 break;
714 case WINED3DTOP_BLENDCURRENTALPHA:
715 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_CURRENT, gl_info, stage, NULL, NULL, -1);
716 case WINED3DTOP_BLENDFACTORALPHA:
717 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TFACTOR, gl_info, stage, NULL, NULL, -1);
718 case WINED3DTOP_BLENDTEXTUREALPHA:
719 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
720 case WINED3DTOP_BLENDDIFFUSEALPHA:
721 if(extrarg == GL_NONE) extrarg = register_for_arg(WINED3DTA_DIFFUSE, gl_info, stage, NULL, NULL, -1);
722 TRACE("glAlphaFragmentOp3ATI(GL_LERP_ATI, %s, GL_NONE, %s, GL_ALPHA, GL_NONE, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
723 debug_register(dstreg),
724 debug_register(extrarg),
725 debug_register(arg1), debug_argmod(argmod1),
726 debug_register(arg2), debug_argmod(argmod2));
727 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_LERP_ATI, dstreg, GL_NONE,
728 extrarg, GL_ALPHA, GL_NONE,
729 arg1, GL_NONE, argmod1,
730 arg2, GL_NONE, argmod2));
731 break;
733 case WINED3DTOP_BLENDTEXTUREALPHAPM:
734 arg0 = register_for_arg(WINED3DTA_TEXTURE, gl_info, stage, NULL, NULL, -1);
735 TRACE("glAlphaFragmentOp3ATI(GL_MAD_ATI, %s, GL_NONE, %s, GL_NONE, %s, %s, GL_ALPHA, GL_COMP_BIT_ATI, %s, GL_NONE, %s)\n",
736 debug_register(dstreg),
737 debug_register(arg2), debug_argmod(argmod2),
738 debug_register(arg0),
739 debug_register(arg1), debug_argmod(argmod1));
740 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_NONE,
741 arg2, GL_NONE, argmod2,
742 arg0, GL_ALPHA, GL_COMP_BIT_ATI,
743 arg1, GL_NONE, argmod1));
744 break;
746 /* D3DTOP_PREMODULATE ???? */
748 case WINED3DTOP_DOTPRODUCT3:
749 TRACE("glAlphaFragmentOp2ATI(GL_DOT3_ATI, %s, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
750 debug_register(dstreg),
751 debug_register(arg1), debug_argmod(argmod1 | GL_BIAS_BIT_ATI),
752 debug_register(arg2), debug_argmod(argmod2 | GL_BIAS_BIT_ATI));
753 GL_EXTCALL(glAlphaFragmentOp2ATI(GL_DOT3_ATI, dstreg, GL_4X_BIT_ATI | GL_SATURATE_BIT_ATI,
754 arg1, GL_NONE, argmod1 | GL_BIAS_BIT_ATI,
755 arg2, GL_NONE, argmod2 | GL_BIAS_BIT_ATI));
756 break;
758 case WINED3DTOP_MULTIPLYADD:
759 TRACE("glAlphaFragmentOp3ATI(GL_MAD_ATI, %s, GL_SATURATE_BIT_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
760 debug_register(dstreg),
761 debug_register(arg1), debug_argmod(argmod1),
762 debug_register(arg2), debug_argmod(argmod2),
763 debug_register(arg0), debug_argmod(argmod0));
764 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_MAD_ATI, dstreg, GL_SATURATE_BIT_ATI,
765 arg1, GL_NONE, argmod1,
766 arg2, GL_NONE, argmod2,
767 arg0, GL_NONE, argmod0));
768 break;
770 case WINED3DTOP_LERP:
771 TRACE("glAlphaFragmentOp3ATI(GL_LERP_ATI, %s, GL_SATURATE_BIT_ATI, %s, GL_NONE, %s, %s, GL_NONE, %s, %s, GL_NONE, %s)\n",
772 debug_register(dstreg),
773 debug_register(arg1), debug_argmod(argmod1),
774 debug_register(arg2), debug_argmod(argmod2),
775 debug_register(arg0), debug_argmod(argmod0));
776 GL_EXTCALL(glAlphaFragmentOp3ATI(GL_LERP_ATI, dstreg, GL_SATURATE_BIT_ATI,
777 arg1, GL_NONE, argmod1,
778 arg2, GL_NONE, argmod2,
779 arg0, GL_NONE, argmod0));
780 break;
782 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
783 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
784 case WINED3DTOP_MODULATECOLOR_ADDALPHA:
785 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
786 case WINED3DTOP_BUMPENVMAP:
787 case WINED3DTOP_BUMPENVMAPLUMINANCE:
788 ERR("Application uses an invalid alpha operation\n");
789 break;
791 default: FIXME("Unhandled alpha operation %d on stage %d\n", op[stage].aop, stage);
795 TRACE("glEndFragmentShaderATI()\n");
796 GL_EXTCALL(glEndFragmentShaderATI());
797 checkGLcall("GL_EXTCALL(glEndFragmentShaderATI())");
798 return ret;
800 #undef GLINFO_LOCATION
802 #define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
803 static void set_tex_op_atifs(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
804 IWineD3DDeviceImpl *This = stateblock->wineD3DDevice;
805 struct atifs_ffp_desc *desc;
806 struct ffp_settings settings;
807 struct atifs_private_data *priv = (struct atifs_private_data *) This->fragment_priv;
808 DWORD mapped_stage;
809 unsigned int i;
811 gen_ffp_op(stateblock, &settings, TRUE);
812 desc = (struct atifs_ffp_desc *) find_ffp_shader(priv->fragment_shaders, &settings);
813 if(!desc) {
814 desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
815 if(!desc) {
816 ERR("Out of memory\n");
817 return;
819 desc->num_textures_used = 0;
820 for(i = 0; i < GL_LIMITS(texture_stages); i++) {
821 if(settings.op[i].cop == WINED3DTOP_DISABLE) break;
822 desc->num_textures_used = i;
825 memcpy(&desc->parent.settings, &settings, sizeof(settings));
826 desc->shader = gen_ati_shader(settings.op, &GLINFO_LOCATION);
827 add_ffp_shader(priv->fragment_shaders, &desc->parent);
828 TRACE("Allocated fixed function replacement shader descriptor %p\n", desc);
831 /* GL_ATI_fragment_shader depends on the GL_TEXTURE_xD enable settings. Update the texture stages
832 * used by this shader
834 for(i = 0; i < desc->num_textures_used; i++) {
835 mapped_stage = This->texUnitMap[i];
836 if(mapped_stage != -1) {
837 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
838 checkGLcall("glActiveTextureARB");
839 texture_activate_dimensions(i, stateblock, context);
843 GL_EXTCALL(glBindFragmentShaderATI(desc->shader));
846 static void state_texfactor_atifs(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
847 float col[4];
848 D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_TEXTUREFACTOR], col);
850 GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col));
851 checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_TFACTOR, col)");
854 static void set_bumpmat(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
855 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
856 float mat[2][2];
858 mat[0][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT00]);
859 mat[1][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT01]);
860 mat[0][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT10]);
861 mat[1][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT11]);
862 /* GL_ATI_fragment_shader allows only constants from 0.0 to 1.0, but the bumpmat
863 * constants can be in any range. While they should stay between [-1.0 and 1.0] because
864 * Shader Model 1.x pixel shaders are clamped to that range negative values are used occasionally,
865 * for example by our d3d9 test. So to get negative values scale -1;1 to 0;1 and undo that in the
866 * shader(it is free). This might potentially reduce precision. However, if the hardware does
867 * support proper floats it shouldn't, and if it doesn't we can't get anything better anyway
869 mat[0][0] = (mat[0][0] + 1.0) * 0.5;
870 mat[1][0] = (mat[1][0] + 1.0) * 0.5;
871 mat[0][1] = (mat[0][1] + 1.0) * 0.5;
872 mat[1][1] = (mat[1][1] + 1.0) * 0.5;
873 GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), (float *) mat));
874 checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), mat)");
877 static void textransform(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
878 if(!isStateDirty(context, STATE_PIXELSHADER)) {
879 set_tex_op_atifs(state, stateblock, context);
883 #undef GLINFO_LOCATION
885 static const struct StateEntryTemplate atifs_fragmentstate_template[] = {
886 {STATE_RENDER(WINED3DRS_TEXTUREFACTOR), { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), state_texfactor_atifs }, 0 },
887 {STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
888 {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
889 {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
890 {STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
891 {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
892 {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
893 {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
894 {STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
895 {STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
896 {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
897 {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
898 {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
899 {STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
900 {STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
901 {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
902 {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
903 {STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
904 {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
905 {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
906 {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
907 {STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
908 {STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
909 {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
910 {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
911 {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
912 {STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
913 {STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
914 {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
915 {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
916 {STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
917 {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
918 {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
919 {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
920 {STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
921 {STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
922 {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
923 {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
924 {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
925 {STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
926 {STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
927 {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
928 {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
929 {STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
930 {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
931 {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
932 {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
933 {STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
934 {STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
935 {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
936 {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
937 {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
938 {STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
939 {STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
940 {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
941 {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
942 {STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
943 {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
944 {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
945 {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
946 {STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
947 {STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
948 {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
949 {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
950 {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
951 {STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
952 {STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
953 {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
954 {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
955 {STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
956 {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
957 {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
958 {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
959 {STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
960 {STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
961 {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
962 {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
963 {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
964 {STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
965 {STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
966 {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
967 {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
968 {STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
969 {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
970 {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
971 {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
972 {STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
973 {STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
974 {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
975 {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
976 {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
977 {STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
978 {STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
979 {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
980 {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
981 {STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
982 {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
983 {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
984 {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
985 {STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
986 {STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), set_tex_op_atifs }, 0 },
987 {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
988 {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
989 {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
990 {STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), set_bumpmat }, 0 },
991 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, 0 },
992 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, 0 },
993 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, 0 },
994 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texdim }, 0 },
995 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texdim }, 0 },
996 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texdim }, 0 },
997 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texdim }, 0 },
998 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texdim }, 0 },
999 {STATE_TEXTURESTAGE(0,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(0, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, 0 },
1000 {STATE_TEXTURESTAGE(1,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(1, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, 0 },
1001 {STATE_TEXTURESTAGE(2,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(2, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, 0 },
1002 {STATE_TEXTURESTAGE(3,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(3, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, 0 },
1003 {STATE_TEXTURESTAGE(4,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(4, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, 0 },
1004 {STATE_TEXTURESTAGE(5,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(5, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, 0 },
1005 {STATE_TEXTURESTAGE(6,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(6, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, 0 },
1006 {STATE_TEXTURESTAGE(7,WINED3DTSS_TEXTURETRANSFORMFLAGS),{STATE_TEXTURESTAGE(7, WINED3DTSS_TEXTURETRANSFORMFLAGS), textransform }, 0 },
1007 {0 /* Terminate */, { 0, 0 }, 0 },
1010 static void atifs_enable(IWineD3DDevice *iface, BOOL enable) {
1011 if(enable) {
1012 glEnable(GL_FRAGMENT_SHADER_ATI);
1013 checkGLcall("glEnable(GL_FRAGMENT_SHADER_ATI)");
1014 } else {
1015 glDisable(GL_FRAGMENT_SHADER_ATI);
1016 checkGLcall("glDisable(GL_FRAGMENT_SHADER_ATI)");
1020 static void atifs_get_caps(WINED3DDEVTYPE devtype, WineD3D_GL_Info *gl_info, struct fragment_caps *caps) {
1021 caps->TextureOpCaps = WINED3DTEXOPCAPS_DISABLE |
1022 WINED3DTEXOPCAPS_SELECTARG1 |
1023 WINED3DTEXOPCAPS_SELECTARG2 |
1024 WINED3DTEXOPCAPS_MODULATE4X |
1025 WINED3DTEXOPCAPS_MODULATE2X |
1026 WINED3DTEXOPCAPS_MODULATE |
1027 WINED3DTEXOPCAPS_ADDSIGNED2X |
1028 WINED3DTEXOPCAPS_ADDSIGNED |
1029 WINED3DTEXOPCAPS_ADD |
1030 WINED3DTEXOPCAPS_SUBTRACT |
1031 WINED3DTEXOPCAPS_ADDSMOOTH |
1032 WINED3DTEXOPCAPS_BLENDCURRENTALPHA |
1033 WINED3DTEXOPCAPS_BLENDFACTORALPHA |
1034 WINED3DTEXOPCAPS_BLENDTEXTUREALPHA |
1035 WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA |
1036 WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM |
1037 WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
1038 WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
1039 WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA |
1040 WINED3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
1041 WINED3DTEXOPCAPS_DOTPRODUCT3 |
1042 WINED3DTEXOPCAPS_MULTIPLYADD |
1043 WINED3DTEXOPCAPS_LERP |
1044 WINED3DTEXOPCAPS_BUMPENVMAP;
1046 /* TODO: Implement WINED3DTEXOPCAPS_BUMPENVMAPLUMINANCE
1047 and WINED3DTEXOPCAPS_PREMODULATE */
1049 /* GL_ATI_fragment_shader always supports 6 textures, which was the limit on r200 cards
1050 * which this extension is exclusively focused on(later cards have GL_ARB_fragment_program).
1051 * If the current card has more than 8 fixed function textures in OpenGL's regular fixed
1052 * function pipeline then the ATI_fragment_shader backend imposes a stricter limit. This
1053 * shouldn't be too hard since Nvidia cards have a limit of 4 textures with the default ffp
1054 * pipeline, and almost all games are happy with that. We can however support up to 8
1055 * texture stages because we have a 2nd pass limit of 8 instructions, and per stage we use
1056 * only 1 instruction.
1058 * The proper fix for this is not to use GL_ATI_fragment_shader on cards newer than the
1059 * r200 series and use an ARB or GLSL shader instead
1061 caps->MaxTextureBlendStages = 8;
1062 caps->MaxSimultaneousTextures = 6;
1064 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_TSSARGTEMP;
1067 static HRESULT atifs_alloc(IWineD3DDevice *iface) {
1068 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
1069 struct atifs_private_data *priv;
1071 This->fragment_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct atifs_private_data));
1072 if(!This->fragment_priv) {
1073 ERR("Out of memory\n");
1074 return E_OUTOFMEMORY;
1076 priv = (struct atifs_private_data *) This->fragment_priv;
1077 priv->fragment_shaders = hash_table_create(ffp_program_key_hash, ffp_program_key_compare);
1078 return WINED3D_OK;
1081 #define GLINFO_LOCATION This->adapter->gl_info
1082 static void atifs_free_ffpshader(void *value, void *device) {
1083 IWineD3DDeviceImpl *This = device;
1084 struct atifs_ffp_desc *entry_ati = value;
1086 ENTER_GL();
1087 GL_EXTCALL(glDeleteFragmentShaderATI(entry_ati->shader));
1088 checkGLcall("glDeleteFragmentShaderATI(entry->shader)");
1089 HeapFree(GetProcessHeap(), 0, entry_ati);
1090 LEAVE_GL();
1093 static void atifs_free(IWineD3DDevice *iface) {
1094 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
1095 struct atifs_private_data *priv = (struct atifs_private_data *) This->fragment_priv;
1097 hash_table_destroy(priv->fragment_shaders, atifs_free_ffpshader, This);
1099 HeapFree(GetProcessHeap(), 0, priv);
1100 This->fragment_priv = NULL;
1102 #undef GLINFO_LOCATION
1104 static BOOL atifs_conv_supported(WINED3DFORMAT fmt) {
1105 TRACE("Checking shader format support for format %s:", debug_d3dformat(fmt));
1106 switch(fmt) {
1107 case WINED3DFMT_V8U8:
1108 case WINED3DFMT_V16U16:
1109 TRACE("[OK]\n");
1110 return TRUE;
1111 default:
1112 TRACE("[FAILED\n");
1113 return FALSE;
1117 const struct fragment_pipeline atifs_fragment_pipeline = {
1118 atifs_enable,
1119 atifs_get_caps,
1120 atifs_alloc,
1121 atifs_free,
1122 atifs_conv_supported,
1123 atifs_fragmentstate_template,
1124 TRUE /* We can disable projected textures */