Direct3D is a state machine; applications set up the state of the lighting, rendering, and transformation modules and then pass data through them. This architecture is integral to Immediate Mode, but it is partially hidden by the Retained-Mode API. The SetRenderState function is a simple way to set the rendering state for a Retained-Mode application.
First, SetRenderState calls the IDirect3DRMDevice::SetQuality method, specifying that the lights are on, that the fill mode is solid, and that Gouraud shading should be used. At this point, applications that need to change the dithering mode or texture quality can call the IDirect3DRMDevice::SetDither or IDirect3DRMDevice::SetTextureQuality methods.
The remainder of this function is a switch statement that calls the IDirect3DRMDevice::SetShades, IDirect3DRM::SetDefaultTextureColors, and IDirect3DRM::SetDefaultTextureShades methods, with different parameters depending on the number of bits-per-pixel supported by the current device.
/////////////////////////////////////////////////////////////////////
//
// SetRenderState
// Set the render quality and shade information.
//
/////////////////////////////////////////////////////////////////////
BOOL
SetRenderState(void)
{
HRESULT rval;
// Set the render quality (light toggle, fill mode, shade mode).
rval = myglobs.dev->lpVtbl->SetQuality(myglobs.dev,
D3DRMLIGHT_ON | D3DRMFILL_SOLID | D3DRMSHADE_GOURAUD);
if (rval != D3DRM_OK) {
return FALSE;
}
// If you want to change the dithering mode, call SetDither here.
// If you want a texture quality other than D3DRMTEXTURE_NEAREST
// (the default value), call SetTextureQuality here.
// Set shade information based on current bits-per-pixel.
switch (myglobs.BPP) {
case 1:
if (FAILED(myglobs.dev->lpVtbl->SetShades(myglobs.dev, 4)))
goto shades_error;
if (FAILED(lpD3DRM->lpVtbl->
SetDefaultTextureShades(lpD3DRM, 4)))
goto shades_error;
break;
case 16:
if (FAILED(myglobs.dev->lpVtbl->SetShades(myglobs.dev, 32)))
goto shades_error;
if (FAILED(lpD3DRM->lpVtbl->
SetDefaultTextureColors(lpD3DRM, 64)))
goto shades_error;
if (FAILED(lpD3DRM->lpVtbl->
SetDefaultTextureShades(lpD3DRM, 32)))
goto shades_error;
break;
case 24:
case 32:
if (FAILED(myglobs.dev->lpVtbl->
SetShades(myglobs.dev, 256)))
goto shades_error;
if (FAILED(lpD3DRM->lpVtbl->
SetDefaultTextureColors(lpD3DRM, 64)))
goto shades_error;
if (FAILED(lpD3DRM->lpVtbl->
SetDefaultTextureShades(lpD3DRM, 256)))
goto shades_error;
break;
}
return TRUE;
shades_error:
return FALSE;
}