Command Buffer Structure (Windows CE 5.0)

Send Feedback

The command buffer is a queue of command tokens that the Microsoft® Direct3D® Mobile middleware maintains. Each token represents a single command for the driver to parse and execute. The driver must read the command buffer's tokens sequentially and execute each command sequentially. If the driver executes the tokens out of sequence, it may render some pixels incorrectly.

Most application calls to the Driect3D Mobile middleware that are intended to change the state of the driver or draw on the screen result in the middleware writing tokens into the command buffer.

Ordinarily, the middleware sends the commands in the buffer to the driver and then clears the buffer when the pixels affected by the command tokens are required on the screen or when the command buffer is full. This process is often referred to as flushing the command buffer. Other occasions where the middleware will flush the command buffer during locks and during calls to D3DM_GetInfo. For more information, see Surface Locks in Direct3D Mobile

To maintain performance, the driver should process command tokens immediately. An exception to this is the token generated by IDirect3DMobileDevice::Present. This token may require the driver to wait until a vertical blank interval period before it can be executed. This token is only found at the end of a command buffer; it permits the driver to return from a call to D3DM_DrawPrimitive while the final Present call is still pending.

The Direct3D Mobile middleware flushes its command buffer by calling the driver's D3DM_DrawPrimitive method with a D3DM_DRAWPRIMITIVE_DATA structure.

Each command consists of a header structure, D3DM_COMMAND, followed by some count of command-specific structures. The header for each command immediately follows the end of the command data for the command before it. Because command buffers are always 32-bit aligned, the command header structure and all command data structures are some multiple of 32 bits. Consequently, all pointer arithmetic involved in parsing a command buffer should be 32bit aligned.

Methods that control the resource manager act immediately; they are not buffered in the command buffer.

Default Command Buffer

When the Direct3D Mobile middleware creates a new context with the driver's D3DM_CreateContext function, it prepares a default command buffer that it passes to the driver's D3DM_DrawPrimitive function immediately after the context is created. The following list describes these cases.

  • The middleware determines which number format to send to the driver with D3DMOP_TRANSFORM tokens for D3DMTS_VIEW, D3DMTS_PROJECTION, D3DMTS_WORLD, and D3DMTS_TEXTUREn transforms, see D3DM_OPERATION and D3DMTRANSFORMSTATETYPE.
  • The middleware determines the number of supported texture stages and then restricts the D3DMOP_TEXTURESTAGESTATE tokens in the default command-buffer to only those with a stage that is supported by the driver.

Usually, the default command buffer is tailored to the capability bits that the driver exposes. It initializes all of the various state variables in the driver to default values. Because this process initializes all variables, variables may be initialized for capabilities the driver does not support. The driver can ignore these state values.

Default Driver State Values

The default driver state includes transformation matrices. All transformation matrices are set to the identity matrix. The data format of the matrices depends on whether the driver advertises itself as fixed or float native as described by the D3DMDEVCAPS_NATIVEFLOAT capability bit, see D3DMDEVCAPS Values. The matrices include all 4 texture stage coordinate transformation matrices, even if the driver does not support texture transformation, or supports less than 4 stages.

The default driver state also includes the viewport. The default viewport is the entire client area of the device window. If the cooperative level is set to full-screen then the default viewport is the entire screen. The default minimum z value for the viewport is set to 0 and the maximum is set to 1.

The initial material is set to flat black. All color parameters are set to black (0,0,0,0) and the specular power is set to 0.

The default driver state also includes NULL index and vertex buffer command tokens.

By default, no textures are bound because none exist when the driver is initialized. There is a default set of texture stage states that are loaded into all values for all 4 possible stages. The driver may ignore any values that do not apply to the capabilities it supports.

The following table shows the default texture stage state values.

Texture Stage State Default
D3DMTSS_ADDRESSU D3DMTADDRESS_WRAP
D3DMTSS_ADDRESSV D3DMTADDRESS_WRAP
D3DMTSS_ADDRESSW D3DMTADDRESS_WRAP
D3DMTSS_ALPHAARG0 D3DMTA_CURRENT
D3DMTSS_ALPHAARG1 D3DMTA_TEXTURE
D3DMTSS_ALPHAARG2 D3DMTA_CURRENT
D3DMTSS_ALPHAOP D3DMTOP_SELECTARG1 for stage 0

D3DMTOP_DISABLE for other Stages

