state.c 347 KB
Newer Older
1 2 3
/*
 * Direct3D state management
 *
4 5 6 7 8 9
 * Copyright 2002 Lionel Ulmer
 * Copyright 2002-2005 Jason Edmeades
 * Copyright 2003-2004 Raphael Junqueira
 * Copyright 2004 Christian Costa
 * Copyright 2005 Oliver Stieber
 * Copyright 2006 Henri Verbeet
10
 * Copyright 2006-2008 Stefan Dösinger for CodeWeavers
11
 * Copyright 2009-2011 Henri Verbeet for CodeWeavers
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "config.h"
29 30
#include "wine/port.h"

31 32 33 34
#include <stdio.h>
#ifdef HAVE_FLOAT_H
# include <float.h>
#endif
35

36 37 38
#include "wined3d_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(d3d);
39
WINE_DECLARE_DEBUG_CHANNEL(d3d_shader);
40

41
/* Context activation for state handler is done by the caller. */
42

43
static void state_undefined(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
44
{
45
    ERR("Undefined state.\n");
46 47
}

48
void state_nop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
49
{
50
    TRACE("%s: nop in current pipe config.\n", debug_d3dstate(state_id));
51 52
}

53
static void state_fillmode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
54
{
55
    enum wined3d_fill_mode mode = state->render_states[WINED3D_RS_FILLMODE];
56
    const struct wined3d_gl_info *gl_info = context->gl_info;
57

58 59
    switch (mode)
    {
60
        case WINED3D_FILL_POINT:
61
            gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
62 63
            checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_POINT)");
            break;
64
        case WINED3D_FILL_WIREFRAME:
65
            gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
66 67
            checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)");
            break;
68
        case WINED3D_FILL_SOLID:
69
            gl_info->gl_ops.gl.p_glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
70 71 72
            checkGLcall("glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)");
            break;
        default:
73
            FIXME("Unrecognized fill mode %#x.\n", mode);
74 75 76
    }
}

77
static void state_lighting(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
78
{
79 80
    const struct wined3d_gl_info *gl_info = context->gl_info;

81 82 83 84 85 86
    /* Lighting is not enabled if transformed vertices are drawn, but lighting
     * does not affect the stream sources, so it is not grouped for
     * performance reasons. This state reads the decoded vertex declaration,
     * so if it is dirty don't do anything. The vertex declaration applying
     * function calls this function for updating. */
    if (isStateDirty(context, STATE_VDECL))
87
        return;
88

89
    if (state->render_states[WINED3D_RS_LIGHTING]
90
            && !context->stream_info.position_transformed)
91
    {
92
        gl_info->gl_ops.gl.p_glEnable(GL_LIGHTING);
93
        checkGLcall("glEnable GL_LIGHTING");
94 95 96 97
    }
    else
    {
        gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
98 99 100 101
        checkGLcall("glDisable GL_LIGHTING");
    }
}

102
static void state_zenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
103
{
104
    enum wined3d_depth_buffer_type zenable = state->render_states[WINED3D_RS_ZENABLE];
105
    const struct wined3d_gl_info *gl_info = context->gl_info;
106

107
    /* No z test without depth stencil buffers */
108
    if (!state->fb->depth_stencil)
109
    {
110
        TRACE("No Z buffer - disabling depth test\n");
111
        zenable = WINED3D_ZB_FALSE;
112 113
    }

114
    switch (zenable)
115
    {
116
        case WINED3D_ZB_FALSE:
117
            gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
118 119
            checkGLcall("glDisable GL_DEPTH_TEST");
            break;
120
        case WINED3D_ZB_TRUE:
121
            gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
122 123
            checkGLcall("glEnable GL_DEPTH_TEST");
            break;
124
        case WINED3D_ZB_USEW:
125
            gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
126 127 128 129
            checkGLcall("glEnable GL_DEPTH_TEST");
            FIXME("W buffer is not well handled\n");
            break;
        default:
130 131 132 133
            FIXME("Unrecognized depth buffer type %#x.\n", zenable);
            break;
    }

134
    if (context->last_was_rhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
135
        context_apply_state(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
136 137
}

138
static void state_cullmode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
139
{
140 141
    const struct wined3d_gl_info *gl_info = context->gl_info;

142 143
    /* glFrontFace() is set in context.c at context init and on an
     * offscreen / onscreen rendering switch. */
144
    switch (state->render_states[WINED3D_RS_CULLMODE])
145
    {
146
        case WINED3D_CULL_NONE:
147
            gl_info->gl_ops.gl.p_glDisable(GL_CULL_FACE);
148 149
            checkGLcall("glDisable GL_CULL_FACE");
            break;
150
        case WINED3D_CULL_CW:
151
            gl_info->gl_ops.gl.p_glEnable(GL_CULL_FACE);
152
            checkGLcall("glEnable GL_CULL_FACE");
153
            gl_info->gl_ops.gl.p_glCullFace(GL_FRONT);
154
            checkGLcall("glCullFace(GL_FRONT)");
155
            break;
156
        case WINED3D_CULL_CCW:
157
            gl_info->gl_ops.gl.p_glEnable(GL_CULL_FACE);
158
            checkGLcall("glEnable GL_CULL_FACE");
159
            gl_info->gl_ops.gl.p_glCullFace(GL_BACK);
160
            checkGLcall("glCullFace(GL_BACK)");
161 162
            break;
        default:
163
            FIXME("Unrecognized cull mode %#x.\n",
164
                    state->render_states[WINED3D_RS_CULLMODE]);
165 166 167
    }
}

168
void state_shademode(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
169
{
170 171
    const struct wined3d_gl_info *gl_info = context->gl_info;

172
    switch (state->render_states[WINED3D_RS_SHADEMODE])
173
    {
174
        case WINED3D_SHADE_FLAT:
175
            gl_info->gl_ops.gl.p_glShadeModel(GL_FLAT);
176 177
            checkGLcall("glShadeModel(GL_FLAT)");
            break;
178
        case WINED3D_SHADE_GOURAUD:
179 180 181
        /* WINED3D_SHADE_PHONG in practice is the same as WINED3D_SHADE_GOURAUD
         * in D3D. */
        case WINED3D_SHADE_PHONG:
182
            gl_info->gl_ops.gl.p_glShadeModel(GL_SMOOTH);
183 184 185
            checkGLcall("glShadeModel(GL_SMOOTH)");
            break;
        default:
186
            FIXME("Unrecognized shade mode %#x.\n",
187
                    state->render_states[WINED3D_RS_SHADEMODE]);
188 189 190
    }
}

191
static void state_ditherenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
192
{
193 194
    const struct wined3d_gl_info *gl_info = context->gl_info;

195
    if (state->render_states[WINED3D_RS_DITHERENABLE])
196
    {
197
        gl_info->gl_ops.gl.p_glEnable(GL_DITHER);
198
        checkGLcall("glEnable GL_DITHER");
199 200 201
    }
    else
    {
202
        gl_info->gl_ops.gl.p_glDisable(GL_DITHER);
203 204 205 206
        checkGLcall("glDisable GL_DITHER");
    }
}

207
static void state_zwritenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
208
{
209 210
    const struct wined3d_gl_info *gl_info = context->gl_info;

211
    if (state->render_states[WINED3D_RS_ZWRITEENABLE])
212
    {
213
        gl_info->gl_ops.gl.p_glDepthMask(1);
214
        checkGLcall("glDepthMask(1)");
215 216 217
    }
    else
    {
218
        gl_info->gl_ops.gl.p_glDepthMask(0);
219 220 221 222
        checkGLcall("glDepthMask(0)");
    }
}

223
GLenum wined3d_gl_compare_func(enum wined3d_cmp_func f)
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
{
    switch (f)
    {
        case WINED3D_CMP_NEVER:
            return GL_NEVER;
        case WINED3D_CMP_LESS:
            return GL_LESS;
        case WINED3D_CMP_EQUAL:
            return GL_EQUAL;
        case WINED3D_CMP_LESSEQUAL:
            return GL_LEQUAL;
        case WINED3D_CMP_GREATER:
            return GL_GREATER;
        case WINED3D_CMP_NOTEQUAL:
            return GL_NOTEQUAL;
        case WINED3D_CMP_GREATEREQUAL:
            return GL_GEQUAL;
        case WINED3D_CMP_ALWAYS:
            return GL_ALWAYS;
        default:
            FIXME("Unrecognized compare function %#x.\n", f);
            return GL_NONE;
    }
}

249
static void state_zfunc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
250
{
251
    GLenum depth_func = wined3d_gl_compare_func(state->render_states[WINED3D_RS_ZFUNC]);
252
    const struct wined3d_gl_info *gl_info = context->gl_info;
253

254
    if (!depth_func) return;
255

256
    gl_info->gl_ops.gl.p_glDepthFunc(depth_func);
257
    checkGLcall("glDepthFunc");
258 259
}

260
static void state_ambient(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
261
{
262
    const struct wined3d_gl_info *gl_info = context->gl_info;
263
    float col[4];
264

265
    D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_AMBIENT], col);
266
    TRACE("Setting ambient to (%f,%f,%f,%f)\n", col[0], col[1], col[2], col[3]);
267
    gl_info->gl_ops.gl.p_glLightModelfv(GL_LIGHT_MODEL_AMBIENT, col);
268 269 270
    checkGLcall("glLightModel for MODEL_AMBIENT");
}

271 272 273 274 275
static void state_blendop_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
    WARN("Unsupported in local OpenGL implementation: glBlendEquation\n");
}

276
static GLenum gl_blend_op(const struct wined3d_gl_info *gl_info, enum wined3d_blend_op op)
277 278 279
{
    switch (op)
    {
280
        case WINED3D_BLEND_OP_ADD:
281
            return GL_FUNC_ADD;
282
        case WINED3D_BLEND_OP_SUBTRACT:
283
            return gl_info->supported[EXT_BLEND_SUBTRACT] ? GL_FUNC_SUBTRACT : GL_FUNC_ADD;
284
        case WINED3D_BLEND_OP_REVSUBTRACT:
285
            return gl_info->supported[EXT_BLEND_SUBTRACT] ? GL_FUNC_REVERSE_SUBTRACT : GL_FUNC_ADD;
286
        case WINED3D_BLEND_OP_MIN:
287
            return gl_info->supported[EXT_BLEND_MINMAX] ? GL_MIN : GL_FUNC_ADD;
288
        case WINED3D_BLEND_OP_MAX:
289
            return gl_info->supported[EXT_BLEND_MINMAX] ? GL_MAX : GL_FUNC_ADD;
290 291
        default:
            FIXME("Unhandled blend op %#x.\n", op);
292
            return GL_FUNC_ADD;
293 294 295 296 297 298 299 300 301 302
    }
}

static void state_blendop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
    const struct wined3d_gl_info *gl_info = context->gl_info;
    GLenum blend_equation_alpha = GL_FUNC_ADD_EXT;
    GLenum blend_equation = GL_FUNC_ADD_EXT;

    /* BLENDOPALPHA requires GL_EXT_blend_equation_separate, so make sure it is around */
303
    if (state->render_states[WINED3D_RS_BLENDOPALPHA]
304 305
            && !gl_info->supported[EXT_BLEND_EQUATION_SEPARATE])
    {
306
        WARN("Unsupported in local OpenGL implementation: glBlendEquationSeparate.\n");
307 308 309
        return;
    }

310 311
    blend_equation = gl_blend_op(gl_info, state->render_states[WINED3D_RS_BLENDOP]);
    blend_equation_alpha = gl_blend_op(gl_info, state->render_states[WINED3D_RS_BLENDOPALPHA]);
312 313
    TRACE("blend_equation %#x, blend_equation_alpha %#x.\n", blend_equation, blend_equation_alpha);

314
    if (state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE])
315
    {
316 317
        GL_EXTCALL(glBlendEquationSeparate(blend_equation, blend_equation_alpha));
        checkGLcall("glBlendEquationSeparate");
318 319 320
    }
    else
    {
321
        GL_EXTCALL(glBlendEquation(blend_equation));
322 323 324 325
        checkGLcall("glBlendEquation");
    }
}

326
static GLenum gl_blend_factor(enum wined3d_blend factor, const struct wined3d_format *dst_format)
327 328 329
{
    switch (factor)
    {
330
        case WINED3D_BLEND_ZERO:
331
            return GL_ZERO;
332
        case WINED3D_BLEND_ONE:
333
            return GL_ONE;
334
        case WINED3D_BLEND_SRCCOLOR:
335
            return GL_SRC_COLOR;
336
        case WINED3D_BLEND_INVSRCCOLOR:
337
            return GL_ONE_MINUS_SRC_COLOR;
338
        case WINED3D_BLEND_SRCALPHA:
339
            return GL_SRC_ALPHA;
340
        case WINED3D_BLEND_INVSRCALPHA:
341
            return GL_ONE_MINUS_SRC_ALPHA;
342
        case WINED3D_BLEND_DESTCOLOR:
343
            return GL_DST_COLOR;
344
        case WINED3D_BLEND_INVDESTCOLOR:
345 346 347 348
            return GL_ONE_MINUS_DST_COLOR;
        /* To compensate for the lack of format switching with backbuffer
         * offscreen rendering, and with onscreen rendering, we modify the
         * alpha test parameters for (INV)DESTALPHA if the render target
349
         * doesn't support alpha blending. A nonexistent alpha channel
350 351 352
         * returns 1.0, so WINED3D_BLEND_DESTALPHA becomes GL_ONE, and
         * WINED3D_BLEND_INVDESTALPHA becomes GL_ZERO. */
        case WINED3D_BLEND_DESTALPHA:
353
            return dst_format->alpha_size ? GL_DST_ALPHA : GL_ONE;
354
        case WINED3D_BLEND_INVDESTALPHA:
355
            return dst_format->alpha_size ? GL_ONE_MINUS_DST_ALPHA : GL_ZERO;
356
        case WINED3D_BLEND_SRCALPHASAT:
357
            return GL_SRC_ALPHA_SATURATE;
358
        case WINED3D_BLEND_BLENDFACTOR:
359
            return GL_CONSTANT_COLOR_EXT;
360
        case WINED3D_BLEND_INVBLENDFACTOR:
361 362 363 364 365 366 367
            return GL_ONE_MINUS_CONSTANT_COLOR_EXT;
        default:
            FIXME("Unhandled blend factor %#x.\n", factor);
            return GL_NONE;
    }
}

368
static void state_blend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
369
{
370
    const struct wined3d_format *rt_format = state->fb->render_targets[0]->format;
371
    unsigned int rt_fmt_flags = state->fb->render_targets[0]->format_flags;
372
    const struct wined3d_gl_info *gl_info = context->gl_info;
373
    GLenum srcBlend, dstBlend;
374
    enum wined3d_blend d3d_blend;
375

376 377
    /* According to the red book, GL_LINE_SMOOTH needs GL_BLEND with specific
     * blending parameters to work. */
378 379 380
    if (state->render_states[WINED3D_RS_ALPHABLENDENABLE]
            || state->render_states[WINED3D_RS_EDGEANTIALIAS]
            || state->render_states[WINED3D_RS_ANTIALIASEDLINEENABLE])
381 382 383
    {
        /* Disable blending in all cases even without pixelshaders.
         * With blending on we could face a big performance penalty.
384
         * The d3d9 visual test confirms the behavior. */
385
        if (context->render_offscreen && !(rt_fmt_flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING))
386
        {
387
            gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
388 389
            checkGLcall("glDisable GL_BLEND");
            return;
390 391 392 393
        }
        else
        {
            gl_info->gl_ops.gl.p_glEnable(GL_BLEND);
394 395
            checkGLcall("glEnable GL_BLEND");
        }
396 397 398 399
    }
    else
    {
        gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
400 401 402 403 404
        checkGLcall("glDisable GL_BLEND");
        /* Nothing more to do - get out */
        return;
    };

405
    /* WINED3D_BLEND_BOTHSRCALPHA and WINED3D_BLEND_BOTHINVSRCALPHA are legacy
406 407
     * source blending values which are still valid up to d3d9. They should
     * not occur as dest blend values. */
408
    d3d_blend = state->render_states[WINED3D_RS_SRCBLEND];
409
    if (d3d_blend == WINED3D_BLEND_BOTHSRCALPHA)
410
    {
411 412
        srcBlend = GL_SRC_ALPHA;
        dstBlend = GL_ONE_MINUS_SRC_ALPHA;
413
    }
414
    else if (d3d_blend == WINED3D_BLEND_BOTHINVSRCALPHA)
415
    {
416 417 418 419 420
        srcBlend = GL_ONE_MINUS_SRC_ALPHA;
        dstBlend = GL_SRC_ALPHA;
    }
    else
    {
421 422
        srcBlend = gl_blend_factor(d3d_blend, rt_format);
        dstBlend = gl_blend_factor(state->render_states[WINED3D_RS_DESTBLEND], rt_format);
423 424
    }

425 426
    if (state->render_states[WINED3D_RS_EDGEANTIALIAS]
            || state->render_states[WINED3D_RS_ANTIALIASEDLINEENABLE])
427
    {
428
        gl_info->gl_ops.gl.p_glEnable(GL_LINE_SMOOTH);
429
        checkGLcall("glEnable(GL_LINE_SMOOTH)");
430 431 432 433 434 435 436 437
        if (srcBlend != GL_SRC_ALPHA)
            WARN("WINED3D_RS_EDGEANTIALIAS enabled, but unexpected src blending param.\n");
        if (dstBlend != GL_ONE_MINUS_SRC_ALPHA && dstBlend != GL_ONE)
            WARN("WINED3D_RS_EDGEANTIALIAS enabled, but unexpected dst blending param.\n");
    }
    else
    {
        gl_info->gl_ops.gl.p_glDisable(GL_LINE_SMOOTH);
438 439 440
        checkGLcall("glDisable(GL_LINE_SMOOTH)");
    }

441
    /* Re-apply BLENDOP(ALPHA) because of a possible SEPARATEALPHABLENDENABLE change */
442 443
    if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_BLENDOP)))
        state_blendop(context, state, STATE_RENDER(WINED3D_RS_BLENDOPALPHA));
444

445
    if (state->render_states[WINED3D_RS_SEPARATEALPHABLENDENABLE])
446
    {
447
        GLenum srcBlendAlpha, dstBlendAlpha;
448 449

        /* Separate alpha blending requires GL_EXT_blend_function_separate, so make sure it is around */
450 451
        if (!context->gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
        {
452
            WARN("Unsupported in local OpenGL implementation: glBlendFuncSeparate.\n");
453 454 455
            return;
        }

456
        /* WINED3D_BLEND_BOTHSRCALPHA and WINED3D_BLEND_BOTHINVSRCALPHA are legacy
457 458
         * source blending values which are still valid up to d3d9. They should
         * not occur as dest blend values. */
459
        d3d_blend = state->render_states[WINED3D_RS_SRCBLENDALPHA];
460
        if (d3d_blend == WINED3D_BLEND_BOTHSRCALPHA)
461
        {
462 463
            srcBlendAlpha = GL_SRC_ALPHA;
            dstBlendAlpha = GL_ONE_MINUS_SRC_ALPHA;
464
        }
465
        else if (d3d_blend == WINED3D_BLEND_BOTHINVSRCALPHA)
466 467 468 469 470
        {
            srcBlendAlpha = GL_ONE_MINUS_SRC_ALPHA;
            dstBlendAlpha = GL_SRC_ALPHA;
        }
        else
471
        {
472 473
            srcBlendAlpha = gl_blend_factor(d3d_blend, rt_format);
            dstBlendAlpha = gl_blend_factor(state->render_states[WINED3D_RS_DESTBLENDALPHA], rt_format);
474 475
        }

476 477
        GL_EXTCALL(glBlendFuncSeparate(srcBlend, dstBlend, srcBlendAlpha, dstBlendAlpha));
        checkGLcall("glBlendFuncSeparate");
478 479 480
    }
    else
    {
481
        TRACE("glBlendFunc src=%x, dst=%x\n", srcBlend, dstBlend);
482
        gl_info->gl_ops.gl.p_glBlendFunc(srcBlend, dstBlend);
483 484
        checkGLcall("glBlendFunc");
    }
485

486
    /* Colorkey fixup for stage 0 alphaop depends on
487 488
     * WINED3D_RS_ALPHABLENDENABLE state, so it may need updating. */
    if (state->render_states[WINED3D_RS_COLORKEYENABLE])
489
        context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP));
490 491
}

492
static void state_blendfactor_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
493
{
494
    WARN("Unsupported in local OpenGL implementation: glBlendColor.\n");
495 496
}

497
static void state_blendfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
498
{
499
    const struct wined3d_gl_info *gl_info = context->gl_info;
500
    float col[4];
501

502 503 504
    TRACE("Setting blend factor to %#x.\n", state->render_states[WINED3D_RS_BLENDFACTOR]);

    D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_BLENDFACTOR], col);
505
    GL_EXTCALL(glBlendColor(col[0], col[1], col[2], col[3]));
506 507 508
    checkGLcall("glBlendColor");
}

509
void state_alpha_test(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
510
{
511
    const struct wined3d_gl_info *gl_info = context->gl_info;
512 513 514 515
    int glParm = 0;
    float ref;
    BOOL enable_ckey = FALSE;

516
    TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
517

518 519 520 521 522 523 524
    /* Find out if the texture on the first stage has a ckey set. The alpha
     * state func reads the texture settings, even though alpha and texture
     * are not grouped together. This is to avoid making a huge alpha +
     * texture + texture stage + ckey block due to the hardly used
     * WINED3D_RS_COLORKEYENABLE state(which is d3d <= 3 only). The texture
     * function will call alpha in case it finds some texture + colorkeyenable
     * combination which needs extra care. */
525
    if (state->textures[0] && (state->textures[0]->async.color_key_flags & WINED3D_CKEY_SRC_BLT))
526
        enable_ckey = TRUE;
527

528
    if (enable_ckey || context->last_was_ckey)
529
        context_apply_state(context, state, STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP));
530 531
    context->last_was_ckey = enable_ckey;

532 533
    if (state->render_states[WINED3D_RS_ALPHATESTENABLE]
            || (state->render_states[WINED3D_RS_COLORKEYENABLE] && enable_ckey))
534
    {
535
        gl_info->gl_ops.gl.p_glEnable(GL_ALPHA_TEST);
536
        checkGLcall("glEnable GL_ALPHA_TEST");
537 538 539 540
    }
    else
    {
        gl_info->gl_ops.gl.p_glDisable(GL_ALPHA_TEST);
541 542 543 544 545 546 547
        checkGLcall("glDisable GL_ALPHA_TEST");
        /* Alpha test is disabled, don't bother setting the params - it will happen on the next
         * enable call
         */
        return;
    }

548
    if (state->render_states[WINED3D_RS_COLORKEYENABLE] && enable_ckey)
549
    {
550
        glParm = GL_NOTEQUAL;
551
        ref = 0.0f;
552 553 554
    }
    else
    {
555
        ref = ((float)state->render_states[WINED3D_RS_ALPHAREF]) / 255.0f;
556
        glParm = wined3d_gl_compare_func(state->render_states[WINED3D_RS_ALPHAFUNC]);
557
    }
558 559 560
    if (glParm)
    {
        gl_info->gl_ops.gl.p_glAlphaFunc(glParm, ref);
561 562 563 564
        checkGLcall("glAlphaFunc");
    }
}

565
void state_clipping(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
566
{
567
    const struct wined3d_gl_info *gl_info = context->gl_info;
568
    DWORD enable  = 0xffffffff;
569 570
    DWORD disable = 0x00000000;

571 572 573 574 575 576 577 578 579 580 581 582 583
    if (use_vs(state) && !context->d3d_info->vs_clipping)
    {
        static BOOL warned;

        /* The OpenGL spec says that clipping planes are disabled when using
         * shaders. Direct3D planes aren't, so that is an issue. The MacOS ATI
         * driver keeps clipping planes activated with shaders in some
         * conditions I got sick of tracking down. The shader state handler
         * disables all clip planes because of that - don't do anything here
         * and keep them disabled. */
        if (state->render_states[WINED3D_RS_CLIPPLANEENABLE] && !warned++)
            FIXME("Clipping not supported with vertex shaders\n");
        return;
584 585
    }

586 587 588 589
    /* glEnable(GL_CLIP_PLANEx) doesn't apply to (ARB backend) vertex shaders.
     * The enabled / disabled planes are hardcoded into the shader. Update the
     * shader to update the enabled clipplanes. In case of fixed function, we
     * need to update the clipping field from ffp_vertex_settings. */
590
    context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
591

592
    /* TODO: Keep track of previously enabled clipplanes to avoid unnecessary resetting
593 594 595 596 597 598
     * of already set values
     */

    /* If enabling / disabling all
     * TODO: Is this correct? Doesn't D3DRS_CLIPPING disable clipping on the viewport frustrum?
     */
599
    if (state->render_states[WINED3D_RS_CLIPPING])
600
    {
601 602
        enable = state->render_states[WINED3D_RS_CLIPPLANEENABLE];
        disable = ~state->render_states[WINED3D_RS_CLIPPLANEENABLE];
603 604 605
    }
    else
    {
606 607 608 609
        disable = 0xffffffff;
        enable  = 0x00;
    }

610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
    if (enable & WINED3DCLIPPLANE0) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE0);
    if (enable & WINED3DCLIPPLANE1) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE1);
    if (enable & WINED3DCLIPPLANE2) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE2);
    if (enable & WINED3DCLIPPLANE3) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE3);
    if (enable & WINED3DCLIPPLANE4) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE4);
    if (enable & WINED3DCLIPPLANE5) gl_info->gl_ops.gl.p_glEnable(GL_CLIP_PLANE5);
    checkGLcall("clip plane enable");

    if (disable & WINED3DCLIPPLANE0) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE0);
    if (disable & WINED3DCLIPPLANE1) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE1);
    if (disable & WINED3DCLIPPLANE2) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE2);
    if (disable & WINED3DCLIPPLANE3) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE3);
    if (disable & WINED3DCLIPPLANE4) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE4);
    if (disable & WINED3DCLIPPLANE5) gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE5);
    checkGLcall("clip plane disable");
625 626
}

627
static void state_specularenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
628
{
629
    const struct wined3d_gl_info *gl_info = context->gl_info;
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
    /* Originally this used glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR)
     * and (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR) to swap between enabled/disabled
     * specular color. This is wrong:
     * Separate specular color means the specular colour is maintained separately, whereas
     * single color means it is merged in. However in both cases they are being used to
     * some extent.
     * To disable specular color, set it explicitly to black and turn off GL_COLOR_SUM_EXT
     * NOTE: If not supported don't give FIXMEs the impact is really minimal and very few people are
     * running 1.4 yet!
     *
     *
     * If register combiners are enabled, enabling / disabling GL_COLOR_SUM has no effect.
     * Instead, we need to setup the FinalCombiner properly.
     *
     * The default setup for the FinalCombiner is:
     *
     * <variable>       <input>                             <mapping>               <usage>
     * GL_VARIABLE_A_NV GL_FOG,                             GL_UNSIGNED_IDENTITY_NV GL_ALPHA
     * GL_VARIABLE_B_NV GL_SPARE0_PLUS_SECONDARY_COLOR_NV   GL_UNSIGNED_IDENTITY_NV GL_RGB
     * GL_VARIABLE_C_NV GL_FOG                              GL_UNSIGNED_IDENTITY_NV GL_RGB
     * GL_VARIABLE_D_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
     * GL_VARIABLE_E_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
     * GL_VARIABLE_F_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
     * GL_VARIABLE_G_NV GL_SPARE0_NV                        GL_UNSIGNED_IDENTITY_NV GL_ALPHA
     *
     * That's pretty much fine as it is, except for variable B, which needs to take
     * either GL_SPARE0_PLUS_SECONDARY_COLOR_NV or GL_SPARE0_NV, depending on
657
     * whether WINED3D_RS_SPECULARENABLE is enabled or not.
658 659
     */

660
    TRACE("Setting specular enable state and materials\n");
661
    if (state->render_states[WINED3D_RS_SPECULARENABLE])
662
    {
663
        gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.specular);
664
        checkGLcall("glMaterialfv");
665

666
        if (state->material.power > gl_info->limits.shininess)
667
        {
668
            /* glMaterialf man page says that the material says that GL_SHININESS must be between 0.0
669
             * and 128.0, although in d3d neither -1 nor 129 produce an error. GL_NV_max_light_exponent
670 671
             * allows bigger values. If the extension is supported, gl_info->limits.shininess contains the
             * value reported by the extension, otherwise 128. For values > gl_info->limits.shininess clamp
Austin English's avatar
Austin English committed
672
             * them, it should be safe to do so without major visual distortions.
673
             */
674
            WARN("Material power = %.8e, limit %.8e\n", state->material.power, gl_info->limits.shininess);
675
            gl_info->gl_ops.gl.p_glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, gl_info->limits.shininess);
676 677 678
        }
        else
        {
679
            gl_info->gl_ops.gl.p_glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, state->material.power);
680
        }
681
        checkGLcall("glMaterialf(GL_SHININESS)");
682

683
        if (gl_info->supported[EXT_SECONDARY_COLOR])
684
            gl_info->gl_ops.gl.p_glEnable(GL_COLOR_SUM_EXT);
685
        else
686 687 688
            TRACE("Specular colors cannot be enabled in this version of opengl\n");
        checkGLcall("glEnable(GL_COLOR_SUM)");

689
        if (gl_info->supported[NV_REGISTER_COMBINERS])
690
        {
691 692 693 694
            GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_PLUS_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
            checkGLcall("glFinalCombinerInputNV()");
        }
    } else {
695
        static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
696 697

        /* for the case of enabled lighting: */
698
        gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
699 700 701
        checkGLcall("glMaterialfv");

        /* for the case of disabled lighting: */
702
        if (gl_info->supported[EXT_SECONDARY_COLOR])
703
            gl_info->gl_ops.gl.p_glDisable(GL_COLOR_SUM_EXT);
704
        else
705 706 707
            TRACE("Specular colors cannot be disabled in this version of opengl\n");
        checkGLcall("glDisable(GL_COLOR_SUM)");

708
        if (gl_info->supported[NV_REGISTER_COMBINERS])
709
        {
710 711 712 713
            GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
            checkGLcall("glFinalCombinerInputNV()");
        }
    }
714

715 716 717 718 719 720 721 722 723 724 725 726 727
    TRACE("diffuse {%.8e, %.8e, %.8e, %.8e}\n",
            state->material.diffuse.r, state->material.diffuse.g,
            state->material.diffuse.b, state->material.diffuse.a);
    TRACE("ambient {%.8e, %.8e, %.8e, %.8e}\n",
            state->material.ambient.r, state->material.ambient.g,
            state->material.ambient.b, state->material.ambient.a);
    TRACE("specular {%.8e, %.8e, %.8e, %.8e}\n",
            state->material.specular.r, state->material.specular.g,
            state->material.specular.b, state->material.specular.a);
    TRACE("emissive {%.8e, %.8e, %.8e, %.8e}\n",
            state->material.emissive.r, state->material.emissive.g,
            state->material.emissive.b, state->material.emissive.a);

