##########################################################################
#
# Copyright 2008-2009 VMware, Inc.
# All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
##########################################################################/

"""d3d8types.h"""

from .winapi import *

D3DCOLOR = Alias("D3DCOLOR", DWORD)

D3DVECTOR = Struct("D3DVECTOR", [
    (Float, "x"),
    (Float, "y"),
    (Float, "z"),
])

D3DCOLORVALUE = Struct("D3DCOLORVALUE", [
    (Float, "r"),
    (Float, "g"),
    (Float, "b"),
    (Float, "a"),
])

D3DRECT = Struct("D3DRECT", [
    (LONG, "x1"),
    (LONG, "y1"),
    (LONG, "x2"),
    (LONG, "y2"),
])

D3DMATRIX = Struct("D3DMATRIX", [
    (Array(Array(Float, 4), 4), "m"),
])

D3DVIEWPORT8 = Struct("D3DVIEWPORT8", [
    (DWORD, "X"),
    (DWORD, "Y"),
    (DWORD, "Width"),
    (DWORD, "Height"),
    (Float, "MinZ"),
    (Float, "MaxZ"),
])

D3DCLIPPLANE = Flags(DWORD, [
    "D3DCLIPPLANE0",
    "D3DCLIPPLANE1",
    "D3DCLIPPLANE2",
    "D3DCLIPPLANE3",
    "D3DCLIPPLANE4",
    "D3DCLIPPLANE5",
])

D3DCS = Flags(DWORD, [
    "D3DCS_ALL",
    "D3DCS_LEFT",
    "D3DCS_RIGHT",
    "D3DCS_TOP",
    "D3DCS_BOTTOM",
    "D3DCS_FRONT",
    "D3DCS_BACK",
    "D3DCS_PLANE0",
    "D3DCS_PLANE1",
    "D3DCS_PLANE2",
    "D3DCS_PLANE3",
    "D3DCS_PLANE4",
    "D3DCS_PLANE5",
])

D3DCLIPSTATUS8 = Struct("D3DCLIPSTATUS8", [
    (DWORD, "ClipUnion"),
    (DWORD, "ClipIntersection"),
])

D3DMATERIAL8 = Struct("D3DMATERIAL8", [
    (D3DCOLORVALUE, "Diffuse"),
    (D3DCOLORVALUE, "Ambient"),
    (D3DCOLORVALUE, "Specular"),
    (D3DCOLORVALUE, "Emissive"),
    (Float, "Power"),
])

D3DLIGHTTYPE = Enum("D3DLIGHTTYPE", [
    "D3DLIGHT_POINT",
    "D3DLIGHT_SPOT",
    "D3DLIGHT_DIRECTIONAL",
])

D3DLIGHT8 = Struct("D3DLIGHT8", [
    (D3DLIGHTTYPE, "Type"),
    (D3DCOLORVALUE, "Diffuse"),
    (D3DCOLORVALUE, "Specular"),
    (D3DCOLORVALUE, "Ambient"),
    (D3DVECTOR, "Position"),
    (D3DVECTOR, "Direction"),
    (Float, "Range"),
    (Float, "Falloff"),
    (Float, "Attenuation0"),
    (Float, "Attenuation1"),
    (Float, "Attenuation2"),
    (Float, "Theta"),
    (Float, "Phi"),
])

D3DCLEAR = Flags(DWORD, [
    "D3DCLEAR_TARGET",
    "D3DCLEAR_ZBUFFER",
    "D3DCLEAR_STENCIL",
])

D3DSHADEMODE = Enum("D3DSHADEMODE", [
    "D3DSHADE_FLAT",
    "D3DSHADE_GOURAUD",
    "D3DSHADE_PHONG",
])

D3DFILLMODE = Enum("D3DFILLMODE", [
    "D3DFILL_POINT",
    "D3DFILL_WIREFRAME",
    "D3DFILL_SOLID",
])

D3DLINEPATTERN = Struct("D3DLINEPATTERN", [
    (WORD, "wRepeatFactor"),
    (WORD, "wLinePattern"),
])

D3DBLEND = Enum("D3DBLEND", [
    "D3DBLEND_ZERO",
    "D3DBLEND_ONE",
    "D3DBLEND_SRCCOLOR",
    "D3DBLEND_INVSRCCOLOR",
    "D3DBLEND_SRCALPHA",
    "D3DBLEND_INVSRCALPHA",
    "D3DBLEND_DESTALPHA",
    "D3DBLEND_INVDESTALPHA",
    "D3DBLEND_DESTCOLOR",
    "D3DBLEND_INVDESTCOLOR",
    "D3DBLEND_SRCALPHASAT",
    "D3DBLEND_BOTHSRCALPHA",
    "D3DBLEND_BOTHINVSRCALPHA",
])

