wined3d: Make the device parameter to is_display_mode_supported() const.
[wine] / dlls / wined3d / nvidia_texture_shader.c
1 /*
2  * Fixed function pipeline replacement using GL_NV_register_combiners
3  * and GL_NV_texture_shader
4  *
5  * Copyright 2006 Henri Verbeet
6  * Copyright 2008 Stefan Dösinger(for CodeWeavers)
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22 #include "config.h"
23
24 #include <math.h>
25 #include <stdio.h>
26
27 #include "wined3d_private.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
30
31 /* GL locking for state handlers is done by the caller. */
32
33 static void nvts_activate_dimensions(const struct wined3d_state *state, DWORD stage, struct wined3d_context *context)
34 {
35     BOOL bumpmap = FALSE;
36
37     if (stage > 0 && (state->texture_states[stage - 1][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAPLUMINANCE
38             || state->texture_states[stage - 1][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAP))
39     {
40         bumpmap = TRUE;
41         context->texShaderBumpMap |= (1 << stage);
42     } else {
43         context->texShaderBumpMap &= ~(1 << stage);
44     }
45
46     if (state->textures[stage])
47     {
48         switch (state->textures[stage]->target)
49         {
50             case GL_TEXTURE_2D:
51                 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_2D);
52                 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
53                 break;
54             case GL_TEXTURE_RECTANGLE_ARB:
55                 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_RECTANGLE_ARB);
56                 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
57                 break;
58             case GL_TEXTURE_3D:
59                 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D);
60                 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D)");
61                 break;
62             case GL_TEXTURE_CUBE_MAP_ARB:
63                 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB);
64                 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB)");
65                 break;
66         }
67     } else {
68         glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
69         checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE)");
70     }
71 }
72
73 struct tex_op_args
74 {
75     GLenum input[3];
76     GLenum mapping[3];
77     GLenum component_usage[3];
78 };
79
80 static GLenum d3dta_to_combiner_input(DWORD d3dta, DWORD stage, INT texture_idx) {
81     switch (d3dta) {
82         case WINED3DTA_DIFFUSE:
83             return GL_PRIMARY_COLOR_NV;
84
85         case WINED3DTA_CURRENT:
86             if (stage) return GL_SPARE0_NV;
87             else return GL_PRIMARY_COLOR_NV;
88
89         case WINED3DTA_TEXTURE:
90             if (texture_idx > -1) return GL_TEXTURE0_ARB + texture_idx;
91             else return GL_PRIMARY_COLOR_NV;
92
93         case WINED3DTA_TFACTOR:
94             return GL_CONSTANT_COLOR0_NV;
95
96         case WINED3DTA_SPECULAR:
97             return GL_SECONDARY_COLOR_NV;
98
99         case WINED3DTA_TEMP:
100             return GL_SPARE1_NV;
101
102         case WINED3DTA_CONSTANT:
103             /* TODO: Support per stage constants (WINED3DTSS_CONSTANT, NV_register_combiners2) */
104             FIXME("WINED3DTA_CONSTANT, not properly supported.\n");
105             return GL_CONSTANT_COLOR1_NV;
106
107         default:
108             FIXME("Unrecognized texture arg %#x\n", d3dta);
109             return GL_TEXTURE;
110     }
111 }
112
113 static GLenum invert_mapping(GLenum mapping) {
114     if (mapping == GL_UNSIGNED_INVERT_NV) return GL_UNSIGNED_IDENTITY_NV;
115     else if (mapping == GL_UNSIGNED_IDENTITY_NV) return GL_UNSIGNED_INVERT_NV;
116
117     FIXME("Unhandled mapping %#x\n", mapping);
118     return mapping;
119 }
120
121 static void get_src_and_opr_nvrc(DWORD stage, DWORD arg, BOOL is_alpha, GLenum* input, GLenum* mapping, GLenum *component_usage, INT texture_idx) {
122     /* The WINED3DTA_COMPLEMENT flag specifies the complement of the input should
123     * be used. */
124     if (arg & WINED3DTA_COMPLEMENT) *mapping = GL_UNSIGNED_INVERT_NV;
125     else *mapping = GL_UNSIGNED_IDENTITY_NV; /* Clamp all values to positive ranges */
126
127     /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the input
128     * should be used for all input components. */
129     if (is_alpha || arg & WINED3DTA_ALPHAREPLICATE) *component_usage = GL_ALPHA;
130     else *component_usage = GL_RGB;
131
132     *input = d3dta_to_combiner_input(arg & WINED3DTA_SELECTMASK, stage, texture_idx);
133 }
134
135 void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state, BOOL is_alpha,
136         int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst)
137 {
138     struct tex_op_args tex_op_args = {{0}, {0}, {0}};
139     GLenum portion = is_alpha ? GL_ALPHA : GL_RGB;
140     GLenum target = GL_COMBINER0_NV + stage;
141     GLenum output;
142
143     TRACE("stage %d, is_alpha %d, op %s, arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n",
144           stage, is_alpha, debug_d3dtop(op), arg1, arg2, arg3, texture_idx);
145
146     /* If a texture stage references an invalid texture unit the stage just
147     * passes through the result from the previous stage */
148     if (is_invalid_op(state, stage, op, arg1, arg2, arg3))
149     {
150         arg1 = WINED3DTA_CURRENT;
151         op = WINED3DTOP_SELECTARG1;
152     }
153
154     get_src_and_opr_nvrc(stage, arg1, is_alpha, &tex_op_args.input[0],
155                          &tex_op_args.mapping[0], &tex_op_args.component_usage[0], texture_idx);
156     get_src_and_opr_nvrc(stage, arg2, is_alpha, &tex_op_args.input[1],
157                          &tex_op_args.mapping[1], &tex_op_args.component_usage[1], texture_idx);
158     get_src_and_opr_nvrc(stage, arg3, is_alpha, &tex_op_args.input[2],
159                          &tex_op_args.mapping[2], &tex_op_args.component_usage[2], texture_idx);
160
161
162     if(dst == WINED3DTA_TEMP) {
163         output = GL_SPARE1_NV;
164     } else {
165         output = GL_SPARE0_NV;
166     }
167
168     /* This is called by a state handler which has the gl lock held and a context for the thread */
169     switch(op)
170     {
171         case WINED3DTOP_DISABLE:
172             /* Only for alpha */
173             if (!is_alpha) ERR("Shouldn't be called for WINED3DTSS_COLOROP (WINED3DTOP_DISABLE)\n");
174             /* Input, prev_alpha*1 */
175             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
176                        GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
177             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
178                        GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
179
180             /* Output */
181             GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
182                        GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
183             break;
184
185         case WINED3DTOP_SELECTARG1:
186         case WINED3DTOP_SELECTARG2:
187             /* Input, arg*1 */
188             if (op == WINED3DTOP_SELECTARG1) {
189                 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
190                            tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
191             } else {
192                 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
193                            tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
194             }
195             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
196                        GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
197
198             /* Output */
199             GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
200                        GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
201             break;
202
203         case WINED3DTOP_MODULATE:
204         case WINED3DTOP_MODULATE2X:
205         case WINED3DTOP_MODULATE4X:
206             /* Input, arg1*arg2 */
207             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
208                        tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
209             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
210                        tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
211
212             /* Output */
213             if (op == WINED3DTOP_MODULATE) {
214                 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
215                            GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
216             } else if (op == WINED3DTOP_MODULATE2X) {
217                 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
218                            GL_DISCARD_NV, GL_SCALE_BY_TWO_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
219             } else if (op == WINED3DTOP_MODULATE4X) {
220                 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
221                            GL_DISCARD_NV, GL_SCALE_BY_FOUR_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
222             }
223             break;
224
225         case WINED3DTOP_ADD:
226         case WINED3DTOP_ADDSIGNED:
227         case WINED3DTOP_ADDSIGNED2X:
228             /* Input, arg1*1+arg2*1 */
229             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
230                        tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
231             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
232                        GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
233             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
234                        tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
235             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
236                        GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
237
238             /* Output */
239             if (op == WINED3DTOP_ADD) {
240                 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
241                            output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
242             } else if (op == WINED3DTOP_ADDSIGNED) {
243                 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
244                            output, GL_NONE, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
245             } else if (op == WINED3DTOP_ADDSIGNED2X) {
246                 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
247                            output, GL_SCALE_BY_TWO_NV, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
248             }
249             break;
250
251         case WINED3DTOP_SUBTRACT:
252             /* Input, arg1*1+-arg2*1 */
253             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
254                        tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
255             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
256                        GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
257             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
258                        tex_op_args.input[1], GL_SIGNED_NEGATE_NV, tex_op_args.component_usage[1]));
259             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
260                        GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
261
262             /* Output */
263             GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
264                        output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
265             break;
266
267         case WINED3DTOP_ADDSMOOTH:
268             /* Input, arg1*1+(1-arg1)*arg2 */
269             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
270                        tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
271             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
272                        GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
273             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
274                        tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
275             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
276                        tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
277
278             /* Output */
279             GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
280                        output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
281             break;
282
283         case WINED3DTOP_BLENDDIFFUSEALPHA:
284         case WINED3DTOP_BLENDTEXTUREALPHA:
285         case WINED3DTOP_BLENDFACTORALPHA:
286         case WINED3DTOP_BLENDTEXTUREALPHAPM:
287         case WINED3DTOP_BLENDCURRENTALPHA:
288         {
289             GLenum alpha_src = GL_PRIMARY_COLOR_NV;
290             if (op == WINED3DTOP_BLENDDIFFUSEALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_DIFFUSE, stage, texture_idx);
291             else if (op == WINED3DTOP_BLENDTEXTUREALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
292             else if (op == WINED3DTOP_BLENDFACTORALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TFACTOR, stage, texture_idx);
293             else if (op == WINED3DTOP_BLENDTEXTUREALPHAPM) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
294             else if (op == WINED3DTOP_BLENDCURRENTALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_CURRENT, stage, texture_idx);
295             else FIXME("Unhandled WINED3DTOP %s, shouldn't happen\n", debug_d3dtop(op));
296
297             /* Input, arg1*alpha_src+arg2*(1-alpha_src) */
298             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
299                        tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
300             if (op == WINED3DTOP_BLENDTEXTUREALPHAPM)
301             {
302                 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
303                            GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
304             } else {
305                 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
306                            alpha_src, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
307             }
308             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
309                        tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
310             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
311                        alpha_src, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
312
313             /* Output */
314             GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
315                        output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
316             break;
317         }
318
319         case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
320             /* Input, arg1_alpha*arg2_rgb+arg1_rgb*1 */
321             if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEALPHA_ADDCOLOR)\n");
322             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
323                        tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
324             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
325                        tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
326             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
327                        tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
328             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
329                        GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
330
331             /* Output */
332             GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
333                        output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
334             break;
335
336         case WINED3DTOP_MODULATECOLOR_ADDALPHA:
337             /* Input, arg1_rgb*arg2_rgb+arg1_alpha*1 */
338             if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATECOLOR_ADDALPHA)\n");
339             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
340                        tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
341             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
342                        tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
343             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
344                        tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
345             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
346                        GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
347
348             /* Output */
349             GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
350                        output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
351             break;
352
353         case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
354             /* Input, (1-arg1_alpha)*arg2_rgb+arg1_rgb*1 */
355             if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEINVALPHA_ADDCOLOR)\n");
356             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
357                        tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), GL_ALPHA));
358             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
359                        tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
360             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
361                        tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
362             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
363                        GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
364
365             /* Output */
366             GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
367                        output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
368             break;
369
370         case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
371             /* Input, (1-arg1_rgb)*arg2_rgb+arg1_alpha*1 */
372             if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEINVCOLOR_ADDALPHA)\n");
373             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
374                        tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
375             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
376                        tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
377             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
378                        tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
379             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
380                        GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
381
382             /* Output */
383             GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
384                        output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
385             break;
386
387         case WINED3DTOP_DOTPRODUCT3:
388             /* Input, arg1 . arg2 */
389             /* FIXME: DX7 uses a different calculation? */
390             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
391                        tex_op_args.input[0], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[0]));
392             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
393                        tex_op_args.input[1], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[1]));
394
395             /* Output */
396             GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
397                        GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_FALSE, GL_FALSE));
398             break;
399
400         case WINED3DTOP_MULTIPLYADD:
401             /* Input, arg3*1+arg1*arg2 */
402             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
403                        tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
404             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
405                        GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
406             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
407                        tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
408             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
409                        tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
410
411             /* Output */
412             GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
413                        output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
414             break;
415
416         case WINED3DTOP_LERP:
417             /* Input, arg3*arg1+(1-arg3)*arg2 */
418             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
419                        tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
420             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
421                        tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
422             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
423                        tex_op_args.input[2], invert_mapping(tex_op_args.mapping[2]), tex_op_args.component_usage[2]));
424             GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
425                        tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
426
427             /* Output */
428             GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
429                        output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
430             break;
431
432         case WINED3DTOP_BUMPENVMAPLUMINANCE:
433         case WINED3DTOP_BUMPENVMAP:
434             if (gl_info->supported[NV_TEXTURE_SHADER])
435             {
436                 /* The bump map stage itself isn't exciting, just read the texture. But tell the next stage to
437                  * perform bump mapping and source from the current stage. Pretty much a SELECTARG2.
438                  * ARG2 is passed through unmodified(apps will most likely use D3DTA_CURRENT for arg2, arg1
439                  * (which will most likely be D3DTA_TEXTURE) is available as a texture shader input for the next stage
440                  */
441                 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
442                            tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
443                 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
444                            GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
445                 /* Always pass through to CURRENT, ignore temp arg */
446                 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
447                            GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
448                 break;
449             }
450
451         default:
452             FIXME("Unhandled WINED3DTOP: stage %d, is_alpha %d, op %s (%#x), arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n",
453                   stage, is_alpha, debug_d3dtop(op), op, arg1, arg2, arg3, texture_idx);
454     }
455
456     checkGLcall("set_tex_op_nvrc()");
457 }
458
459
460 static void nvrc_colorop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
461 {
462     DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
463     const struct wined3d_device *device = context->swapchain->device;
464     BOOL tex_used = device->fixed_function_usage_map & (1 << stage);
465     DWORD mapped_stage = device->texUnitMap[stage];
466     const struct wined3d_gl_info *gl_info = context->gl_info;
467
468     TRACE("Setting color op for stage %u.\n", stage);
469
470     /* Using a pixel shader? Don't care for anything here, the shader applying does it */
471     if (use_ps(state)) return;
472
473     if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
474
475     if (mapped_stage != WINED3D_UNMAPPED_STAGE)
476     {
477         if (tex_used && mapped_stage >= gl_info->limits.textures)
478         {
479             FIXME("Attempt to enable unsupported stage!\n");
480             return;
481         }
482         context_active_texture(context, gl_info, mapped_stage);
483     }
484
485     if (state->lowest_disabled_stage > 0)
486     {
487         glEnable(GL_REGISTER_COMBINERS_NV);
488         GL_EXTCALL(glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, state->lowest_disabled_stage));
489     }
490     else
491     {
492         glDisable(GL_REGISTER_COMBINERS_NV);
493     }
494     if (stage >= state->lowest_disabled_stage)
495     {
496         TRACE("Stage disabled\n");
497         if (mapped_stage != WINED3D_UNMAPPED_STAGE)
498         {
499             /* Disable everything here */
500             glDisable(GL_TEXTURE_2D);
501             checkGLcall("glDisable(GL_TEXTURE_2D)");
502             glDisable(GL_TEXTURE_3D);
503             checkGLcall("glDisable(GL_TEXTURE_3D)");
504             if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
505             {
506                 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
507                 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
508             }
509             if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
510             {
511                 glDisable(GL_TEXTURE_RECTANGLE_ARB);
512                 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
513             }
514             if (gl_info->supported[NV_TEXTURE_SHADER2] && mapped_stage < gl_info->limits.textures)
515             {
516                 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
517             }
518         }
519         /* All done */
520         return;
521     }
522
523     /* The sampler will also activate the correct texture dimensions, so no need to do it here
524      * if the sampler for this stage is dirty
525      */
526     if (!isStateDirty(context, STATE_SAMPLER(stage)))
527     {
528         if (tex_used)
529         {
530             if (gl_info->supported[NV_TEXTURE_SHADER2])
531             {
532                 nvts_activate_dimensions(state, stage, context);
533             }
534             else
535             {
536                 texture_activate_dimensions(state->textures[stage], gl_info);
537             }
538         }
539     }
540
541     /* Set the texture combiners */
542     set_tex_op_nvrc(gl_info, state, FALSE, stage,
543             state->texture_states[stage][WINED3DTSS_COLOROP],
544             state->texture_states[stage][WINED3DTSS_COLORARG1],
545             state->texture_states[stage][WINED3DTSS_COLORARG2],
546             state->texture_states[stage][WINED3DTSS_COLORARG0],
547             mapped_stage,
548             state->texture_states[stage][WINED3DTSS_RESULTARG]);
549
550     /* In register combiners bump mapping is done in the stage AFTER the one that has the bump map operation set,
551      * thus the texture shader may have to be updated
552      */
553     if (gl_info->supported[NV_TEXTURE_SHADER2])
554     {
555         BOOL usesBump = (state->texture_states[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAPLUMINANCE
556                 || state->texture_states[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAP);
557         BOOL usedBump = !!(context->texShaderBumpMap & 1 << (stage + 1));
558         if (usesBump != usedBump)
559         {
560             context_active_texture(context, gl_info, mapped_stage + 1);
561             nvts_activate_dimensions(state, stage + 1, context);
562             context_active_texture(context, gl_info, mapped_stage);
563         }
564     }
565 }
566
567 static void nvts_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
568 {
569     DWORD sampler = state_id - STATE_SAMPLER(0);
570     DWORD mapped_stage = context->swapchain->device->texUnitMap[sampler];
571
572     /* No need to enable / disable anything here for unused samplers. The tex_colorop
573     * handler takes care. Also no action is needed with pixel shaders, or if tex_colorop
574     * will take care of this business
575     */
576     if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures) return;
577     if (sampler >= state->lowest_disabled_stage) return;
578     if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) return;
579
580     nvts_activate_dimensions(state, sampler, context);
581 }
582
583 static void nvts_bumpenvmat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
584 {
585     DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
586     DWORD mapped_stage = context->swapchain->device->texUnitMap[stage + 1];
587     const struct wined3d_gl_info *gl_info = context->gl_info;
588     float mat[2][2];
589
590     /* Direct3D sets the matrix in the stage reading the perturbation map. The result is used to
591      * offset the destination stage(always stage + 1 in d3d). In GL_NV_texture_shader, the bump
592      * map offsetting is done in the stage reading the bump mapped texture, and the perturbation
593      * map is read from a specified source stage(always stage - 1 for d3d). Thus set the matrix
594      * for stage + 1. Keep the nvrc tex unit mapping in mind too
595      */
596     if (mapped_stage < gl_info->limits.textures)
597     {
598         context_active_texture(context, gl_info, mapped_stage);
599
600         /* We can't just pass a pointer to the state to GL due to the
601          * different matrix format (column major vs row major). */
602         mat[0][0] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT00]);
603         mat[1][0] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT01]);
604         mat[0][1] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT10]);
605         mat[1][1] = *((float *)&state->texture_states[stage][WINED3DTSS_BUMPENVMAT11]);
606         glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float *)mat);
607         checkGLcall("glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, mat)");
608     }
609 }
610
611 static void nvrc_texfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
612 {
613     const struct wined3d_gl_info *gl_info = context->gl_info;
614     float col[4];
615     D3DCOLORTOGLFLOAT4(state->render_states[WINED3DRS_TEXTUREFACTOR], col);
616     GL_EXTCALL(glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &col[0]));
617 }
618
619 /* Context activation is done by the caller. */
620 static void nvrc_enable(BOOL enable) {}
621
622 /* Context activation and GL locking are done by the caller. */
623 static void nvts_enable(BOOL enable)
624 {
625     if(enable) {
626         glEnable(GL_TEXTURE_SHADER_NV);
627         checkGLcall("glEnable(GL_TEXTURE_SHADER_NV)");
628     } else {
629         glDisable(GL_TEXTURE_SHADER_NV);
630         checkGLcall("glDisable(GL_TEXTURE_SHADER_NV)");
631     }
632 }
633
634 static void nvrc_fragment_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
635 {
636     caps->PrimitiveMiscCaps = WINED3DPMISCCAPS_TSSARGTEMP;
637
638     /* The caps below can be supported but aren't handled yet in utils.c
639      * 'd3dta_to_combiner_input', disable them until support is fixed */
640 #if 0
641     if (gl_info->supported[NV_REGISTER_COMBINERS2])
642         caps->PrimitiveMiscCaps |=  WINED3DPMISCCAPS_PERSTAGECONSTANT;
643 #endif
644
645     caps->TextureOpCaps = WINED3DTEXOPCAPS_ADD
646             | WINED3DTEXOPCAPS_ADDSIGNED
647             | WINED3DTEXOPCAPS_ADDSIGNED2X
648             | WINED3DTEXOPCAPS_MODULATE
649             | WINED3DTEXOPCAPS_MODULATE2X
650             | WINED3DTEXOPCAPS_MODULATE4X
651             | WINED3DTEXOPCAPS_SELECTARG1
652             | WINED3DTEXOPCAPS_SELECTARG2
653             | WINED3DTEXOPCAPS_DISABLE
654             | WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA
655             | WINED3DTEXOPCAPS_BLENDTEXTUREALPHA
656             | WINED3DTEXOPCAPS_BLENDFACTORALPHA
657             | WINED3DTEXOPCAPS_BLENDCURRENTALPHA
658             | WINED3DTEXOPCAPS_LERP
659             | WINED3DTEXOPCAPS_SUBTRACT
660             | WINED3DTEXOPCAPS_ADDSMOOTH
661             | WINED3DTEXOPCAPS_MULTIPLYADD
662             | WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
663             | WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
664             | WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM
665             | WINED3DTEXOPCAPS_DOTPRODUCT3
666             | WINED3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
667             | WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA;
668
669     if (gl_info->supported[NV_TEXTURE_SHADER2])
670     {
671         /* Bump mapping is supported already in NV_TEXTURE_SHADER, but that extension does
672          * not support 3D textures. This asks for trouble if an app uses both bump mapping
673          * and 3D textures. It also allows us to keep the code simpler by having texture
674          * shaders constantly enabled. */
675         caps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAP;
676         /* TODO: Luminance bump map? */
677     }
678
679 #if 0
680     /* FIXME: Add
681             caps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAPLUMINANCE
682             WINED3DTEXOPCAPS_PREMODULATE */
683 #endif
684
685     caps->MaxTextureBlendStages = min(MAX_TEXTURES, gl_info->limits.general_combiners);
686     caps->MaxSimultaneousTextures = gl_info->limits.textures;
687 }
688
689 static HRESULT nvrc_fragment_alloc(struct wined3d_device *device) { return WINED3D_OK; }
690 /* Context activation is done by the caller. */
691 static void nvrc_fragment_free(struct wined3d_device *device) {}
692
693 /* Two fixed function pipeline implementations using GL_NV_register_combiners and
694  * GL_NV_texture_shader. The nvts_fragment_pipeline assumes that both extensions
695  * are available(geforce 3 and newer), while nvrc_fragment_pipeline uses only the
696  * register combiners extension(Pre-GF3).
697  */
698
699 static BOOL nvts_color_fixup_supported(struct color_fixup_desc fixup)
700 {
701     if (TRACE_ON(d3d))
702     {
703         TRACE("Checking support for fixup:\n");
704         dump_color_fixup_desc(fixup);
705     }
706
707     /* We only support identity conversions. */
708     if (is_identity_fixup(fixup))
709     {
710         TRACE("[OK]\n");
711         return TRUE;
712     }
713
714     TRACE("[FAILED]\n");
715     return FALSE;
716 }
717
718 static const struct StateEntryTemplate nvrc_fragmentstate_template[] = {
719     { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          nvrc_colorop        }, WINED3D_GL_EXT_NONE             },
720     { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG1),        { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
721     { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG2),        { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
722     { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         }, WINED3D_GL_EXT_NONE             },
723     { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
724     { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
725     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     nvts_bumpenvmat     }, NV_TEXTURE_SHADER2              },
726     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
727     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
728     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
729     { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
730     { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
731     { STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
732     { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          nvrc_colorop        }, WINED3D_GL_EXT_NONE             },
733     { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG1),        { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
734     { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG2),        { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
735     { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         }, WINED3D_GL_EXT_NONE             },
736     { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
737     { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
738     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     nvts_bumpenvmat     }, NV_TEXTURE_SHADER2              },
739     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
740     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
741     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
742     { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
743     { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
744     { STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
745     { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          nvrc_colorop        }, WINED3D_GL_EXT_NONE             },
746     { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG1),        { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
747     { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG2),        { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
748     { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         }, WINED3D_GL_EXT_NONE             },
749     { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
750     { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
751     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     nvts_bumpenvmat     }, NV_TEXTURE_SHADER2              },
752     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
753     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
754     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
755     { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
756     { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
757     { STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
758     { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          nvrc_colorop        }, WINED3D_GL_EXT_NONE             },
759     { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG1),        { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
760     { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG2),        { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
761     { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         }, WINED3D_GL_EXT_NONE             },
762     { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
763     { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
764     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     nvts_bumpenvmat     }, NV_TEXTURE_SHADER2              },
765     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
766     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
767     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
768     { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
769     { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
770     { STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
771     { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          nvrc_colorop        }, WINED3D_GL_EXT_NONE             },
772     { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG1),        { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
773     { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG2),        { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
774     { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         }, WINED3D_GL_EXT_NONE             },
775     { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
776     { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
777     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     nvts_bumpenvmat     }, NV_TEXTURE_SHADER2              },
778     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
779     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
780     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
781     { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
782     { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
783     { STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
784     { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          nvrc_colorop        }, WINED3D_GL_EXT_NONE             },
785     { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG1),        { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
786     { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG2),        { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
787     { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         }, WINED3D_GL_EXT_NONE             },
788     { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
789     { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
790     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     nvts_bumpenvmat     }, NV_TEXTURE_SHADER2              },
791     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
792     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
793     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
794     { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
795     { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
796     { STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
797     { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          nvrc_colorop        }, WINED3D_GL_EXT_NONE             },
798     { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG1),        { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
799     { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG2),        { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
800     { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         }, WINED3D_GL_EXT_NONE             },
801     { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
802     { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
803     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     nvts_bumpenvmat     }, NV_TEXTURE_SHADER2              },
804     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
805     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
806     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
807     { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
808     { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
809     { STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
810     { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          nvrc_colorop        }, WINED3D_GL_EXT_NONE             },
811     { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG1),        { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
812     { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG2),        { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
813     { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         }, WINED3D_GL_EXT_NONE             },
814     { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
815     { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
816     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     nvts_bumpenvmat     }, NV_TEXTURE_SHADER2              },
817     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
818     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
819     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     NULL                }, NV_TEXTURE_SHADER2              },
820     { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
821     { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          NULL                }, WINED3D_GL_EXT_NONE             },
822     { STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          NULL                }, WINED3D_GL_EXT_NONE             },
823     { STATE_PIXELSHADER,                                  { STATE_PIXELSHADER,                                  apply_pixelshader   }, WINED3D_GL_EXT_NONE             },
824     { STATE_RENDER(WINED3DRS_SRGBWRITEENABLE),            { STATE_PIXELSHADER,                                  NULL                }, WINED3D_GL_EXT_NONE             },
825     { STATE_RENDER(WINED3DRS_TEXTUREFACTOR),              { STATE_RENDER(WINED3DRS_TEXTUREFACTOR),              nvrc_texfactor      }, WINED3D_GL_EXT_NONE             },
826     { STATE_RENDER(WINED3DRS_FOGCOLOR),                   { STATE_RENDER(WINED3DRS_FOGCOLOR),                   state_fogcolor      }, WINED3D_GL_EXT_NONE             },
827     { STATE_RENDER(WINED3DRS_FOGDENSITY),                 { STATE_RENDER(WINED3DRS_FOGDENSITY),                 state_fogdensity    }, WINED3D_GL_EXT_NONE             },
828     { STATE_RENDER(WINED3DRS_FOGENABLE),                  { STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog_fragpart  }, WINED3D_GL_EXT_NONE             },
829     { STATE_RENDER(WINED3DRS_FOGTABLEMODE),               { STATE_RENDER(WINED3DRS_FOGENABLE),                  NULL                }, WINED3D_GL_EXT_NONE             },
830     { STATE_RENDER(WINED3DRS_FOGVERTEXMODE),              { STATE_RENDER(WINED3DRS_FOGENABLE),                  NULL                }, WINED3D_GL_EXT_NONE             },
831     { STATE_RENDER(WINED3DRS_FOGSTART),                   { STATE_RENDER(WINED3DRS_FOGSTART),                   state_fogstartend   }, WINED3D_GL_EXT_NONE             },
832     { STATE_RENDER(WINED3DRS_FOGEND),                     { STATE_RENDER(WINED3DRS_FOGSTART),                   NULL                }, WINED3D_GL_EXT_NONE             },
833     { STATE_SAMPLER(0),                                   { STATE_SAMPLER(0),                                   nvts_texdim         }, NV_TEXTURE_SHADER2              },
834     { STATE_SAMPLER(0),                                   { STATE_SAMPLER(0),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
835     { STATE_SAMPLER(1),                                   { STATE_SAMPLER(1),                                   nvts_texdim         }, NV_TEXTURE_SHADER2              },
836     { STATE_SAMPLER(1),                                   { STATE_SAMPLER(1),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
837     { STATE_SAMPLER(2),                                   { STATE_SAMPLER(2),                                   nvts_texdim         }, NV_TEXTURE_SHADER2              },
838     { STATE_SAMPLER(2),                                   { STATE_SAMPLER(2),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
839     { STATE_SAMPLER(3),                                   { STATE_SAMPLER(3),                                   nvts_texdim         }, NV_TEXTURE_SHADER2              },
840     { STATE_SAMPLER(3),                                   { STATE_SAMPLER(3),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
841     { STATE_SAMPLER(4),                                   { STATE_SAMPLER(4),                                   nvts_texdim         }, NV_TEXTURE_SHADER2              },
842     { STATE_SAMPLER(4),                                   { STATE_SAMPLER(4),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
843     { STATE_SAMPLER(5),                                   { STATE_SAMPLER(5),                                   nvts_texdim         }, NV_TEXTURE_SHADER2              },
844     { STATE_SAMPLER(5),                                   { STATE_SAMPLER(5),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
845     { STATE_SAMPLER(6),                                   { STATE_SAMPLER(6),                                   nvts_texdim         }, NV_TEXTURE_SHADER2              },
846     { STATE_SAMPLER(6),                                   { STATE_SAMPLER(6),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
847     { STATE_SAMPLER(7),                                   { STATE_SAMPLER(7),                                   nvts_texdim         }, NV_TEXTURE_SHADER2              },
848     { STATE_SAMPLER(7),                                   { STATE_SAMPLER(7),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
849     {0 /* Terminate */,                                   { 0,                                                  0                   }, WINED3D_GL_EXT_NONE             },
850 };
851
852 const struct fragment_pipeline nvts_fragment_pipeline = {
853     nvts_enable,
854     nvrc_fragment_get_caps,
855     nvrc_fragment_alloc,
856     nvrc_fragment_free,
857     nvts_color_fixup_supported,
858     nvrc_fragmentstate_template,
859     FALSE /* we cannot disable projected textures. The vertex pipe has to do it */
860 };
861
862 const struct fragment_pipeline nvrc_fragment_pipeline = {
863     nvrc_enable,
864     nvrc_fragment_get_caps,
865     nvrc_fragment_alloc,
866     nvrc_fragment_free,
867     nvts_color_fixup_supported,
868     nvrc_fragmentstate_template,
869     FALSE /* we cannot disable projected textures. The vertex pipe has to do it */
870 };