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
32 void nvts_activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
35 if(stage > 0 && (stateblock->textureState[stage - 1][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAPLUMINANCE ||
36 stateblock->textureState[stage - 1][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAP)) {
38 context->texShaderBumpMap |= (1 << stage);
40 context->texShaderBumpMap &= ~(1 << stage);
43 if(stateblock->textures[stage]) {
44 switch(stateblock->textureDimensions[stage]) {
46 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_2D);
47 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
49 case GL_TEXTURE_RECTANGLE_ARB:
50 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, bumpmap ? GL_OFFSET_TEXTURE_2D_NV : GL_TEXTURE_RECTANGLE_ARB);
51 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, ...)");
54 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D);
55 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_3D)");
57 case GL_TEXTURE_CUBE_MAP_ARB:
58 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB);
59 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_CUBE_MAP_ARB)");
63 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
64 checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE)");
71 GLenum component_usage[3];
74 static GLenum d3dta_to_combiner_input(DWORD d3dta, DWORD stage, INT texture_idx) {
76 case WINED3DTA_DIFFUSE:
77 return GL_PRIMARY_COLOR_NV;
79 case WINED3DTA_CURRENT:
80 if (stage) return GL_SPARE0_NV;
81 else return GL_PRIMARY_COLOR_NV;
83 case WINED3DTA_TEXTURE:
84 if (texture_idx > -1) return GL_TEXTURE0_ARB + texture_idx;
85 else return GL_PRIMARY_COLOR_NV;
87 case WINED3DTA_TFACTOR:
88 return GL_CONSTANT_COLOR0_NV;
90 case WINED3DTA_SPECULAR:
91 return GL_SECONDARY_COLOR_NV;
96 case WINED3DTA_CONSTANT:
97 /* TODO: Support per stage constants (WINED3DTSS_CONSTANT, NV_register_combiners2) */
98 FIXME("WINED3DTA_CONSTANT, not properly supported.\n");
99 return GL_CONSTANT_COLOR1_NV;
102 FIXME("Unrecognized texture arg %#x\n", d3dta);
107 static GLenum invert_mapping(GLenum mapping) {
108 if (mapping == GL_UNSIGNED_INVERT_NV) return GL_UNSIGNED_IDENTITY_NV;
109 else if (mapping == GL_UNSIGNED_IDENTITY_NV) return GL_UNSIGNED_INVERT_NV;
111 FIXME("Unhandled mapping %#x\n", mapping);
115 static void get_src_and_opr_nvrc(DWORD stage, DWORD arg, BOOL is_alpha, GLenum* input, GLenum* mapping, GLenum *component_usage, INT texture_idx) {
116 /* The WINED3DTA_COMPLEMENT flag specifies the complement of the input should
118 if (arg & WINED3DTA_COMPLEMENT) *mapping = GL_UNSIGNED_INVERT_NV;
119 else *mapping = GL_UNSIGNED_IDENTITY_NV; /* Clamp all values to positive ranges */
121 /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the input
122 * should be used for all input components. */
123 if (is_alpha || arg & WINED3DTA_ALPHAREPLICATE) *component_usage = GL_ALPHA;
124 else *component_usage = GL_RGB;
126 *input = d3dta_to_combiner_input(arg & WINED3DTA_SELECTMASK, stage, texture_idx);
129 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) {
130 IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl*)iface;
131 tex_op_args tex_op_args = {{0}, {0}, {0}};
132 GLenum portion = is_alpha ? GL_ALPHA : GL_RGB;
133 GLenum target = GL_COMBINER0_NV + stage;
135 IWineD3DStateBlockImpl *stateblock = This->stateBlock; /* For GLINFO_LOCATION */
137 TRACE("stage %d, is_alpha %d, op %s, arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n",
138 stage, is_alpha, debug_d3dtop(op), arg1, arg2, arg3, texture_idx);
140 /* If a texture stage references an invalid texture unit the stage just
141 * passes through the result from the previous stage */
142 if (is_invalid_op(This, stage, op, arg1, arg2, arg3)) {
143 arg1 = WINED3DTA_CURRENT;
144 op = WINED3DTOP_SELECTARG1;
147 get_src_and_opr_nvrc(stage, arg1, is_alpha, &tex_op_args.input[0],
148 &tex_op_args.mapping[0], &tex_op_args.component_usage[0], texture_idx);
149 get_src_and_opr_nvrc(stage, arg2, is_alpha, &tex_op_args.input[1],
150 &tex_op_args.mapping[1], &tex_op_args.component_usage[1], texture_idx);
151 get_src_and_opr_nvrc(stage, arg3, is_alpha, &tex_op_args.input[2],
152 &tex_op_args.mapping[2], &tex_op_args.component_usage[2], texture_idx);
155 if(dst == WINED3DTA_TEMP) {
156 output = GL_SPARE1_NV;
158 output = GL_SPARE0_NV;
161 /* This is called by a state handler which has the gl lock held and a context for the thread */
164 case WINED3DTOP_DISABLE:
166 if (!is_alpha) ERR("Shouldn't be called for WINED3DTSS_COLOROP (WINED3DTOP_DISABLE)\n");
167 /* Input, prev_alpha*1 */
168 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
169 GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
170 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
171 GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
174 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
175 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
178 case WINED3DTOP_SELECTARG1:
179 case WINED3DTOP_SELECTARG2:
181 if (op == WINED3DTOP_SELECTARG1) {
182 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
183 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
185 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
186 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
188 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
189 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
192 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
193 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
196 case WINED3DTOP_MODULATE:
197 case WINED3DTOP_MODULATE2X:
198 case WINED3DTOP_MODULATE4X:
199 /* Input, arg1*arg2 */
200 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
201 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
202 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
203 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
206 if (op == WINED3DTOP_MODULATE) {
207 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
208 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
209 } else if (op == WINED3DTOP_MODULATE2X) {
210 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
211 GL_DISCARD_NV, GL_SCALE_BY_TWO_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
212 } else if (op == WINED3DTOP_MODULATE4X) {
213 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
214 GL_DISCARD_NV, GL_SCALE_BY_FOUR_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
219 case WINED3DTOP_ADDSIGNED:
220 case WINED3DTOP_ADDSIGNED2X:
221 /* Input, arg1*1+arg2*1 */
222 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
223 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
224 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
225 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
226 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
227 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
228 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
229 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
232 if (op == WINED3DTOP_ADD) {
233 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
234 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
235 } else if (op == WINED3DTOP_ADDSIGNED) {
236 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
237 output, GL_NONE, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
238 } else if (op == WINED3DTOP_ADDSIGNED2X) {
239 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
240 output, GL_SCALE_BY_TWO_NV, GL_BIAS_BY_NEGATIVE_ONE_HALF_NV, GL_FALSE, GL_FALSE, GL_FALSE));
244 case WINED3DTOP_SUBTRACT:
245 /* Input, arg1*1+-arg2*1 */
246 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
247 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
248 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
249 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
250 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
251 tex_op_args.input[1], GL_SIGNED_NEGATE_NV, tex_op_args.component_usage[1]));
252 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
253 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
256 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
257 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
260 case WINED3DTOP_ADDSMOOTH:
261 /* Input, arg1*1+(1-arg1)*arg2 */
262 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
263 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
264 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
265 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
266 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
267 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
268 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
269 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
272 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
273 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
276 case WINED3DTOP_BLENDDIFFUSEALPHA:
277 case WINED3DTOP_BLENDTEXTUREALPHA:
278 case WINED3DTOP_BLENDFACTORALPHA:
279 case WINED3DTOP_BLENDTEXTUREALPHAPM:
280 case WINED3DTOP_BLENDCURRENTALPHA:
282 GLenum alpha_src = GL_PRIMARY_COLOR_NV;
283 if (op == WINED3DTOP_BLENDDIFFUSEALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_DIFFUSE, stage, texture_idx);
284 else if (op == WINED3DTOP_BLENDTEXTUREALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
285 else if (op == WINED3DTOP_BLENDFACTORALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_TFACTOR, stage, texture_idx);
286 else if (op == WINED3DTOP_BLENDTEXTUREALPHAPM) alpha_src = d3dta_to_combiner_input(WINED3DTA_TEXTURE, stage, texture_idx);
287 else if (op == WINED3DTOP_BLENDCURRENTALPHA) alpha_src = d3dta_to_combiner_input(WINED3DTA_CURRENT, stage, texture_idx);
288 else FIXME("Unhandled WINED3DTOP %s, shouldn't happen\n", debug_d3dtop(op));
290 /* Input, arg1*alpha_src+arg2*(1-alpha_src) */
291 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
292 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
293 if (op == WINED3DTOP_BLENDTEXTUREALPHAPM)
295 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
296 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
298 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
299 alpha_src, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA));
301 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
302 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
303 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
304 alpha_src, GL_UNSIGNED_INVERT_NV, GL_ALPHA));
307 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
308 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
312 case WINED3DTOP_MODULATEALPHA_ADDCOLOR:
313 /* Input, arg1_alpha*arg2_rgb+arg1_rgb*1 */
314 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEALPHA_ADDCOLOR)\n");
315 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
316 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
317 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
318 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
319 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
320 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
321 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
322 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
325 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
326 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
329 case WINED3DTOP_MODULATECOLOR_ADDALPHA:
330 /* Input, arg1_rgb*arg2_rgb+arg1_alpha*1 */
331 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATECOLOR_ADDALPHA)\n");
332 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
333 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
334 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
335 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
336 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
337 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
338 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
339 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
342 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
343 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
346 case WINED3DTOP_MODULATEINVALPHA_ADDCOLOR:
347 /* Input, (1-arg1_alpha)*arg2_rgb+arg1_rgb*1 */
348 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEINVALPHA_ADDCOLOR)\n");
349 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
350 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), GL_ALPHA));
351 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
352 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
353 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
354 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
355 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
356 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
359 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
360 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
363 case WINED3DTOP_MODULATEINVCOLOR_ADDALPHA:
364 /* Input, (1-arg1_rgb)*arg2_rgb+arg1_alpha*1 */
365 if (is_alpha) ERR("Only supported for WINED3DTSS_COLOROP (WINED3DTOP_MODULATEINVCOLOR_ADDALPHA)\n");
366 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
367 tex_op_args.input[0], invert_mapping(tex_op_args.mapping[0]), tex_op_args.component_usage[0]));
368 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
369 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
370 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
371 tex_op_args.input[0], tex_op_args.mapping[0], GL_ALPHA));
372 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
373 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
376 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
377 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
380 case WINED3DTOP_DOTPRODUCT3:
381 /* Input, arg1 . arg2 */
382 /* FIXME: DX7 uses a different calculation? */
383 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
384 tex_op_args.input[0], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[0]));
385 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
386 tex_op_args.input[1], GL_EXPAND_NORMAL_NV, tex_op_args.component_usage[1]));
389 GL_EXTCALL(glCombinerOutputNV(target, portion, output, GL_DISCARD_NV,
390 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_FALSE, GL_FALSE));
393 case WINED3DTOP_MULTIPLYADD:
394 /* Input, arg3*1+arg1*arg2 */
395 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
396 tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
397 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
398 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
399 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
400 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
401 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
402 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
405 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
406 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
409 case WINED3DTOP_LERP:
410 /* Input, arg3*arg1+(1-arg3)*arg2 */
411 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
412 tex_op_args.input[2], tex_op_args.mapping[2], tex_op_args.component_usage[2]));
413 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
414 tex_op_args.input[0], tex_op_args.mapping[0], tex_op_args.component_usage[0]));
415 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_C_NV,
416 tex_op_args.input[2], invert_mapping(tex_op_args.mapping[2]), tex_op_args.component_usage[2]));
417 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_D_NV,
418 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
421 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_DISCARD_NV, GL_DISCARD_NV,
422 output, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
425 case WINED3DTOP_BUMPENVMAPLUMINANCE:
426 case WINED3DTOP_BUMPENVMAP:
427 if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
428 /* The bump map stage itself isn't exciting, just read the texture. But tell the next stage to
429 * perform bump mapping and source from the current stage. Pretty much a SELECTARG2.
430 * ARG2 is passed through unmodified(apps will most likely use D3DTA_CURRENT for arg2, arg1
431 * (which will most likely be D3DTA_TEXTURE) is available as a texture shader input for the next stage
433 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_A_NV,
434 tex_op_args.input[1], tex_op_args.mapping[1], tex_op_args.component_usage[1]));
435 GL_EXTCALL(glCombinerInputNV(target, portion, GL_VARIABLE_B_NV,
436 GL_ZERO, GL_UNSIGNED_INVERT_NV, portion));
437 /* Always pass through to CURRENT, ignore temp arg */
438 GL_EXTCALL(glCombinerOutputNV(target, portion, GL_SPARE0_NV, GL_DISCARD_NV,
439 GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE));
444 FIXME("Unhandled WINED3DTOP: stage %d, is_alpha %d, op %s (%#x), arg1 %#x, arg2 %#x, arg3 %#x, texture_idx %d\n",
445 stage, is_alpha, debug_d3dtop(op), op, arg1, arg2, arg3, texture_idx);
448 checkGLcall("set_tex_op_nvrc()\n");
453 static void nvrc_colorop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
454 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
455 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
456 BOOL tex_used = stateblock->wineD3DDevice->fixed_function_usage_map[stage];
458 TRACE("Setting color op for stage %d\n", stage);
460 if (stateblock->pixelShader && stateblock->wineD3DDevice->ps_selected_mode != SHADER_NONE &&
461 ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function) {
462 /* Using a pixel shader? Don't care for anything here, the shader applying does it */
466 if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);
468 if (mapped_stage != -1) {
469 if (GL_SUPPORT(ARB_MULTITEXTURE)) {
470 if (tex_used && mapped_stage >= GL_LIMITS(textures)) {
471 FIXME("Attempt to enable unsupported stage!\n");
474 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
475 checkGLcall("glActiveTextureARB");
476 } else if (stage > 0) {
477 WARN("Program using multiple concurrent textures which this opengl implementation doesn't support\n");
482 if(stateblock->lowest_disabled_stage > 0) {
483 glEnable(GL_REGISTER_COMBINERS_NV);
484 GL_EXTCALL(glCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, stateblock->lowest_disabled_stage));
486 glDisable(GL_REGISTER_COMBINERS_NV);
488 if(stage >= stateblock->lowest_disabled_stage) {
489 TRACE("Stage disabled\n");
490 if (mapped_stage != -1) {
491 /* Disable everything here */
492 glDisable(GL_TEXTURE_2D);
493 checkGLcall("glDisable(GL_TEXTURE_2D)");
494 glDisable(GL_TEXTURE_3D);
495 checkGLcall("glDisable(GL_TEXTURE_3D)");
496 if(GL_SUPPORT(ARB_TEXTURE_CUBE_MAP)) {
497 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
498 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
500 if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE)) {
501 glDisable(GL_TEXTURE_RECTANGLE_ARB);
502 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
504 if(GL_SUPPORT(NV_TEXTURE_SHADER2) && mapped_stage < GL_LIMITS(textures)) {
505 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
512 /* The sampler will also activate the correct texture dimensions, so no need to do it here
513 * if the sampler for this stage is dirty
515 if(!isStateDirty(context, STATE_SAMPLER(stage))) {
517 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
518 nvts_activate_dimensions(stage, stateblock, context);
520 texture_activate_dimensions(stage, stateblock, context);
525 /* Set the texture combiners */
526 set_tex_op_nvrc((IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
527 stateblock->textureState[stage][WINED3DTSS_COLOROP],
528 stateblock->textureState[stage][WINED3DTSS_COLORARG1],
529 stateblock->textureState[stage][WINED3DTSS_COLORARG2],
530 stateblock->textureState[stage][WINED3DTSS_COLORARG0],
532 stateblock->textureState[stage][WINED3DTSS_RESULTARG]);
534 /* In register combiners bump mapping is done in the stage AFTER the one that has the bump map operation set,
535 * thus the texture shader may have to be updated
537 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
538 BOOL usesBump = (stateblock->textureState[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAPLUMINANCE ||
539 stateblock->textureState[stage][WINED3DTSS_COLOROP] == WINED3DTOP_BUMPENVMAP) ? TRUE : FALSE;
540 BOOL usedBump = (context->texShaderBumpMap & 1 << (stage + 1)) ? TRUE : FALSE;
541 if(usesBump != usedBump) {
542 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage + 1));
543 checkGLcall("glActiveTextureARB");
544 nvts_activate_dimensions(stage + 1, stateblock, context);
545 GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
546 checkGLcall("glActiveTextureARB");
551 void nvts_texdim(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
552 DWORD sampler = state - STATE_SAMPLER(0);
553 DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[sampler];
555 /* No need to enable / disable anything here for unused samplers. The tex_colorop
556 * handler takes care. Also no action is needed with pixel shaders, or if tex_colorop
557 * will take care of this business
559 if(mapped_stage == -1 || mapped_stage >= GL_LIMITS(textures)) return;
560 if(sampler >= stateblock->lowest_disabled_stage) return;
561 if(isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP))) return;
563 nvts_activate_dimensions(sampler, stateblock, context);
566 static void nvts_bumpenvmat(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
567 DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
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, WineD3DContext *context) {
595 D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_TEXTUREFACTOR], col);
596 GL_EXTCALL(glCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &col[0]));
598 #undef GLINFO_LOCATION
600 #define GLINFO_LOCATION (*gl_info)
601 static void nvrc_enable(IWineD3DDevice *iface, BOOL enable) { }
603 static void nvts_enable(IWineD3DDevice *iface, BOOL enable) {
605 glEnable(GL_TEXTURE_SHADER_NV);
606 checkGLcall("glEnable(GL_TEXTURE_SHADER_NV)");
608 glDisable(GL_TEXTURE_SHADER_NV);
609 checkGLcall("glDisable(GL_TEXTURE_SHADER_NV)");
613 static void nvrc_fragment_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct fragment_caps *pCaps)
615 pCaps->TextureOpCaps = WINED3DTEXOPCAPS_ADD |
616 WINED3DTEXOPCAPS_ADDSIGNED |
617 WINED3DTEXOPCAPS_ADDSIGNED2X |
618 WINED3DTEXOPCAPS_MODULATE |
619 WINED3DTEXOPCAPS_MODULATE2X |
620 WINED3DTEXOPCAPS_MODULATE4X |
621 WINED3DTEXOPCAPS_SELECTARG1 |
622 WINED3DTEXOPCAPS_SELECTARG2 |
623 WINED3DTEXOPCAPS_DISABLE |
624 WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA |
625 WINED3DTEXOPCAPS_BLENDTEXTUREALPHA |
626 WINED3DTEXOPCAPS_BLENDFACTORALPHA |
627 WINED3DTEXOPCAPS_BLENDCURRENTALPHA |
628 WINED3DTEXOPCAPS_LERP |
629 WINED3DTEXOPCAPS_SUBTRACT |
630 WINED3DTEXOPCAPS_ADDSMOOTH |
631 WINED3DTEXOPCAPS_MULTIPLYADD |
632 WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
633 WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
634 WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM |
635 WINED3DTEXOPCAPS_DOTPRODUCT3 |
636 WINED3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
637 WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA;
639 if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
640 /* Bump mapping is supported already in NV_TEXTURE_SHADER, but that extension does
641 * not support 3D textures. This asks for trouble if an app uses both bump mapping
642 * and 3D textures. It also allows us to keep the code simpler by having texture
643 * shaders constantly enabled.
645 pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAP;
646 /* TODO: Luminance bump map? */
651 pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAPLUMINANCE
652 WINED3DTEXOPCAPS_PREMODULATE */
655 pCaps->MaxTextureBlendStages = GL_LIMITS(texture_stages);
656 pCaps->MaxSimultaneousTextures = GL_LIMITS(textures);
658 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_TSSARGTEMP;
660 /* The caps below can be supported but aren't handled yet in utils.c 'd3dta_to_combiner_input', disable them until support is fixed */
662 if (GL_SUPPORT(NV_REGISTER_COMBINERS2))
663 pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_PERSTAGECONSTANT;
667 static HRESULT nvrc_fragment_alloc(IWineD3DDevice *iface) { return WINED3D_OK; }
668 static void nvrc_fragment_free(IWineD3DDevice *iface) {}
670 /* Two fixed function pipeline implementations using GL_NV_register_combiners and
671 * GL_NV_texture_shader. The nvts_fragment_pipeline assumes that both extensions
672 * are available(geforce 3 and newer), while nvrc_fragment_pipeline uses only the
673 * register combiners extension(Pre-GF3).
676 static BOOL nvts_conv_supported(WINED3DFORMAT fmt) {
677 TRACE("Checking shader format support for format %s: [FAILED]\n", debug_d3dformat(fmt));
681 const struct StateEntryTemplate nvrc_fragmentstate_template[] = {
682 { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
683 { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
684 { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
685 { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
686 { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
687 { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
688 { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
689 { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
690 { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
691 { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
692 { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
693 { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
694 { STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
695 { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
696 { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
697 { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
698 { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
699 { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
700 { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
701 { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
702 { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
703 { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
704 { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
705 { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
706 { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
707 { STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
708 { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
709 { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
710 { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
711 { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
712 { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
713 { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
714 { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
715 { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
716 { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
717 { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
718 { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
719 { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
720 { STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
721 { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
722 { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
723 { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
724 { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
725 { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
726 { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
727 { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
728 { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
729 { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
730 { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
731 { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
732 { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
733 { STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
734 { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
735 { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
736 { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
737 { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
738 { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
739 { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
740 { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
741 { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
742 { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
743 { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
744 { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
745 { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
746 { STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
747 { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
748 { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
749 { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
750 { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
751 { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
752 { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
753 { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
754 { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
755 { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
756 { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
757 { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
758 { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
759 { STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
760 { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
761 { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
762 { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
763 { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
764 { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
765 { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
766 { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
767 { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
768 { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
769 { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
770 { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
771 { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
772 { STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
773 { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
774 { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG1), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
775 { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG2), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
776 { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
777 { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG1), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
778 { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG2), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
779 { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
780 { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT01), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
781 { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT10), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
782 { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT11), { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00), nvts_bumpenvmat }, NV_TEXTURE_SHADER2 },
783 { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG0), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
784 { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG0), { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP), tex_alphaop }, 0 },
785 { STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG), { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP), nvrc_colorop }, 0 },
786 { STATE_PIXELSHADER, { STATE_PIXELSHADER, apply_pixelshader }, 0 },
787 { STATE_RENDER(WINED3DRS_SRGBWRITEENABLE), { STATE_PIXELSHADER, apply_pixelshader }, 0 },
788 { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), { STATE_RENDER(WINED3DRS_TEXTUREFACTOR), nvrc_texfactor }, 0 },
789 { STATE_SAMPLER(0), { STATE_SAMPLER(0), nvts_texdim }, NV_TEXTURE_SHADER2 },
790 { STATE_SAMPLER(0), { STATE_SAMPLER(0), sampler_texdim }, 0 },
791 { STATE_SAMPLER(1), { STATE_SAMPLER(1), nvts_texdim }, NV_TEXTURE_SHADER2 },
792 { STATE_SAMPLER(1), { STATE_SAMPLER(1), sampler_texdim }, 0 },
793 { STATE_SAMPLER(2), { STATE_SAMPLER(2), nvts_texdim }, NV_TEXTURE_SHADER2 },
794 { STATE_SAMPLER(2), { STATE_SAMPLER(2), sampler_texdim }, 0 },
795 { STATE_SAMPLER(3), { STATE_SAMPLER(3), nvts_texdim }, NV_TEXTURE_SHADER2 },
796 { STATE_SAMPLER(3), { STATE_SAMPLER(3), sampler_texdim }, 0 },
797 { STATE_SAMPLER(4), { STATE_SAMPLER(4), nvts_texdim }, NV_TEXTURE_SHADER2 },
798 { STATE_SAMPLER(4), { STATE_SAMPLER(4), sampler_texdim }, 0 },
799 { STATE_SAMPLER(5), { STATE_SAMPLER(5), nvts_texdim }, NV_TEXTURE_SHADER2 },
800 { STATE_SAMPLER(5), { STATE_SAMPLER(5), sampler_texdim }, 0 },
801 { STATE_SAMPLER(6), { STATE_SAMPLER(6), nvts_texdim }, NV_TEXTURE_SHADER2 },
802 { STATE_SAMPLER(6), { STATE_SAMPLER(6), sampler_texdim }, 0 },
803 { STATE_SAMPLER(7), { STATE_SAMPLER(7), nvts_texdim }, NV_TEXTURE_SHADER2 },
804 { STATE_SAMPLER(7), { STATE_SAMPLER(7), sampler_texdim }, 0 },
805 {0 /* Terminate */, { 0, 0 }, 0 },
808 const struct fragment_pipeline nvts_fragment_pipeline = {
810 nvrc_fragment_get_caps,
814 nvrc_fragmentstate_template,
815 FALSE /* we cannot disable projected textures. The vertex pipe has to do it */
818 const struct fragment_pipeline nvrc_fragment_pipeline = {
820 nvrc_fragment_get_caps,
824 nvrc_fragmentstate_template,
825 FALSE /* we cannot disable projected textures. The vertex pipe has to do it */