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
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
31 #define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
33 /* GL locking for state handlers is done by the caller. */
35 static void nvts_activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
39 if(stage > 0 && (stateblock->textureState[stage - 1][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAPLUMINANCE ||
40 stateblock->textureState[stage - 1][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAP)) {
42 context->texShaderBumpMap |= (1 << stage);
44 context->texShaderBumpMap &= ~(1 << stage);
47 if(stateblock->textures[stage]) {
48 switch(IWineD3DBaseTexture_GetTextureDimensions(stateblock->textures[stage])) {
50 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_2D);
51 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
53 case GL_TEXTURE_RECTANGLE_ARB:
54 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_RECTANGLE_ARB);
55 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
58 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D);
59 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D)");
61 case GL_TEXTURE_CUBE_MAP_ARB:
62 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB);
63 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB)");
67 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
68 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE)");
75 GLenum component_usage[3];
78 static GLenum d3dta_to_combiner_input(DWORD d3dta, DWORD stage, INT texture_idx) {
80 case WINED3DTA_DIFFUSE:
81 return GL_PRIMARY_COLOR_NV;
83 case WINED3DTA_CURRENT:
84 if (stage) return GL_SPARE0_NV;
85 else return GL_PRIMARY_COLOR_NV;
87 case WINED3DTA_TEXTURE:
88 if (texture_idx > -1) return GL_TEXTURE0_ARB + texture_idx;
89 else return GL_PRIMARY_COLOR_NV;
91 case WINED3DTA_TFACTOR:
92 return GL_CONSTANT_COLOR0_NV;
94 case WINED3DTA_SPECULAR:
95 return GL_SECONDARY_COLOR_NV;
100 case WINED3DTA_CONSTANT:
101 /* TODO: Support per stage constants (WINED3DTSS_CONSTANT, NV_register_combiners2) */
102 FIXME("WINED3DTA_CONSTANT, not properly supported.\n");
103 return GL_CONSTANT_COLOR1_NV;
106 FIXME("Unrecognized texture arg %#x\n", d3dta);
111 static GLenum invert_mapping(GLenum mapping) {
112 if (mapping == GL_UNSIGNED_INVERT_NV) return GL_UNSIGNED_IDENTITY_NV;
113 else if (mapping == GL_UNSIGNED_IDENTITY_NV) return GL_UNSIGNED_INVERT_NV;
115 FIXME("Unhandled mapping %#x\n", mapping);
119 static void get_src_and_opr_nvrc(DWORD stage, DWORD arg, BOOL is_alpha, GLenum* input, GLenum* mapping, GLenum *component_usage, INT texture_idx) {
120 /* The WINED3DTA_COMPLEMENT flag specifies the complement of the input should
122 if (arg & WINED3DTA_COMPLEMENT) *mapping = GL_UNSIGNED_INVERT_NV;
123 else *mapping = GL_UNSIGNED_IDENTITY_NV; /* Clamp all values to positive ranges */
125 /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the input
126 * should be used for all input components. */
127 if (is_alpha || arg & WINED3DTA_ALPHAREPLICATE) *component_usage = GL_ALPHA;
128 else *component_usage = GL_RGB;
130 *input = d3dta_to_combiner_input(arg & WINED3DTA_SELECTMASK, stage, texture_idx);
133 void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst) {
134 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl*)iface;
135 tex_op_args tex_op_args = {{0}, {0}, {0}};
136 GLenum portion = is_alpha ? GL_ALPHA : GL_RGB;
137 GLenum target = GL_COMBINER0_NV + stage;
139 IWineD3DStateBlockImpl *stateblock = This->stateBlock; /* For GLINFO_LOCATION */
141 TRACE("stage %d, is_alpha %d, op %s, arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n",
142 stage, is_alpha, debug_d3dtop(op), arg1, arg2, arg3, texture_idx);
144 /* If a texture stage references an invalid texture unit the stage just
145 * passes through the result from the previous stage */
146 if (is_invalid_op(This, stage, op, arg1, arg2, arg3)) {
147 arg1 = WINED3DTA_CURRENT;
148 op = WINED3DTOP_SELECTARG1;
151 get_src_and_opr_nvrc(stage, arg1, is_alpha, &tex_op_args.input[0],
152 &tex_op_args.mapping[0], &tex_op_args.component_usage[0], texture_idx);
153 get_src_and_opr_nvrc(stage, arg2, is_alpha, &tex_op_args.input[1],
154 &tex_op_args.mapping[1], &tex_op_args.component_usage[1], texture_idx);
155 get_src_and_opr_nvrc(stage, arg3, is_alpha, &tex_op_args.input[2],
156 &tex_op_args.mapping[2], &tex_op_args.component_usage[2], texture_idx);
159 if(dst == WINED3DTA_TEMP) {
160 output = GL_SPARE1_NV;
162 output = GL_SPARE0_NV;
165 /* This is called by a state handler which has the gl lock held and a context for the thread */
168 case WINED3DTOP_DISABLE:
170 if (!is_alpha) ERR("Shouldn't be called for WINED3DTSS_COLOROP (WINED3DTOP_DISABLE)\n");
171 /* Input, prev_alpha*1 */
172 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
173 GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
174 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
175 GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
178 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
179 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
182 case WINED3DTOP_SELECTARG1:
183 case WINED3DTOP_SELECTARG2:
185 if (op == WINED3DTOP_SELECTARG1) {
186 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
187 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
189 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
190 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
192 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
193 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
196 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
197 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
200 case WINED3DTOP_MODULATE:
201 case WINED3DTOP_MODULATE2X:
202 case WINED3DTOP_MODULATE4X:
203 /* Input, arg1*arg2 */
204 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
205 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
206 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
207 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
210 if (op == WINED3DTOP_MODULATE) {
211 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
212 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
213 } else if (op == WINED3DTOP_MODULATE2X) {
214 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
215 GL_DISCARD_NV, GL_SCALE_BY_TWO_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
216 } else if (op == WINED3DTOP_MODULATE4X) {
217 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
218 GL_DISCARD_NV, GL_SCALE_BY_FOUR_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
223 case WINED3DTOP_ADDSIGNED:
224 case WINED3DTOP_ADDSIGNED2X:
225 /* Input, arg1*1+arg2*1 */
226 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
227 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
228 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
229 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
230 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
231 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
232 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
233 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
236 if (op == WINED3DTOP_ADD) {
237 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
238 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
239 } else if (op == WINED3DTOP_ADDSIGNED) {
240 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
241 output, GL_NONE, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
242 } else if (op == WINED3DTOP_ADDSIGNED2X) {
243 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
244 output, GL_SCALE_BY_TWO_NV, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
248 case WINED3DTOP_SUBTRACT:
249 /* Input, arg1*1+-arg2*1 */
250 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
251 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
252 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
253 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
254 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
255 tex_op_args.input[1], GL_SIGNED_NEGATE_NV, tex_op_args.component_usage[1]));
256 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
257 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
260 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
261 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
264 case WINED3DTOP_ADDSMOOTH:
265 /* Input, arg1*1+(1-arg1)*arg2 */
266 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
267 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
268 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
269 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
270 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
271 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
272 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
273 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
276 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
277 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
280 case WINED3DTOP_BLENDDIFFUSEALPHA:
281 case WINED3DTOP_BLENDTEXTUREALPHA:
282 case WINED3DTOP_BLENDFACTORALPHA:
283 case WINED3DTOP_BLENDTEXTUREALPHAPM:
284 case WINED3DTOP_BLENDCURRENTALPHA:
286 GLenum alpha_src = GL_PRIMARY_COLOR_NV;
287 if (op == WINED3DTOP_BLENDDIFFUSEALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_DIFFUSE, stage, texture_idx);
288 else if (op == WINED3DTOP_BLENDTEXTUREALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
289 else if (op == WINED3DTOP_BLENDFACTORALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TFACTOR, stage, texture_idx);
290 else if (op == WINED3DTOP_BLENDTEXTUREALPHAPM) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
291 else if (op == WINED3DTOP_BLENDCURRENTALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_CURRENT, stage, texture_idx);
292 else FIXME("Unhandled WINED3DTOP %s, shouldn't happen\n", debug_d3dtop(op));
294 /* Input, arg1*alpha_src+arg2*(1-alpha_src) */
295 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
296 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
297 if (op == WINED3DTOP_BLENDTEXTUREALPHAPM)
299 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
300 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
302 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
303 alpha_src, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
305 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
306 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
307 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
308 alpha_src, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
311 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
312 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
316 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
317 /* Input, arg1_alpha*arg2_rgb+arg1_rgb*1 */
318 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEALPHA_ADDCOLOR)\n");
319 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
320 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
321 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
322 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
323 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
324 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
325 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
326 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
329 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
330 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
333 case WINED3DTOP_MODULATECOLOR_ADDALPHA:
334 /* Input, arg1_rgb*arg2_rgb+arg1_alpha*1 */
335 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATECOLOR_ADDALPHA)\n");
336 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
337 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
338 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
339 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
340 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
341 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
342 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
343 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
346 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
347 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
350 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
351 /* Input, (1-arg1_alpha)*arg2_rgb+arg1_rgb*1 */
352 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEINVALPHA_ADDCOLOR)\n");
353 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
354 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), GL_ALPHA));
355 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
356 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
357 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
358 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
359 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
360 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
363 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
364 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
367 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
368 /* Input, (1-arg1_rgb)*arg2_rgb+arg1_alpha*1 */
369 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEINVCOLOR_ADDALPHA)\n");
370 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
371 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
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], GL_ALPHA));
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 WINED3DTOP_DOTPRODUCT3:
385 /* Input, arg1 . arg2 */
386 /* FIXME: DX7 uses a different calculation? */
387 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
388 tex_op_args.input[0], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[0]));
389 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
390 tex_op_args.input[1], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[1]));
393 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
394 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_FALSE, GL_FALSE));
397 case WINED3DTOP_MULTIPLYADD:
398 /* Input, arg3*1+arg1*arg2 */
399 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
400 tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
401 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
402 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
403 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
404 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
405 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
406 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
409 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
410 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
413 case WINED3DTOP_LERP:
414 /* Input, arg3*arg1+(1-arg3)*arg2 */
415 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
416 tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
417 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
418 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
419 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
420 tex_op_args.input[2], invert_mapping(tex_op_args.mapping[2]), tex_op_args.component_usage[2]));
421 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
422 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
425 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
426 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
429 case WINED3DTOP_BUMPENVMAPLUMINANCE:
430 case WINED3DTOP_BUMPENVMAP:
431 if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
432 /* The bump map stage itself isn't exciting, just read the texture. But tell the next stage to
433 * perform bump mapping and source from the current stage. Pretty much a SELECTARG2.
434 * ARG2 is passed through unmodified(apps will most likely use D3DTA_CURRENT for arg2, arg1
435 * (which will most likely be D3DTA_TEXTURE) is available as a texture shader input for the next stage
437 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
438 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
439 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
440 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
441 /* Always pass through to CURRENT, ignore temp arg */
442 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
443 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
448 FIXME("Unhandled WINED3DTOP: stage %d, is_alpha %d, op %s (%#x), arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n",
449 stage, is_alpha, debug_d3dtop(op), op, arg1, arg2, arg3, texture_idx);
452 checkGLcall("set_tex_op_nvrc()");
456 static void nvrc_colorop(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
458 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
459 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
460 BOOL tex_used = stateblock->wineD3DDevice->fixed_function_usage_map & (1 << stage);
462 TRACE("Setting color op for stage %d\n", stage);
464 /* Using a pixel shader? Don't care for anything here, the shader applying does it */
465 if (use_ps(stateblock)) return;
467 if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
469 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
471 if (tex_used && mapped_stage >= GL_LIMITS(textures)) {
472 FIXME("Attempt to enable unsupported stage!\n");
475 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
476 checkGLcall("glActiveTextureARB");
479 if(stateblock->lowest_disabled_stage > 0) {
480 glEnable(GL_REGISTER_COMBINERS_NV);
481 GL_EXTCALL(glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, stateblock->lowest_disabled_stage));
483 glDisable(GL_REGISTER_COMBINERS_NV);
485 if(stage >= stateblock->lowest_disabled_stage) {
486 TRACE("Stage disabled\n");
487 if (mapped_stage != WINED3D_UNMAPPED_STAGE)
489 /* Disable everything here */
490 glDisable(GL_TEXTURE_2D);
491 checkGLcall("glDisable(GL_TEXTURE_2D)");
492 glDisable(GL_TEXTURE_3D);
493 checkGLcall("glDisable(GL_TEXTURE_3D)");
494 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
495 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
496 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
498 if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
499 glDisable(GL_TEXTURE_RECTANGLE_ARB);
500 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
502 if(GL_SUPPORT(NV_TEXTURE_SHADER2) && mapped_stage < GL_LIMITS(textures)) {
503 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
510 /* The sampler will also activate the correct texture dimensions, so no need to do it here
511 * if the sampler for this stage is dirty
513 if(!isStateDirty(context, STATE_SAMPLER(stage))) {
515 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
516 nvts_activate_dimensions(stage, stateblock, context);
518 texture_activate_dimensions(stage, stateblock, context);
523 /* Set the texture combiners */
524 set_tex_op_nvrc((IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
525 stateblock->textureState[stage][WINED3DTSS_COLOROP],
526 stateblock->textureState[stage][WINED3DTSS_COLORARG1],
527 stateblock->textureState[stage][WINED3DTSS_COLORARG2],
528 stateblock->textureState[stage][WINED3DTSS_COLORARG0],
530 stateblock->textureState[stage][WINED3DTSS_RESULTARG]);
532 /* In register combiners bump mapping is done in the stage AFTER the one that has the bump map operation set,
533 * thus the texture shader may have to be updated
535 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
536 BOOL usesBump = (stateblock->textureState[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAPLUMINANCE ||
537 stateblock->textureState[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAP) ? TRUE : FALSE;
538 BOOL usedBump = (context->texShaderBumpMap & 1 << (stage + 1)) ? TRUE : FALSE;
539 if(usesBump != usedBump) {
540 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage + 1));
541 checkGLcall("glActiveTextureARB");
542 nvts_activate_dimensions(stage + 1, stateblock, context);
543 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
544 checkGLcall("glActiveTextureARB");
549 static void nvts_texdim(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
551 DWORD sampler = state - STATE_SAMPLER(0);
552 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[sampler];
554 /* No need to enable / disable anything here for unused samplers. The tex_colorop
555 * handler takes care. Also no action is needed with pixel shaders, or if tex_colorop
556 * will take care of this business
558 if(mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= GL_LIMITS(textures)) return;
559 if(sampler >= stateblock->lowest_disabled_stage) return;
560 if(isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) return;
562 nvts_activate_dimensions(sampler, stateblock, context);
565 static void nvts_bumpenvmat(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
567 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
568 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage + 1];
571 /* Direct3D sets the matrix in the stage reading the perturbation map. The result is used to
572 * offset the destination stage(always stage + 1 in d3d). In GL_NV_texture_shader, the bump
573 * map offsetting is done in the stage reading the bump mapped texture, and the perturbation
574 * map is read from a specified source stage(always stage - 1 for d3d). Thus set the matrix
575 * for stage + 1. Keep the nvrc tex unit mapping in mind too
577 if(mapped_stage < GL_LIMITS(textures)) {
578 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
579 checkGLcall("GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage))");
581 /* We can't just pass a pointer to the stateblock to GL due to the different matrix
582 * format(column major vs row major)
584 mat[0][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT00]);
585 mat[1][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT01]);
586 mat[0][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT10]);
587 mat[1][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT11]);
588 glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, (float *) mat);
589 checkGLcall("glTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, mat)");
593 static void nvrc_texfactor(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
596 D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_TEXTUREFACTOR], col);
597 GL_EXTCALL(glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &col[0]));
599 #undef GLINFO_LOCATION
601 #define GLINFO_LOCATION (*gl_info)
602 /* Context activation is done by the caller. */
603 static void nvrc_enable(IWineD3DDevice *iface, BOOL enable) { }
605 /* Context activation is done by the caller. */
606 static void nvts_enable(IWineD3DDevice *iface, BOOL enable) {
609 glEnable(GL_TEXTURE_SHADER_NV);
610 checkGLcall("glEnable(GL_TEXTURE_SHADER_NV)");
612 glDisable(GL_TEXTURE_SHADER_NV);
613 checkGLcall("glDisable(GL_TEXTURE_SHADER_NV)");
618 static void nvrc_fragment_get_caps(WINED3DDEVTYPE devtype,
619 const struct wined3d_gl_info *gl_info, struct fragment_caps *pCaps)
621 pCaps->TextureOpCaps = WINED3DTEXOPCAPS_ADD |
622 WINED3DTEXOPCAPS_ADDSIGNED |
623 WINED3DTEXOPCAPS_ADDSIGNED2X |
624 WINED3DTEXOPCAPS_MODULATE |
625 WINED3DTEXOPCAPS_MODULATE2X |
626 WINED3DTEXOPCAPS_MODULATE4X |
627 WINED3DTEXOPCAPS_SELECTARG1 |
628 WINED3DTEXOPCAPS_SELECTARG2 |
629 WINED3DTEXOPCAPS_DISABLE |
630 WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA |
631 WINED3DTEXOPCAPS_BLENDTEXTUREALPHA |
632 WINED3DTEXOPCAPS_BLENDFACTORALPHA |
633 WINED3DTEXOPCAPS_BLENDCURRENTALPHA |
634 WINED3DTEXOPCAPS_LERP |
635 WINED3DTEXOPCAPS_SUBTRACT |
636 WINED3DTEXOPCAPS_ADDSMOOTH |
637 WINED3DTEXOPCAPS_MULTIPLYADD |
638 WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
639 WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
640 WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM |
641 WINED3DTEXOPCAPS_DOTPRODUCT3 |
642 WINED3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
643 WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA;
645 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
646 /* Bump mapping is supported already in NV_TEXTURE_SHADER, but that extension does
647 * not support 3D textures. This asks for trouble if an app uses both bump mapping
648 * and 3D textures. It also allows us to keep the code simpler by having texture
649 * shaders constantly enabled.
651 pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAP;
652 /* TODO: Luminance bump map? */
657 pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAPLUMINANCE
658 WINED3DTEXOPCAPS_PREMODULATE */
661 pCaps->MaxTextureBlendStages = GL_LIMITS(texture_stages);
662 pCaps->MaxSimultaneousTextures = GL_LIMITS(textures);
664 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_TSSARGTEMP;
666 /* The caps below can be supported but aren't handled yet in utils.c 'd3dta_to_combiner_input', disable them until support is fixed */
668 if (GL_SUPPORT(NV_REGISTER_COMBINERS2))
669 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_PERSTAGECONSTANT;
673 static HRESULT nvrc_fragment_alloc(IWineD3DDevice *iface) { return WINED3D_OK; }
674 /* Context activation is done by the caller. */
675 static void nvrc_fragment_free(IWineD3DDevice *iface) {}
677 /* Two fixed function pipeline implementations using GL_NV_register_combiners and
678 * GL_NV_texture_shader. The nvts_fragment_pipeline assumes that both extensions
679 * are available(geforce 3 and newer), while nvrc_fragment_pipeline uses only the
680 * register combiners extension(Pre-GF3).
683 static BOOL nvts_color_fixup_supported(struct color_fixup_desc fixup)
687 TRACE("Checking support for fixup:\n");
688 dump_color_fixup_desc(fixup);
691 /* We only support identity conversions. */
692 if (is_identity_fixup(fixup))
702 static const struct StateEntryTemplate nvrc_fragmentstate_template[] = {
703 { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
704 { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
705 { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
706 { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
707 { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
708 { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
709 { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
710 { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
711 { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
712 { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
713 { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
714 { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
715 { STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
716 { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
717 { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
718 { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
719 { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
720 { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
721 { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
722 { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
723 { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
724 { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
725 { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
726 { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
727 { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
728 { STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
729 { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
730 { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
731 { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
732 { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
733 { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
734 { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
735 { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
736 { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
737 { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
738 { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
739 { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
740 { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
741 { STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
742 { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
743 { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
744 { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
745 { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
746 { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
747 { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
748 { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
749 { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
750 { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
751 { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
752 { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
753 { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
754 { STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
755 { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
756 { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
757 { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
758 { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
759 { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
760 { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
761 { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
762 { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
763 { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
764 { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
765 { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
766 { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
767 { STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
768 { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
769 { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
770 { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
771 { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
772 { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
773 { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
774 { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
775 { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
776 { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
777 { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
778 { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
779 { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
780 { STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
781 { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
782 { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
783 { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
784 { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
785 { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
786 { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
787 { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
788 { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
789 { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
790 { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
791 { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
792 { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
793 { STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
794 { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
795 { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
796 { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
797 { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
798 { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
799 { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
800 { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
801 { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
802 { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
803 { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
804 { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
805 { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop }, WINED3D_GL_EXT_NONE },
806 { STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), nvrc_colorop }, WINED3D_GL_EXT_NONE },
807 { STATE_PIXELSHADER, { STATE_PIXELSHADER, apply_pixelshader }, WINED3D_GL_EXT_NONE },
808 { STATE_RENDER(WINED3DRS_SRGBWRITEENABLE), { STATE_PIXELSHADER, apply_pixelshader }, WINED3D_GL_EXT_NONE },
809 { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), nvrc_texfactor }, WINED3D_GL_EXT_NONE },
810 { STATE_RENDER(WINED3DRS_FOGCOLOR), { STATE_RENDER(WINED3DRS_FOGCOLOR), state_fogcolor }, WINED3D_GL_EXT_NONE },
811 { STATE_RENDER(WINED3DRS_FOGDENSITY), { STATE_RENDER(WINED3DRS_FOGDENSITY), state_fogdensity }, WINED3D_GL_EXT_NONE },
812 { STATE_RENDER(WINED3DRS_FOGENABLE), { STATE_RENDER(WINED3DRS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE },
813 { STATE_RENDER(WINED3DRS_FOGTABLEMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE },
814 { STATE_RENDER(WINED3DRS_FOGVERTEXMODE), { STATE_RENDER(WINED3DRS_FOGENABLE), state_fog_fragpart }, WINED3D_GL_EXT_NONE },
815 { STATE_RENDER(WINED3DRS_FOGSTART), { STATE_RENDER(WINED3DRS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE },
816 { STATE_RENDER(WINED3DRS_FOGEND), { STATE_RENDER(WINED3DRS_FOGSTART), state_fogstartend }, WINED3D_GL_EXT_NONE },
817 { STATE_SAMPLER(0), { STATE_SAMPLER(0), nvts_texdim }, NV_TEXTURE_SHADER2 },
818 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, WINED3D_GL_EXT_NONE },
819 { STATE_SAMPLER(1), { STATE_SAMPLER(1), nvts_texdim }, NV_TEXTURE_SHADER2 },
820 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, WINED3D_GL_EXT_NONE },
821 { STATE_SAMPLER(2), { STATE_SAMPLER(2), nvts_texdim }, NV_TEXTURE_SHADER2 },
822 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, WINED3D_GL_EXT_NONE },
823 { STATE_SAMPLER(3), { STATE_SAMPLER(3), nvts_texdim }, NV_TEXTURE_SHADER2 },
824 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texdim }, WINED3D_GL_EXT_NONE },
825 { STATE_SAMPLER(4), { STATE_SAMPLER(4), nvts_texdim }, NV_TEXTURE_SHADER2 },
826 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texdim }, WINED3D_GL_EXT_NONE },
827 { STATE_SAMPLER(5), { STATE_SAMPLER(5), nvts_texdim }, NV_TEXTURE_SHADER2 },
828 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texdim }, WINED3D_GL_EXT_NONE },
829 { STATE_SAMPLER(6), { STATE_SAMPLER(6), nvts_texdim }, NV_TEXTURE_SHADER2 },
830 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texdim }, WINED3D_GL_EXT_NONE },
831 { STATE_SAMPLER(7), { STATE_SAMPLER(7), nvts_texdim }, NV_TEXTURE_SHADER2 },
832 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texdim }, WINED3D_GL_EXT_NONE },
833 {0 /* Terminate */, { 0, 0 }, WINED3D_GL_EXT_NONE },
836 const struct fragment_pipeline nvts_fragment_pipeline = {
838 nvrc_fragment_get_caps,
841 nvts_color_fixup_supported,
842 nvrc_fragmentstate_template,
843 FALSE /* we cannot disable projected textures. The vertex pipe has to do it */
846 const struct fragment_pipeline nvrc_fragment_pipeline = {
848 nvrc_fragment_get_caps,
851 nvts_color_fixup_supported,
852 nvrc_fragmentstate_template,
853 FALSE /* we cannot disable projected textures. The vertex pipe has to do it */