Gizmo3D

gzContext.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzContext.h
00003 // Module       : 
00004 // Description  : Class definition of the gzContext 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  991101  Created file    
00020 //
00021 //******************************************************************************
00022 #ifndef __GZ_CONTEXT_H__
00023 #define __GZ_CONTEXT_H__
00024 
00030 #include "gzBaseLibrary.h"
00031 
00032 #include "gzGraphicsEngine.h"
00033 #include "gzState.h"
00034 #include "gzLight.h"
00035 #include "gzClipPlane.h"
00036 #include "gzRenderAction.h"
00037 #include "gzCuller.h"
00038 #include "gzRoi.h"
00039 #include "gzEnvironment.h"
00040 #include "gzRecursive.h"
00041 #include "gzTexture.h"
00042 #include "gzFont.h"
00043 
00044 //******************************************************************************
00045 // Class    : gzContext
00046 //                                  
00047 // Purpose  : 
00048 //                                  
00049 // Notes    : - 
00050 //                                  
00051 // Revision History...                          
00052 //                                  
00053 // Who  Date    Description                     
00054 //                                  
00055 // AMO  020204  Created 
00056 //                                  
00057 //******************************************************************************
00058 class gzContext : public gzReference
00059 {
00060 public:
00061 
00062     // ------------------ General methods --------------------
00063 
00064     GZ_GRAPH_EXPORT gzContext();
00065 
00066     GZ_GRAPH_EXPORT gzContext(const gzContext &copy);
00067 
00068     GZ_GRAPH_EXPORT virtual ~gzContext();
00069 
00071     GZ_GRAPH_EXPORT gzVoid transferStateTo(gzContext *context);
00072 
00074     GZ_GRAPH_EXPORT virtual gzBool  useDeepCopy() { return FALSE; } 
00075 
00076 
00078     GZ_GRAPH_EXPORT static gzContext *getCurrentContext(gzULong threadID);
00079 
00081     GZ_GRAPH_EXPORT static gzContext *getCurrentContext();  // gets default context on a TID basis
00082 
00084     GZ_GRAPH_EXPORT static gzVoid     setCurrentContext(gzContext *context);
00085 
00087     GZ_GRAPH_EXPORT static gzVoid     clearContextStorage();
00088 
00090     GZ_GRAPH_EXPORT gzVoid  cleanContext();
00091 
00092     GZ_GRAPH_EXPORT gzVoid  cleanStateAttributes();
00093 
00094     GZ_GRAPH_EXPORT gzVoid  reactivate();
00095 
00096     // ---------------- Common methods ---------------------------------------------
00097 
00098     GZ_GRAPH_EXPORT gzVoid setColorMask(gzBool redMask , gzBool greenMask , gzBool blueMask , gzBool alphaMask );
00099 
00100     GZ_GRAPH_EXPORT gzVoid setMaxTransparencySortDistance(const gzReal & distance);
00101 
00102     GZ_GRAPH_EXPORT gzVoid setMinCullFactorSize(const gzReal & size);
00103     GZ_GRAPH_EXPORT gzVoid setMinShadowCullFactorSize(const gzReal & size);
00104     GZ_GRAPH_EXPORT gzVoid setCullMask(const gzCullMaskValue &cullMask);
00105 
00107     static GZ_GRAPH_EXPORT gzDouble getPathID(gzList<gzNode> &history);
00108 
00110     GZ_GRAPH_EXPORT gzVoid  setSelectedNode(gzList<gzNode> &history);
00111     GZ_GRAPH_EXPORT gzVoid  setNoSelectedNode();
00112 
00114     GZ_GRAPH_EXPORT gzVoid  readBackState(gzEnumBits bits);
00115 
00117     gzDynamicTypeContainer  attributeContainer;
00118 
00119     // ---------------- Common Attributes ------------------------------------------
00120 
00121     // Context info, You need to supply this on non Gizmo3D window applications
00122 
00123     gzWindowContext         winContext;         
00124     gzDeviceContext         deviceContext;      
00125     gzRenderContext         renderContext;      
00126 
00127     // General vars
00128 
00129     gzContext               *mainContext;       
00130 
00131     // State vars
00132 
00133     gzRefPointer<gzState>   currentState;
00134     gzRefPointer<gzState>   globalState;
00135     gzQueue<gzState *>      stackState;
00136     gzBool                  stateChange;
00137 
00138     // Depth State Bits
00139     gzEnum                  currentDepthFunc;
00140     gzBool                  enabledDepthTest;
00141     gzBool                  enabledDepthWriteMask;
00142 
00143     gzBool                  useDepthBuffer;     
00144 
00145     // StateAttribute vars
00146 
00147     gzArray< gzTexture * >  currentTexture;
00148 
00149     gzMaterial *            currentMaterial;
00150     gzMaterial *            currentBackMaterial;
00151 
00152     gzArray< gzTexEnv * >   currentTexEnv;
00153 
00154     gzArray< gzTexGen * >   currentTexGen;
00155 
00156     gzArray<gzGFXProgram *> currentGFXPrograms;
00157     gzArray<gzGFXProgram *> pendingGFXPrograms;
00158 
00159     gzBool                  hasActiveGFXPrograms;
00160 
00161     gzBool                  activeSeparation;
00162 
00163     gzTexture *             currentStateTexture;
00164     gzMaterial *            currentStateMaterial;
00165 
00166     // state
00167 
00168     gzULong                             activeStateAttributeIndex;
00169 
00170     gzDynamicArray<gzStateAttribute>    currentStateAttributeStack;
00171     gzULong                             currentStateAttributeIndex;
00172     gzStateAttribute *                  currentStateAttribute;
00173 
00174 
00175     // Blending
00176 
00177     gzBool currentStipple;
00178     gzBool currentBlend;
00179     gzBool currentPolygonMode;
00180 
00181     // Alpha Func
00182     gzBool currentAlphaFunc;
00183 
00184     gzFloat currentLineWidth;
00185     gzFloat currentPointSize;
00186 
00187     // LightState
00188 
00189     gzDynamicArray<gzLightState>    currentLightStateStack;
00190     gzULong                         currentLightStateIndex;
00191     gzLightState                    currentLightState;
00192     gzULong                         activeLightStateIndex;
00193     gzQueue<gzLightState>           currentLightStateStorage;
00194 
00195     gzLightState                    mainLightState;
00196 
00197     // Lights
00198     gzBool                          enabledLight[GZ_NUMBER_OF_ACTIVE_LIGHTS];
00199 
00200     // Generic lighting
00201 
00202     gzRGBA      globalAmbient;
00203     gzBool      localViewer;
00204     gzBool      twoSideLighting;
00205     gzBool      stateDisabledLighting;
00206 
00207     // ClipState
00208 
00209     gzDynamicArray<gzClipState> currentClipStateStack;
00210     gzULong                     currentClipStateIndex;
00211     gzClipState                 currentClipState;
00212     gzULong                     activeClipStateIndex;
00213     gzQueue<gzClipState>        currentClipStateStorage;
00214 
00215     gzClipState                 mainClipState;
00216 
00217     gzBool                      enabledClipStates[GZ_NUMBER_OF_ACTIVE_CLIP_PLANES];
00218 
00219     // Fog
00220 
00221     gzDynamicArray<gzFogInfo>   currentFogStateStack;
00222     gzULong                     currentFogStateIndex;
00223     gzFogInfo                   currentFogState;
00224     gzULong                     activeFogStateIndex;
00225     gzQueue<gzFogInfo>          currentFogStateStorage;
00226 
00227     // Transform
00228 
00229     gzDynamicArray<gzMatrix4>   currentTransformStack;
00230     gzQueue<gzMatrix4>          currentTransformStorage;
00231 
00232     gzULong                     currentTransformIndex;
00233     gzQueue<gzULong>            currentTransformIndexStorage;
00234     gzULong                     nextTransformIndex;
00235     gzULong                     activeTransformIndex;
00236 
00237     gzMatrix4                   currentTransform;
00238     gzMatrix4                   currentInvertedTransform;
00239     gzULong                     currentInvertedIndex;
00240 
00241     gzReal                      currentMaxScale;
00242     gzQueue<gzReal>             currentMaxScaleStorage;
00243     gzDynamicArray<gzReal>      currentMaxScaleStack;
00244 
00245     gzReal                      mainMaxScale;
00246     gzMatrix4                   mainTransform;
00247     gzMatrix4                   mainInvertedTransform;
00248 
00249     gzMatrix4                   mainProjTransform;
00250     gzMatrix4                   mainInvertedProjTransform;
00251 
00252     gzULong                     reservedTransforms;
00253     
00254     // Shadow Transform UpdateID
00255     
00256     gzDynamicArray<gzULong>     currentTransformUpdateIDStack;
00257     gzQueue<gzULong>            currentTransformUpdateIDStorage;
00258     gzULong                     currentTransformUpdateID;
00259 
00260     // Frame
00261 
00262     gzULong                     currentFrameIndex;
00263     gzDouble                    currentFrameFraction;
00264     gzULong                     currentNextFrameIndex;
00265 
00266     gzQueue<gzULong>            currentFrameIndexStorage;
00267     gzQueue<gzULong>            currentNextFrameIndexStorage;
00268     gzQueue<gzDouble>           currentFrameFractionStorage;
00269 
00270 
00271     // General vars
00272 
00273     gzULong                 pid;
00274     gzULong                 enumerator;
00275     gzDouble                renderTime;
00276     gzDouble                nowTime;
00277     gzULong                 renderID;
00278     gzULong                 stencilMaxValue;
00279     gzULong                 multiPassNumber;
00280     gzULong                 winWidth;
00281     gzULong                 winHeight;
00282     gzLong                  winOffsetX;
00283     gzLong                  winOffsetY;
00284 
00285 
00286     gzBool                  compiled;
00287 
00288     // general transparency
00289     gzBool                  useTransparency;
00290     gzFloat                 transparency;
00291     gzFloat                 currentMaterialTransparency;
00292 
00293     // unique identifier
00294     gzULong                 contextID;
00295 
00296     // Portal Recursive Mask 
00297     gzULong                 currentStencilValue;
00298 
00299     // Recursive depth
00300 
00301     gzReal                              currentRecursiveDepth;
00302     gzQueue<gzReal>                     currentRecursiveDepthStorage;
00303     gzDynamicArray<gzRecursiveData>     recursiveDataStorage;
00304 
00305     gzReal                              currentRecursiveDepthScaleFactor;
00306     gzQueue<gzReal>                     currentRecursiveDepthScaleFactorStorage;
00307 
00308 
00309     // Render engine
00310     gzUByte                             reverseRenderTextures;
00311 
00312     gzDataSort<gzRenderNode>            sortedNodes[GZ_ACTION_STAGE_COUNT];
00313 
00314     gzCamera                            * currentCamera;
00315     gzRefPointer<gzContext>             recursiveContext;
00316 
00317     // Cullers
00318 
00319     gzRefList<gzCuller>                 cullers;
00320 
00321     // Lods
00322 
00323     gzBool                              hasCalculatedInvScaleMag;
00324     gzFloat                             invScaleMag;
00325     gzFloat                             invLodFactorMag;
00326 
00327     gzReal                              currentLodDistance;
00328     gzQueue<gzReal>                     currentLodDistanceStorage;
00329 
00330     gzReal                              genericFadeDistance;
00331 
00332     // Sorting far distance for transparent objects
00333     gzDouble                            maxTransparencySortDistanceFactor;
00334 
00335     // minimal feature culling size
00336     gzReal                              minCullFactorSize;
00337     gzReal                              minShadowCullFactorSize;
00338 
00339 
00340     // Lod
00341     gzDynamicArray<gzBool>              currentLodStack;
00342     gzULong                             currentLodIndex;
00343 
00344     // Polygon Offset
00345 
00346     gzPolyOffsetMode                    currentPolygonOffsetMode;
00347     gzActionStage                       actionStage;
00348 
00349 
00350     // Texture IDs
00351     gzRefPointer<gzRefIdStorage>        unboundTextureID;
00352 
00353     // DisplayList IDs
00354     gzRefPointer<gzRefIdStorage>        unboundDisplayListID;
00355 
00356     // VBO IDs
00357     gzRefPointer<gzRefIdStorage>        unboundVboID;
00358 
00359     // Intersector Busy in same thread
00360 
00361     gzBool                              inIntersector;
00362 
00363     // Roi information
00364 
00365     gzDoubleXYZ                         currentRoiPosition;
00366     gzQueue<gzDoubleXYZ>                currentRoiPositionStorage;
00367     gzBool                              isCameraRoiPositioned;
00368     gzULong                             currentRoiLocalMatrixIndex;
00369     gzMatrix4                           currentRoiLocalMatrix;
00370 
00371     gzULong                             forceLodMask;
00372 
00373     // Lod forced renering
00374     gzQueue<gzULong>                    forceLodMaskStorage;
00375 
00376     // Shadow utilites
00377     gzDynamicArray<gzFloat>             imagemap;
00378     gzBool                              shadowRender;
00379     gzBool                              clearBCap;
00380     gzBool                              infiniteFarPlane;
00381 
00382     gzList<gzLight>                     shadowedLights;
00383 
00384     // Index utility
00385     gzDynamicArray<gzULong>             indArray;
00386 
00387     // ColorMask                        
00388 
00389     gzBool                              redMask;
00390     gzBool                              greenMask;
00391     gzBool                              blueMask;
00392     gzBool                              alphaMask;
00393 
00394     // Stereo info
00395     gzBool                              stereo;
00396 
00397     // State info about currentCulling modes
00398     gzInt                               currentCull;
00399     gzInt                               currentPolygonModeBack;
00400     gzInt                               currentPolygonModeFront;
00401 
00402 
00403     // Stats
00404     gzULong                             numberOfDrawnTris;  // All primitives
00405 
00406     gzULong                             primTriCount;
00407     gzULong                             primQuadCount;
00408     gzULong                             primQuadStripCount;
00409     gzULong                             primTriFanCount;
00410     gzULong                             primTriStripCount;
00411     gzULong                             primPointCount;
00412     gzULong                             primLineCount;
00413     gzULong                             primLineStripCount;
00414     gzULong                             primLineLoopCount;
00415     gzULong                             primPolyCount;
00416 
00417     gzDouble                            cullTime;
00418     gzDouble                            drawTime;
00419     gzDouble                            appTime;
00420     gzDouble                            lockTime;
00421     gzDouble                            nodeDataTime;
00422 
00423     gzDouble                            avgCullTime;
00424     gzDouble                            avgDrawTime;
00425     gzDouble                            avgAppTime;
00426     gzDouble                            avgLockTime;
00427     gzDouble                            avgNodeDataTime;
00428 
00429 
00430     gzULong                             textureTransfers;
00431     gzULong                             textureActivations;
00432     gzULong                             textureSize;
00433 
00434     // Random sequence
00435 
00436     gzULong                             currentRandomSeed;
00437     gzQueue<gzULong>                    currentRandomSeedStorage;
00438 
00439     // Sequence ordering
00440     gzULong                             currentSequence;
00441     gzQueue<gzULong>                    currentSequenceStorage;
00442 
00443     // Origin
00444 
00445     gzULong                             currentOriginID;
00446     gzQueue<gzULong>                    currentOriginIDStorage;
00447     gzReal                              currentOriginScale;
00448 
00449 
00450     // Update max count numbers per frame
00451 
00452     gzULong                             maxVBOGeomPerFrame;
00453     gzULong                             currentVBOGeomPerFrame;
00454 
00455     gzULong                             maxDisplayListGeomPerFrame;
00456     gzULong                             currentDisplayListGeomPerFrame;
00457 
00458     // GLSL
00459 
00460     gzHandle                            currentProgramObject;
00461     gzInt                               currentInvertedTransformUniformID;
00462 
00463     // Transform Base
00464 
00465     gzULong                             currentTransformBaseIndex;
00466     gzULong                             nextTransformBaseIndex;
00467     gzQueue<gzULong>                    currentTransformBaseIndexStorage;
00468     gzULong                             activeTransformBaseIndex;
00469 
00470     gzULong                             currentNumberOfTransformBases;
00471     gzQueue<gzULong>                    currentTransformBaseSizeStorage;
00472 
00473     gzDynamicArray<gzTransformID>       currentTransformBaseStack;
00474 
00475     gzDouble                            pathID;
00476     gzDouble                            pathStep;
00477 
00478     gzNode  *                           selectedNode;
00479     gzDouble                            selectedPathID;
00480 
00481     gzBool                              enablePathID;
00482 
00483     // Culling
00484 
00485     gzCullMaskValue                     cullMask;
00486     
00487     // Texture transfer
00488     
00489     gzUInt                              textureBufferID;
00490 
00491 private:
00492 
00493     gzVoid init();
00494 
00495     gzRefPointer<gzLibReference>    m_libref;
00496 
00497     friend class gzContextStore;
00498 
00499     static gzRefDict<gzValueCompareInterface,gzContext> s_contextList;
00500 
00501     static  gzULong                 s_lastPid;
00502     static  gzContext *             s_lastContext;
00503 
00504     static gzUniqueIDManager        s_idManager;
00505 
00506     static  gzULong                 s_enumerator;
00507 
00508     static gzMutex                  s_contextMutex;
00509 };
00510 
00511 
00512 #endif
00513 

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