728
    gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
729
    checkGLcall("glMaterialfv(GL_AMBIENT)");
730
    gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
731
    checkGLcall("glMaterialfv(GL_DIFFUSE)");
732
    gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.emissive);
733
    checkGLcall("glMaterialfv(GL_EMISSION)");
734 735
}

736
static void state_texfactor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
737
{
738
    const struct wined3d_gl_info *gl_info = context->gl_info;
739 740 741
    unsigned int i;

    /* Note the texture color applies to all textures whereas
742
     * GL_TEXTURE_ENV_COLOR applies to active only. */
743
    float col[4];
744
    D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_TEXTUREFACTOR], col);
745

746
    /* And now the default texture color as well */
747
    for (i = 0; i < context->d3d_info->limits.ffp_blend_stages; ++i)
748
    {
749 750
        /* Note the WINED3D_RS value applies to all textures, but GL has one
         * per texture, so apply it now ready to be used! */
751
        context_active_texture(context, gl_info, i);
752

753
        gl_info->gl_ops.gl.p_glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &col[0]);
754
        checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);");
755 756 757
    }
}

758 759 760
static void renderstate_stencil_twosided(struct wined3d_context *context, GLint face,
        GLint func, GLint ref, GLuint mask, GLint stencilFail, GLint depthFail, GLint stencilPass)
{
761 762
    const struct wined3d_gl_info *gl_info = context->gl_info;

763
    gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
764 765 766
    checkGLcall("glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
    GL_EXTCALL(glActiveStencilFaceEXT(face));
    checkGLcall("glActiveStencilFaceEXT(...)");
767
    gl_info->gl_ops.gl.p_glStencilFunc(func, ref, mask);
768
    checkGLcall("glStencilFunc(...)");
769
    gl_info->gl_ops.gl.p_glStencilOp(stencilFail, depthFail, stencilPass);
770
    checkGLcall("glStencilOp(...)");
771 772
}

773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
static GLenum gl_stencil_op(enum wined3d_stencil_op op)
{
    switch (op)
    {
        case WINED3D_STENCIL_OP_KEEP:
            return GL_KEEP;
        case WINED3D_STENCIL_OP_ZERO:
            return GL_ZERO;
        case WINED3D_STENCIL_OP_REPLACE:
            return GL_REPLACE;
        case WINED3D_STENCIL_OP_INCR_SAT:
            return GL_INCR;
        case WINED3D_STENCIL_OP_DECR_SAT:
            return GL_DECR;
        case WINED3D_STENCIL_OP_INVERT:
            return GL_INVERT;
        case WINED3D_STENCIL_OP_INCR:
790
            return GL_INCR_WRAP;
791
        case WINED3D_STENCIL_OP_DECR:
792
            return GL_DECR_WRAP;
793 794 795 796 797 798
        default:
            FIXME("Unrecognized stencil op %#x.\n", op);
            return GL_KEEP;
    }
}

799
static void state_stencil(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
800
{
801
    const struct wined3d_gl_info *gl_info = context->gl_info;
802 803
    DWORD onesided_enable;
    DWORD twosided_enable;
804 805 806 807 808 809 810 811 812 813
    GLint func;
    GLint func_ccw;
    GLint ref;
    GLuint mask;
    GLint stencilFail;
    GLint stencilFail_ccw;
    GLint stencilPass;
    GLint stencilPass_ccw;
    GLint depthFail;
    GLint depthFail_ccw;
814

815
    /* No stencil test without a stencil buffer. */
816
    if (!state->fb->depth_stencil)
817
    {
818
        gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
819 820 821 822
        checkGLcall("glDisable GL_STENCIL_TEST");
        return;
    }

823 824
    onesided_enable = state->render_states[WINED3D_RS_STENCILENABLE];
    twosided_enable = state->render_states[WINED3D_RS_TWOSIDEDSTENCILMODE];
825
    if (!(func = wined3d_gl_compare_func(state->render_states[WINED3D_RS_STENCILFUNC])))
826
        func = GL_ALWAYS;
827
    if (!(func_ccw = wined3d_gl_compare_func(state->render_states[WINED3D_RS_CCW_STENCILFUNC])))
828
        func_ccw = GL_ALWAYS;
829 830
    ref = state->render_states[WINED3D_RS_STENCILREF];
    mask = state->render_states[WINED3D_RS_STENCILMASK];
831 832 833 834 835 836
    stencilFail = gl_stencil_op(state->render_states[WINED3D_RS_STENCILFAIL]);
    depthFail = gl_stencil_op(state->render_states[WINED3D_RS_STENCILZFAIL]);
    stencilPass = gl_stencil_op(state->render_states[WINED3D_RS_STENCILPASS]);
    stencilFail_ccw = gl_stencil_op(state->render_states[WINED3D_RS_CCW_STENCILFAIL]);
    depthFail_ccw = gl_stencil_op(state->render_states[WINED3D_RS_CCW_STENCILZFAIL]);
    stencilPass_ccw = gl_stencil_op(state->render_states[WINED3D_RS_CCW_STENCILPASS]);
837

838 839 840
    TRACE("(onesided %d, twosided %d, ref %x, mask %x, "
          "GL_FRONT: func: %x, fail %x, zfail %x, zpass %x "
          "GL_BACK: func: %x, fail %x, zfail %x, zpass %x )\n",
841 842 843 844
    onesided_enable, twosided_enable, ref, mask,
    func, stencilFail, depthFail, stencilPass,
    func_ccw, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);

845 846 847
    if (twosided_enable && onesided_enable)
    {
        gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST);
848 849
        checkGLcall("glEnable GL_STENCIL_TEST");

850 851 852 853 854 855 856 857 858
        if (gl_info->supported[WINED3D_GL_VERSION_2_0])
        {
            GL_EXTCALL(glStencilFuncSeparate(GL_FRONT, func, ref, mask));
            GL_EXTCALL(glStencilOpSeparate(GL_FRONT, stencilFail, depthFail, stencilPass));
            GL_EXTCALL(glStencilFuncSeparate(GL_BACK, func_ccw, ref, mask));
            GL_EXTCALL(glStencilOpSeparate(GL_BACK, stencilFail_ccw, depthFail_ccw, stencilPass_ccw));
            checkGLcall("setting two sided stencil state");
        }
        else if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
859
        {
860 861 862 863 864 865
            /* Apply back first, then front. This function calls glActiveStencilFaceEXT,
             * which has an effect on the code below too. If we apply the front face
             * afterwards, we are sure that the active stencil face is set to front,
             * and other stencil functions which do not use two sided stencil do not have
             * to set it back
             */
866 867 868 869
            renderstate_stencil_twosided(context, GL_BACK,
                    func_ccw, ref, mask, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
            renderstate_stencil_twosided(context, GL_FRONT,
                    func, ref, mask, stencilFail, depthFail, stencilPass);
870
        }
871
        else if (gl_info->supported[ATI_SEPARATE_STENCIL])
872
        {
873 874 875 876 877 878
            GL_EXTCALL(glStencilFuncSeparateATI(func, func_ccw, ref, mask));
            checkGLcall("glStencilFuncSeparateATI(...)");
            GL_EXTCALL(glStencilOpSeparateATI(GL_FRONT, stencilFail, depthFail, stencilPass));
            checkGLcall("glStencilOpSeparateATI(GL_FRONT, ...)");
            GL_EXTCALL(glStencilOpSeparateATI(GL_BACK, stencilFail_ccw, depthFail_ccw, stencilPass_ccw));
            checkGLcall("glStencilOpSeparateATI(GL_BACK, ...)");
879 880 881
        }
        else
        {
882 883
            ERR("Separate (two sided) stencil not supported on this version of opengl. Caps weren't honored?\n");
        }
884 885 886
    }
    else if(onesided_enable)
    {
887
        if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
888
        {
889
            gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
890
            checkGLcall("glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
891
        }
892

893 894 895
        /* This code disables the ATI extension as well, since the standard stencil functions are equal
         * to calling the ATI functions with GL_FRONT_AND_BACK as face parameter
         */
896
        gl_info->gl_ops.gl.p_glEnable(GL_STENCIL_TEST);
897
        checkGLcall("glEnable GL_STENCIL_TEST");
898
        gl_info->gl_ops.gl.p_glStencilFunc(func, ref, mask);
899
        checkGLcall("glStencilFunc(...)");
900
        gl_info->gl_ops.gl.p_glStencilOp(stencilFail, depthFail, stencilPass);
901
        checkGLcall("glStencilOp(...)");
902 903 904 905
    }
    else
    {
        gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST);
906
        checkGLcall("glDisable GL_STENCIL_TEST");
907 908 909
    }
}

910
static void state_stencilwrite2s(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
911
{
912
    DWORD mask = state->fb->depth_stencil ? state->render_states[WINED3D_RS_STENCILWRITEMASK] : 0;
913
    const struct wined3d_gl_info *gl_info = context->gl_info;
914

915 916
    GL_EXTCALL(glActiveStencilFaceEXT(GL_BACK));
    checkGLcall("glActiveStencilFaceEXT(GL_BACK)");
917
    gl_info->gl_ops.gl.p_glStencilMask(mask);
918 919 920
    checkGLcall("glStencilMask");
    GL_EXTCALL(glActiveStencilFaceEXT(GL_FRONT));
    checkGLcall("glActiveStencilFaceEXT(GL_FRONT)");
921
    gl_info->gl_ops.gl.p_glStencilMask(mask);
922 923
}

924
static void state_stencilwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
925
{
926
    DWORD mask = state->fb->depth_stencil ? state->render_states[WINED3D_RS_STENCILWRITEMASK] : 0;
927
    const struct wined3d_gl_info *gl_info = context->gl_info;
928

929
    gl_info->gl_ops.gl.p_glStencilMask(mask);
930 931 932
    checkGLcall("glStencilMask");
}

933
static void state_fog_vertexpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
934
{
935
    const struct wined3d_gl_info *gl_info = context->gl_info;
936

937
    TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
938

939
    if (!state->render_states[WINED3D_RS_FOGENABLE])
940
        return;
941 942

    /* Table fog on: Never use fog coords, and use per-fragment fog */
943
    if (state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE)
944
    {
945 946 947 948
        gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_NICEST);
        if (context->fog_coord)
        {
            gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
949 950 951
            checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
            context->fog_coord = FALSE;
        }
952 953 954 955

        /* Range fog is only used with per-vertex fog in d3d */
        if (gl_info->supported[NV_FOG_DISTANCE])
        {
956
            gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
957 958
            checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)");
        }
959 960 961 962
        return;
    }

    /* Otherwise use per-vertex fog in any case */
963
    gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_FASTEST);
964

965
    if (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE || context->last_was_rhw)
966
    {
967
        /* No fog at all, or transformed vertices: Use fog coord */
968 969 970
        if (!context->fog_coord)
        {
            gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
971 972 973
            checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT)");
            context->fog_coord = TRUE;
        }
974 975 976
    }
    else
    {
977
        /* Otherwise, use the fragment depth */
978 979 980
        if (context->fog_coord)
        {
            gl_info->gl_ops.gl.p_glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
981 982 983
            checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT)");
            context->fog_coord = FALSE;
        }
984

985
        if (state->render_states[WINED3D_RS_RANGEFOGENABLE])
986 987 988
        {
            if (gl_info->supported[NV_FOG_DISTANCE])
            {
989
                gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV);
990 991 992 993 994 995 996 997 998
                checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV)");
            }
            else
            {
                WARN("Range fog enabled, but not supported by this GL implementation.\n");
            }
        }
        else if (gl_info->supported[NV_FOG_DISTANCE])
        {
999
            gl_info->gl_ops.gl.p_glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
1000 1001
            checkGLcall("glFogi(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV)");
        }
1002 1003
    }
}
1004

1005
void state_fogstartend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1006
{
1007
    const struct wined3d_gl_info *gl_info = context->gl_info;
1008 1009
    float fogstart, fogend;

1010
    get_fog_start_end(context, state, &fogstart, &fogend);
1011

1012
    gl_info->gl_ops.gl.p_glFogf(GL_FOG_START, fogstart);
1013 1014 1015
    checkGLcall("glFogf(GL_FOG_START, fogstart)");
    TRACE("Fog Start == %f\n", fogstart);

1016
    gl_info->gl_ops.gl.p_glFogf(GL_FOG_END, fogend);
1017 1018 1019 1020
    checkGLcall("glFogf(GL_FOG_END, fogend)");
    TRACE("Fog End == %f\n", fogend);
}

1021
void state_fog_fragpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1022
{
1023
    const struct wined3d_gl_info *gl_info = context->gl_info;
1024
    enum fogsource new_source;
1025 1026
    DWORD fogstart = state->render_states[WINED3D_RS_FOGSTART];
    DWORD fogend = state->render_states[WINED3D_RS_FOGEND];
1027

1028
    TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
1029

1030
    if (!state->render_states[WINED3D_RS_FOGENABLE])
1031
    {
1032
        /* No fog? Disable it, and we're done :-) */
1033
        glDisableWINE(GL_FOG);
1034
        checkGLcall("glDisable GL_FOG");
1035
        return;
1036 1037
    }

1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
    /* Fog Rules:
     *
     * With fixed function vertex processing, Direct3D knows 2 different fog input sources.
     * It can use the Z value of the vertex, or the alpha component of the specular color.
     * This depends on the fog vertex, fog table and the vertex declaration. If the Z value
     * is used, fogstart, fogend and the equation type are used, otherwise linear fog with
     * start = 255, end = 0 is used. Obviously the msdn is not very clear on that.
     *
     * FOGTABLEMODE != NONE:
     *  The Z value is used, with the equation specified, no matter what vertex type.
     *
     * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, untransformed:
     *  Per vertex fog is calculated using the specified fog equation and the parameters
     *
     * FOGTABLEMODE == NONE, FOGVERTEXMODE != NONE, transformed, OR
     * FOGTABLEMODE == NONE, FOGVERTEXMODE == NONE, untransformed:
     *  Linear fog with start = 255.0, end = 0.0, input comes from the specular color
     *
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
     *
     * Rules for vertex fog with shaders:
     *
     * When mixing fixed function functionality with the programmable pipeline, D3D expects
     * the fog computation to happen during transformation while openGL expects it to happen
     * during rasterization. Also, prior to pixel shader 3.0 D3D handles fog blending after
     * the pixel shader while openGL always expects the pixel shader to handle the blending.
     * To solve this problem, WineD3D does:
     * 1) implement a linear fog equation and fog blending at the end of every pre 3.0 pixel
     * shader,
     * and 2) disables the fog computation (in either the fixed function or programmable
     * rasterizer) if using a vertex program.
     *
1069 1070 1071 1072 1073 1074 1075
     * D3D shaders can provide an explicit fog coordinate. This fog coordinate is used with
     * D3DRS_FOGTABLEMODE==D3DFOG_NONE. The FOGVERTEXMODE is ignored, d3d always uses linear
     * fog with start=1.0 and end=0.0 in this case. This is similar to fog coordinates in
     * the specular color, a vertex shader counts as pretransformed geometry in this case.
     * There are some GL differences between specular fog coords and vertex shaders though.
     *
     * With table fog the vertex shader fog coordinate is ignored.
1076 1077 1078
     *
     * If a fogtablemode and a fogvertexmode are specified, table fog is applied (with or
     * without shaders).
1079
     */
1080

1081 1082 1083
    /* DX 7 sdk: "If both render states(vertex and table fog) are set to valid modes,
     * the system will apply only pixel(=table) fog effects."
     */
1084
    if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
1085
    {
1086 1087
        if (use_vs(state))
        {
1088
            gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1089 1090
            checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
            new_source = FOGSOURCE_VS;
1091 1092 1093
        }
        else
        {
1094
            switch (state->render_states[WINED3D_RS_FOGVERTEXMODE])
1095
            {
1096
                /* If processed vertices are used, fall through to the NONE case */
1097 1098 1099
                case WINED3D_FOG_EXP:
                    if (!context->last_was_rhw)
                    {
1100
                        gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP);
1101 1102 1103 1104 1105 1106
                        checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
                        new_source = FOGSOURCE_FFP;
                        break;
                    }
                    /* drop through */

1107 1108 1109
                case WINED3D_FOG_EXP2:
                    if (!context->last_was_rhw)
                    {
1110
                        gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP2);
1111 1112 1113 1114 1115 1116
                        checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
                        new_source = FOGSOURCE_FFP;
                        break;
                    }
                    /* drop through */

1117 1118 1119
                case WINED3D_FOG_LINEAR:
                    if (!context->last_was_rhw)
                    {
1120
                        gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1121 1122 1123 1124 1125
                        checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
                        new_source = FOGSOURCE_FFP;
                        break;
                    }
                    /* drop through */
1126

1127
                case WINED3D_FOG_NONE:
1128 1129 1130 1131 1132
                    /* Both are none? According to msdn the alpha channel of the specular
                     * color contains a fog factor. Set it in drawStridedSlow.
                     * Same happens with Vertexfog on transformed vertices
                     */
                    new_source = FOGSOURCE_COORD;
1133
                    gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1134
                    checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1135
                    break;
1136

1137
                default:
1138 1139
                    FIXME("Unexpected WINED3D_RS_FOGVERTEXMODE %#x.\n",
                            state->render_states[WINED3D_RS_FOGVERTEXMODE]);
1140 1141
                    new_source = FOGSOURCE_FFP; /* Make the compiler happy */
            }
1142 1143
        }
    } else {
1144
        new_source = FOGSOURCE_FFP;
1145

1146
        switch (state->render_states[WINED3D_RS_FOGTABLEMODE])
1147
        {
1148
            case WINED3D_FOG_EXP:
1149
                gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP);
1150
                checkGLcall("glFogi(GL_FOG_MODE, GL_EXP)");
1151 1152
                break;

1153
            case WINED3D_FOG_EXP2:
1154
                gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_EXP2);
1155
                checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2)");
1156 1157
                break;

1158
            case WINED3D_FOG_LINEAR:
1159
                gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
1160
                checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)");
1161 1162
                break;

1163
            case WINED3D_FOG_NONE:   /* Won't happen */
1164
            default:
1165 1166
                FIXME("Unexpected WINED3D_RS_FOGTABLEMODE %#x.\n",
                        state->render_states[WINED3D_RS_FOGTABLEMODE]);
1167 1168 1169
        }
    }

1170
    glEnableWINE(GL_FOG);
1171
    checkGLcall("glEnable GL_FOG");
1172
    if (new_source != context->fog_source || fogstart == fogend)
1173
    {
1174
        context->fog_source = new_source;
1175
        state_fogstartend(context, state, STATE_RENDER(WINED3D_RS_FOGSTART));
1176
    }
1177
}
1178

1179
void state_fogcolor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1180
{
1181
    const struct wined3d_gl_info *gl_info = context->gl_info;
1182
    float col[4];
1183

1184
    D3DCOLORTOGLFLOAT4(state->render_states[WINED3D_RS_FOGCOLOR], col);
1185
    gl_info->gl_ops.gl.p_glFogfv(GL_FOG_COLOR, col);
1186 1187 1188
    checkGLcall("glFog GL_FOG_COLOR");
}

1189
void state_fogdensity(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1190
{
1191
    const struct wined3d_gl_info *gl_info = context->gl_info;
1192 1193 1194 1195
    union {
        DWORD d;
        float f;
    } tmpvalue;
1196

1197
    tmpvalue.d = state->render_states[WINED3D_RS_FOGDENSITY];
1198
    gl_info->gl_ops.gl.p_glFogfv(GL_FOG_DENSITY, &tmpvalue.f);
1199 1200 1201
    checkGLcall("glFogf(GL_FOG_DENSITY, (float) Value)");
}

1202
static void state_colormat(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1203
{
1204
    const struct wined3d_gl_info *gl_info = context->gl_info;
1205
    GLenum Parm = 0;
1206

1207
    /* Depends on the decoded vertex declaration to read the existence of diffuse data.
1208 1209
     * The vertex declaration will call this function if the fixed function pipeline is used.
     */
1210 1211

    if(isStateDirty(context, STATE_VDECL)) {
1212 1213 1214
        return;
    }

1215
    context->num_untracked_materials = 0;
1216
    if ((context->stream_info.use_map & (1u << WINED3D_FFP_DIFFUSE))
1217
            && state->render_states[WINED3D_RS_COLORVERTEX])
1218
    {
1219
        TRACE("diff %d, amb %d, emis %d, spec %d\n",
1220 1221 1222 1223
                state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE],
                state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE],
                state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE],
                state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE]);
1224

1225
        if (state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1226
        {
1227
            if (state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1228
                Parm = GL_AMBIENT_AND_DIFFUSE;
1229
            else
1230
                Parm = GL_DIFFUSE;
1231
            if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1232
            {
1233 1234 1235
                context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
                context->num_untracked_materials++;
            }
1236
            if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1237
            {
1238 1239 1240
                context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
                context->num_untracked_materials++;
            }
1241
        }
1242
        else if (state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1243
        {
1244
            Parm = GL_AMBIENT;
1245
            if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1246
            {
1247 1248 1249
                context->untracked_materials[context->num_untracked_materials] = GL_EMISSION;
                context->num_untracked_materials++;
            }
1250
            if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1251
            {
1252 1253 1254
                context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
                context->num_untracked_materials++;
            }
1255
        }
1256
        else if (state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1257
        {
1258
            Parm = GL_EMISSION;
1259
            if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1260
            {
1261 1262 1263
                context->untracked_materials[context->num_untracked_materials] = GL_SPECULAR;
                context->num_untracked_materials++;
            }
1264
        }
1265
        else if (state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE] == WINED3D_MCS_COLOR1)
1266
        {
1267 1268
            Parm = GL_SPECULAR;
        }
1269
    }
1270

1271
    /* Nothing changed, return. */
1272
    if (Parm == context->tracking_parm) return;
1273

1274 1275 1276
    if (!Parm)
    {
        gl_info->gl_ops.gl.p_glDisable(GL_COLOR_MATERIAL);
1277
        checkGLcall("glDisable GL_COLOR_MATERIAL");
1278 1279 1280 1281
    }
    else
    {
        gl_info->gl_ops.gl.p_glColorMaterial(GL_FRONT_AND_BACK, Parm);
1282
        checkGLcall("glColorMaterial(GL_FRONT_AND_BACK, Parm)");
1283
        gl_info->gl_ops.gl.p_glEnable(GL_COLOR_MATERIAL);
1284
        checkGLcall("glEnable(GL_COLOR_MATERIAL)");
1285
    }
1286 1287 1288

    /* Apparently calls to glMaterialfv are ignored for properties we're
     * tracking with glColorMaterial, so apply those here. */
1289 1290
    switch (context->tracking_parm)
    {
1291
        case GL_AMBIENT_AND_DIFFUSE:
1292 1293
            gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
            gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
1294 1295 1296 1297
            checkGLcall("glMaterialfv");
            break;

        case GL_DIFFUSE:
1298
            gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, (float *)&state->material.diffuse);
1299 1300 1301 1302
            checkGLcall("glMaterialfv");
            break;

        case GL_AMBIENT:
1303
            gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, (float *)&state->material.ambient);
1304 1305 1306 1307
            checkGLcall("glMaterialfv");
            break;

        case GL_EMISSION:
1308
            gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (float *)&state->material.emissive);
1309 1310 1311 1312 1313
            checkGLcall("glMaterialfv");
            break;

        case GL_SPECULAR:
            /* Only change material color if specular is enabled, otherwise it is set to black */
1314
            if (state->render_states[WINED3D_RS_SPECULARENABLE])
1315
            {
1316
                gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float *)&state->material.specular);
1317
                checkGLcall("glMaterialfv");
1318 1319 1320
            }
            else
            {
1321
                static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
1322
                gl_info->gl_ops.gl.p_glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &black[0]);
1323 1324 1325 1326 1327
                checkGLcall("glMaterialfv");
            }
            break;
    }

1328
    context->tracking_parm = Parm;
1329 1330
}

1331
static void state_linepattern(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1332
{
1333
    const struct wined3d_gl_info *gl_info = context->gl_info;
1334 1335 1336 1337
    union
    {
        DWORD d;
        struct wined3d_line_pattern lp;
1338
    } tmppattern;
1339
    tmppattern.d = state->render_states[WINED3D_RS_LINEPATTERN];
1340

1341
    TRACE("Line pattern: repeat %d bits %x.\n", tmppattern.lp.repeat_factor, tmppattern.lp.line_pattern);
1342

1343 1344
    if (tmppattern.lp.repeat_factor)
    {
1345
        gl_info->gl_ops.gl.p_glLineStipple(tmppattern.lp.repeat_factor, tmppattern.lp.line_pattern);
1346
        checkGLcall("glLineStipple(repeat, linepattern)");
1347
        gl_info->gl_ops.gl.p_glEnable(GL_LINE_STIPPLE);
1348
        checkGLcall("glEnable(GL_LINE_STIPPLE);");
1349 1350 1351
    }
    else
    {
1352
        gl_info->gl_ops.gl.p_glDisable(GL_LINE_STIPPLE);
1353 1354 1355 1356
        checkGLcall("glDisable(GL_LINE_STIPPLE);");
    }
}

1357
static void state_normalize(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1358
{
1359 1360
    const struct wined3d_gl_info *gl_info = context->gl_info;

1361
    if (isStateDirty(context, STATE_VDECL))
1362
        return;
1363

1364 1365 1366 1367
    /* Without vertex normals, we set the current normal to 0/0/0 to remove the diffuse factor
     * from the opengl lighting equation, as d3d does. Normalization of 0/0/0 can lead to a division
     * by zero and is not properly defined in opengl, so avoid it
     */
1368
    if (state->render_states[WINED3D_RS_NORMALIZENORMALS]
1369
            && (context->stream_info.use_map & (1u << WINED3D_FFP_NORMAL)))
1370
    {
1371
        gl_info->gl_ops.gl.p_glEnable(GL_NORMALIZE);
1372
        checkGLcall("glEnable(GL_NORMALIZE);");
1373 1374 1375
    }
    else
    {
1376
        gl_info->gl_ops.gl.p_glDisable(GL_NORMALIZE);
1377 1378 1379 1380
        checkGLcall("glDisable(GL_NORMALIZE);");
    }
}

1381
static void state_psizemin_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1382
{
1383
    float min, max;
1384

1385
    get_pointsize_minmax(context, state, &min, &max);
1386

1387 1388 1389 1390
    if (min != 1.0f)
        FIXME("WINED3D_RS_POINTSIZE_MIN value %.8e not supported on this OpenGL implementation.\n", min);
    if (max != 64.0f)
        FIXME("WINED3D_RS_POINTSIZE_MAX value %.8e not supported on this OpenGL implementation.\n", max);
1391 1392
}

1393
static void state_psizemin_ext(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1394
{
1395
    const struct wined3d_gl_info *gl_info = context->gl_info;
1396
    float min, max;
1397

1398
    get_pointsize_minmax(context, state, &min, &max);
1399

1400
    GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, min);
1401
    checkGLcall("glPointParameterfEXT(...)");
1402
    GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, max);
1403 1404 1405
    checkGLcall("glPointParameterfEXT(...)");
}

1406
static void state_psizemin_arb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1407
{
1408
    const struct wined3d_gl_info *gl_info = context->gl_info;
1409
    float min, max;
1410

1411
    get_pointsize_minmax(context, state, &min, &max);
1412

1413
    GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MIN_ARB, min);
1414
    checkGLcall("glPointParameterfARB(...)");
1415
    GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MAX_ARB, max);
1416
    checkGLcall("glPointParameterfARB(...)");
1417 1418
}

1419
static void state_pscale(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1420
{
1421
    const struct wined3d_gl_info *gl_info = context->gl_info;
1422 1423
    float att[3];
    float pointsize;
1424

1425
    get_pointsize(context, state, &pointsize, att);
1426

1427
    if (gl_info->supported[ARB_POINT_PARAMETERS])
1428
    {
1429
        GL_EXTCALL(glPointParameterfvARB)(GL_POINT_DISTANCE_ATTENUATION_ARB, att);
1430
        checkGLcall("glPointParameterfvARB(GL_DISTANCE_ATTENUATION_ARB, ...)");
1431
    }
1432
    else if (gl_info->supported[EXT_POINT_PARAMETERS])
1433
    {
1434
        GL_EXTCALL(glPointParameterfvEXT)(GL_DISTANCE_ATTENUATION_EXT, att);
1435
        checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...)");
1436
    }
1437
    else if (state->render_states[WINED3D_RS_POINTSCALEENABLE])
1438
    {
1439
        WARN("POINT_PARAMETERS not supported in this version of opengl\n");
1440
    }
1441

1442
    gl_info->gl_ops.gl.p_glPointSize(max(pointsize, FLT_MIN));
1443
    checkGLcall("glPointSize(...);");
1444 1445
}

1446
static void state_debug_monitor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1447
{
1448
    WARN("token: %#x.\n", state->render_states[WINED3D_RS_DEBUGMONITORTOKEN]);
1449 1450
}

1451
static void state_colorwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1452
{
1453 1454 1455 1456
    DWORD mask0 = state->render_states[WINED3D_RS_COLORWRITEENABLE];
    DWORD mask1 = state->render_states[WINED3D_RS_COLORWRITEENABLE1];
    DWORD mask2 = state->render_states[WINED3D_RS_COLORWRITEENABLE2];
    DWORD mask3 = state->render_states[WINED3D_RS_COLORWRITEENABLE3];
1457
    const struct wined3d_gl_info *gl_info = context->gl_info;
1458 1459

    TRACE("Color mask: r(%d) g(%d) b(%d) a(%d)\n",
1460 1461 1462 1463
            mask0 & WINED3DCOLORWRITEENABLE_RED ? 1 : 0,
            mask0 & WINED3DCOLORWRITEENABLE_GREEN ? 1 : 0,
            mask0 & WINED3DCOLORWRITEENABLE_BLUE ? 1 : 0,
            mask0 & WINED3DCOLORWRITEENABLE_ALPHA ? 1 : 0);
1464
    gl_info->gl_ops.gl.p_glColorMask(mask0 & WINED3DCOLORWRITEENABLE_RED ? GL_TRUE : GL_FALSE,
1465 1466 1467
            mask0 & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
            mask0 & WINED3DCOLORWRITEENABLE_BLUE ? GL_TRUE : GL_FALSE,
            mask0 & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE);
1468 1469
    checkGLcall("glColorMask(...)");

1470 1471 1472
    if (!((mask1 == mask0 && mask2 == mask0 && mask3 == mask0)
        || (mask1 == 0xf && mask2 == 0xf && mask3 == 0xf)))
    {
1473
        FIXME("WINED3D_RS_COLORWRITEENABLE/1/2/3, %#x/%#x/%#x/%#x not yet implemented.\n",
1474 1475
            mask0, mask1, mask2, mask3);
        FIXME("Missing of cap D3DPMISCCAPS_INDEPENDENTWRITEMASKS wasn't honored?\n");
1476 1477 1478
    }
}

