home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8090 / ModelEdit.7z / renderstyle.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-03-08  |  8.6 KB  |  243 lines

  1. // renderstyle.h
  2. //    Defines a render style. The renderer supports setting render styles for render 
  3. // objects. 
  4.  
  5. #ifndef __RENDERSTYLE_H__
  6. #define __RENDERSTYLE_H__
  7.  
  8. #include <string>
  9.  
  10. using namespace std;
  11.  
  12. #define MAX_NUM_TEXTURES_PER_PASS            4
  13.  
  14. // RENDER STATE TYPES
  15. enum ERenStyle_ZBufferMode {
  16.     RENDERSTYLE_ZRW,                        // Z Read/Write
  17.     RENDERSTYLE_ZRO,                        // Z Read Only
  18.     RENDERSTYLE_NOZ };                        // No Z
  19.  
  20. enum ERenStyle_TestMode {
  21.     RENDERSTYLE_NOALPHATEST,
  22.     RENDERSTYLE_ALPHATEST_LESS,
  23.     RENDERSTYLE_ALPHATEST_LESSEQUAL,
  24.     RENDERSTYLE_ALPHATEST_GREATER,
  25.     RENDERSTYLE_ALPHATEST_GREATEREQUAL,
  26.     RENDERSTYLE_ALPHATEST_EQUAL,
  27.     RENDERSTYLE_ALPHATEST_NOTEQUAL };
  28.  
  29. enum ERenStyle_ClipMode {
  30.     RENDERSTYLE_NOCLIP,
  31.     RENDERSTYLE_FASTCLIP,
  32.     RENDERSTYLE_FULLCLIP };
  33.  
  34. enum ERenStyle_FillMode {
  35.     RENDERSTYLE_WIRE,
  36.     RENDERSTYLE_FILL };
  37.  
  38. enum ERenStyle_CullMode {
  39.     RENDERSTYLE_CULL_NONE,                    // Don't CULL
  40.     RENDERSTYLE_CULL_CCW,                    // CULL Counter Clockwise
  41.     RENDERSTYLE_CULL_CW };                    // CULL Clockwise
  42.  
  43. // TEXTURE STAGE TYPES
  44. enum ERenStyle_ColorOp {
  45.     RENDERSTYLE_COLOROP_DISABLE,
  46.     RENDERSTYLE_COLOROP_SELECTARG1,
  47.     RENDERSTYLE_COLOROP_SELECTARG2,
  48.     RENDERSTYLE_COLOROP_MODULATE,
  49.     RENDERSTYLE_COLOROP_MODULATE2X,
  50.     RENDERSTYLE_COLOROP_MODULATEALPHA,
  51.     RENDERSTYLE_COLOROP_MODULATETFACTOR,
  52.     RENDERSTYLE_COLOROP_ADD,
  53.     RENDERSTYLE_COLOROP_DOTPRODUCT3,
  54.     RENDERSTYLE_COLOROP_BUMPENVMAP,
  55.     RENDERSTYLE_COLOROP_BUMPENVMAPLUM,
  56.     RENDERSTYLE_COLOROP_DECAL,
  57.     RENDERSTYLE_COLOROP_HIGHLIGHT,
  58.     RENDERSTYLE_COLOROP_HIGHLIGHT2 };
  59.  
  60. enum ERenStyle_ColorArg {
  61.     RENDERSTYLE_COLORARG_CURRENT,
  62.     RENDERSTYLE_COLORARG_DIFFUSE,
  63.     RENDERSTYLE_COLORARG_TEXTURE, 
  64.     RENDERSTYLE_COLORARG_TFACTOR };
  65.  
  66. enum ERenStyle_AlphaOp {
  67.     RENDERSTYLE_ALPHAOP_DISABLE,
  68.     RENDERSTYLE_ALPHAOP_SELECTARG1,
  69.     RENDERSTYLE_ALPHAOP_SELECTARG2,
  70.     RENDERSTYLE_ALPHAOP_MODULATE,
  71.     RENDERSTYLE_ALPHAOP_MODULATEALPHA,
  72.     RENDERSTYLE_ALPHAOP_MODULATETFACTOR,
  73.     RENDERSTYLE_ALPHAOP_ADD };
  74.  
  75. enum ERenStyle_AlphaArg {
  76.     RENDERSTYLE_ALPHAARG_CURRENT,
  77.     RENDERSTYLE_ALPHAARG_DIFFUSE,
  78.     RENDERSTYLE_ALPHAARG_TEXTURE,
  79.     RENDERSTYLE_ALPHAARG_TFACTOR };
  80.  
  81. enum ERenStyle_UV_Source {
  82.     RENDERSTYLE_UVFROM_MODELDATA_UVSET1,
  83.     RENDERSTYLE_UVFROM_MODELDATA_UVSET2,
  84.     RENDERSTYLE_UVFROM_MODELDATA_UVSET3,
  85.     RENDERSTYLE_UVFROM_MODELDATA_UVSET4,
  86.     RENDERSTYLE_UVFROM_CAMERASPACENORMAL,
  87.     RENDERSTYLE_UVFROM_CAMERASPACEPOSITION,
  88.     RENDERSTYLE_UVFROM_CAMERASPACEREFLTVECT };
  89.  
  90. enum ERenStyle_TextureParam {
  91.     RENDERSTYLE_NOTEXTURE,
  92.     RENDERSTYLE_USE_TEXTURE1,
  93.     RENDERSTYLE_USE_TEXTURE2,
  94.     RENDERSTYLE_USE_TEXTURE3,
  95.     RENDERSTYLE_USE_TEXTURE4 };
  96.  
  97. enum ERenStyle_UV_Address {
  98.     RENDERSTYLE_UVADDR_WRAP,
  99.     RENDERSTYLE_UVADDR_CLAMP,
  100.     RENDERSTYLE_UVADDR_MIRROR,
  101.     RENDERSTYLE_UVADDR_MIRRORONCE };
  102.  
  103. enum ERenStyle_TexFilter {
  104.     RENDERSTYLE_TEXFILTER_POINT,
  105.     RENDERSTYLE_TEXFILTER_BILINEAR,
  106.     RENDERSTYLE_TEXFILTER_TRILINEAR,
  107.     RENDERSTYLE_TEXFILTER_ANISOTROPIC,
  108.     RENDERSTYLE_TEXFILTER_POINT_PTMIP };
  109.  
  110. struct FourFloatVector {                    // Four float vector...
  111.     FourFloatVector()        { }
  112.     FourFloatVector(float nx, float ny, float nz, float nw)    { x = nx; y = ny; z = nz; w = nw; }
  113.     FourFloatVector(D3DVECTOR v)                            { x = v.x; y = v.y; z = v.z; w = 1.0f; }
  114.     float                    x,y,z,w; };
  115.  
  116. struct FourFloatColor {                        // Four float color...
  117.     FourFloatColor()        { }
  118.     FourFloatColor(float nr, float ng, float nb, float na)    { r = nr; g = ng; b = nb; a = na; }
  119.     float                    r,g,b,a; };
  120.  
  121. // RENDER PASS TYPES
  122. enum ERenStyle_BlendMode {                    //    Cs - Source Color, As - Source Alpha, Cd - Dest Color, Ad - Dest Alpha
  123.     RENDERSTYLE_NOBLEND,                    // Cs
  124.     RENDERSTYLE_BLEND_ADD,                    // Cs             + Cd
  125.     RENDERSTYLE_BLEND_SATURATE,                // Cs * (1 - Cd) + Cd
  126.     RENDERSTYLE_BLEND_MOD_SRCALPHA,            // Cs * As         + Cd * (1 - As)
  127.     RENDERSTYLE_BLEND_MOD_SRCCOLOR,            // Cs * Cs         + Cd * (1 - Cs)
  128.     RENDERSTYLE_BLEND_MOD_DSTCOLOR,            // Cs * Cd         + Cd * (1 - Cd)
  129.     RENDERSTYLE_BLEND_MUL_SRCCOL_DSTCOL,    // Cs * Cs         + Cd * Cd
  130.     RENDERSTYLE_BLEND_MUL_SRCCOL_ONE,        // Cs * Cs         + Cd
  131.     RENDERSTYLE_BLEND_MUL_SRCALPHA_ZERO,    // Cs * As
  132.     RENDERSTYLE_BLEND_MUL_SRCALPHA_ONE,        // Cs * As         + Cd
  133.     RENDERSTYLE_BLEND_MUL_DSTCOL_ZERO };    // Cs * Cd
  134.  
  135. struct TextureStageOps {                    // Each Render Pass has a set of ops it'll do to apply the texture - this struct defines them.
  136.     ERenStyle_TextureParam            TextureParam;
  137.     ERenStyle_ColorOp                ColorOp;
  138.     ERenStyle_ColorArg                ColorArg1,ColorArg2;
  139.     ERenStyle_AlphaOp                AlphaOp;
  140.     ERenStyle_AlphaArg                AlphaArg1,AlphaArg2; 
  141.     ERenStyle_UV_Source                UVSource; 
  142.     ERenStyle_UV_Address            UAddress;    
  143.     ERenStyle_UV_Address            VAddress;    
  144.     ERenStyle_TexFilter                TexFilter;
  145.     bool                            UVTransform_Enable;
  146.     float                            UVTransform_Matrix[16]; 
  147.     bool                            UVProject_Enable; };
  148.  
  149. struct RenderPassOp {                        // Each Render Style has one or more render passes. Each pass has a different set of textures and blend modes...
  150.     TextureStageOps                    TextureStages[4];
  151.     ERenStyle_BlendMode                BlendMode; 
  152.     ERenStyle_ZBufferMode            ZBufferMode; 
  153.     ERenStyle_CullMode                CullMode;
  154.     uint32                            TextureFactor; 
  155.     uint32                            AlphaRef;
  156.     bool                            DynamicLight;
  157.     ERenStyle_TestMode                AlphaTestMode;
  158.     ERenStyle_FillMode                FillMode;
  159.  
  160.     bool                            bUseBumpEnvMap;            // BumpEnvMap Params...
  161.     uint32                            BumpEnvMapStage;
  162.     float                            fBumpEnvMap_Scale;
  163.     float                            fBumpEnvMap_Offset; };
  164.  
  165. struct LightingMaterial {                    // Lighting Materials...
  166.     FourFloatColor                    Ambient;
  167.     FourFloatColor                    Diffuse;
  168.     FourFloatColor                    Emissive;
  169.     FourFloatColor                    Specular;
  170.     float                            SpecularPower; };
  171.  
  172. struct RSD3DOptions {                        // Platform options: Direct3D...
  173. };
  174.  
  175. struct RSD3DRenderPass {                    // Platform Render Pass options: Direct3D...
  176.     bool                            bUseVertexShader;
  177.     string                            VertexShaderFilename;
  178.     bool                            bExpandForSkinning;
  179.     int32                            ConstVector_ConstReg1;    // Should be -1 if not used (same goes for all const regs)...
  180.     FourFloatVector                    ConstVector_Param1;
  181.     int32                            ConstVector_ConstReg2;
  182.     FourFloatVector                    ConstVector_Param2;
  183.     int32                            ConstVector_ConstReg3;
  184.     FourFloatVector                    ConstVector_Param3;
  185.     int32                            WorldViewTransform_ConstReg;
  186.     uint32                            WorldViewTransform_Count;
  187.     int32                            ProjTransform_ConstReg;
  188.     int32                            WorldViewProjTransform_ConstReg;
  189.     int32                            ViewProjTransform_ConstReg;
  190.     int32                            CamPos_MSpc_ConstReg;
  191.     uint32                            Light_Count;
  192.     int32                            LightPosition_MSpc_ConstReg;
  193.     int32                            LightPosition_CSpc_ConstReg;
  194.     int32                            LightColor_ConstReg;
  195.     int32                            LightAtt_ConstReg;
  196.     int32                            Material_AmbDifEm_ConstReg;
  197.     int32                            Material_Specular_ConstReg; 
  198.     int32                            AmbientLight_ConstReg; 
  199.     int32                            PrevWorldViewTrans_ConstReg; 
  200.     uint32                            PrevWorldViewTrans_Count;
  201.     int32                            Last_ConstReg;
  202.  
  203.     bool                            bDeclaration_Stream_Position[4];    // Declaration flags...
  204.     bool                            bDeclaration_Stream_Normal[4];
  205.     bool                            bDeclaration_Stream_UVSets[4];
  206.     bool                            bDeclaration_Stream_BasisVectors[4]; 
  207.     int32                            Declaration_Stream_UVCount[4]; };
  208.  
  209. class CRenderStyle {
  210. public:
  211.     CRenderStyle()                    { m_iRefCnt = 0; }
  212.     virtual ~CRenderStyle()            { }
  213.  
  214.     // Get/Set RenderState Settings...
  215.     // RenderStates...
  216.     virtual void                    SetClipMode(ERenStyle_ClipMode eMode)                    = 0;
  217.     virtual ERenStyle_ClipMode        GetClipMode()                                            = 0;
  218.     // Lighting Material...
  219.     virtual bool                    SetLightingMaterial(LightingMaterial& LightMaterial)    = 0;
  220.     virtual bool                    GetLightingMaterial(LightingMaterial* pLightMaterial)    = 0;
  221.     // RenderPasses...
  222.     virtual bool                    AddRenderPass(RenderPassOp& Renderpass)                    = 0;
  223.     virtual bool                    RemoveRenderPass(uint32 iPass)                            = 0;
  224.     virtual bool                    SetRenderPass(uint32 iPass,RenderPassOp& RenderPass)    = 0;
  225.     virtual bool                    GetRenderPass(uint32 iPass,RenderPassOp* pRenderPass)    = 0;
  226.     virtual uint32                    GetRenderPassCount()                                    = 0;
  227.     // Platform Options: Direct3D...
  228.     virtual bool                    SetDirect3D_Options(RSD3DOptions& Options)                { return false; }
  229.     virtual bool                    GetDirect3D_Options(RSD3DOptions* pOptions)                { pOptions = NULL; return false; }
  230.     virtual bool                    SetRenderPass_D3DOptions(uint32 iPass,RSD3DRenderPass* pD3DRenderPass)    { return false; }
  231.     virtual bool                    GetRenderPass_D3DOptions(uint32 iPass,RSD3DRenderPass* pD3DRenderPass)    { pD3DRenderPass = NULL; return false; }
  232.  
  233.     // Helper Functions...
  234.     virtual bool                    Compile()                                                = 0;    // May need to be compiled if it has been changed (will automattically be done if used - but you may choose to do it at a particular time since it may take some time).
  235.     virtual void                    SetDefaults()                                            = 0;
  236.     virtual uint32                    GetRefCount()                                            { return m_iRefCnt; }
  237.  
  238. protected:
  239.     uint32                            m_iRefCnt;                                                // Used to figure out if/when we can get rid of this guy...
  240. };
  241.  
  242. #endif
  243.