⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtmachinestate.h

📁 游戏编程精华02-含有几十个游戏编程例子
💻 H
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************NVMH1****
File:
dtMachineState.h

Copyright (C) 1999, 2000 NVIDIA Corporation
This file is provided without support, instruction, or implied warranty of any
kind.  NVIDIA makes no guarantee of its fitness for a particular purpose and is
not liable under any circumstances for any damages or loss whatsoever arising
from the use or inability to use this file or items derived from it.

Comments:


******************************************************************************/

#ifndef DTMACHINESTATE_H	   
#define DTMACHINESTATE_H	   

typedef struct dtTextureStage
{
    //dtpTexture pTexture; 
    D3DTEXTUREMIPFILTER mipfilter;
    D3DTEXTUREMAGFILTER magfilter;
    D3DTEXTUREMINFILTER minfilter;
    
    D3DTEXTUREOP colorop;
    int colorarg1, color1comp, color1arep;
    int colorarg2, color2comp, color2arep;
    
    D3DTEXTUREOP alphaop;
    int alphaarg1, alpha1comp;
    int alphaarg2, alpha2comp;
    
    
    D3DTEXTUREADDRESS address;
    
    D3DTEXTUREADDRESS textureaddress;
    int texcoordindex;
    int miplevels;
    DWORD maxanisotropy;
    D3DCOLOR bordercolor;
    Float32 mipmaplodbias;
    DWORD maxmiplevel;
    D3DTEXTURETRANSFORMFLAGS texturetransformflags;

} dtTextureStage;


typedef struct _dtMachineStateData
{
    LPDIRECT3DDEVICE_TYPE    pd3d_device;       // The D3D device
    
    dtTextureStage ts[8];  //  8 stage pipeline
    
    D3DANTIALIASMODE antialiasmode;
    D3DZBUFFERTYPE zbuffertype;
    D3DFILLMODE fillmode;
    D3DSHADEMODE shademode;      
    DWORD linepattern;     
    bool zwriteenable;
    
    bool alphatestenable;
    bool lastpixel;
    D3DBLEND srcblend;
    D3DBLEND destblend;
    D3DCULL cullmode;
    D3DCMPFUNC zfunc;
    BYTE alpharef;
    D3DCMPFUNC alphafunc;
    bool ditherenable;
    bool alphablendenable;
    bool fogenable;
    bool specularenable;
    bool zvisible;
    bool stippledalpha;
    D3DCOLOR fogcolor;

    D3DFOGMODE fog_vertex_mode;
    Float32 fog_vertex_start;
    Float32 fog_vertex_end;
    Float32 fog_vertex_density;

    D3DFOGMODE fog_table_mode;
    Float32 fog_table_density;
    Float32 fog_table_start;
    Float32 fog_table_end;

    bool edgeantialias;
    bool colorkeyenable;
    bool rangefogenable;

    bool stencil_enable;
    D3DSTENCILOP stencil_fail;
    D3DSTENCILOP stencil_zfail;
    D3DSTENCILOP stencil_pass;
    D3DCMPFUNC stencil_func;
    BYTE stencil_ref;
    BYTE stencil_mask;
    BYTE stencil_write_mask;
    bool clipping;
    bool lighting;
    bool extents;
    D3DCOLOR ambient;      
    bool colorvertex;
    bool localviewer;
    bool normalizenormals;  
    bool colorkeyblendenable;
    D3DMATERIALCOLORSOURCE diffusematerialsource;
    D3DMATERIALCOLORSOURCE ambientmaterialsource;
    D3DMATERIALCOLORSOURCE specularmaterialsource;
    D3DMATERIALCOLORSOURCE emissivematerialsource;
    D3DVERTEXBLENDFLAGS vertexblendflags;
    DWORD clipplaneenable;
    LONG zbias;
    
    DWORD texturefactor;

    LPD3DMATERIAL7 lpMaterial;
    
} _dtMachineStateData;

class dtMachineState
{
public:
    static void SetDefaultRenderStates();
//    static void RestoreRenderState();
//    static HRESULT Create3DDevice(LPDIRECT3D_TYPE pD3D, GUID & guid, LPDIRECTDRAWSURFACE_TYPE pddsBackBuffer);

    _dtMachineStateData m;

    static dtMachineState * m_pInstance;
    static dtMachineState * GetpInstance() { return m_pInstance;}
	
	static LPDIRECT3DDEVICE_TYPE & GetpD3DDevice() {	return msData().pd3d_device; }
	// LPDIRECT3DDEVICE_TYPE & dtMachineState::GetpD3DDevice()


    static _dtMachineStateData * pdtData() { return &m_pInstance->m;}
    static _dtMachineStateData & msData() { return m_pInstance->m;}

	static HRESULT SetTexture(const int &stage, dtpTexture pt) 
    { 
        if (pt)  
            return pt->SetTextureInStage(stage);
        else
            return GetpD3DDevice()->SetTexture(stage, 0);
    
    }
    static HRESULT SetTexture(const int &stage, dtpCubeMap cm) 
    { 
        if (cm)  
            return GetpD3DDevice()->SetTexture(stage, cm->GetSurface(0) );
        else
            return GetpD3DDevice()->SetTexture(stage, 0 );    
    }
    static HRESULT SetTexture(const int &stage, LPDIRECTDRAWSURFACE_TYPE pt) 
    { 
        return GetpD3DDevice()->SetTexture(stage, pt);
    }
    static HRESULT GetTexture(const int &stage, LPDIRECTDRAWSURFACE_TYPE * lplpTexture) 
    { 
        return GetpD3DDevice()->GetTexture(stage, lplpTexture) ;
    }
//    */