1479
static void set_color_mask(const struct wined3d_gl_info *gl_info, UINT index, DWORD mask)
1480
{
1481
    GL_EXTCALL(glColorMaski(index,
1482 1483 1484 1485
            mask & WINED3DCOLORWRITEENABLE_RED ? GL_TRUE : GL_FALSE,
            mask & WINED3DCOLORWRITEENABLE_GREEN ? GL_TRUE : GL_FALSE,
            mask & WINED3DCOLORWRITEENABLE_BLUE ? GL_TRUE : GL_FALSE,
            mask & WINED3DCOLORWRITEENABLE_ALPHA ? GL_TRUE : GL_FALSE));
1486
    checkGLcall("glColorMaski");
1487 1488
}

1489
static void state_colorwrite0(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1490
{
1491
    set_color_mask(context->gl_info, 0, state->render_states[WINED3D_RS_COLORWRITEENABLE]);
1492 1493
}

1494
static void state_colorwrite1(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1495
{
1496
    set_color_mask(context->gl_info, 1, state->render_states[WINED3D_RS_COLORWRITEENABLE1]);
1497 1498
}

1499
static void state_colorwrite2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1500
{
1501
    set_color_mask(context->gl_info, 2, state->render_states[WINED3D_RS_COLORWRITEENABLE2]);
1502 1503
}

1504
static void state_colorwrite3(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1505
{
1506
    set_color_mask(context->gl_info, 3, state->render_states[WINED3D_RS_COLORWRITEENABLE3]);
1507 1508
}

1509
static void state_localviewer(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1510
{
1511 1512
    const struct wined3d_gl_info *gl_info = context->gl_info;

1513
    if (state->render_states[WINED3D_RS_LOCALVIEWER])
1514
    {
1515
        gl_info->gl_ops.gl.p_glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
1516
        checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)");
1517 1518 1519 1520
    }
    else
    {
        gl_info->gl_ops.gl.p_glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
1521 1522 1523 1524
        checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)");
    }
}

1525
static void state_lastpixel(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1526
{
1527
    if (state->render_states[WINED3D_RS_LASTPIXEL])
1528
    {
1529
        TRACE("Last Pixel Drawing Enabled\n");
1530 1531 1532
    }
    else
    {
1533 1534
        static BOOL warned;
        if (!warned) {
1535
            FIXME("Last Pixel Drawing Disabled, not handled yet\n");
1536
            warned = TRUE;
1537 1538 1539
        } else {
            TRACE("Last Pixel Drawing Disabled, not handled yet\n");
        }
1540 1541 1542
    }
}

1543
void state_pointsprite_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1544
{
1545 1546
    static BOOL warned;

1547
    /* TODO: NV_POINT_SPRITE */
1548
    if (!warned && state->render_states[WINED3D_RS_POINTSPRITEENABLE])
1549
    {
1550 1551 1552
        /* A FIXME, not a WARN because point sprites should be software emulated if not supported by HW */
        FIXME("Point sprites not supported\n");
        warned = TRUE;
1553
    }
1554
}
1555

1556
void state_pointsprite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1557
{
1558 1559
    const struct wined3d_gl_info *gl_info = context->gl_info;

1560
    if (state->render_states[WINED3D_RS_POINTSPRITEENABLE])
1561
    {
1562
        gl_info->gl_ops.gl.p_glEnable(GL_POINT_SPRITE_ARB);
1563
        checkGLcall("glEnable(GL_POINT_SPRITE_ARB)");
1564 1565 1566 1567
    }
    else
    {
        gl_info->gl_ops.gl.p_glDisable(GL_POINT_SPRITE_ARB);
1568
        checkGLcall("glDisable(GL_POINT_SPRITE_ARB)");
1569 1570 1571
    }
}

1572
static void state_wrap(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1573
{
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590
    if (state->render_states[WINED3D_RS_WRAP0]
            || state->render_states[WINED3D_RS_WRAP1]
            || state->render_states[WINED3D_RS_WRAP2]
            || state->render_states[WINED3D_RS_WRAP3]
            || state->render_states[WINED3D_RS_WRAP4]
            || state->render_states[WINED3D_RS_WRAP5]
            || state->render_states[WINED3D_RS_WRAP6]
            || state->render_states[WINED3D_RS_WRAP7]
            || state->render_states[WINED3D_RS_WRAP8]
            || state->render_states[WINED3D_RS_WRAP9]
            || state->render_states[WINED3D_RS_WRAP10]
            || state->render_states[WINED3D_RS_WRAP11]
            || state->render_states[WINED3D_RS_WRAP12]
            || state->render_states[WINED3D_RS_WRAP13]
            || state->render_states[WINED3D_RS_WRAP14]
            || state->render_states[WINED3D_RS_WRAP15])
        FIXME("(WINED3D_RS_WRAP0) Texture wrapping not yet supported.\n");
1591 1592
}

1593
static void state_msaa_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1594
{
1595
    if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS])
1596
        WARN("Multisample antialiasing not supported by GL.\n");
1597 1598
}

1599
static void state_msaa(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1600
{
1601 1602
    const struct wined3d_gl_info *gl_info = context->gl_info;

1603
    if (state->render_states[WINED3D_RS_MULTISAMPLEANTIALIAS])
1604
    {
1605
        gl_info->gl_ops.gl.p_glEnable(GL_MULTISAMPLE_ARB);
1606
        checkGLcall("glEnable(GL_MULTISAMPLE_ARB)");
1607 1608 1609 1610
    }
    else
    {
        gl_info->gl_ops.gl.p_glDisable(GL_MULTISAMPLE_ARB);
1611
        checkGLcall("glDisable(GL_MULTISAMPLE_ARB)");
1612 1613 1614
    }
}

1615
static void state_scissor(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1616
{
1617 1618
    const struct wined3d_gl_info *gl_info = context->gl_info;

1619
    if (state->render_states[WINED3D_RS_SCISSORTESTENABLE])
1620
    {
1621
        gl_info->gl_ops.gl.p_glEnable(GL_SCISSOR_TEST);
1622
        checkGLcall("glEnable(GL_SCISSOR_TEST)");
1623 1624 1625 1626
    }
    else
    {
        gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
1627 1628 1629 1630
        checkGLcall("glDisable(GL_SCISSOR_TEST)");
    }
}

1631 1632 1633 1634
/* The Direct3D depth bias is specified in normalized depth coordinates. In
 * OpenGL the bias is specified in units of "the smallest value that is
 * guaranteed to produce a resolvable offset for a given implementation". To
 * convert from D3D to GL we need to divide the D3D depth bias by that value.
1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645
 * We try to detect the value from GL with test draws. On most drivers (r300g,
 * 600g, Nvidia, i965 on Mesa) the value is 2^23 for fixed point depth buffers,
 * for r200 and i965 on OSX it is 2^24, for r500 on OSX it is 2^22. For floating
 * point buffers it is 2^22, 2^23 or 2^24 depending on the GPU. The value does
 * not depend on the depth buffer precision on any driver.
 *
 * Two games that are picky regarding depth bias are Mass Effect 2 (flickering
 * decals) and F.E.A.R and F.E.A.R. 2 (semi-transparent guns).
 *
 * Note that SLOPESCALEDEPTHBIAS is a scaling factor for the depth slope, and
 * doesn't need to be scaled to account for GL vs D3D differences. */
1646
static void state_depthbias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1647
{
1648 1649
    const struct wined3d_gl_info *gl_info = context->gl_info;

1650 1651
    if (state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS]
            || state->render_states[WINED3D_RS_DEPTHBIAS])
1652
    {
1653
        const struct wined3d_rendertarget_view *depth = state->fb->depth_stencil;
1654 1655
        float scale;

1656 1657 1658 1659 1660 1661
        union
        {
            DWORD d;
            float f;
        } scale_bias, const_bias;

1662 1663
        scale_bias.d = state->render_states[WINED3D_RS_SLOPESCALEDEPTHBIAS];
        const_bias.d = state->render_states[WINED3D_RS_DEPTHBIAS];
1664

1665
        gl_info->gl_ops.gl.p_glEnable(GL_POLYGON_OFFSET_FILL);
1666
        checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL)");
1667

1668
        if (context->swapchain->device->wined3d->flags & WINED3D_LEGACY_DEPTH_BIAS)
1669
        {
1670
            float bias = -(float)const_bias.d;
1671
            gl_info->gl_ops.gl.p_glPolygonOffset(bias, bias);
1672
            checkGLcall("glPolygonOffset");
1673 1674 1675
        }
        else
        {
1676 1677
            if (depth)
            {
1678 1679 1680 1681 1682
                if (depth->format_flags & WINED3DFMT_FLAG_FLOAT)
                    scale = gl_info->float_polyoffset_scale;
                else
                    scale = gl_info->fixed_polyoffset_scale;

1683
                TRACE("Depth format %s, using depthbias scale of %.8e.\n",
1684
                      debug_d3dformat(depth->format->id), scale);
1685 1686 1687 1688 1689 1690 1691
            }
            else
            {
                /* The context manager will reapply this state on a depth stencil change */
                TRACE("No depth stencil, using depthbias scale of 0.0.\n");
                scale = 0.0f;
            }
1692

1693
            gl_info->gl_ops.gl.p_glPolygonOffset(scale_bias.f, const_bias.f * scale);
1694 1695 1696 1697 1698
            checkGLcall("glPolygonOffset(...)");
        }
    }
    else
    {
1699
        gl_info->gl_ops.gl.p_glDisable(GL_POLYGON_OFFSET_FILL);
1700 1701 1702 1703
        checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL)");
    }
}

1704
static void state_zvisible(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1705
{
1706 1707
    if (state->render_states[WINED3D_RS_ZVISIBLE])
        FIXME("WINED3D_RS_ZVISIBLE not implemented.\n");
1708 1709
}

1710
static void state_stippledalpha(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1711
{
1712
    if (state->render_states[WINED3D_RS_STIPPLEDALPHA])
1713
        FIXME("Stippled Alpha not supported yet.\n");
1714 1715
}

1716
static void state_antialias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1717
{
1718
    if (state->render_states[WINED3D_RS_ANTIALIAS])
1719
        FIXME("Antialias not supported yet.\n");
1720 1721
}

1722
static void state_multisampmask(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1723
{
1724 1725 1726
    if (state->render_states[WINED3D_RS_MULTISAMPLEMASK] != 0xffffffff)
        FIXME("WINED3D_RS_MULTISAMPLEMASK %#x not yet implemented.\n",
                state->render_states[WINED3D_RS_MULTISAMPLEMASK]);
1727 1728
}

1729
static void state_patchedgestyle(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1730
{
1731
    if (state->render_states[WINED3D_RS_PATCHEDGESTYLE] != WINED3D_PATCH_EDGE_DISCRETE)
1732 1733
        FIXME("WINED3D_RS_PATCHEDGESTYLE %#x not yet implemented.\n",
                state->render_states[WINED3D_RS_PATCHEDGESTYLE]);
1734 1735
}

1736
static void state_patchsegments(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1737
{
1738 1739 1740 1741 1742 1743
    union {
        DWORD d;
        float f;
    } tmpvalue;
    tmpvalue.f = 1.0f;

1744
    if (state->render_states[WINED3D_RS_PATCHSEGMENTS] != tmpvalue.d)
1745
    {
1746 1747
        static BOOL displayed = FALSE;

1748
        tmpvalue.d = state->render_states[WINED3D_RS_PATCHSEGMENTS];
1749
        if(!displayed)
1750
            FIXME("(WINED3D_RS_PATCHSEGMENTS,%f) not yet implemented\n", tmpvalue.f);
1751 1752

        displayed = TRUE;
1753
    }
1754 1755
}

1756
static void state_positiondegree(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1757
{
1758 1759 1760
    if (state->render_states[WINED3D_RS_POSITIONDEGREE] != WINED3D_DEGREE_CUBIC)
        FIXME("WINED3D_RS_POSITIONDEGREE %#x not yet implemented.\n",
                state->render_states[WINED3D_RS_POSITIONDEGREE]);
1761 1762
}

1763
static void state_normaldegree(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1764
{
1765 1766 1767
    if (state->render_states[WINED3D_RS_NORMALDEGREE] != WINED3D_DEGREE_LINEAR)
        FIXME("WINED3D_RS_NORMALDEGREE %#x not yet implemented.\n",
                state->render_states[WINED3D_RS_NORMALDEGREE]);
1768 1769
}

1770
static void state_tessellation(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1771
{
1772 1773 1774
    if (state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION])
        FIXME("WINED3D_RS_ENABLEADAPTIVETESSELLATION %#x not yet implemented.\n",
                state->render_states[WINED3D_RS_ENABLEADAPTIVETESSELLATION]);
1775 1776
}

1777
static void state_nvdb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1778 1779 1780 1781 1782 1783 1784 1785
{
    union {
        DWORD d;
        float f;
    } zmin, zmax;

    const struct wined3d_gl_info *gl_info = context->gl_info;

1786
    if (state->render_states[WINED3D_RS_ADAPTIVETESS_X] == WINED3DFMT_NVDB)
1787
    {
1788 1789
        zmin.d = state->render_states[WINED3D_RS_ADAPTIVETESS_Z];
        zmax.d = state->render_states[WINED3D_RS_ADAPTIVETESS_W];
1790 1791 1792 1793 1794

        /* If zmin is larger than zmax INVALID_VALUE error is generated.
         * In d3d9 test is not performed in this case*/
        if (zmin.f <= zmax.f)
        {
1795
            gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_BOUNDS_TEST_EXT);
1796 1797 1798 1799
            checkGLcall("glEnable(GL_DEPTH_BOUNDS_TEST_EXT)");
            GL_EXTCALL(glDepthBoundsEXT(zmin.f, zmax.f));
            checkGLcall("glDepthBoundsEXT(...)");
        }
1800 1801 1802
        else
        {
            gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
1803 1804 1805
            checkGLcall("glDisable(GL_DEPTH_BOUNDS_TEST_EXT)");
        }
    }
1806 1807 1808
    else
    {
        gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_BOUNDS_TEST_EXT);
1809 1810 1811
        checkGLcall("glDisable(GL_DEPTH_BOUNDS_TEST_EXT)");
    }

1812
    state_tessellation(context, state, STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION));
1813 1814
}

1815
static void state_wrapu(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1816
{
1817 1818
    if (state->render_states[WINED3D_RS_WRAPU])
        FIXME("Render state WINED3D_RS_WRAPU not implemented yet.\n");
1819 1820
}

1821
static void state_wrapv(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1822
{
1823 1824
    if (state->render_states[WINED3D_RS_WRAPV])
        FIXME("Render state WINED3D_RS_WRAPV not implemented yet.\n");
1825 1826
}

1827
static void state_monoenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1828
{
1829 1830
    if (state->render_states[WINED3D_RS_MONOENABLE])
        FIXME("Render state WINED3D_RS_MONOENABLE not implemented yet.\n");
1831 1832
}

1833
static void state_rop2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1834
{
1835 1836
    if (state->render_states[WINED3D_RS_ROP2])
        FIXME("Render state WINED3D_RS_ROP2 not implemented yet.\n");
1837 1838
}

1839
static void state_planemask(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1840
{
1841 1842
    if (state->render_states[WINED3D_RS_PLANEMASK])
        FIXME("Render state WINED3D_RS_PLANEMASK not implemented yet.\n");
1843 1844
}

1845
static void state_subpixel(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1846
{
1847 1848
    if (state->render_states[WINED3D_RS_SUBPIXEL])
        FIXME("Render state WINED3D_RS_SUBPIXEL not implemented yet.\n");
1849 1850
}

1851
static void state_subpixelx(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1852
{
1853 1854
    if (state->render_states[WINED3D_RS_SUBPIXELX])
        FIXME("Render state WINED3D_RS_SUBPIXELX not implemented yet.\n");
1855 1856
}

1857
static void state_stippleenable(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1858
{
1859 1860
    if (state->render_states[WINED3D_RS_STIPPLEENABLE])
        FIXME("Render state WINED3D_RS_STIPPLEENABLE not implemented yet.\n");
1861 1862
}

1863
static void state_mipmaplodbias(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1864
{
1865 1866
    if (state->render_states[WINED3D_RS_MIPMAPLODBIAS])
        FIXME("Render state WINED3D_RS_MIPMAPLODBIAS not implemented yet.\n");
1867 1868
}

1869
static void state_anisotropy(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1870
{
1871 1872
    if (state->render_states[WINED3D_RS_ANISOTROPY])
        FIXME("Render state WINED3D_RS_ANISOTROPY not implemented yet.\n");
1873 1874
}

1875
static void state_flushbatch(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1876
{
1877 1878
    if (state->render_states[WINED3D_RS_FLUSHBATCH])
        FIXME("Render state WINED3D_RS_FLUSHBATCH not implemented yet.\n");
1879 1880
}

1881
static void state_translucentsi(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1882
{
1883 1884
    if (state->render_states[WINED3D_RS_TRANSLUCENTSORTINDEPENDENT])
        FIXME("Render state WINED3D_RS_TRANSLUCENTSORTINDEPENDENT not implemented yet.\n");
1885 1886
}

1887
static void state_extents(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1888
{
1889 1890
    if (state->render_states[WINED3D_RS_EXTENTS])
        FIXME("Render state WINED3D_RS_EXTENTS not implemented yet.\n");
1891 1892
}

1893
static void state_ckeyblend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1894
{
1895 1896
    if (state->render_states[WINED3D_RS_COLORKEYBLENDENABLE])
        FIXME("Render state WINED3D_RS_COLORKEYBLENDENABLE not implemented yet.\n");
1897 1898
}

1899
static void state_swvp(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
1900
{
1901
    static int once;
1902
    if (state->render_states[WINED3D_RS_SOFTWAREVERTEXPROCESSING])
1903 1904 1905 1906
    {
        if (!once++)
            FIXME("Software vertex processing not implemented.\n");
    }
1907 1908
}

1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947
static void get_src_and_opr(DWORD arg, BOOL is_alpha, GLenum* source, GLenum* operand) {
    /* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the
    * input should be used for all input components. The WINED3DTA_COMPLEMENT
    * flag specifies the complement of the input should be used. */
    BOOL from_alpha = is_alpha || arg & WINED3DTA_ALPHAREPLICATE;
    BOOL complement = arg & WINED3DTA_COMPLEMENT;

    /* Calculate the operand */
    if (complement) {
        if (from_alpha) *operand = GL_ONE_MINUS_SRC_ALPHA;
        else *operand = GL_ONE_MINUS_SRC_COLOR;
    } else {
        if (from_alpha) *operand = GL_SRC_ALPHA;
        else *operand = GL_SRC_COLOR;
    }

    /* Calculate the source */
    switch (arg & WINED3DTA_SELECTMASK) {
        case WINED3DTA_CURRENT: *source = GL_PREVIOUS_EXT; break;
        case WINED3DTA_DIFFUSE: *source = GL_PRIMARY_COLOR_EXT; break;
        case WINED3DTA_TEXTURE: *source = GL_TEXTURE; break;
        case WINED3DTA_TFACTOR: *source = GL_CONSTANT_EXT; break;
        case WINED3DTA_SPECULAR:
            /*
            * According to the GL_ARB_texture_env_combine specs, SPECULAR is
            * 'Secondary color' and isn't supported until base GL supports it
            * There is no concept of temp registers as far as I can tell
            */
            FIXME("Unhandled texture arg WINED3DTA_SPECULAR\n");
            *source = GL_TEXTURE;
            break;
        default:
            FIXME("Unrecognized texture arg %#x\n", arg);
            *source = GL_TEXTURE;
            break;
    }
}

/* Setup the texture operations texture stage states */
1948
static void set_tex_op(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
1949
        BOOL isAlpha, int Stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3)
1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961
{
    GLenum src1, src2, src3;
    GLenum opr1, opr2, opr3;
    GLenum comb_target;
    GLenum src0_target, src1_target, src2_target;
    GLenum opr0_target, opr1_target, opr2_target;
    GLenum scal_target;
    GLenum opr=0, invopr, src3_target, opr3_target;
    BOOL Handled = FALSE;

    TRACE("Alpha?(%d), Stage:%d Op(%s), a1(%d), a2(%d), a3(%d)\n", isAlpha, Stage, debug_d3dtop(op), arg1, arg2, arg3);

1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972
    /* Operations usually involve two args, src0 and src1 and are operations
     * of the form (a1 <operation> a2). However, some of the more complex
     * operations take 3 parameters. Instead of the (sensible) addition of a3,
     * Microsoft added in a third parameter called a0. Therefore these are
     * operations of the form a0 <operation> a1 <operation> a2. I.e., the new
     * parameter goes to the front.
     *
     * However, below we treat the new (a0) parameter as src2/opr2, so in the
     * actual functions below, expect their syntax to differ slightly to those
     * listed in the manuals. I.e., replace arg1 with arg3, arg2 with arg1 and
     * arg3 with arg2. This affects WINED3DTOP_MULTIPLYADD and WINED3DTOP_LERP. */
1973

1974 1975 1976 1977 1978 1979 1980 1981 1982
    if (isAlpha)
    {
        comb_target = GL_COMBINE_ALPHA;
        src0_target = GL_SOURCE0_ALPHA;
        src1_target = GL_SOURCE1_ALPHA;
        src2_target = GL_SOURCE2_ALPHA;
        opr0_target = GL_OPERAND0_ALPHA;
        opr1_target = GL_OPERAND1_ALPHA;
        opr2_target = GL_OPERAND2_ALPHA;
1983 1984
        scal_target = GL_ALPHA_SCALE;
    }
1985 1986 1987 1988 1989 1990 1991 1992 1993 1994
    else
    {
        comb_target = GL_COMBINE_RGB;
        src0_target = GL_SOURCE0_RGB;
        src1_target = GL_SOURCE1_RGB;
        src2_target = GL_SOURCE2_RGB;
        opr0_target = GL_OPERAND0_RGB;
        opr1_target = GL_OPERAND1_RGB;
        opr2_target = GL_OPERAND2_RGB;
        scal_target = GL_RGB_SCALE;
1995 1996 1997 1998
    }

        /* If a texture stage references an invalid texture unit the stage just
        * passes through the result from the previous stage */
1999
    if (is_invalid_op(state, Stage, op, arg1, arg2, arg3))
2000
    {
2001
        arg1 = WINED3DTA_CURRENT;
2002
        op = WINED3D_TOP_SELECT_ARG1;
2003 2004
    }

2005
    if (isAlpha && !state->textures[Stage] && arg1 == WINED3DTA_TEXTURE)
2006
    {
2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018
        get_src_and_opr(WINED3DTA_DIFFUSE, isAlpha, &src1, &opr1);
    } else {
        get_src_and_opr(arg1, isAlpha, &src1, &opr1);
    }
    get_src_and_opr(arg2, isAlpha, &src2, &opr2);
    get_src_and_opr(arg3, isAlpha, &src3, &opr3);

    TRACE("ct(%x), 1:(%x,%x), 2:(%x,%x), 3:(%x,%x)\n", comb_target, src1, opr1, src2, opr2, src3, opr3);

    Handled = TRUE; /* Assume will be handled */

    /* Other texture operations require special extensions: */
2019
    if (gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
2020
    {
2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031
        if (isAlpha) {
            opr = GL_SRC_ALPHA;
            invopr = GL_ONE_MINUS_SRC_ALPHA;
            src3_target = GL_SOURCE3_ALPHA_NV;
            opr3_target = GL_OPERAND3_ALPHA_NV;
        } else {
            opr = GL_SRC_COLOR;
            invopr = GL_ONE_MINUS_SRC_COLOR;
            src3_target = GL_SOURCE3_RGB_NV;
            opr3_target = GL_OPERAND3_RGB_NV;
        }
2032 2033 2034
        switch (op)
        {
            case WINED3D_TOP_DISABLE: /* Only for alpha */
2035
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2036
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2037
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
2038
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2039
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
2040
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2041
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2042
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2043
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2044
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2045
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2046
                checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
2047
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2048
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2049
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2050
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
                checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
                break;

            case WINED3D_TOP_SELECT_ARG1: /* = a1 * 1 + 0 * 0 */
            case WINED3D_TOP_SELECT_ARG2: /* = a2 * 1 + 0 * 0 */
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
                if (op == WINED3D_TOP_SELECT_ARG1)
                {
                    gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
                    checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
                    gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
                    checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
                }
                else
                {
                    gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
                    checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
                    gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
                    checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
                }
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
                checkGLcall("GL_TEXTURE_ENV, src2_target, GL_ZERO");
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2084 2085 2086
                checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
                break;

2087
            case WINED3D_TOP_MODULATE:
2088
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2089
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2090
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2091
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2092
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2093
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2094
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2095
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2096
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2097
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2098
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2099
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2100
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2101
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2102
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2103
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2104
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2105
                checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2106
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2107 2108
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;
2109
            case WINED3D_TOP_MODULATE_2X:
2110
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2111
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2112
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2113
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2114
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2115
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2116
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2117
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2118
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2119
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2120
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2121
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2122
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2123
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2124
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2125
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2126
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2127
                checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2128
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2129 2130
                checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
                break;
2131
            case WINED3D_TOP_MODULATE_4X:
2132
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2133
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD"); /* Add = a0*a1 + a2*a3 */
2134
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2135
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2136
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2137
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2138
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2139
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2140
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2141
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2142
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_ZERO);
2143
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2144
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2145
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2146
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2147
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2148
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2149
                checkGLcall("GL_TEXTURE_ENV, opr3_target, opr1");
2150
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
2151 2152 2153
                checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
                break;

2154
            case WINED3D_TOP_ADD:
2155
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2156
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2157
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2158
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2159
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2160
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2161
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2162
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2163
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2164
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2165
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2166
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2167
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2168
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2169
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2170
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2171
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2172
                checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2173
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2174 2175 2176
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;

2177
            case WINED3D_TOP_ADD_SIGNED:
2178
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2179
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2180
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2181
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2182
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2183
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2184
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2185
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2186
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2187
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2188
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2189
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2190
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2191
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2192
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2193
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2194
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2195
                checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2196
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2197 2198 2199
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;

2200
            case WINED3D_TOP_ADD_SIGNED_2X:
2201
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2202
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2203
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2204
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2205
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2206
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2207
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2208
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2209
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2210
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2211
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2212
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2213
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2214
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2215
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2216
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2217
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2218
                checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2219
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2220 2221 2222
                checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
                break;

2223
            case WINED3D_TOP_ADD_SMOOTH:
2224
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2225
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2226
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2227
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2228
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2229
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2230
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2231
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2232
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2233
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2234
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2235
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2236
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2237
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2238
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2239 2240 2241 2242 2243 2244 2245
                checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
                switch (opr1) {
                    case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
                    case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
                }
2246
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2247
                checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2248
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2249 2250 2251
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;

2252
            case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
2253
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2254
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2255
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2256
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2257
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2258
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2259
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_PRIMARY_COLOR);
2260
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_PRIMARY_COLOR");
2261
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2262
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2263
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2264
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2265
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2266
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2267
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_PRIMARY_COLOR);
2268
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_PRIMARY_COLOR");
2269
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2270
                checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2271
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2272 2273
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;
2274
            case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
2275
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2276
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2277
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2278
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2279
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2280
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2281
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_TEXTURE);
2282
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_TEXTURE");
2283
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2284
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2285
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2286
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2287
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2288
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2289
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
2290
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
2291
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2292
                checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2293
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2294 2295
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;
2296
            case WINED3D_TOP_BLEND_FACTOR_ALPHA:
2297
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2298
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2299
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2300
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2301
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2302
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2303
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_CONSTANT);
2304
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_CONSTANT");
2305
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2306
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2307
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2308
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2309
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2310
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2311
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_CONSTANT);
2312
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_CONSTANT");
2313
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2314
                checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2315
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2316 2317
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;
2318
            case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
2319
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2320
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2321
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2322
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2323
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2324
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2325
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2326
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2327
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2328
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2329
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2330
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2331
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2332
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2333
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_TEXTURE);
2334
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_TEXTURE");
2335
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA);
2336
                checkGLcall("GL_TEXTURE_ENV, opr3_target, GL_ONE_MINUS_SRC_ALPHA");
2337
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2338 2339
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;
2340
            case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
2341 2342 2343
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");                 /* Add = a0*a1 + a2*a3 */
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);  /*  a0 = src1/opr1     */
2344
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2345 2346 2347
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");                   /*  a1 = 1 (see docs)  */
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2348
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2349
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2350
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2351
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);  /*  a2 = arg2          */
2352
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2353 2354 2355
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");                   /*  a3 = src1 alpha    */
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2356 2357 2358 2359 2360
                checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
                switch (opr) {
                    case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                }
2361
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2362
                checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2363
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2364 2365
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;
2366
            case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
2367
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2368
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2369
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2370
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2371
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2372
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2373
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2374
                checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2375
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2376
                checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2377
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2378 2379 2380 2381 2382
                checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
                switch (opr1) {
                    case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                }
2383
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2384
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2385
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2386
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2387
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2388
                checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2389
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2390 2391
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;
2392
            case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
2393
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2394
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2395
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2396
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2397
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2398
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2399
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2400
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2401
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2402
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2403
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2404
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2405
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2406
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2407
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src1);
2408 2409 2410 2411 2412 2413 2414
                checkGLcall("GL_TEXTURE_ENV, src3_target, src1");
                switch (opr1) {
                    case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
                    case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
                }
2415
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr);
2416
                checkGLcall("GL_TEXTURE_ENV, opr3_target, opr");
2417
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2418 2419
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;
2420
            case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
2421
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2422
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2423
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2424 2425 2426 2427 2428 2429 2430
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
                switch (opr1) {
                    case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
                    case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
                }
2431
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2432
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2433
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2434
                checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2435
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2436
                checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2437
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2438 2439 2440 2441 2442
                checkGLcall("GL_TEXTURE_ENV, src2_target, src1");
                switch (opr1) {
                    case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                }
2443
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr);
2444
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr");
2445
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, GL_ZERO);
2446
                checkGLcall("GL_TEXTURE_ENV, src3_target, GL_ZERO");
2447
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, invopr);
2448
                checkGLcall("GL_TEXTURE_ENV, opr3_target, invopr");
2449
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2450 2451
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;
2452
            case WINED3D_TOP_MULTIPLY_ADD:
2453
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2454
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2455
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
2456
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2457
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
2458
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2459
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, GL_ZERO);
2460
                checkGLcall("GL_TEXTURE_ENV, src1_target, GL_ZERO");
2461
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, invopr);
2462
                checkGLcall("GL_TEXTURE_ENV, opr1_target, invopr");
2463
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src1);
2464
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2465
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr1);
2466
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2467
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src3_target, src2);
2468
                checkGLcall("GL_TEXTURE_ENV, src3_target, src3");
2469
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr3_target, opr2);
2470
                checkGLcall("GL_TEXTURE_ENV, opr3_target, opr3");
