OpenGL Volumizer 2.7 Reference Pages


NAME
vzTMFragmentProgram - Shader for using fragment programs.

INHERITS FROM
vzTMShader

HEADER FILE
#include <Volumizer2/TMFragmentProgram.h>

PUBLIC METHOD SUMMARY
static vzTMFragmentProgram* load ( const char* filename);
vzTMFragmentProgram ( char* fragmentProgram);
void setProgram ( char* fragmentProgram);
char* getProgram (  );
void setMultiTexCallbacks ( int numCB, vzTMShaderCB* callbacks, void* userData);
void getMultiTexCallbacks ( int& numCB, vzTMShaderCB*& callbacks, void*& userData);

PROTECTED METHOD SUMMARY
virtual ~vzTMFragmentProgram (  );

PROTECTED MEMBER SUMMARY
TMFragmentProgramImpl* _impl;

CLASS DESCRIPTION
The vzTMFragmentProgram is a built-in shader to be used with the vzTMRenderAction. The class is derived from vzTMShader and provides an interface for programmable shading using the ARB_fragment_program extension. The shader accepts the fragment program string as an argument to its constructor. The fragment program is applied to each polygon being rendered for the shape's geometry. The program string can be updated using the appropriate set method. The OpenGL state for the shader can be set and restored using the pre and post shape callbacks. The volume is rendered using 3D texture mapping with the given "volume" texture as the currently bound texture.

PARAMETERS
The shader uses a single parameter:


METHOD DESCRIPTIONS

   vzTMFragmentProgram()
vzTMFragmentProgram ( char* fragmentProgram);

Constructor. The program string is shallow copied internally to the fragment program and hence should not be deleted.

   ~vzTMFragmentProgram()
virtual ~vzTMFragmentProgram (  );

Destructor.

   getMultiTexCallbacks()
void getMultiTexCallbacks ( int& numCB, vzTMShaderCB*& callbacks, void*& userData);

Get the multi-texture callbacks.

   getProgram()
char* getProgram (  );

Get the program string for this shader.

   load()
static vzTMFragmentProgram* load ( const char* filename);

Factory used to load the fragment program from the given file name.

   setMultiTexCallbacks()
void setMultiTexCallbacks ( int numCB, vzTMShaderCB* callbacks, void* userData);

Sets the multi-texture callbacks for the fragment program. These callbacks can be used to the bind the volume textures and lookup tables to specific texture units corresponding to the callback number. The callbacks might be used to set texture unit/object specific OpenGL state by directly calling the corresponding OpenGL functions. The default number of callbacks is 0. The callbacks are defined as -
typedef void (*vzTMShaderCB)(vzTMShaderData *shaderData);

For example, the following code initializes the callbacks for a fragment program implementing a dependent texture lookup using the "lookup_table" parameter.
  
   static char FragmentProgram[] = "!!ARBfp1.0\n"
                                  "TEMP volume;\n"
                                  "TEX volume, fragment.texcoord[0], texture[0], 3D;\n"
                                  "TEX result.color, volume, texture[1], 1D;\n"
                                  "END"
  
   // Load the fragment program
   vzTMFragmentProgram *fp = new vzTMFragmentProgram(FragmentProgram);

   const int texCallbacks = 2;
   vzTMShaderCB *multiTexCB = new vzTMShaderCB[texCallbacks];
   multiTexCB[0] = tex0;
   multiTexCB[1] = tex1;

   // Set the multi-texture callbacks as slice callbacks
   fp->setMultiTexCallbacks(texCallbacks, multiTexCB, fp);
The multi-texture callbacks might look like the following two callbacks -

  void tex0(vzTMShaderData *data) {

    // enable "volume" texture
    data->bindVolumeTextureCB("volume", data, VZ_TM_ENABLE);

    // bind "volume" texture
    if(!data->bindVolumeTextureCB("volume", data)) {
      cerr<<"slice0: Error binding texture 'volume'"<<endl;
    }
  }
  
  void tex1(vzTMShaderData *data) {

    // enable "lookup_table" parameter (1D texture on Onyx4 systems)
    data->bindLookupTableCB("lookup_table", data, VZ_TM_ENABLE);
  
    // bind "lookup_table" parameter
    if(!data->bindLookupTableCB("lookup_table", data)) {
      cerr<<"slice1: Error binding texture 'lookup_table'"<<endl;
    }
  }

   setProgram()
void setProgram ( char* fragmentProgram);

Update the program string for the fragment program.

MEMBER DESCRIPTIONS

   _impl
TMFragmentProgramImpl* _impl;

SEE ALSO
vzParameterVolumeTexture, vzTMRenderAction, vzTMShader

Back to Index