mpr: Tweak a label so it matches the one in wininet.
[wine/multimedia.git] / dlls / wined3d / nvidia_texture_shader.c
blob1fef98009e9c4c827f64cd135d347c2c7b8d523e
1 /*
2 * Fixed function pipeline replacement using GL_NV_register_combiners
3 * and GL_NV_texture_shader
5 * Copyright 2006 Henri Verbeet
6 * Copyright 2008 Stefan Dösinger(for CodeWeavers)
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.
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.
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
22 #include "config.h"
24 #include <math.h>
25 #include <stdio.h>
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
31 /* GL locking for state handlers is done by the caller. */
33 static void nvts_activate_dimensions(const struct wined3d_state *state, DWORD stage, struct wined3d_context *context)
35 BOOL bumpmap = FALSE;
37 if (stage > 0
38 && (state->texture_states[stage - 1][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP_LUMINANCE
39 || state->texture_states[stage - 1][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP))
41 bumpmap = TRUE;
42 context->texShaderBumpMap |= (1 << stage);
43 } else {
44 context->texShaderBumpMap &= ~(1 << stage);
47 if (state->textures[stage])
49 switch (state->textures[stage]->target)
51 case GL_TEXTURE_2D:
52 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_2D);
53 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
54 break;
55 case GL_TEXTURE_RECTANGLE_ARB:
56 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_RECTANGLE_ARB);
57 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
58 break;
59 case GL_TEXTURE_3D:
60 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D);
61 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D)");
62 break;
63 case GL_TEXTURE_CUBE_MAP_ARB:
64 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB);
65 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB)");
66 break;
68 } else {
69 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
70 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE)");
74 struct tex_op_args
76 GLenum input[3];
77 GLenum mapping[3];
78 GLenum component_usage[3];
81 static GLenum d3dta_to_combiner_input(DWORD d3dta, DWORD stage, INT texture_idx) {
82 switch (d3dta) {
83 case WINED3DTA_DIFFUSE:
84 return GL_PRIMARY_COLOR_NV;
86 case WINED3DTA_CURRENT:
87 if (stage) return GL_SPARE0_NV;
88 else return GL_PRIMARY_COLOR_NV;
90 case WINED3DTA_TEXTURE:
91 if (texture_idx > -1) return GL_TEXTURE0_ARB + texture_idx;
92 else return GL_PRIMARY_COLOR_NV;
94 case WINED3DTA_TFACTOR:
95 return GL_CONSTANT_COLOR0_NV;
97 case WINED3DTA_SPECULAR:
98 return GL_SECONDARY_COLOR_NV;
100 case WINED3DTA_TEMP:
101 return GL_SPARE1_NV;
103 case WINED3DTA_CONSTANT:
104 /* TODO: Support per stage constants (WINED3D_TSS_CONSTANT, NV_register_combiners2) */
105 FIXME("WINED3DTA_CONSTANT, not properly supported.\n");
106 return GL_CONSTANT_COLOR1_NV;
108 default:
109 FIXME("Unrecognized texture arg %#x\n", d3dta);
110 return GL_TEXTURE;
114 static GLenum invert_mapping(GLenum mapping) {
115 if (mapping == GL_UNSIGNED_INVERT_NV) return GL_UNSIGNED_IDENTITY_NV;
116 else if (mapping == GL_UNSIGNED_IDENTITY_NV) return GL_UNSIGNED_INVERT_NV;
118 FIXME("Unhandled mapping %#x\n", mapping);
119 return mapping;
122 static void get_src_and_opr_nvrc(DWORD stage, DWORD arg, BOOL is_alpha, GLenum* input, GLenum* mapping, GLenum *component_usage, INT texture_idx) {
123 /* The WINED3DTA_COMPLEMENT flag specifies the complement of the input should
124 * be used. */
125 if (arg & WINED3DTA_COMPLEMENT) *mapping = GL_UNSIGNED_INVERT_NV;
126 else *mapping = GL_UNSIGNED_IDENTITY_NV; /* Clamp all values to positive ranges */
128 /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the input
129 * should be used for all input components. */
130 if (is_alpha || arg & WINED3DTA_ALPHAREPLICATE) *component_usage = GL_ALPHA;
131 else *component_usage = GL_RGB;
133 *input = d3dta_to_combiner_input(arg & WINED3DTA_SELECTMASK, stage, texture_idx);
136 void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state, BOOL is_alpha,
137 int stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst)
139 struct tex_op_args tex_op_args = {{0}, {0}, {0}};
140 GLenum portion = is_alpha ? GL_ALPHA : GL_RGB;
141 GLenum target = GL_COMBINER0_NV + stage;
142 GLenum output;
144 TRACE("stage %d, is_alpha %d, op %s, arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n",
145 stage, is_alpha, debug_d3dtop(op), arg1, arg2, arg3, texture_idx);
147 /* If a texture stage references an invalid texture unit the stage just
148 * passes through the result from the previous stage */
149 if (is_invalid_op(state, stage, op, arg1, arg2, arg3))
151 arg1 = WINED3DTA_CURRENT;
152 op = WINED3D_TOP_SELECT_ARG1;
155 get_src_and_opr_nvrc(stage, arg1, is_alpha, &tex_op_args.input[0],
156 &tex_op_args.mapping[0], &tex_op_args.component_usage[0], texture_idx);
157 get_src_and_opr_nvrc(stage, arg2, is_alpha, &tex_op_args.input[1],
158 &tex_op_args.mapping[1], &tex_op_args.component_usage[1], texture_idx);
159 get_src_and_opr_nvrc(stage, arg3, is_alpha, &tex_op_args.input[2],
160 &tex_op_args.mapping[2], &tex_op_args.component_usage[2], texture_idx);
163 if(dst == WINED3DTA_TEMP) {
164 output = GL_SPARE1_NV;
165 } else {
166 output = GL_SPARE0_NV;
169 /* This is called by a state handler which has the gl lock held and a context for the thread */
170 switch (op)
172 case WINED3D_TOP_DISABLE:
173 /* Only for alpha */
174 if (!is_alpha)
175 ERR("Shouldn't be called for WINED3D_TSS_COLOR_OP (WINED3DTOP_DISABLE).\n");
176 /* Input, prev_alpha*1 */
177 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
178 GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
179 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
180 GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
182 /* Output */
183 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
184 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
185 break;
187 case WINED3D_TOP_SELECT_ARG1:
188 case WINED3D_TOP_SELECT_ARG2:
189 /* Input, arg*1 */
190 if (op == WINED3D_TOP_SELECT_ARG1)
191 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
192 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
193 else
194 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
195 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
196 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
197 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
199 /* Output */
200 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
201 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
202 break;
204 case WINED3D_TOP_MODULATE:
205 case WINED3D_TOP_MODULATE_2X:
206 case WINED3D_TOP_MODULATE_4X:
207 /* Input, arg1*arg2 */
208 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
209 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
210 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
211 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
213 /* Output */
214 if (op == WINED3D_TOP_MODULATE)
215 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
216 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
217 else if (op == WINED3D_TOP_MODULATE_2X)
218 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
219 GL_DISCARD_NV, GL_SCALE_BY_TWO_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
220 else if (op == WINED3D_TOP_MODULATE_4X)
221 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
222 GL_DISCARD_NV, GL_SCALE_BY_FOUR_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
223 break;
225 case WINED3D_TOP_ADD:
226 case WINED3D_TOP_ADD_SIGNED:
227 case WINED3D_TOP_ADD_SIGNED_2X:
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));
238 /* Output */
239 if (op == WINED3D_TOP_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 == WINED3D_TOP_ADD_SIGNED)
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 == WINED3D_TOP_ADD_SIGNED_2X)
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 break;
250 case WINED3D_TOP_SUBTRACT:
251 /* Input, arg1*1+-arg2*1 */
252 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
253 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
254 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
255 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
256 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
257 tex_op_args.input[1], GL_SIGNED_NEGATE_NV, tex_op_args.component_usage[1]));
258 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
259 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
261 /* Output */
262 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
263 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
264 break;
266 case WINED3D_TOP_ADD_SMOOTH:
267 /* Input, arg1*1+(1-arg1)*arg2 */
268 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
269 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
270 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
271 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
272 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
273 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
274 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
275 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
277 /* Output */
278 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
279 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
280 break;
282 case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
283 case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
284 case WINED3D_TOP_BLEND_FACTOR_ALPHA:
285 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
286 case WINED3D_TOP_BLEND_CURRENT_ALPHA:
288 GLenum alpha_src = GL_PRIMARY_COLOR_NV;
289 if (op == WINED3D_TOP_BLEND_DIFFUSE_ALPHA)
290 alpha_src = d3dta_to_combiner_input(WINED3DTA_DIFFUSE, stage, texture_idx);
291 else if (op == WINED3D_TOP_BLEND_TEXTURE_ALPHA)
292 alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
293 else if (op == WINED3D_TOP_BLEND_FACTOR_ALPHA)
294 alpha_src = d3dta_to_combiner_input(WINED3DTA_TFACTOR, stage, texture_idx);
295 else if (op == WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM)
296 alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
297 else if (op == WINED3D_TOP_BLEND_CURRENT_ALPHA)
298 alpha_src = d3dta_to_combiner_input(WINED3DTA_CURRENT, stage, texture_idx);
299 else
300 FIXME("Unhandled texture op %s, shouldn't happen.\n", debug_d3dtop(op));
302 /* Input, arg1*alpha_src+arg2*(1-alpha_src) */
303 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
304 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
305 if (op == WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM)
307 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
308 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
309 } else {
310 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
311 alpha_src, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
313 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
314 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
315 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
316 alpha_src, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
318 /* Output */
319 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
320 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
321 break;
324 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
325 /* Input, arg1_alpha*arg2_rgb+arg1_rgb*1 */
326 if (is_alpha)
327 ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATEALPHA_ADDCOLOR).\n");
328 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
329 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
330 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
331 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
332 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
333 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
334 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
335 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
337 /* Output */
338 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
339 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
340 break;
342 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
343 /* Input, arg1_rgb*arg2_rgb+arg1_alpha*1 */
344 if (is_alpha)
345 ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATECOLOR_ADDALPHA).\n");
346 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
347 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
348 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
349 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
350 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
351 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
352 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
353 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
355 /* Output */
356 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
357 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
358 break;
360 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
361 /* Input, (1-arg1_alpha)*arg2_rgb+arg1_rgb*1 */
362 if (is_alpha)
363 ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATEINVALPHA_ADDCOLOR).\n");
364 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
365 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), GL_ALPHA));
366 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
367 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
368 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
369 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
370 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
371 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
373 /* Output */
374 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
375 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
376 break;
378 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
379 /* Input, (1-arg1_rgb)*arg2_rgb+arg1_alpha*1 */
380 if (is_alpha)
381 ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATEINVCOLOR_ADDALPHA).\n");
382 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
383 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
384 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
385 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
386 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
387 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
388 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
389 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
391 /* Output */
392 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
393 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
394 break;
396 case WINED3D_TOP_DOTPRODUCT3:
397 /* Input, arg1 . arg2 */
398 /* FIXME: DX7 uses a different calculation? */
399 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
400 tex_op_args.input[0], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[0]));
401 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
402 tex_op_args.input[1], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[1]));
404 /* Output */
405 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
406 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_FALSE, GL_FALSE));
407 break;
409 case WINED3D_TOP_MULTIPLY_ADD:
410 /* Input, arg3*1+arg1*arg2 */
411 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
412 tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
413 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
414 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
415 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
416 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
417 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
418 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
420 /* Output */
421 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
422 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
423 break;
425 case WINED3D_TOP_LERP:
426 /* Input, arg3*arg1+(1-arg3)*arg2 */
427 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
428 tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
429 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
430 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
431 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
432 tex_op_args.input[2], invert_mapping(tex_op_args.mapping[2]), tex_op_args.component_usage[2]));
433 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
434 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
436 /* Output */
437 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
438 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
439 break;
441 case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
442 case WINED3D_TOP_BUMPENVMAP:
443 if (gl_info->supported[NV_TEXTURE_SHADER])
445 /* The bump map stage itself isn't exciting, just read the texture. But tell the next stage to
446 * perform bump mapping and source from the current stage. Pretty much a SELECTARG2.
447 * ARG2 is passed through unmodified(apps will most likely use D3DTA_CURRENT for arg2, arg1
448 * (which will most likely be D3DTA_TEXTURE) is available as a texture shader input for the next stage
450 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
451 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
452 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
453 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
454 /* Always pass through to CURRENT, ignore temp arg */
455 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
456 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
457 break;
460 default:
461 FIXME("Unhandled texture op: stage %d, is_alpha %d, op %s (%#x), arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d.\n",
462 stage, is_alpha, debug_d3dtop(op), op, arg1, arg2, arg3, texture_idx);
465 checkGLcall("set_tex_op_nvrc()");
469 static void nvrc_colorop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
471 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
472 const struct wined3d_device *device = context->swapchain->device;
473 BOOL tex_used = device->fixed_function_usage_map & (1 << stage);
474 DWORD mapped_stage = device->texUnitMap[stage];
475 const struct wined3d_gl_info *gl_info = context->gl_info;
477 TRACE("Setting color op for stage %u.\n", stage);
479 /* Using a pixel shader? Don't care for anything here, the shader applying does it */
480 if (use_ps(state)) return;
482 if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
484 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
486 if (tex_used && mapped_stage >= gl_info->limits.textures)
488 FIXME("Attempt to enable unsupported stage!\n");
489 return;
491 context_active_texture(context, gl_info, mapped_stage);
494 if (state->lowest_disabled_stage > 0)
496 glEnable(GL_REGISTER_COMBINERS_NV);
497 GL_EXTCALL(glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, state->lowest_disabled_stage));
499 else
501 glDisable(GL_REGISTER_COMBINERS_NV);
503 if (stage >= state->lowest_disabled_stage)
505 TRACE("Stage disabled\n");
506 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
508 /* Disable everything here */
509 glDisable(GL_TEXTURE_2D);
510 checkGLcall("glDisable(GL_TEXTURE_2D)");
511 glDisable(GL_TEXTURE_3D);
512 checkGLcall("glDisable(GL_TEXTURE_3D)");
513 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
515 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
516 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
518 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
520 glDisable(GL_TEXTURE_RECTANGLE_ARB);
521 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
523 if (gl_info->supported[NV_TEXTURE_SHADER2] && mapped_stage < gl_info->limits.textures)
525 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
528 /* All done */
529 return;
532 /* The sampler will also activate the correct texture dimensions, so no need to do it here
533 * if the sampler for this stage is dirty
535 if (!isStateDirty(context, STATE_SAMPLER(stage)))
537 if (tex_used)
539 if (gl_info->supported[NV_TEXTURE_SHADER2])
541 nvts_activate_dimensions(state, stage, context);
543 else
545 texture_activate_dimensions(state->textures[stage], gl_info);
550 /* Set the texture combiners */
551 set_tex_op_nvrc(gl_info, state, FALSE, stage,
552 state->texture_states[stage][WINED3D_TSS_COLOR_OP],
553 state->texture_states[stage][WINED3D_TSS_COLOR_ARG1],
554 state->texture_states[stage][WINED3D_TSS_COLOR_ARG2],
555 state->texture_states[stage][WINED3D_TSS_COLOR_ARG0],
556 mapped_stage,
557 state->texture_states[stage][WINED3D_TSS_RESULT_ARG]);
559 /* In register combiners bump mapping is done in the stage AFTER the one that has the bump map operation set,
560 * thus the texture shader may have to be updated
562 if (gl_info->supported[NV_TEXTURE_SHADER2])
564 BOOL usesBump = (state->texture_states[stage][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP_LUMINANCE
565 || state->texture_states[stage][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP);
566 BOOL usedBump = !!(context->texShaderBumpMap & 1 << (stage + 1));
567 if (usesBump != usedBump)
569 context_active_texture(context, gl_info, mapped_stage + 1);
570 nvts_activate_dimensions(state, stage + 1, context);
571 context_active_texture(context, gl_info, mapped_stage);
576 static void nvts_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
578 DWORD sampler = state_id - STATE_SAMPLER(0);
579 DWORD mapped_stage = context->swapchain->device->texUnitMap[sampler];
581 /* No need to enable / disable anything here for unused samplers. The tex_colorop
582 * handler takes care. Also no action is needed with pixel shaders, or if tex_colorop
583 * will take care of this business. */
584 if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures)
585 return;
586 if (sampler >= state->lowest_disabled_stage)
587 return;
588 if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP)))
589 return;
591 nvts_activate_dimensions(state, sampler, context);
594 static void nvts_bumpenvmat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
596 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
597 DWORD mapped_stage = context->swapchain->device->texUnitMap[stage + 1];
598 const struct wined3d_gl_info *gl_info = context->gl_info;
599 float mat[2][2];
601 /* Direct3D sets the matrix in the stage reading the perturbation map. The result is used to
602 * offset the destination stage(always stage + 1 in d3d). In GL_NV_texture_shader, the bump
603 * map offsetting is done in the stage reading the bump mapped texture, and the perturbation
604 * map is read from a specified source stage(always stage - 1 for d3d). Thus set the matrix
605 * for stage + 1. Keep the nvrc tex unit mapping in mind too
607 if (mapped_stage < gl_info->limits.textures)
609 context_active_texture(context, gl_info, mapped_stage);
611 /* We can't just pass a pointer to the state to GL due to the
612 * different matrix format (column major vs row major). */
613 mat[0][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT00]);
614 mat[1][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT01]);
615 mat[0][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT10]);
616 mat[1][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT11]);
617 glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float *)mat);
618 checkGLcall("glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, mat)");
622 static void nvrc_texfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
624 const struct wined3d_gl_info *gl_info = context->gl_info;
625 float col[4];
627 D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_TEXTUREFACTOR], col);
628 GL_EXTCALL(glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &col[0]));
631 /* Context activation is done by the caller. */
632 static void nvrc_enable(BOOL enable)
634 if (enable)
636 glEnable(GL_REGISTER_COMBINERS_NV);
637 checkGLcall("glEnable(GL_REGISTER_COMBINERS_NV)");
639 else
641 glDisable(GL_REGISTER_COMBINERS_NV);
642 checkGLcall("glDisable(GL_REGISTER_COMBINERS_NV)");
646 /* Context activation and GL locking are done by the caller. */
647 static void nvts_enable(BOOL enable)
649 nvrc_enable(enable);
650 if (enable)
652 glEnable(GL_TEXTURE_SHADER_NV);
653 checkGLcall("glEnable(GL_TEXTURE_SHADER_NV)");
655 else
657 glDisable(GL_TEXTURE_SHADER_NV);
658 checkGLcall("glDisable(GL_TEXTURE_SHADER_NV)");
662 static void nvrc_fragment_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
664 caps->PrimitiveMiscCaps = WINED3DPMISCCAPS_TSSARGTEMP;
666 /* The caps below can be supported but aren't handled yet in utils.c
667 * 'd3dta_to_combiner_input', disable them until support is fixed */
668 #if 0
669 if (gl_info->supported[NV_REGISTER_COMBINERS2])
670 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_PERSTAGECONSTANT;
671 #endif
673 caps->TextureOpCaps = WINED3DTEXOPCAPS_ADD
674 | WINED3DTEXOPCAPS_ADDSIGNED
675 | WINED3DTEXOPCAPS_ADDSIGNED2X
676 | WINED3DTEXOPCAPS_MODULATE
677 | WINED3DTEXOPCAPS_MODULATE2X
678 | WINED3DTEXOPCAPS_MODULATE4X
679 | WINED3DTEXOPCAPS_SELECTARG1
680 | WINED3DTEXOPCAPS_SELECTARG2
681 | WINED3DTEXOPCAPS_DISABLE
682 | WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA
683 | WINED3DTEXOPCAPS_BLENDTEXTUREALPHA
684 | WINED3DTEXOPCAPS_BLENDFACTORALPHA
685 | WINED3DTEXOPCAPS_BLENDCURRENTALPHA
686 | WINED3DTEXOPCAPS_LERP
687 | WINED3DTEXOPCAPS_SUBTRACT
688 | WINED3DTEXOPCAPS_ADDSMOOTH
689 | WINED3DTEXOPCAPS_MULTIPLYADD
690 | WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
691 | WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
692 | WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM
693 | WINED3DTEXOPCAPS_DOTPRODUCT3
694 | WINED3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
695 | WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA;
697 if (gl_info->supported[NV_TEXTURE_SHADER2])
699 /* Bump mapping is supported already in NV_TEXTURE_SHADER, but that extension does
700 * not support 3D textures. This asks for trouble if an app uses both bump mapping
701 * and 3D textures. It also allows us to keep the code simpler by having texture
702 * shaders constantly enabled. */
703 caps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAP;
704 /* TODO: Luminance bump map? */
707 #if 0
708 /* FIXME: Add
709 caps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAPLUMINANCE
710 WINED3DTEXOPCAPS_PREMODULATE */
711 #endif
713 caps->MaxTextureBlendStages = min(MAX_TEXTURES, gl_info->limits.general_combiners);
714 caps->MaxSimultaneousTextures = gl_info->limits.textures;
717 static HRESULT nvrc_fragment_alloc(struct wined3d_device *device) { return WINED3D_OK; }
718 /* Context activation is done by the caller. */
719 static void nvrc_fragment_free(struct wined3d_device *device) {}
721 /* Two fixed function pipeline implementations using GL_NV_register_combiners and
722 * GL_NV_texture_shader. The nvts_fragment_pipeline assumes that both extensions
723 * are available(geforce 3 and newer), while nvrc_fragment_pipeline uses only the
724 * register combiners extension(Pre-GF3).
727 static BOOL nvts_color_fixup_supported(struct color_fixup_desc fixup)
729 if (TRACE_ON(d3d))
731 TRACE("Checking support for fixup:\n");
732 dump_color_fixup_desc(fixup);
735 /* We only support identity conversions. */
736 if (is_identity_fixup(fixup))
738 TRACE("[OK]\n");
739 return TRUE;
742 TRACE("[FAILED]\n");
743 return FALSE;
746 static const struct StateEntryTemplate nvrc_fragmentstate_template[] =
748 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
749 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
750 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
751 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
752 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
753 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
754 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
755 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
756 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
757 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
758 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
759 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
760 { STATE_TEXTURESTAGE(0, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
761 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
762 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
763 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
764 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
765 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
766 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
767 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
768 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
769 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
770 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
771 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
772 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
773 { STATE_TEXTURESTAGE(1, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
774 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
775 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
776 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
777 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
778 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
779 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
780 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
781 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
782 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
783 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
784 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
785 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
786 { STATE_TEXTURESTAGE(2, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
787 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
788 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
789 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
790 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
791 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
792 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
793 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
794 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
795 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
796 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
797 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
798 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
799 { STATE_TEXTURESTAGE(3, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
800 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
801 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
802 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
803 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
804 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
805 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
806 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
807 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
808 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
809 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
810 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
811 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
812 { STATE_TEXTURESTAGE(4, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
813 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
814 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
815 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
816 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
817 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
818 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
819 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
820 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
821 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
822 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
823 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
824 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
825 { STATE_TEXTURESTAGE(5, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
826 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
827 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
828 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
829 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
830 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
831 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
832 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
833 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
834 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
835 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
836 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
837 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
838 { STATE_TEXTURESTAGE(6, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
839 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
840 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
841 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
842 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
843 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
844 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
845 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
846 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
847 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
848 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
849 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
850 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
851 { STATE_TEXTURESTAGE(7, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
852 { STATE_PIXELSHADER, { STATE_PIXELSHADER, apply_pixelshader }, WINED3D_GL_EXT_NONE },
853 { STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE },
854 { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), nvrc_texfactor }, WINED3D_GL_EXT_NONE },
855 { STATE_RENDER(WINED3D_RS_FOGCOLOR), { STATE_RENDER(WINED3D_RS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE },
856 { STATE_RENDER(WINED3D_RS_FOGDENSITY), { STATE_RENDER(WINED3D_RS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE },
857 { STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE },
858 { STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
859 { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
860 { STATE_RENDER(WINED3D_RS_FOGSTART), { STATE_RENDER(WINED3D_RS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE },
861 { STATE_RENDER(WINED3D_RS_FOGEND), { STATE_RENDER(WINED3D_RS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE },
862 { STATE_SAMPLER(0), { STATE_SAMPLER(0), nvts_texdim }, NV_TEXTURE_SHADER2 },
863 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, WINED3D_GL_EXT_NONE },
864 { STATE_SAMPLER(1), { STATE_SAMPLER(1), nvts_texdim }, NV_TEXTURE_SHADER2 },
865 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, WINED3D_GL_EXT_NONE },
866 { STATE_SAMPLER(2), { STATE_SAMPLER(2), nvts_texdim }, NV_TEXTURE_SHADER2 },
867 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, WINED3D_GL_EXT_NONE },
868 { STATE_SAMPLER(3), { STATE_SAMPLER(3), nvts_texdim }, NV_TEXTURE_SHADER2 },
869 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texdim }, WINED3D_GL_EXT_NONE },
870 { STATE_SAMPLER(4), { STATE_SAMPLER(4), nvts_texdim }, NV_TEXTURE_SHADER2 },
871 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texdim }, WINED3D_GL_EXT_NONE },
872 { STATE_SAMPLER(5), { STATE_SAMPLER(5), nvts_texdim }, NV_TEXTURE_SHADER2 },
873 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texdim }, WINED3D_GL_EXT_NONE },
874 { STATE_SAMPLER(6), { STATE_SAMPLER(6), nvts_texdim }, NV_TEXTURE_SHADER2 },
875 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texdim }, WINED3D_GL_EXT_NONE },
876 { STATE_SAMPLER(7), { STATE_SAMPLER(7), nvts_texdim }, NV_TEXTURE_SHADER2 },
877 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texdim }, WINED3D_GL_EXT_NONE },
878 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
881 const struct fragment_pipeline nvts_fragment_pipeline = {
882 nvts_enable,
883 nvrc_fragment_get_caps,
884 nvrc_fragment_alloc,
885 nvrc_fragment_free,
886 nvts_color_fixup_supported,
887 nvrc_fragmentstate_template,
888 FALSE /* we cannot disable projected textures. The vertex pipe has to do it */
891 const struct fragment_pipeline nvrc_fragment_pipeline = {
892 nvrc_enable,
893 nvrc_fragment_get_caps,
894 nvrc_fragment_alloc,
895 nvrc_fragment_free,
896 nvts_color_fixup_supported,
897 nvrc_fragmentstate_template,
898 FALSE /* we cannot disable projected textures. The vertex pipe has to do it */