D3DMTSS_BORDERCOLOR 0 (black)
D3DMTSS_COLORARG0 D3DMTA_CURRENT
D3DMTSS_COLORARG1 D3DMTA_TEXTURE
D3DMTSS_COLORARG2 D3DMTA_CURRENT
D3DMTSS_COLOROP D3DMTOP_MODULATE for stage 0

D3DMTOP_DISABLE for other Stages

D3DMTSS_MAGFILTER D3DMTEXF_POINT
D3DMTSS_MAXANISOTROPY 1
D3DMTSS_MAXMIPLEVEL 0
D3DMTSS_MINFILTER D3DMTEXF_POINT
D3DMTSS_MIPFILTER D3DMTEXF_NONE
D3DMTSS_MIPMAPLODBIAS 0
D3DMTSS_RESULTARG D3DMTA_CURRENT
D3DMTSS_TEXCOORDINDEX 0
D3DMTSS_TEXTURETRANSFORMFLAGS D3DMTTFF_DISABLE

The following table shows the default render state values.

Render State Default Value
D3DMRS_ALPHABLENDENABLE FALSE
D3DMRS_ALPHAFUNC D3DMCMP_ALWAYS
D3DMRS_ALPHAREF 0
D3DMRS_ALPHATESTENABLE FALSE
D3DMRS_AMBIENT 0 (Black)
D3DMRS_AMBIENTMATERIALSOURCE D3DMMCS_MATERIAL
D3DMRS_BLENDOP D3DMBLENDOP_ADD
D3DMRS_CLIPPING TRUE
D3DMRS_COLORVERTEX TRUE
D3DMRS_COLORWRITEENABLE D3DMCOLORWRITEENABLE_ALL
D3DMRS_CULLMODE D3DMCULL_CCW
D3DMRS_DEPTHBIAS 0
D3DMRS_DESTBLEND D3DMBLEND_ZERO
D3DMRS_DIFFUSEMATERIALSOURCE D3DMMCS_COLOR1
D3DMRS_DITHERENABLE FALSE
D3DMRS_FILLMODE D3DMFILL_SOLID
D3DMRS_FOGCOLOR 0
D3DMRS_FOGDENSITY 0
D3DMRS_FOGENABLE FALSE
D3DMRS_FOGEND 0
D3DMRS_FOGSTART 0
D3DMRS_FOGTABLEMODE D3DMFOG_NONE
D3DMRS_FOGVERTEXMODE D3DMFOG_NONE
D3DMRS_LASTPIXEL TRUE
D3DMRS_LIGHTING TRUE
D3DMRS_LOCALVIEWER TRUE
D3DMRS_NORMALIZENORMALS FALSE
D3DMRS_RANGEFOGENABLE FALSE
D3DMRS_SHADEMODE D3DMSHADE_GOURAUD
D3DMRS_SLOPESCALEDEPTHBIAS 0
D3DMRS_SPECULARENABLE FALSE
D3DMRS_SPECULARMATERIALSOURCE D3DMMCS_COLOR2
D3DMRS_SRCBLEND D3DMBLEND_ONE
D3DMRS_STENCILENABLE FALSE
D3DMRS_STENCILFAIL D3DMSTENCILOP_KEEP
D3DMRS_STENCILFUNC D3DMCMP_ALWAYS
D3DMRS_STENCILMASK 0xFFFFFFFF
D3DMRS_STENCILPASS D3DMSTENCILOP_KEEP
D3DMRS_STENCILREF 0
D3DMRS_STENCILWRITEMASK 0xFFFFFFFF
D3DMRS_STENCILZFAIL D3DMSTENCILOP_KEEP
D3DMRS_TEXTUREFACTOR 0xFFFFFFFF (White)
D3DMRS_TEXTUREPERSPECTIVE FALSE
D3DMRS_WRAP0 0
D3DMRS_WRAP1 0
D3DMRS_WRAP2 0
D3DMRS_WRAP3 0
D3DMRS_ZENABLE TRUE (D3DMZB_TRUE) if D3DMPRESENT_PARAMETERS.EnableAutoDepthStencil was set to TRUE, FALSE otherwise.
D3DMRS_ZFUNC D3DMCMP_LESSEQUAL
D3DMRS_ZWRITEENABLE TRUE if the EnableAutoDepthStencil member of D3DMPRESENT_PARAMETERS is TRUE

FALSE otherwise.

See Also

Driver Interactions with the Direct3D Mobile Middleware

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.