Texture Stages

[Previous] [Next]

Direct3D supplies advanced texture-blending capabilities that allow you to combine up to eight textures on a primitive at once. The IDirect3DDevice7 interface provides texture stages as part of Direct3D's multitexturing capability. Each texture stage contains a texture and operations that can be performed on the texture. Together, the textures associated with these stages form the set of current textures.

You set the current textures by using the IDirect3DDevice7::SetTexture method as just discussed. Until you change the textures, all the current textures will be blended on any of the rendered primitives in a scene.

Each texture state is defined by its texture stage. You need to set the state of each texture by using the IDirect3DDevice7::SetTextureStageState method. The first parameter is passed as the stage number (0 to 7). The second parameter is set to a member of the D3DTEXTURESTAGESTATETYPE enumerated type. The third parameter is passed as the state value for the texture state. Here's the declaration for the IDirect3DDevice7::SetTextureStageState method:

 HRESULT IDirect3DDevice7::SetTextureStageState(     DWORD dwStage,     D3DTEXTURESTAGESTATETYPE dwState,     DWORD dwValue ); 

ParameterDescription
dwStageStage identifier of the texture stage this call will affect; devices can currently have up to eight set textures (valid values are 0 to 7)
dwStateTexture stage to be set; this parameter can be any member of the D3DTEXTURESTAGESTATETYPE enumerated type setting
dwValueState value to be set; the dwState parameter determines the meaning of this value

Here's the definition of the D3DTEXTURESTAGESTATETYPE enumerated type, which defines texture-stage types:

 typedef enum _D3DTEXTURESTAGESTATETYPE {      D3DTSS_COLOROP        = 1,       D3DTSS_COLORARG1      = 2,       D3DTSS_COLORARG2      = 3,       D3DTSS_ALPHAOP        = 4,       D3DTSS_ALPHAARG1      = 5,       D3DTSS_ALPHAARG2      = 6,       D3DTSS_BUMPENVMAT00   = 7,       D3DTSS_BUMPENVMAT01   = 8,       D3DTSS_BUMPENVMAT10   = 9,       D3DTSS_BUMPENVMAT11   = 10,      D3DTSS_TEXCOORDINDEX  = 11,      D3DTSS_ADDRESS        = 12,      D3DTSS_ADDRESSU       = 13,      D3DTSS_ADDRESSV       = 14,      D3DTSS_BORDERCOLOR    = 15,      D3DTSS_MAGFILTER      = 16,      D3DTSS_MINFILTER      = 17,      D3DTSS_MIPFILTER      = 18,      D3DTSS_MIPMAPLODBIAS  = 19,      D3DTSS_MAXMIPLEVEL    = 20,      D3DTSS_MAXANISOTROPY  = 21,      D3DTSS_BUMPENVLSCALE  = 22,      D3DTSS_BUMPENVLOFFSET = 23,      D3DTSS_TEXTURETRANSFORMFLAGS = 24,     D3DTSS_FORCE_DWORD   = 0x7fffffff, } D3DTEXTURESTAGESTATETYPE; 