D3DBLENDOP = Enum("D3DBLENDOP", [
    "D3DBLENDOP_ADD",
    "D3DBLENDOP_SUBTRACT",
    "D3DBLENDOP_REVSUBTRACT",
    "D3DBLENDOP_MIN",
    "D3DBLENDOP_MAX",
])

D3DTEXTUREADDRESS = Enum("D3DTEXTUREADDRESS", [
    "D3DTADDRESS_WRAP",
    "D3DTADDRESS_MIRROR",
    "D3DTADDRESS_CLAMP",
    "D3DTADDRESS_BORDER",
    "D3DTADDRESS_MIRRORONCE",
])

D3DCULL = Enum("D3DCULL", [
    "D3DCULL_NONE",
    "D3DCULL_CW",
    "D3DCULL_CCW",
])

D3DCMPFUNC = Enum("D3DCMPFUNC", [
    "D3DCMP_NEVER",
    "D3DCMP_LESS",
    "D3DCMP_EQUAL",
    "D3DCMP_LESSEQUAL",
    "D3DCMP_GREATER",
    "D3DCMP_NOTEQUAL",
    "D3DCMP_GREATEREQUAL",
    "D3DCMP_ALWAYS",
])

D3DSTENCILOP = Enum("D3DSTENCILOP", [
    "D3DSTENCILOP_KEEP",
    "D3DSTENCILOP_ZERO",
    "D3DSTENCILOP_REPLACE",
    "D3DSTENCILOP_INCRSAT",
    "D3DSTENCILOP_DECRSAT",
    "D3DSTENCILOP_INVERT",
    "D3DSTENCILOP_INCR",
    "D3DSTENCILOP_DECR",
])

D3DFOGMODE = Enum("D3DFOGMODE", [
    "D3DFOG_NONE",
    "D3DFOG_EXP",
    "D3DFOG_EXP2",
    "D3DFOG_LINEAR",
])

D3DZBUFFERTYPE = Enum("D3DZBUFFERTYPE", [
    "D3DZB_FALSE",
    "D3DZB_TRUE",
    "D3DZB_USEW",
])

D3DPRIMITIVETYPE = Enum("D3DPRIMITIVETYPE", [
    "D3DPT_POINTLIST",
    "D3DPT_LINELIST",
    "D3DPT_LINESTRIP",
    "D3DPT_TRIANGLELIST",
    "D3DPT_TRIANGLESTRIP",
    "D3DPT_TRIANGLEFAN",
])

D3DTRANSFORMSTATETYPE = Enum("D3DTRANSFORMSTATETYPE", [
    "D3DTS_VIEW",
    "D3DTS_PROJECTION",
    "D3DTS_TEXTURE0",
    "D3DTS_TEXTURE1",
    "D3DTS_TEXTURE2",
    "D3DTS_TEXTURE3",
    "D3DTS_TEXTURE4",
    "D3DTS_TEXTURE5",
    "D3DTS_TEXTURE6",
    "D3DTS_TEXTURE7",
    "D3DTS_WORLD",
    "D3DTS_WORLD1",
    "D3DTS_WORLD2",
    "D3DTS_WORLD3",
])

D3DMATERIALCOLORSOURCE = Enum("D3DMATERIALCOLORSOURCE", [
    "D3DMCS_MATERIAL",
    "D3DMCS_COLOR1",
    "D3DMCS_COLOR2",
])

D3DWRAPCOORD = Flags(DWORD, [
    "D3DWRAPCOORD_0",
    "D3DWRAPCOORD_1",
    "D3DWRAPCOORD_2",
    "D3DWRAPCOORD_3",
])

D3DCOLORWRITEENABLE = Flags(DWORD, [
    "D3DCOLORWRITEENABLE_RED",
    "D3DCOLORWRITEENABLE_GREEN",
    "D3DCOLORWRITEENABLE_BLUE",
    "D3DCOLORWRITEENABLE_ALPHA",
])

D3DORDERTYPE = Enum("D3DORDERTYPE", [
    "D3DORDER_LINEAR",
    "D3DORDER_QUADRATIC",
    "D3DORDER_CUBIC",
    "D3DORDER_QUINTIC",
])

D3DPATCHEDGESTYLE = Enum("D3DPATCHEDGESTYLE", [
    "D3DPATCHEDGE_DISCRETE",
    "D3DPATCHEDGE_CONTINUOUS",
])

D3DVERTEXBLENDFLAGS = Enum("D3DVERTEXBLENDFLAGS", [
    "D3DVBF_DISABLE",
    "D3DVBF_1WEIGHTS",
    "D3DVBF_2WEIGHTS",
    "D3DVBF_3WEIGHTS",
    "D3DVBF_TWEENING",
    "D3DVBF_0WEIGHTS",
])

D3DDEBUGMONITORTOKENS = Enum("D3DDEBUGMONITORTOKENS", [
    "D3DDMT_ENABLE",
    "D3DDMT_DISABLE",
])

# TODO: Convert these to/from actual floats
FLOAT_AS_DWORD = DWORD

