gbuf.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: gbuf.h : GBuffer manager.
00004 
00005     DESCRIPTION:
00006 
00007     CREATED BY: Dan Silva
00008 
00009     HISTORY:
00010 
00011  *> Copyright (c) 1998, All Rights Reserved.
00012  **********************************************************************/
00013 
00014 #pragma once
00015 #include "coreexp.h"
00016 #include "maxheap.h"
00017 #include "strbasic.h"
00018 #include "maxtypes.h"
00019 #include "point2.h"
00020 #include "color.h"
00021 #include "baseinterface.h"
00022 // forward declarations
00023 class NameTab;
00024 
00025 #define NUMGBCHAN 14
00026 
00030 #define GB_Z                0   //!< (4)  Z-Buffer depth, float
00031 #define GB_MTL_ID           1   //!< (1)  ID assigned to mtl via mtl editor
00032 #define GB_NODE_ID          2   //!< (2)  ID assigned to node via properties
00033 #define GB_UV               3   //!< (8)  UV coordinates - Point2 
00034 #define GB_NORMAL           4   //!< (4)  Normal vector in view space, compressed 
00035 #define GB_REALPIX          5   //!< (4)  Non-clamped colors in "RealPixel" format 
00036 #define GB_COVERAGE         6   //!< (1)  Pixel coverage of the front surface
00037 #define GB_BG               7   //!< (3)  RGB color of what's behind the front object 
00038 #define GB_NODE_RENDER_ID   8   //!< (2)  System node number, valid during a render
00039 #define GB_COLOR            9   //!< (3)  Color (RGB)
00040 #define GB_TRANSP           10  //!< (3)  Transparency (RGB)
00041 #define GB_VELOC            11  //!< (8)  Velocity (Point2)
00042 #define GB_WEIGHT           12  //!< (3)  Weight of layers contribution to pixel color
00043 #define GB_MASK             13  //!< (2)  Sub pixel coverage mask
00044 
00045 
00050 CoreExport int GBDataSize(int i);
00051 
00071 CoreExport MCHAR* GBChannelName(int i);
00072 
00073 // Recognized channel bits 
00074 
00085 #define BMM_CHAN_NONE     0
00086 
00111 #define BMM_CHAN_Z        (1<<GB_Z)         //!<  Z-buffer depth, float
00112 
00121 #define BMM_CHAN_MTL_ID   (1<<GB_MTL_ID)    //!<  ID assigned to the material via the Material Editor. 
00122 
00128 #define BMM_CHAN_NODE_ID  (1<<GB_NODE_ID)   //!<  ID assigned to node using the Object Properties / G-buffer ID spinner.
00129 
00138 #define BMM_CHAN_UV       (1<<GB_UV)        //!<  UV coordinates, stored as Point2.
00139 
00153 #define BMM_CHAN_NORMAL   (1<<GB_NORMAL)    //!<  Normal vector in view space, compressed
00154 
00161 #define BMM_CHAN_REALPIX  (1<<GB_REALPIX)   //!<  Non clamped colors in "RealPixel" format
00162 
00170 #define BMM_CHAN_COVERAGE (1<<GB_COVERAGE)  //!<  Pixel coverage of front surface
00171 
00180 #define BMM_CHAN_BG       (1<<GB_BG)        //!<  RGB color of what's behind front object
00181 
00191 #define BMM_CHAN_NODE_RENDER_ID (1<<GB_NODE_RENDER_ID) //!<  System node number - valid during a render.
00192 
00197 #define BMM_CHAN_COLOR    (1<<GB_COLOR)     //!<  Color returned by the material shader for the fragment.
00198 
00203 #define BMM_CHAN_TRANSP   (1<<GB_TRANSP)    //!<  Transparency returned by the material shader for the fragment.
00204 
00209 #define BMM_CHAN_VELOC    (1<<GB_VELOC)     //!<  Gives the velocity vector of the fragment relative to the screen, in screen coordinates.
00210 
00229 #define BMM_CHAN_WEIGHT   (1<<GB_WEIGHT)    //!<  The sub-pixel weight of a fragment.
00230 
00231 #define BMM_CHAN_MASK     (1<<GB_MASK)      //!<  Subpixel mask 
00232 
00233 
00239 #define BMM_CHAN_TYPE_UNKNOWN 0 
00240 #define BMM_CHAN_TYPE_8   2 //!< 1 byte per pixel
00241 #define BMM_CHAN_TYPE_16  3 //!< 1 word per pixel
00242 #define BMM_CHAN_TYPE_24  8 //!< 3 bytes per pixel
00243 #define BMM_CHAN_TYPE_32  4 //!< 2 words per pixel
00244 #define BMM_CHAN_TYPE_48  5 //!< 3 words per pixel
00245 #define BMM_CHAN_TYPE_64  6 //!< 4 words per pixel
00246 #define BMM_CHAN_TYPE_96  7 //!< 6 words per pixel
00247 
00248 
00252 struct GBufData: public MaxHeapOperators {
00254     float z;
00256     UBYTE mtl_id;
00258     UWORD node_id;
00260     Point2 uv;
00262     DWORD normal;
00264     RealPixel realpix;
00266     UBYTE coverage;
00268     UWORD rend_id;
00270     Color24 color;
00272     Color24 transp;
00274     Color24 weight;
00276     Point2 veloc;
00277     UWORD mask;
00278     };
00279     
00280 
00281 //------------------------------------gbuf.h ----------------------------------------------
00282 
00311 class GBufReader  : public InterfaceServer {
00312     public:
00320     virtual int  StartLine(int y)=0;        // -1 = no data for line, or x of first non-empty pixel
00327     virtual BOOL StartPixel(int x)=0;       // -1 = eol,; 0 = empty; 1= has data  ( Automatically starts first layer)
00332     virtual BOOL StartPixel(int x,int y)=0; // -1 = eol,; 0 = empty; 1= has data ( includes StartLine)
00336     virtual BOOL StartNextLayer()=0;        // 0 = no more layers ( Do not call before first layer )
00339     virtual int NextPixel()=0;              // -1 = eol,; 0 = empty; 1 = has data
00340     // Read a data element: chan is one of { GB_Z, GB_MTL_ID, GB_NODE_ID, ... etc }
00348     virtual BOOL ReadChannelData(int chan, void *data)=0; // 1= has data;  0= didnt have data
00356     virtual BOOL ReadAllData(GBufData *data)=0; // 1= has data;  0= didnt have data
00368     virtual BOOL ModifyChannelData(int chan, void *data)=0;  // 1=success   0=fail
00378     virtual BOOL ModifyAllData(GBufData *data)=0; // 1= success;  0= fail
00381     virtual void DeleteThis()=0;
00382     // Generic expansion function
00400     #pragma warning(push)
00401     #pragma warning(disable:4100)
00402     virtual INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0) { return 0; } 
00403     #pragma warning(pop)
00404     };  
00405 
00406 
00407 // This assumes pixels are created in increasing order of x.
00462 class GBufWriter : public InterfaceServer {
00463     public:
00468     virtual void StartLine(int y)=0;         // 1 = success  0 = fail ( Must call before every line)
00474     virtual void StartPixel(int x)=0;        // 1 = success  0 = fail  ( Must call to start each pixel )
00476     virtual void StartNextLayer()=0;         // 1 = success  0 = fail  ( Must call before first layer)
00477     // Write a data element: chan is one of { GB_Z, GB_MTL_ID, GB_NODE_ID, ... etc }
00486     virtual BOOL WriteChannelData(int chan, void *data)=0;  // 1=success   0=fail
00494     virtual BOOL WriteAllData(GBufData *data)=0; // 1= success;  0= fail
00497     virtual BOOL EndLine()=0;                 // 1=success   0=fail ( Just call after every line)
00500     virtual void DeleteThis()=0;
00501     // Generic expansion function
00502     #pragma warning(push)
00503     #pragma warning(disable:4100)
00504     virtual INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0) { return 0; } 
00505     #pragma warning(pop)
00506     };  
00507 
00598 class GBuffer : public InterfaceServer {
00599     public:
00607     virtual void SetRasterSize(int ww, int hh)=0;     // when create bitmap or size changes.
00609     virtual int Width()=0;
00611     virtual int Height()=0;
00622     virtual int InitBuffer()=0;                        // call before writing buffer.
00628     virtual ULONG CreateChannels(ULONG channelMask)=0; // create specified channels
00634     virtual void  DeleteChannels(ULONG channelMask)=0; // delete specified channels 
00636     virtual ULONG ChannelsPresent()=0;
00645     virtual void  *GetChannel( ULONG channelID, ULONG& chanType)=0; 
00648     virtual GBufReader *CreateReader()=0;
00653     virtual void DestroyReader(GBufReader *pRdr)=0;
00656     virtual GBufWriter *CreateWriter()=0;
00661     virtual void DestroyWriter(GBufWriter *pRdr)=0;
00667     virtual BOOL IsDefaultGBuffer() { return FALSE; }
00669     virtual void DeleteThis()=0;
00676     virtual void Copy(GBuffer *gbfrom)=0;
00690     virtual void CopyScale(GBuffer *gbfrom, int cw=-1, int ch=-1)=0;
00710     virtual void Position(int srcy, int trgy, int srcx, int trgx, int trgw, int trgh )=0;
00711 
00712     // for file writing
00724     virtual int  NumberLayerRecords(int y)=0;  
00737     virtual int  GetLayerChannel(int y, int ichan, char *data)=0; // ichan = -1 creates array of x values
00738 
00739     // for file reading
00748     virtual int CreateLayerRecords(int y, int num)=0;  
00760     virtual int SetLayerChannel(int y, int ichan, char *data)=0; // ichan = -1 gets array of x values
00761     
00762     // This scans the entire image and updates the minimum and maximum values
00768     virtual void UpdateChannelMinMax()=0;
00769 
00770     // Get Channel limits  ( currently only valid for z,uv,veloc)
00786     virtual BOOL GetChannelMin(int chan, void *data)=0;
00802     virtual BOOL GetChannelMax(int chan, void *data)=0;
00803     
00804     // names indexed by NodeRenderId
00808     virtual NameTab& NodeRenderIDNameTab()=0;
00809 
00810     // Array of Image blur multipliers indexed by NodeRenderID
00813     virtual Tab<float>& ImageBlurMultiplierTab()=0;
00814 
00815     // Generic expansion function
00816     // JH 11/17/00 Now deriving from InterfaceServer. Extesibility via GetInterface()
00817     //virtual INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0) { return 0; } 
00818 
00819 
00820     // Gives the color corresponding to the id in input
00821     // This function represent the color-id mapping that is done for :
00822     // The Material Id render element
00823     // The Object Id render element
00824     // The Material Effects and Object channels of the rpf format
00825     // id - the material or object id for which the color is wanted
00826     // cOut - output color of BMM_Color_24 type
00836     CoreExport static void ColorById( int id , BMM_Color_24& cOut );
00837 
00838     };
00839 
00844 CoreExport void SetMaximumGBufferLayerDepth(int m);
00846 CoreExport int GetMaximumGBufferLayerDepth();
00847 
00852 CoreExport GBuffer *NewDefaultGBuffer();
00853