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
23 #include "wine/port.h"
28 #include "wined3d_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
32 /* GL locking for state handlers is done by the caller. */
34 static void nvts_activate_dimensions(const struct wined3d_state *state, DWORD stage, struct wined3d_context *context)
36 const struct wined3d_gl_info *gl_info = context->gl_info;
40 && (state->texture_states[stage - 1][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP_LUMINANCE
41 || state->texture_states[stage - 1][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP))
44 context->texShaderBumpMap |= (1 << stage);
46 context->texShaderBumpMap &= ~(1 << stage);
49 if (state->textures[stage])
51 switch (state->textures[stage]->target)
54 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV,
55 bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_2D);
56 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
58 case GL_TEXTURE_RECTANGLE_ARB:
59 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV,
60 bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_RECTANGLE_ARB);
61 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
64 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D);
65 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D)");
67 case GL_TEXTURE_CUBE_MAP_ARB:
68 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB);
69 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB)");
75 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
76 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE)");
84 GLenum component_usage[3];
87 static GLenum d3dta_to_combiner_input(DWORD d3dta, DWORD stage, INT texture_idx) {
89 case WINED3DTA_DIFFUSE:
90 return GL_PRIMARY_COLOR_NV;
92 case WINED3DTA_CURRENT:
93 if (stage) return GL_SPARE0_NV;
94 else return GL_PRIMARY_COLOR_NV;
96 case WINED3DTA_TEXTURE:
97 if (texture_idx > -1) return GL_TEXTURE0_ARB + texture_idx;
98 else return GL_PRIMARY_COLOR_NV;
100 case WINED3DTA_TFACTOR:
101 return GL_CONSTANT_COLOR0_NV;
103 case WINED3DTA_SPECULAR:
104 return GL_SECONDARY_COLOR_NV;
109 case WINED3DTA_CONSTANT:
110 /* TODO: Support per stage constants (WINED3D_TSS_CONSTANT, NV_register_combiners2) */
111 FIXME("WINED3DTA_CONSTANT, not properly supported.\n");
112 return GL_CONSTANT_COLOR1_NV;
115 FIXME("Unrecognized texture arg %#x\n", d3dta);
120 static GLenum invert_mapping(GLenum mapping) {
121 if (mapping == GL_UNSIGNED_INVERT_NV) return GL_UNSIGNED_IDENTITY_NV;
122 else if (mapping == GL_UNSIGNED_IDENTITY_NV) return GL_UNSIGNED_INVERT_NV;
124 FIXME("Unhandled mapping %#x\n", mapping);
128 static void get_src_and_opr_nvrc(DWORD stage, DWORD arg, BOOL is_alpha, GLenum* input, GLenum* mapping, GLenum *component_usage, INT texture_idx) {
129 /* The WINED3DTA_COMPLEMENT flag specifies the complement of the input should
131 if (arg & WINED3DTA_COMPLEMENT) *mapping = GL_UNSIGNED_INVERT_NV;
132 else *mapping = GL_UNSIGNED_IDENTITY_NV; /* Clamp all values to positive ranges */
134 /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the input
135 * should be used for all input components. */
136 if (is_alpha || arg & WINED3DTA_ALPHAREPLICATE) *component_usage = GL_ALPHA;
137 else *component_usage = GL_RGB;
139 *input = d3dta_to_combiner_input(arg & WINED3DTA_SELECTMASK, stage, texture_idx);
142 void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state, BOOL is_alpha,
143 int stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst)
145 struct tex_op_args tex_op_args = {{0}, {0}, {0}};
146 GLenum portion = is_alpha ? GL_ALPHA : GL_RGB;
147 GLenum target = GL_COMBINER0_NV + stage;
150 TRACE("stage %d, is_alpha %d, op %s, arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n",
151 stage, is_alpha, debug_d3dtop(op), arg1, arg2, arg3, texture_idx);
153 /* If a texture stage references an invalid texture unit the stage just
154 * passes through the result from the previous stage */
155 if (is_invalid_op(state, stage, op, arg1, arg2, arg3))
157 arg1 = WINED3DTA_CURRENT;
158 op = WINED3D_TOP_SELECT_ARG1;
161 get_src_and_opr_nvrc(stage, arg1, is_alpha, &tex_op_args.input[0],
162 &tex_op_args.mapping[0], &tex_op_args.component_usage[0], texture_idx);
163 get_src_and_opr_nvrc(stage, arg2, is_alpha, &tex_op_args.input[1],
164 &tex_op_args.mapping[1], &tex_op_args.component_usage[1], texture_idx);
165 get_src_and_opr_nvrc(stage, arg3, is_alpha, &tex_op_args.input[2],
166 &tex_op_args.mapping[2], &tex_op_args.component_usage[2], texture_idx);
169 if(dst == WINED3DTA_TEMP) {
170 output = GL_SPARE1_NV;
172 output = GL_SPARE0_NV;
175 /* This is called by a state handler which has the gl lock held and a context for the thread */
178 case WINED3D_TOP_DISABLE:
181 ERR("Shouldn't be called for WINED3D_TSS_COLOR_OP (WINED3DTOP_DISABLE).\n");
182 /* Input, prev_alpha*1 */
183 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
184 GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
185 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
186 GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
189 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
190 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
193 case WINED3D_TOP_SELECT_ARG1:
194 case WINED3D_TOP_SELECT_ARG2:
196 if (op == WINED3D_TOP_SELECT_ARG1)
197 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
198 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
200 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
201 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
202 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
203 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
206 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
207 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
210 case WINED3D_TOP_MODULATE:
211 case WINED3D_TOP_MODULATE_2X:
212 case WINED3D_TOP_MODULATE_4X:
213 /* Input, arg1*arg2 */
214 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
215 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
216 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
217 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
220 if (op == WINED3D_TOP_MODULATE)
221 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
222 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
223 else if (op == WINED3D_TOP_MODULATE_2X)
224 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
225 GL_DISCARD_NV, GL_SCALE_BY_TWO_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
226 else if (op == WINED3D_TOP_MODULATE_4X)
227 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
228 GL_DISCARD_NV, GL_SCALE_BY_FOUR_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
231 case WINED3D_TOP_ADD:
232 case WINED3D_TOP_ADD_SIGNED:
233 case WINED3D_TOP_ADD_SIGNED_2X:
234 /* Input, arg1*1+arg2*1 */
235 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
236 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
237 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
238 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
239 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
240 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
241 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
242 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
245 if (op == WINED3D_TOP_ADD)
246 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
247 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
248 else if (op == WINED3D_TOP_ADD_SIGNED)
249 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
250 output, GL_NONE, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
251 else if (op == WINED3D_TOP_ADD_SIGNED_2X)
252 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
253 output, GL_SCALE_BY_TWO_NV, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
256 case WINED3D_TOP_SUBTRACT:
257 /* Input, arg1*1+-arg2*1 */
258 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
259 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
260 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
261 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
262 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
263 tex_op_args.input[1], GL_SIGNED_NEGATE_NV, tex_op_args.component_usage[1]));
264 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
265 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
268 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
269 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
272 case WINED3D_TOP_ADD_SMOOTH:
273 /* Input, arg1*1+(1-arg1)*arg2 */
274 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
275 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
276 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
277 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
278 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
279 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
280 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
281 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
284 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
285 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
288 case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
289 case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
290 case WINED3D_TOP_BLEND_FACTOR_ALPHA:
291 case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
292 case WINED3D_TOP_BLEND_CURRENT_ALPHA:
294 GLenum alpha_src = GL_PRIMARY_COLOR_NV;
295 if (op == WINED3D_TOP_BLEND_DIFFUSE_ALPHA)
296 alpha_src = d3dta_to_combiner_input(WINED3DTA_DIFFUSE, stage, texture_idx);
297 else if (op == WINED3D_TOP_BLEND_TEXTURE_ALPHA)
298 alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
299 else if (op == WINED3D_TOP_BLEND_FACTOR_ALPHA)
300 alpha_src = d3dta_to_combiner_input(WINED3DTA_TFACTOR, stage, texture_idx);
301 else if (op == WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM)
302 alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
303 else if (op == WINED3D_TOP_BLEND_CURRENT_ALPHA)
304 alpha_src = d3dta_to_combiner_input(WINED3DTA_CURRENT, stage, texture_idx);
306 FIXME("Unhandled texture op %s, shouldn't happen.\n", debug_d3dtop(op));
308 /* Input, arg1*alpha_src+arg2*(1-alpha_src) */
309 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
310 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
311 if (op == WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM)
313 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
314 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
316 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
317 alpha_src, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
319 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
320 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
321 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
322 alpha_src, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
325 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
326 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
330 case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
331 /* Input, arg1_alpha*arg2_rgb+arg1_rgb*1 */
333 ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATEALPHA_ADDCOLOR).\n");
334 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
335 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
336 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
337 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
338 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
339 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
340 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
341 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
344 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
345 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
348 case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
349 /* Input, arg1_rgb*arg2_rgb+arg1_alpha*1 */
351 ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATECOLOR_ADDALPHA).\n");
352 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
353 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
354 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
355 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
356 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
357 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
358 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
359 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
362 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
363 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
366 case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
367 /* Input, (1-arg1_alpha)*arg2_rgb+arg1_rgb*1 */
369 ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATEINVALPHA_ADDCOLOR).\n");
370 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
371 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), GL_ALPHA));
372 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
373 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
374 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
375 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
376 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
377 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
380 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
381 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
384 case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
385 /* Input, (1-arg1_rgb)*arg2_rgb+arg1_alpha*1 */
387 ERR("Only supported for WINED3D_TSS_COLOR_OP (WINED3DTOP_MODULATEINVCOLOR_ADDALPHA).\n");
388 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
389 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
390 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
391 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
392 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
393 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
394 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
395 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
398 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
399 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
402 case WINED3D_TOP_DOTPRODUCT3:
403 /* Input, arg1 . arg2 */
404 /* FIXME: DX7 uses a different calculation? */
405 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
406 tex_op_args.input[0], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[0]));
407 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
408 tex_op_args.input[1], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[1]));
411 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
412 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_FALSE, GL_FALSE));
415 case WINED3D_TOP_MULTIPLY_ADD:
416 /* Input, arg3*1+arg1*arg2 */
417 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
418 tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
419 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
420 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
421 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
422 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
423 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
424 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
427 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
428 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
431 case WINED3D_TOP_LERP:
432 /* Input, arg3*arg1+(1-arg3)*arg2 */
433 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
434 tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
435 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
436 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
437 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
438 tex_op_args.input[2], invert_mapping(tex_op_args.mapping[2]), tex_op_args.component_usage[2]));
439 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
440 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
443 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
444 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
447 case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
448 case WINED3D_TOP_BUMPENVMAP:
449 if (gl_info->supported[NV_TEXTURE_SHADER])
451 /* The bump map stage itself isn't exciting, just read the texture. But tell the next stage to
452 * perform bump mapping and source from the current stage. Pretty much a SELECTARG2.
453 * ARG2 is passed through unmodified(apps will most likely use D3DTA_CURRENT for arg2, arg1
454 * (which will most likely be D3DTA_TEXTURE) is available as a texture shader input for the next stage
456 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
457 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
458 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
459 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
460 /* Always pass through to CURRENT, ignore temp arg */
461 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
462 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
467 FIXME("Unhandled texture op: stage %d, is_alpha %d, op %s (%#x), arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d.\n",
468 stage, is_alpha, debug_d3dtop(op), op, arg1, arg2, arg3, texture_idx);
471 checkGLcall("set_tex_op_nvrc()");
475 static void nvrc_colorop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
477 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
478 const struct wined3d_device *device = context->swapchain->device;
479 BOOL tex_used = device->fixed_function_usage_map & (1 << stage);
480 DWORD mapped_stage = device->texUnitMap[stage];
481 const struct wined3d_gl_info *gl_info = context->gl_info;
483 TRACE("Setting color op for stage %u.\n", stage);
485 /* Using a pixel shader? Don't care for anything here, the shader applying does it */
486 if (use_ps(state)) return;
488 if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
490 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
492 if (tex_used && mapped_stage >= gl_info->limits.textures)
494 FIXME("Attempt to enable unsupported stage!\n");
497 context_active_texture(context, gl_info, mapped_stage);
500 if (state->lowest_disabled_stage > 0)
502 gl_info->gl_ops.gl.p_glEnable(GL_REGISTER_COMBINERS_NV);
503 GL_EXTCALL(glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, state->lowest_disabled_stage));
507 gl_info->gl_ops.gl.p_glDisable(GL_REGISTER_COMBINERS_NV);
509 if (stage >= state->lowest_disabled_stage)
511 TRACE("Stage disabled\n");
512 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
514 /* Disable everything here */
515 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
516 checkGLcall("glDisable(GL_TEXTURE_2D)");
517 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
518 checkGLcall("glDisable(GL_TEXTURE_3D)");
519 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
521 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
522 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
524 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
526 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
527 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
529 if (gl_info->supported[NV_TEXTURE_SHADER2] && mapped_stage < gl_info->limits.textures)
531 gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
538 /* The sampler will also activate the correct texture dimensions, so no need to do it here
539 * if the sampler for this stage is dirty
541 if (!isStateDirty(context, STATE_SAMPLER(stage)))
545 if (gl_info->supported[NV_TEXTURE_SHADER2])
547 nvts_activate_dimensions(state, stage, context);
551 texture_activate_dimensions(state->textures[stage], gl_info);
556 /* Set the texture combiners */
557 set_tex_op_nvrc(gl_info, state, FALSE, stage,
558 state->texture_states[stage][WINED3D_TSS_COLOR_OP],
559 state->texture_states[stage][WINED3D_TSS_COLOR_ARG1],
560 state->texture_states[stage][WINED3D_TSS_COLOR_ARG2],
561 state->texture_states[stage][WINED3D_TSS_COLOR_ARG0],
563 state->texture_states[stage][WINED3D_TSS_RESULT_ARG]);
565 /* In register combiners bump mapping is done in the stage AFTER the one that has the bump map operation set,
566 * thus the texture shader may have to be updated
568 if (gl_info->supported[NV_TEXTURE_SHADER2])
570 BOOL usesBump = (state->texture_states[stage][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP_LUMINANCE
571 || state->texture_states[stage][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_BUMPENVMAP);
572 BOOL usedBump = !!(context->texShaderBumpMap & 1 << (stage + 1));
573 if (usesBump != usedBump)
575 context_active_texture(context, gl_info, mapped_stage + 1);
576 nvts_activate_dimensions(state, stage + 1, context);
577 context_active_texture(context, gl_info, mapped_stage);
582 static void nvts_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
584 DWORD sampler = state_id - STATE_SAMPLER(0);
585 DWORD mapped_stage = context->swapchain->device->texUnitMap[sampler];
587 /* No need to enable / disable anything here for unused samplers. The tex_colorop
588 * handler takes care. Also no action is needed with pixel shaders, or if tex_colorop
589 * will take care of this business. */
590 if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures)
592 if (sampler >= state->lowest_disabled_stage)
594 if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP)))
597 nvts_activate_dimensions(state, sampler, context);
600 static void nvts_bumpenvmat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
602 DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
603 DWORD mapped_stage = context->swapchain->device->texUnitMap[stage + 1];
604 const struct wined3d_gl_info *gl_info = context->gl_info;
607 /* Direct3D sets the matrix in the stage reading the perturbation map. The result is used to
608 * offset the destination stage(always stage + 1 in d3d). In GL_NV_texture_shader, the bump
609 * map offsetting is done in the stage reading the bump mapped texture, and the perturbation
610 * map is read from a specified source stage(always stage - 1 for d3d). Thus set the matrix
611 * for stage + 1. Keep the nvrc tex unit mapping in mind too
613 if (mapped_stage < gl_info->limits.textures)
615 context_active_texture(context, gl_info, mapped_stage);
617 /* We can't just pass a pointer to the state to GL due to the
618 * different matrix format (column major vs row major). */
619 mat[0][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT00]);
620 mat[1][0] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT01]);
621 mat[0][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT10]);
622 mat[1][1] = *((float *)&state->texture_states[stage][WINED3D_TSS_BUMPENV_MAT11]);
623 gl_info->gl_ops.gl.p_glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float *)mat);
624 checkGLcall("glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, mat)");
628 static void nvrc_texfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
630 const struct wined3d_gl_info *gl_info = context->gl_info;
633 D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_TEXTUREFACTOR], col);
634 GL_EXTCALL(glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &col[0]));
637 /* Context activation is done by the caller. */
638 static void nvrc_enable(const struct wined3d_gl_info *gl_info, BOOL enable)
642 gl_info->gl_ops.gl.p_glEnable(GL_REGISTER_COMBINERS_NV);
643 checkGLcall("glEnable(GL_REGISTER_COMBINERS_NV)");
647 gl_info->gl_ops.gl.p_glDisable(GL_REGISTER_COMBINERS_NV);
648 checkGLcall("glDisable(GL_REGISTER_COMBINERS_NV)");
652 /* Context activation and GL locking are done by the caller. */
653 static void nvts_enable(const struct wined3d_gl_info *gl_info, BOOL enable)
655 nvrc_enable(gl_info, enable);
658 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_SHADER_NV);
659 checkGLcall("glEnable(GL_TEXTURE_SHADER_NV)");
663 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_SHADER_NV);
664 checkGLcall("glDisable(GL_TEXTURE_SHADER_NV)");
668 static void nvrc_fragment_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
670 caps->PrimitiveMiscCaps = WINED3DPMISCCAPS_TSSARGTEMP;
672 /* The caps below can be supported but aren't handled yet in utils.c
673 * 'd3dta_to_combiner_input', disable them until support is fixed */
675 if (gl_info->supported[NV_REGISTER_COMBINERS2])
676 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_PERSTAGECONSTANT;
679 caps->TextureOpCaps = WINED3DTEXOPCAPS_ADD
680 | WINED3DTEXOPCAPS_ADDSIGNED
681 | WINED3DTEXOPCAPS_ADDSIGNED2X
682 | WINED3DTEXOPCAPS_MODULATE
683 | WINED3DTEXOPCAPS_MODULATE2X
684 | WINED3DTEXOPCAPS_MODULATE4X
685 | WINED3DTEXOPCAPS_SELECTARG1
686 | WINED3DTEXOPCAPS_SELECTARG2
687 | WINED3DTEXOPCAPS_DISABLE
688 | WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA
689 | WINED3DTEXOPCAPS_BLENDTEXTUREALPHA
690 | WINED3DTEXOPCAPS_BLENDFACTORALPHA
691 | WINED3DTEXOPCAPS_BLENDCURRENTALPHA
692 | WINED3DTEXOPCAPS_LERP
693 | WINED3DTEXOPCAPS_SUBTRACT
694 | WINED3DTEXOPCAPS_ADDSMOOTH
695 | WINED3DTEXOPCAPS_MULTIPLYADD
696 | WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
697 | WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
698 | WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM
699 | WINED3DTEXOPCAPS_DOTPRODUCT3
700 | WINED3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
701 | WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA;
703 if (gl_info->supported[NV_TEXTURE_SHADER2])
705 /* Bump mapping is supported already in NV_TEXTURE_SHADER, but that extension does
706 * not support 3D textures. This asks for trouble if an app uses both bump mapping
707 * and 3D textures. It also allows us to keep the code simpler by having texture
708 * shaders constantly enabled. */
709 caps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAP;
710 /* TODO: Luminance bump map? */
715 caps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAPLUMINANCE
716 WINED3DTEXOPCAPS_PREMODULATE */
719 caps->MaxTextureBlendStages = min(MAX_TEXTURES, gl_info->limits.general_combiners);
720 caps->MaxSimultaneousTextures = gl_info->limits.textures;
723 static HRESULT nvrc_fragment_alloc(struct wined3d_device *device) { return WINED3D_OK; }
724 /* Context activation is done by the caller. */
725 static void nvrc_fragment_free(struct wined3d_device *device) {}
727 /* Two fixed function pipeline implementations using GL_NV_register_combiners and
728 * GL_NV_texture_shader. The nvts_fragment_pipeline assumes that both extensions
729 * are available(geforce 3 and newer), while nvrc_fragment_pipeline uses only the
730 * register combiners extension(Pre-GF3).
733 static BOOL nvts_color_fixup_supported(struct color_fixup_desc fixup)
737 TRACE("Checking support for fixup:\n");
738 dump_color_fixup_desc(fixup);
741 /* We only support identity conversions. */
742 if (is_identity_fixup(fixup))
752 static const struct StateEntryTemplate nvrc_fragmentstate_template[] =
754 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
755 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
756 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
757 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
758 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
759 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
760 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
761 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
762 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
763 { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
764 { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
765 { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
766 { STATE_TEXTURESTAGE(0, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
767 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
768 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
769 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
770 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
771 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
772 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
773 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
774 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
775 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
776 { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
777 { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
778 { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
779 { STATE_TEXTURESTAGE(1, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
780 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
781 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
782 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
783 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
784 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
785 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
786 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
787 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
788 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
789 { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
790 { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
791 { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
792 { STATE_TEXTURESTAGE(2, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
793 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
794 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
795 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
796 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
797 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
798 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
799 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
800 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
801 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
802 { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
803 { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
804 { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
805 { STATE_TEXTURESTAGE(3, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
806 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
807 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
808 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
809 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
810 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
811 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
812 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
813 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
814 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
815 { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
816 { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
817 { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
818 { STATE_TEXTURESTAGE(4, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
819 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
820 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
821 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
822 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
823 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
824 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
825 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
826 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
827 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
828 { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
829 { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
830 { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
831 { STATE_TEXTURESTAGE(5, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
832 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
833 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
834 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
835 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
836 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
837 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
838 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
839 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
840 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
841 { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
842 { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
843 { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
844 { STATE_TEXTURESTAGE(6, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
845 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
846 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
847 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
848 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), tex_alphaop }, WINED3D_GL_EXT_NONE },
849 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG1), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
850 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG2), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
851 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
852 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
853 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
854 { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), NULL }, NV_TEXTURE_SHADER2 },
855 { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
856 { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG0), { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP), NULL }, WINED3D_GL_EXT_NONE },
857 { STATE_TEXTURESTAGE(7, WINED3D_TSS_RESULT_ARG), { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP), NULL }, WINED3D_GL_EXT_NONE },
858 { STATE_PIXELSHADER, { STATE_PIXELSHADER, apply_pixelshader }, WINED3D_GL_EXT_NONE },
859 { STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE), { STATE_PIXELSHADER, NULL }, WINED3D_GL_EXT_NONE },
860 { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR), nvrc_texfactor }, WINED3D_GL_EXT_NONE },
861 { STATE_RENDER(WINED3D_RS_FOGCOLOR), { STATE_RENDER(WINED3D_RS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE },
862 { STATE_RENDER(WINED3D_RS_FOGDENSITY), { STATE_RENDER(WINED3D_RS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE },
863 { STATE_RENDER(WINED3D_RS_FOGENABLE), { STATE_RENDER(WINED3D_RS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE },
864 { STATE_RENDER(WINED3D_RS_FOGTABLEMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
865 { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE), { STATE_RENDER(WINED3D_RS_FOGENABLE), NULL }, WINED3D_GL_EXT_NONE },
866 { STATE_RENDER(WINED3D_RS_FOGSTART), { STATE_RENDER(WINED3D_RS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE },
867 { STATE_RENDER(WINED3D_RS_FOGEND), { STATE_RENDER(WINED3D_RS_FOGSTART), NULL }, WINED3D_GL_EXT_NONE },
868 { STATE_SAMPLER(0), { STATE_SAMPLER(0), nvts_texdim }, NV_TEXTURE_SHADER2 },
869 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, WINED3D_GL_EXT_NONE },
870 { STATE_SAMPLER(1), { STATE_SAMPLER(1), nvts_texdim }, NV_TEXTURE_SHADER2 },
871 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, WINED3D_GL_EXT_NONE },
872 { STATE_SAMPLER(2), { STATE_SAMPLER(2), nvts_texdim }, NV_TEXTURE_SHADER2 },
873 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, WINED3D_GL_EXT_NONE },
874 { STATE_SAMPLER(3), { STATE_SAMPLER(3), nvts_texdim }, NV_TEXTURE_SHADER2 },
875 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texdim }, WINED3D_GL_EXT_NONE },
876 { STATE_SAMPLER(4), { STATE_SAMPLER(4), nvts_texdim }, NV_TEXTURE_SHADER2 },
877 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texdim }, WINED3D_GL_EXT_NONE },
878 { STATE_SAMPLER(5), { STATE_SAMPLER(5), nvts_texdim }, NV_TEXTURE_SHADER2 },
879 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texdim }, WINED3D_GL_EXT_NONE },
880 { STATE_SAMPLER(6), { STATE_SAMPLER(6), nvts_texdim }, NV_TEXTURE_SHADER2 },
881 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texdim }, WINED3D_GL_EXT_NONE },
882 { STATE_SAMPLER(7), { STATE_SAMPLER(7), nvts_texdim }, NV_TEXTURE_SHADER2 },
883 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texdim }, WINED3D_GL_EXT_NONE },
884 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
887 const struct fragment_pipeline nvts_fragment_pipeline = {
889 nvrc_fragment_get_caps,
892 nvts_color_fixup_supported,
893 nvrc_fragmentstate_template,
894 FALSE /* we cannot disable projected textures. The vertex pipe has to do it */
897 const struct fragment_pipeline nvrc_fragment_pipeline = {
899 nvrc_fragment_get_caps,
902 nvts_color_fixup_supported,
903 nvrc_fragmentstate_template,
904 FALSE /* we cannot disable projected textures. The vertex pipe has to do it */