D3DRENDERSTATETYPE, D3DRENDERSTATEVALUE = EnumPolymorphic("D3DRENDERSTATETYPE", "State", [
    ("D3DRS_ZENABLE", D3DZBUFFERTYPE),
    ("D3DRS_FILLMODE", D3DFILLMODE),
    ("D3DRS_SHADEMODE", D3DSHADEMODE),
    ("D3DRS_LINEPATTERN", DWORD), # D3DLINEPATTERN
    ("D3DRS_ZWRITEENABLE", BOOL),
    ("D3DRS_ALPHATESTENABLE", BOOL),
    ("D3DRS_LASTPIXEL", BOOL),
    ("D3DRS_SRCBLEND", D3DBLEND),
    ("D3DRS_DESTBLEND", D3DBLEND),
    ("D3DRS_CULLMODE", D3DCULL),
    ("D3DRS_ZFUNC", D3DCMPFUNC),
    ("D3DRS_ALPHAREF", DWORD),
    ("D3DRS_ALPHAFUNC", D3DCMPFUNC),
    ("D3DRS_DITHERENABLE", BOOL),
    ("D3DRS_ALPHABLENDENABLE", BOOL),
    ("D3DRS_FOGENABLE", BOOL),
    ("D3DRS_SPECULARENABLE", BOOL),
    ("D3DRS_ZVISIBLE", BOOL),
    ("D3DRS_FOGCOLOR", D3DCOLOR),
    ("D3DRS_FOGTABLEMODE", D3DFOGMODE),
    ("D3DRS_FOGSTART", FLOAT_AS_DWORD),
    ("D3DRS_FOGEND", FLOAT_AS_DWORD),
    ("D3DRS_FOGDENSITY", FLOAT_AS_DWORD),
    ("D3DRS_EDGEANTIALIAS", BOOL),
    ("D3DRS_ZBIAS", LONG),
    ("D3DRS_RANGEFOGENABLE", BOOL),
    ("D3DRS_STENCILENABLE", BOOL),
    ("D3DRS_STENCILFAIL", D3DSTENCILOP),
    ("D3DRS_STENCILZFAIL", D3DSTENCILOP),
    ("D3DRS_STENCILPASS", D3DSTENCILOP),
    ("D3DRS_STENCILFUNC", D3DCMPFUNC),
    ("D3DRS_STENCILREF", DWORD),
    ("D3DRS_STENCILMASK", DWORD),
    ("D3DRS_STENCILWRITEMASK", DWORD),
    ("D3DRS_TEXTUREFACTOR", D3DCOLOR),
    ("D3DRS_WRAP0", D3DWRAPCOORD),
    ("D3DRS_WRAP1", D3DWRAPCOORD),
    ("D3DRS_WRAP2", D3DWRAPCOORD),
    ("D3DRS_WRAP3", D3DWRAPCOORD),
    ("D3DRS_WRAP4", D3DWRAPCOORD),
    ("D3DRS_WRAP5", D3DWRAPCOORD),
    ("D3DRS_WRAP6", D3DWRAPCOORD),
    ("D3DRS_WRAP7", D3DWRAPCOORD),
    ("D3DRS_CLIPPING", BOOL),
    ("D3DRS_LIGHTING", BOOL),
    ("D3DRS_AMBIENT", D3DCOLOR),
    ("D3DRS_FOGVERTEXMODE", D3DFOGMODE),
    ("D3DRS_COLORVERTEX", BOOL),
    ("D3DRS_LOCALVIEWER", BOOL),
    ("D3DRS_NORMALIZENORMALS", BOOL),
    ("D3DRS_DIFFUSEMATERIALSOURCE", D3DMATERIALCOLORSOURCE),
    ("D3DRS_SPECULARMATERIALSOURCE", D3DMATERIALCOLORSOURCE),
    ("D3DRS_AMBIENTMATERIALSOURCE", D3DMATERIALCOLORSOURCE),
    ("D3DRS_EMISSIVEMATERIALSOURCE", D3DMATERIALCOLORSOURCE),
    ("D3DRS_VERTEXBLEND", D3DVERTEXBLENDFLAGS),
    ("D3DRS_CLIPPLANEENABLE", D3DCLIPPLANE),
    ("D3DRS_SOFTWAREVERTEXPROCESSING", BOOL),
    ("D3DRS_POINTSIZE", FLOAT_AS_DWORD),
    ("D3DRS_POINTSIZE_MIN", FLOAT_AS_DWORD),
    ("D3DRS_POINTSPRITEENABLE", BOOL),
    ("D3DRS_POINTSCALEENABLE", BOOL),
    ("D3DRS_POINTSCALE_A", FLOAT_AS_DWORD),
    ("D3DRS_POINTSCALE_B", FLOAT_AS_DWORD),
    ("D3DRS_POINTSCALE_C", FLOAT_AS_DWORD),
    ("D3DRS_MULTISAMPLEANTIALIAS", BOOL),
    ("D3DRS_MULTISAMPLEMASK", DWORD),
    ("D3DRS_PATCHEDGESTYLE", D3DPATCHEDGESTYLE),
    ("D3DRS_PATCHSEGMENTS", DWORD),
    ("D3DRS_DEBUGMONITORTOKEN", D3DDEBUGMONITORTOKENS),
    ("D3DRS_POINTSIZE_MAX", FLOAT_AS_DWORD),
    ("D3DRS_INDEXEDVERTEXBLENDENABLE", BOOL),
    ("D3DRS_COLORWRITEENABLE", DWORD),
    ("D3DRS_TWEENFACTOR", FLOAT_AS_DWORD),
    ("D3DRS_BLENDOP", D3DBLENDOP),
    ("D3DRS_POSITIONORDER", D3DORDERTYPE),
    ("D3DRS_NORMALORDER", D3DORDERTYPE),

    # XXX: D3DRENDERSTATE_WRAPBIAS + n
], DWORD)

