Gizmo3D

gzState.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzState.h
00003 // Module       : 
00004 // Description  : Class definition of the gzState class
00005 // Author       : Anders Modén      
00006 // Product      : Gizmo3D 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden   
00009 //          
00010 // NOTE:    Gizmo3D is a high performance 3D Scene Graph and effect visualisation 
00011 //          C++ toolkit for Linux, Mac OS X, Windows (Win32) and IRIX® for  
00012 //          usage in Game or VisSim development.
00013 //
00014 //
00015 // Revision History...                          
00016 //                                  
00017 // Who  Date    Description                     
00018 //                                  
00019 // AMO  981111  Created file    
00020 //
00021 //******************************************************************************
00022 #ifndef __GZ_STATE_H__
00023 #define __GZ_STATE_H__
00024 
00032 typedef enum {  GZ_ACTION_STAGE_TRAVERSE                    =-1,    
00033                 GZ_ACTION_STAGE_DEFAULT                     =3,     
00034 
00035                 GZ_ACTION_STAGE_UNDERLAY                    =0,     
00036                 GZ_ACTION_STAGE_FRONT_TO_BACK               =1,     
00037                 GZ_ACTION_STAGE_USER_1                      =2,     
00038                 GZ_ACTION_STAGE_SORTED_TEXTURE              =3,     
00039                 GZ_ACTION_STAGE_SORTED_NOFLIP_TEXTURE       =4,     
00040                 GZ_ACTION_STAGE_MULTIPASS_TEXTURE           =5,     
00041                 GZ_ACTION_STAGE_SCENE_GRAPH_ORDER           =6,     
00042                 GZ_ACTION_STAGE_USER_2                      =7,     
00043                 GZ_ACTION_STAGE_BACK_TO_FRONT               =8,     
00044                 GZ_ACTION_STAGE_USER_3                      =9,     
00045                 GZ_ACTION_STAGE_ALPHA_SORTED_TRANSPARENCY   =10,    
00046                 GZ_ACTION_STAGE_SEPARATE_ALPHA_HIGHQ        =11,    
00047                 GZ_ACTION_STAGE_SEPARATE_ALPHA              =12,    
00048                 GZ_ACTION_STAGE_USER_4                      =13,    
00049                 GZ_ACTION_STAGE_SHADOWED_TRANSPARENCY       =14,    
00050                 GZ_ACTION_STAGE_NO_DEPTH_UPDATE             =15,    
00051                 GZ_ACTION_STAGE_SHADOW                      =16,    
00052                 GZ_ACTION_STAGE_TRANSPARENCY                =17,    
00053                 GZ_ACTION_STAGE_USER_5                      =18,    
00054                 GZ_ACTION_STAGE_OVERLAY                     =19,    
00055                 GZ_ACTION_STAGE_COUNT                       =20,    
00056                 GZ_ACTION_STAGE_PRE_RENDER                  =21,    
00057                 GZ_ACTION_STAGE_POST_RENDER                 =22,    
00058              } gzActionStage;
00059 
00061 typedef enum { GZ_STATE_ON , GZ_STATE_OFF , GZ_STATE_GLOBAL } gzStateModeActivation;
00062 
00063 
00064 #include "gzObject.h"
00065 #include "gzMatrix.h"
00066 #include "gzTexture.h"
00067 #include "gzMaterial.h"
00068 #include "gzTexEnv.h"
00069 #include "gzTexGen.h"
00070 #include "gzShader.h"
00071 
00072 class gzContext;    // Forward decl of graphics context
00073 
00075 typedef enum {  
00076                 GZ_STATE_EMPTY              = 0 ,
00077                 GZ_STATE_LINE_STIPPLE       = (1 << 0), 
00078                 GZ_STATE_POLYGON_MODE       = (1 << 1), 
00079                 GZ_STATE_BLENDING           = (1 << 2), 
00080                 GZ_STATE_TEXTURE            = (1 << 3), 
00081                 GZ_STATE_MATERIAL           = (1 << 4), 
00082                 GZ_STATE_TEXENV             = (1 << 5), 
00083                 GZ_STATE_TEXGEN             = (1 << 6), 
00084                 GZ_STATE_POLYGON_OFFSET     = (1 << 7), 
00085                 GZ_STATE_ACTION_STAGE       = (1 << 8), 
00086                 GZ_STATE_GENERATE_DEBUG_INFO= (1 << 9), 
00087                 GZ_STATE_ALPHA_FUNC         = (1 << 10),
00088                 GZ_STATE_GFX_PROGRAM        = (1 << 11),
00089 
00090              } gzStateMode;
00091 
00092 GZ_USE_BIT_LOGIC(gzStateMode);      // Allow | & operators for gzStateMode
00093 
00095 enum gzPolygonModeType 
00096 {
00097     GZ_POLYGON_MODE_FILL,   
00098     GZ_POLYGON_MODE_LINE,   
00099     GZ_POLYGON_MODE_POINT,  
00100     GZ_POLYGON_MODE_CULL    
00101 };
00102 
00104 enum gzStateBlendFactor
00105 {   
00106     GZ_BLEND_ZERO                   =GZ_ZERO ,                  
00107     GZ_BLEND_ONE                    =GZ_ONE,                    
00108     GZ_BLEND_DST_COLOR              =GZ_DST_COLOR ,             
00109     GZ_BLEND_SRC_COLOR              =GZ_SRC_COLOR ,             
00110     GZ_BLEND_ONE_MINUS_DST_COLOR    =GZ_ONE_MINUS_DST_COLOR,    
00111     GZ_BLEND_ONE_MINUS_SRC_COLOR    =GZ_ONE_MINUS_SRC_COLOR,    
00112     GZ_BLEND_SRC_ALPHA              =GZ_SRC_ALPHA,              
00113     GZ_BLEND_ONE_MINUS_SRC_ALPHA    =GZ_ONE_MINUS_SRC_ALPHA,    
00114     GZ_BLEND_DST_ALPHA              =GZ_DST_ALPHA,              
00115     GZ_BLEND_ONE_MINUS_DST_ALPHA    =GZ_ONE_MINUS_DST_ALPHA,    
00116     GZ_BLEND_SRC_ALPHA_SATURATE     =GZ_SRC_ALPHA_SATURATE      
00117 };
00118 
00120 enum gzAlphaFuncFactor
00121 {
00122     GZ_ALPHA_FUNC_NEVER     =GZ_NEVER,      
00123     GZ_ALPHA_FUNC_ALWAYS    =GZ_ALWAYS,     
00124     GZ_ALPHA_FUNC_LESS      =GZ_LESS,       
00125     GZ_ALPHA_FUNC_LEQUAL    =GZ_LEQUAL,     
00126     GZ_ALPHA_FUNC_EQUAL     =GZ_EQUAL,      
00127     GZ_ALPHA_FUNC_GEQUAL    =GZ_GEQUAL,     
00128     GZ_ALPHA_FUNC_GREATER   =GZ_GREATER,    
00129     GZ_ALPHA_FUNC_NOTEQUAL  =GZ_NOTEQUAL    
00130 };
00131 
00132 enum gzPolyOffsetMode
00133 { 
00134     GZ_POLYGON_OFFSET_FILL_MODE =GZ_POLYGON_OFFSET_FILL,    
00135     GZ_POLYGON_OFFSET_LINE_MODE =GZ_POLYGON_OFFSET_LINE,    
00136     GZ_POLYGON_OFFSET_POINT_MODE=GZ_POLYGON_OFFSET_POINT    
00137 };
00138 
00140 enum gzStateDebugMode
00141 {
00142     GZ_STATE_DEBUG_OFF              =   0,          
00143     GZ_STATE_DEBUG_SHOW_NORMALS     =   (1<<0),     
00144     GZ_STATE_DEBUG_SHOW_BSPHERE     =   (1<<1),     
00145     GZ_STATE_DEBUG_COLLECT_STATS    =   (1<<2),     
00146 };
00147 
00148 GZ_USE_BIT_LOGIC(gzStateDebugMode);     // Allow | & operators for gzStateDebugMode
00149 
00150 //******************************************************************************
00151 // Function : gzGraphicsStats
00152 //                                  
00153 // Purpose  : Creates a string with statistics about the GFX pieline
00154 //                                  
00155 // Notes    : - 
00156 //                                  
00157 // Revision History...                          
00158 //                                  
00159 // Who  Date    Description                     
00160 //                                  
00161 // AMO  021208  Created 
00162 //                                  
00163 //******************************************************************************
00165 GZ_GRAPH_EXPORT gzString gzGraphicsStats(gzContext *context);
00166 
00167 
00168 //******************************************************************************
00169 // Class    : gzStateAttribute
00170 //                                  
00171 // Purpose  : Holds the current state attributes
00172 //                                  
00173 // Notes    : - 
00174 //                                  
00175 // Revision History...                          
00176 //                                  
00177 // Who  Date    Description                     
00178 //                                  
00179 // AMO  981111  Created 
00180 //                                  
00181 //******************************************************************************
00183 class gzStateAttribute
00184 {
00185 public:
00186 
00187     // State attribute management
00189     GZ_GRAPH_EXPORT gzVoid activate(gzContext *context,gzBool activatePrograms);
00190 
00191     GZ_GRAPH_EXPORT gzVoid activatePrograms(gzContext *context);
00192     
00194     GZ_GRAPH_EXPORT gzStateAttribute();
00195 
00197     GZ_GRAPH_EXPORT virtual ~gzStateAttribute(){};
00198 
00200     GZ_GRAPH_EXPORT gzVoid pushCurrentStateAttribute(gzContext *context);
00201 
00202     // --------------- Current States ----------------------
00203     
00205     GZ_GRAPH_EXPORT static gzTexture *      getCurrentStateTexture(gzContext *context);
00206     
00208     GZ_GRAPH_EXPORT static gzMaterial*      getCurrentStateMaterial(gzContext *context);
00209     
00211 
00214     GZ_GRAPH_EXPORT static gzGFXProgram *   getCurrentGFXProgram(gzContext *context,gzGFXProgramType type);
00215 
00217     GZ_GRAPH_EXPORT static gzFloat getCurrentStateTransparency(gzContext *context);
00218 
00220     GZ_GRAPH_EXPORT static gzBool getActiveSeparation(gzContext *context);
00221 
00222     // -------------- Control ------------------------------
00223 
00225     GZ_GRAPH_EXPORT static gzVoid resetIndex(gzContext *context);
00226 
00228     GZ_GRAPH_EXPORT static gzULong getCurrentStateAttributeIndex(gzContext *context);
00229 
00231     GZ_GRAPH_EXPORT static gzBool activateIndex(gzContext *context , gzULong index);
00232 
00234 
00237     GZ_GRAPH_EXPORT virtual gzVoid  setCopyMode(gzCopyMode mode);
00238 
00239     // State attribute data
00240 
00242     GZ_GRAPH_EXPORT gzBool isEnabled(gzStateMode mode) { return (m_enable_mode & mode)!=0; }
00243 
00245     GZ_GRAPH_EXPORT gzStateDebugMode getDebugMode();
00246 
00248     GZ_GRAPH_EXPORT gzVoid operator=(const gzStateAttribute & right);
00249 
00251 
00254     GZ_GRAPH_EXPORT gzBool operator!=(const gzStateAttribute & right);
00255 
00257 
00260     GZ_GRAPH_EXPORT gzBool operator==(const gzStateAttribute & right);
00261 
00262     GZ_GRAPH_EXPORT gzVoid clear();
00263 
00264 private:
00265     friend class gzState;
00266     friend class gzContext;
00267 
00268     // Attributes
00269 
00270     gzStateMode         m_enable_mode;
00271     gzStateMode         m_disable_mode;
00272 
00273     gzUShort            m_lineStipple;
00274     gzInt               m_stippleFactor;
00275 
00276     gzStateBlendFactor  m_blend_src;
00277     gzStateBlendFactor  m_blend_dst;
00278 
00279     gzPolygonModeType   m_polygon_front_mode;
00280     gzPolygonModeType   m_polygon_back_mode;
00281 
00282     // Texture enabled is embedded in texture class
00283     gzArray< gzRefPointer<gzTexture>    >   m_texture;
00284 
00285     // Material enabled is embedded in material class
00286     gzRefPointer<gzMaterial>                m_material;
00287 
00288     gzRefPointer<gzMaterial>                m_backmaterial;
00289 
00290     // TexEnv
00291     gzArray< gzRefPointer<gzTexEnv> >       m_texenv;
00292 
00293     // TexGen
00294     gzArray< gzRefPointer<gzTexGen> >       m_texgen;
00295 
00296     gzArray< gzRefPointer<gzGFXProgram> >   m_gfxPrograms;
00297 
00298 
00299     // Polygon Offset
00300     gzPolyOffsetMode    m_polygonOffsetMode;
00301     gzFloat             m_polygonOffsetFactor;
00302     gzFloat             m_polygonOffsetUnit;
00303 
00304     // ActionStage
00305 
00306     gzActionStage       m_actionStage;
00307 
00308     // Debug info
00309     gzStateDebugMode    m_debugMode;
00310 
00311     // Transparency
00312     gzFloat             m_transparency;
00313 
00314     // Alpha func
00315     gzAlphaFuncFactor   m_alphaFunc;
00316     gzFloat             m_alphaRef;
00317 
00318     // Generic
00319     gzULong             m_currentStateUpdateID;
00320     gzBool              m_accumulateTransparency:1;
00321     gzBool              m_separateBackAndFrontRender:1;
00322     gzBool              m_useTransp:1;
00323 };
00324 
00325 //******************************************************************************
00326 // Class    : gzState
00327 //                                  
00328 // Purpose  : Provides the user interface for state management
00329 //                                  
00330 // Notes    : - 
00331 //                                  
00332 // Revision History...                          
00333 //                                  
00334 // Who  Date    Description                     
00335 //                                  
00336 // AMO  981111  Created 
00337 //                                  
00338 //******************************************************************************
00340 class gzState : public gzObject 
00341 {
00342 public:
00343     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00344     
00346     GZ_GRAPH_EXPORT gzState();
00347     
00349     GZ_GRAPH_EXPORT virtual ~gzState(){};
00350 
00351     // ---------- Clone interface ---------------------------------------
00353     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00354 
00356 
00360     GZ_GRAPH_EXPORT virtual gzBool  useDeepCopy();
00361     
00363 
00366     GZ_GRAPH_EXPORT virtual gzVoid  setCopyMode(gzCopyMode mode);
00367 
00368     // ---------- Activation of states ----------------------------------
00369 
00371 
00375     GZ_GRAPH_EXPORT gzVoid activate(gzContext *context);        // Immediate mode
00376     GZ_GRAPH_EXPORT gzVoid deactivate(gzContext *context);      // Immediate mode
00377 
00378     // ---------- Global state control ( scene graph mode ) -------------
00379 
00381 
00386     GZ_GRAPH_EXPORT static gzVoid setGlobalState(  gzContext *context, gzState *state );
00387     
00388     //The state is applied as current state to the context.
00390     GZ_GRAPH_EXPORT static gzVoid setCurrentState( gzContext *context, gzState *state );
00391     
00392     //Returns the current state for the context.
00397     GZ_GRAPH_EXPORT static gzState *getCurrentState(gzContext *context);
00398 
00400     GZ_GRAPH_EXPORT static gzVoid activateCurrentState(gzContext *context);
00401     
00403 
00406     GZ_GRAPH_EXPORT static gzVoid invalidateActiveState(gzContext *context);
00407 
00408 
00410     GZ_GRAPH_EXPORT static gzVoid resetIndex(gzContext *context);
00411 
00413     GZ_GRAPH_EXPORT static gzVoid push(gzContext *context);
00414 
00416     GZ_GRAPH_EXPORT static gzVoid pop(gzContext *context);
00417 
00419     GZ_GRAPH_EXPORT static gzActionStage useActionStage(gzContext *context);
00420 
00422 
00427     GZ_GRAPH_EXPORT gzVoid setMode( gzStateMode mode , gzStateModeActivation activation );
00428     
00430 
00441     GZ_GRAPH_EXPORT gzVoid setOverride( gzStateMode mode , gzStateModeActivation activation );
00442     
00444     GZ_GRAPH_EXPORT gzStateModeActivation getMode(gzStateMode mode);
00445 
00447     GZ_GRAPH_EXPORT gzVoid disableAllNonEnabledModes();
00448 
00449     // Attributes
00450 
00452 
00462     GZ_GRAPH_EXPORT gzVoid setLineStipple( gzUShort stipple );
00463     
00465 
00481     GZ_GRAPH_EXPORT gzVoid setStippleFactor( gzInt factor );
00482 
00484 
00499     GZ_GRAPH_EXPORT gzVoid setBlendFunction( gzStateBlendFactor src  , gzStateBlendFactor dst );
00500     GZ_GRAPH_EXPORT gzVoid setSeparateFrontAndBackRender(gzBool on);
00501 
00503     /*
00504     The default mode is GZ_POLYGON_FILL.
00505     */
00506     GZ_GRAPH_EXPORT gzVoid setFrontPolygonMode( gzPolygonModeType mode );
00507     
00509     /*
00510     The default mode is GZ_POLYGON_FILL.
00511     */
00512     GZ_GRAPH_EXPORT gzVoid setBackPolygonMode( gzPolygonModeType mode );
00513 
00515 
00522     GZ_GRAPH_EXPORT gzVoid      setTexture( gzTexture *texture , gzULong unit=0);
00523     
00525 
00528     GZ_GRAPH_EXPORT gzTexture * getTexture(gzULong unit=0);
00529     
00531     GZ_GRAPH_EXPORT gzVoid      setNumberOfTextures(gzULong units);
00532     
00534     GZ_GRAPH_EXPORT gzULong     getNumberOfTextures();
00535 
00537 
00541     GZ_GRAPH_EXPORT gzVoid      setMaterial( gzMaterial *material );
00542     
00544     GZ_GRAPH_EXPORT gzMaterial  *getMaterial();
00545 
00547 
00550     GZ_GRAPH_EXPORT gzVoid      setBackMaterial( gzMaterial *material );
00551 
00553     GZ_GRAPH_EXPORT gzMaterial  *getBackMaterial();
00554 
00556 
00562     GZ_GRAPH_EXPORT gzVoid      setTexEnv( gzTexEnv *env , gzULong unit=0);
00563     
00565     GZ_GRAPH_EXPORT gzTexEnv *  getTexEnv(gzULong unit=0);
00566     
00568 
00571     GZ_GRAPH_EXPORT gzVoid      setNumberOfTexEnv(gzULong units);
00572     
00574     GZ_GRAPH_EXPORT gzULong     getNumberOfTexEnv();
00575 
00576 
00578 
00584     GZ_GRAPH_EXPORT gzVoid      setTexGen( gzTexGen *gen , gzULong unit=0);
00585 
00587     GZ_GRAPH_EXPORT gzTexGen *  getTexGen(gzULong unit=0);
00588 
00590 
00593     GZ_GRAPH_EXPORT gzVoid      setNumberOfTexGen(gzULong units);
00594 
00596     GZ_GRAPH_EXPORT gzULong     getNumberOfTexGen();
00597 
00599 
00603     GZ_GRAPH_EXPORT gzVoid      setTransparency( gzClampf transparency , gzBool accumTransparency=TRUE);
00604     
00606     GZ_GRAPH_EXPORT gzClampf    getTransparency( gzBool *accumTransparency=NULL);
00607 
00627     GZ_GRAPH_EXPORT gzVoid setPolygonOffset(gzPolyOffsetMode mode , gzFloat factor , gzFloat unit);
00628 
00630     /*
00631         Must be enabled with GZ_STATE_ACTION_STAGE
00632     */
00633     GZ_GRAPH_EXPORT gzVoid setActionStage(gzActionStage stage );
00634 
00636     GZ_GRAPH_EXPORT gzActionStage getActionStage();
00637 
00639 
00645     GZ_GRAPH_EXPORT gzVoid setDebugMode(gzStateDebugMode mode );
00646 
00648 
00655     GZ_GRAPH_EXPORT gzVoid setAlphaFunc(gzAlphaFuncFactor func , gzClampf refValue);
00656 
00657     // Utility functions
00658 
00660     GZ_GRAPH_EXPORT gzVoid setBestAlphaTextureSettings(gzImage *image,gzSerializeAdapterFlags flags);
00661 
00662     // GFX Programs
00663 
00665     /*
00666     The GZ_STATE_GFX_PROGRAM mode has to be enabled if you want to use shaders.
00667     */
00668     GZ_GRAPH_EXPORT gzVoid setGFXProgram(gzGFXProgramType type,gzGFXProgram *program);
00669 
00670     // ----------- Static utlities for the context ------------------
00671 
00673 
00676     GZ_GRAPH_EXPORT static gzVoid setCurrentDepthFunc( gzContext *context , gzEnum func);
00677 
00679     GZ_GRAPH_EXPORT static gzEnum getCurrentDepthFunc(gzContext *context);
00680 
00681 
00683     GZ_GRAPH_EXPORT static gzVoid setUseDepthBuffer( gzContext *context , gzBool on);
00684 
00686     GZ_GRAPH_EXPORT static gzBool getUseDepthBuffer(gzContext *context);
00687 
00688     // ---------- Debug function ----------------------------------------
00690 
00693     GZ_GRAPH_EXPORT virtual gzVoid  debugOutput(gzString base , gzString anchor , gzDebugFlags features);
00694 
00695     // ---------- Serializing -------------------------------------------
00697     GZ_GRAPH_EXPORT virtual gzVoid write(gzSerializeAdapter *adapter);
00698 
00700     GZ_GRAPH_EXPORT virtual gzVoid read(gzSerializeAdapter *adapter);
00701 
00703 
00706     GZ_GRAPH_EXPORT virtual gzULong getDataSize(gzSerializeAdapter *adapter) const;
00707 
00709 
00712     GZ_GRAPH_EXPORT gzBool operator==(const gzState & right);
00713     
00715 
00718     GZ_GRAPH_EXPORT gzBool operator!=(const gzState & right);
00719 
00720 
00721 private:
00722 
00723     friend class gzContext;
00724 
00725     static gzVoid activateCurrentNow(gzContext *context);
00726 
00727     gzVoid updateFromState( gzContext *context,gzState *state);
00728 
00729     gzStateAttribute                    m_originalState;
00730     gzStateMode                         m_original_lock_mode;
00731 
00732     gzDynamicArray<gzStateAttribute>    m_currentState;
00733     gzDynamicArray<gzStateMode>         m_current_lock_mode;
00734     
00735     gzBool          m_active:1;
00736 
00737 };
00738 
00739 GZ_DECLARE_REFPTR(gzState);
00740 
00741 #endif

Documentation for Gizmo3D generated at Wed Feb 20 11:54:10 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond