Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

SLContext.h

Go to the documentation of this file.
00001 /*
00002     File:           SLContext.h
00003 
00004     Function:       State machine for rendering a scene. You can add attributes
00005                     to the context, and also push & pop the current context.
00006                     
00007     Author(s):      Andrew Willmott
00008 
00009     Copyright:      (c) 1995-2000, Andrew Willmott
00010  */
00011 
00012 #ifndef __SLContext__
00013 #define __SLContext__
00014 
00015 
00016 #include "cl/NArray.h"
00017 #include <iostream.h>
00018 
00019 
00020 #define SC_GET(X) ((sc ## X *) context->Get(a ## X))
00021 // shorthand for fetch & cast: assumes existance of a local variable
00022 // context pointing to the current context.
00023 
00024 
00025 // --- Attribute types & definition -------------------------------------------
00026 
00027 // We don't store the attributes themselves. Instead we store pointers
00028 // to attributes that reside in the scene tree.
00029 // We also define daemons that can be installed to process attributes as they
00030 // are encountered.
00031 
00032 typedef Int             AttrType;
00033 typedef Void            *AttrPtr;
00034 
00035 class AttrDaemon 
00036 {
00037     public:
00038     
00039     virtual Void            Set(AttrPtr attrPtr) = 0;
00040     virtual AttrPtr         Get() = 0;
00041     virtual Void            Save() = 0;
00042     virtual Void            Restore() = 0;
00043 };
00044 
00045 class AttrRec
00046 {
00047 public:
00048     union
00049     {
00050         AttrPtr         data;
00051         AttrDaemon      *daemon;
00052     };
00053     UInt16              level;  // level at which it was last set 
00054 };
00055 
00056 class AttrStackRec
00057 {
00058 public:
00059     AttrRec     attrRec;
00060     AttrType    attrType;
00061 };
00062 
00063 ostream &operator << (ostream &s, const AttrRec &ar);
00064 ostream &operator << (ostream &s, const AttrStackRec &asr);
00065 
00066 typedef NArray<AttrRec> AttrList;
00067 typedef NArray<AttrStackRec> AttrStackList;
00068 
00069 
00070 // --- The SLContext class ----------------------------------------------------
00071 
00072 
00073 class SLContext
00074 {
00075 public:
00076     SLContext(Int maxAttributes);
00077 
00078     AttrPtr             Get(AttrType attrType);
00080     Void                Set(AttrType attrType, AttrPtr attrPtr);
00082     Void                SetDaemon(AttrType attrType, AttrDaemon *daemon);
00083     
00084     Bool                IsCurrent(AttrType attrType);
00085     
00086     Void                Push();     
00087     Void                Pop();      
00088     Void                Clear();    
00089 
00090 protected:  
00091     AttrList        attributeList;
00092     AttrStackList   attributeStack;
00093     Int             level;          // Current size of the (pseudo) stack
00094 
00095     friend ostream &operator << (ostream &s, const SLContext &ctx);
00096 };
00097 
00098 
00099 #endif

Generated at Sat Aug 5 00:17:03 2000 for Graphics Class Library by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000