D3DTSS_TCI = Flags(DWORD, [
    #"D3DTSS_TCI_PASSTHRU", # 0
    "D3DTSS_TCI_CAMERASPACENORMAL",
    "D3DTSS_TCI_CAMERASPACEPOSITION",
    "D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR",
])

D3DTEXTUREOP = Enum("D3DTEXTUREOP", [
    "D3DTOP_DISABLE",
    "D3DTOP_SELECTARG1",
    "D3DTOP_SELECTARG2",
    "D3DTOP_MODULATE",
    "D3DTOP_MODULATE2X",
    "D3DTOP_MODULATE4X",
    "D3DTOP_ADD",
    "D3DTOP_ADDSIGNED",
    "D3DTOP_ADDSIGNED2X",
    "D3DTOP_SUBTRACT",
    "D3DTOP_ADDSMOOTH",
    "D3DTOP_BLENDDIFFUSEALPHA",
    "D3DTOP_BLENDTEXTUREALPHA",
    "D3DTOP_BLENDFACTORALPHA",
    "D3DTOP_BLENDTEXTUREALPHAPM",
    "D3DTOP_BLENDCURRENTALPHA",
    "D3DTOP_PREMODULATE",
    "D3DTOP_MODULATEALPHA_ADDCOLOR",
    "D3DTOP_MODULATECOLOR_ADDALPHA",
    "D3DTOP_MODULATEINVALPHA_ADDCOLOR",
    "D3DTOP_MODULATEINVCOLOR_ADDALPHA",
    "D3DTOP_BUMPENVMAP",
    "D3DTOP_BUMPENVMAPLUMINANCE",
    "D3DTOP_DOTPRODUCT3",
    "D3DTOP_MULTIPLYADD",
    "D3DTOP_LERP",
])

# XXX: Actually a mixture of enums and flags
D3DTA = FakeEnum(DWORD, [
    "D3DTA_DIFFUSE",
    "D3DTA_CURRENT",
    "D3DTA_TEXTURE",
    "D3DTA_TFACTOR",
    "D3DTA_SPECULAR",
    "D3DTA_TEMP",
    #"D3DTA_COMPLEMENT",
    #"D3DTA_ALPHAREPLICATE",
])

D3DTEXTURETRANSFORMFLAGS = Enum("D3DTEXTURETRANSFORMFLAGS", [
    "D3DTTFF_DISABLE",
    "D3DTTFF_COUNT1",
    "D3DTTFF_COUNT2",
    "D3DTTFF_COUNT3",
    "D3DTTFF_COUNT4",
    "D3DTTFF_PROJECTED",
])

D3DTEXTUREFILTERTYPE = Enum("D3DTEXTUREFILTERTYPE", [
    "D3DTEXF_NONE",
    "D3DTEXF_POINT",
    "D3DTEXF_LINEAR",
    "D3DTEXF_ANISOTROPIC",
    "D3DTEXF_FLATCUBIC",
    "D3DTEXF_GAUSSIANCUBIC",
])