    dtMachineState();
    

    // matrices are not saved in state
/*    static HRESULT SetTextureStageState(const DWORD &dwStage, const D3DTEXTURESTAGESTATETYPE &dwState,  const DWORD dwValue) 
    {
        return GetpD3DDevice()->SetTextureStageState(dwStage, dwState, dwValue);
    }

/*
    static HRESULT SetAntiAlias(const D3DANTIALIASMODE &mode) 
    { 
        msData().antialiasmode = mode;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_ANTIALIAS          , mode);
    }    /*  */
/*    static HRESULT EnableZ(const D3DZBUFFERTYPE &type) 
    { 
        msData().zbuffertype = type;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_ZENABLE    , type);
    }    
    /* D3DZBUFFERTYPE (or true/false for legacy) */
/*    static HRESULT SetFillMode(const D3DFILLMODE &fillmode) 
    {
        msData().fillmode = fillmode;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_FILLMODE           , fillmode);
    }    
    /*         */
/*    static HRESULT SetShadeMode(const D3DSHADEMODE &shademode) 
    {
        msData().shademode = shademode;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_SHADEMODE          , shademode); 
    }    
    /*  */
/*    static HRESULT SetLinePattern(const DWORD &pat) 
    {
        msData().linepattern = pat;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_LINEPATTERN        , pat);
    }   
    /*  */
/*    static HRESULT EnableZWrite(const bool &b) 
    {
        msData().zwriteenable = b;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE       , b); 
    }    /* true to enable z writes */
/*    static HRESULT EnableAlphaTest(const bool &b) 
    {
        msData().alphatestenable = b;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE    , b); 
    }   /* true to enable alpha tests */
/*    static HRESULT EnableLastPixel(const bool &b) 
    {
        msData().lastpixel = b;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_LASTPIXEL          , b); 
    }   /* true for last-pixel on lines */
/*    static HRESULT SetAlphaSrcBlend(const D3DBLEND &blend) 
    { 
        msData().srcblend = blend;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND           , blend) ;
    }   /*  */
/*    static HRESULT SetAlphaDestBlend(const D3DBLEND &blend) 
    { 
        msData().destblend = blend;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND          , blend) ;
    }   /* D3DBLEND */
/*    static HRESULT SetCullMode(const D3DCULL &cullmode) 
    { 
        msData().cullmode = cullmode;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_CULLMODE           , cullmode) ;
    }   /*  */
/*    static HRESULT SetZFunc(const D3DCMPFUNC &func) 
    { 
        msData().zfunc = func;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_ZFUNC              , func) ;
    }  /*  */
/*    static HRESULT SetAlphaRef(const BYTE &ref) 
    { 
        msData().alpharef = ref;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHAREF, ref) ;
    }   /*  */
/*    static HRESULT SetAlphaFunc(const D3DCMPFUNC &func) 
    { 
        msData().alphafunc = func;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHAFUNC          , func) ;
    }  /*  */
/*    static HRESULT EnableDither(const bool &b) 
    { 
        msData().ditherenable = b;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_DITHERENABLE       , b); 
    }   /* true to enable dithering */
/*    static HRESULT EnableAlphaBlend(const bool &b) 
    { 
        msData().alphablendenable = b;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE        , b); 
    }   /* true to enable alpha blending */
/*    static HRESULT EnableFog(const bool &b) 
    { 
        msData().fogenable = b;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_FOGENABLE          , b); 
    }  /* true to enable fog */
/*    static HRESULT EnableSpecular(const bool &b) 
    { 
        msData().specularenable = b;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_SPECULARENABLE     , b); 
    }   /* true to enable specular */
/*    static HRESULT EnableZVisible(const bool &b) 
    { 
        msData().zvisible = b;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_ZVISIBLE           , b) ;
    }   /* true to enable z checking */
/*    static HRESULT EnableStippledAlpha(const bool &b) 
    { 
        msData().stippledalpha = b;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_STIPPLEDALPHA      , b); 
    }   /* true to enable stippled alpha */
/*    static HRESULT SetFogColor(const D3DCOLOR &color) 
    { 
        msData().fogcolor = color;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_FOGCOLOR           , color) ;
    }   /*  */
/*    static HRESULT SetFogTableMode(const D3DFOGMODE &fogmode) 
    { 
        msData().fog_table_mode = fogmode;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE       , fogmode) ;
    }   /*  */
/*    static HRESULT SetFogTableStart(const Float32 & fogstart) 
    {
        msData().fog_table_start = fogstart;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_FOGTABLESTART , *(DWORD *)&fogstart) ;
    }
	*/
/*    static HRESULT SetFogTableEnd(const Float32 & fogend) 
    { 
        msData().fog_table_end = fogend;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_FOGTABLEEND , *(DWORD *)&fogend) ; 
    }   */
/*    static HRESULT SetFogTableDensity(const Float32 & fogdensity)  
    { 
        msData().fog_table_density = fogdensity;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_FOGTABLEDENSITY , *(DWORD *)&fogdensity) ; 
    } 
*/	
/*    static HRESULT EnableEdgeAntiAlias(const bool &b) 
    { 
        msData().edgeantialias = b;
        return GetpD3DDevice()->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS      , b); 
    }   /* true to enable edge antialiasing */
/*    static HRESULT EnableColorkey(const bool &b) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -