Class GBufWriter

3DS Max Plug-In SDK

Class GBufWriter

See Also: Class GBuffer, Class GBufReader, Structure GBufData, List of GBuffer Channels Indexes.

class GBufWriter : public InterfaceServer

Description:

This class is available in release 3.0 and later only.

This is the writer object returned from GBuffer::CreateWriter(). This class assumes pixels are created in increasing order of x.

Here is an example of writing multiple layer data to the G-Buffer using methods of this class.

 GBuffer *gb = NewDefaultGBuffer();

 gb->SetRasterSize(100,10);

 gb->CreateChannels((1<<GB_Z)|(1<<GB_MTL_ID)|(1<<GB_BG));

 gb->InitBuffer();

 

 GBufWriter *wrt = gb->CreateWriter();

 for (int y=0; y<10; y++) {

  wrt->StartLine(y);

  BOOL bb = 0;

  for (int x=5; x<100; x+=4) {

   wrt->StartPixel(x);

   wrt->StartNextLayer();

   float z = 5.0f*float(x)*float(y);

   wrt->WriteChannelData(GB_Z,(void *)&z);

   UBYTE mid = 36+x;

   wrt->WriteChannelData(GB_MTL_ID,(void *)&mid);

   Color24 c;

   c.r = 10+x; c.g = 20+x; c.b = 30+x;

   wrt->WriteChannelData(GB_BG,(void *)&c);

 

   wrt->StartNextLayer();

   z = 15.0f*float(x)*float(y);

   wrt->WriteChannelData(GB_Z,(void *)&z);

   mid = 26+x;

   wrt->WriteChannelData(GB_MTL_ID,(void *)&mid);

   c.r =30+x; c.g = 20+x; c.b = 10+x;

   wrt->WriteChannelData(GB_BG,(void *)&c);

 

   if (bb) {

    wrt->StartNextLayer();

    z = 17.0f*float(x)*float(y);

    wrt->WriteChannelData(GB_Z,(void *)&z);

    mid = 64+x;

    wrt->WriteChannelData(GB_MTL_ID,(void *)&mid);

    c.r = 130+x; c.g = 120+x; c.b = 110+x;

    wrt->WriteChannelData(GB_BG,(void *)&c);

    }

   bb = !bb;

   }

  wrt->EndLine();

  }

 gb->DestroyWriter(wrt);

All methods of this class are implemented by the System.

Methods:

public:

Prototype:

virtual void StartLine(int y)=0;

Remarks:

This method should be called before writing every line.

Parameters:

int y

The zero based index of the scan line to start.

Prototype:

virtual void StartPixel(int x)=0;

Remarks:

This method must be called before writing each pixel and must be called with increasing x values on a line.

Parameters:

int x

The zero based index of the pixel to start.

Prototype:

virtual void StartNextLayer()=0;

Remarks:

This method must be called before writing the first layer.

Prototype:

virtual BOOL WriteChannelData(int chan, void *data)=0;

Remarks:

Call this method to write a data element to the specified channel of the G-Buffer to the current scan line and pixel.

Parameters:

int chan

See List of GBuffer Channels Indexes.

void *data

Points to the G-Buffer data to write.

Return Value:

TRUE on success; FALSE on failure.

Prototype:

virtual BOOL WriteAllData(GBufData *data)=0;

Remarks:

This method writes all the channel data from the GBufData structure passed to the current scan line and pixel.

Parameters:

GBufData *data

Points to the G-Buffer data to write. See Structure GBufData.

Return Value:

TRUE on success; FALSE on failure.

Prototype:

virtual BOOL EndLine()=0;

Remarks:

This method should be called after writing each line.

Return Value:

TRUE on success; FALSE on failure.

Prototype:

virtual void DeleteThis()=0;

Remarks:

Deletes this writer object. Call this method when finished using it.