D3DTEXTURESTAGESTATETYPE, D3DTEXTURESTAGESTATEVALUE = EnumPolymorphic("D3DTEXTURESTAGESTATETYPE", "Type", [
    ("D3DTSS_COLOROP", D3DTEXTUREOP),
    ("D3DTSS_COLORARG1", D3DTA),
    ("D3DTSS_COLORARG2", D3DTA),
    ("D3DTSS_ALPHAOP", D3DTEXTUREOP),
    ("D3DTSS_ALPHAARG1", D3DTA),
    ("D3DTSS_ALPHAARG2", D3DTA),
    ("D3DTSS_BUMPENVMAT00", FLOAT_AS_DWORD),
    ("D3DTSS_BUMPENVMAT01", FLOAT_AS_DWORD),
    ("D3DTSS_BUMPENVMAT10", FLOAT_AS_DWORD),
    ("D3DTSS_BUMPENVMAT11", FLOAT_AS_DWORD),
    ("D3DTSS_TEXCOORDINDEX", D3DTSS_TCI),
    ("D3DTSS_ADDRESSU", D3DTEXTUREADDRESS),
    ("D3DTSS_ADDRESSV", D3DTEXTUREADDRESS),
    ("D3DTSS_BORDERCOLOR", D3DCOLOR),
    ("D3DTSS_MAGFILTER", D3DTEXTUREFILTERTYPE),
    ("D3DTSS_MINFILTER", D3DTEXTUREFILTERTYPE),
    ("D3DTSS_MIPFILTER", D3DTEXTUREFILTERTYPE),
    ("D3DTSS_MIPMAPLODBIAS", FLOAT_AS_DWORD),
    ("D3DTSS_MAXMIPLEVEL", DWORD),
    ("D3DTSS_MAXANISOTROPY", DWORD),
    ("D3DTSS_BUMPENVLSCALE", FLOAT_AS_DWORD),
    ("D3DTSS_BUMPENVLOFFSET", FLOAT_AS_DWORD),
    ("D3DTSS_TEXTURETRANSFORMFLAGS", D3DTEXTURETRANSFORMFLAGS),
    ("D3DTSS_ADDRESSW", D3DTEXTUREADDRESS),
    ("D3DTSS_COLORARG0", D3DTA),
    ("D3DTSS_ALPHAARG0", D3DTA),
    ("D3DTSS_RESULTARG", D3DTA),
], DWORD)

D3DPV = Flags(DWORD, [
    "D3DPV_DONOTCOPYDATA",
])

# XXX: Actually a mixture of enums and flags
D3DFVF = Flags(DWORD, [
    "D3DFVF_RESERVED0",
    "D3DFVF_XYZ",
    "D3DFVF_XYZRHW",
    "D3DFVF_XYZB1",
    "D3DFVF_XYZB2",
    "D3DFVF_XYZB3",
    "D3DFVF_XYZB4",
    "D3DFVF_XYZB5",
    "D3DFVF_NORMAL",
    "D3DFVF_PSIZE",
    "D3DFVF_DIFFUSE",
    "D3DFVF_SPECULAR",
    #"D3DFVF_TEX0",
    #"D3DFVF_TEX1",
    #"D3DFVF_TEX2",
    #"D3DFVF_TEX3",
    #"D3DFVF_TEX4",
    #"D3DFVF_TEX5",
    #"D3DFVF_TEX6",
    #"D3DFVF_TEX7",
    #"D3DFVF_TEX8",
    "D3DFVF_LASTBETA_UBYTE4",
    "D3DFVF_RESERVED2",
    #"D3DFVF_TEXCOORDSIZE1(0)",
    #"D3DFVF_TEXCOORDSIZE2(0)",
    #"D3DFVF_TEXCOORDSIZE3(0)",
    #"D3DFVF_TEXCOORDSIZE4(0)",
    #"D3DFVF_TEXCOORDSIZE1(1)",
    #"D3DFVF_TEXCOORDSIZE2(1)",
    #"D3DFVF_TEXCOORDSIZE3(1)",
    #"D3DFVF_TEXCOORDSIZE4(1)",
    #"D3DFVF_TEXCOORDSIZE1(2)",
    #"D3DFVF_TEXCOORDSIZE2(2)",
    #"D3DFVF_TEXCOORDSIZE3(2)",
    #"D3DFVF_TEXCOORDSIZE4(2)",
    #"D3DFVF_TEXCOORDSIZE1(3)",
    #"D3DFVF_TEXCOORDSIZE2(3)",
    #"D3DFVF_TEXCOORDSIZE3(3)",
    #"D3DFVF_TEXCOORDSIZE4(3)",
])

# XXX
D3DVSD_TOKENTYPE = Enum("D3DVSD_TOKENTYPE", [
    "D3DVSD_TOKEN_NOP",
    "D3DVSD_TOKEN_STREAM",
    "D3DVSD_TOKEN_STREAMDATA",
    "D3DVSD_TOKEN_TESSELLATOR",
    "D3DVSD_TOKEN_CONSTMEM",
    "D3DVSD_TOKEN_EXT",
    "D3DVSD_TOKEN_END",
])