These are the members of the D3DTEXTURESTAGESTATETYPE enumerated type:

  • D3DTSS_COLOROP The texture-stage state is a color-blending operation identified by one of the members of the D3DTEXTUREOP enumerated type. The default value for the first texture stage, texture stage 0, is D3DTOP_MODULATE. The default for all other stages is D3DTOP_DISABLE.
  • D3DTSS_COLORARG1 The texture-stage state is the first color argument for the stage, which is identified by a texture argument flag. The default argument is D3DTA_TEXTURE.
  • D3DTSS_COLORARG2 The texture-stage state is the second color argument for the stage, identified by a texture argument flag. The default argument is D3DTA_CURRENT.
  • D3DTSS_ALPHAOP The texture-stage state is an alpha blending operation identified by one of the members of the D3DTEXTUREOP enumerated type. The default value for the first texture stage (stage 0) is D3DTOP_SELECTARG1. The default for all other stages is D3DTOP_DISABLE.
  • D3DTSS_ALPHAARG1 The texture-stage state is the first alpha argument for the stage, identified by a texture argument flag. The default argument is D3DTA_TEXTURE. If you don't set a texture for this stage, the default argument is D3DTA_DIFFUSE.
  • D3DTSS_ALPHAARG2 The texture-stage state is the second alpha argument for the stage, identified by a texture argument flag. The default argument is D3DTA_CURRENT.
  • D3DTSS_BUMPENVMAT00 The texture-stage state is a D3DVALUE for the [0][0] coefficient in a bump mapping matrix. A bump mapping matrix stores a texture's depth information. (See the section "Bump Mapping" later in the chapter.) The default value is 0.
  • D3DTSS_BUMPENVMAT01 The texture-stage state is a D3DVALUE for the [0][1] coefficient in a bump mapping matrix. The default value is 0.
  • D3DTSS_BUMPENVMAT10 The texture-stage state is a D3DVALUE for the [1][0] coefficient in a bump mapping matrix. The default value is 0.
  • D3DTSS_BUMPENVMAT11 The texture-stage state is a D3DVALUE for the [1][1] coefficient in a bump mapping matrix. The default value is 0.
  • D3DTSS_TEXCOORDINDEX The index of the texture coordinate set to use with this texture stage. The default index is 0. Set this state to the zero-based index of the texture set for each vertex that this texture stage will use. You can specify up to eight sets of texture coordinates for each vertex. If a vertex doesn't include a set of texture coordinates at the specified index, the system defaults to using the (u, v) coordinates (0, 0).
  • D3DTSS_ADDRESS A member of the D3DTEXTUREADDRESS enumerated type. This value selects the texture-addressing mode for both the u and v coordinates. The default is D3DTADDRESS_WRAP.
  • D3DTSS_ADDRESSU A member of the D3DTEXTUREADDRESS enumerated type. This value selects the texture-addressing mode for the u coordinate. The default is D3DTADDRESS_WRAP.
  • D3DTSS_ADDRESSV A member of the D3DTEXTUREADDRESS enumerated type. This value selects the texture-addressing mode for the v coordinate. The default value is D3DTADDRESS_WRAP.
  • D3DTSS_BORDERCOLOR A D3DCOLOR value that describes the color to be used for rasterizing texture coordinates outside the [0.0,1.0] range. The default color is 0x00000000.
  • D3DTSS_MAGFILTER A member of the D3DTEXTUREMAGFILTER enumerated type that specifies the texture magnification filter to be used when rendering the texture onto primitives. The default value is D3DTFG_POINT.
  • D3DTSS_MINFILTER A member of the D3DTEXTUREMINFILTER enumerated type that specifies the texture minification filter to be used when rendering the texture onto primitives. The default value is D3DTFN_POINT.
  • D3DTSS_MIPFILTER A member of the D3DTEXTUREMIPFILTER enumerated type that indicates the texture magnification filter to be used when rendering the texture onto primitives. The default value is D3DTFP_NONE.
  • D3DTSS_MIPMAPLODBIAS The level of detail bias for mipmaps. You can use this member to make textures appear more chunky or more blurred. The default value is 0.
  • D3DTSS_MAXMIPLEVEL The maximum mipmap level of detail that a program will allow, specified as an index from the top of the mipmap chain. Lower values specify higher levels of detail within the mipmap chain. The default value, which is 0, specifies that all levels can be used. Nonzero values indicate that the application won't display mipmaps that have a higher level of detail than the mipmap at the specified index.
  • D3DTSS_MAXANISOTROPY The maximum level of anisotropy. The default value is 1.
  • D3DTSS_BUMPENVLSCALE A D3DVALUE scale for bump map luminance. The default value is 0.
  • D3DTSS_BUMPENVLOFFSET A D3DVALUE offset for bump map luminance. The default value is 0.
  • D3DTSS_FORCE_DWORD A member that forces the D3DTEXTURESTAGESTATETYPE enumerated type to be 32 bits in size. This value isn't used.

Although most texture properties are set using SetTextureStageState, you can set the texture-wrapping state (see the section "Texture Wrapping" near the end of this chapter for more information) for the current textures using the IDirect3DDevice7::SetRenderState method. Pass a value from D3DRENDERSTATE_WRAP0 to D3DRENDERSTATE_WRAP7 for the first parameter, and pass the desired combination of the D3DWRAP_U and D3DWRAP_V flags to enable wrapping in the u or v directions. This code shows how to set the texture-wrapping state:

 m_pd3dDevice->SetRenderState(D3DRENDERSTATE_WRAP0, D3DWRAP_U); 



Inside Direct3D
Inside Direct3D (Dv-Mps Inside)
ISBN: 0735606137
EAN: 2147483647
Year: 1999
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net