2471
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2472 2473 2474
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
                break;

2475 2476
            case WINED3D_TOP_BUMPENVMAP:
            case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
2477
                FIXME("Implement bump environment mapping in GL_NV_texture_env_combine4 path\n");
2478 2479
                Handled = FALSE;
                break;
2480 2481 2482 2483

            default:
                Handled = FALSE;
        }
2484 2485 2486
        if (Handled)
        {
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV);
2487 2488 2489 2490 2491 2492 2493 2494
            checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE4_NV");

            return;
        }
    } /* GL_NV_texture_env_combine4 */

    Handled = TRUE; /* Again, assume handled */
    switch (op) {
2495
        case WINED3D_TOP_DISABLE: /* Only for alpha */
2496
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2497
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2498
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT);
2499
            checkGLcall("GL_TEXTURE_ENV, src0_target, GL_PREVIOUS_EXT");
2500
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA);
2501
            checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_SRC_ALPHA");
2502
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2503 2504
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2505
        case WINED3D_TOP_SELECT_ARG1:
2506
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2507
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2508
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2509
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2510
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2511
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2512
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2513 2514
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2515
        case WINED3D_TOP_SELECT_ARG2:
2516
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_REPLACE);
2517
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_REPLACE");
2518
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src2);
2519
            checkGLcall("GL_TEXTURE_ENV, src0_target, src2");
2520
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr2);
2521
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr2");
2522
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2523 2524
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2525
        case WINED3D_TOP_MODULATE:
2526
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2527
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2528
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2529
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2530
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2531
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2532
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2533
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2534
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2535
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2536
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2537 2538
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2539
        case WINED3D_TOP_MODULATE_2X:
2540
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2541
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2542
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2543
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2544
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2545
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2546
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2547
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2548
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2549
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2550
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2551 2552
            checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
            break;
2553
        case WINED3D_TOP_MODULATE_4X:
2554
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE);
2555
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE");
2556
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2557
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2558
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2559
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2560
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2561
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2562
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2563
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2564
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 4);
2565 2566
            checkGLcall("GL_TEXTURE_ENV, scal_target, 4");
            break;
2567
        case WINED3D_TOP_ADD:
2568
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD);
2569
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD");
2570
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2571
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2572
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2573
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2574
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2575
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2576
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2577
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2578
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2579 2580
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2581
        case WINED3D_TOP_ADD_SIGNED:
2582
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2583
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2584
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2585
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2586
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2587
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2588
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2589
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2590
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2591
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2592
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2593 2594
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2595
        case WINED3D_TOP_ADD_SIGNED_2X:
2596
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED);
2597
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_ADD_SIGNED");
2598
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2599
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2600
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2601
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2602
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2603
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2604
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2605
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2606
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 2);
2607 2608
            checkGLcall("GL_TEXTURE_ENV, scal_target, 2");
            break;
2609
        case WINED3D_TOP_SUBTRACT:
2610
            if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE])
2611
            {
2612
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_SUBTRACT);
2613
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_SUBTRACT");
2614
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2615
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2616
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2617
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2618
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2619
                checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2620
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2621
                checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2622
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2623 2624 2625 2626 2627 2628
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            } else {
                FIXME("This version of opengl does not support GL_SUBTRACT\n");
            }
            break;

2629
        case WINED3D_TOP_BLEND_DIFFUSE_ALPHA:
2630
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2631
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2632
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2633
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2634
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2635
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2636
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2637
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2638
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2639
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2640
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR);
2641
            checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PRIMARY_COLOR");
2642
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2643
            checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2644
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2645 2646
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2647
        case WINED3D_TOP_BLEND_TEXTURE_ALPHA:
2648
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2649
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2650
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2651
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2652
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2653
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2654
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2655
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2656
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2657
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2658
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_TEXTURE);
2659
            checkGLcall("GL_TEXTURE_ENV, src2_target, GL_TEXTURE");
2660
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2661
            checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2662
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2663 2664
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2665
        case WINED3D_TOP_BLEND_FACTOR_ALPHA:
2666
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2667
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2668
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2669
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2670
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2671
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2672
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2673
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2674
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2675
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2676
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_CONSTANT);
2677
            checkGLcall("GL_TEXTURE_ENV, src2_target, GL_CONSTANT");
2678
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2679
            checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2680
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2681 2682
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2683
        case WINED3D_TOP_BLEND_CURRENT_ALPHA:
2684
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2685
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2686
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2687
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2688
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2689
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2690
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2691
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2692
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2693
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2694
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, GL_PREVIOUS);
2695
            checkGLcall("GL_TEXTURE_ENV, src2_target, GL_PREVIOUS");
2696
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA);
2697
            checkGLcall("GL_TEXTURE_ENV, opr2_target, GL_SRC_ALPHA");
2698
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2699 2700
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2701
        case WINED3D_TOP_DOTPRODUCT3:
2702
            if (gl_info->supported[ARB_TEXTURE_ENV_DOT3])
2703
            {
2704
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB);
2705
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_ARB");
2706
            }
2707
            else if (gl_info->supported[EXT_TEXTURE_ENV_DOT3])
2708
            {
2709
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT);
2710 2711 2712 2713
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA_EXT");
            } else {
                FIXME("This version of opengl does not support GL_DOT3\n");
            }
2714
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2715
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2716
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2717
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2718
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2719
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2720
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2721
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2722
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2723 2724
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2725
        case WINED3D_TOP_LERP:
2726
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE);
2727
            checkGLcall("GL_TEXTURE_ENV, comb_target, GL_INTERPOLATE");
2728
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2729
            checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2730
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2731
            checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2732
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src2);
2733
            checkGLcall("GL_TEXTURE_ENV, src1_target, src2");
2734
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr2);
2735
            checkGLcall("GL_TEXTURE_ENV, opr1_target, opr2");
2736
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src3);
2737
            checkGLcall("GL_TEXTURE_ENV, src2_target, src3");
2738
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr3);
2739
            checkGLcall("GL_TEXTURE_ENV, opr2_target, opr3");
2740
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2741 2742
            checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            break;
2743
        case WINED3D_TOP_ADD_SMOOTH:
2744
            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2745
            {
2746
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2747
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2748
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2749 2750 2751 2752 2753 2754 2755
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
                switch (opr1) {
                    case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
                    case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
                }
2756
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2757
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2758
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2759
                checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2760
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2761
                checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2762
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2763
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2764
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2765
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2766
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2767 2768 2769
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            } else
                Handled = FALSE;
2770
            break;
2771
        case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
2772
            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2773
            {
2774
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2775
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2776
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, GL_TEXTURE);
2777
                checkGLcall("GL_TEXTURE_ENV, src0_target, GL_TEXTURE");
2778
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_ALPHA);
2779
                checkGLcall("GL_TEXTURE_ENV, opr0_target, GL_ONE_MINUS_SRC_APHA");
2780
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2781
                checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2782
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2783
                checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2784
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2785
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2786
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2787
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2788
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2789 2790 2791
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            } else
                Handled = FALSE;
2792
            break;
2793
        case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
2794
            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2795
            {
2796
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2797
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2798
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2799 2800 2801 2802 2803 2804 2805
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
                switch (opr1) {
                    case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                    case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                }
2806
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2807
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2808
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2809
                checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2810
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2811
                checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2812
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2813
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2814
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2815
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2816
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2817 2818 2819
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            } else
                Handled = FALSE;
2820
            break;
2821
        case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
2822
            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2823
            {
2824
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2825
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2826
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2827
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2828
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2829
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2830
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2831 2832 2833 2834 2835 2836 2837
                checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
                switch (opr1) {
                    case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                    case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                }
2838
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
2839
                checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
2840
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2841
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2842
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2843
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2844
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2845 2846 2847
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            } else
                Handled = FALSE;
2848
            break;
2849
        case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
2850
            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2851
            {
2852
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2853
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2854
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2855 2856 2857 2858 2859 2860 2861
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
                switch (opr1) {
                    case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_ALPHA; break;
                    case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
                }
2862
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2863
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2864
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2865
                checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
2866
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
2867
                checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
2868
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2869
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2870
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2871
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2872
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2873 2874 2875
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            } else
                Handled = FALSE;
2876
            break;
2877
        case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
2878
            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2879
            {
2880
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2881
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2882
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2883 2884 2885 2886 2887 2888 2889
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
                switch (opr1) {
                    case GL_SRC_COLOR: opr = GL_ONE_MINUS_SRC_COLOR; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_SRC_COLOR; break;
                    case GL_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
                }
2890
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr);
2891
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr");
2892
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
2893 2894 2895 2896 2897 2898 2899
                checkGLcall("GL_TEXTURE_ENV, src1_target, src1");
                switch (opr1) {
                    case GL_SRC_COLOR: opr = GL_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_COLOR: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                    case GL_SRC_ALPHA: opr = GL_SRC_ALPHA; break;
                    case GL_ONE_MINUS_SRC_ALPHA: opr = GL_ONE_MINUS_SRC_ALPHA; break;
                }
2900
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr);
2901
                checkGLcall("GL_TEXTURE_ENV, opr1_target, opr");
2902
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2903
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2904
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2905
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2906
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2907 2908 2909
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            } else
                Handled = FALSE;
2910
            break;
2911
        case WINED3D_TOP_MULTIPLY_ADD:
2912
            if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3])
2913
            {
2914
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI);
2915
                checkGLcall("GL_TEXTURE_ENV, comb_target, GL_MODULATE_ADD_ATI");
2916
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src0_target, src1);
2917
                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
2918
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr1);
2919
                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr1");
2920
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src1_target, src3);
2921
                checkGLcall("GL_TEXTURE_ENV, src1_target, src3");
2922
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr3);
2923
                checkGLcall("GL_TEXTURE_ENV, opr1_target, opr3");
2924
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
2925
                checkGLcall("GL_TEXTURE_ENV, src2_target, src2");
2926
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
2927
                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
2928
                gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, scal_target, 1);
2929 2930 2931
                checkGLcall("GL_TEXTURE_ENV, scal_target, 1");
            } else
                Handled = FALSE;
2932
            break;
2933 2934
        case WINED3D_TOP_BUMPENVMAP_LUMINANCE:
        case WINED3D_TOP_BUMPENVMAP:
2935
            if (gl_info->supported[NV_TEXTURE_SHADER2])
2936
            {
2937 2938 2939 2940 2941
                /* Technically texture shader support without register combiners is possible, but not expected to occur
                 * on real world cards, so for now a fixme should be enough
                 */
                FIXME("Implement bump mapping with GL_NV_texture_shader in non register combiner path\n");
            }
2942 2943 2944
            Handled = FALSE;
            break;

2945 2946 2947 2948 2949 2950
        default:
            Handled = FALSE;
    }

    if (Handled) {
        BOOL  combineOK = TRUE;
2951
        if (gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
2952
        {
2953 2954
            DWORD op2;

2955
            if (isAlpha)
2956
                op2 = state->texture_states[Stage][WINED3D_TSS_COLOR_OP];
2957
            else
2958
                op2 = state->texture_states[Stage][WINED3D_TSS_ALPHA_OP];
2959 2960

            /* Note: If COMBINE4 in effect can't go back to combine! */
2961 2962 2963 2964 2965 2966 2967 2968 2969
            switch (op2)
            {
                case WINED3D_TOP_ADD_SMOOTH:
                case WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM:
                case WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR:
                case WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA:
                case WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR:
                case WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA:
                case WINED3D_TOP_MULTIPLY_ADD:
2970
                    /* Ignore those implemented in both cases */
2971 2972 2973 2974
                    switch (op)
                    {
                        case WINED3D_TOP_SELECT_ARG1:
                        case WINED3D_TOP_SELECT_ARG2:
2975 2976 2977 2978 2979 2980 2981 2982 2983 2984
                            combineOK = FALSE;
                            Handled   = FALSE;
                            break;
                        default:
                            FIXME("Can't use COMBINE4 and COMBINE together, thisop=%s, otherop=%s, isAlpha(%d)\n", debug_d3dtop(op), debug_d3dtop(op2), isAlpha);
                            return;
                    }
            }
        }

2985 2986
        if (combineOK)
        {
2987
            gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
2988
            checkGLcall("GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE");
2989 2990 2991 2992 2993 2994 2995 2996 2997 2998

            return;
        }
    }

    /* After all the extensions, if still unhandled, report fixme */
    FIXME("Unhandled texture operation %s\n", debug_d3dtop(op));
}


2999
static void tex_colorop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3000
{
3001
    DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3002
    BOOL tex_used = context->fixed_function_usage_map & (1u << stage);
3003
    DWORD mapped_stage = context->tex_unit_map[stage];
3004
    const struct wined3d_gl_info *gl_info = context->gl_info;
3005 3006 3007

    TRACE("Setting color op for stage %d\n", stage);

3008
    /* Using a pixel shader? Don't care for anything here, the shader applying does it */
3009
    if (use_ps(state)) return;
3010

3011 3012
    if (stage != mapped_stage) WARN("Using non 1:1 mapping: %d -> %d!\n", stage, mapped_stage);

3013 3014
    if (mapped_stage != WINED3D_UNMAPPED_STAGE)
    {
3015
        if (tex_used && mapped_stage >= gl_info->limits.textures)
3016
        {
3017
            FIXME("Attempt to enable unsupported stage!\n");
3018 3019
            return;
        }
3020
        context_active_texture(context, gl_info, mapped_stage);
3021 3022
    }

3023
    if (stage >= context->lowest_disabled_stage)
3024
    {
3025
        TRACE("Stage disabled\n");
3026 3027
        if (mapped_stage != WINED3D_UNMAPPED_STAGE)
        {
3028
            /* Disable everything here */
3029
            gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
3030
            checkGLcall("glDisable(GL_TEXTURE_2D)");
3031
            gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
3032
            checkGLcall("glDisable(GL_TEXTURE_3D)");
3033
            if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3034
            {
3035
                gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
3036 3037
                checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
            }
3038
            if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
3039
            {
3040
                gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
3041 3042
                checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
            }
3043
        }
3044 3045 3046 3047
        /* All done */
        return;
    }

3048 3049 3050
    /* The sampler will also activate the correct texture dimensions, so no
     * need to do it here if the sampler for this stage is dirty. */
    if (!isStateDirty(context, STATE_SAMPLER(stage)) && tex_used)
3051
        texture_activate_dimensions(state->textures[stage], gl_info);
3052

3053
    set_tex_op(gl_info, state, FALSE, stage,
3054 3055 3056 3057
            state->texture_states[stage][WINED3D_TSS_COLOR_OP],
            state->texture_states[stage][WINED3D_TSS_COLOR_ARG1],
            state->texture_states[stage][WINED3D_TSS_COLOR_ARG2],
            state->texture_states[stage][WINED3D_TSS_COLOR_ARG0]);
3058 3059
}

3060
void tex_alphaop(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3061
{
3062
    DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3063
    BOOL tex_used = context->fixed_function_usage_map & (1u << stage);
3064
    DWORD mapped_stage = context->tex_unit_map[stage];
3065
    const struct wined3d_gl_info *gl_info = context->gl_info;
3066
    DWORD op, arg1, arg2, arg0;
3067 3068

    TRACE("Setting alpha op for stage %d\n", stage);
3069
    /* Do not care for enabled / disabled stages, just assign the settings. colorop disables / enables required stuff */
3070 3071
    if (mapped_stage != WINED3D_UNMAPPED_STAGE)
    {
3072
        if (tex_used && mapped_stage >= gl_info->limits.textures)
3073
        {
3074
            FIXME("Attempt to enable unsupported stage!\n");
3075 3076
            return;
        }
3077
        context_active_texture(context, gl_info, mapped_stage);
3078 3079
    }

3080 3081 3082 3083
    op = state->texture_states[stage][WINED3D_TSS_ALPHA_OP];
    arg1 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG1];
    arg2 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG2];
    arg0 = state->texture_states[stage][WINED3D_TSS_ALPHA_ARG0];
3084

3085
    if (state->render_states[WINED3D_RS_COLORKEYENABLE] && !stage && state->textures[0])
3086
    {
3087
        struct wined3d_texture *texture = state->textures[0];
3088
        GLenum texture_dimensions = texture->target;
3089 3090 3091

        if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
        {
3092
            if (texture->async.color_key_flags & WINED3D_CKEY_SRC_BLT && !texture->resource.format->alpha_size)
3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115
            {
                /* Color keying needs to pass alpha values from the texture through to have the alpha test work
                 * properly. On the other hand applications can still use texture combiners apparently. This code
                 * takes care that apps cannot remove the texture's alpha channel entirely.
                 *
                 * The fixup is required for Prince of Persia 3D(prison bars), while Moto racer 2 requires
                 * D3DTOP_MODULATE to work on color keyed surfaces. Aliens vs Predator 1 uses color keyed textures
                 * and alpha component of diffuse color to draw things like translucent text and perform other
                 * blending effects.
                 *
                 * Aliens vs Predator 1 relies on diffuse alpha having an effect, so it cannot be ignored. To
                 * provide the behavior expected by the game, while emulating the colorkey, diffuse alpha must be
                 * modulated with texture alpha. OTOH, Moto racer 2 at some points sets alphaop/alphaarg to
                 * SELECTARG/CURRENT, yet puts garbage in diffuse alpha (zeroes). This works on native, because the
                 * game disables alpha test and alpha blending. Alpha test is overwritten by wine's for purposes of
                 * color-keying though, so this will lead to missing geometry if texture alpha is modulated (pixels
                 * fail alpha test). To get around this, ALPHABLENDENABLE state is checked: if the app enables alpha
                 * blending, it can be expected to provide meaningful values in diffuse alpha, so it should be
                 * modulated with texture alpha; otherwise, selecting diffuse alpha is ignored in favour of texture
                 * alpha.
                 *
                 * What to do with multitexturing? So far no app has been found that uses color keying with
                 * multitexturing */
3116
                if (op == WINED3D_TOP_DISABLE)
3117
                {
3118
                    arg1 = WINED3DTA_TEXTURE;
3119
                    op = WINED3D_TOP_SELECT_ARG1;
3120
                }
3121
                else if (op == WINED3D_TOP_SELECT_ARG1 && arg1 != WINED3DTA_TEXTURE)
3122
                {
3123
                    if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
3124 3125
                    {
                        arg2 = WINED3DTA_TEXTURE;
3126
                        op = WINED3D_TOP_MODULATE;
3127 3128 3129
                    }
                    else arg1 = WINED3DTA_TEXTURE;
                }
3130
                else if (op == WINED3D_TOP_SELECT_ARG2 && arg2 != WINED3DTA_TEXTURE)
3131
                {
3132
                    if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
3133 3134
                    {
                        arg1 = WINED3DTA_TEXTURE;
3135
                        op = WINED3D_TOP_MODULATE;
3136 3137
                    }
                    else arg2 = WINED3DTA_TEXTURE;
3138 3139
                }
            }
3140 3141 3142
        }
    }

3143 3144 3145
    /* tex_alphaop is shared between the ffp and nvrc because the difference only comes down to
     * this if block here, and the other code(color keying, texture unit selection) are the same
     */
3146
    TRACE("Setting alpha op for stage %d\n", stage);
3147
    if (gl_info->supported[NV_REGISTER_COMBINERS])
3148
    {
3149
        set_tex_op_nvrc(gl_info, state, TRUE, stage, op, arg1, arg2, arg0,
3150
                mapped_stage, state->texture_states[stage][WINED3D_TSS_RESULT_ARG]);
3151 3152 3153
    }
    else
    {
3154
        set_tex_op(gl_info, state, TRUE, stage, op, arg1, arg2, arg0);
3155 3156 3157
    }
}

3158
static void transform_texture(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3159
{
3160
    const struct wined3d_gl_info *gl_info = context->gl_info;
3161 3162 3163
    unsigned int tex = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
    unsigned int mapped_stage = context->tex_unit_map[tex];
    struct wined3d_matrix mat;
3164

3165
    /* Ignore this when a vertex shader is used, or if the streams aren't sorted out yet */
3166
    if (use_vs(state) || isStateDirty(context, STATE_VDECL))
3167
    {
3168 3169 3170 3171
        TRACE("Using a vertex shader, or stream sources not sorted out yet, skipping\n");
        return;
    }

3172
    if (mapped_stage == WINED3D_UNMAPPED_STAGE) return;
3173
    if (mapped_stage >= gl_info->limits.textures) return;
3174

3175
    context_active_texture(context, gl_info, mapped_stage);
3176 3177 3178 3179 3180 3181 3182
    gl_info->gl_ops.gl.p_glMatrixMode(GL_TEXTURE);
    checkGLcall("glMatrixMode(GL_TEXTURE)");

    get_texture_matrix(context, state, mapped_stage, &mat);

    gl_info->gl_ops.gl.p_glLoadMatrixf(&mat._11);
    checkGLcall("glLoadMatrixf");
3183 3184
}

3185
static void unload_tex_coords(const struct wined3d_gl_info *gl_info)
3186
{
3187
    unsigned int texture_idx;
3188

3189
    for (texture_idx = 0; texture_idx < gl_info->limits.texture_coords; ++texture_idx)
3190
    {
3191
        GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + texture_idx));
3192
        gl_info->gl_ops.gl.p_glDisableClientState(GL_TEXTURE_COORD_ARRAY);
3193 3194 3195
    }
}

3196 3197
static void load_tex_coords(const struct wined3d_context *context, const struct wined3d_stream_info *si,
        GLuint *curVBO, const struct wined3d_state *state)
3198
{
3199
    const struct wined3d_gl_info *gl_info = context->gl_info;
3200
    unsigned int mapped_stage = 0;
3201
    unsigned int textureNo;
3202

3203
    for (textureNo = 0; textureNo < context->d3d_info->limits.ffp_blend_stages; ++textureNo)
3204
    {
3205
        int coordIdx = state->texture_states[textureNo][WINED3D_TSS_TEXCOORD_INDEX];
3206

3207
        mapped_stage = context->tex_unit_map[textureNo];
3208
        if (mapped_stage == WINED3D_UNMAPPED_STAGE) continue;
3209

3210 3211 3212 3213 3214 3215
        if (mapped_stage >= gl_info->limits.texture_coords)
        {
            FIXME("Attempted to load unsupported texture coordinate %u\n", mapped_stage);
            continue;
        }

3216
        if (coordIdx < MAX_TEXTURES && (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coordIdx))))
3217
        {
3218 3219
            const struct wined3d_stream_info_element *e = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];

3220 3221
            TRACE("Setting up texture %u, idx %d, coordindx %u, data {%#x:%p}.\n",
                    textureNo, mapped_stage, coordIdx, e->data.buffer_object, e->data.addr);
3222

3223
            if (*curVBO != e->data.buffer_object)
3224
            {
3225 3226
                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
                checkGLcall("glBindBuffer");
3227
                *curVBO = e->data.buffer_object;
3228
            }
3229 3230 3231 3232

            GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
            checkGLcall("glClientActiveTextureARB");

3233
            /* The coords to supply depend completely on the fvf / vertex shader */
3234
            gl_info->gl_ops.gl.p_glTexCoordPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
3235
                    e->data.addr + state->load_base_vertex_index * e->stride);
3236
            gl_info->gl_ops.gl.p_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
3237 3238 3239
        }
        else
        {
3240
            GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + mapped_stage, 0, 0, 0, 1));
3241 3242
        }
    }
3243
    if (gl_info->supported[NV_REGISTER_COMBINERS])
3244 3245
    {
        /* The number of the mapped stages increases monotonically, so it's fine to use the last used one. */
3246
        for (textureNo = mapped_stage + 1; textureNo < gl_info->limits.textures; ++textureNo)
3247
        {
3248 3249 3250
            GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + textureNo, 0, 0, 0, 1));
        }
    }
3251 3252

    checkGLcall("loadTexCoords");
3253
}
3254

3255
static void tex_coordindex(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3256
{
3257
    DWORD stage = (state_id - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
3258 3259 3260 3261
    static const GLfloat s_plane[] = { 1.0f, 0.0f, 0.0f, 0.0f };
    static const GLfloat t_plane[] = { 0.0f, 1.0f, 0.0f, 0.0f };
    static const GLfloat r_plane[] = { 0.0f, 0.0f, 1.0f, 0.0f };
    static const GLfloat q_plane[] = { 0.0f, 0.0f, 0.0f, 1.0f };
3262
    const struct wined3d_gl_info *gl_info = context->gl_info;
3263
    DWORD mapped_stage = context->tex_unit_map[stage];
3264

3265 3266
    if (mapped_stage == WINED3D_UNMAPPED_STAGE)
    {
3267 3268 3269
        TRACE("No texture unit mapped to stage %d. Skipping texture coordinates.\n", stage);
        return;
    }
3270

3271
    if (mapped_stage >= gl_info->limits.fragment_samplers)
3272
    {
3273
        WARN("stage %u not mapped to a valid texture unit (%u)\n", stage, mapped_stage);
3274 3275
        return;
    }
3276
    context_active_texture(context, gl_info, mapped_stage);
3277 3278 3279

    /* Values 0-7 are indexes into the FVF tex coords - See comments in DrawPrimitive
     *
3280
     * FIXME: When using generated texture coordinates, the index value is used to specify the wrapping mode.
3281
     * eg. SetTextureStageState( 0, WINED3D_TSS_TEXCOORDINDEX, WINED3D_TSS_TCI_CAMERASPACEPOSITION | 1 );
3282
     * means use the vertex position (camera-space) as the input texture coordinates
3283
     * for this texture stage, and the wrap mode set in the WINED3D_RS_WRAP1 render
3284 3285 3286
     * state. We do not (yet) support the WINED3DRENDERSTATE_WRAPx values, nor tie them up
     * to the TEXCOORDINDEX value
     */
3287
    switch (state->texture_states[stage][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000)
3288 3289 3290 3291
    {
        case WINED3DTSS_TCI_PASSTHRU:
            /* Use the specified texture coordinates contained within the
             * vertex format. This value resolves to zero. */
3292 3293 3294 3295
            gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_S);
            gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_T);
            gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
            gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_Q);
3296
            checkGLcall("WINED3DTSS_TCI_PASSTHRU - Disable texgen.");
3297
            break;
3298

3299 3300 3301 3302
        case WINED3DTSS_TCI_CAMERASPACEPOSITION:
            /* CameraSpacePosition means use the vertex position, transformed to camera space,
             * as the input texture coordinates for this stage's texture transformation. This
             * equates roughly to EYE_LINEAR */
3303

3304 3305 3306 3307 3308 3309 3310 3311
            gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
            gl_info->gl_ops.gl.p_glPushMatrix();
            gl_info->gl_ops.gl.p_glLoadIdentity();
            gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
            gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
            gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
            gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
            gl_info->gl_ops.gl.p_glPopMatrix();
3312
            checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set eye plane.");
3313

3314 3315 3316
            gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
            gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
            gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
3317 3318
            checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Set texgen mode.");

3319 3320 3321
            gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
            gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
            gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3322 3323
            checkGLcall("WINED3DTSS_TCI_CAMERASPACEPOSITION - Enable texgen.");

3324
            break;
3325

3326
        case WINED3DTSS_TCI_CAMERASPACENORMAL:
3327 3328
            /* Note that NV_TEXGEN_REFLECTION support is implied when
             * ARB_TEXTURE_CUBE_MAP is supported */
3329
            if (!gl_info->supported[NV_TEXGEN_REFLECTION])
3330
            {
3331
                FIXME("WINED3DTSS_TCI_CAMERASPACENORMAL not supported.\n");
3332 3333 3334
                break;
            }

3335 3336 3337 3338 3339 3340 3341 3342
            gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
            gl_info->gl_ops.gl.p_glPushMatrix();
            gl_info->gl_ops.gl.p_glLoadIdentity();
            gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
            gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
            gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
            gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
            gl_info->gl_ops.gl.p_glPopMatrix();
3343
            checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Set eye plane.");
3344

3345 3346 3347
            gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
            gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
            gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_NV);
3348 3349
            checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Set texgen mode.");

3350 3351 3352
            gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
            gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
            gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3353
            checkGLcall("WINED3DTSS_TCI_CAMERASPACENORMAL - Enable texgen.");
3354 3355 3356 3357

            break;

        case WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR:
3358 3359
            /* Note that NV_TEXGEN_REFLECTION support is implied when
             * ARB_TEXTURE_CUBE_MAP is supported */
3360
            if (!gl_info->supported[NV_TEXGEN_REFLECTION])
3361
            {
3362
                FIXME("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR not supported.\n");
3363
                break;
3364 3365
            }

3366 3367 3368 3369 3370 3371 3372 3373
            gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
            gl_info->gl_ops.gl.p_glPushMatrix();
            gl_info->gl_ops.gl.p_glLoadIdentity();
            gl_info->gl_ops.gl.p_glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
            gl_info->gl_ops.gl.p_glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
            gl_info->gl_ops.gl.p_glTexGenfv(GL_R, GL_EYE_PLANE, r_plane);
            gl_info->gl_ops.gl.p_glTexGenfv(GL_Q, GL_EYE_PLANE, q_plane);
            gl_info->gl_ops.gl.p_glPopMatrix();
3374
            checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Set eye plane.");
3375

3376 3377 3378
            gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
            gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
            gl_info->gl_ops.gl.p_glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_NV);
3379 3380
            checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Set texgen mode.");

3381 3382 3383
            gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
            gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
            gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_R);
3384
            checkGLcall("WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR - Enable texgen.");
3385 3386 3387

            break;

3388
        case WINED3DTSS_TCI_SPHEREMAP:
3389 3390
            gl_info->gl_ops.gl.p_glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
            gl_info->gl_ops.gl.p_glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
3391 3392
            checkGLcall("WINED3DTSS_TCI_SPHEREMAP - Set texgen mode.");

3393 3394 3395
            gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_S);
            gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_GEN_T);
            gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
3396 3397 3398 3399
            checkGLcall("WINED3DTSS_TCI_SPHEREMAP - Enable texgen.");

            break;

3400
        default:
3401 3402
            FIXME("Unhandled WINED3D_TSS_TEXCOORD_INDEX %#x.\n",
                    state->texture_states[stage][WINED3D_TSS_TEXCOORD_INDEX]);
3403 3404 3405 3406
            gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_S);
            gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_T);
            gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_R);
            gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_GEN_Q);