# XXX
D3DVSDT = FakeEnum(DWORD, [
    "D3DVSDT_FLOAT1",
    "D3DVSDT_FLOAT2",
    "D3DVSDT_FLOAT3",
    "D3DVSDT_FLOAT4",
    "D3DVSDT_D3DCOLOR",
    "D3DVSDT_UBYTE4",
    "D3DVSDT_SHORT2",
    "D3DVSDT_SHORT4",
    "D3DVSDE_POSITION",
    "D3DVSDE_BLENDWEIGHT",
    "D3DVSDE_BLENDINDICES",
    "D3DVSDE_NORMAL",
    "D3DVSDE_PSIZE",
    "D3DVSDE_DIFFUSE",
    "D3DVSDE_SPECULAR",
    "D3DVSDE_TEXCOORD0",
    "D3DVSDE_TEXCOORD1",
    "D3DVSDE_TEXCOORD2",
    "D3DVSDE_TEXCOORD3",
    "D3DVSDE_TEXCOORD4",
    "D3DVSDE_TEXCOORD5",
    "D3DVSDE_TEXCOORD6",
    "D3DVSDE_TEXCOORD7",
    "D3DVSDE_POSITION2",
    "D3DVSDE_NORMAL2",
    "D3DDP_MAXTEXCOORD",
    "D3DSI_OPCODE_MASK",
])

D3DBASISTYPE = Enum("D3DBASISTYPE", [
    "D3DBASIS_BEZIER",
    "D3DBASIS_BSPLINE",
    "D3DBASIS_INTERPOLATE",
])

D3DSTATEBLOCKTYPE = Enum("D3DSTATEBLOCKTYPE", [
    "D3DSBT_ALL",
    "D3DSBT_PIXELSTATE",
    "D3DSBT_VERTEXSTATE",
])

D3DDEVTYPE = Enum("D3DDEVTYPE", [
    "D3DDEVTYPE_HAL",
    "D3DDEVTYPE_REF",
    "D3DDEVTYPE_SW",
])

D3DMULTISAMPLE_TYPE = Enum("D3DMULTISAMPLE_TYPE", [
    "D3DMULTISAMPLE_NONE",
    "D3DMULTISAMPLE_2_SAMPLES",
    "D3DMULTISAMPLE_3_SAMPLES",
    "D3DMULTISAMPLE_4_SAMPLES",
    "D3DMULTISAMPLE_5_SAMPLES",
    "D3DMULTISAMPLE_6_SAMPLES",
    "D3DMULTISAMPLE_7_SAMPLES",
    "D3DMULTISAMPLE_8_SAMPLES",
    "D3DMULTISAMPLE_9_SAMPLES",
    "D3DMULTISAMPLE_10_SAMPLES",
    "D3DMULTISAMPLE_11_SAMPLES",
    "D3DMULTISAMPLE_12_SAMPLES",
    "D3DMULTISAMPLE_13_SAMPLES",
    "D3DMULTISAMPLE_14_SAMPLES",
    "D3DMULTISAMPLE_15_SAMPLES",
    "D3DMULTISAMPLE_16_SAMPLES",
])

D3DFORMAT = Enum("D3DFORMAT", [
    "D3DFMT_UNKNOWN",
    "D3DFMT_R8G8B8",
    "D3DFMT_A8R8G8B8",
    "D3DFMT_X8R8G8B8",
    "D3DFMT_R5G6B5",
    "D3DFMT_X1R5G5B5",
    "D3DFMT_A1R5G5B5",
    "D3DFMT_A4R4G4B4",
    "D3DFMT_R3G3B2",
    "D3DFMT_A8",
    "D3DFMT_A8R3G3B2",
    "D3DFMT_X4R4G4B4",
    "D3DFMT_A2B10G10R10",
    "D3DFMT_G16R16",
    "D3DFMT_A8P8",
    "D3DFMT_P8",
    "D3DFMT_L8",
    "D3DFMT_A8L8",
    "D3DFMT_A4L4",
    "D3DFMT_V8U8",
    "D3DFMT_L6V5U5",
    "D3DFMT_X8L8V8U8",
    "D3DFMT_Q8W8V8U8",
    "D3DFMT_V16U16",
    "D3DFMT_W11V11U10",
    "D3DFMT_A2W10V10U10",
    "D3DFMT_UYVY",
    "D3DFMT_YUY2",
    "D3DFMT_DXT1",
    "D3DFMT_DXT2",
    "D3DFMT_DXT3",
    "D3DFMT_DXT4",
    "D3DFMT_DXT5",
    "D3DFMT_D16_LOCKABLE",
    "D3DFMT_D32",
    "D3DFMT_D15S1",
    "D3DFMT_D24S8",
    "D3DFMT_D16",
    "D3DFMT_D24X8",
    "D3DFMT_D24X4S4",
    "D3DFMT_VERTEXDATA",
    "D3DFMT_INDEX16",
    "D3DFMT_INDEX32",
])

D3DDISPLAYMODE = Struct("D3DDISPLAYMODE", [
    (UINT, "Width"),
    (UINT, "Height"),
    (UINT, "RefreshRate"),
    (D3DFORMAT, "Format"),
])

D3DCREATE = Flags(DWORD, [
    "D3DCREATE_FPU_PRESERVE",
    "D3DCREATE_MULTITHREADED",
    "D3DCREATE_PUREDEVICE",
    "D3DCREATE_SOFTWARE_VERTEXPROCESSING",
    "D3DCREATE_HARDWARE_VERTEXPROCESSING",
    "D3DCREATE_MIXED_VERTEXPROCESSING",
    "D3DCREATE_DISABLE_DRIVER_MANAGEMENT",
])

