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