3407 3408
            checkGLcall("Disable texgen.");

3409
            break;
3410
    }
3411

3412
    /* Update the texture matrix. */
3413
    if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + stage)))
3414
        transform_texture(context, state, STATE_TEXTURESTAGE(stage, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
3415

3416 3417
    if (!isStateDirty(context, STATE_VDECL) && context->namedArraysLoaded)
    {
3418
        /* Reload the arrays if we are using fixed function arrays to reflect the selected coord input
3419
         * source. Call loadTexCoords directly because there is no need to reparse the vertex declaration
3420 3421 3422
         * and do all the things linked to it
         * TODO: Tidy that up to reload only the arrays of the changed unit
         */
3423
        GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
3424

3425
        unload_tex_coords(gl_info);
3426
        load_tex_coords(context, &context->stream_info, &curVBO, state);
3427
    }
3428 3429
}

3430
static void sampler_texmatrix(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3431
{
3432 3433
    const DWORD sampler = state_id - STATE_SAMPLER(0);
    const struct wined3d_texture *texture = state->textures[sampler];
3434

3435
    TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
3436

3437
    if(!texture) return;
3438
    /* The fixed function np2 texture emulation uses the texture matrix to fix up the coordinates
3439
     * wined3d_texture_apply_state_changes() multiplies the set matrix with a fixup matrix. Before the
3440 3441
     * scaling is reapplied or removed, the texture matrix has to be reapplied
     *
Tobias Jakobi's avatar
Tobias Jakobi committed
3442
     * The mapped stage is already active because the sampler() function below, which is part of the
3443 3444
     * misc pipeline
     */
3445 3446
    if (sampler < MAX_TEXTURES)
    {
3447
        const BOOL texIsPow2 = !(texture->flags & WINED3D_TEXTURE_POW2_MAT_IDENT);
3448

3449
        if (texIsPow2 || (context->lastWasPow2Texture & (1u << sampler)))
3450
        {
3451
            if (texIsPow2)
3452
                context->lastWasPow2Texture |= 1u << sampler;
3453
            else
3454
                context->lastWasPow2Texture &= ~(1u << sampler);
3455 3456

            transform_texture(context, state,
3457
                    STATE_TEXTURESTAGE(context->tex_unit_map[sampler], WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
3458 3459 3460 3461
        }
    }
}

3462 3463
static enum wined3d_texture_address wined3d_texture_address_mode(const struct wined3d_texture *texture,
        enum wined3d_texture_address t)
3464
{
3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483
    if (t < WINED3D_TADDRESS_WRAP || t > WINED3D_TADDRESS_MIRROR_ONCE)
    {
        FIXME("Unrecognized or unsupported texture address mode %#x.\n", t);
        return WINED3D_TADDRESS_WRAP;
    }

    /* Cubemaps are always set to clamp, regardless of the sampler state. */
    if (texture->target == GL_TEXTURE_CUBE_MAP_ARB || ((texture->flags & WINED3D_TEXTURE_COND_NP2)
            && t == WINED3D_TADDRESS_WRAP))
        return WINED3D_TADDRESS_CLAMP;

    return t;
}

static void wined3d_sampler_desc_from_sampler_states(struct wined3d_sampler_desc *desc,
        const struct wined3d_gl_info *gl_info, const DWORD *sampler_states, const struct wined3d_texture *texture)
{
    union
    {
3484 3485
        float f;
        DWORD d;
3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513
    } lod_bias;

    desc->address_u = wined3d_texture_address_mode(texture, sampler_states[WINED3D_SAMP_ADDRESS_U]);
    desc->address_v = wined3d_texture_address_mode(texture, sampler_states[WINED3D_SAMP_ADDRESS_V]);
    desc->address_w = wined3d_texture_address_mode(texture, sampler_states[WINED3D_SAMP_ADDRESS_W]);
    D3DCOLORTOGLFLOAT4(sampler_states[WINED3D_SAMP_BORDER_COLOR], desc->border_color);
    if (sampler_states[WINED3D_SAMP_MAG_FILTER] > WINED3D_TEXF_ANISOTROPIC)
        FIXME("Unrecognized or unsupported WINED3D_SAMP_MAG_FILTER %#x.\n",
                sampler_states[WINED3D_SAMP_MAG_FILTER]);
    desc->mag_filter = min(max(sampler_states[WINED3D_SAMP_MAG_FILTER], WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR);
    if (sampler_states[WINED3D_SAMP_MIN_FILTER] > WINED3D_TEXF_ANISOTROPIC)
        FIXME("Unrecognized or unsupported WINED3D_SAMP_MIN_FILTER %#x.\n",
                sampler_states[WINED3D_SAMP_MIN_FILTER]);
    desc->min_filter = min(max(sampler_states[WINED3D_SAMP_MIN_FILTER], WINED3D_TEXF_POINT), WINED3D_TEXF_LINEAR);
    if (sampler_states[WINED3D_SAMP_MIP_FILTER] > WINED3D_TEXF_ANISOTROPIC)
        FIXME("Unrecognized or unsupported WINED3D_SAMP_MIP_FILTER %#x.\n",
                sampler_states[WINED3D_SAMP_MIP_FILTER]);
    desc->mip_filter = min(max(sampler_states[WINED3D_SAMP_MIP_FILTER], WINED3D_TEXF_NONE), WINED3D_TEXF_LINEAR);
    lod_bias.d = sampler_states[WINED3D_SAMP_MIPMAP_LOD_BIAS];
    desc->lod_bias = lod_bias.f;
    desc->min_lod = -1000.0f;
    desc->max_lod = 1000.0f;
    desc->max_anisotropy = sampler_states[WINED3D_SAMP_MAX_ANISOTROPY];
    if ((sampler_states[WINED3D_SAMP_MAG_FILTER] != WINED3D_TEXF_ANISOTROPIC
                && sampler_states[WINED3D_SAMP_MIN_FILTER] != WINED3D_TEXF_ANISOTROPIC
                && sampler_states[WINED3D_SAMP_MIP_FILTER] != WINED3D_TEXF_ANISOTROPIC)
            || (texture->flags & WINED3D_TEXTURE_COND_NP2))
        desc->max_anisotropy = 1;
3514
    desc->compare = texture->resource.format_flags & WINED3DFMT_FLAG_SHADOW;
3515 3516 3517
    desc->comparison_func = WINED3D_CMP_LESSEQUAL;
    desc->srgb_decode = sampler_states[WINED3D_SAMP_SRGB_TEXTURE];

3518
    if (!(texture->resource.format_flags & WINED3DFMT_FLAG_FILTERING))
3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542
    {
        desc->mag_filter = WINED3D_TEXF_POINT;
        desc->min_filter = WINED3D_TEXF_POINT;
        desc->mip_filter = WINED3D_TEXF_NONE;
    }

    if (texture->flags & WINED3D_TEXTURE_COND_NP2)
    {
        desc->mip_filter = WINED3D_TEXF_NONE;
        if (gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT])
            desc->min_filter = WINED3D_TEXF_POINT;
    }
}

/* Enabling and disabling texture dimensions is done by texture stage state /
 * pixel shader setup, this function only has to bind textures and set the per
 * texture states. */
static void sampler(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
    DWORD sampler_idx = state_id - STATE_SAMPLER(0);
    DWORD mapped_stage = context->tex_unit_map[sampler_idx];
    const struct wined3d_gl_info *gl_info = context->gl_info;

    TRACE("Sampler %u.\n", sampler_idx);
3543

3544

3545 3546
    if (mapped_stage == WINED3D_UNMAPPED_STAGE)
    {
3547
        TRACE("No sampler mapped to stage %u. Returning.\n", sampler_idx);
3548 3549 3550
        return;
    }

3551
    if (mapped_stage >= gl_info->limits.combined_samplers)
3552
    {
3553 3554
        return;
    }
3555
    context_active_texture(context, gl_info, mapped_stage);
3556

3557
    if (state->textures[sampler_idx])
3558
    {
3559 3560 3561 3562 3563 3564
        struct wined3d_texture *texture = state->textures[sampler_idx];
        BOOL srgb = state->sampler_states[sampler_idx][WINED3D_SAMP_SRGB_TEXTURE];
        const DWORD *sampler_states = state->sampler_states[sampler_idx];
        struct wined3d_sampler_desc desc;
        struct gl_texture *gl_tex;
        unsigned int base_level;
3565

3566
        wined3d_sampler_desc_from_sampler_states(&desc, gl_info, sampler_states, texture);
3567

3568
        wined3d_texture_bind(texture, context, srgb);
3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598
        if (!gl_info->supported[ARB_SAMPLER_OBJECTS])
        {
            wined3d_texture_apply_sampler_desc(texture, &desc, gl_info);
        }
        else
        {
            struct wined3d_device *device = context->swapchain->device;
            struct wined3d_sampler *sampler;
            struct wine_rb_entry *entry;

            if ((entry = wine_rb_get(&device->samplers, &desc)))
            {
                sampler = WINE_RB_ENTRY_VALUE(entry, struct wined3d_sampler, entry);
            }
            else
            {
                if (FAILED(wined3d_sampler_create(device, &desc, NULL, &sampler)))
                {
                    ERR("Failed to create sampler.\n");
                    sampler = NULL;
                }
                else
                {
                    if (wine_rb_put(&device->samplers, &desc, &sampler->entry) == -1)
                        ERR("Failed to insert sampler.\n");
                }
            }

            if (sampler)
            {
3599
                GL_EXTCALL(glBindSampler(mapped_stage, sampler->name));
3600 3601 3602
                checkGLcall("glBindSampler");
            }
        }
3603 3604 3605 3606 3607 3608 3609 3610

        if (texture->flags & WINED3D_TEXTURE_COND_NP2)
            base_level = 0;
        else if (desc.mip_filter == WINED3D_TEXF_NONE)
            base_level = texture->lod;
        else
            base_level = min(max(sampler_states[WINED3D_SAMP_MAX_MIP_LEVEL],
                    texture->lod), texture->level_count - 1);
3611

3612 3613
        gl_tex = wined3d_texture_get_gl_texture(texture, texture->flags & WINED3D_TEXTURE_IS_SRGB);
        if (base_level != gl_tex->base_level)
3614
        {
3615 3616 3617 3618 3619 3620
            /* Note that WINED3D_SAMP_MAX_MIP_LEVEL specifies the largest mipmap
             * (default 0), while GL_TEXTURE_MAX_LEVEL specifies the smallest
             * mimap used (default 1000). So WINED3D_SAMP_MAX_MIP_LEVEL
             * corresponds to GL_TEXTURE_BASE_LEVEL. */
            gl_info->gl_ops.gl.p_glTexParameteri(texture->target, GL_TEXTURE_BASE_LEVEL, base_level);
            gl_tex->base_level = base_level;
3621 3622
        }

3623
        /* Trigger shader constant reloading (for NP2 texcoord fixup) */
3624
        if (!(texture->flags & WINED3D_TEXTURE_POW2_MAT_IDENT))
3625
            context->constant_update_mask |= WINED3D_SHADER_CONST_PS_NP2_FIXUP;
3626
    }
3627
    else
3628
    {
3629
        context_bind_texture(context, GL_NONE, 0);
3630 3631 3632
    }
}

3633
void apply_pixelshader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3634
{
3635
    unsigned int i;
3636

3637
    if (use_ps(state))
3638 3639 3640 3641
    {
        if (!context->last_was_pshader)
        {
            /* Former draw without a pixel shader, some samplers may be
3642
             * disabled because of WINED3D_TSS_COLOR_OP = WINED3DTOP_DISABLE
3643 3644 3645 3646 3647
             * make sure to enable them. */
            for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i)
            {
                if (!isStateDirty(context, STATE_SAMPLER(i)))
                    sampler(context, state, STATE_SAMPLER(i));
3648
            }
3649
            context->last_was_pshader = TRUE;
3650
        }
3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661
        else
        {
            /* Otherwise all samplers were activated by the code above in
             * earlier draws, or by sampler() if a different texture was
             * bound. I don't have to do anything. */
        }
    }
    else
    {
        /* Disabled the pixel shader - color ops weren't applied while it was
         * enabled, so re-apply them. */
3662
        for (i = 0; i < context->d3d_info->limits.ffp_blend_stages; ++i)
3663
        {
3664 3665
            if (!isStateDirty(context, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP)))
                context_apply_state(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_COLOR_OP));
3666
        }
3667
        context->last_was_pshader = FALSE;
3668
    }
3669

3670
    context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
3671 3672
}

3673
static void state_geometry_shader(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3674
{
3675
    context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_GEOMETRY;
3676 3677
}

3678
static void shader_bumpenv(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3679
{
3680
    context->constant_update_mask |= WINED3D_SHADER_CONST_PS_BUMP_ENV;
3681
}
3682

3683
static void transform_world(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3684
{
3685
    const struct wined3d_gl_info *gl_info = context->gl_info;
3686
    struct wined3d_matrix mat;
3687

3688 3689 3690 3691
    /* This function is called by transform_view below if the view matrix was changed too
     *
     * Deliberately no check if the vertex declaration is dirty because the vdecl state
     * does not always update the world matrix, only on a switch between transformed
3692
     * and untransformed draws. It *may* happen that the world matrix is set 2 times during one
3693
     * draw, but that should be rather rare and cheaper in total.
3694
     */
3695
    gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3696 3697
    checkGLcall("glMatrixMode");

3698
    get_modelview_matrix(context, state, 0, &mat);
3699 3700 3701

    gl_info->gl_ops.gl.p_glLoadMatrixf((GLfloat *)&mat);
    checkGLcall("glLoadMatrixf");
3702 3703
}

3704
void clipplane(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3705
{
3706
    const struct wined3d_gl_info *gl_info = context->gl_info;
3707
    UINT index = state_id - STATE_CLIPPLANE(0);
3708
    GLdouble plane[4];
3709

3710
    if (isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)) || index >= gl_info->limits.clipplanes)
3711 3712
        return;

3713 3714
    gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
    gl_info->gl_ops.gl.p_glPushMatrix();
3715

3716
    /* Clip Plane settings are affected by the model view in OpenGL, the View transform in direct3d */
3717
    if (!use_vs(state))
3718
        gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW]._11);
3719
    else
3720 3721 3722
        /* With vertex shaders, clip planes are not transformed in Direct3D,
         * while in OpenGL they are still transformed by the model view matix. */
        gl_info->gl_ops.gl.p_glLoadIdentity();
3723

3724 3725 3726 3727 3728
    plane[0] = state->clip_planes[index].x;
    plane[1] = state->clip_planes[index].y;
    plane[2] = state->clip_planes[index].z;
    plane[3] = state->clip_planes[index].w;

3729
    TRACE("Clipplane [%.8e, %.8e, %.8e, %.8e]\n",
3730
            plane[0], plane[1], plane[2], plane[3]);
3731
    gl_info->gl_ops.gl.p_glClipPlane(GL_CLIP_PLANE0 + index, plane);
3732 3733
    checkGLcall("glClipPlane");

3734
    gl_info->gl_ops.gl.p_glPopMatrix();
3735 3736
}

3737
static void transform_worldex(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3738
{
3739
    UINT matrix = state_id - STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0));
3740
    const struct wined3d_gl_info *gl_info = context->gl_info;
3741
    GLenum glMat;
3742

3743 3744
    TRACE("Setting world matrix %d\n", matrix);

3745
    if (matrix >= gl_info->limits.blends)
3746
    {
3747 3748 3749 3750
        WARN("Unsupported blend matrix set\n");
        return;
    }

3751 3752 3753
    if (isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)))
        return;

3754
    /* GL_MODELVIEW0_ARB:  0x1700
Tobias Jakobi's avatar
Tobias Jakobi committed
3755
     * GL_MODELVIEW1_ARB:  0x850a
3756 3757 3758
     * GL_MODELVIEW2_ARB:  0x8722
     * GL_MODELVIEW3_ARB:  0x8723
     * etc
3759
     * GL_MODELVIEW31_ARB: 0x873f
3760 3761 3762 3763
     */
    if(matrix == 1) glMat = GL_MODELVIEW1_ARB;
    else glMat = GL_MODELVIEW2_ARB - 2 + matrix;

3764
    gl_info->gl_ops.gl.p_glMatrixMode(glMat);
3765 3766
    checkGLcall("glMatrixMode(glMat)");

3767 3768 3769
    /* World matrix 0 is multiplied with the view matrix because d3d uses 3
     * matrices while gl uses only 2. To avoid weighting the view matrix
     * incorrectly it has to be multiplied into every GL modelview matrix. */
3770
    gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW]._11);
3771
    checkGLcall("glLoadMatrixf");
3772
    gl_info->gl_ops.gl.p_glMultMatrixf(&state->transforms[WINED3D_TS_WORLD_MATRIX(matrix)]._11);
3773
    checkGLcall("glMultMatrixf");
3774 3775
}

3776
static void state_vertexblend_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3777
{
3778
    enum wined3d_vertex_blend_flags f = state->render_states[WINED3D_RS_VERTEXBLEND];
3779
    static unsigned int once;
3780

3781 3782
    if (f == WINED3D_VBF_DISABLE)
        return;
3783

3784 3785
    if (!once++) FIXME("Vertex blend flags %#x not supported.\n", f);
    else WARN("Vertex blend flags %#x not supported.\n", f);
3786 3787
}

3788
static void state_vertexblend(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3789
{
3790
    enum wined3d_vertex_blend_flags val = state->render_states[WINED3D_RS_VERTEXBLEND];
3791
    struct wined3d_device *device = context->swapchain->device;
3792
    const struct wined3d_gl_info *gl_info = context->gl_info;
3793
    static unsigned int once;
3794

3795 3796 3797 3798 3799
    switch (val)
    {
        case WINED3D_VBF_1WEIGHTS:
        case WINED3D_VBF_2WEIGHTS:
        case WINED3D_VBF_3WEIGHTS:
3800
            gl_info->gl_ops.gl.p_glEnable(GL_VERTEX_BLEND_ARB);
3801
            checkGLcall("glEnable(GL_VERTEX_BLEND_ARB)");
3802

3803 3804 3805
            /* D3D adds one more matrix which has weight (1 - sum(weights)).
             * This is enabled at context creation with enabling
             * GL_WEIGHT_SUM_UNITY_ARB. */
3806
            GL_EXTCALL(glVertexBlendARB(state->render_states[WINED3D_RS_VERTEXBLEND] + 1));
3807

3808
            if (!device->vertexBlendUsed)
3809
            {
3810
                unsigned int i;
3811
                for (i = 1; i < gl_info->limits.blends; ++i)
3812
                {
3813 3814
                    if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(i))))
                        transform_worldex(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(i)));
3815
                }
3816
                device->vertexBlendUsed = TRUE;
3817 3818 3819
            }
            break;

3820 3821
        case WINED3D_VBF_TWEENING:
        case WINED3D_VBF_0WEIGHTS: /* Indexed vertex blending, not supported. */
3822 3823 3824
            if (!once++) FIXME("Vertex blend flags %#x not supported.\n", val);
            else WARN("Vertex blend flags %#x not supported.\n", val);
            /* Fall through. */
3825
        case WINED3D_VBF_DISABLE:
3826
            gl_info->gl_ops.gl.p_glDisable(GL_VERTEX_BLEND_ARB);
3827
            checkGLcall("glDisable(GL_VERTEX_BLEND_ARB)");
3828 3829 3830 3831
            break;
    }
}

3832
static void transform_view(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3833
{
3834
    const struct wined3d_gl_info *gl_info = context->gl_info;
3835
    const struct wined3d_light_info *light = NULL;
3836 3837 3838 3839 3840 3841 3842 3843
    unsigned int k;

    /* If we are changing the View matrix, reset the light and clipping planes to the new view
     * NOTE: We have to reset the positions even if the light/plane is not currently
     *       enabled, since the call to enable it will not reset the position.
     * NOTE2: Apparently texture transforms do NOT need reapplying
     */

3844
    gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3845
    checkGLcall("glMatrixMode(GL_MODELVIEW)");
3846
    gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW]._11);
3847 3848 3849
    checkGLcall("glLoadMatrixf(...)");

    /* Reset lights. TODO: Call light apply func */
3850
    for (k = 0; k < gl_info->limits.lights; ++k)
3851
    {
3852 3853
        if (!(light = state->lights[k]))
            continue;
3854
        if (light->OriginalParms.type == WINED3D_LIGHT_DIRECTIONAL)
3855
            gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, &light->direction.x);
3856
        else
3857
            gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_POSITION, &light->position.x);
3858
        checkGLcall("glLightfv posn");
3859
        gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + light->glIndex, GL_SPOT_DIRECTION, &light->direction.x);
3860 3861 3862
        checkGLcall("glLightfv dirn");
    }

3863
    /* Reset Clipping Planes  */
3864
    for (k = 0; k < gl_info->limits.clipplanes; ++k)
3865
    {
3866 3867
        if (!isStateDirty(context, STATE_CLIPPLANE(k)))
            clipplane(context, state, STATE_CLIPPLANE(k));
3868
    }
3869

3870 3871 3872
    if (context->last_was_rhw)
    {
        gl_info->gl_ops.gl.p_glLoadIdentity();
3873 3874 3875 3876 3877 3878
        checkGLcall("glLoadIdentity()");
        /* No need to update the world matrix, the identity is fine */
        return;
    }

    /* Call the world matrix state, this will apply the combined WORLD + VIEW matrix
3879
     * No need to do it here if the state is scheduled for update. */
3880 3881
    if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))))
        transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
3882

3883
    /* Avoid looping over a number of matrices if the app never used the functionality */
3884
    if (context->swapchain->device->vertexBlendUsed)
3885
    {
3886
        for (k = 1; k < gl_info->limits.blends; ++k)
3887
        {
3888 3889
            if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(k))))
                transform_worldex(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(k)));
3890 3891
        }
    }
3892 3893
}

3894
static void transform_projection(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3895
{
3896
    const struct wined3d_gl_info *gl_info = context->gl_info;
3897
    struct wined3d_matrix projection;
3898 3899

    gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
3900
    checkGLcall("glMatrixMode(GL_PROJECTION)");
3901

3902 3903 3904
    get_projection_matrix(context, state, &projection);
    gl_info->gl_ops.gl.p_glLoadMatrixf(&projection._11);
    checkGLcall("glLoadMatrixf");
3905 3906
}

3907 3908 3909
/* This should match any arrays loaded in load_vertex_data.
 * TODO: Only load / unload arrays if we have to. */
static void unload_vertex_data(const struct wined3d_gl_info *gl_info)
3910
{
3911 3912 3913
    gl_info->gl_ops.gl.p_glDisableClientState(GL_VERTEX_ARRAY);
    gl_info->gl_ops.gl.p_glDisableClientState(GL_NORMAL_ARRAY);
    gl_info->gl_ops.gl.p_glDisableClientState(GL_COLOR_ARRAY);
3914
    if (gl_info->supported[EXT_SECONDARY_COLOR])
3915
        gl_info->gl_ops.gl.p_glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
3916
    if (gl_info->supported[ARB_VERTEX_BLEND])
3917
        gl_info->gl_ops.gl.p_glDisableClientState(GL_WEIGHT_ARRAY_ARB);
3918
    unload_tex_coords(gl_info);
3919 3920
}

3921
static inline void unload_numbered_array(struct wined3d_context *context, int i)
3922
{
3923 3924
    const struct wined3d_gl_info *gl_info = context->gl_info;

3925 3926
    GL_EXTCALL(glDisableVertexAttribArray(i));
    checkGLcall("glDisableVertexAttribArray");
3927
    if (gl_info->supported[ARB_INSTANCED_ARRAYS])
3928
        GL_EXTCALL(glVertexAttribDivisor(i, 0));
3929

3930
    context->numbered_array_mask &= ~(1u << i);
3931 3932
}

3933
/* This should match any arrays loaded in loadNumberedArrays
3934 3935
 * TODO: Only load / unload arrays if we have to. */
static void unload_numbered_arrays(struct wined3d_context *context)
3936
{
3937 3938 3939
    /* disable any attribs (this is the same for both GLSL and ARB modes) */
    int i;

3940
    for (i = 0; i < context->gl_info->limits.vertex_attribs; ++i) {
3941
        unload_numbered_array(context, i);
3942 3943 3944
    }
}

3945 3946
static void load_numbered_arrays(struct wined3d_context *context,
        const struct wined3d_stream_info *stream_info, const struct wined3d_state *state)
3947
{
3948 3949
    const struct wined3d_gl_info *gl_info = context->gl_info;
    GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
3950 3951
    int i;

3952
    /* Default to no instancing */
3953
    context->instance_count = 0;
3954

3955 3956 3957 3958
    for (i = 0; i < MAX_ATTRIBS; i++)
    {
        const struct wined3d_stream_state *stream;

3959
        if (!(stream_info->use_map & (1u << i)))
3960
        {
3961
            if (context->numbered_array_mask & (1u << i))
3962
                unload_numbered_array(context, i);
3963 3964 3965
            if (!use_vs(state) && i == WINED3D_FFP_DIFFUSE)
                GL_EXTCALL(glVertexAttrib4f(i, 1.0f, 1.0f, 1.0f, 1.0f));
            else
3966
                GL_EXTCALL(glVertexAttrib4f(i, 0.0f, 0.0f, 0.0f, 0.0f));
3967
            continue;
3968
        }
3969

3970
        stream = &state->streams[stream_info->elements[i].stream_idx];
3971

3972 3973
        if ((stream->flags & WINED3DSTREAMSOURCE_INSTANCEDATA) && !context->instance_count)
            context->instance_count = state->streams[0].frequency ? state->streams[0].frequency : 1;
3974

3975 3976 3977
        if (gl_info->supported[ARB_INSTANCED_ARRAYS])
        {
            GL_EXTCALL(glVertexAttribDivisor(i, stream_info->elements[i].divisor));
3978
        }
3979
        else if (stream_info->elements[i].divisor)
3980
        {
3981 3982
            /* Unload instanced arrays, they will be loaded using
             * immediate mode instead. */
3983
            if (context->numbered_array_mask & (1u << i))
3984 3985
                unload_numbered_array(context, i);
            continue;
3986 3987
        }

3988
        TRACE_(d3d_shader)("Loading array %u [VBO=%u]\n", i, stream_info->elements[i].data.buffer_object);
3989

3990 3991
        if (stream_info->elements[i].stride)
        {
3992
            if (curVBO != stream_info->elements[i].data.buffer_object)
3993
            {
3994 3995
                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, stream_info->elements[i].data.buffer_object));
                checkGLcall("glBindBuffer");
3996
                curVBO = stream_info->elements[i].data.buffer_object;
3997
            }
3998 3999 4000 4001
            /* Use the VBO to find out if a vertex buffer exists, not the vb
             * pointer. vb can point to a user pointer data blob. In that case
             * curVBO will be 0. If there is a vertex buffer but no vbo we
             * won't be load converted attributes anyway. */
4002
            GL_EXTCALL(glVertexAttribPointer(i, stream_info->elements[i].format->gl_vtx_format,
4003 4004
                    stream_info->elements[i].format->gl_vtx_type,
                    stream_info->elements[i].format->gl_normalized,
4005
                    stream_info->elements[i].stride, stream_info->elements[i].data.addr
4006
                    + state->load_base_vertex_index * stream_info->elements[i].stride));
4007

4008
            if (!(context->numbered_array_mask & (1u << i)))
4009
            {
4010
                GL_EXTCALL(glEnableVertexAttribArray(i));
4011
                context->numbered_array_mask |= (1u << i);
4012
            }
4013 4014 4015 4016
        }
        else
        {
            /* Stride = 0 means always the same values.
4017
             * glVertexAttribPointer doesn't do that. Instead disable the
4018 4019
             * pointer and set up the attribute statically. But we have to
             * figure out the system memory address. */
4020
            const BYTE *ptr = stream_info->elements[i].data.addr;
4021
            if (stream_info->elements[i].data.buffer_object)
4022
            {
4023
                ptr += (ULONG_PTR)buffer_get_sysmem(stream->buffer, context);
4024
            }
4025

4026
            if (context->numbered_array_mask & (1u << i)) unload_numbered_array(context, i);
4027

4028
            switch (stream_info->elements[i].format->id)
4029
            {
4030
                case WINED3DFMT_R32_FLOAT:
4031
                    GL_EXTCALL(glVertexAttrib1fv(i, (const GLfloat *)ptr));
4032
                    break;
4033
                case WINED3DFMT_R32G32_FLOAT:
4034
                    GL_EXTCALL(glVertexAttrib2fv(i, (const GLfloat *)ptr));
4035
                    break;
4036
                case WINED3DFMT_R32G32B32_FLOAT:
4037
                    GL_EXTCALL(glVertexAttrib3fv(i, (const GLfloat *)ptr));
4038
                    break;
4039
                case WINED3DFMT_R32G32B32A32_FLOAT:
4040
                    GL_EXTCALL(glVertexAttrib4fv(i, (const GLfloat *)ptr));
4041 4042
                    break;

4043
                case WINED3DFMT_R8G8B8A8_UINT:
4044
                    GL_EXTCALL(glVertexAttrib4ubv(i, ptr));
4045
                    break;
4046
                case WINED3DFMT_B8G8R8A8_UNORM:
4047
                    if (gl_info->supported[ARB_VERTEX_ARRAY_BGRA])
4048 4049
                    {
                        const DWORD *src = (const DWORD *)ptr;
4050 4051 4052
                        DWORD c = *src & 0xff00ff00u;
                        c |= (*src & 0xff0000u) >> 16;
                        c |= (*src & 0xffu) << 16;
4053
                        GL_EXTCALL(glVertexAttrib4Nubv(i, (GLubyte *)&c));
4054 4055 4056
                        break;
                    }
                    /* else fallthrough */
4057
                case WINED3DFMT_R8G8B8A8_UNORM:
4058
                    GL_EXTCALL(glVertexAttrib4Nubv(i, ptr));
4059 4060
                    break;

4061
                case WINED3DFMT_R16G16_SINT:
4062
                    GL_EXTCALL(glVertexAttrib2sv(i, (const GLshort *)ptr));
4063
                    break;
4064
                case WINED3DFMT_R16G16B16A16_SINT:
4065
                    GL_EXTCALL(glVertexAttrib4sv(i, (const GLshort *)ptr));
4066 4067
                    break;

4068
                case WINED3DFMT_R16G16_SNORM:
4069
                {
4070
                    const GLshort s[4] = {((const GLshort *)ptr)[0], ((const GLshort *)ptr)[1], 0, 1};
4071
                    GL_EXTCALL(glVertexAttrib4Nsv(i, s));
4072 4073
                    break;
                }
4074
                case WINED3DFMT_R16G16_UNORM:
4075
                {
4076
                    const GLushort s[4] = {((const GLushort *)ptr)[0], ((const GLushort *)ptr)[1], 0, 1};
4077
                    GL_EXTCALL(glVertexAttrib4Nusv(i, s));
4078 4079
                    break;
                }
4080
                case WINED3DFMT_R16G16B16A16_SNORM:
4081
                    GL_EXTCALL(glVertexAttrib4Nsv(i, (const GLshort *)ptr));
4082
                    break;
4083
                case WINED3DFMT_R16G16B16A16_UNORM:
4084
                    GL_EXTCALL(glVertexAttrib4Nusv(i, (const GLushort *)ptr));
4085 4086
                    break;

4087
                case WINED3DFMT_R10G10B10A2_UINT:
4088
                    FIXME("Unsure about WINED3DDECLTYPE_UDEC3\n");
4089
                    /*glVertexAttrib3usvARB(i, (const GLushort *)ptr); Does not exist */
4090
                    break;
4091
                case WINED3DFMT_R10G10B10A2_SNORM:
4092
                    FIXME("Unsure about WINED3DDECLTYPE_DEC3N\n");
4093
                    /*glVertexAttrib3NusvARB(i, (const GLushort *)ptr); Does not exist */
4094 4095
                    break;

4096
                case WINED3DFMT_R16G16_FLOAT:
4097 4098 4099 4100 4101 4102 4103 4104 4105
                    if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
                    {
                        /* Not supported by GL_ARB_half_float_vertex. */
                        GL_EXTCALL(glVertexAttrib2hvNV(i, (const GLhalfNV *)ptr));
                    }
                    else
                    {
                        float x = float_16_to_32(((const unsigned short *)ptr) + 0);
                        float y = float_16_to_32(((const unsigned short *)ptr) + 1);
4106
                        GL_EXTCALL(glVertexAttrib2f(i, x, y));
4107
                    }
4108
                    break;
4109
                case WINED3DFMT_R16G16B16A16_FLOAT:
4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120
                    if (gl_info->supported[NV_HALF_FLOAT] && gl_info->supported[NV_VERTEX_PROGRAM])
                    {
                        /* Not supported by GL_ARB_half_float_vertex. */
                        GL_EXTCALL(glVertexAttrib4hvNV(i, (const GLhalfNV *)ptr));
                    }
                    else
                    {
                        float x = float_16_to_32(((const unsigned short *)ptr) + 0);
                        float y = float_16_to_32(((const unsigned short *)ptr) + 1);
                        float z = float_16_to_32(((const unsigned short *)ptr) + 2);
                        float w = float_16_to_32(((const unsigned short *)ptr) + 3);
4121
                        GL_EXTCALL(glVertexAttrib4f(i, x, y, z, w));
4122
                    }
4123 4124 4125 4126 4127 4128 4129
                    break;

                default:
                    ERR("Unexpected declaration in stride 0 attributes\n");
                    break;

            }
4130
        }
4131
    }