D3DDEVICE_CREATION_PARAMETERS = Struct("D3DDEVICE_CREATION_PARAMETERS", [
    (UINT, "AdapterOrdinal"),
    (D3DDEVTYPE, "DeviceType"),
    (HWND, "hFocusWindow"),
    (D3DCREATE, "BehaviorFlags"),
])

D3DSWAPEFFECT = Enum("D3DSWAPEFFECT", [
    "D3DSWAPEFFECT_DISCARD",
    "D3DSWAPEFFECT_FLIP",
    "D3DSWAPEFFECT_COPY",
    "D3DSWAPEFFECT_COPY_VSYNC",
])

D3DPOOL = Enum("D3DPOOL", [
    "D3DPOOL_DEFAULT",
    "D3DPOOL_MANAGED",
    "D3DPOOL_SYSTEMMEM",
    "D3DPOOL_SCRATCH",
])

D3DPRESENT = FakeEnum(DWORD, [
    "D3DPRESENT_RATE_DEFAULT",
    "D3DPRESENT_RATE_UNLIMITED",
])

D3DPRESENTFLAG = Flags(DWORD, [
    "D3DPRESENTFLAG_LOCKABLE_BACKBUFFER",
])

D3DPRESENT_INTERVAL = Flags(DWORD, [
    "D3DPRESENT_INTERVAL_DEFAULT", # 0
    "D3DPRESENT_INTERVAL_ONE",
    "D3DPRESENT_INTERVAL_TWO",
    "D3DPRESENT_INTERVAL_THREE",
    "D3DPRESENT_INTERVAL_FOUR",
    "D3DPRESENT_INTERVAL_IMMEDIATE",
])

D3DPRESENT_PARAMETERS = Struct("D3DPRESENT_PARAMETERS", [
    (UINT, "BackBufferWidth"),
    (UINT, "BackBufferHeight"),
    (D3DFORMAT, "BackBufferFormat"),
    (UINT, "BackBufferCount"),
    (D3DMULTISAMPLE_TYPE, "MultiSampleType"),
    (D3DSWAPEFFECT, "SwapEffect"),
    (HWND, "hDeviceWindow"),
    (BOOL, "Windowed"),
    (BOOL, "EnableAutoDepthStencil"),
    (D3DFORMAT, "AutoDepthStencilFormat"),
    (D3DPRESENTFLAG, "Flags"),
    (UINT, "FullScreen_RefreshRateInHz"),
    (D3DPRESENT_INTERVAL, "FullScreen_PresentationInterval"),
])

D3DGAMMARAMP = Struct("D3DGAMMARAMP", [
    (Array(WORD, 256), "red"),
    (Array(WORD, 256), "green"),
    (Array(WORD, 256), "blue"),
])

D3DBACKBUFFER_TYPE = Enum("D3DBACKBUFFER_TYPE", [
    "D3DBACKBUFFER_TYPE_MONO",
    "D3DBACKBUFFER_TYPE_LEFT",
    "D3DBACKBUFFER_TYPE_RIGHT",
])

D3DRESOURCETYPE = Enum("D3DRESOURCETYPE", [
    "D3DRTYPE_SURFACE",
    "D3DRTYPE_VOLUME",
    "D3DRTYPE_TEXTURE",
    "D3DRTYPE_VOLUMETEXTURE",
    "D3DRTYPE_CUBETEXTURE",
    "D3DRTYPE_VERTEXBUFFER",
    "D3DRTYPE_INDEXBUFFER",
])

D3DUSAGE = Flags(DWORD, [
    "D3DUSAGE_RENDERTARGET",
    "D3DUSAGE_DEPTHSTENCIL",
    "D3DUSAGE_WRITEONLY",
    "D3DUSAGE_SOFTWAREPROCESSING",
    "D3DUSAGE_DONOTCLIP",
    "D3DUSAGE_POINTS",
    "D3DUSAGE_RTPATCHES",
    "D3DUSAGE_NPATCHES",
    "D3DUSAGE_DYNAMIC",
])

D3DCUBEMAP_FACES = Enum("D3DCUBEMAP_FACES", [
    "D3DCUBEMAP_FACE_POSITIVE_X",
    "D3DCUBEMAP_FACE_NEGATIVE_X",
    "D3DCUBEMAP_FACE_POSITIVE_Y",
    "D3DCUBEMAP_FACE_NEGATIVE_Y",
    "D3DCUBEMAP_FACE_POSITIVE_Z",
    "D3DCUBEMAP_FACE_NEGATIVE_Z",
])

D3DLOCK = Flags(DWORD, [
    "D3DLOCK_READONLY",
    "D3DLOCK_DISCARD",
    "D3DLOCK_NOOVERWRITE",
    "D3DLOCK_NOSYSLOCK",
    "D3DLOCK_NO_DIRTY_UPDATE",
])

