Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Writing a Loader/Saver Plug-In

This section presents information common to the development of a Scene Loader or Saver Plug-In. It discusses the sample files, the plug-in directory search mechanism, and the standard DLL functions.

Loader and Saver plug-ins are implemented as dynamic link libraries (DLLs). DLLs are object code libraries that let multiple programs share code, data, and resources. Dynamic linking allows an executable module to include only the information needed at run time to locate the executable code for a DLL function. This type of linking differs from the more familiar static linking, which requires a copy of a library function's executable code in the executable module of each application using it.

The development tool for creating these DLLs is Microsoft Visual C++. For a description of how to create a new plug-in see Creating a New Plug-in Project.

Required Plug-In Entry Points

There are two DLL entry points that a plug-in must export. These two 'must have' entry points are:

Implementation of the Plug-In Entry Points

This section briefly points out, in general terms, how the entry points can be implemented.

Implementation of queryPlugInterfaceType

The following sample code shows a possible implementation of a Plug-In for both loading and saving .NBF files:

// NBFLoaderSaver.cpp

#include "nvsg/PlugInterfaceID.h" // definition of UPITID_VERSION,
                                  // UPITID_SCENE_LOADER, and
                                  // UPITID_SCENE_SAVER

// unique plug-in types
const UPITID PITID_SCENE_LOADER(UPITID_SCENE_LOADER, UPITID_VERSION);
const UPITID PITID_SCENE_SAVER(UPITID_SCENE_SAVER, UPITID_VERSION);

bool queryPlugInterfaceType(const UPITID& pitid, vector<UPIID>& piids)
{
  piids.clear();
  if ( pitid==PITID_SCENE_LOADER )
  {
    piids.push_back(UPIID(".NBF", PITID_SCENE_LOADER));
  }
  else if ( pitid==PITID_SCENE_SAVER )
  {
    piids.push_back(UPIID(".NBF", PITID_SCENE_LOADER));
  }
  return !piids.empty();
}

Implementation of getPlugInterface

The following sample code shows a possible implementation of a Plug-In for both loading and saving .NBF files:

bool getPlugInterface(const UPIID& piid, PlugIn *& pi)
{
  const UPIID PIID_NBF_SCENE_LOADER = UPIID(".NBF", PITID_SCENE_LOADER));
  const UPIID PIID_NBF_SCENE_SAVER  = UPIID(".NBF", PITID_SCENE_SAVER));

  if ( piid==PIID_NBF_SCENE_LOADER )
  {
    return !!(pi=new NBFLoader());
  }
  else if ( piid==PIID_NBF_SCENE_SAVER )
  {
    return !!(pi=new NBFSaver());
  }
  return false;
}

Back to Working With NVSG Classes


Generated on Tue Mar 1 13:20:21 2005 for NVSGSDK by NVIDIA