4132
    checkGLcall("Loading numbered arrays");
4133 4134
}

4135
static void load_vertex_data(struct wined3d_context *context,
4136
        const struct wined3d_stream_info *si, const struct wined3d_state *state)
4137
{
4138 4139
    const struct wined3d_gl_info *gl_info = context->gl_info;
    GLuint curVBO = gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] ? ~0U : 0;
4140
    const struct wined3d_stream_info_element *e;
4141 4142

    TRACE("Using fast vertex array code\n");
4143 4144

    /* This is fixed function pipeline only, and the fixed function pipeline doesn't do instancing */
4145
    context->instance_count = 0;
4146

4147
    /* Blend Data ---------------------------------------------- */
4148 4149
    if ((si->use_map & (1u << WINED3D_FFP_BLENDWEIGHT))
            || si->use_map & (1u << WINED3D_FFP_BLENDINDICES))
4150
    {
4151 4152
        e = &si->elements[WINED3D_FFP_BLENDWEIGHT];

4153
        if (gl_info->supported[ARB_VERTEX_BLEND])
4154
        {
4155
            TRACE("Blend %u %p %u\n", e->format->component_count,
4156
                    e->data.addr + state->load_base_vertex_index * e->stride, e->stride);
4157

4158
            gl_info->gl_ops.gl.p_glEnableClientState(GL_WEIGHT_ARRAY_ARB);
4159
            checkGLcall("glEnableClientState(GL_WEIGHT_ARRAY_ARB)");
4160

4161
            GL_EXTCALL(glVertexBlendARB(e->format->component_count + 1));
4162

4163
            if (curVBO != e->data.buffer_object)
4164
            {
4165 4166
                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
                checkGLcall("glBindBuffer");
4167
                curVBO = e->data.buffer_object;
4168 4169
            }

4170
            TRACE("glWeightPointerARB(%#x, %#x, %#x, %p);\n",
4171 4172
                    e->format->gl_vtx_format,
                    e->format->gl_vtx_type,
4173
                    e->stride,
4174
                    e->data.addr + state->load_base_vertex_index * e->stride);
4175
            GL_EXTCALL(glWeightPointerARB(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4176
                    e->data.addr + state->load_base_vertex_index * e->stride));
4177 4178 4179

            checkGLcall("glWeightPointerARB");

4180
            if (si->use_map & (1u << WINED3D_FFP_BLENDINDICES))
4181
            {
4182 4183 4184
                static BOOL warned;
                if (!warned)
                {
4185
                    FIXME("blendMatrixIndices support\n");
4186
                    warned = TRUE;
4187 4188 4189
                }
            }
        } else {
4190 4191 4192 4193
            /* TODO: support blends in drawStridedSlow
             * No need to write a FIXME here, this is done after the general vertex decl decoding
             */
            WARN("unsupported blending in openGl\n");
4194
        }
4195 4196 4197
    }
    else
    {
4198
        if (gl_info->supported[ARB_VERTEX_BLEND])
4199
        {
4200 4201
            static const GLbyte one = 1;
            GL_EXTCALL(glWeightbvARB(1, &one));
4202
            checkGLcall("glWeightbvARB(gl_info->max_blends, weights)");
4203 4204 4205 4206
        }
    }

    /* Point Size ----------------------------------------------*/
4207
    if (si->use_map & (1u << WINED3D_FFP_PSIZE))
4208
    {
4209 4210 4211 4212 4213 4214
        /* no such functionality in the fixed function GL pipeline */
        TRACE("Cannot change ptSize here in openGl\n");
        /* TODO: Implement this function in using shaders if they are available */
    }

    /* Vertex Pointers -----------------------------------------*/
4215
    if (si->use_map & (1u << WINED3D_FFP_POSITION))
4216
    {
4217
        e = &si->elements[WINED3D_FFP_POSITION];
4218

4219
        if (curVBO != e->data.buffer_object)
4220
        {
4221 4222
            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
            checkGLcall("glBindBuffer");
4223
            curVBO = e->data.buffer_object;
4224 4225
        }

4226 4227 4228
        TRACE("glVertexPointer(%#x, %#x, %#x, %p);\n",
                e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
                e->data.addr + state->load_base_vertex_index * e->stride);
4229
        gl_info->gl_ops.gl.p_glVertexPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4230
                e->data.addr + state->load_base_vertex_index * e->stride);
4231
        checkGLcall("glVertexPointer(...)");
4232
        gl_info->gl_ops.gl.p_glEnableClientState(GL_VERTEX_ARRAY);
4233 4234 4235 4236
        checkGLcall("glEnableClientState(GL_VERTEX_ARRAY)");
    }

    /* Normals -------------------------------------------------*/
4237
    if (si->use_map & (1u << WINED3D_FFP_NORMAL))
4238
    {
4239
        e = &si->elements[WINED3D_FFP_NORMAL];
4240

4241
        if (curVBO != e->data.buffer_object)
4242
        {
4243 4244
            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
            checkGLcall("glBindBuffer");
4245
            curVBO = e->data.buffer_object;
4246
        }
4247

4248
        TRACE("glNormalPointer(%#x, %#x, %p);\n", e->format->gl_vtx_type, e->stride,
4249
                e->data.addr + state->load_base_vertex_index * e->stride);
4250
        gl_info->gl_ops.gl.p_glNormalPointer(e->format->gl_vtx_type, e->stride,
4251
                e->data.addr + state->load_base_vertex_index * e->stride);
4252
        checkGLcall("glNormalPointer(...)");
4253
        gl_info->gl_ops.gl.p_glEnableClientState(GL_NORMAL_ARRAY);
4254 4255
        checkGLcall("glEnableClientState(GL_NORMAL_ARRAY)");

4256 4257 4258 4259
    }
    else
    {
        gl_info->gl_ops.gl.p_glNormal3f(0, 0, 0);
4260
        checkGLcall("glNormal3f(0, 0, 0)");
4261 4262 4263
    }

    /* Diffuse Colour --------------------------------------------*/
4264
    if (si->use_map & (1u << WINED3D_FFP_DIFFUSE))
4265
    {
4266
        e = &si->elements[WINED3D_FFP_DIFFUSE];
4267

4268
        if (curVBO != e->data.buffer_object)
4269
        {
4270 4271
            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
            checkGLcall("glBindBuffer");
4272
            curVBO = e->data.buffer_object;
4273
        }
4274

4275
        TRACE("glColorPointer(%#x, %#x %#x, %p);\n",
4276
                e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4277
                e->data.addr + state->load_base_vertex_index * e->stride);
4278
        gl_info->gl_ops.gl.p_glColorPointer(e->format->gl_vtx_format, e->format->gl_vtx_type, e->stride,
4279
                e->data.addr + state->load_base_vertex_index * e->stride);
4280
        checkGLcall("glColorPointer(4, GL_UNSIGNED_BYTE, ...)");
4281
        gl_info->gl_ops.gl.p_glEnableClientState(GL_COLOR_ARRAY);
4282 4283
        checkGLcall("glEnableClientState(GL_COLOR_ARRAY)");

4284 4285 4286 4287
    }
    else
    {
        gl_info->gl_ops.gl.p_glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
4288 4289 4290 4291
        checkGLcall("glColor4f(1, 1, 1, 1)");
    }

    /* Specular Colour ------------------------------------------*/
4292
    if (si->use_map & (1u << WINED3D_FFP_SPECULAR))
4293
    {
4294
        TRACE("setting specular colour\n");
4295

4296
        e = &si->elements[WINED3D_FFP_SPECULAR];
4297

4298
        if (gl_info->supported[EXT_SECONDARY_COLOR])
4299
        {
4300 4301
            GLenum type = e->format->gl_vtx_type;
            GLint format = e->format->gl_vtx_format;
4302

4303
            if (curVBO != e->data.buffer_object)
4304
            {
4305 4306
                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
                checkGLcall("glBindBuffer");
4307
                curVBO = e->data.buffer_object;
4308
            }
4309

4310
            if (format != 4 || (gl_info->quirks & WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA))
4311 4312 4313 4314 4315 4316
            {
                /* Usually specular colors only allow 3 components, since they have no alpha. In D3D, the specular alpha
                 * contains the fog coordinate, which is passed to GL with GL_EXT_fog_coord. However, the fixed function
                 * vertex pipeline can pass the specular alpha through, and pixel shaders can read it. So it GL accepts
                 * 4 component secondary colors use it
                 */
4317
                TRACE("glSecondaryColorPointer(%#x, %#x, %#x, %p);\n", format, type, e->stride,
4318
                        e->data.addr + state->load_base_vertex_index * e->stride);
4319
                GL_EXTCALL(glSecondaryColorPointerEXT(format, type, e->stride,
4320
                        e->data.addr + state->load_base_vertex_index * e->stride));
4321 4322 4323 4324 4325 4326 4327
                checkGLcall("glSecondaryColorPointerEXT(format, type, ...)");
            }
            else
            {
                switch(type)
                {
                    case GL_UNSIGNED_BYTE:
4328
                        TRACE("glSecondaryColorPointer(3, GL_UNSIGNED_BYTE, %#x, %p);\n", e->stride,
4329
                                e->data.addr + state->load_base_vertex_index * e->stride);
4330
                        GL_EXTCALL(glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, e->stride,
4331
                                e->data.addr + state->load_base_vertex_index * e->stride));
4332 4333 4334 4335 4336 4337
                        checkGLcall("glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, ...)");
                        break;

                    default:
                        FIXME("Add 4 component specular color pointers for type %x\n", type);
                        /* Make sure that the right color component is dropped */
4338
                        TRACE("glSecondaryColorPointer(3, %#x, %#x, %p);\n", type, e->stride,
4339
                                e->data.addr + state->load_base_vertex_index * e->stride);
4340
                        GL_EXTCALL(glSecondaryColorPointerEXT(3, type, e->stride,
4341
                                e->data.addr + state->load_base_vertex_index * e->stride));
4342 4343 4344
                        checkGLcall("glSecondaryColorPointerEXT(3, type, ...)");
                }
            }
4345
            gl_info->gl_ops.gl.p_glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
4346
            checkGLcall("glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT)");
4347 4348 4349 4350
        }
        else
        {
            WARN("Specular colour is not supported in this GL implementation.\n");
4351
        }
4352 4353 4354
    }
    else
    {
4355
        if (gl_info->supported[EXT_SECONDARY_COLOR])
4356
        {
4357 4358
            GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
            checkGLcall("glSecondaryColor3fEXT(0, 0, 0)");
4359 4360 4361 4362
        }
        else
        {
            WARN("Specular colour is not supported in this GL implementation.\n");
4363 4364 4365 4366
        }
    }

    /* Texture coords -------------------------------------------*/
4367
    load_tex_coords(context, si, &curVBO, state);
4368 4369
}

4370
static void streamsrc(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4371
{
4372 4373 4374 4375
    BOOL load_numbered = context->d3d_info->ffp_generic_attributes
            || (use_vs(state) && !context->use_immediate_mode_draw);
    BOOL load_named = !context->d3d_info->ffp_generic_attributes
            && !use_vs(state) && !context->use_immediate_mode_draw;
4376

4377
    if (isStateDirty(context, STATE_VDECL)) return;
4378 4379
    if (context->numberedArraysLoaded && !load_numbered)
    {
4380
        unload_numbered_arrays(context);
4381 4382 4383 4384 4385
        context->numberedArraysLoaded = FALSE;
        context->numbered_array_mask = 0;
    }
    else if (context->namedArraysLoaded)
    {
4386
        unload_vertex_data(context->gl_info);
4387 4388 4389 4390 4391 4392
        context->namedArraysLoaded = FALSE;
    }

    if (load_numbered)
    {
        TRACE("Loading numbered arrays\n");
4393
        load_numbered_arrays(context, &context->stream_info, state);
4394 4395 4396 4397 4398
        context->numberedArraysLoaded = TRUE;
    }
    else if (load_named)
    {
        TRACE("Loading vertex data\n");
4399
        load_vertex_data(context, &context->stream_info, state);
4400 4401
        context->namedArraysLoaded = TRUE;
    }
4402 4403
}

4404
static void vdecl_miscpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4405
{
4406 4407 4408
    if (isStateDirty(context, STATE_STREAMSRC))
        return;
    streamsrc(context, state, STATE_STREAMSRC);
4409 4410
}

4411
static void vertexdeclaration(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4412
{
4413
    const struct wined3d_gl_info *gl_info = context->gl_info;
4414
    BOOL useVertexShaderFunction = use_vs(state);
4415
    BOOL updateFog = FALSE;
4416
    BOOL transformed;
4417
    BOOL wasrhw = context->last_was_rhw;
4418
    unsigned int i;
4419

4420
    transformed = context->stream_info.position_transformed;
4421
    if (transformed != context->last_was_rhw && !useVertexShaderFunction)
4422 4423
        updateFog = TRUE;

4424
    context->last_was_rhw = transformed;
4425

4426 4427 4428 4429 4430 4431 4432 4433
    /* Don't have to apply the matrices when vertex shaders are used. When
     * vshaders are turned off this function will be called again anyway to
     * make sure they're properly set. */
    if (!useVertexShaderFunction)
    {
        /* TODO: Move this mainly to the viewport state and only apply when
         * the vp has changed or transformed / untransformed was switched. */
        if (wasrhw != context->last_was_rhw
4434
                && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION))
4435
                && !isStateDirty(context, STATE_VIEWPORT))
4436
            transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447
        /* World matrix needs reapplication here only if we're switching between rhw and non-rhw
         * mode.
         *
         * If a vertex shader is used, the world matrix changed and then vertex shader unbound
         * this check will fail and the matrix not applied again. This is OK because a simple
         * world matrix change reapplies the matrix - These checks here are only to satisfy the
         * needs of the vertex declaration.
         *
         * World and view matrix go into the same gl matrix, so only apply them when neither is
         * dirty
         */
4448 4449 4450
        if (transformed != wasrhw && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)))
                && !isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_VIEW)))
            transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
4451
        if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_COLORVERTEX)))
4452
            context_apply_state(context, state, STATE_RENDER(WINED3D_RS_COLORVERTEX));
4453 4454
        if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_LIGHTING)))
            state_lighting(context, state, STATE_RENDER(WINED3D_RS_LIGHTING));
4455 4456 4457 4458

        if (context->last_was_vshader)
        {
            updateFog = TRUE;
4459

4460 4461 4462
            if (!context->d3d_info->vs_clipping
                    && !isStateDirty(context, STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE)))
            {
4463
                state_clipping(context, state, STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE));
4464
            }
4465

4466
            for (i = 0; i < gl_info->limits.clipplanes; ++i)
4467
            {
4468
                clipplane(context, state, STATE_CLIPPLANE(i));
4469
            }
4470
        }
4471 4472
        if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_NORMALIZENORMALS)))
            state_normalize(context, state, STATE_RENDER(WINED3D_RS_NORMALIZENORMALS));
4473 4474 4475
    }
    else
    {
4476 4477
        if(!context->last_was_vshader) {
            static BOOL warned = FALSE;
4478 4479
            if (!context->d3d_info->vs_clipping)
            {
4480 4481 4482
                /* Disable all clip planes to get defined results on all drivers. See comment in the
                 * state_clipping state handler
                 */
4483
                for (i = 0; i < gl_info->limits.clipplanes; ++i)
4484
                {
4485
                    gl_info->gl_ops.gl.p_glDisable(GL_CLIP_PLANE0 + i);
4486 4487
                    checkGLcall("glDisable(GL_CLIP_PLANE0 + i)");
                }
4488

4489
                if (!warned && state->render_states[WINED3D_RS_CLIPPLANEENABLE])
4490
                {
4491 4492 4493
                    FIXME("Clipping not supported with vertex shaders\n");
                    warned = TRUE;
                }
4494
            }
4495 4496 4497 4498 4499 4500 4501 4502 4503
            if (wasrhw)
            {
                /* Apply the transform matrices when switching from rhw
                 * drawing to vertex shaders. Vertex shaders themselves do
                 * not need it, but the matrices are not reapplied
                 * automatically when switching back from vertex shaders to
                 * fixed function processing. So make sure we leave the fixed
                 * function vertex processing states back in a sane state
                 * before switching to shaders. */
4504 4505 4506 4507
                if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
                    transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
                if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0))))
                    transform_world(context, state, STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(0)));
4508
            }
4509
            updateFog = TRUE;
4510 4511 4512 4513 4514

            /* Vertex shader clipping ignores the view matrix. Update all clipplanes
             * (Note: ARB shaders can read the clip planes for clipping emulation even if
             * device->vs_clipping is false.
             */
4515
            for (i = 0; i < gl_info->limits.clipplanes; ++i)
4516
            {
4517
                clipplane(context, state, STATE_CLIPPLANE(i));
4518
            }
4519
        }
4520
    }
4521

4522
    context->last_was_vshader = useVertexShaderFunction;
4523
    context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
4524

4525
    if (updateFog)
4526
        context_apply_state(context, state, STATE_RENDER(WINED3D_RS_FOGVERTEXMODE));
4527

4528 4529 4530 4531 4532 4533
    if (!useVertexShaderFunction)
    {
        unsigned int i;

        for (i = 0; i < MAX_TEXTURES; ++i)
        {
4534
            if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + i)))
4535
                transform_texture(context, state, STATE_TEXTURESTAGE(i, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS));
4536
        }
4537

4538 4539
        if (use_ps(state) && state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.shader_version.major == 1
                && state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.shader_version.minor <= 3)
4540
            context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
4541
    }
4542 4543
}

4544
static void viewport_miscpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4545
{
4546
    const struct wined3d_rendertarget_view *target = state->fb->render_targets[0];
4547
    const struct wined3d_gl_info *gl_info = context->gl_info;
4548
    struct wined3d_viewport vp = state->viewport;
4549

4550 4551 4552 4553
    if (vp.width > target->width)
        vp.width = target->width;
    if (vp.height > target->height)
        vp.height = target->height;
4554

4555
    gl_info->gl_ops.gl.p_glDepthRange(vp.min_z, vp.max_z);
4556
    checkGLcall("glDepthRange");
4557 4558
    /* Note: GL requires lower left, DirectX supplies upper left. This is
     * reversed when using offscreen rendering. */
4559 4560
    if (context->render_offscreen)
    {
4561
        gl_info->gl_ops.gl.p_glViewport(vp.x, vp.y, vp.width, vp.height);
4562 4563 4564 4565
    }
    else
    {
        UINT width, height;
4566

4567
        surface_get_drawable_size(wined3d_rendertarget_view_get_surface(target), context, &width, &height);
4568
        gl_info->gl_ops.gl.p_glViewport(vp.x, (height - (vp.y + vp.height)),
4569
                vp.width, vp.height);
4570
    }
4571
    checkGLcall("glViewport");
4572
}
4573

4574
static void viewport_vertexpart(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4575
{
4576 4577
    if (!isStateDirty(context, STATE_TRANSFORM(WINED3D_TS_PROJECTION)))
        transform_projection(context, state, STATE_TRANSFORM(WINED3D_TS_PROJECTION));
4578 4579
    if (!isStateDirty(context, STATE_RENDER(WINED3D_RS_POINTSCALEENABLE))
            && state->render_states[WINED3D_RS_POINTSCALEENABLE])
4580
        state_pscale(context, state, STATE_RENDER(WINED3D_RS_POINTSCALEENABLE));
4581
    /* Update the position fixup. */
4582
    context->constant_update_mask |= WINED3D_SHADER_CONST_VS_POS_FIXUP;
4583 4584
}

4585
static void light(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4586
{
4587
    const struct wined3d_gl_info *gl_info = context->gl_info;
4588 4589
    UINT Index = state_id - STATE_ACTIVELIGHT(0);
    const struct wined3d_light_info *lightInfo = state->lights[Index];
4590

4591 4592
    if (!lightInfo)
    {
4593
        gl_info->gl_ops.gl.p_glDisable(GL_LIGHT0 + Index);
4594
        checkGLcall("glDisable(GL_LIGHT0 + Index)");
4595 4596 4597
    }
    else
    {
4598
        float quad_att;
4599
        float colRGBA[] = {0.0f, 0.0f, 0.0f, 0.0f};
4600 4601

        /* Light settings are affected by the model view in OpenGL, the View transform in direct3d*/
4602 4603
        gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
        gl_info->gl_ops.gl.p_glPushMatrix();
4604
        gl_info->gl_ops.gl.p_glLoadMatrixf(&state->transforms[WINED3D_TS_VIEW]._11);
4605 4606

        /* Diffuse: */
4607 4608 4609 4610
        colRGBA[0] = lightInfo->OriginalParms.diffuse.r;
        colRGBA[1] = lightInfo->OriginalParms.diffuse.g;
        colRGBA[2] = lightInfo->OriginalParms.diffuse.b;
        colRGBA[3] = lightInfo->OriginalParms.diffuse.a;
4611
        gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_DIFFUSE, colRGBA);
4612 4613 4614
        checkGLcall("glLightfv");

        /* Specular */
4615 4616 4617 4618
        colRGBA[0] = lightInfo->OriginalParms.specular.r;
        colRGBA[1] = lightInfo->OriginalParms.specular.g;
        colRGBA[2] = lightInfo->OriginalParms.specular.b;
        colRGBA[3] = lightInfo->OriginalParms.specular.a;
4619
        gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_SPECULAR, colRGBA);
4620 4621 4622
        checkGLcall("glLightfv");

        /* Ambient */
4623 4624 4625 4626
        colRGBA[0] = lightInfo->OriginalParms.ambient.r;
        colRGBA[1] = lightInfo->OriginalParms.ambient.g;
        colRGBA[2] = lightInfo->OriginalParms.ambient.b;
        colRGBA[3] = lightInfo->OriginalParms.ambient.a;
4627
        gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_AMBIENT, colRGBA);
4628 4629
        checkGLcall("glLightfv");

4630 4631 4632
        if ((lightInfo->OriginalParms.range * lightInfo->OriginalParms.range) >= FLT_MIN)
            quad_att = 1.4f / (lightInfo->OriginalParms.range * lightInfo->OriginalParms.range);
        else
4633
            quad_att = 0.0f; /*  0 or  MAX?  (0 seems to be ok) */
4634

4635 4636 4637 4638
        /* Do not assign attenuation values for lights that do not use them. D3D apps are free to pass any junk,
         * but gl drivers use them and may crash due to bad Attenuation values. Need for Speed most wanted sets
         * Attenuation0 to NaN and crashes in the gl lib
         */
4639

4640 4641
        switch (lightInfo->OriginalParms.type)
        {
4642
            case WINED3D_LIGHT_POINT:
4643
                /* Position */
4644
                gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->position.x);
4645
                checkGLcall("glLightfv");
4646
                gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4647
                checkGLcall("glLightf");
4648 4649
                gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION,
                        lightInfo->OriginalParms.attenuation0);
4650
                checkGLcall("glLightf");
4651 4652
                gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION,
                        lightInfo->OriginalParms.attenuation1);
4653
                checkGLcall("glLightf");
4654 4655
                if (quad_att < lightInfo->OriginalParms.attenuation2)
                    quad_att = lightInfo->OriginalParms.attenuation2;
4656
                gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
4657
                checkGLcall("glLightf");
4658 4659 4660
                /* FIXME: Range */
                break;

4661
            case WINED3D_LIGHT_SPOT:
4662
                /* Position */
4663
                gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->position.x);
4664 4665
                checkGLcall("glLightfv");
                /* Direction */
4666
                gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_SPOT_DIRECTION, &lightInfo->direction.x);
4667
                checkGLcall("glLightfv");
4668
                gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, lightInfo->exponent);
4669
                checkGLcall("glLightf");
4670
                gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4671
                checkGLcall("glLightf");
4672 4673
                gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_CONSTANT_ATTENUATION,
                        lightInfo->OriginalParms.attenuation0);
4674
                checkGLcall("glLightf");
4675 4676
                gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_LINEAR_ATTENUATION,
                        lightInfo->OriginalParms.attenuation1);
4677
                checkGLcall("glLightf");
4678 4679
                if (quad_att < lightInfo->OriginalParms.attenuation2)
                    quad_att = lightInfo->OriginalParms.attenuation2;
4680
                gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_QUADRATIC_ATTENUATION, quad_att);
4681
                checkGLcall("glLightf");
4682 4683 4684
                /* FIXME: Range */
                break;

4685
            case WINED3D_LIGHT_DIRECTIONAL:
4686
                /* Direction */
4687
                /* Note GL uses w position of 0 for direction! */
4688
                gl_info->gl_ops.gl.p_glLightfv(GL_LIGHT0 + Index, GL_POSITION, &lightInfo->direction.x);
4689
                checkGLcall("glLightfv");
4690
                gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_CUTOFF, lightInfo->cutoff);
4691
                checkGLcall("glLightf");
4692
                gl_info->gl_ops.gl.p_glLightf(GL_LIGHT0 + Index, GL_SPOT_EXPONENT, 0.0f);
4693 4694 4695 4696
                checkGLcall("glLightf");
                break;

            default:
4697
                FIXME("Unrecognized light type %#x.\n", lightInfo->OriginalParms.type);
4698 4699 4700
        }

        /* Restore the modelview matrix */
4701
        gl_info->gl_ops.gl.p_glPopMatrix();
4702

4703
        gl_info->gl_ops.gl.p_glEnable(GL_LIGHT0 + Index);
4704 4705 4706 4707
        checkGLcall("glEnable(GL_LIGHT0 + Index)");
    }
}

4708
static void scissorrect(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4709
{
4710
    const struct wined3d_gl_info *gl_info = context->gl_info;
4711 4712 4713 4714 4715 4716
    const RECT *r = &state->scissor_rect;

    /* Warning: glScissor uses window coordinates, not viewport coordinates,
     * so our viewport correction does not apply. Warning2: Even in windowed
     * mode the coords are relative to the window, not the screen. */
    TRACE("Setting new scissor rect to %s.\n", wine_dbgstr_rect(r));
4717

4718 4719
    if (context->render_offscreen)
    {
4720
        gl_info->gl_ops.gl.p_glScissor(r->left, r->top, r->right - r->left, r->bottom - r->top);
4721 4722 4723
    }
    else
    {
4724
        const struct wined3d_rendertarget_view *target = state->fb->render_targets[0];
4725 4726 4727
        UINT height;
        UINT width;

4728
        surface_get_drawable_size(wined3d_rendertarget_view_get_surface(target), context, &width, &height);
4729
        gl_info->gl_ops.gl.p_glScissor(r->left, height - r->bottom, r->right - r->left, r->bottom - r->top);
4730
    }
4731 4732 4733
    checkGLcall("glScissor");
}

4734
static void indexbuffer(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4735
{
4736
    const struct wined3d_stream_info *stream_info = &context->stream_info;
4737 4738
    const struct wined3d_gl_info *gl_info = context->gl_info;

4739
    if (!state->index_buffer || !stream_info->all_vbo)
4740
    {
4741
        GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
4742 4743 4744
    }
    else
    {
4745
        struct wined3d_buffer *ib = state->index_buffer;
4746
        GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib->buffer_object));
4747 4748 4749
    }
}