D3DVERTEXBUFFER_DESC = Struct("D3DVERTEXBUFFER_DESC", [
    (D3DFORMAT, "Format"),
    (D3DRESOURCETYPE, "Type"),
    (D3DUSAGE, "Usage"),
    (D3DPOOL, "Pool"),
    (UINT, "Size"),
    (DWORD, "FVF"),
])

D3DINDEXBUFFER_DESC = Struct("D3DINDEXBUFFER_DESC", [
    (D3DFORMAT, "Format"),
    (D3DRESOURCETYPE, "Type"),
    (D3DUSAGE, "Usage"),
    (D3DPOOL, "Pool"),
    (UINT, "Size"),
])

D3DSURFACE_DESC = Struct("D3DSURFACE_DESC", [
    (D3DFORMAT, "Format"),
    (D3DRESOURCETYPE, "Type"),
    (D3DUSAGE, "Usage"),
    (D3DPOOL, "Pool"),
    (UINT, "Size"),
    (D3DMULTISAMPLE_TYPE, "MultiSampleType"),
    (UINT, "Width"),
    (UINT, "Height"),
])

D3DVOLUME_DESC = Struct("D3DVOLUME_DESC", [
    (D3DFORMAT, "Format"),
    (D3DRESOURCETYPE, "Type"),
    (D3DUSAGE, "Usage"),
    (D3DPOOL, "Pool"),
    (UINT, "Size"),
    (UINT, "Width"),
    (UINT, "Height"),
    (UINT, "Depth"),
])

D3DLOCKED_RECT = Struct("D3DLOCKED_RECT", [
    (INT, "Pitch"),
    (LinearPointer(Void, "_MappedSize"), "pBits"),
])

D3DBOX = Struct("D3DBOX", [
    (UINT, "Left"),
    (UINT, "Top"),
    (UINT, "Right"),
    (UINT, "Bottom"),
    (UINT, "Front"),
    (UINT, "Back"),
])

D3DLOCKED_BOX = Struct("D3DLOCKED_BOX", [
    (INT, "RowPitch"),
    (INT, "SlicePitch"),
    (LinearPointer(Void, "_MappedSize"), "pBits"),
])

D3DRANGE = Struct("D3DRANGE", [
    (UINT, "Offset"),
    (UINT, "Size"),
])

D3DRECTPATCH_INFO = Struct("D3DRECTPATCH_INFO", [
    (UINT, "StartVertexOffsetWidth"),
    (UINT, "StartVertexOffsetHeight"),
    (UINT, "Width"),
    (UINT, "Height"),
    (UINT, "Stride"),
    (D3DBASISTYPE, "Basis"),
    (D3DORDERTYPE, "Order"),
])

D3DTRIPATCH_INFO = Struct("D3DTRIPATCH_INFO", [
    (UINT, "StartVertexOffset"),
    (UINT, "NumVertices"),
    (D3DBASISTYPE, "Basis"),
    (D3DORDERTYPE, "Order"),
])

D3DADAPTER_IDENTIFIER8 = Struct("D3DADAPTER_IDENTIFIER8", [
    (CString, "Driver"),
    (CString, "Description"),
    (LARGE_INTEGER, "DriverVersion"),
    (DWORD, "VendorId"),
    (DWORD, "DeviceId"),
    (DWORD, "SubSysId"),
    (DWORD, "Revision"),
    (GUID, "DeviceIdentifier"),
    (DWORD, "WHQLLevel"),
])

D3DRASTER_STATUS = Struct("D3DRASTER_STATUS", [
    (BOOL, "InVBlank"),
    (UINT, "ScanLine"),
])

D3DDEVINFOID = FakeEnum(DWORD, [
    "D3DDEVINFOID_RESOURCEMANAGER",
    "D3DDEVINFOID_VERTEXSTATS",
])

D3DRESOURCESTATS = Struct("D3DRESOURCESTATS", [
    (BOOL, "bThrashing"),
    (DWORD, "ApproxBytesDownloaded"),
    (DWORD, "NumEvicts"),
    (DWORD, "NumVidCreates"),
    (DWORD, "LastPri"),
    (DWORD, "NumUsed"),
    (DWORD, "NumUsedInVidMem"),
    (DWORD, "WorkingSet"),
    (DWORD, "WorkingSetBytes"),
    (DWORD, "TotalManaged"),
    (DWORD, "TotalBytes"),
])

D3DDEVINFO_RESOURCEMANAGER = Struct("D3DDEVINFO_RESOURCEMANAGER", [
    (Array(D3DRESOURCESTATS, "D3DRTYPECOUNT"), "stats"),
])

D3DDEVINFO_D3DVERTEXSTATS = Struct("D3DDEVINFO_D3DVERTEXSTATS", [
    (DWORD, "NumRenderedTriangles"),
    (DWORD, "NumExtraClippingTriangles"),
])

