ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

wined3d_private.h
Go to the documentation of this file.
00001 /*
00002  * Direct3D wine internal private include file
00003  *
00004  * Copyright 2002-2003 The wine-d3d team
00005  * Copyright 2002-2003 Raphael Junqueira
00006  * Copyright 2002-2003, 2004 Jason Edmeades
00007  * Copyright 2005 Oliver Stieber
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00022  */
00023 
00024 #ifndef __WINE_WINED3D_PRIVATE_H
00025 #define __WINE_WINED3D_PRIVATE_H
00026 
00027 #include <stdarg.h>
00028 #include <math.h>
00029 #include <limits.h>
00030 #define NONAMELESSUNION
00031 #define NONAMELESSSTRUCT
00032 #define COBJMACROS
00033 #include "windef.h"
00034 #include "winbase.h"
00035 #include "winreg.h"
00036 #include "wingdi.h"
00037 #include "winuser.h"
00038 #include "wine/debug.h"
00039 #include "wine/unicode.h"
00040 
00041 #include "objbase.h"
00042 #include "wine/wined3d.h"
00043 #include "wined3d_gl.h"
00044 #include "wine/list.h"
00045 #include "wine/rbtree.h"
00046 
00047 /* Driver quirks */
00048 #define WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT       0x00000001
00049 #define WINED3D_QUIRK_SET_TEXCOORD_W            0x00000002
00050 #define WINED3D_QUIRK_GLSL_CLIP_VARYING         0x00000004
00051 #define WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA     0x00000008
00052 #define WINED3D_QUIRK_NV_CLIP_BROKEN            0x00000010
00053 #define WINED3D_QUIRK_FBO_TEX_UPDATE            0x00000020
00054 #define WINED3D_QUIRK_BROKEN_RGBA16             0x00000040
00055 #define WINED3D_QUIRK_INFO_LOG_SPAM             0x00000080
00056 #define WINED3D_QUIRK_LIMITED_TEX_FILTERING     0x00000100
00057 
00058 /* Texture format fixups */
00059 
00060 enum fixup_channel_source
00061 {
00062     CHANNEL_SOURCE_ZERO = 0,
00063     CHANNEL_SOURCE_ONE = 1,
00064     CHANNEL_SOURCE_X = 2,
00065     CHANNEL_SOURCE_Y = 3,
00066     CHANNEL_SOURCE_Z = 4,
00067     CHANNEL_SOURCE_W = 5,
00068     CHANNEL_SOURCE_COMPLEX0 = 6,
00069     CHANNEL_SOURCE_COMPLEX1 = 7,
00070 };
00071 
00072 enum complex_fixup
00073 {
00074     COMPLEX_FIXUP_NONE = 0,
00075     COMPLEX_FIXUP_YUY2 = 1,
00076     COMPLEX_FIXUP_UYVY = 2,
00077     COMPLEX_FIXUP_YV12 = 3,
00078     COMPLEX_FIXUP_P8   = 4,
00079 };
00080 
00081 #include <pshpack2.h>
00082 struct color_fixup_desc
00083 {
00084     unsigned x_sign_fixup : 1;
00085     unsigned x_source : 3;
00086     unsigned y_sign_fixup : 1;
00087     unsigned y_source : 3;
00088     unsigned z_sign_fixup : 1;
00089     unsigned z_source : 3;
00090     unsigned w_sign_fixup : 1;
00091     unsigned w_source : 3;
00092 };
00093 #include <poppack.h>
00094 
00095 static const struct color_fixup_desc COLOR_FIXUP_IDENTITY =
00096         {0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W};
00097 
00098 static inline struct color_fixup_desc create_color_fixup_desc(
00099         int sign0, enum fixup_channel_source src0, int sign1, enum fixup_channel_source src1,
00100         int sign2, enum fixup_channel_source src2, int sign3, enum fixup_channel_source src3)
00101 {
00102     struct color_fixup_desc fixup =
00103     {
00104         sign0, src0,
00105         sign1, src1,
00106         sign2, src2,
00107         sign3, src3,
00108     };
00109     return fixup;
00110 }
00111 
00112 static inline struct color_fixup_desc create_complex_fixup_desc(enum complex_fixup complex_fixup)
00113 {
00114     struct color_fixup_desc fixup =
00115     {
00116         0, complex_fixup & (1 << 0) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
00117         0, complex_fixup & (1 << 1) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
00118         0, complex_fixup & (1 << 2) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
00119         0, complex_fixup & (1 << 3) ? CHANNEL_SOURCE_COMPLEX1 : CHANNEL_SOURCE_COMPLEX0,
00120     };
00121     return fixup;
00122 }
00123 
00124 static inline BOOL is_identity_fixup(struct color_fixup_desc fixup)
00125 {
00126     return !memcmp(&fixup, &COLOR_FIXUP_IDENTITY, sizeof(fixup));
00127 }
00128 
00129 static inline BOOL is_complex_fixup(struct color_fixup_desc fixup)
00130 {
00131     return fixup.x_source == CHANNEL_SOURCE_COMPLEX0 || fixup.x_source == CHANNEL_SOURCE_COMPLEX1;
00132 }
00133 
00134 static inline enum complex_fixup get_complex_fixup(struct color_fixup_desc fixup)
00135 {
00136     enum complex_fixup complex_fixup = 0;
00137     if (fixup.x_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1 << 0);
00138     if (fixup.y_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1 << 1);
00139     if (fixup.z_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1 << 2);
00140     if (fixup.w_source == CHANNEL_SOURCE_COMPLEX1) complex_fixup |= (1 << 3);
00141     return complex_fixup;
00142 }
00143 
00144 void *wined3d_rb_alloc(size_t size) DECLSPEC_HIDDEN;
00145 void *wined3d_rb_realloc(void *ptr, size_t size) DECLSPEC_HIDDEN;
00146 void wined3d_rb_free(void *ptr) DECLSPEC_HIDDEN;
00147 
00148 /* Device caps */
00149 #define MAX_PALETTES            65536
00150 #define MAX_STREAMS             16
00151 #define MAX_TEXTURES            8
00152 #define MAX_FRAGMENT_SAMPLERS   16
00153 #define MAX_VERTEX_SAMPLERS     4
00154 #define MAX_COMBINED_SAMPLERS   (MAX_FRAGMENT_SAMPLERS + MAX_VERTEX_SAMPLERS)
00155 #define MAX_ACTIVE_LIGHTS       8
00156 #define MAX_CLIPPLANES          WINED3DMAXUSERCLIPPLANES
00157 
00158 struct min_lookup
00159 {
00160     GLenum mip[WINED3D_TEXF_LINEAR + 1];
00161 };
00162 
00163 extern const struct min_lookup minMipLookup[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
00164 extern const struct min_lookup minMipLookup_noFilter[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
00165 extern const struct min_lookup minMipLookup_noMip[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
00166 extern const GLenum magLookup[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
00167 extern const GLenum magLookup_noFilter[WINED3D_TEXF_LINEAR + 1] DECLSPEC_HIDDEN;
00168 
00169 static inline GLenum wined3d_gl_mag_filter(const GLenum mag_lookup[], enum wined3d_texture_filter_type mag_filter)
00170 {
00171     return mag_lookup[mag_filter];
00172 }
00173 
00174 static inline GLenum wined3d_gl_min_mip_filter(const struct min_lookup min_mip_lookup[],
00175         enum wined3d_texture_filter_type min_filter, enum wined3d_texture_filter_type mip_filter)
00176 {
00177     return min_mip_lookup[min_filter].mip[mip_filter];
00178 }
00179 
00180 /* float_16_to_32() and float_32_to_16() (see implementation in
00181  * surface_base.c) convert 16 bit floats in the FLOAT16 data type
00182  * to standard C floats and vice versa. They do not depend on the encoding
00183  * of the C float, so they are platform independent, but slow. On x86 and
00184  * other IEEE 754 compliant platforms the conversion can be accelerated by
00185  * bit shifting the exponent and mantissa. There are also some SSE-based
00186  * assembly routines out there.
00187  *
00188  * See GL_NV_half_float for a reference of the FLOAT16 / GL_HALF format
00189  */
00190 static inline float float_16_to_32(const unsigned short *in) {
00191     const unsigned short s = ((*in) & 0x8000);
00192     const unsigned short e = ((*in) & 0x7C00) >> 10;
00193     const unsigned short m = (*in) & 0x3FF;
00194     const float sgn = (s ? -1.0f : 1.0f);
00195 
00196     if(e == 0) {
00197         if(m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
00198         else return sgn * powf(2, -14.0f) * ((float)m / 1024.0f);
00199     } else if(e < 31) {
00200         return sgn * powf(2, (float)e - 15.0f) * (1.0f + ((float)m / 1024.0f));
00201     } else {
00202         if(m == 0) return sgn * INFINITY; /* +INF / -INF */
00203         else return NAN; /* NAN */
00204     }
00205 }
00206 
00207 static inline float float_24_to_32(DWORD in)
00208 {
00209     const float sgn = in & 0x800000 ? -1.0f : 1.0f;
00210     const unsigned short e = (in & 0x780000) >> 19;
00211     const unsigned int m = in & 0x7ffff;
00212 
00213     if (e == 0)
00214     {
00215         if (m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
00216         else return sgn * powf(2, -6.0f) * ((float)m / 524288.0f);
00217     }
00218     else if (e < 15)
00219     {
00220         return sgn * powf(2, (float)e - 7.0f) * (1.0f + ((float)m / 524288.0f));
00221     }
00222     else
00223     {
00224         if (m == 0) return sgn * INFINITY; /* +INF / -INF */
00225         else return NAN; /* NAN */
00226     }
00227 }
00228 
00232 #define VS_NONE    0
00233 #define VS_HW      1
00234 
00235 #define PS_NONE    0
00236 #define PS_HW      1
00237 
00238 #define VBO_NONE   0
00239 #define VBO_HW     1
00240 
00241 #define ORM_BACKBUFFER  0
00242 #define ORM_FBO         1
00243 
00244 #define SHADER_ARB  1
00245 #define SHADER_GLSL 2
00246 #define SHADER_ATI  3
00247 #define SHADER_NONE 4
00248 
00249 #define RTL_READDRAW   1
00250 #define RTL_READTEX    2
00251 
00252 #define PCI_VENDOR_NONE 0xffff /* e.g. 0x8086 for Intel and 0x10de for Nvidia */
00253 #define PCI_DEVICE_NONE 0xffff /* e.g. 0x14f for a Geforce6200 */
00254 
00255 /* NOTE: When adding fields to this structure, make sure to update the default
00256  * values in wined3d_main.c as well. */
00257 struct wined3d_settings
00258 {
00259     /* vertex and pixel shader modes */
00260     int vs_mode;
00261     int ps_mode;
00262     /* Ideally, we don't want the user to have to request GLSL. If the
00263      * hardware supports GLSL, we should use it. However, until it's fully
00264      * implemented, we'll leave it as a registry setting for developers. */
00265     BOOL glslRequested;
00266     int offscreen_rendering_mode;
00267     int rendertargetlock_mode;
00268     unsigned short pci_vendor_id;
00269     unsigned short pci_device_id;
00270     /* Memory tracking and object counting. */
00271     unsigned int emulated_textureram;
00272     char *logo;
00273     int allow_multisampling;
00274     BOOL strict_draw_ordering;
00275     BOOL always_offscreen;
00276 };
00277 
00278 extern struct wined3d_settings wined3d_settings DECLSPEC_HIDDEN;
00279 
00280 enum wined3d_sampler_texture_type
00281 {
00282     WINED3DSTT_UNKNOWN = 0,
00283     WINED3DSTT_1D = 1,
00284     WINED3DSTT_2D = 2,
00285     WINED3DSTT_CUBE = 3,
00286     WINED3DSTT_VOLUME = 4,
00287 };
00288 
00289 enum wined3d_shader_register_type
00290 {
00291     WINED3DSPR_TEMP = 0,
00292     WINED3DSPR_INPUT = 1,
00293     WINED3DSPR_CONST = 2,
00294     WINED3DSPR_ADDR = 3,
00295     WINED3DSPR_TEXTURE = 3,
00296     WINED3DSPR_RASTOUT = 4,
00297     WINED3DSPR_ATTROUT = 5,
00298     WINED3DSPR_TEXCRDOUT = 6,
00299     WINED3DSPR_OUTPUT = 6,
00300     WINED3DSPR_CONSTINT = 7,
00301     WINED3DSPR_COLOROUT = 8,
00302     WINED3DSPR_DEPTHOUT = 9,
00303     WINED3DSPR_SAMPLER = 10,
00304     WINED3DSPR_CONST2 = 11,
00305     WINED3DSPR_CONST3 = 12,
00306     WINED3DSPR_CONST4 = 13,
00307     WINED3DSPR_CONSTBOOL = 14,
00308     WINED3DSPR_LOOP = 15,
00309     WINED3DSPR_TEMPFLOAT16 = 16,
00310     WINED3DSPR_MISCTYPE = 17,
00311     WINED3DSPR_LABEL = 18,
00312     WINED3DSPR_PREDICATE = 19,
00313     WINED3DSPR_IMMCONST,
00314     WINED3DSPR_CONSTBUFFER,
00315     WINED3DSPR_NULL,
00316     WINED3DSPR_RESOURCE,
00317 };
00318 
00319 enum wined3d_immconst_type
00320 {
00321     WINED3D_IMMCONST_SCALAR,
00322     WINED3D_IMMCONST_VEC4,
00323 };
00324 
00325 #define WINED3DSP_NOSWIZZLE (0 | (1 << 2) | (2 << 4) | (3 << 6))
00326 
00327 enum wined3d_shader_src_modifier
00328 {
00329     WINED3DSPSM_NONE = 0,
00330     WINED3DSPSM_NEG = 1,
00331     WINED3DSPSM_BIAS = 2,
00332     WINED3DSPSM_BIASNEG = 3,
00333     WINED3DSPSM_SIGN = 4,
00334     WINED3DSPSM_SIGNNEG = 5,
00335     WINED3DSPSM_COMP = 6,
00336     WINED3DSPSM_X2 = 7,
00337     WINED3DSPSM_X2NEG = 8,
00338     WINED3DSPSM_DZ = 9,
00339     WINED3DSPSM_DW = 10,
00340     WINED3DSPSM_ABS = 11,
00341     WINED3DSPSM_ABSNEG = 12,
00342     WINED3DSPSM_NOT = 13,
00343 };
00344 
00345 #define WINED3DSP_WRITEMASK_0   0x1 /* .x r */
00346 #define WINED3DSP_WRITEMASK_1   0x2 /* .y g */
00347 #define WINED3DSP_WRITEMASK_2   0x4 /* .z b */
00348 #define WINED3DSP_WRITEMASK_3   0x8 /* .w a */
00349 #define WINED3DSP_WRITEMASK_ALL 0xf /* all */
00350 
00351 enum wined3d_shader_dst_modifier
00352 {
00353     WINED3DSPDM_NONE = 0,
00354     WINED3DSPDM_SATURATE = 1,
00355     WINED3DSPDM_PARTIALPRECISION = 2,
00356     WINED3DSPDM_MSAMPCENTROID = 4,
00357 };
00358 
00359 /* Undocumented opcode control to identify projective texture lookups in ps 2.0 and later */
00360 #define WINED3DSI_TEXLD_PROJECT 1
00361 #define WINED3DSI_TEXLD_BIAS    2
00362 
00363 enum wined3d_shader_rel_op
00364 {
00365     WINED3D_SHADER_REL_OP_GT = 1,
00366     WINED3D_SHADER_REL_OP_EQ = 2,
00367     WINED3D_SHADER_REL_OP_GE = 3,
00368     WINED3D_SHADER_REL_OP_LT = 4,
00369     WINED3D_SHADER_REL_OP_NE = 5,
00370     WINED3D_SHADER_REL_OP_LE = 6,
00371 };
00372 
00373 #define WINED3D_SM1_VS  0xfffe
00374 #define WINED3D_SM1_PS  0xffff
00375 #define WINED3D_SM4_PS  0x0000
00376 #define WINED3D_SM4_VS  0x0001
00377 #define WINED3D_SM4_GS  0x0002
00378 
00379 /* Shader version tokens, and shader end tokens */
00380 #define WINED3DPS_VERSION(major, minor) ((WINED3D_SM1_PS << 16) | ((major) << 8) | (minor))
00381 #define WINED3DVS_VERSION(major, minor) ((WINED3D_SM1_VS << 16) | ((major) << 8) | (minor))
00382 
00383 /* Shader backends */
00384 
00385 /* TODO: Make this dynamic, based on shader limits ? */
00386 #define MAX_ATTRIBS 16
00387 #define MAX_REG_ADDR 1
00388 #define MAX_REG_TEMP 32
00389 #define MAX_REG_TEXCRD 8
00390 #define MAX_REG_INPUT 12
00391 #define MAX_REG_OUTPUT 12
00392 #define MAX_CONST_I 16
00393 #define MAX_CONST_B 16
00394 
00395 /* FIXME: This needs to go up to 2048 for
00396  * Shader model 3 according to msdn (and for software shaders) */
00397 #define MAX_LABELS 16
00398 
00399 #define SHADER_PGMSIZE 65535
00400 
00401 struct wined3d_shader_buffer
00402 {
00403     char *buffer;
00404     unsigned int bsize;
00405     unsigned int lineNo;
00406     BOOL newline;
00407 };
00408 
00409 enum WINED3D_SHADER_INSTRUCTION_HANDLER
00410 {
00411     WINED3DSIH_ABS,
00412     WINED3DSIH_ADD,
00413     WINED3DSIH_AND,
00414     WINED3DSIH_BEM,
00415     WINED3DSIH_BREAK,
00416     WINED3DSIH_BREAKC,
00417     WINED3DSIH_BREAKP,
00418     WINED3DSIH_CALL,
00419     WINED3DSIH_CALLNZ,
00420     WINED3DSIH_CMP,
00421     WINED3DSIH_CND,
00422     WINED3DSIH_CRS,
00423     WINED3DSIH_CUT,
00424     WINED3DSIH_DCL,
00425     WINED3DSIH_DEF,
00426     WINED3DSIH_DEFB,
00427     WINED3DSIH_DEFI,
00428     WINED3DSIH_DIV,
00429     WINED3DSIH_DP2ADD,
00430     WINED3DSIH_DP3,
00431     WINED3DSIH_DP4,
00432     WINED3DSIH_DST,
00433     WINED3DSIH_DSX,
00434     WINED3DSIH_DSY,
00435     WINED3DSIH_ELSE,
00436     WINED3DSIH_EMIT,
00437     WINED3DSIH_ENDIF,
00438     WINED3DSIH_ENDLOOP,
00439     WINED3DSIH_ENDREP,
00440     WINED3DSIH_EQ,
00441     WINED3DSIH_EXP,
00442     WINED3DSIH_EXPP,
00443     WINED3DSIH_FRC,
00444     WINED3DSIH_FTOI,
00445     WINED3DSIH_GE,
00446     WINED3DSIH_IADD,
00447     WINED3DSIH_IEQ,
00448     WINED3DSIH_IF,
00449     WINED3DSIH_IFC,
00450     WINED3DSIH_IGE,
00451     WINED3DSIH_IMUL,
00452     WINED3DSIH_ITOF,
00453     WINED3DSIH_LABEL,
00454     WINED3DSIH_LD,
00455     WINED3DSIH_LIT,
00456     WINED3DSIH_LOG,
00457     WINED3DSIH_LOGP,
00458     WINED3DSIH_LOOP,
00459     WINED3DSIH_LRP,
00460     WINED3DSIH_LT,
00461     WINED3DSIH_M3x2,
00462     WINED3DSIH_M3x3,
00463     WINED3DSIH_M3x4,
00464     WINED3DSIH_M4x3,
00465     WINED3DSIH_M4x4,
00466     WINED3DSIH_MAD,
00467     WINED3DSIH_MAX,
00468     WINED3DSIH_MIN,
00469     WINED3DSIH_MOV,
00470     WINED3DSIH_MOVA,
00471     WINED3DSIH_MOVC,
00472     WINED3DSIH_MUL,
00473     WINED3DSIH_NOP,
00474     WINED3DSIH_NRM,
00475     WINED3DSIH_PHASE,
00476     WINED3DSIH_POW,
00477     WINED3DSIH_RCP,
00478     WINED3DSIH_REP,
00479     WINED3DSIH_RET,
00480     WINED3DSIH_ROUND_NI,
00481     WINED3DSIH_RSQ,
00482     WINED3DSIH_SAMPLE,
00483     WINED3DSIH_SAMPLE_GRAD,
00484     WINED3DSIH_SAMPLE_LOD,
00485     WINED3DSIH_SETP,
00486     WINED3DSIH_SGE,
00487     WINED3DSIH_SGN,
00488     WINED3DSIH_SINCOS,
00489     WINED3DSIH_SLT,
00490     WINED3DSIH_SQRT,
00491     WINED3DSIH_SUB,
00492     WINED3DSIH_TEX,
00493     WINED3DSIH_TEXBEM,
00494     WINED3DSIH_TEXBEML,
00495     WINED3DSIH_TEXCOORD,
00496     WINED3DSIH_TEXDEPTH,
00497     WINED3DSIH_TEXDP3,
00498     WINED3DSIH_TEXDP3TEX,
00499     WINED3DSIH_TEXKILL,
00500     WINED3DSIH_TEXLDD,
00501     WINED3DSIH_TEXLDL,
00502     WINED3DSIH_TEXM3x2DEPTH,
00503     WINED3DSIH_TEXM3x2PAD,
00504     WINED3DSIH_TEXM3x2TEX,
00505     WINED3DSIH_TEXM3x3,
00506     WINED3DSIH_TEXM3x3DIFF,
00507     WINED3DSIH_TEXM3x3PAD,
00508     WINED3DSIH_TEXM3x3SPEC,
00509     WINED3DSIH_TEXM3x3TEX,
00510     WINED3DSIH_TEXM3x3VSPEC,
00511     WINED3DSIH_TEXREG2AR,
00512     WINED3DSIH_TEXREG2GB,
00513     WINED3DSIH_TEXREG2RGB,
00514     WINED3DSIH_UDIV,
00515     WINED3DSIH_USHR,
00516     WINED3DSIH_UTOF,
00517     WINED3DSIH_XOR,
00518     WINED3DSIH_TABLE_SIZE
00519 };
00520 
00521 enum wined3d_shader_type
00522 {
00523     WINED3D_SHADER_TYPE_PIXEL,
00524     WINED3D_SHADER_TYPE_VERTEX,
00525     WINED3D_SHADER_TYPE_GEOMETRY,
00526 };
00527 
00528 struct wined3d_shader_version
00529 {
00530     enum wined3d_shader_type type;
00531     BYTE major;
00532     BYTE minor;
00533 };
00534 
00535 #define WINED3D_SHADER_VERSION(major, minor) (((major) << 8) | (minor))
00536 
00537 struct wined3d_shader_reg_maps
00538 {
00539     struct wined3d_shader_version shader_version;
00540     BYTE texcoord;                          /* MAX_REG_TEXCRD, 8 */
00541     BYTE address;                           /* MAX_REG_ADDR, 1 */
00542     WORD labels;                            /* MAX_LABELS, 16 */
00543     DWORD temporary;                        /* MAX_REG_TEMP, 32 */
00544     DWORD *constf;                          /* pixel, vertex */
00545     DWORD texcoord_mask[MAX_REG_TEXCRD];    /* vertex < 3.0 */
00546     WORD input_registers;                   /* max(MAX_REG_INPUT, MAX_ATTRIBS), 16 */
00547     WORD output_registers;                  /* MAX_REG_OUTPUT, 12 */
00548     WORD integer_constants;                 /* MAX_CONST_I, 16 */
00549     WORD boolean_constants;                 /* MAX_CONST_B, 16 */
00550     WORD local_int_consts;                  /* MAX_CONST_I, 16 */
00551     WORD local_bool_consts;                 /* MAX_CONST_B, 16 */
00552 
00553     enum wined3d_sampler_texture_type sampler_type[max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS)];
00554     BYTE bumpmat;                           /* MAX_TEXTURES, 8 */
00555     BYTE luminanceparams;                   /* MAX_TEXTURES, 8 */
00556 
00557     WORD usesnrm        : 1;
00558     WORD vpos           : 1;
00559     WORD usesdsx        : 1;
00560     WORD usesdsy        : 1;
00561     WORD usestexldd     : 1;
00562     WORD usesmova       : 1;
00563     WORD usesfacing     : 1;
00564     WORD usesrelconstF  : 1;
00565     WORD fog            : 1;
00566     WORD usestexldl     : 1;
00567     WORD usesifc        : 1;
00568     WORD usescall       : 1;
00569     WORD usespow        : 1;
00570     WORD padding        : 3;
00571 
00572     DWORD rt_mask; /* Used render targets, 32 max. */
00573 
00574     /* Whether or not loops are used in this shader, and nesting depth */
00575     unsigned loop_depth;
00576     UINT min_rel_offset, max_rel_offset;
00577 };
00578 
00579 /* Keeps track of details for TEX_M#x# instructions which need to maintain
00580  * state information between multiple instructions. */
00581 struct wined3d_shader_tex_mx
00582 {
00583     unsigned int current_row;
00584     DWORD texcoord_w[2];
00585 };
00586 
00587 struct wined3d_shader_loop_state
00588 {
00589     UINT current_depth;
00590     UINT current_reg;
00591 };
00592 
00593 struct wined3d_shader_context
00594 {
00595     const struct wined3d_shader *shader;
00596     const struct wined3d_gl_info *gl_info;
00597     const struct wined3d_shader_reg_maps *reg_maps;
00598     struct wined3d_shader_buffer *buffer;
00599     struct wined3d_shader_tex_mx *tex_mx;
00600     struct wined3d_shader_loop_state *loop_state;
00601     void *backend_data;
00602 };
00603 
00604 struct wined3d_shader_register
00605 {
00606     enum wined3d_shader_register_type type;
00607     UINT idx;
00608     UINT array_idx;
00609     const struct wined3d_shader_src_param *rel_addr;
00610     enum wined3d_immconst_type immconst_type;
00611     DWORD immconst_data[4];
00612 };
00613 
00614 struct wined3d_shader_dst_param
00615 {
00616     struct wined3d_shader_register reg;
00617     DWORD write_mask;
00618     DWORD modifiers;
00619     DWORD shift;
00620 };
00621 
00622 struct wined3d_shader_src_param
00623 {
00624     struct wined3d_shader_register reg;
00625     DWORD swizzle;
00626     enum wined3d_shader_src_modifier modifiers;
00627 };
00628 
00629 struct wined3d_shader_instruction
00630 {
00631     const struct wined3d_shader_context *ctx;
00632     enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx;
00633     DWORD flags;
00634     BOOL coissue;
00635     DWORD predicate;
00636     UINT dst_count;
00637     const struct wined3d_shader_dst_param *dst;
00638     UINT src_count;
00639     const struct wined3d_shader_src_param *src;
00640 };
00641 
00642 struct wined3d_shader_semantic
00643 {
00644     WINED3DDECLUSAGE usage;
00645     UINT usage_idx;
00646     enum wined3d_sampler_texture_type sampler_type;
00647     struct wined3d_shader_dst_param reg;
00648 };
00649 
00650 struct wined3d_shader_attribute
00651 {
00652     WINED3DDECLUSAGE usage;
00653     UINT usage_idx;
00654 };
00655 
00656 struct wined3d_shader_loop_control
00657 {
00658     unsigned int count;
00659     unsigned int start;
00660     int step;
00661 };
00662 
00663 struct wined3d_shader_frontend
00664 {
00665     void *(*shader_init)(const DWORD *ptr, const struct wined3d_shader_signature *output_signature);
00666     void (*shader_free)(void *data);
00667     void (*shader_read_header)(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version);
00668     void (*shader_read_opcode)(void *data, const DWORD **ptr, struct wined3d_shader_instruction *ins, UINT *param_size);
00669     void (*shader_read_src_param)(void *data, const DWORD **ptr, struct wined3d_shader_src_param *src_param,
00670             struct wined3d_shader_src_param *src_rel_addr);
00671     void (*shader_read_dst_param)(void *data, const DWORD **ptr, struct wined3d_shader_dst_param *dst_param,
00672             struct wined3d_shader_src_param *dst_rel_addr);
00673     void (*shader_read_semantic)(const DWORD **ptr, struct wined3d_shader_semantic *semantic);
00674     void (*shader_read_comment)(const DWORD **ptr, const char **comment, UINT *comment_size);
00675     BOOL (*shader_is_end)(void *data, const DWORD **ptr);
00676 };
00677 
00678 extern const struct wined3d_shader_frontend sm1_shader_frontend DECLSPEC_HIDDEN;
00679 extern const struct wined3d_shader_frontend sm4_shader_frontend DECLSPEC_HIDDEN;
00680 
00681 typedef void (*SHADER_HANDLER)(const struct wined3d_shader_instruction *);
00682 
00683 struct shader_caps {
00684     DWORD               VertexShaderVersion;
00685     DWORD               MaxVertexShaderConst;
00686 
00687     DWORD               PixelShaderVersion;
00688     float               PixelShader1xMaxValue;
00689     DWORD               MaxPixelShaderConst;
00690 
00691     BOOL                VSClipping;
00692 };
00693 
00694 enum tex_types
00695 {
00696     tex_1d       = 0,
00697     tex_2d       = 1,
00698     tex_3d       = 2,
00699     tex_cube     = 3,
00700     tex_rect     = 4,
00701     tex_type_count = 5,
00702 };
00703 
00704 enum vertexprocessing_mode {
00705     fixedfunction,
00706     vertexshader,
00707     pretransformed
00708 };
00709 
00710 #define WINED3D_CONST_NUM_UNUSED ~0U
00711 
00712 enum fogmode {
00713     FOG_OFF,
00714     FOG_LINEAR,
00715     FOG_EXP,
00716     FOG_EXP2
00717 };
00718 
00719 /* Stateblock dependent parameters which have to be hardcoded
00720  * into the shader code
00721  */
00722 
00723 #define WINED3D_PSARGS_PROJECTED (1 << 3)
00724 #define WINED3D_PSARGS_TEXTRANSFORM_SHIFT 4
00725 #define WINED3D_PSARGS_TEXTRANSFORM_MASK 0xf
00726 
00727 struct ps_compile_args {
00728     struct color_fixup_desc     color_fixup[MAX_FRAGMENT_SAMPLERS];
00729     enum vertexprocessing_mode  vp_mode;
00730     enum fogmode                fog;
00731     WORD                        tex_transform; /* ps 1.0-1.3, 4 textures */
00732     /* Texture types(2D, Cube, 3D) in ps 1.x */
00733     WORD                        srgb_correction;
00734     WORD                        np2_fixup;
00735     /* Bitmap for NP2 texcoord fixups (16 samplers max currently).
00736        D3D9 has a limit of 16 samplers and the fixup is superfluous
00737        in D3D10 (unconditional NP2 support mandatory). */
00738     WORD shadow; /* MAX_FRAGMENT_SAMPLERS, 16 */
00739 };
00740 
00741 enum fog_src_type {
00742     VS_FOG_Z        = 0,
00743     VS_FOG_COORD    = 1
00744 };
00745 
00746 struct vs_compile_args {
00747     BYTE                        fog_src;
00748     BYTE                        clip_enabled;
00749     WORD                        swizzle_map;   /* MAX_ATTRIBS, 16 */
00750 };
00751 
00752 struct wined3d_context;
00753 struct wined3d_state;
00754 
00755 struct wined3d_shader_backend_ops
00756 {
00757     void (*shader_handle_instruction)(const struct wined3d_shader_instruction *);
00758     void (*shader_select)(const struct wined3d_context *context, BOOL usePS, BOOL useVS);
00759     void (*shader_select_depth_blt)(void *shader_priv, const struct wined3d_gl_info *gl_info,
00760             enum tex_types tex_type, const SIZE *ds_mask_size);
00761     void (*shader_deselect_depth_blt)(void *shader_priv, const struct wined3d_gl_info *gl_info);
00762     void (*shader_update_float_vertex_constants)(struct wined3d_device *device, UINT start, UINT count);
00763     void (*shader_update_float_pixel_constants)(struct wined3d_device *device, UINT start, UINT count);
00764     void (*shader_load_constants)(const struct wined3d_context *context, char usePS, char useVS);
00765     void (*shader_load_np2fixup_constants)(void *shader_priv, const struct wined3d_gl_info *gl_info,
00766             const struct wined3d_state *state);
00767     void (*shader_destroy)(struct wined3d_shader *shader);
00768     HRESULT (*shader_alloc_private)(struct wined3d_device *device);
00769     void (*shader_free_private)(struct wined3d_device *device);
00770     void (*shader_context_destroyed)(void *shader_priv, const struct wined3d_context *context);
00771     void (*shader_get_caps)(const struct wined3d_gl_info *gl_info, struct shader_caps *caps);
00772     BOOL (*shader_color_fixup_supported)(struct color_fixup_desc fixup);
00773 };
00774 
00775 extern const struct wined3d_shader_backend_ops glsl_shader_backend DECLSPEC_HIDDEN;
00776 extern const struct wined3d_shader_backend_ops arb_program_shader_backend DECLSPEC_HIDDEN;
00777 extern const struct wined3d_shader_backend_ops none_shader_backend DECLSPEC_HIDDEN;
00778 
00779 /* X11 locking */
00780 
00781 extern void (CDECL *wine_tsx11_lock_ptr)(void) DECLSPEC_HIDDEN;
00782 extern void (CDECL *wine_tsx11_unlock_ptr)(void) DECLSPEC_HIDDEN;
00783 
00784 /* As GLX relies on X, this is needed */
00785 extern int num_lock DECLSPEC_HIDDEN;
00786 
00787 #if 0
00788 #define ENTER_GL() ++num_lock; if (num_lock > 1) FIXME("Recursive use of GL lock to: %d\n", num_lock); wine_tsx11_lock_ptr()
00789 #define LEAVE_GL() if (num_lock != 1) FIXME("Recursive use of GL lock: %d\n", num_lock); --num_lock; wine_tsx11_unlock_ptr()
00790 #else
00791 #define ENTER_GL() wine_tsx11_lock_ptr()
00792 #define LEAVE_GL() wine_tsx11_unlock_ptr()
00793 #endif
00794 
00795 /*****************************************************************************
00796  * Defines
00797  */
00798 
00799 /* GL related defines */
00800 /* ------------------ */
00801 #define GL_EXTCALL(f) (gl_info->f)
00802 
00803 #define D3DCOLOR_B_R(dw) (((dw) >> 16) & 0xFF)
00804 #define D3DCOLOR_B_G(dw) (((dw) >>  8) & 0xFF)
00805 #define D3DCOLOR_B_B(dw) (((dw) >>  0) & 0xFF)
00806 #define D3DCOLOR_B_A(dw) (((dw) >> 24) & 0xFF)
00807 
00808 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
00809 #define D3DCOLOR_G(dw) (((float) (((dw) >>  8) & 0xFF)) / 255.0f)
00810 #define D3DCOLOR_B(dw) (((float) (((dw) >>  0) & 0xFF)) / 255.0f)
00811 #define D3DCOLOR_A(dw) (((float) (((dw) >> 24) & 0xFF)) / 255.0f)
00812 
00813 #define D3DCOLORTOGLFLOAT4(dw, vec) do { \
00814   (vec)[0] = D3DCOLOR_R(dw); \
00815   (vec)[1] = D3DCOLOR_G(dw); \
00816   (vec)[2] = D3DCOLOR_B(dw); \
00817   (vec)[3] = D3DCOLOR_A(dw); \
00818 } while(0)
00819 
00820 #define HIGHEST_TRANSFORMSTATE WINED3D_TS_WORLD_MATRIX(255) /* Highest value in wined3d_transform_state. */
00821 
00822 /* Checking of API calls */
00823 /* --------------------- */
00824 #ifndef WINE_NO_DEBUG_MSGS
00825 #define checkGLcall(A)                                              \
00826 do {                                                                \
00827     GLint err;                                                      \
00828     if (!__WINE_IS_DEBUG_ON(_ERR, __wine_dbch___default)) break;    \
00829     err = glGetError();                                             \
00830     if (err == GL_NO_ERROR) {                                       \
00831        TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__);        \
00832                                                                     \
00833     } else do {                                                     \
00834         ERR(">>>>>>>>>>>>>>>>> %s (%#x) from %s @ %s / %d\n",       \
00835             debug_glerror(err), err, A, __FILE__, __LINE__);        \
00836        err = glGetError();                                          \
00837     } while (err != GL_NO_ERROR);                                   \
00838 } while(0)
00839 #else
00840 #define checkGLcall(A) do {} while(0)
00841 #endif
00842 
00843 /* Trace routines / diagnostics */
00844 /* ---------------------------- */
00845 
00846 /* Dump out a matrix and copy it */
00847 #define conv_mat(mat,gl_mat)                                                                \
00848 do {                                                                                        \
00849     TRACE("%f %f %f %f\n", (mat)->u.s._11, (mat)->u.s._12, (mat)->u.s._13, (mat)->u.s._14); \
00850     TRACE("%f %f %f %f\n", (mat)->u.s._21, (mat)->u.s._22, (mat)->u.s._23, (mat)->u.s._24); \
00851     TRACE("%f %f %f %f\n", (mat)->u.s._31, (mat)->u.s._32, (mat)->u.s._33, (mat)->u.s._34); \
00852     TRACE("%f %f %f %f\n", (mat)->u.s._41, (mat)->u.s._42, (mat)->u.s._43, (mat)->u.s._44); \
00853     memcpy(gl_mat, (mat), 16 * sizeof(float));                                              \
00854 } while (0)
00855 
00856 /* Trace vector and strided data information */
00857 #define TRACE_STRIDED(si, name) do { if (si->use_map & (1 << name)) \
00858         TRACE( #name " = (data {%#x:%p}, stride %d, format %s, stream %u)\n", \
00859         si->elements[name].data.buffer_object, si->elements[name].data.addr, si->elements[name].stride, \
00860         debug_d3dformat(si->elements[name].format->id), si->elements[name].stream_idx); } while(0)
00861 
00862 /* Global variables */
00863 extern const float identity[16] DECLSPEC_HIDDEN;
00864 
00865 enum wined3d_ffp_idx
00866 {
00867     WINED3D_FFP_POSITION = 0,
00868     WINED3D_FFP_BLENDWEIGHT = 1,
00869     WINED3D_FFP_BLENDINDICES = 2,
00870     WINED3D_FFP_NORMAL = 3,
00871     WINED3D_FFP_PSIZE = 4,
00872     WINED3D_FFP_DIFFUSE = 5,
00873     WINED3D_FFP_SPECULAR = 6,
00874     WINED3D_FFP_TEXCOORD0 = 7,
00875     WINED3D_FFP_TEXCOORD1 = 8,
00876     WINED3D_FFP_TEXCOORD2 = 9,
00877     WINED3D_FFP_TEXCOORD3 = 10,
00878     WINED3D_FFP_TEXCOORD4 = 11,
00879     WINED3D_FFP_TEXCOORD5 = 12,
00880     WINED3D_FFP_TEXCOORD6 = 13,
00881     WINED3D_FFP_TEXCOORD7 = 14,
00882 };
00883 
00884 enum wined3d_ffp_emit_idx
00885 {
00886     WINED3D_FFP_EMIT_FLOAT1 = 0,
00887     WINED3D_FFP_EMIT_FLOAT2 = 1,
00888     WINED3D_FFP_EMIT_FLOAT3 = 2,
00889     WINED3D_FFP_EMIT_FLOAT4 = 3,
00890     WINED3D_FFP_EMIT_D3DCOLOR = 4,
00891     WINED3D_FFP_EMIT_UBYTE4 = 5,
00892     WINED3D_FFP_EMIT_SHORT2 = 6,
00893     WINED3D_FFP_EMIT_SHORT4 = 7,
00894     WINED3D_FFP_EMIT_UBYTE4N = 8,
00895     WINED3D_FFP_EMIT_SHORT2N = 9,
00896     WINED3D_FFP_EMIT_SHORT4N = 10,
00897     WINED3D_FFP_EMIT_USHORT2N = 11,
00898     WINED3D_FFP_EMIT_USHORT4N = 12,
00899     WINED3D_FFP_EMIT_UDEC3 = 13,
00900     WINED3D_FFP_EMIT_DEC3N = 14,
00901     WINED3D_FFP_EMIT_FLOAT16_2 = 15,
00902     WINED3D_FFP_EMIT_FLOAT16_4 = 16,
00903     WINED3D_FFP_EMIT_COUNT = 17
00904 };
00905 
00906 struct wined3d_bo_address
00907 {
00908     GLuint buffer_object;
00909     const BYTE *addr;
00910 };
00911 
00912 struct wined3d_stream_info_element
00913 {
00914     const struct wined3d_format *format;
00915     struct wined3d_bo_address data;
00916     GLsizei stride;
00917     UINT stream_idx;
00918 };
00919 
00920 struct wined3d_stream_info
00921 {
00922     struct wined3d_stream_info_element elements[MAX_ATTRIBS];
00923     BOOL position_transformed;
00924     WORD swizzle_map; /* MAX_ATTRIBS, 16 */
00925     WORD use_map; /* MAX_ATTRIBS, 16 */
00926 };
00927 
00928 /*****************************************************************************
00929  * Prototypes
00930  */
00931 
00932 /* Routine common to the draw primitive and draw indexed primitive routines */
00933 void drawPrimitive(struct wined3d_device *device, UINT index_count,
00934         UINT start_idx, UINT idxBytes, const void *idxData) DECLSPEC_HIDDEN;
00935 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) DECLSPEC_HIDDEN;
00936 
00937 typedef void (WINE_GLAPI *glAttribFunc)(const void *data);
00938 typedef void (WINE_GLAPI *glMultiTexCoordFunc)(GLenum unit, const void *data);
00939 extern glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
00940 extern glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
00941 extern glAttribFunc specular_func_3ubv DECLSPEC_HIDDEN;
00942 extern glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
00943 extern glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
00944 extern glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
00945 
00946 #define eps 1e-8
00947 
00948 #define GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, tex_num) \
00949     (((((d3dvtVertexType) >> (16 + (2 * (tex_num)))) + 1) & 0x03) + 1)
00950 
00951 /* Routines and structures related to state management */
00952 
00953 #define STATE_RENDER(a) (a)
00954 #define STATE_IS_RENDER(a) ((a) >= STATE_RENDER(1) && (a) <= STATE_RENDER(WINEHIGHEST_RENDER_STATE))
00955 
00956 #define STATE_TEXTURESTAGE(stage, num) (STATE_RENDER(WINEHIGHEST_RENDER_STATE) + 1 + (stage) * (WINED3D_HIGHEST_TEXTURE_STATE + 1) + (num))
00957 #define STATE_IS_TEXTURESTAGE(a) ((a) >= STATE_TEXTURESTAGE(0, 1) && (a) <= STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE))
00958 
00959 /* + 1 because samplers start with 0 */
00960 #define STATE_SAMPLER(num) (STATE_TEXTURESTAGE(MAX_TEXTURES - 1, WINED3D_HIGHEST_TEXTURE_STATE) + 1 + (num))
00961 #define STATE_IS_SAMPLER(num) ((num) >= STATE_SAMPLER(0) && (num) <= STATE_SAMPLER(MAX_COMBINED_SAMPLERS - 1))
00962 
00963 #define STATE_PIXELSHADER (STATE_SAMPLER(MAX_COMBINED_SAMPLERS - 1) + 1)
00964 #define STATE_IS_PIXELSHADER(a) ((a) == STATE_PIXELSHADER)
00965 
00966 #define STATE_TRANSFORM(a) (STATE_PIXELSHADER + (a))
00967 #define STATE_IS_TRANSFORM(a) ((a) >= STATE_TRANSFORM(1) && (a) <= STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)))
00968 
00969 #define STATE_STREAMSRC (STATE_TRANSFORM(WINED3D_TS_WORLD_MATRIX(255)) + 1)
00970 #define STATE_IS_STREAMSRC(a) ((a) == STATE_STREAMSRC)
00971 #define STATE_INDEXBUFFER (STATE_STREAMSRC + 1)
00972 #define STATE_IS_INDEXBUFFER(a) ((a) == STATE_INDEXBUFFER)
00973 
00974 #define STATE_VDECL (STATE_INDEXBUFFER + 1)
00975 #define STATE_IS_VDECL(a) ((a) == STATE_VDECL)
00976 
00977 #define STATE_VSHADER (STATE_VDECL + 1)
00978 #define STATE_IS_VSHADER(a) ((a) == STATE_VSHADER)
00979 
00980 #define STATE_VIEWPORT (STATE_VSHADER + 1)
00981 #define STATE_IS_VIEWPORT(a) ((a) == STATE_VIEWPORT)
00982 
00983 #define STATE_VERTEXSHADERCONSTANT (STATE_VIEWPORT + 1)
00984 #define STATE_PIXELSHADERCONSTANT (STATE_VERTEXSHADERCONSTANT + 1)
00985 #define STATE_IS_VERTEXSHADERCONSTANT(a) ((a) == STATE_VERTEXSHADERCONSTANT)
00986 #define STATE_IS_PIXELSHADERCONSTANT(a) ((a) == STATE_PIXELSHADERCONSTANT)
00987 
00988 #define STATE_ACTIVELIGHT(a) (STATE_PIXELSHADERCONSTANT + (a) + 1)
00989 #define STATE_IS_ACTIVELIGHT(a) ((a) >= STATE_ACTIVELIGHT(0) && (a) < STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS))
00990 
00991 #define STATE_SCISSORRECT (STATE_ACTIVELIGHT(MAX_ACTIVE_LIGHTS - 1) + 1)
00992 #define STATE_IS_SCISSORRECT(a) ((a) == STATE_SCISSORRECT)
00993 
00994 #define STATE_CLIPPLANE(a) (STATE_SCISSORRECT + 1 + (a))
00995 #define STATE_IS_CLIPPLANE(a) ((a) >= STATE_CLIPPLANE(0) && (a) <= STATE_CLIPPLANE(MAX_CLIPPLANES - 1))
00996 
00997 #define STATE_MATERIAL (STATE_CLIPPLANE(MAX_CLIPPLANES))
00998 #define STATE_IS_MATERIAL(a) ((a) == STATE_MATERIAL)
00999 
01000 #define STATE_FRONTFACE (STATE_MATERIAL + 1)
01001 #define STATE_IS_FRONTFACE(a) ((a) == STATE_FRONTFACE)
01002 
01003 #define STATE_POINTSPRITECOORDORIGIN  (STATE_FRONTFACE + 1)
01004 #define STATE_IS_POINTSPRITECOORDORIGIN(a) ((a) == STATE_POINTSPRITECOORDORIGIN)
01005 
01006 #define STATE_BASEVERTEXINDEX  (STATE_POINTSPRITECOORDORIGIN + 1)
01007 #define STATE_IS_BASEVERTEXINDEX(a) ((a) == STATE_BASEVERTEXINDEX)
01008 
01009 #define STATE_FRAMEBUFFER (STATE_BASEVERTEXINDEX + 1)
01010 #define STATE_IS_FRAMEBUFFER(a) ((a) == STATE_FRAMEBUFFER)
01011 
01012 #define STATE_HIGHEST (STATE_FRAMEBUFFER)
01013 
01014 enum fogsource {
01015     FOGSOURCE_FFP,
01016     FOGSOURCE_VS,
01017     FOGSOURCE_COORD,
01018 };
01019 
01020 #define WINED3D_MAX_FBO_ENTRIES 64
01021 
01022 struct wined3d_occlusion_query
01023 {
01024     struct list entry;
01025     GLuint id;
01026     struct wined3d_context *context;
01027 };
01028 
01029 union wined3d_gl_query_object
01030 {
01031     GLuint id;
01032     GLsync sync;
01033 };
01034 
01035 struct wined3d_event_query
01036 {
01037     struct list entry;
01038     union wined3d_gl_query_object object;
01039     struct wined3d_context *context;
01040 };
01041 
01042 enum wined3d_event_query_result
01043 {
01044     WINED3D_EVENT_QUERY_OK,
01045     WINED3D_EVENT_QUERY_WAITING,
01046     WINED3D_EVENT_QUERY_NOT_STARTED,
01047     WINED3D_EVENT_QUERY_WRONG_THREAD,
01048     WINED3D_EVENT_QUERY_ERROR
01049 };
01050 
01051 void wined3d_event_query_destroy(struct wined3d_event_query *query) DECLSPEC_HIDDEN;
01052 enum wined3d_event_query_result wined3d_event_query_finish(const struct wined3d_event_query *query,
01053         const struct wined3d_device *device) DECLSPEC_HIDDEN;
01054 void wined3d_event_query_issue(struct wined3d_event_query *query, const struct wined3d_device *device) DECLSPEC_HIDDEN;
01055 BOOL wined3d_event_query_supported(const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
01056 
01057 struct wined3d_context
01058 {
01059     const struct wined3d_gl_info *gl_info;
01060     const struct StateEntry *state_table;
01061     /* State dirtification
01062      * dirtyArray is an array that contains markers for dirty states. numDirtyEntries states are dirty, their numbers are in indices
01063      * 0...numDirtyEntries - 1. isStateDirty is a redundant copy of the dirtyArray. Technically only one of them would be needed,
01064      * but with the help of both it is easy to find out if a state is dirty(just check the array index), and for applying dirty states
01065      * only numDirtyEntries array elements have to be checked, not STATE_HIGHEST states.
01066      */
01067     DWORD                   dirtyArray[STATE_HIGHEST + 1]; /* Won't get bigger than that, a state is never marked dirty 2 times */
01068     DWORD                   numDirtyEntries;
01069     DWORD isStateDirty[STATE_HIGHEST / (sizeof(DWORD) * CHAR_BIT) + 1]; /* Bitmap to find out quickly if a state is dirty */
01070 
01071     struct wined3d_swapchain *swapchain;
01072     struct wined3d_surface *current_rt;
01073     DWORD                   tid;    /* Thread ID which owns this context at the moment */
01074 
01075     /* Stores some information about the context state for optimization */
01076     WORD render_offscreen : 1;
01077     WORD last_was_rhw : 1;              /* true iff last draw_primitive was in xyzrhw mode */
01078     WORD last_was_pshader : 1;
01079     WORD last_was_vshader : 1;
01080     WORD namedArraysLoaded : 1;
01081     WORD numberedArraysLoaded : 1;
01082     WORD last_was_blit : 1;
01083     WORD last_was_ckey : 1;
01084     WORD fog_coord : 1;
01085     WORD fog_enabled : 1;
01086     WORD num_untracked_materials : 2;   /* Max value 2 */
01087     WORD current : 1;
01088     WORD destroyed : 1;
01089     WORD valid : 1;
01090     WORD padding : 1;
01091     BYTE texShaderBumpMap;              /* MAX_TEXTURES, 8 */
01092     BYTE lastWasPow2Texture;            /* MAX_TEXTURES, 8 */
01093     DWORD                   numbered_array_mask;
01094     GLenum                  tracking_parm;     /* Which source is tracking current colour         */
01095     GLenum                  untracked_materials[2];
01096     UINT                    blit_w, blit_h;
01097     enum fogsource          fog_source;
01098     DWORD active_texture;
01099     DWORD texture_type[MAX_COMBINED_SAMPLERS];
01100 
01101     /* The actual opengl context */
01102     UINT level;
01103     HGLRC restore_ctx;
01104     HDC restore_dc;
01105     int restore_pf;
01106     HGLRC                   glCtx;
01107     HWND                    win_handle;
01108     HDC                     hdc;
01109     int pixel_format;
01110     GLint                   aux_buffers;
01111 
01112     /* FBOs */
01113     UINT                    fbo_entry_count;
01114     struct list             fbo_list;
01115     struct list             fbo_destroy_list;
01116     struct fbo_entry        *current_fbo;
01117     GLuint                  fbo_read_binding;
01118     GLuint                  fbo_draw_binding;
01119     BOOL rebind_fbo;
01120     struct wined3d_surface **blit_targets;
01121     GLenum *draw_buffers;
01122     DWORD draw_buffers_mask; /* Enabled draw buffers, 31 max. */
01123 
01124     /* Queries */
01125     GLuint *free_occlusion_queries;
01126     UINT free_occlusion_query_size;
01127     UINT free_occlusion_query_count;
01128     struct list occlusion_queries;
01129 
01130     union wined3d_gl_query_object *free_event_queries;
01131     UINT free_event_query_size;
01132     UINT free_event_query_count;
01133     struct list event_queries;
01134 
01135     /* Extension emulation */
01136     GLint                   gl_fog_source;
01137     GLfloat                 fog_coord_value;
01138     GLfloat                 color[4], fogstart, fogend, fogcolor[4];
01139     GLuint                  dummy_arbfp_prog;
01140 };
01141 
01142 struct wined3d_fb_state
01143 {
01144     struct wined3d_surface **render_targets;
01145     struct wined3d_surface *depth_stencil;
01146 };
01147 
01148 typedef void (*APPLYSTATEFUNC)(struct wined3d_context *ctx, const struct wined3d_state *state, DWORD state_id);
01149 
01150 struct StateEntry
01151 {
01152     DWORD representative;
01153     APPLYSTATEFUNC apply;
01154 };
01155 
01156 struct StateEntryTemplate
01157 {
01158     DWORD state;
01159     struct StateEntry content;
01160     enum wined3d_gl_extension extension;
01161 };
01162 
01163 struct fragment_caps
01164 {
01165     DWORD PrimitiveMiscCaps;
01166     DWORD TextureOpCaps;
01167     DWORD MaxTextureBlendStages;
01168     DWORD MaxSimultaneousTextures;
01169 };
01170 
01171 struct fragment_pipeline
01172 {
01173     void (*enable_extension)(BOOL enable);
01174     void (*get_caps)(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps);
01175     HRESULT (*alloc_private)(struct wined3d_device *device);
01176     void (*free_private)(struct wined3d_device *device);
01177     BOOL (*color_fixup_supported)(struct color_fixup_desc fixup);
01178     const struct StateEntryTemplate *states;
01179     BOOL ffp_proj_control;
01180 };
01181 
01182 extern const struct StateEntryTemplate misc_state_template[] DECLSPEC_HIDDEN;
01183 extern const struct StateEntryTemplate ffp_vertexstate_template[] DECLSPEC_HIDDEN;
01184 extern const struct fragment_pipeline ffp_fragment_pipeline DECLSPEC_HIDDEN;
01185 extern const struct fragment_pipeline atifs_fragment_pipeline DECLSPEC_HIDDEN;
01186 extern const struct fragment_pipeline arbfp_fragment_pipeline DECLSPEC_HIDDEN;
01187 extern const struct fragment_pipeline nvts_fragment_pipeline DECLSPEC_HIDDEN;
01188 extern const struct fragment_pipeline nvrc_fragment_pipeline DECLSPEC_HIDDEN;
01189 
01190 /* "Base" state table */
01191 HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
01192         const struct wined3d_gl_info *gl_info, const struct StateEntryTemplate *vertex,
01193         const struct fragment_pipeline *fragment, const struct StateEntryTemplate *misc) DECLSPEC_HIDDEN;
01194 
01195 enum wined3d_blit_op
01196 {
01197     WINED3D_BLIT_OP_COLOR_BLIT,
01198     WINED3D_BLIT_OP_COLOR_FILL,
01199     WINED3D_BLIT_OP_DEPTH_FILL,
01200     WINED3D_BLIT_OP_DEPTH_BLIT,
01201 };
01202 
01203 /* Shaders for color conversions in blits. Do not do blit operations while
01204  * already under the GL lock. */
01205 struct blit_shader
01206 {
01207     HRESULT (*alloc_private)(struct wined3d_device *device);
01208     void (*free_private)(struct wined3d_device *device);
01209     HRESULT (*set_shader)(void *blit_priv, struct wined3d_context *context, const struct wined3d_surface *surface);
01210     void (*unset_shader)(const struct wined3d_gl_info *gl_info);
01211     BOOL (*blit_supported)(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op,
01212             const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format,
01213             const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format);
01214     HRESULT (*color_fill)(struct wined3d_device *device, struct wined3d_surface *dst_surface,
01215             const RECT *dst_rect, const struct wined3d_color *color);
01216     HRESULT (*depth_fill)(struct wined3d_device *device,
01217             struct wined3d_surface *surface, const RECT *rect, float depth);
01218 };
01219 
01220 extern const struct blit_shader ffp_blit DECLSPEC_HIDDEN;
01221 extern const struct blit_shader arbfp_blit DECLSPEC_HIDDEN;
01222 extern const struct blit_shader cpu_blit DECLSPEC_HIDDEN;
01223 
01224 const struct blit_shader *wined3d_select_blitter(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op,
01225         const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format,
01226         const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format)
01227         DECLSPEC_HIDDEN;
01228 
01229 /* Temporary blit_shader helper functions */
01230 HRESULT arbfp_blit_surface(struct wined3d_device *device, DWORD filter,
01231         struct wined3d_surface *src_surface, const RECT *src_rect,
01232         struct wined3d_surface *dst_surface, const RECT *dst_rect) DECLSPEC_HIDDEN;
01233 
01234 struct wined3d_context *context_acquire(const struct wined3d_device *device,
01235         struct wined3d_surface *target) DECLSPEC_HIDDEN;
01236 void context_alloc_event_query(struct wined3d_context *context,
01237         struct wined3d_event_query *query) DECLSPEC_HIDDEN;
01238 void context_alloc_occlusion_query(struct wined3d_context *context,
01239         struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
01240 void context_apply_blit_state(struct wined3d_context *context, const struct wined3d_device *device) DECLSPEC_HIDDEN;
01241 BOOL context_apply_clear_state(struct wined3d_context *context, const struct wined3d_device *device,
01242         UINT rt_count, const struct wined3d_fb_state *fb) DECLSPEC_HIDDEN;
01243 BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_device *device) DECLSPEC_HIDDEN;
01244 void context_apply_fbo_state_blit(struct wined3d_context *context, GLenum target,
01245         struct wined3d_surface *render_target, struct wined3d_surface *depth_stencil, DWORD location) DECLSPEC_HIDDEN;
01246 void context_active_texture(struct wined3d_context *context, const struct wined3d_gl_info *gl_info,
01247         unsigned int unit) DECLSPEC_HIDDEN;
01248 void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint name) DECLSPEC_HIDDEN;
01249 void context_check_fbo_status(const struct wined3d_context *context, GLenum target) DECLSPEC_HIDDEN;
01250 struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, struct wined3d_surface *target,
01251         const struct wined3d_format *ds_format) DECLSPEC_HIDDEN;
01252 void context_destroy(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
01253 void context_free_event_query(struct wined3d_event_query *query) DECLSPEC_HIDDEN;
01254 void context_free_occlusion_query(struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
01255 struct wined3d_context *context_get_current(void) DECLSPEC_HIDDEN;
01256 DWORD context_get_tls_idx(void) DECLSPEC_HIDDEN;
01257 void context_invalidate_state(struct wined3d_context *context, DWORD state_id) DECLSPEC_HIDDEN;
01258 void context_release(struct wined3d_context *context) DECLSPEC_HIDDEN;
01259 void context_resource_released(const struct wined3d_device *device,
01260         struct wined3d_resource *resource, enum wined3d_resource_type type) DECLSPEC_HIDDEN;
01261 void context_resource_unloaded(const struct wined3d_device *device,
01262         struct wined3d_resource *resource, enum wined3d_resource_type type) DECLSPEC_HIDDEN;
01263 BOOL context_set_current(struct wined3d_context *ctx) DECLSPEC_HIDDEN;
01264 void context_set_draw_buffer(struct wined3d_context *context, GLenum buffer) DECLSPEC_HIDDEN;
01265 void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN;
01266 void context_state_drawbuf(struct wined3d_context *context,
01267         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
01268 void context_state_fb(struct wined3d_context *context,
01269         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
01270 void context_surface_update(struct wined3d_context *context, const struct wined3d_surface *surface) DECLSPEC_HIDDEN;
01271 
01272 /*****************************************************************************
01273  * Internal representation of a light
01274  */
01275 struct wined3d_light_info
01276 {
01277     struct wined3d_light OriginalParms; /* Note D3D8LIGHT == D3D9LIGHT */
01278     DWORD        OriginalIndex;
01279     LONG         glIndex;
01280     BOOL         enabled;
01281 
01282     /* Converted parms to speed up swapping lights */
01283     float                         lightPosn[4];
01284     float                         lightDirn[4];
01285     float                         exponent;
01286     float                         cutoff;
01287 
01288     struct list entry;
01289 };
01290 
01291 /* The default light parameters */
01292 extern const struct wined3d_light WINED3D_default_light DECLSPEC_HIDDEN;
01293 
01294 struct wined3d_pixel_format
01295 {
01296     int iPixelFormat; /* WGL pixel format */
01297     int iPixelType; /* WGL pixel type e.g. WGL_TYPE_RGBA_ARB, WGL_TYPE_RGBA_FLOAT_ARB or WGL_TYPE_COLORINDEX_ARB */
01298     int redSize, greenSize, blueSize, alphaSize, colorSize;
01299     int depthSize, stencilSize;
01300     BOOL windowDrawable;
01301     BOOL doubleBuffer;
01302     int auxBuffers;
01303     int numSamples;
01304 };
01305 
01306 enum wined3d_pci_vendor
01307 {
01308     HW_VENDOR_SOFTWARE                 = 0x0000,
01309     HW_VENDOR_AMD                      = 0x1002,
01310     HW_VENDOR_NVIDIA                   = 0x10de,
01311     HW_VENDOR_INTEL                    = 0x8086,
01312 };
01313 
01314 enum wined3d_pci_device
01315 {
01316     CARD_WINE                       = 0x0000,
01317 
01318     CARD_AMD_RAGE_128PRO            = 0x5246,
01319     CARD_AMD_RADEON_7200            = 0x5144,
01320     CARD_AMD_RADEON_8500            = 0x514c,
01321     CARD_AMD_RADEON_9500            = 0x4144,
01322     CARD_AMD_RADEON_XPRESS_200M     = 0x5955,
01323     CARD_AMD_RADEON_X700            = 0x5e4c,
01324     CARD_AMD_RADEON_X1600           = 0x71c2,
01325     CARD_AMD_RADEON_HD2350          = 0x94c7,
01326     CARD_AMD_RADEON_HD2600          = 0x9581,
01327     CARD_AMD_RADEON_HD2900          = 0x9400,
01328     CARD_AMD_RADEON_HD3200          = 0x9620,
01329     CARD_AMD_RADEON_HD4350          = 0x954f,
01330     CARD_AMD_RADEON_HD4550          = 0x9540,
01331     CARD_AMD_RADEON_HD4600          = 0x9495,
01332     CARD_AMD_RADEON_HD4650          = 0x9498,
01333     CARD_AMD_RADEON_HD4670          = 0x9490,
01334     CARD_AMD_RADEON_HD4700          = 0x944e,
01335     CARD_AMD_RADEON_HD4770          = 0x94b3,
01336     CARD_AMD_RADEON_HD4800          = 0x944c, /* Picked one value between 9440, 944c, 9442, 9460 */
01337     CARD_AMD_RADEON_HD4830          = 0x944c,
01338     CARD_AMD_RADEON_HD4850          = 0x9442,
01339     CARD_AMD_RADEON_HD4870          = 0x9440,
01340     CARD_AMD_RADEON_HD4890          = 0x9460,
01341     CARD_AMD_RADEON_HD5400          = 0x68f9,
01342     CARD_AMD_RADEON_HD5600          = 0x68d8,
01343     CARD_AMD_RADEON_HD5700          = 0x68BE, /* Picked HD5750 */
01344     CARD_AMD_RADEON_HD5750          = 0x68BE,
01345     CARD_AMD_RADEON_HD5770          = 0x68B8,
01346     CARD_AMD_RADEON_HD5800          = 0x6898, /* Picked HD5850 */
01347     CARD_AMD_RADEON_HD5850          = 0x6898,
01348     CARD_AMD_RADEON_HD5870          = 0x6899,
01349     CARD_AMD_RADEON_HD5900          = 0x689c,
01350     CARD_AMD_RADEON_HD6300          = 0x9803,
01351     CARD_AMD_RADEON_HD6400          = 0x6770,
01352     CARD_AMD_RADEON_HD6410D         = 0x9644,
01353     CARD_AMD_RADEON_HD6550D         = 0x9640,
01354     CARD_AMD_RADEON_HD6600          = 0x6758,
01355     CARD_AMD_RADEON_HD6600M         = 0x6741,
01356     CARD_AMD_RADEON_HD6800          = 0x6739,
01357     CARD_AMD_RADEON_HD6900          = 0x6719,
01358 
01359     CARD_NVIDIA_RIVA_128            = 0x0018,
01360     CARD_NVIDIA_RIVA_TNT            = 0x0020,
01361     CARD_NVIDIA_RIVA_TNT2           = 0x0028,
01362     CARD_NVIDIA_GEFORCE             = 0x0100,
01363     CARD_NVIDIA_GEFORCE2_MX         = 0x0110,
01364     CARD_NVIDIA_GEFORCE2            = 0x0150,
01365     CARD_NVIDIA_GEFORCE3            = 0x0200,
01366     CARD_NVIDIA_GEFORCE4_MX         = 0x0170,
01367     CARD_NVIDIA_GEFORCE4_TI4200     = 0x0253,
01368     CARD_NVIDIA_GEFORCEFX_5200      = 0x0320,
01369     CARD_NVIDIA_GEFORCEFX_5600      = 0x0312,
01370     CARD_NVIDIA_GEFORCEFX_5800      = 0x0302,
01371     CARD_NVIDIA_GEFORCE_6200        = 0x014f,
01372     CARD_NVIDIA_GEFORCE_6600GT      = 0x0140,
01373     CARD_NVIDIA_GEFORCE_6800        = 0x0041,
01374     CARD_NVIDIA_GEFORCE_7400        = 0x01d8,
01375     CARD_NVIDIA_GEFORCE_7300        = 0x01d7, /* GeForce Go 7300 */
01376     CARD_NVIDIA_GEFORCE_7600        = 0x0391,
01377     CARD_NVIDIA_GEFORCE_7800GT      = 0x0092,
01378     CARD_NVIDIA_GEFORCE_8100        = 0x084F,
01379     CARD_NVIDIA_GEFORCE_8200        = 0x0849, /* Other PCI ID 0x084B */
01380     CARD_NVIDIA_GEFORCE_8300GS      = 0x0423,
01381     CARD_NVIDIA_GEFORCE_8400GS      = 0x0404,
01382     CARD_NVIDIA_GEFORCE_8500GT      = 0x0421,
01383     CARD_NVIDIA_GEFORCE_8600GT      = 0x0402,
01384     CARD_NVIDIA_GEFORCE_8600MGT     = 0x0407,
01385     CARD_NVIDIA_GEFORCE_8800GTS     = 0x0193,
01386     CARD_NVIDIA_GEFORCE_8800GTX     = 0x0191,
01387     CARD_NVIDIA_GEFORCE_9200        = 0x086d,
01388     CARD_NVIDIA_GEFORCE_9400GT      = 0x042c,
01389     CARD_NVIDIA_GEFORCE_9500GT      = 0x0640,
01390     CARD_NVIDIA_GEFORCE_9600GT      = 0x0622,
01391     CARD_NVIDIA_GEFORCE_9800GT      = 0x0614,
01392     CARD_NVIDIA_GEFORCE_210         = 0x0a23,
01393     CARD_NVIDIA_GEFORCE_GT220       = 0x0a20,
01394     CARD_NVIDIA_GEFORCE_GT240       = 0x0ca3,
01395     CARD_NVIDIA_GEFORCE_GTX260      = 0x05e2,
01396     CARD_NVIDIA_GEFORCE_GTX275      = 0x05e6,
01397     CARD_NVIDIA_GEFORCE_GTX280      = 0x05e1,
01398     CARD_NVIDIA_GEFORCE_GT320M      = 0x0a2d,
01399     CARD_NVIDIA_GEFORCE_GT325M      = 0x0a35,
01400     CARD_NVIDIA_GEFORCE_GT330       = 0x0ca0,
01401     CARD_NVIDIA_GEFORCE_GTS350M     = 0x0cb0,
01402     CARD_NVIDIA_GEFORCE_GT420       = 0x0de2,
01403     CARD_NVIDIA_GEFORCE_GT430       = 0x0de1,
01404     CARD_NVIDIA_GEFORCE_GT440       = 0x0de0,
01405     CARD_NVIDIA_GEFORCE_GTS450      = 0x0dc4,
01406     CARD_NVIDIA_GEFORCE_GTX460      = 0x0e22,
01407     CARD_NVIDIA_GEFORCE_GTX460M     = 0x0dd1,
01408     CARD_NVIDIA_GEFORCE_GTX465      = 0x06c4,
01409     CARD_NVIDIA_GEFORCE_GTX470      = 0x06cd,
01410     CARD_NVIDIA_GEFORCE_GTX480      = 0x06c0,
01411     CARD_NVIDIA_GEFORCE_GT540M      = 0x0df4,
01412     CARD_NVIDIA_GEFORCE_GTX550      = 0x1244,
01413     CARD_NVIDIA_GEFORCE_GT555M      = 0x04b8,
01414     CARD_NVIDIA_GEFORCE_GTX560TI    = 0x1200,
01415     CARD_NVIDIA_GEFORCE_GTX560      = 0x1201,
01416     CARD_NVIDIA_GEFORCE_GTX570      = 0x1081,
01417     CARD_NVIDIA_GEFORCE_GTX580      = 0x1080,
01418 
01419     CARD_INTEL_830M                 = 0x3577,
01420     CARD_INTEL_855GM                = 0x3582,
01421     CARD_INTEL_845G                 = 0x2562,
01422     CARD_INTEL_865G                 = 0x2572,
01423     CARD_INTEL_915G                 = 0x2582,
01424     CARD_INTEL_E7221G               = 0x258a,
01425     CARD_INTEL_915GM                = 0x2592,
01426     CARD_INTEL_945G                 = 0x2772,
01427     CARD_INTEL_945GM                = 0x27a2,
01428     CARD_INTEL_945GME               = 0x27ae,
01429     CARD_INTEL_Q35                  = 0x29b2,
01430     CARD_INTEL_G33                  = 0x29c2,
01431     CARD_INTEL_Q33                  = 0x29d2,
01432     CARD_INTEL_PNVG                 = 0xa001,
01433     CARD_INTEL_PNVM                 = 0xa011,
01434     CARD_INTEL_965Q                 = 0x2992,
01435     CARD_INTEL_965G                 = 0x2982,
01436     CARD_INTEL_946GZ                = 0x2972,
01437     CARD_INTEL_965GM                = 0x2a02,
01438     CARD_INTEL_965GME               = 0x2a12,
01439     CARD_INTEL_GM45                 = 0x2a42,
01440     CARD_INTEL_IGD                  = 0x2e02,
01441     CARD_INTEL_Q45                  = 0x2e12,
01442     CARD_INTEL_G45                  = 0x2e22,
01443     CARD_INTEL_G41                  = 0x2e32,
01444     CARD_INTEL_B43                  = 0x2e92,
01445     CARD_INTEL_ILKD                 = 0x0042,
01446     CARD_INTEL_ILKM                 = 0x0046,
01447     CARD_INTEL_SNBD                 = 0x0122,
01448     CARD_INTEL_SNBM                 = 0x0126,
01449     CARD_INTEL_SNBS                 = 0x010a,
01450     CARD_INTEL_IVBD                 = 0x0162,
01451     CARD_INTEL_IVBM                 = 0x0166,
01452     CARD_INTEL_IVBS                 = 0x015a,
01453 };
01454 
01455 struct wined3d_fbo_ops
01456 {
01457     PGLFNGLISRENDERBUFFERPROC                       glIsRenderbuffer;
01458     PGLFNGLBINDRENDERBUFFERPROC                     glBindRenderbuffer;
01459     PGLFNGLDELETERENDERBUFFERSPROC                  glDeleteRenderbuffers;
01460     PGLFNGLGENRENDERBUFFERSPROC                     glGenRenderbuffers;
01461     PGLFNGLRENDERBUFFERSTORAGEPROC                  glRenderbufferStorage;
01462     PGLFNRENDERBUFFERSTORAGEMULTISAMPLEPROC         glRenderbufferStorageMultisample;
01463     PGLFNGLGETRENDERBUFFERPARAMETERIVPROC           glGetRenderbufferParameteriv;
01464     PGLFNGLISFRAMEBUFFERPROC                        glIsFramebuffer;
01465     PGLFNGLBINDFRAMEBUFFERPROC                      glBindFramebuffer;
01466     PGLFNGLDELETEFRAMEBUFFERSPROC                   glDeleteFramebuffers;
01467     PGLFNGLGENFRAMEBUFFERSPROC                      glGenFramebuffers;
01468     PGLFNGLCHECKFRAMEBUFFERSTATUSPROC               glCheckFramebufferStatus;
01469     PGLFNGLFRAMEBUFFERTEXTURE1DPROC                 glFramebufferTexture1D;
01470     PGLFNGLFRAMEBUFFERTEXTURE2DPROC                 glFramebufferTexture2D;
01471     PGLFNGLFRAMEBUFFERTEXTURE3DPROC                 glFramebufferTexture3D;
01472     PGLFNGLFRAMEBUFFERRENDERBUFFERPROC              glFramebufferRenderbuffer;
01473     PGLFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC  glGetFramebufferAttachmentParameteriv;
01474     PGLFNGLBLITFRAMEBUFFERPROC                      glBlitFramebuffer;
01475     PGLFNGLGENERATEMIPMAPPROC                       glGenerateMipmap;
01476 };
01477 
01478 struct wined3d_gl_limits
01479 {
01480     UINT buffers;
01481     UINT lights;
01482     UINT textures;
01483     UINT texture_stages;
01484     UINT texture_coords;
01485     UINT fragment_samplers;
01486     UINT vertex_samplers;
01487     UINT combined_samplers;
01488     UINT general_combiners;
01489     UINT sampler_stages;
01490     UINT clipplanes;
01491     UINT texture_size;
01492     UINT texture3d_size;
01493     float pointsize_max;
01494     float pointsize_min;
01495     UINT blends;
01496     UINT anisotropy;
01497     float shininess;
01498     UINT samples;
01499     UINT vertex_attribs;
01500 
01501     UINT glsl_varyings;
01502     UINT glsl_vs_float_constants;
01503     UINT glsl_ps_float_constants;
01504 
01505     UINT arb_vs_float_constants;
01506     UINT arb_vs_native_constants;
01507     UINT arb_vs_instructions;
01508     UINT arb_vs_temps;
01509     UINT arb_ps_float_constants;
01510     UINT arb_ps_local_constants;
01511     UINT arb_ps_native_constants;
01512     UINT arb_ps_instructions;
01513     UINT arb_ps_temps;
01514 };
01515 
01516 struct wined3d_gl_info
01517 {
01518     DWORD glsl_version;
01519     struct wined3d_gl_limits limits;
01520     DWORD reserved_glsl_constants;
01521     DWORD quirks;
01522     BOOL supported[WINED3D_GL_EXT_COUNT];
01523     GLint wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP + 1];
01524 
01525     struct wined3d_fbo_ops fbo_ops;
01526 #define USE_GL_FUNC(type, pfn, ext, replace) type pfn;
01527     /* GL function pointers */
01528     GL_EXT_FUNCS_GEN
01529     /* WGL function pointers */
01530     WGL_EXT_FUNCS_GEN
01531 #undef USE_GL_FUNC
01532 
01533     struct wined3d_format *formats;
01534 };
01535 
01536 struct wined3d_driver_info
01537 {
01538     enum wined3d_pci_vendor vendor;
01539     enum wined3d_pci_device device;
01540     const char *name;
01541     const char *description;
01542     unsigned int vidmem;
01543     DWORD version_high;
01544     DWORD version_low;
01545 };
01546 
01547 /* The adapter structure */
01548 struct wined3d_adapter
01549 {
01550     UINT ordinal;
01551     BOOL                    opengl;
01552 
01553     POINT monitorPoint;
01554     SIZE screen_size;
01555     enum wined3d_format_id screen_format;
01556 
01557     struct wined3d_gl_info  gl_info;
01558     struct wined3d_driver_info driver_info;
01559     WCHAR                   DeviceName[CCHDEVICENAME]; /* DeviceName for use with e.g. ChangeDisplaySettings */
01560     unsigned int cfg_count;
01561     struct wined3d_pixel_format *cfgs;
01562     unsigned int            TextureRam; /* Amount of texture memory both video ram + AGP/TurboCache/HyperMemory/.. */
01563     unsigned int            UsedTextureRam;
01564     LUID luid;
01565 
01566     const struct fragment_pipeline *fragment_pipe;
01567     const struct wined3d_shader_backend_ops *shader_backend;
01568     const struct blit_shader *blitter;
01569 };
01570 
01571 unsigned int adapter_adjust_memory(struct wined3d_adapter *adapter, int amount) DECLSPEC_HIDDEN;
01572 
01573 BOOL initPixelFormats(struct wined3d_gl_info *gl_info, enum wined3d_pci_vendor vendor) DECLSPEC_HIDDEN;
01574 BOOL initPixelFormatsNoGL(struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
01575 extern void add_gl_compat_wrappers(struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
01576 
01577 /*****************************************************************************
01578  * High order patch management
01579  */
01580 struct WineD3DRectPatch
01581 {
01582     UINT                            Handle;
01583     float                          *mem;
01584     struct wined3d_strided_data strided;
01585     struct wined3d_rect_patch_info rect_patch_info;
01586     float                           numSegs[4];
01587     char                            has_normals, has_texcoords;
01588     struct list                     entry;
01589 };
01590 
01591 HRESULT tesselate_rectpatch(struct wined3d_device *device, struct WineD3DRectPatch *patch) DECLSPEC_HIDDEN;
01592 
01593 enum projection_types
01594 {
01595     proj_none    = 0,
01596     proj_count3  = 1,
01597     proj_count4  = 2
01598 };
01599 
01600 enum dst_arg
01601 {
01602     resultreg    = 0,
01603     tempreg      = 1
01604 };
01605 
01606 /*****************************************************************************
01607  * Fixed function pipeline replacements
01608  */
01609 #define ARG_UNUSED          0xff
01610 struct texture_stage_op
01611 {
01612     unsigned                cop : 8;
01613     unsigned                carg1 : 8;
01614     unsigned                carg2 : 8;
01615     unsigned                carg0 : 8;
01616 
01617     unsigned                aop : 8;
01618     unsigned                aarg1 : 8;
01619     unsigned                aarg2 : 8;
01620     unsigned                aarg0 : 8;
01621 
01622     struct color_fixup_desc color_fixup;
01623     unsigned                tex_type : 3;
01624     unsigned                dst : 1;
01625     unsigned                projected : 2;
01626     unsigned                padding : 10;
01627 };
01628 
01629 struct ffp_frag_settings {
01630     struct texture_stage_op     op[MAX_TEXTURES];
01631     enum fogmode fog;
01632     /* Use shorts instead of chars to get dword alignment */
01633     unsigned short sRGB_write;
01634     unsigned short emul_clipplanes;
01635 };
01636 
01637 struct ffp_frag_desc
01638 {
01639     struct wine_rb_entry entry;
01640     struct ffp_frag_settings    settings;
01641 };
01642 
01643 extern const struct wine_rb_functions wined3d_ffp_frag_program_rb_functions DECLSPEC_HIDDEN;
01644 extern const struct wined3d_parent_ops wined3d_null_parent_ops DECLSPEC_HIDDEN;
01645 
01646 void gen_ffp_frag_op(const struct wined3d_device *device, const struct wined3d_state *state,
01647         struct ffp_frag_settings *settings, BOOL ignore_textype) DECLSPEC_HIDDEN;
01648 const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
01649         const struct ffp_frag_settings *settings) DECLSPEC_HIDDEN;
01650 void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc) DECLSPEC_HIDDEN;
01651 void wined3d_get_draw_rect(const struct wined3d_state *state, RECT *rect) DECLSPEC_HIDDEN;
01652 
01653 struct wined3d
01654 {
01655     LONG ref;
01656     void *parent;
01657     DWORD flags;
01658     UINT dxVersion;
01659     UINT adapter_count;
01660     struct wined3d_adapter adapters[1];
01661 };
01662 
01663 HRESULT wined3d_init(struct wined3d *wined3d, UINT version, DWORD flags, void *parent) DECLSPEC_HIDDEN;
01664 BOOL wined3d_register_window(HWND window, struct wined3d_device *device) DECLSPEC_HIDDEN;
01665 void wined3d_unregister_window(HWND window) DECLSPEC_HIDDEN;
01666 
01667 /*****************************************************************************
01668  * IWineD3DDevice implementation structure
01669  */
01670 #define WINED3D_UNMAPPED_STAGE ~0U
01671 
01672 /* Multithreaded flag. Removed from the public header to signal that IWineD3D::CreateDevice ignores it */
01673 #define WINED3DCREATE_MULTITHREADED 0x00000004
01674 
01675 struct wined3d_device
01676 {
01677     LONG ref;
01678 
01679     /* WineD3D Information  */
01680     struct wined3d_device_parent *device_parent;
01681     struct wined3d *wined3d;
01682     struct wined3d_adapter *adapter;
01683 
01684     /* Window styles to restore when switching fullscreen mode */
01685     LONG                    style;
01686     LONG                    exStyle;
01687 
01688     /* X and GL Information */
01689     GLenum                  offscreenBuffer;
01690 
01691     /* Selected capabilities */
01692     int vs_selected_mode;
01693     int ps_selected_mode;
01694     const struct wined3d_shader_backend_ops *shader_backend;
01695     void *shader_priv;
01696     void *fragment_priv;
01697     void *blit_priv;
01698     struct StateEntry StateTable[STATE_HIGHEST + 1];
01699     /* Array of functions for states which are handled by more than one pipeline part */
01700     APPLYSTATEFUNC *multistate_funcs[STATE_HIGHEST + 1];
01701     const struct fragment_pipeline *frag_pipe;
01702     const struct blit_shader *blitter;
01703 
01704     unsigned int max_ffp_textures;
01705     DWORD vshader_version, pshader_version;
01706     DWORD d3d_vshader_constantF, d3d_pshader_constantF; /* Advertised d3d caps, not GL ones */
01707     DWORD vs_clipping;
01708 
01709     WORD view_ident : 1;                /* true iff view matrix is identity */
01710     WORD vertexBlendUsed : 1;           /* To avoid needless setting of the blend matrices */
01711     WORD isRecordingState : 1;
01712     WORD isInDraw : 1;
01713     WORD bCursorVisible : 1;
01714     WORD d3d_initialized : 1;
01715     WORD inScene : 1;                   /* A flag to check for proper BeginScene / EndScene call pairs */
01716     WORD softwareVertexProcessing : 1;  /* process vertex shaders using software or hardware */
01717     WORD useDrawStridedSlow : 1;
01718     WORD instancedDraw : 1;
01719     WORD filter_messages : 1;
01720     WORD padding : 5;
01721 
01722     BYTE fixed_function_usage_map;      /* MAX_TEXTURES, 8 */
01723 
01724 #define DDRAW_PITCH_ALIGNMENT 8
01725 #define D3D8_PITCH_ALIGNMENT 4
01726     unsigned char           surface_alignment; /* Line Alignment of surfaces                      */
01727 
01728     /* State block related */
01729     struct wined3d_stateblock *stateBlock;
01730     struct wined3d_stateblock *updateStateBlock;
01731 
01732     /* Internal use fields  */
01733     struct wined3d_device_creation_parameters create_parms;
01734     HWND focus_window;
01735 
01736     struct wined3d_swapchain **swapchains;
01737     UINT swapchain_count;
01738 
01739     struct list             resources; /* a linked list to track resources created by the device */
01740     struct list             shaders;   /* a linked list to track shaders (pixel and vertex)      */
01741 
01742     /* Render Target Support */
01743     DWORD valid_rt_mask;
01744     struct wined3d_fb_state fb;
01745     struct wined3d_surface *onscreen_depth_stencil;
01746     struct wined3d_surface *auto_depth_stencil;
01747 
01748     /* For rendering to a texture using glCopyTexImage */
01749     GLuint                  depth_blt_texture;
01750 
01751     /* Cursor management */
01752     UINT                    xHotSpot;
01753     UINT                    yHotSpot;
01754     UINT                    xScreenSpace;
01755     UINT                    yScreenSpace;
01756     UINT                    cursorWidth, cursorHeight;
01757     GLuint                  cursorTexture;
01758     HCURSOR                 hardwareCursor;
01759 
01760     /* The Wine logo surface */
01761     struct wined3d_surface *logo_surface;
01762 
01763     /* Textures for when no other textures are mapped */
01764     UINT dummy_texture_2d[MAX_COMBINED_SAMPLERS];
01765     UINT dummy_texture_rect[MAX_COMBINED_SAMPLERS];
01766     UINT dummy_texture_3d[MAX_COMBINED_SAMPLERS];
01767     UINT dummy_texture_cube[MAX_COMBINED_SAMPLERS];
01768 
01769     /* With register combiners we can skip junk texture stages */
01770     DWORD                     texUnitMap[MAX_COMBINED_SAMPLERS];
01771     DWORD                     rev_tex_unit_map[MAX_COMBINED_SAMPLERS];
01772 
01773     /* Stream source management */
01774     struct wined3d_stream_info strided_streams;
01775     const struct wined3d_strided_data *up_strided;
01776     struct wined3d_event_query *buffer_queries[MAX_ATTRIBS];
01777     unsigned int num_buffer_queries;
01778 
01779     /* Context management */
01780     struct wined3d_context **contexts;
01781     UINT context_count;
01782 
01783     /* High level patch management */
01784 #define PATCHMAP_SIZE 43
01785 #define PATCHMAP_HASHFUNC(x) ((x) % PATCHMAP_SIZE) /* Primitive and simple function */
01786     struct list             patches[PATCHMAP_SIZE];
01787 };
01788 
01789 HRESULT device_clear_render_targets(struct wined3d_device *device, UINT rt_count, const struct wined3d_fb_state *fb,
01790         UINT rect_count, const RECT *rects, const RECT *draw_rect, DWORD flags,
01791         const struct wined3d_color *color, float depth, DWORD stencil) DECLSPEC_HIDDEN;
01792 BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
01793 void device_context_remove(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
01794 HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d,
01795         UINT adapter_idx, enum wined3d_device_type device_type, HWND focus_window, DWORD flags,
01796         BYTE surface_alignment, struct wined3d_device_parent *device_parent) DECLSPEC_HIDDEN;
01797 void device_preload_textures(const struct wined3d_device *device) DECLSPEC_HIDDEN;
01798 LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL unicode,
01799         UINT message, WPARAM wparam, LPARAM lparam, WNDPROC proc) DECLSPEC_HIDDEN;
01800 void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
01801 void device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource) DECLSPEC_HIDDEN;
01802 void device_stream_info_from_declaration(struct wined3d_device *device,
01803         struct wined3d_stream_info *stream_info, BOOL *fixup) DECLSPEC_HIDDEN;
01804 void device_switch_onscreen_ds(struct wined3d_device *device, struct wined3d_context *context,
01805         struct wined3d_surface *depth_stencil) DECLSPEC_HIDDEN;
01806 void device_update_stream_info(struct wined3d_device *device, const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
01807 void device_update_tex_unit_map(struct wined3d_device *device) DECLSPEC_HIDDEN;
01808 void device_invalidate_state(const struct wined3d_device *device, DWORD state) DECLSPEC_HIDDEN;
01809 
01810 static inline BOOL isStateDirty(const struct wined3d_context *context, DWORD state)
01811 {
01812     DWORD idx = state / (sizeof(*context->isStateDirty) * CHAR_BIT);
01813     BYTE shift = state & ((sizeof(*context->isStateDirty) * CHAR_BIT) - 1);
01814     return context->isStateDirty[idx] & (1 << shift);
01815 }
01816 
01817 static inline void invalidate_active_texture(const struct wined3d_device *device, struct wined3d_context *context)
01818 {
01819     DWORD sampler = device->rev_tex_unit_map[context->active_texture];
01820     if (sampler != WINED3D_UNMAPPED_STAGE)
01821         context_invalidate_state(context, STATE_SAMPLER(sampler));
01822 }
01823 
01824 #define WINED3D_RESOURCE_ACCESS_GPU     0x1
01825 #define WINED3D_RESOURCE_ACCESS_CPU     0x2
01826 /* SCRATCH is mostly the same as CPU, but can't be used by the GPU at all,
01827  * not even for resource uploads. */
01828 #define WINED3D_RESOURCE_ACCESS_SCRATCH 0x4
01829 
01830 struct wined3d_resource_ops
01831 {
01832     void (*resource_unload)(struct wined3d_resource *resource);
01833 };
01834 
01835 struct wined3d_resource
01836 {
01837     LONG ref;
01838     struct wined3d_device *device;
01839     enum wined3d_resource_type type;
01840     const struct wined3d_format *format;
01841     enum wined3d_multisample_type multisample_type;
01842     UINT                    multisample_quality;
01843     DWORD                   usage;
01844     enum wined3d_pool pool;
01845     DWORD access_flags;
01846     UINT width;
01847     UINT height;
01848     UINT depth;
01849     UINT                    size;
01850     DWORD                   priority;
01851     BYTE                   *allocatedMemory; /* Pointer to the real data location */
01852     BYTE                   *heapMemory; /* Pointer to the HeapAlloced block of memory */
01853     struct list             privateData;
01854     struct list             resource_list_entry;
01855 
01856     void *parent;
01857     const struct wined3d_parent_ops *parent_ops;
01858     const struct wined3d_resource_ops *resource_ops;
01859 };
01860 
01861 void resource_cleanup(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
01862 DWORD resource_get_priority(const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
01863 HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device,
01864         enum wined3d_resource_type type, const struct wined3d_format *format,
01865         enum wined3d_multisample_type multisample_type, UINT multisample_quality,
01866         DWORD usage, enum wined3d_pool pool, UINT width, UINT height, UINT depth, UINT size,
01867         void *parent, const struct wined3d_parent_ops *parent_ops,
01868         const struct wined3d_resource_ops *resource_ops) DECLSPEC_HIDDEN;
01869 DWORD resource_set_priority(struct wined3d_resource *resource, DWORD priority) DECLSPEC_HIDDEN;
01870 void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
01871 
01872 /* Tests show that the start address of resources is 32 byte aligned */
01873 #define RESOURCE_ALIGNMENT 16
01874 
01875 enum wined3d_texture_state
01876 {
01877     WINED3DTEXSTA_ADDRESSU       = 0,
01878     WINED3DTEXSTA_ADDRESSV       = 1,
01879     WINED3DTEXSTA_ADDRESSW       = 2,
01880     WINED3DTEXSTA_BORDERCOLOR    = 3,
01881     WINED3DTEXSTA_MAGFILTER      = 4,
01882     WINED3DTEXSTA_MINFILTER      = 5,
01883     WINED3DTEXSTA_MIPFILTER      = 6,
01884     WINED3DTEXSTA_MAXMIPLEVEL    = 7,
01885     WINED3DTEXSTA_MAXANISOTROPY  = 8,
01886     WINED3DTEXSTA_SRGBTEXTURE    = 9,
01887     WINED3DTEXSTA_SHADOW         = 10,
01888     MAX_WINETEXTURESTATES        = 11,
01889 };
01890 
01891 enum WINED3DSRGB
01892 {
01893     SRGB_ANY                                = 0,    /* Uses the cached value(e.g. external calls) */
01894     SRGB_RGB                                = 1,    /* Loads the rgb texture */
01895     SRGB_SRGB                               = 2,    /* Loads the srgb texture */
01896 };
01897 
01898 struct gl_texture
01899 {
01900     DWORD                   states[MAX_WINETEXTURESTATES];
01901     BOOL                    dirty;
01902     GLuint                  name;
01903 };
01904 
01905 struct wined3d_texture_ops
01906 {
01907     HRESULT (*texture_bind)(struct wined3d_texture *texture,
01908             struct wined3d_context *context, BOOL srgb);
01909     void (*texture_preload)(struct wined3d_texture *texture, enum WINED3DSRGB srgb);
01910     void (*texture_sub_resource_add_dirty_region)(struct wined3d_resource *sub_resource,
01911             const struct wined3d_box *dirty_region);
01912     void (*texture_sub_resource_cleanup)(struct wined3d_resource *sub_resource);
01913 };
01914 
01915 #define WINED3D_TEXTURE_COND_NP2            0x1
01916 #define WINED3D_TEXTURE_POW2_MAT_IDENT      0x2
01917 #define WINED3D_TEXTURE_IS_SRGB             0x4
01918 
01919 struct wined3d_texture
01920 {
01921     struct wined3d_resource resource;
01922     const struct wined3d_texture_ops *texture_ops;
01923     struct gl_texture texture_rgb, texture_srgb;
01924     struct wined3d_resource **sub_resources;
01925     UINT layer_count;
01926     UINT level_count;
01927     float pow2_matrix[16];
01928     UINT lod;
01929     enum wined3d_texture_filter_type filter_type;
01930     LONG bind_count;
01931     DWORD sampler;
01932     DWORD flags;
01933     const struct min_lookup *min_mip_lookup;
01934     const GLenum *mag_lookup;
01935     GLenum target;
01936 };
01937 
01938 static inline struct wined3d_texture *wined3d_texture_from_resource(struct wined3d_resource *resource)
01939 {
01940     return CONTAINING_RECORD(resource, struct wined3d_texture, resource);
01941 }
01942 
01943 static inline struct gl_texture *wined3d_texture_get_gl_texture(struct wined3d_texture *texture,
01944         const struct wined3d_gl_info *gl_info, BOOL srgb)
01945 {
01946     return srgb && !gl_info->supported[EXT_TEXTURE_SRGB_DECODE]
01947             ? &texture->texture_srgb : &texture->texture_rgb;
01948 }
01949 
01950 void wined3d_texture_apply_state_changes(struct wined3d_texture *texture,
01951         const DWORD samplerStates[WINED3D_HIGHEST_SAMPLER_STATE + 1],
01952         const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
01953 void wined3d_texture_set_dirty(struct wined3d_texture *texture, BOOL dirty) DECLSPEC_HIDDEN;
01954 
01955 struct wined3d_volume
01956 {
01957     struct wined3d_resource resource;
01958     struct wined3d_texture *container;
01959     BOOL                    lockable;
01960     BOOL                    locked;
01961     struct wined3d_box lockedBox;
01962     struct wined3d_box dirtyBox;
01963     BOOL                    dirty;
01964 };
01965 
01966 static inline struct wined3d_volume *volume_from_resource(struct wined3d_resource *resource)
01967 {
01968     return CONTAINING_RECORD(resource, struct wined3d_volume, resource);
01969 }
01970 
01971 void volume_add_dirty_box(struct wined3d_volume *volume, const struct wined3d_box *dirty_box) DECLSPEC_HIDDEN;
01972 void volume_load(const struct wined3d_volume *volume, struct wined3d_context *context, UINT level, BOOL srgb_mode) DECLSPEC_HIDDEN;
01973 void volume_set_container(struct wined3d_volume *volume, struct wined3d_texture *container) DECLSPEC_HIDDEN;
01974 
01975 struct wined3d_surface_dib
01976 {
01977     HBITMAP DIBsection;
01978     void *bitmap_data;
01979     UINT bitmap_size;
01980 };
01981 
01982 struct wined3d_renderbuffer_entry
01983 {
01984     struct list entry;
01985     GLuint id;
01986     UINT width;
01987     UINT height;
01988 };
01989 
01990 struct fbo_entry
01991 {
01992     struct list entry;
01993     struct wined3d_surface **render_targets;
01994     struct wined3d_surface *depth_stencil;
01995     DWORD location;
01996     DWORD rt_mask;
01997     BOOL attached;
01998     GLuint id;
01999 };
02000 
02001 enum wined3d_container_type
02002 {
02003     WINED3D_CONTAINER_NONE = 0,
02004     WINED3D_CONTAINER_SWAPCHAIN,
02005     WINED3D_CONTAINER_TEXTURE,
02006 };
02007 
02008 struct wined3d_subresource_container
02009 {
02010     enum wined3d_container_type type;
02011     union
02012     {
02013         struct wined3d_swapchain *swapchain;
02014         struct wined3d_texture *texture;
02015         void *base;
02016     } u;
02017 };
02018 
02019 struct wined3d_surface_ops
02020 {
02021     HRESULT (*surface_private_setup)(struct wined3d_surface *surface);
02022     void (*surface_realize_palette)(struct wined3d_surface *surface);
02023     void (*surface_map)(struct wined3d_surface *surface, const RECT *rect, DWORD flags);
02024     void (*surface_unmap)(struct wined3d_surface *surface);
02025 };
02026 
02027 struct wined3d_surface
02028 {
02029     struct wined3d_resource resource;
02030     const struct wined3d_surface_ops *surface_ops;
02031     struct wined3d_subresource_container container;
02032     struct wined3d_palette *palette; /* D3D7 style palette handling */
02033     DWORD draw_binding;
02034 
02035     DWORD flags;
02036 
02037     WINED3DSURFTYPE surface_type;
02038     UINT                      pow2Width;
02039     UINT                      pow2Height;
02040 
02041     /* A method to retrieve the drawable size. Not in the Vtable to make it changeable */
02042     void (*get_drawable_size)(const struct wined3d_context *context, UINT *width, UINT *height);
02043 
02044     /* PBO */
02045     GLuint                    pbo;
02046     GLuint rb_multisample;
02047     GLuint rb_resolved;
02048     GLuint texture_name;
02049     GLuint texture_name_srgb;
02050     GLint texture_level;
02051     GLenum texture_target;
02052 
02053     RECT                      lockedRect;
02054     RECT                      dirtyRect;
02055     int                       lockCount;
02056 #define MAXLOCKCOUNT          50 /* After this amount of locks do not free the sysmem copy */
02057 
02058     /* For GetDC */
02059     struct wined3d_surface_dib dib;
02060     HDC                       hDC;
02061 
02062     /* Color keys for DDraw */
02063     struct wined3d_color_key dst_blt_color_key;
02064     struct wined3d_color_key src_blt_color_key;
02065     struct wined3d_color_key dst_overlay_color_key;
02066     struct wined3d_color_key src_overlay_color_key;
02067     DWORD                     CKeyFlags;
02068 
02069     struct wined3d_color_key gl_color_key;
02070 
02071     struct list               renderbuffers;
02072     const struct wined3d_renderbuffer_entry *current_renderbuffer;
02073     SIZE ds_current_size;
02074 
02075     /* DirectDraw Overlay handling */
02076     RECT                      overlay_srcrect;
02077     RECT                      overlay_destrect;
02078     struct wined3d_surface *overlay_dest;
02079     struct list               overlays;
02080     struct list               overlay_entry;
02081 };
02082 
02083 static inline struct wined3d_surface *surface_from_resource(struct wined3d_resource *resource)
02084 {
02085     return CONTAINING_RECORD(resource, struct wined3d_surface, resource);
02086 }
02087 
02088 static inline GLuint surface_get_texture_name(const struct wined3d_surface *surface,
02089         const struct wined3d_gl_info *gl_info, BOOL srgb)
02090 {
02091     return srgb && !gl_info->supported[EXT_TEXTURE_SRGB_DECODE]
02092             ? surface->texture_name_srgb : surface->texture_name;
02093 }
02094 
02095 void surface_add_dirty_rect(struct wined3d_surface *surface, const struct wined3d_box *dirty_rect) DECLSPEC_HIDDEN;
02096 void surface_bind(struct wined3d_surface *surface, struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
02097 HRESULT surface_color_fill(struct wined3d_surface *s,
02098         const RECT *rect, const struct wined3d_color *color) DECLSPEC_HIDDEN;
02099 GLenum surface_get_gl_buffer(const struct wined3d_surface *surface) DECLSPEC_HIDDEN;
02100 BOOL surface_init_sysmem(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
02101 void surface_internal_preload(struct wined3d_surface *surface, enum WINED3DSRGB srgb) DECLSPEC_HIDDEN;
02102 BOOL surface_is_offscreen(const struct wined3d_surface *surface) DECLSPEC_HIDDEN;
02103 HRESULT surface_load(struct wined3d_surface *surface, BOOL srgb) DECLSPEC_HIDDEN;
02104 void surface_load_ds_location(struct wined3d_surface *surface,
02105         struct wined3d_context *context, DWORD location) DECLSPEC_HIDDEN;
02106 void surface_load_fb_texture(struct wined3d_surface *surface, BOOL srgb) DECLSPEC_HIDDEN;
02107 HRESULT surface_load_location(struct wined3d_surface *surface, DWORD location, const RECT *rect) DECLSPEC_HIDDEN;
02108 void surface_modify_ds_location(struct wined3d_surface *surface, DWORD location, UINT w, UINT h) DECLSPEC_HIDDEN;
02109 void surface_modify_location(struct wined3d_surface *surface, DWORD location, BOOL persistent) DECLSPEC_HIDDEN;
02110 void surface_prepare_rb(struct wined3d_surface *surface,
02111         const struct wined3d_gl_info *gl_info, BOOL multisample) DECLSPEC_HIDDEN;
02112 void surface_prepare_texture(struct wined3d_surface *surface,
02113         struct wined3d_context *context, BOOL srgb) DECLSPEC_HIDDEN;
02114 void surface_set_compatible_renderbuffer(struct wined3d_surface *surface,
02115         const struct wined3d_surface *rt) DECLSPEC_HIDDEN;
02116 void surface_set_container(struct wined3d_surface *surface,
02117         enum wined3d_container_type type, void *container) DECLSPEC_HIDDEN;
02118 void surface_set_texture_name(struct wined3d_surface *surface, GLuint name, BOOL srgb_name) DECLSPEC_HIDDEN;
02119 void surface_set_texture_target(struct wined3d_surface *surface, GLenum target) DECLSPEC_HIDDEN;
02120 void surface_translate_drawable_coords(const struct wined3d_surface *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN;
02121 void surface_update_draw_binding(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
02122 HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const POINT *dst_point,
02123         struct wined3d_surface *src_surface, const RECT *src_rect) DECLSPEC_HIDDEN;
02124 
02125 void get_drawable_size_swapchain(const struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
02126 void get_drawable_size_backbuffer(const struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
02127 void get_drawable_size_fbo(const struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
02128 
02129 void draw_textured_quad(const struct wined3d_surface *src_surface, struct wined3d_context *context,
02130         const RECT *src_rect, const RECT *dst_rect, enum wined3d_texture_filter_type filter) DECLSPEC_HIDDEN;
02131 void flip_surface(struct wined3d_surface *front, struct wined3d_surface *back) DECLSPEC_HIDDEN;
02132 
02133 /* Surface flags: */
02134 #define SFLAG_CONVERTED         0x00000001 /* Converted for color keying or palettized. */
02135 #define SFLAG_DISCARD           0x00000002 /* ??? */
02136 #define SFLAG_NONPOW2           0x00000004 /* Surface sizes are not a power of 2 */
02137 #define SFLAG_NORMCOORD         0x00000008 /* Set if GL texture coordinates are normalized (non-texture rectangle). */
02138 #define SFLAG_LOCKABLE          0x00000010 /* Surface can be locked. */
02139 #define SFLAG_DYNLOCK           0x00000020 /* Surface is often locked by the application. */
02140 #define SFLAG_LOCKED            0x00000040 /* Surface is currently locked. */
02141 #define SFLAG_DCINUSE           0x00000080 /* Set between GetDC and ReleaseDC calls. */
02142 #define SFLAG_LOST              0x00000100 /* Surface lost flag for ddraw. */
02143 #define SFLAG_GLCKEY            0x00000200 /* The GL texture was created with a color key. */
02144 #define SFLAG_CLIENT            0x00000400 /* GL_APPLE_client_storage is used with this surface. */
02145 #define SFLAG_INOVERLAYDRAW     0x00000800 /* Overlay drawing is in progress. Recursion prevention. */
02146 #define SFLAG_DIBSECTION        0x00001000 /* Has a DIB section attached for GetDC. */
02147 #define SFLAG_USERPTR           0x00002000 /* The application allocated the memory for this surface. */
02148 #define SFLAG_ALLOCATED         0x00004000 /* A GL texture is allocated for this surface. */
02149 #define SFLAG_SRGBALLOCATED     0x00008000 /* A sRGB GL texture is allocated for this surface. */
02150 #define SFLAG_PBO               0x00010000 /* The surface has a PBO. */
02151 #define SFLAG_INSYSMEM          0x00020000 /* The system memory copy is current. */
02152 #define SFLAG_INTEXTURE         0x00040000 /* The GL texture is current. */
02153 #define SFLAG_INSRGBTEX         0x00080000 /* The GL sRGB texture is current. */
02154 #define SFLAG_INDRAWABLE        0x00100000 /* The GL drawable is current. */
02155 #define SFLAG_INRB_MULTISAMPLE  0x00200000 /* The multisample renderbuffer is current. */
02156 #define SFLAG_INRB_RESOLVED     0x00400000 /* The resolved renderbuffer is current. */
02157 #define SFLAG_PIN_SYSMEM        0x02000000 /* Keep the surface in sysmem, at the same address. */
02158 
02159 /* In some conditions the surface memory must not be freed:
02160  * SFLAG_CONVERTED: Converting the data back would take too long
02161  * SFLAG_DIBSECTION: The dib code manages the memory
02162  * SFLAG_LOCKED: The app requires access to the surface data
02163  * SFLAG_DYNLOCK: Avoid freeing the data for performance
02164  * SFLAG_PBO: PBOs don't use 'normal' memory. It is either allocated by the driver or must be NULL.
02165  * SFLAG_CLIENT: OpenGL uses our memory as backup
02166  */
02167 #define SFLAG_DONOTFREE     (SFLAG_CONVERTED        | \
02168                              SFLAG_DYNLOCK          | \
02169                              SFLAG_LOCKED           | \
02170                              SFLAG_CLIENT           | \
02171                              SFLAG_DIBSECTION       | \
02172                              SFLAG_USERPTR          | \
02173                              SFLAG_PBO              | \
02174                              SFLAG_PIN_SYSMEM)
02175 
02176 #define SFLAG_LOCATIONS     (SFLAG_INSYSMEM         | \
02177                              SFLAG_INTEXTURE        | \
02178                              SFLAG_INSRGBTEX        | \
02179                              SFLAG_INDRAWABLE       | \
02180                              SFLAG_INRB_MULTISAMPLE | \
02181                              SFLAG_INRB_RESOLVED)
02182 
02183 typedef enum {
02184     NO_CONVERSION,
02185     CONVERT_PALETTED,
02186     CONVERT_PALETTED_CK,
02187     CONVERT_CK_565,
02188     CONVERT_CK_5551,
02189     CONVERT_CK_RGB24,
02190     CONVERT_RGB32_888
02191 } CONVERT_TYPES;
02192 
02193 HRESULT d3dfmt_get_conv(const struct wined3d_surface *surface, BOOL need_alpha_ck, BOOL use_texturing,
02194         struct wined3d_format *format, CONVERT_TYPES *convert) DECLSPEC_HIDDEN;
02195 void d3dfmt_p8_init_palette(const struct wined3d_surface *surface, BYTE table[256][4], BOOL colorkey) DECLSPEC_HIDDEN;
02196 
02197 struct wined3d_vertex_declaration_element
02198 {
02199     const struct wined3d_format *format;
02200     BOOL ffp_valid;
02201     WORD input_slot;
02202     WORD offset;
02203     UINT output_slot;
02204     BYTE method;
02205     BYTE usage;
02206     BYTE usage_idx;
02207 };
02208 
02209 struct wined3d_vertex_declaration
02210 {
02211     LONG ref;
02212     void *parent;
02213     const struct wined3d_parent_ops *parent_ops;
02214     struct wined3d_device *device;
02215 
02216     struct wined3d_vertex_declaration_element *elements;
02217     UINT element_count;
02218 
02219     DWORD                   streams[MAX_STREAMS];
02220     UINT                    num_streams;
02221     BOOL                    position_transformed;
02222     BOOL                    half_float_conv_needed;
02223 };
02224 
02225 struct wined3d_saved_states
02226 {
02227     DWORD transform[(HIGHEST_TRANSFORMSTATE >> 5) + 1];
02228     WORD streamSource;                          /* MAX_STREAMS, 16 */
02229     WORD streamFreq;                            /* MAX_STREAMS, 16 */
02230     DWORD renderState[(WINEHIGHEST_RENDER_STATE >> 5) + 1];
02231     DWORD textureState[MAX_TEXTURES];           /* WINED3D_HIGHEST_TEXTURE_STATE + 1, 18 */
02232     WORD samplerState[MAX_COMBINED_SAMPLERS];   /* WINED3D_HIGHEST_SAMPLER_STATE + 1, 14 */
02233     DWORD clipplane;                            /* WINED3DMAXUSERCLIPPLANES, 32 */
02234     WORD pixelShaderConstantsB;                 /* MAX_CONST_B, 16 */
02235     WORD pixelShaderConstantsI;                 /* MAX_CONST_I, 16 */
02236     BOOL *pixelShaderConstantsF;
02237     WORD vertexShaderConstantsB;                /* MAX_CONST_B, 16 */
02238     WORD vertexShaderConstantsI;                /* MAX_CONST_I, 16 */
02239     BOOL *vertexShaderConstantsF;
02240     DWORD textures : 20;                        /* MAX_COMBINED_SAMPLERS, 20 */
02241     DWORD primitive_type : 1;
02242     DWORD indices : 1;
02243     DWORD material : 1;
02244     DWORD viewport : 1;
02245     DWORD vertexDecl : 1;
02246     DWORD pixelShader : 1;
02247     DWORD vertexShader : 1;
02248     DWORD scissorRect : 1;
02249     DWORD padding : 4;
02250 };
02251 
02252 struct StageState {
02253     DWORD stage;
02254     DWORD state;
02255 };
02256 
02257 struct wined3d_stream_state
02258 {
02259     struct wined3d_buffer *buffer;
02260     UINT offset;
02261     UINT stride;
02262     UINT frequency;
02263     UINT flags;
02264 };
02265 
02266 struct wined3d_state
02267 {
02268     const struct wined3d_fb_state *fb;
02269 
02270     struct wined3d_vertex_declaration *vertex_declaration;
02271     struct wined3d_stream_state streams[MAX_STREAMS + 1 /* tesselated pseudo-stream */];
02272     BOOL user_stream;
02273     struct wined3d_buffer *index_buffer;
02274     enum wined3d_format_id index_format;
02275     INT base_vertex_index;
02276     INT load_base_vertex_index; /* Non-indexed drawing needs 0 here, indexed needs base_vertex_index. */
02277     GLenum gl_primitive_type;
02278 
02279     struct wined3d_shader *vertex_shader;
02280     BOOL vs_consts_b[MAX_CONST_B];
02281     INT vs_consts_i[MAX_CONST_I * 4];
02282     float *vs_consts_f;
02283 
02284     struct wined3d_shader *pixel_shader;
02285     BOOL ps_consts_b[MAX_CONST_B];
02286     INT ps_consts_i[MAX_CONST_I * 4];
02287     float *ps_consts_f;
02288 
02289     struct wined3d_texture *textures[MAX_COMBINED_SAMPLERS];
02290     DWORD sampler_states[MAX_COMBINED_SAMPLERS][WINED3D_HIGHEST_SAMPLER_STATE + 1];
02291     DWORD texture_states[MAX_TEXTURES][WINED3D_HIGHEST_TEXTURE_STATE + 1];
02292     DWORD lowest_disabled_stage;
02293 
02294     struct wined3d_matrix transforms[HIGHEST_TRANSFORMSTATE + 1];
02295     double clip_planes[MAX_CLIPPLANES][4];
02296     struct wined3d_material material;
02297     struct wined3d_viewport viewport;
02298     RECT scissor_rect;
02299 
02300     /* Light hashmap . Collisions are handled using standard wine double linked lists */
02301 #define LIGHTMAP_SIZE 43 /* Use of a prime number recommended. Set to 1 for a linked list! */
02302 #define LIGHTMAP_HASHFUNC(x) ((x) % LIGHTMAP_SIZE) /* Primitive and simple function */
02303     struct list light_map[LIGHTMAP_SIZE]; /* Hash map containing the lights */
02304     const struct wined3d_light_info *lights[MAX_ACTIVE_LIGHTS]; /* Map of opengl lights to d3d lights */
02305 
02306     DWORD render_states[WINEHIGHEST_RENDER_STATE + 1];
02307 };
02308 
02309 struct wined3d_stateblock
02310 {
02311     LONG                      ref;     /* Note: Ref counting not required */
02312     struct wined3d_device *device;
02313     enum wined3d_stateblock_type blockType;
02314 
02315     /* Array indicating whether things have been set or changed */
02316     struct wined3d_saved_states changed;
02317     struct wined3d_state state;
02318 
02319     /* Contained state management */
02320     DWORD                     contained_render_states[WINEHIGHEST_RENDER_STATE + 1];
02321     unsigned int              num_contained_render_states;
02322     DWORD                     contained_transform_states[HIGHEST_TRANSFORMSTATE + 1];
02323     unsigned int              num_contained_transform_states;
02324     DWORD                     contained_vs_consts_i[MAX_CONST_I];
02325     unsigned int              num_contained_vs_consts_i;
02326     DWORD                     contained_vs_consts_b[MAX_CONST_B];
02327     unsigned int              num_contained_vs_consts_b;
02328     DWORD                     *contained_vs_consts_f;
02329     unsigned int              num_contained_vs_consts_f;
02330     DWORD                     contained_ps_consts_i[MAX_CONST_I];
02331     unsigned int              num_contained_ps_consts_i;
02332     DWORD                     contained_ps_consts_b[MAX_CONST_B];
02333     unsigned int              num_contained_ps_consts_b;
02334     DWORD                     *contained_ps_consts_f;
02335     unsigned int              num_contained_ps_consts_f;
02336     struct StageState         contained_tss_states[MAX_TEXTURES * (WINED3D_HIGHEST_TEXTURE_STATE + 1)];
02337     unsigned int              num_contained_tss_states;
02338     struct StageState         contained_sampler_states[MAX_COMBINED_SAMPLERS * WINED3D_HIGHEST_SAMPLER_STATE];
02339     unsigned int              num_contained_sampler_states;
02340 };
02341 
02342 void stateblock_init_contained_states(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN;
02343 void stateblock_init_default_state(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN;
02344 void stateblock_unbind_resources(struct wined3d_stateblock *stateblock) DECLSPEC_HIDDEN;
02345 
02346 /* Direct3D terminology with little modifications. We do not have an issued state
02347  * because only the driver knows about it, but we have a created state because d3d
02348  * allows GetData on a created issue, but opengl doesn't
02349  */
02350 enum query_state {
02351     QUERY_CREATED,
02352     QUERY_SIGNALLED,
02353     QUERY_BUILDING
02354 };
02355 
02356 struct wined3d_query_ops
02357 {
02358     HRESULT (*query_get_data)(struct wined3d_query *query, void *data, DWORD data_size, DWORD flags);
02359     HRESULT (*query_issue)(struct wined3d_query *query, DWORD flags);
02360 };
02361 
02362 struct wined3d_query
02363 {
02364     LONG ref;
02365     const struct wined3d_query_ops *query_ops;
02366     struct wined3d_device *device;
02367     enum query_state         state;
02368     enum wined3d_query_type type;
02369     DWORD data_size;
02370     void                     *extendedData;
02371 };
02372 
02373 /* TODO: Add tests and support for FLOAT16_4 POSITIONT, D3DCOLOR position, other
02374  * fixed function semantics as D3DCOLOR or FLOAT16 */
02375 enum wined3d_buffer_conversion_type
02376 {
02377     CONV_NONE,
02378     CONV_D3DCOLOR,
02379     CONV_POSITIONT,
02380 };
02381 
02382 struct wined3d_map_range
02383 {
02384     UINT offset;
02385     UINT size;
02386 };
02387 
02388 #define WINED3D_BUFFER_OPTIMIZED    0x01    /* Optimize has been called for the buffer */
02389 #define WINED3D_BUFFER_HASDESC      0x02    /* A vertex description has been found */
02390 #define WINED3D_BUFFER_CREATEBO     0x04    /* Attempt to create a buffer object next PreLoad */
02391 #define WINED3D_BUFFER_DOUBLEBUFFER 0x08    /* Use a vbo and local allocated memory */
02392 #define WINED3D_BUFFER_FLUSH        0x10    /* Manual unmap flushing */
02393 #define WINED3D_BUFFER_DISCARD      0x20    /* A DISCARD lock has occurred since the last PreLoad */
02394 #define WINED3D_BUFFER_NOSYNC       0x40    /* All locks since the last PreLoad had NOOVERWRITE set */
02395 #define WINED3D_BUFFER_APPLESYNC    0x80    /* Using sync as in GL_APPLE_flush_buffer_range */
02396 
02397 struct wined3d_buffer
02398 {
02399     struct wined3d_resource resource;
02400 
02401     struct wined3d_buffer_desc desc;
02402 
02403     GLuint buffer_object;
02404     GLenum buffer_object_usage;
02405     GLenum buffer_type_hint;
02406     UINT buffer_object_size;
02407     LONG bind_count;
02408     DWORD flags;
02409 
02410     LONG lock_count;
02411     struct wined3d_map_range *maps;
02412     ULONG maps_size, modified_areas;
02413     struct wined3d_event_query *query;
02414 
02415     /* conversion stuff */
02416     UINT decl_change_count, full_conversion_count;
02417     UINT draw_count;
02418     UINT stride;                                            /* 0 if no conversion */
02419     UINT conversion_stride;                                 /* 0 if no shifted conversion */
02420     enum wined3d_buffer_conversion_type *conversion_map;    /* NULL if no conversion */
02421 };
02422 
02423 static inline struct wined3d_buffer *buffer_from_resource(struct wined3d_resource *resource)
02424 {
02425     return CONTAINING_RECORD(resource, struct wined3d_buffer, resource);
02426 }
02427 
02428 void buffer_get_memory(struct wined3d_buffer *buffer, const struct wined3d_gl_info *gl_info,
02429         struct wined3d_bo_address *data) DECLSPEC_HIDDEN;
02430 BYTE *buffer_get_sysmem(struct wined3d_buffer *This, const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
02431 
02432 struct wined3d_rendertarget_view
02433 {
02434     LONG refcount;
02435 
02436     struct wined3d_resource *resource;
02437     void *parent;
02438 };
02439 
02440 struct wined3d_swapchain_ops
02441 {
02442     HRESULT (*swapchain_present)(struct wined3d_swapchain *swapchain, const RECT *src_rect,
02443             const RECT *dst_rect, const RGNDATA *dirty_region, DWORD flags);
02444 };
02445 
02446 struct wined3d_swapchain
02447 {
02448     LONG ref;
02449     void *parent;
02450     const struct wined3d_parent_ops *parent_ops;
02451     const struct wined3d_swapchain_ops *swapchain_ops;
02452     struct wined3d_device *device;
02453 
02454     struct wined3d_surface **back_buffers;
02455     struct wined3d_surface *front_buffer;
02456     struct wined3d_swapchain_desc desc;
02457     DWORD orig_width, orig_height;
02458     enum wined3d_format_id orig_fmt;
02459     struct wined3d_gamma_ramp orig_gamma;
02460     BOOL render_to_fbo;
02461     const struct wined3d_format *ds_format;
02462 
02463     LONG prev_time, frames;   /* Performance tracking */
02464 
02465     struct wined3d_context **context;
02466     unsigned int num_contexts;
02467 
02468     HWND win_handle;
02469     HWND device_window;
02470 
02471     HDC backup_dc;
02472     HWND backup_wnd;
02473 };
02474 
02475 void x11_copy_to_screen(const struct wined3d_swapchain *swapchain, const RECT *rect) DECLSPEC_HIDDEN;
02476 
02477 struct wined3d_context *swapchain_get_context(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
02478 void swapchain_destroy_contexts(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
02479 HDC swapchain_get_backup_dc(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
02480 void swapchain_update_draw_bindings(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
02481 void swapchain_update_render_to_fbo(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
02482 
02483 #define DEFAULT_REFRESH_RATE 0
02484 
02485 /*****************************************************************************
02486  * Utility function prototypes
02487  */
02488 
02489 /* Trace routines */
02490 const char *debug_d3dformat(enum wined3d_format_id format_id) DECLSPEC_HIDDEN;
02491 const char *debug_d3ddevicetype(enum wined3d_device_type device_type) DECLSPEC_HIDDEN;
02492 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type) DECLSPEC_HIDDEN;
02493 const char *debug_d3dusage(DWORD usage) DECLSPEC_HIDDEN;
02494 const char *debug_d3dusagequery(DWORD usagequery) DECLSPEC_HIDDEN;
02495 const char *debug_d3ddeclmethod(WINED3DDECLMETHOD method) DECLSPEC_HIDDEN;
02496 const char *debug_d3ddeclusage(BYTE usage) DECLSPEC_HIDDEN;
02497 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type) DECLSPEC_HIDDEN;
02498 const char *debug_d3drenderstate(enum wined3d_render_state state) DECLSPEC_HIDDEN;
02499 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state) DECLSPEC_HIDDEN;
02500 const char *debug_d3dstate(DWORD state) DECLSPEC_HIDDEN;
02501 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type) DECLSPEC_HIDDEN;
02502 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state) DECLSPEC_HIDDEN;
02503 const char *debug_d3dtstype(enum wined3d_transform_state tstype) DECLSPEC_HIDDEN;
02504 const char *debug_d3dpool(enum wined3d_pool pool) DECLSPEC_HIDDEN;
02505 const char *debug_fbostatus(GLenum status) DECLSPEC_HIDDEN;
02506 const char *debug_glerror(GLenum error) DECLSPEC_HIDDEN;
02507 const char *debug_d3dbasis(enum wined3d_basis_type basis) DECLSPEC_HIDDEN;
02508 const char *debug_d3ddegree(enum wined3d_degree_type order) DECLSPEC_HIDDEN;
02509 const char *debug_d3dtop(enum wined3d_texture_op d3dtop) DECLSPEC_HIDDEN;
02510 void dump_color_fixup_desc(struct color_fixup_desc fixup) DECLSPEC_HIDDEN;
02511 const char *debug_surflocation(DWORD flag) DECLSPEC_HIDDEN;
02512 
02513 BOOL is_invalid_op(const struct wined3d_state *state, int stage,
02514         enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3) DECLSPEC_HIDDEN;
02515 void set_tex_op_nvrc(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state,
02516         BOOL is_alpha, int stage, enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3,
02517         INT texture_idx, DWORD dst) DECLSPEC_HIDDEN;
02518 void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords,
02519         BOOL transformed, enum wined3d_format_id coordtype, BOOL ffp_can_disable_proj) DECLSPEC_HIDDEN;
02520 void texture_activate_dimensions(const struct wined3d_texture *texture,
02521         const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
02522 void sampler_texdim(struct wined3d_context *context,
02523         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
02524 void tex_alphaop(struct wined3d_context *context,
02525         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
02526 void apply_pixelshader(struct wined3d_context *context,
02527         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
02528 void state_fogcolor(struct wined3d_context *context,
02529         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
02530 void state_fogdensity(struct wined3d_context *context,
02531         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
02532 void state_fogstartend(struct wined3d_context *context,
02533         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
02534 void state_fog_fragpart(struct wined3d_context *context,
02535         const struct wined3d_state *state, DWORD state_id) DECLSPEC_HIDDEN;
02536 
02537 BOOL getColorBits(const struct wined3d_format *format,
02538         BYTE *redSize, BYTE *greenSize, BYTE *blueSize, BYTE *alphaSize, BYTE *totalSize) DECLSPEC_HIDDEN;
02539 BOOL getDepthStencilBits(const struct wined3d_format *format,
02540         BYTE *depthSize, BYTE *stencilSize) DECLSPEC_HIDDEN;
02541 
02542 /* Math utils */
02543 void multiply_matrix(struct wined3d_matrix *dest, const struct wined3d_matrix *src1,
02544         const struct wined3d_matrix *src2) DECLSPEC_HIDDEN;
02545 UINT wined3d_log2i(UINT32 x) DECLSPEC_HIDDEN;
02546 unsigned int count_bits(unsigned int mask) DECLSPEC_HIDDEN;
02547 
02548 void select_shader_mode(const struct wined3d_gl_info *gl_info, int *ps_selected, int *vs_selected) DECLSPEC_HIDDEN;
02549 
02550 struct wined3d_shader_lconst
02551 {
02552     struct list entry;
02553     unsigned int idx;
02554     DWORD value[4];
02555 };
02556 
02557 struct wined3d_shader_limits
02558 {
02559     unsigned int temporary;
02560     unsigned int texcoord;
02561     unsigned int sampler;
02562     unsigned int constant_int;
02563     unsigned int constant_float;
02564     unsigned int constant_bool;
02565     unsigned int address;
02566     unsigned int packed_output;
02567     unsigned int packed_input;
02568     unsigned int attributes;
02569     unsigned int label;
02570 };
02571 
02572 #ifdef __GNUC__
02573 #define PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)))
02574 #else
02575 #define PRINTF_ATTR(fmt,args)
02576 #endif
02577 
02578 /* Base Shader utility functions. */
02579 int shader_addline(struct wined3d_shader_buffer *buffer, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
02580 int shader_vaddline(struct wined3d_shader_buffer *buffer, const char *fmt, va_list args) DECLSPEC_HIDDEN;
02581 
02582 /* Vertex shader utility functions */
02583 BOOL vshader_get_input(const struct wined3d_shader *shader,
02584         BYTE usage_req, BYTE usage_idx_req, unsigned int *regnum) DECLSPEC_HIDDEN;
02585 
02586 struct wined3d_vertex_shader
02587 {
02588     struct wined3d_shader_attribute attributes[MAX_ATTRIBS];
02589 };
02590 
02591 struct wined3d_pixel_shader
02592 {
02593     /* Pixel shader input semantics */
02594     DWORD input_reg_map[MAX_REG_INPUT];
02595     BOOL input_reg_used[MAX_REG_INPUT];
02596     unsigned int declared_in_count;
02597 
02598     /* Some information about the shader behavior */
02599     BOOL color0_mov;
02600     DWORD color0_reg;
02601 };
02602 
02603 struct wined3d_shader
02604 {
02605     LONG ref;
02606     struct wined3d_shader_limits limits;
02607     DWORD *function;
02608     UINT functionLength;
02609     BOOL load_local_constsF;
02610     const struct wined3d_shader_frontend *frontend;
02611     void *frontend_data;
02612     void *backend_data;
02613 
02614     void *parent;
02615     const struct wined3d_parent_ops *parent_ops;
02616 
02617     /* Programs this shader is linked with */
02618     struct list linked_programs;
02619 
02620     /* Immediate constants (override global ones) */
02621     struct list constantsB;
02622     struct list constantsF;
02623     struct list constantsI;
02624     struct wined3d_shader_reg_maps reg_maps;
02625 
02626     struct wined3d_shader_signature_element input_signature[max(MAX_ATTRIBS, MAX_REG_INPUT)];
02627     struct wined3d_shader_signature_element output_signature[MAX_REG_OUTPUT];
02628 
02629     /* Pointer to the parent device */
02630     struct wined3d_device *device;
02631     struct list shader_list_entry;
02632 
02633     union
02634     {
02635         struct wined3d_vertex_shader vs;
02636         struct wined3d_pixel_shader ps;
02637     } u;
02638 };
02639 
02640 void pixelshader_update_samplers(struct wined3d_shader_reg_maps *reg_maps,
02641         struct wined3d_texture * const *textures) DECLSPEC_HIDDEN;
02642 void find_ps_compile_args(const struct wined3d_state *state,
02643         const struct wined3d_shader *shader, struct ps_compile_args *args) DECLSPEC_HIDDEN;
02644 
02645 void find_vs_compile_args(const struct wined3d_state *state,
02646         const struct wined3d_shader *shader, struct vs_compile_args *args) DECLSPEC_HIDDEN;
02647 
02648 void shader_buffer_clear(struct wined3d_shader_buffer *buffer) DECLSPEC_HIDDEN;
02649 BOOL shader_buffer_init(struct wined3d_shader_buffer *buffer) DECLSPEC_HIDDEN;
02650 void shader_buffer_free(struct wined3d_shader_buffer *buffer) DECLSPEC_HIDDEN;
02651 void shader_dump_src_param(const struct wined3d_shader_src_param *param,
02652         const struct wined3d_shader_version *shader_version) DECLSPEC_HIDDEN;
02653 void shader_dump_dst_param(const struct wined3d_shader_dst_param *param,
02654         const struct wined3d_shader_version *shader_version) DECLSPEC_HIDDEN;
02655 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps *reg_maps,
02656         unsigned int max) DECLSPEC_HIDDEN;
02657 void shader_generate_main(const struct wined3d_shader *shader, struct wined3d_shader_buffer *buffer,
02658         const struct wined3d_shader_reg_maps *reg_maps, const DWORD *byte_code, void *backend_ctx) DECLSPEC_HIDDEN;
02659 BOOL shader_match_semantic(const char *semantic_name, WINED3DDECLUSAGE usage) DECLSPEC_HIDDEN;
02660 
02661 static inline BOOL shader_is_pshader_version(enum wined3d_shader_type type)
02662 {
02663     return type == WINED3D_SHADER_TYPE_PIXEL;
02664 }
02665 
02666 static inline BOOL shader_is_vshader_version(enum wined3d_shader_type type)
02667 {
02668     return type == WINED3D_SHADER_TYPE_VERTEX;
02669 }
02670 
02671 static inline BOOL shader_is_scalar(const struct wined3d_shader_register *reg)
02672 {
02673     switch (reg->type)
02674     {
02675         case WINED3DSPR_RASTOUT:
02676             /* oFog & oPts */
02677             if (reg->idx) return TRUE;
02678             /* oPos */
02679             return FALSE;
02680 
02681         case WINED3DSPR_DEPTHOUT:   /* oDepth */
02682         case WINED3DSPR_CONSTBOOL:  /* b# */
02683         case WINED3DSPR_LOOP:       /* aL */
02684         case WINED3DSPR_PREDICATE:  /* p0 */
02685             return TRUE;
02686 
02687         case WINED3DSPR_MISCTYPE:
02688             switch(reg->idx)
02689             {
02690                 case 0: /* vPos */
02691                     return FALSE;
02692                 case 1: /* vFace */
02693                     return TRUE;
02694                 default:
02695                     return FALSE;
02696             }
02697 
02698         case WINED3DSPR_IMMCONST:
02699             return reg->immconst_type == WINED3D_IMMCONST_SCALAR;
02700 
02701         default:
02702             return FALSE;
02703     }
02704 }
02705 
02706 static inline void shader_get_position_fixup(const struct wined3d_context *context,
02707         const struct wined3d_state *state, float *position_fixup)
02708 {
02709     position_fixup[0] = 1.0f;
02710     position_fixup[1] = 1.0f;
02711     position_fixup[2] = (63.0f / 64.0f) / state->viewport.width;
02712     position_fixup[3] = -(63.0f / 64.0f) / state->viewport.height;
02713 
02714     if (context->render_offscreen)
02715     {
02716         position_fixup[1] *= -1.0f;
02717         position_fixup[3] *= -1.0f;
02718     }
02719 }
02720 
02721 static inline BOOL shader_constant_is_local(const struct wined3d_shader *shader, DWORD reg)
02722 {
02723     struct wined3d_shader_lconst *lconst;
02724 
02725     if (shader->load_local_constsF)
02726         return FALSE;
02727 
02728     LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry)
02729     {
02730         if (lconst->idx == reg)
02731             return TRUE;
02732     }
02733 
02734     return FALSE;
02735 }
02736 
02737 /* Using additional shader constants (uniforms in GLSL / program environment
02738  * or local parameters in ARB) is costly:
02739  * ARB only knows float4 parameters and GLSL compiler are not really smart
02740  * when it comes to efficiently pack float2 uniforms, so no space is wasted
02741  * (in fact most compilers map a float2 to a full float4 uniform).
02742  *
02743  * For NP2 texcoord fixup we only need 2 floats (width and height) for each
02744  * 2D texture used in the shader. We therefore pack fixup info for 2 textures
02745  * into a single shader constant (uniform / program parameter).
02746  *
02747  * This structure is shared between the GLSL and the ARB backend.*/
02748 struct ps_np2fixup_info {
02749     unsigned char     idx[MAX_FRAGMENT_SAMPLERS]; /* indices to the real constant */
02750     WORD              active; /* bitfield indicating if we can apply the fixup */
02751     WORD              num_consts;
02752 };
02753 
02754 /* sRGB correction constants */
02755 static const float srgb_cmp = 0.0031308f;
02756 static const float srgb_mul_low = 12.92f;
02757 static const float srgb_pow = 0.41666f;
02758 static const float srgb_mul_high = 1.055f;
02759 static const float srgb_sub_high = 0.055f;
02760 
02761 struct wined3d_palette
02762 {
02763     LONG ref;
02764     void *parent;
02765     struct wined3d_device *device;
02766 
02767     HPALETTE                   hpal;
02768     WORD                       palVersion;     /*|               */
02769     WORD                       palNumEntries;  /*|  LOGPALETTE   */
02770     PALETTEENTRY               palents[256];   /*|               */
02771     /* This is to store the palette in 'screen format' */
02772     int                        screen_palents[256];
02773     DWORD flags;
02774 };
02775 
02776 /* DirectDraw utility functions */
02777 extern enum wined3d_format_id pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN;
02778 
02779 /*****************************************************************************
02780  * Pixel format management
02781  */
02782 
02783 /* WineD3D pixel format flags */
02784 #define WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING    0x00000001
02785 #define WINED3DFMT_FLAG_FILTERING                   0x00000002
02786 #define WINED3DFMT_FLAG_DEPTH                       0x00000004
02787 #define WINED3DFMT_FLAG_STENCIL                     0x00000008
02788 #define WINED3DFMT_FLAG_RENDERTARGET                0x00000010
02789 #define WINED3DFMT_FLAG_FOURCC                      0x00000020
02790 #define WINED3DFMT_FLAG_FBO_ATTACHABLE              0x00000040
02791 #define WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB         0x00000080
02792 #define WINED3DFMT_FLAG_GETDC                       0x00000100
02793 #define WINED3DFMT_FLAG_FLOAT                       0x00000200
02794 #define WINED3DFMT_FLAG_BUMPMAP                     0x00000400
02795 #define WINED3DFMT_FLAG_SRGB_READ                   0x00000800
02796 #define WINED3DFMT_FLAG_SRGB_WRITE                  0x00001000
02797 #define WINED3DFMT_FLAG_VTF                         0x00002000
02798 #define WINED3DFMT_FLAG_SHADOW                      0x00004000
02799 #define WINED3DFMT_FLAG_COMPRESSED                  0x00008000
02800 #define WINED3DFMT_FLAG_BROKEN_PITCH                0x00010000
02801 #define WINED3DFMT_FLAG_BLOCKS                      0x00020000
02802 
02803 struct wined3d_format
02804 {
02805     enum wined3d_format_id id;
02806 
02807     DWORD red_mask;
02808     DWORD green_mask;
02809     DWORD blue_mask;
02810     DWORD alpha_mask;
02811     UINT byte_count;
02812     BYTE depth_size;
02813     BYTE stencil_size;
02814 
02815     UINT block_width;
02816     UINT block_height;
02817     UINT block_byte_count;
02818 
02819     enum wined3d_ffp_emit_idx emit_idx;
02820     GLint component_count;
02821     GLenum gl_vtx_type;
02822     GLint gl_vtx_format;
02823     GLboolean gl_normalized;
02824     unsigned int component_size;
02825 
02826     GLint glInternal;
02827     GLint glGammaInternal;
02828     GLint rtInternal;
02829     GLint glFormat;
02830     GLint glType;
02831     UINT  conv_byte_count;
02832     unsigned int flags;
02833     float heightscale;
02834     struct color_fixup_desc color_fixup;
02835     void (*convert)(const BYTE *src, BYTE *dst, UINT pitch, UINT width, UINT height);
02836 };
02837 
02838 const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl_info,
02839         enum wined3d_format_id format_id) DECLSPEC_HIDDEN;
02840 UINT wined3d_format_calculate_size(const struct wined3d_format *format,
02841         UINT alignment, UINT width, UINT height) DECLSPEC_HIDDEN;
02842 DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface,
02843         const struct wined3d_color *color) DECLSPEC_HIDDEN;
02844 
02845 static inline BOOL use_vs(const struct wined3d_state *state)
02846 {
02847     /* Check stateblock->vertexDecl to allow this to be used from
02848      * IWineD3DDeviceImpl_FindTexUnitMap(). This is safe because
02849      * stateblock->vertexShader implies a vertex declaration instead of ddraw
02850      * style strided data. */
02851     return state->vertex_shader && !state->vertex_declaration->position_transformed;
02852 }
02853 
02854 static inline BOOL use_ps(const struct wined3d_state *state)
02855 {
02856     return !!state->pixel_shader;
02857 }
02858 
02859 static inline void context_apply_state(struct wined3d_context *context,
02860         const struct wined3d_state *state, DWORD state_id)
02861 {
02862     const struct StateEntry *state_table = context->state_table;
02863     DWORD rep = state_table[state_id].representative;
02864     state_table[rep].apply(context, state, rep);
02865 }
02866 
02867 /* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */
02868 #define WINED3D_OPENGL_WINDOW_CLASS_NAME "WineD3D_OpenGL"
02869 
02870 #define MAKEDWORD_VERSION(maj, min) (((maj & 0xffff) << 16) | (min & 0xffff))
02871 
02872 #endif

Generated on Sun May 27 2012 04:22:27 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.