4750
static void frontface(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4751
{
4752 4753
    const struct wined3d_gl_info *gl_info = context->gl_info;

4754 4755
    if (context->render_offscreen)
    {
4756
        gl_info->gl_ops.gl.p_glFrontFace(GL_CCW);
4757
        checkGLcall("glFrontFace(GL_CCW)");
4758 4759 4760 4761
    }
    else
    {
        gl_info->gl_ops.gl.p_glFrontFace(GL_CW);
4762 4763 4764 4765
        checkGLcall("glFrontFace(GL_CW)");
    }
}

4766
static void psorigin_w(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4767 4768 4769 4770 4771 4772 4773 4774 4775 4776
{
    static BOOL warned;

    if (!warned)
    {
        WARN("Point sprite coordinate origin switching not supported.\n");
        warned = TRUE;
    }
}

4777
static void psorigin(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
4778 4779 4780 4781
{
    const struct wined3d_gl_info *gl_info = context->gl_info;
    GLint origin = context->render_offscreen ? GL_LOWER_LEFT : GL_UPPER_LEFT;

4782 4783
    GL_EXTCALL(glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, origin));
    checkGLcall("glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, ...)");
4784 4785
}

4786 4787
void state_srgbwrite(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
4788
    unsigned int rt_fmt_flags = state->fb->render_targets[0]->format_flags;
4789 4790 4791 4792
    const struct wined3d_gl_info *gl_info = context->gl_info;

    TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);

4793
    if (state->render_states[WINED3D_RS_SRGBWRITEENABLE] && rt_fmt_flags & WINED3DFMT_FLAG_SRGB_WRITE)
4794 4795 4796 4797 4798
        gl_info->gl_ops.gl.p_glEnable(GL_FRAMEBUFFER_SRGB);
    else
        gl_info->gl_ops.gl.p_glDisable(GL_FRAMEBUFFER_SRGB);
}

4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848
static void state_cb(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
        enum wined3d_shader_type type, unsigned int base, unsigned int count)
{
    struct wined3d_buffer *buffer;
    unsigned int i;

    for (i = 0; i < count; ++i)
    {
        buffer = state->cb[type][i];
        GL_EXTCALL(glBindBufferBase(GL_UNIFORM_BUFFER, base + i, buffer ? buffer->buffer_object : 0));
    }
    checkGLcall("glBindBufferBase");
}

static void state_cb_vs(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
    const struct wined3d_gl_limits *limits = &context->gl_info->limits;

    TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);

    state_cb(context->gl_info, state, WINED3D_SHADER_TYPE_VERTEX, 0, limits->vertex_uniform_blocks);
}

static void state_cb_gs(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
    const struct wined3d_gl_limits *limits = &context->gl_info->limits;

    TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);

    state_cb(context->gl_info, state, WINED3D_SHADER_TYPE_GEOMETRY,
            limits->vertex_uniform_blocks, limits->geometry_uniform_blocks);
}

static void state_cb_ps(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
    const struct wined3d_gl_limits *limits = &context->gl_info->limits;

    TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);

    state_cb(context->gl_info, state, WINED3D_SHADER_TYPE_PIXEL,
            limits->vertex_uniform_blocks + limits->geometry_uniform_blocks, limits->fragment_uniform_blocks);
}

static void state_cb_warn(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
    TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);

    WARN("Constant buffers (%s) no supported.\n", debug_d3dstate(state_id));
}

4849 4850 4851 4852 4853 4854 4855 4856
static void state_shader_resource_binding(struct wined3d_context *context,
        const struct wined3d_state *state, DWORD state_id)
{
    TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);

    context->update_shader_resource_bindings = 1;
}

4857 4858 4859 4860 4861 4862 4863 4864
const struct StateEntryTemplate misc_state_template[] =
{
    { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX),  { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX),  state_cb_vs,        }, ARB_UNIFORM_BUFFER_OBJECT       },
    { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX),  { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX),  state_cb_warn,      }, WINED3D_GL_EXT_NONE             },
    { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),{ STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),state_cb_gs,        }, ARB_UNIFORM_BUFFER_OBJECT       },
    { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),{ STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),state_cb_warn,      }, WINED3D_GL_EXT_NONE             },
    { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL),   { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL),   state_cb_ps,        }, ARB_UNIFORM_BUFFER_OBJECT       },
    { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL),   { STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL),   state_cb_warn,      }, WINED3D_GL_EXT_NONE             },
4865
    { STATE_SHADER_RESOURCE_BINDING,                      { STATE_SHADER_RESOURCE_BINDING,                      state_shader_resource_binding}, WINED3D_GL_EXT_NONE    },
4866 4867 4868 4869 4870 4871 4872 4873 4874 4875
    { STATE_RENDER(WINED3D_RS_SRCBLEND),                  { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_DESTBLEND),                 { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE),          { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE),          state_blend         }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_EDGEANTIALIAS),             { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ANTIALIASEDLINEENABLE),     { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_SEPARATEALPHABLENDENABLE),  { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_SRCBLENDALPHA),             { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA),            { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_DESTBLENDALPHA),            { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_BLENDOPALPHA),              { STATE_RENDER(WINED3D_RS_ALPHABLENDENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
4876 4877
    { STATE_STREAMSRC,                                    { STATE_STREAMSRC,                                    streamsrc           }, WINED3D_GL_EXT_NONE             },
    { STATE_VDECL,                                        { STATE_VDECL,                                        vdecl_miscpart      }, WINED3D_GL_EXT_NONE             },
4878 4879
    { STATE_FRONTFACE,                                    { STATE_FRONTFACE,                                    frontface           }, WINED3D_GL_EXT_NONE             },
    { STATE_SCISSORRECT,                                  { STATE_SCISSORRECT,                                  scissorrect         }, WINED3D_GL_EXT_NONE             },
4880 4881 4882
    { STATE_POINTSPRITECOORDORIGIN,                       { STATE_POINTSPRITECOORDORIGIN,                       psorigin            }, WINED3D_GL_VERSION_2_0          },
    { STATE_POINTSPRITECOORDORIGIN,                       { STATE_POINTSPRITECOORDORIGIN,                       psorigin_w          }, WINED3D_GL_EXT_NONE             },

4883
    /* TODO: Move shader constant loading to vertex and fragment pipeline respectively, as soon as the pshader and
4884 4885
     * vshader loadings are untied from each other
     */
4886
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00),   { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00),   shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4887 4888 4889
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01),   { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10),   { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11),   { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
4890
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00),   { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00),   shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4891 4892 4893
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01),   { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10),   { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11),   { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
4894
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00),   { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00),   shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4895 4896 4897
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01),   { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10),   { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11),   { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
4898
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00),   { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00),   shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4899 4900 4901
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01),   { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10),   { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11),   { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
4902
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00),   { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00),   shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4903 4904 4905
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01),   { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10),   { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11),   { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
4906
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00),   { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00),   shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4907 4908 4909
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01),   { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10),   { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11),   { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
4910
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00),   { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00),   shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4911 4912 4913
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01),   { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10),   { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11),   { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
4914
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00),   { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00),   shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4915 4916 4917
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01),   { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10),   { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11),   { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00),   NULL                }, WINED3D_GL_EXT_NONE             },
4918
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE),  { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE),  shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4919
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE),  NULL                }, WINED3D_GL_EXT_NONE             },
4920
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE),  { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE),  shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4921
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE),  NULL                }, WINED3D_GL_EXT_NONE             },
4922
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE),  { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE),  shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4923
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE),  NULL                }, WINED3D_GL_EXT_NONE             },
4924
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE),  { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE),  shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4925
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE),  NULL                }, WINED3D_GL_EXT_NONE             },
4926
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE),  { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE),  shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4927
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE),  NULL                }, WINED3D_GL_EXT_NONE             },
4928
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE),  { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE),  shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4929
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE),  NULL                }, WINED3D_GL_EXT_NONE             },
4930
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE),  { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE),  shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4931
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE),  NULL                }, WINED3D_GL_EXT_NONE             },
4932
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE),  { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE),  shader_bumpenv      }, WINED3D_GL_EXT_NONE             },
4933
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LOFFSET), { STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE),  NULL                }, WINED3D_GL_EXT_NONE             },
4934 4935

    { STATE_VIEWPORT,                                     { STATE_VIEWPORT,                                     viewport_miscpart   }, WINED3D_GL_EXT_NONE             },
4936
    { STATE_INDEXBUFFER,                                  { STATE_INDEXBUFFER,                                  indexbuffer         }, ARB_VERTEX_BUFFER_OBJECT        },
4937
    { STATE_INDEXBUFFER,                                  { STATE_INDEXBUFFER,                                  state_nop           }, WINED3D_GL_EXT_NONE             },
4938
    { STATE_RENDER(WINED3D_RS_ANTIALIAS),                 { STATE_RENDER(WINED3D_RS_ANTIALIAS),                 state_antialias     }, WINED3D_GL_EXT_NONE             },
4939
    { STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE),        { STATE_RENDER(WINED3D_RS_TEXTUREPERSPECTIVE),        state_nop           }, WINED3D_GL_EXT_NONE             },
4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011
    { STATE_RENDER(WINED3D_RS_ZENABLE),                   { STATE_RENDER(WINED3D_RS_ZENABLE),                   state_zenable       }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAPU),                     { STATE_RENDER(WINED3D_RS_WRAPU),                     state_wrapu         }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAPV),                     { STATE_RENDER(WINED3D_RS_WRAPV),                     state_wrapv         }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_FILLMODE),                  { STATE_RENDER(WINED3D_RS_FILLMODE),                  state_fillmode      }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_LINEPATTERN),               { STATE_RENDER(WINED3D_RS_LINEPATTERN),               state_linepattern   }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_MONOENABLE),                { STATE_RENDER(WINED3D_RS_MONOENABLE),                state_monoenable    }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ROP2),                      { STATE_RENDER(WINED3D_RS_ROP2),                      state_rop2          }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_PLANEMASK),                 { STATE_RENDER(WINED3D_RS_PLANEMASK),                 state_planemask     }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ZWRITEENABLE),              { STATE_RENDER(WINED3D_RS_ZWRITEENABLE),              state_zwritenable   }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_LASTPIXEL),                 { STATE_RENDER(WINED3D_RS_LASTPIXEL),                 state_lastpixel     }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_CULLMODE),                  { STATE_RENDER(WINED3D_RS_CULLMODE),                  state_cullmode      }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ZFUNC),                     { STATE_RENDER(WINED3D_RS_ZFUNC),                     state_zfunc         }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_DITHERENABLE),              { STATE_RENDER(WINED3D_RS_DITHERENABLE),              state_ditherenable  }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_SUBPIXEL),                  { STATE_RENDER(WINED3D_RS_SUBPIXEL),                  state_subpixel      }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_SUBPIXELX),                 { STATE_RENDER(WINED3D_RS_SUBPIXELX),                 state_subpixelx     }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_STIPPLEDALPHA),             { STATE_RENDER(WINED3D_RS_STIPPLEDALPHA),             state_stippledalpha }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_STIPPLEENABLE),             { STATE_RENDER(WINED3D_RS_STIPPLEENABLE),             state_stippleenable }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS),             { STATE_RENDER(WINED3D_RS_MIPMAPLODBIAS),             state_mipmaplodbias }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ANISOTROPY),                { STATE_RENDER(WINED3D_RS_ANISOTROPY),                state_anisotropy    }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_FLUSHBATCH),                { STATE_RENDER(WINED3D_RS_FLUSHBATCH),                state_flushbatch    }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),{ STATE_RENDER(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT),state_translucentsi }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_STENCILENABLE),             { STATE_RENDER(WINED3D_RS_STENCILENABLE),             state_stencil       }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_STENCILFAIL),               { STATE_RENDER(WINED3D_RS_STENCILENABLE),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_STENCILZFAIL),              { STATE_RENDER(WINED3D_RS_STENCILENABLE),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_STENCILPASS),               { STATE_RENDER(WINED3D_RS_STENCILENABLE),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_STENCILFUNC),               { STATE_RENDER(WINED3D_RS_STENCILENABLE),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_STENCILREF),                { STATE_RENDER(WINED3D_RS_STENCILENABLE),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_STENCILMASK),               { STATE_RENDER(WINED3D_RS_STENCILENABLE),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK),          { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK),          state_stencilwrite2s}, EXT_STENCIL_TWO_SIDE            },
    { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK),          { STATE_RENDER(WINED3D_RS_STENCILWRITEMASK),          state_stencilwrite  }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_TWOSIDEDSTENCILMODE),       { STATE_RENDER(WINED3D_RS_STENCILENABLE),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_CCW_STENCILFAIL),           { STATE_RENDER(WINED3D_RS_STENCILENABLE),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_CCW_STENCILZFAIL),          { STATE_RENDER(WINED3D_RS_STENCILENABLE),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_CCW_STENCILPASS),           { STATE_RENDER(WINED3D_RS_STENCILENABLE),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_CCW_STENCILFUNC),           { STATE_RENDER(WINED3D_RS_STENCILENABLE),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP0),                     { STATE_RENDER(WINED3D_RS_WRAP0),                     state_wrap          }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP1),                     { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP2),                     { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP3),                     { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP4),                     { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP5),                     { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP6),                     { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP7),                     { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP8),                     { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP9),                     { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP10),                    { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP11),                    { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP12),                    { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP13),                    { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP14),                    { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_WRAP15),                    { STATE_RENDER(WINED3D_RS_WRAP0),                     NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_EXTENTS),                   { STATE_RENDER(WINED3D_RS_EXTENTS),                   state_extents       }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE),       { STATE_RENDER(WINED3D_RS_COLORKEYBLENDENABLE),       state_ckeyblend     }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING),  { STATE_RENDER(WINED3D_RS_SOFTWAREVERTEXPROCESSING),  state_swvp          }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE),            { STATE_RENDER(WINED3D_RS_PATCHEDGESTYLE),            state_patchedgestyle}, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_PATCHSEGMENTS),             { STATE_RENDER(WINED3D_RS_PATCHSEGMENTS),             state_patchsegments }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_POSITIONDEGREE),            { STATE_RENDER(WINED3D_RS_POSITIONDEGREE),            state_positiondegree}, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_NORMALDEGREE),              { STATE_RENDER(WINED3D_RS_NORMALDEGREE),              state_normaldegree  }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_MINTESSELLATIONLEVEL),      { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_MAXTESSELLATIONLEVEL),      { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_X),            { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Y),            { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_Z),            { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ADAPTIVETESS_W),            { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_nvdb          }, EXT_DEPTH_BOUNDS_TEST           },
    { STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),{ STATE_RENDER(WINED3D_RS_ENABLEADAPTIVETESSELLATION),state_tessellation  }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS),      { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS),      state_msaa          }, ARB_MULTISAMPLE                 },
    { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS),      { STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS),      state_msaa_w        }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK),           { STATE_RENDER(WINED3D_RS_MULTISAMPLEMASK),           state_multisampmask }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN),         { STATE_RENDER(WINED3D_RS_DEBUGMONITORTOKEN),         state_debug_monitor }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE),          { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE),          state_colorwrite0   }, EXT_DRAW_BUFFERS2               },
    { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE),          { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE),          state_colorwrite    }, WINED3D_GL_EXT_NONE             },
5012
    { STATE_RENDER(WINED3D_RS_BLENDOP),                   { STATE_RENDER(WINED3D_RS_BLENDOP),                   state_blendop       }, WINED3D_GL_BLEND_EQUATION       },
5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025
    { STATE_RENDER(WINED3D_RS_BLENDOP),                   { STATE_RENDER(WINED3D_RS_BLENDOP),                   state_blendop_w     }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE),         { STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE),         state_scissor       }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_SLOPESCALEDEPTHBIAS),       { STATE_RENDER(WINED3D_RS_DEPTHBIAS),                 NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1),         { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1),         state_colorwrite1   }, EXT_DRAW_BUFFERS2               },
    { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1),         { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2),         { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2),         state_colorwrite2   }, EXT_DRAW_BUFFERS2               },
    { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2),         { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3),         { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3),         state_colorwrite3   }, EXT_DRAW_BUFFERS2               },
    { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3),         { STATE_RENDER(WINED3D_RS_COLORWRITEENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_BLENDFACTOR),               { STATE_RENDER(WINED3D_RS_BLENDFACTOR),               state_blendfactor   }, EXT_BLEND_COLOR                 },
    { STATE_RENDER(WINED3D_RS_BLENDFACTOR),               { STATE_RENDER(WINED3D_RS_BLENDFACTOR),               state_blendfactor_w }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_DEPTHBIAS),                 { STATE_RENDER(WINED3D_RS_DEPTHBIAS),                 state_depthbias     }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ZVISIBLE),                  { STATE_RENDER(WINED3D_RS_ZVISIBLE),                  state_zvisible      }, WINED3D_GL_EXT_NONE             },
5026
    /* Samplers */
5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046
    { STATE_SAMPLER(0),                                   { STATE_SAMPLER(0),                                   sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(1),                                   { STATE_SAMPLER(1),                                   sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(2),                                   { STATE_SAMPLER(2),                                   sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(3),                                   { STATE_SAMPLER(3),                                   sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(4),                                   { STATE_SAMPLER(4),                                   sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(5),                                   { STATE_SAMPLER(5),                                   sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(6),                                   { STATE_SAMPLER(6),                                   sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(7),                                   { STATE_SAMPLER(7),                                   sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(8),                                   { STATE_SAMPLER(8),                                   sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(9),                                   { STATE_SAMPLER(9),                                   sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(10),                                  { STATE_SAMPLER(10),                                  sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(11),                                  { STATE_SAMPLER(11),                                  sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(12),                                  { STATE_SAMPLER(12),                                  sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(13),                                  { STATE_SAMPLER(13),                                  sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(14),                                  { STATE_SAMPLER(14),                                  sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(15),                                  { STATE_SAMPLER(15),                                  sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(16), /* Vertex sampler 0 */           { STATE_SAMPLER(16),                                  sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(17), /* Vertex sampler 1 */           { STATE_SAMPLER(17),                                  sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(18), /* Vertex sampler 2 */           { STATE_SAMPLER(18),                                  sampler             }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(19), /* Vertex sampler 3 */           { STATE_SAMPLER(19),                                  sampler             }, WINED3D_GL_EXT_NONE             },
5047
    { STATE_BASEVERTEXINDEX,                              { STATE_BASEVERTEXINDEX,                              state_nop,          }, ARB_DRAW_ELEMENTS_BASE_VERTEX   },
5048
    { STATE_BASEVERTEXINDEX,                              { STATE_STREAMSRC,                                    NULL,               }, WINED3D_GL_EXT_NONE             },
5049
    { STATE_FRAMEBUFFER,                                  { STATE_FRAMEBUFFER,                                  context_state_fb    }, WINED3D_GL_EXT_NONE             },
5050 5051
    { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL),            { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL),            context_state_drawbuf},WINED3D_GL_EXT_NONE             },
    { STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY),         { STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY),         state_geometry_shader}, WINED3D_GL_EXT_NONE             },
5052
    {0 /* Terminate */,                                   { 0,                                                  0                   }, WINED3D_GL_EXT_NONE             },
5053 5054
};

5055
static const struct StateEntryTemplate vp_ffp_states[] =
5056
{
5057
    { STATE_VDECL,                                        { STATE_VDECL,                                        vertexdeclaration   }, WINED3D_GL_EXT_NONE             },
5058
    { STATE_SHADER(WINED3D_SHADER_TYPE_VERTEX),           { STATE_VDECL,                                        NULL                }, WINED3D_GL_EXT_NONE             },
5059 5060
    { STATE_MATERIAL,                                     { STATE_RENDER(WINED3D_RS_SPECULARENABLE),            NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_SPECULARENABLE),            { STATE_RENDER(WINED3D_RS_SPECULARENABLE),            state_specularenable}, WINED3D_GL_EXT_NONE             },
5061
      /* Clip planes */
5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093
    { STATE_CLIPPLANE(0),                                 { STATE_CLIPPLANE(0),                                 clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(1),                                 { STATE_CLIPPLANE(1),                                 clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(2),                                 { STATE_CLIPPLANE(2),                                 clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(3),                                 { STATE_CLIPPLANE(3),                                 clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(4),                                 { STATE_CLIPPLANE(4),                                 clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(5),                                 { STATE_CLIPPLANE(5),                                 clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(6),                                 { STATE_CLIPPLANE(6),                                 clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(7),                                 { STATE_CLIPPLANE(7),                                 clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(8),                                 { STATE_CLIPPLANE(8),                                 clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(9),                                 { STATE_CLIPPLANE(9),                                 clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(10),                                { STATE_CLIPPLANE(10),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(11),                                { STATE_CLIPPLANE(11),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(12),                                { STATE_CLIPPLANE(12),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(13),                                { STATE_CLIPPLANE(13),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(14),                                { STATE_CLIPPLANE(14),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(15),                                { STATE_CLIPPLANE(15),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(16),                                { STATE_CLIPPLANE(16),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(17),                                { STATE_CLIPPLANE(17),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(18),                                { STATE_CLIPPLANE(18),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(19),                                { STATE_CLIPPLANE(19),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(20),                                { STATE_CLIPPLANE(20),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(21),                                { STATE_CLIPPLANE(21),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(22),                                { STATE_CLIPPLANE(22),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(23),                                { STATE_CLIPPLANE(23),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(24),                                { STATE_CLIPPLANE(24),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(25),                                { STATE_CLIPPLANE(25),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(26),                                { STATE_CLIPPLANE(26),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(27),                                { STATE_CLIPPLANE(27),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(28),                                { STATE_CLIPPLANE(28),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(29),                                { STATE_CLIPPLANE(29),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(30),                                { STATE_CLIPPLANE(30),                                clipplane           }, WINED3D_GL_EXT_NONE             },
    { STATE_CLIPPLANE(31),                                { STATE_CLIPPLANE(31),                                clipplane           }, WINED3D_GL_EXT_NONE             },
5094
      /* Lights */
5095
    { STATE_LIGHT_TYPE,                                   { STATE_LIGHT_TYPE,                                   state_nop           }, WINED3D_GL_EXT_NONE             },
5096 5097 5098 5099 5100 5101 5102 5103
    { STATE_ACTIVELIGHT(0),                               { STATE_ACTIVELIGHT(0),                               light               }, WINED3D_GL_EXT_NONE             },
    { STATE_ACTIVELIGHT(1),                               { STATE_ACTIVELIGHT(1),                               light               }, WINED3D_GL_EXT_NONE             },
    { STATE_ACTIVELIGHT(2),                               { STATE_ACTIVELIGHT(2),                               light               }, WINED3D_GL_EXT_NONE             },
    { STATE_ACTIVELIGHT(3),                               { STATE_ACTIVELIGHT(3),                               light               }, WINED3D_GL_EXT_NONE             },
    { STATE_ACTIVELIGHT(4),                               { STATE_ACTIVELIGHT(4),                               light               }, WINED3D_GL_EXT_NONE             },
    { STATE_ACTIVELIGHT(5),                               { STATE_ACTIVELIGHT(5),                               light               }, WINED3D_GL_EXT_NONE             },
    { STATE_ACTIVELIGHT(6),                               { STATE_ACTIVELIGHT(6),                               light               }, WINED3D_GL_EXT_NONE             },
    { STATE_ACTIVELIGHT(7),                               { STATE_ACTIVELIGHT(7),                               light               }, WINED3D_GL_EXT_NONE             },
5104
    /* Viewport */
5105
    { STATE_VIEWPORT,                                     { STATE_VIEWPORT,                                     viewport_vertexpart }, WINED3D_GL_EXT_NONE             },
5106
      /* Transform states follow                    */
5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372
    { STATE_TRANSFORM(WINED3D_TS_VIEW),                   { STATE_TRANSFORM(WINED3D_TS_VIEW),                   transform_view      }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_PROJECTION),             { STATE_TRANSFORM(WINED3D_TS_PROJECTION),             transform_projection}, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_TEXTURE0),               { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL            }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_TEXTURE1),               { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL            }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_TEXTURE2),               { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL            }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_TEXTURE3),               { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL            }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_TEXTURE4),               { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL            }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_TEXTURE5),               { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL            }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_TEXTURE6),               { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL            }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_TEXTURE7),               { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), NULL            }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  0)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  0)),      transform_world     }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  1)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  1)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  2)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  2)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  3)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  3)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  4)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  4)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  5)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  5)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  6)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  6)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  7)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  7)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  8)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  8)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  9)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(  9)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 10)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 10)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 11)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 11)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 12)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 12)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 13)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 13)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 14)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 14)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 15)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 15)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 16)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 16)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 17)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 17)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 18)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 18)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 19)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 19)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 20)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 20)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 21)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 21)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 22)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 22)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 23)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 23)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 24)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 24)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 25)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 25)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 26)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 26)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 27)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 27)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 28)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 28)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 29)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 29)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 30)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 30)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 31)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 31)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 32)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 32)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 33)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 33)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 34)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 34)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 35)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 35)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 36)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 36)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 37)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 37)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 38)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 38)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 39)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 39)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 40)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 40)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 41)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 41)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 42)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 42)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 43)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 43)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 44)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 44)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 45)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 45)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 46)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 46)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 47)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 47)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 48)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 48)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 49)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 49)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 50)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 50)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 51)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 51)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 52)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 52)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 53)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 53)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 54)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 54)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 55)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 55)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 56)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 56)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 57)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 57)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 58)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 58)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 59)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 59)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 60)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 60)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 61)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 61)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 62)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 62)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 63)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 63)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 64)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 64)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 65)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 65)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 66)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 66)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 67)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 67)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 68)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 68)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 69)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 69)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 70)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 70)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 71)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 71)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 72)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 72)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 73)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 73)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 74)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 74)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 75)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 75)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 76)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 76)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 77)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 77)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 78)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 78)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 79)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 79)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 80)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 80)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 81)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 81)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 82)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 82)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 83)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 83)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 84)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 84)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 85)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 85)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 86)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 86)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 87)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 87)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 88)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 88)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 89)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 89)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 90)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 90)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 91)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 91)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 92)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 92)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 93)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 93)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 94)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 94)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 95)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 95)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 96)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 96)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 97)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 97)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 98)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 98)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 99)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX( 99)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(100)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(100)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(101)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(101)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(102)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(102)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(103)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(103)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(104)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(104)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(105)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(105)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(106)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(106)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(107)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(107)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(108)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(108)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(109)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(109)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(110)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(110)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(111)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(111)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(112)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(112)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(113)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(113)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(114)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(114)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(115)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(115)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(116)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(116)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(117)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(117)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(118)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(118)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(119)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(119)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(120)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(120)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(121)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(121)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(122)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(122)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(123)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(123)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(124)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(124)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(125)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(125)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(126)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(126)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(127)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(127)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(128)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(128)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(129)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(129)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(130)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(130)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(131)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(131)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(132)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(132)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(133)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(133)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(134)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(134)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(135)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(135)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(136)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(136)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(137)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(137)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(138)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(138)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(139)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(139)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(140)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(140)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(141)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(141)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(142)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(142)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(143)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(143)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(144)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(144)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(145)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(145)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(146)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(146)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(147)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(147)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(148)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(148)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(149)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(149)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(150)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(150)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(151)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(151)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(152)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(152)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(153)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(153)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(154)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(154)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(155)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(155)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(156)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(156)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(157)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(157)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(158)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(158)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(159)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(159)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(160)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(160)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(161)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(161)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(162)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(162)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(163)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(163)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(164)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(164)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(165)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(165)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(166)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(166)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(167)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(167)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(168)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(168)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(169)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(169)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(170)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(170)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(171)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(171)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(172)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(172)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(173)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(173)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(174)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(174)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(175)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(175)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(176)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(176)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(177)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(177)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(178)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(178)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(179)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(179)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(180)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(180)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(181)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(181)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(182)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(182)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(183)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(183)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(184)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(184)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(185)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(185)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(186)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(186)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(187)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(187)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(188)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(188)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(189)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(189)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(190)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(190)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(191)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(191)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(192)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(192)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(193)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(193)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(194)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(194)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(195)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(195)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(196)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(196)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(197)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(197)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(198)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(198)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(199)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(199)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(200)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(200)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(201)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(201)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(202)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(202)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(203)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(203)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(204)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(204)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(205)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(205)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(206)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(206)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(207)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(207)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(208)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(208)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(209)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(209)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(210)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(210)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(211)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(211)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(212)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(212)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(213)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(213)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(214)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(214)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(215)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(215)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(216)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(216)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(217)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(217)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(218)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(218)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(219)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(219)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(220)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(220)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(221)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(221)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(222)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(222)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(223)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(223)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(224)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(224)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(225)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(225)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(226)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(226)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(227)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(227)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(228)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(228)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(229)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(229)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(230)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(230)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(231)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(231)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(232)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(232)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(233)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(233)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(234)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(234)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(235)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(235)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(236)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(236)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(237)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(237)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(238)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(238)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(239)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(239)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(240)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(240)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(241)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(241)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(242)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(242)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(243)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(243)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(244)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(244)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(245)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(245)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(246)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(246)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(247)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(247)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(248)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(248)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(249)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(249)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(250)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(250)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(251)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(251)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(252)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(252)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(253)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(253)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(254)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(254)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
    { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)),      { STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)),      transform_worldex   }, WINED3D_GL_EXT_NONE             },
5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture   }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture   }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture   }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture   }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture   }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture   }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture   }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), {STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS), transform_texture   }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXCOORD_INDEX),  { STATE_TEXTURESTAGE(0, WINED3D_TSS_TEXCOORD_INDEX),  tex_coordindex      }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXCOORD_INDEX),  { STATE_TEXTURESTAGE(1, WINED3D_TSS_TEXCOORD_INDEX),  tex_coordindex      }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXCOORD_INDEX),  { STATE_TEXTURESTAGE(2, WINED3D_TSS_TEXCOORD_INDEX),  tex_coordindex      }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXCOORD_INDEX),  { STATE_TEXTURESTAGE(3, WINED3D_TSS_TEXCOORD_INDEX),  tex_coordindex      }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXCOORD_INDEX),  { STATE_TEXTURESTAGE(4, WINED3D_TSS_TEXCOORD_INDEX),  tex_coordindex      }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXCOORD_INDEX),  { STATE_TEXTURESTAGE(5, WINED3D_TSS_TEXCOORD_INDEX),  tex_coordindex      }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXCOORD_INDEX),  { STATE_TEXTURESTAGE(6, WINED3D_TSS_TEXCOORD_INDEX),  tex_coordindex      }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXCOORD_INDEX),  { STATE_TEXTURESTAGE(7, WINED3D_TSS_TEXCOORD_INDEX),  tex_coordindex      }, WINED3D_GL_EXT_NONE             },
5389
      /* Fog */
5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421
    { STATE_RENDER(WINED3D_RS_FOGENABLE),                 { STATE_RENDER(WINED3D_RS_FOGENABLE),                 state_fog_vertexpart}, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_FOGTABLEMODE),              { STATE_RENDER(WINED3D_RS_FOGENABLE),                 NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE),             { STATE_RENDER(WINED3D_RS_FOGENABLE),                 NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_RANGEFOGENABLE),            { STATE_RENDER(WINED3D_RS_FOGENABLE),                 NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_CLIPPING),                  { STATE_RENDER(WINED3D_RS_CLIPPING),                  state_clipping      }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_CLIPPLANEENABLE),           { STATE_RENDER(WINED3D_RS_CLIPPING),                  NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_LIGHTING),                  { STATE_RENDER(WINED3D_RS_LIGHTING),                  state_lighting      }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_AMBIENT),                   { STATE_RENDER(WINED3D_RS_AMBIENT),                   state_ambient       }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_COLORVERTEX),               { STATE_RENDER(WINED3D_RS_COLORVERTEX),               state_colormat      }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_LOCALVIEWER),               { STATE_RENDER(WINED3D_RS_LOCALVIEWER),               state_localviewer   }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_NORMALIZENORMALS),          { STATE_RENDER(WINED3D_RS_NORMALIZENORMALS),          state_normalize     }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_DIFFUSEMATERIALSOURCE),     { STATE_RENDER(WINED3D_RS_COLORVERTEX),               NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_SPECULARMATERIALSOURCE),    { STATE_RENDER(WINED3D_RS_COLORVERTEX),               NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_AMBIENTMATERIALSOURCE),     { STATE_RENDER(WINED3D_RS_COLORVERTEX),               NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_EMISSIVEMATERIALSOURCE),    { STATE_RENDER(WINED3D_RS_COLORVERTEX),               NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_VERTEXBLEND),               { STATE_RENDER(WINED3D_RS_VERTEXBLEND),               state_vertexblend   }, ARB_VERTEX_BLEND                },
    { STATE_RENDER(WINED3D_RS_VERTEXBLEND),               { STATE_RENDER(WINED3D_RS_VERTEXBLEND),               state_vertexblend_w }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_POINTSIZE),                 { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN),             { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN),             state_psizemin_arb  }, ARB_POINT_PARAMETERS            },
    { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN),             { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN),             state_psizemin_ext  }, EXT_POINT_PARAMETERS            },
    { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN),             { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN),             state_psizemin_w    }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE),         { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE),         state_pointsprite   }, ARB_POINT_SPRITE                },
    { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE),         { STATE_RENDER(WINED3D_RS_POINTSPRITEENABLE),         state_pointsprite_w }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE),          { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE),          state_pscale        }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_POINTSCALE_A),              { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_POINTSCALE_B),              { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_POINTSCALE_C),              { STATE_RENDER(WINED3D_RS_POINTSCALEENABLE),          NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX),             { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN),             NULL                }, ARB_POINT_PARAMETERS            },
    { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX),             { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN),             NULL                }, EXT_POINT_PARAMETERS            },
    { STATE_RENDER(WINED3D_RS_POINTSIZE_MAX),             { STATE_RENDER(WINED3D_RS_POINTSIZE_MIN),             NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_TWEENFACTOR),               { STATE_RENDER(WINED3D_RS_VERTEXBLEND),               NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_INDEXEDVERTEXBLENDENABLE),  { STATE_RENDER(WINED3D_RS_VERTEXBLEND),               NULL                }, WINED3D_GL_EXT_NONE             },
5422

5423 5424 5425 5426 5427
    /* Samplers for NP2 texture matrix adjustions. They are not needed if GL_ARB_texture_non_power_of_two is supported,
     * so register a NULL state handler in that case to get the vertex part of sampler() skipped(VTF is handled in the misc states.
     * otherwise, register sampler_texmatrix, which takes care of updating the texture matrix
     */
    { STATE_SAMPLER(0),                                   { 0,                                                  NULL                }, ARB_TEXTURE_NON_POWER_OF_TWO    },
5428
    { STATE_SAMPLER(0),                                   { 0,                                                  NULL                }, WINED3D_GL_NORMALIZED_TEXRECT   },
5429
    { STATE_SAMPLER(0),                                   { STATE_SAMPLER(0),                                   sampler_texmatrix   }, WINED3D_GL_EXT_NONE             },
5430
    { STATE_SAMPLER(1),                                   { 0,                                                  NULL                }, ARB_TEXTURE_NON_POWER_OF_TWO    },
5431
    { STATE_SAMPLER(1),                                   { 0,                                                  NULL                }, WINED3D_GL_NORMALIZED_TEXRECT   },
5432
    { STATE_SAMPLER(1),                                   { STATE_SAMPLER(1),                                   sampler_texmatrix   }, WINED3D_GL_EXT_NONE             },
5433
    { STATE_SAMPLER(2),                                   { 0,                                                  NULL                }, ARB_TEXTURE_NON_POWER_OF_TWO    },
5434
    { STATE_SAMPLER(2),                                   { 0,                                                  NULL                }, WINED3D_GL_NORMALIZED_TEXRECT   },
5435
    { STATE_SAMPLER(2),                                   { STATE_SAMPLER(2),                                   sampler_texmatrix   }, WINED3D_GL_EXT_NONE             },
5436
    { STATE_SAMPLER(3),                                   { 0,                                                  NULL                }, ARB_TEXTURE_NON_POWER_OF_TWO    },
5437
    { STATE_SAMPLER(3),                                   { 0,                                                  NULL                }, WINED3D_GL_NORMALIZED_TEXRECT   },
5438
    { STATE_SAMPLER(3),                                   { STATE_SAMPLER(3),                                   sampler_texmatrix   }, WINED3D_GL_EXT_NONE             },
5439
    { STATE_SAMPLER(4),                                   { 0,                                                  NULL                }, ARB_TEXTURE_NON_POWER_OF_TWO    },
5440
    { STATE_SAMPLER(4),                                   { 0,                                                  NULL                }, WINED3D_GL_NORMALIZED_TEXRECT   },
5441
    { STATE_SAMPLER(4),                                   { STATE_SAMPLER(4),                                   sampler_texmatrix   }, WINED3D_GL_EXT_NONE             },
5442
    { STATE_SAMPLER(5),                                   { 0,                                                  NULL                }, ARB_TEXTURE_NON_POWER_OF_TWO    },
5443
    { STATE_SAMPLER(5),                                   { 0,                                                  NULL                }, WINED3D_GL_NORMALIZED_TEXRECT   },
5444
    { STATE_SAMPLER(5),                                   { STATE_SAMPLER(5),                                   sampler_texmatrix   }, WINED3D_GL_EXT_NONE             },
5445
    { STATE_SAMPLER(6),                                   { 0,                                                  NULL                }, ARB_TEXTURE_NON_POWER_OF_TWO    },
5446
    { STATE_SAMPLER(6),                                   { 0,                                                  NULL                }, WINED3D_GL_NORMALIZED_TEXRECT   },
5447
    { STATE_SAMPLER(6),                                   { STATE_SAMPLER(6),                                   sampler_texmatrix   }, WINED3D_GL_EXT_NONE             },
5448
    { STATE_SAMPLER(7),                                   { 0,                                                  NULL                }, ARB_TEXTURE_NON_POWER_OF_TWO    },
5449
    { STATE_SAMPLER(7),                                   { 0,                                                  NULL                }, WINED3D_GL_NORMALIZED_TEXRECT   },
5450
    { STATE_SAMPLER(7),                                   { STATE_SAMPLER(7),                                   sampler_texmatrix   }, WINED3D_GL_EXT_NONE             },
5451
    { STATE_POINT_ENABLE,                                 { STATE_POINT_ENABLE,                                 state_nop           }, WINED3D_GL_EXT_NONE             },
5452
    {0 /* Terminate */,                                   { 0,                                                  0                   }, WINED3D_GL_EXT_NONE             },
5453 5454
};

5455
static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP),        { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP),        tex_colorop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG1),      { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG2),      { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP),        { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP),        tex_alphaop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG1),      { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG2),      { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_ARG0),      { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_ARG0),      { STATE_TEXTURESTAGE(0, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_RESULT_ARG),      { STATE_TEXTURESTAGE(0, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(0, WINED3D_TSS_CONSTANT),        { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP),        { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP),        tex_colorop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG1),      { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG2),      { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP),        { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP),        tex_alphaop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG1),      { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG2),      { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_ARG0),      { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_ARG0),      { STATE_TEXTURESTAGE(1, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_RESULT_ARG),      { STATE_TEXTURESTAGE(1, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(1, WINED3D_TSS_CONSTANT),        { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP),        { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP),        tex_colorop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG1),      { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG2),      { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP),        { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP),        tex_alphaop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG1),      { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG2),      { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_ARG0),      { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_ARG0),      { STATE_TEXTURESTAGE(2, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_RESULT_ARG),      { STATE_TEXTURESTAGE(2, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(2, WINED3D_TSS_CONSTANT),        { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP),        { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP),        tex_colorop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG1),      { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG2),      { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP),        { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP),        tex_alphaop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG1),      { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG2),      { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_ARG0),      { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_ARG0),      { STATE_TEXTURESTAGE(3, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_RESULT_ARG),      { STATE_TEXTURESTAGE(3, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(3, WINED3D_TSS_CONSTANT),        { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP),        { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP),        tex_colorop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG1),      { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG2),      { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP),        { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP),        tex_alphaop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG1),      { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG2),      { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_ARG0),      { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_ARG0),      { STATE_TEXTURESTAGE(4, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_RESULT_ARG),      { STATE_TEXTURESTAGE(4, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(4, WINED3D_TSS_CONSTANT),        { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP),        { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP),        tex_colorop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG1),      { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG2),      { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP),        { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP),        tex_alphaop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG1),      { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG2),      { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_ARG0),      { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_ARG0),      { STATE_TEXTURESTAGE(5, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_RESULT_ARG),      { STATE_TEXTURESTAGE(5, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(5, WINED3D_TSS_CONSTANT),        { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP),        { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP),        tex_colorop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG1),      { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG2),      { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP),        { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP),        tex_alphaop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG1),      { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG2),      { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_ARG0),      { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_ARG0),      { STATE_TEXTURESTAGE(6, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_RESULT_ARG),      { STATE_TEXTURESTAGE(6, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(6, WINED3D_TSS_CONSTANT),        { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP),        { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP),        tex_colorop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG1),      { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG2),      { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP),        { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP),        tex_alphaop         }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG1),      { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG2),      { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_ARG0),      { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_ARG0),      { STATE_TEXTURESTAGE(7, WINED3D_TSS_ALPHA_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_RESULT_ARG),      { STATE_TEXTURESTAGE(7, WINED3D_TSS_COLOR_OP),        NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_TEXTURESTAGE(7, WINED3D_TSS_CONSTANT),        { 0 /* As long as we don't support D3DTA_CONSTANT */, NULL                }, WINED3D_GL_EXT_NONE             },
5536
    { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL),            { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL),            apply_pixelshader   }, WINED3D_GL_EXT_NONE             },
5537 5538 5539 5540
    { STATE_RENDER(WINED3D_RS_ALPHAFUNC),                 { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE),           NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ALPHAREF),                  { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE),           NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE),           { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE),           state_alpha_test    }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_COLORKEYENABLE),            { STATE_RENDER(WINED3D_RS_ALPHATESTENABLE),           NULL                }, WINED3D_GL_EXT_NONE             },
5541
    { STATE_COLOR_KEY,                                    { STATE_COLOR_KEY,                                    state_nop           }, WINED3D_GL_EXT_NONE             },
5542
    { STATE_RENDER(WINED3D_RS_SRGBWRITEENABLE),           { STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL),            NULL                }, WINED3D_GL_EXT_NONE             },
5543 5544 5545 5546 5547 5548 5549 5550
    { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR),             { STATE_RENDER(WINED3D_RS_TEXTUREFACTOR),             state_texfactor     }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_FOGCOLOR),                  { STATE_RENDER(WINED3D_RS_FOGCOLOR),                  state_fogcolor      }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_FOGDENSITY),                { STATE_RENDER(WINED3D_RS_FOGDENSITY),                state_fogdensity    }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_FOGENABLE),                 { STATE_RENDER(WINED3D_RS_FOGENABLE),                 state_fog_fragpart  }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_FOGTABLEMODE),              { STATE_RENDER(WINED3D_RS_FOGENABLE),                 NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_FOGVERTEXMODE),             { STATE_RENDER(WINED3D_RS_FOGENABLE),                 NULL                }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_FOGSTART),                  { STATE_RENDER(WINED3D_RS_FOGSTART),                  state_fogstartend   }, WINED3D_GL_EXT_NONE             },
    { STATE_RENDER(WINED3D_RS_FOGEND),                    { STATE_RENDER(WINED3D_RS_FOGSTART),                  NULL                }, WINED3D_GL_EXT_NONE             },
5551
    { STATE_RENDER(WINED3D_RS_SHADEMODE),                 { STATE_RENDER(WINED3D_RS_SHADEMODE),                 state_shademode     }, WINED3D_GL_EXT_NONE             },
5552 5553 5554 5555 5556 5557 5558 5559 5560
    { STATE_SAMPLER(0),                                   { STATE_SAMPLER(0),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(1),                                   { STATE_SAMPLER(1),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(2),                                   { STATE_SAMPLER(2),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(3),                                   { STATE_SAMPLER(3),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(4),                                   { STATE_SAMPLER(4),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(5),                                   { STATE_SAMPLER(5),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(6),                                   { STATE_SAMPLER(6),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
    { STATE_SAMPLER(7),                                   { STATE_SAMPLER(7),                                   sampler_texdim      }, WINED3D_GL_EXT_NONE             },
    {0 /* Terminate */,                                   { 0,                                                  0                   }, WINED3D_GL_EXT_NONE             },
5561
};
5562

5563
/* Context activation is done by the caller. */
5564
static void ffp_enable(const struct wined3d_gl_info *gl_info, BOOL enable) {}
5565

5566 5567 5568 5569 5570 5571 5572 5573 5574
static void *ffp_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
{
    return shader_priv;
}

static void ffp_free(struct wined3d_device *device) {}

static void vp_ffp_get_caps(const struct wined3d_gl_info *gl_info, struct wined3d_vertex_caps *caps)
{
5575
    caps->xyzrhw = FALSE;
5576
    caps->ffp_generic_attributes = FALSE;
5577 5578 5579 5580 5581 5582 5583 5584
    caps->max_active_lights = gl_info->limits.lights;
    caps->max_vertex_blend_matrices = gl_info->limits.blends;
    caps->max_vertex_blend_matrix_index = 0;
    caps->vertex_processing_caps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS
            | WINED3DVTXPCAPS_MATERIALSOURCE7
            | WINED3DVTXPCAPS_POSITIONALLIGHTS
            | WINED3DVTXPCAPS_LOCALVIEWER
            | WINED3DVTXPCAPS_VERTEXFOG
5585 5586
            | WINED3DVTXPCAPS_TEXGEN
            | WINED3DVTXPCAPS_TEXGEN_SPHEREMAP;
5587 5588 5589 5590 5591 5592 5593
    caps->fvf_caps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
    caps->max_user_clip_planes = gl_info->limits.clipplanes;
    caps->raster_caps = 0;
    if (gl_info->supported[NV_FOG_DISTANCE])
        caps->raster_caps |= WINED3DPRASTERCAPS_FOGRANGE;
}

5594 5595 5596 5597 5598
static DWORD vp_ffp_get_emul_mask(const struct wined3d_gl_info *gl_info)
{
    return GL_EXT_EMUL_ARB_MULTITEXTURE | GL_EXT_EMUL_EXT_FOG_COORD;
}

5599 5600 5601 5602
const struct wined3d_vertex_pipe_ops ffp_vertex_pipe =
{
    ffp_enable,
    vp_ffp_get_caps,
5603
    vp_ffp_get_emul_mask,
5604 5605 5606 5607 5608
    ffp_alloc,
    ffp_free,
    vp_ffp_states,
};

5609
static void ffp_fragment_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
5610
{
5611
    caps->wined3d_caps = 0;
5612 5613 5614 5615 5616 5617 5618 5619 5620 5621
    caps->PrimitiveMiscCaps = 0;
    caps->TextureOpCaps = WINED3DTEXOPCAPS_ADD
            | WINED3DTEXOPCAPS_ADDSIGNED
            | WINED3DTEXOPCAPS_ADDSIGNED2X
            | WINED3DTEXOPCAPS_MODULATE
            | WINED3DTEXOPCAPS_MODULATE2X
            | WINED3DTEXOPCAPS_MODULATE4X
            | WINED3DTEXOPCAPS_SELECTARG1
            | WINED3DTEXOPCAPS_SELECTARG2
            | WINED3DTEXOPCAPS_DISABLE;
5622

5623 5624 5625 5626
    if (gl_info->supported[ARB_TEXTURE_ENV_COMBINE]
            || gl_info->supported[EXT_TEXTURE_ENV_COMBINE]
            || gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
    {
5627 5628 5629 5630 5631 5632
        caps->TextureOpCaps |= WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA
                | WINED3DTEXOPCAPS_BLENDTEXTUREALPHA
                | WINED3DTEXOPCAPS_BLENDFACTORALPHA
                | WINED3DTEXOPCAPS_BLENDCURRENTALPHA
                | WINED3DTEXOPCAPS_LERP
                | WINED3DTEXOPCAPS_SUBTRACT;
5633
    }
5634 5635 5636
    if (gl_info->supported[ATI_TEXTURE_ENV_COMBINE3]
            || gl_info->supported[NV_TEXTURE_ENV_COMBINE4])
    {
5637 5638 5639 5640 5641
        caps->TextureOpCaps |= WINED3DTEXOPCAPS_ADDSMOOTH
                | WINED3DTEXOPCAPS_MULTIPLYADD
                | WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
                | WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
                | WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM;
5642
    }
5643
    if (gl_info->supported[ARB_TEXTURE_ENV_DOT3])
5644
        caps->TextureOpCaps |= WINED3DTEXOPCAPS_DOTPRODUCT3;
5645

5646 5647
    caps->MaxTextureBlendStages = gl_info->limits.textures;
    caps->MaxSimultaneousTextures = gl_info->limits.textures;
5648 5649
}

5650 5651 5652 5653 5654
static DWORD ffp_fragment_get_emul_mask(const struct wined3d_gl_info *gl_info)
{
    return GL_EXT_EMUL_ARB_MULTITEXTURE | GL_EXT_EMUL_EXT_FOG_COORD;
}

5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670
static BOOL ffp_color_fixup_supported(struct color_fixup_desc fixup)
{
    if (TRACE_ON(d3d))
    {
        TRACE("Checking support for fixup:\n");
        dump_color_fixup_desc(fixup);
    }

    /* We only support identity conversions. */
    if (is_identity_fixup(fixup))
    {
        TRACE("[OK]\n");
        return TRUE;
    }

    TRACE("[FAILED]\n");
5671 5672
    return FALSE;
}
5673

5674 5675 5676 5677 5678 5679 5680 5681 5682
static BOOL ffp_none_context_alloc(struct wined3d_context *context)
{
    return TRUE;
}

static void ffp_none_context_free(struct wined3d_context *context)
{
}

5683
const struct fragment_pipeline ffp_fragment_pipeline = {
5684
    ffp_enable,
5685
    ffp_fragment_get_caps,
5686
    ffp_fragment_get_emul_mask,
5687 5688
    ffp_alloc,
    ffp_free,
5689 5690
    ffp_none_context_alloc,
    ffp_none_context_free,
5691
    ffp_color_fixup_supported,
5692
    ffp_fragmentstate_template,
5693
};
5694

5695
static void none_enable(const struct wined3d_gl_info *gl_info, BOOL enable) {}
5696

5697
static void *none_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
5698
{
5699
    return shader_priv;
5700 5701
}

5702 5703 5704
static void none_free(struct wined3d_device *device) {}

static void vp_none_get_caps(const struct wined3d_gl_info *gl_info, struct wined3d_vertex_caps *caps)
5705
{
5706
    memset(caps, 0, sizeof(*caps));
5707 5708
}

5709 5710 5711 5712 5713
static DWORD vp_none_get_emul_mask(const struct wined3d_gl_info *gl_info)
{
    return 0;
}

5714 5715 5716 5717
const struct wined3d_vertex_pipe_ops none_vertex_pipe =
{
    none_enable,
    vp_none_get_caps,
5718
    vp_none_get_emul_mask,
5719 5720 5721 5722 5723 5724 5725 5726 5727
    none_alloc,
    none_free,
    NULL,
};

static void fp_none_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
{
    memset(caps, 0, sizeof(*caps));
}
5728

5729 5730 5731 5732 5733
static DWORD fp_none_get_emul_mask(const struct wined3d_gl_info *gl_info)
{
    return 0;
}

5734 5735 5736 5737 5738 5739 5740
static BOOL fp_none_color_fixup_supported(struct color_fixup_desc fixup)
{
    return is_identity_fixup(fixup);
}

const struct fragment_pipeline none_fragment_pipe =
{
5741
    none_enable,
5742
    fp_none_get_caps,
5743
    fp_none_get_emul_mask,
5744 5745
    none_alloc,
    none_free,
5746 5747
    ffp_none_context_alloc,
    ffp_none_context_free,
5748 5749 5750 5751
    fp_none_color_fixup_supported,
    NULL,
};

5752 5753
static unsigned int num_handlers(const APPLYSTATEFUNC *funcs)
{
5754 5755 5756 5757 5758
    unsigned int i;
    for(i = 0; funcs[i]; i++);
    return i;
}

5759
static void multistate_apply_2(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
5760
{
5761 5762
    context->swapchain->device->multistate_funcs[state_id][0](context, state, state_id);
    context->swapchain->device->multistate_funcs[state_id][1](context, state, state_id);
5763 5764
}

5765
static void multistate_apply_3(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
5766
{
5767 5768 5769
    context->swapchain->device->multistate_funcs[state_id][0](context, state, state_id);
    context->swapchain->device->multistate_funcs[state_id][1](context, state, state_id);
    context->swapchain->device->multistate_funcs[state_id][2](context, state, state_id);
5770 5771
}

5772 5773
static void prune_invalid_states(struct StateEntry *state_table, const struct wined3d_gl_info *gl_info,
        const struct wined3d_d3d_info *d3d_info)
5774 5775 5776
{
    unsigned int start, last, i;

5777
    start = STATE_TEXTURESTAGE(d3d_info->limits.ffp_blend_stages, 0);
5778 5779 5780 5781 5782 5783 5784
    last = STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE);
    for (i = start; i <= last; ++i)
    {
        state_table[i].representative = 0;
        state_table[i].apply = state_undefined;
    }

5785
    start = STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + d3d_info->limits.ffp_blend_stages);
5786
    last = STATE_TRANSFORM(WINED3D_TS_TEXTURE0 + MAX_TEXTURES - 1);
5787 5788 5789 5790 5791
    for (i = start; i <= last; ++i)
    {
        state_table[i].representative = 0;
        state_table[i].apply = state_undefined;
    }
5792

5793
    start = STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(d3d_info->limits.ffp_vertex_blend_matrices));
5794
    last = STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255));
5795 5796 5797 5798 5799
    for (i = start; i <= last; ++i)
    {
        state_table[i].representative = 0;
        state_table[i].apply = state_undefined;
    }
5800 5801
}

5802 5803
static void validate_state_table(struct StateEntry *state_table)
{
5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815
    static const struct
    {
        DWORD first;
        DWORD last;
    }
    rs_holes[] =
    {
        {  1,   1},
        {  3,   3},
        { 17,  18},
        { 21,  21},
        { 42,  45},
5816
        { 47,  47},
5817 5818 5819 5820 5821 5822 5823
        { 61, 127},
        {149, 150},
        {169, 169},
        {177, 177},
        {196, 197},
        {  0,   0},
    };
5824 5825 5826 5827 5828 5829
    static const DWORD simple_states[] =
    {
        STATE_MATERIAL,
        STATE_VDECL,
        STATE_STREAMSRC,
        STATE_INDEXBUFFER,
5830 5831 5832
        STATE_SHADER(WINED3D_SHADER_TYPE_VERTEX),
        STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY),
        STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL),
5833 5834 5835
        STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX),
        STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY),
        STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL),
5836
        STATE_SHADER_RESOURCE_BINDING,
5837
        STATE_VIEWPORT,
5838
        STATE_LIGHT_TYPE,
5839 5840
        STATE_SCISSORRECT,
        STATE_FRONTFACE,
5841
        STATE_POINTSPRITECOORDORIGIN,
5842
        STATE_BASEVERTEXINDEX,
5843
        STATE_FRAMEBUFFER,
5844
        STATE_POINT_ENABLE,
5845
        STATE_COLOR_KEY,
5846
    };
5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860
    unsigned int i, current;

    for (i = STATE_RENDER(1), current = 0; i <= STATE_RENDER(WINEHIGHEST_RENDER_STATE); ++i)
    {
        if (!rs_holes[current].first || i < STATE_RENDER(rs_holes[current].first))
        {
            if (!state_table[i].representative)
                ERR("State %s (%#x) should have a representative.\n", debug_d3dstate(i), i);
        }
        else if (state_table[i].representative)
            ERR("State %s (%#x) shouldn't have a representative.\n", debug_d3dstate(i), i);

        if (i == STATE_RENDER(rs_holes[current].last)) ++current;
    }
5861

5862 5863 5864 5865 5866 5867 5868
    for (i = 0; i < sizeof(simple_states) / sizeof(*simple_states); ++i)
    {
        if (!state_table[simple_states[i]].representative)
            ERR("State %s (%#x) should have a representative.\n",
                    debug_d3dstate(simple_states[i]), simple_states[i]);
    }

5869 5870 5871
    for (i = 0; i < STATE_HIGHEST + 1; ++i)
    {
        DWORD rep = state_table[i].representative;
5872
        if (rep)
5873
        {
5874
            if (state_table[rep].representative != rep)
5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889
            {
                ERR("State %s (%#x) has invalid representative %s (%#x).\n",
                        debug_d3dstate(i), i, debug_d3dstate(rep), rep);
                state_table[i].representative = 0;
            }

            if (rep != i)
            {
                if (state_table[i].apply)
                    ERR("State %s (%#x) has both a handler and representative.\n", debug_d3dstate(i), i);
            }
            else if (!state_table[i].apply)
            {
                ERR("Self representing state %s (%#x) has no handler.\n", debug_d3dstate(i), i);
            }
5890 5891 5892 5893
        }
    }
}

5894
HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
5895 5896 5897
        const struct wined3d_gl_info *gl_info, const struct wined3d_d3d_info *d3d_info,
        const struct wined3d_vertex_pipe_ops *vertex, const struct fragment_pipeline *fragment,
        const struct StateEntryTemplate *misc)
5898
{
5899 5900 5901
    unsigned int i, type, handlers;
    APPLYSTATEFUNC multistate_funcs[STATE_HIGHEST + 1][3];
    const struct StateEntryTemplate *cur;
5902
    BOOL set[STATE_HIGHEST + 1];
5903 5904 5905

    memset(multistate_funcs, 0, sizeof(multistate_funcs));

5906 5907 5908 5909 5910
    for(i = 0; i < STATE_HIGHEST + 1; i++) {
        StateTable[i].representative = 0;
        StateTable[i].apply = state_undefined;
    }

5911 5912 5913 5914
    for(type = 0; type < 3; type++) {
        /* This switch decides the order in which the states are applied */
        switch(type) {
            case 0: cur = misc; break;
5915
            case 1: cur = fragment->states; break;
5916
            case 2: cur = vertex->vp_states; break;
5917 5918 5919 5920
            default: cur = NULL; /* Stupid compiler */
        }
        if(!cur) continue;

5921 5922 5923 5924 5925
        /* GL extension filtering should not prevent multiple handlers being applied from different
         * pipeline parts
         */
        memset(set, 0, sizeof(set));

5926
        for(i = 0; cur[i].state; i++) {
5927
            APPLYSTATEFUNC *funcs_array;
5928 5929 5930 5931 5932 5933 5934 5935 5936 5937

            /* Only use the first matching state with the available extension from one template.
             * e.g.
             * {D3DRS_FOOBAR, {D3DRS_FOOBAR, func1}, XYZ_FANCY},
             * {D3DRS_FOOBAR, {D3DRS_FOOBAR, func2}, 0        }
             *
             * if GL_XYZ_fancy is supported, ignore the 2nd line
             */
            if(set[cur[i].state]) continue;
            /* Skip state lines depending on unsupported extensions */
5938
            if (!gl_info->supported[cur[i].extension]) continue;
5939 5940 5941 5942 5943 5944 5945 5946
            set[cur[i].state] = TRUE;
            /* In some cases having an extension means that nothing has to be
             * done for a state, e.g. if GL_ARB_texture_non_power_of_two is
             * supported, the texture coordinate fixup can be ignored. If the
             * apply function is used, mark the state set(done above) to prevent
             * applying later lines, but do not record anything in the state
             * table
             */
5947
            if (!cur[i].content.representative) continue;
5948

5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959
            handlers = num_handlers(multistate_funcs[cur[i].state]);
            multistate_funcs[cur[i].state][handlers] = cur[i].content.apply;
            switch(handlers) {
                case 0:
                    StateTable[cur[i].state].apply = cur[i].content.apply;
                    break;
                case 1:
                    StateTable[cur[i].state].apply = multistate_apply_2;
                    dev_multistate_funcs[cur[i].state] = HeapAlloc(GetProcessHeap(),
                                                                   0,
                                                                   sizeof(**dev_multistate_funcs) * 2);
5960 5961 5962 5963
                    if (!dev_multistate_funcs[cur[i].state]) {
                        goto out_of_mem;
                    }

5964 5965 5966 5967 5968
                    dev_multistate_funcs[cur[i].state][0] = multistate_funcs[cur[i].state][0];
                    dev_multistate_funcs[cur[i].state][1] = multistate_funcs[cur[i].state][1];
                    break;
                case 2:
                    StateTable[cur[i].state].apply = multistate_apply_3;
5969 5970 5971 5972 5973 5974 5975 5976 5977
                    funcs_array = HeapReAlloc(GetProcessHeap(),
                                              0,
                                              dev_multistate_funcs[cur[i].state],
                                              sizeof(**dev_multistate_funcs) * 3);
                    if (!funcs_array) {
                        goto out_of_mem;
                    }

                    dev_multistate_funcs[cur[i].state] = funcs_array;
5978 5979 5980 5981 5982 5983 5984
                    dev_multistate_funcs[cur[i].state][2] = multistate_funcs[cur[i].state][2];
                    break;
                default:
                    ERR("Unexpected amount of state handlers for state %u: %u\n",
                        cur[i].state, handlers + 1);
            }

5985 5986 5987 5988 5989
            if (StateTable[cur[i].state].representative
                    && StateTable[cur[i].state].representative != cur[i].content.representative)
            {
                FIXME("State %s (%#x) has different representatives in different pipeline parts.\n",
                        debug_d3dstate(cur[i].state), cur[i].state);
5990 5991 5992 5993
            }
            StateTable[cur[i].state].representative = cur[i].content.representative;
        }
    }
5994

5995
    prune_invalid_states(StateTable, gl_info, d3d_info);
5996 5997
    validate_state_table(StateTable);

5998 5999 6000 6001 6002 6003 6004 6005 6006 6007
    return WINED3D_OK;

out_of_mem:
    for (i = 0; i <= STATE_HIGHEST; ++i) {
        HeapFree(GetProcessHeap(), 0, dev_multistate_funcs[i]);
    }

    memset(dev_multistate_funcs, 0, (STATE_HIGHEST + 1)*sizeof(*dev_multistate_funcs));

    return E_OUTOFMEMORY;
6008
}