Main Page   Compound List   File List   Compound Members   File Members  

CgBinding Class Reference

Virtual base class inherited by application to provide run-time binding with the shader program. More...

#include <cgbinding.h>

List of all members.

Public Methods

 CgBinding (void)
 Constructor for CgBinding interface.

 ~CgBinding (void)
 Destructor for the CgBinding class.

virtual bool ValidateVertexBindingType (VertexBindingType type)=0
virtual void * GetVertexBindingType (VertexBindingType type, void *context1, void *context2)=0
virtual bool ValidatePixelBindingType (VertexBindingType type)=0
virtual void * GetPixelBindingType (PixelBindingType type, void *context1, void *context2)=0
VertexBindingType AsciiToVertexBindingType (const char *bind_name)
 Convert ascii string into VertexBindingType.

PixelBindingType AsciiToPixelBindingType (const char *bind_name)
 Convert ascii string into PixelBindingType.

CgVertexShaderCreateVertexShader (const char *program, VertexBindingFormat type, unsigned int device)
 Create a vertex shader program by compiling a Cg source file.

CgPixelShaderCreatePixelShader (const char *program, unsigned int device)
 Create a pixel shader program by compiling a Cg source file.

bool ReleaseVertexShader (CgVertexShader *shader)
 Release a previously loaded VertexShader program.

bool ReleasePixelShader (CgPixelShader *shader)
 Release a previously loaded VertexShader program.

void * GetVertexAttributes (VertexBindingFormat type)
 Converts the enumerated vertex type into a valid vertex attributes pointer.

const char * GetLastListing (void) const
const char * GetLastError (void) const


Detailed Description

Virtual base class inherited by application to provide run-time binding with the shader program.

The application needs to only provide two services to run vertex shader programs. First it must be able to validate whether or not it knows how to manage a particular VertexBindingType and be able to provide real-time data for those binding types it says it can support. The same thing is true to bind pixel shader programs as well.

See also:
enum VertexBindingFormat , enum VertexBindingType , enum PixelBindingType
Author:
John W. Ratcliff
Date:
July 18, 2002


Constructor & Destructor Documentation

CgBinding::CgBinding void   
 

Constructor for CgBinding interface.

Simply initializes member variables to their default state.

Author:
John W. Ratcliff

CgBinding::~CgBinding void   
 

Destructor for the CgBinding class.

Free's up all previously allocated shader programs.

Author:
John W. Ratcliff


Member Function Documentation

PixelBindingType CgBinding::AsciiToPixelBindingType const char *    bind_name
 

Convert ascii string into PixelBindingType.

This method is the key routine that allows for the ability to run-time dynamically bind a Cg program to your application. Because Cg is a general purpose programming language you can name your variables anything you want. However, each one of these variables must be bound to your application so they can be updated int real-time.

Therefore each variable must be mapped to a specific application operation. If you create new variable name that must be bound to your application you should add it to the VertexBindingType enumeration and provide the ASCII mapping for it here. First make sure it doesn't map to an existing type, and if it does simply make it an alias. Realize that every single PixelBindingType is going to require application code on your part to provide that service.

The only reason that PixelBindings and VertexBindings are seperated out is because they are such distinctly different operations I felt it would create less confusion than if they were all mixed up into a single enumeration.

Parameters:
bind_name  Ascii name of the bind variable.
See also:
enum PixelBindingType
Author:
John W. Ratcliff

VertexBindingType CgBinding::AsciiToVertexBindingType const char *    bind_name
 

Convert ascii string into VertexBindingType.

This method is the key routine that allows for the ability to run-time dynamically bind a Cg program to your application. Because Cg is a general purpose programming language you can name your variables anything you want. However, each one of these variables must be bound to your application so they can be updated int real-time.

Therefore each variable must be mapped to a specific application operation. If you create new variable name that must be bound to your application you should add it to the VertexBindingType enumeration and provide the ASCII mapping for it here. First make sure it doesn't map to an existing type, and if it does simply make it an alias. Realize that every single VertexBindingType is going to require application code on your part to provide that service.

Parameters:
bind_name  Ascii name of the bind variable.
See also:
enum VertexBindingType
Author:
John W. Ratcliff

CgPixelShader * CgBinding::CreatePixelShader const char *    program,
unsigned int    device_handle
 

Create a pixel shader program by compiling a Cg source file.

This method creates a pixel shader on the current device by loading the Cg source code specified. If there are any errors it will return a null pointer and you can find out why it failed by calling the method GetLastError.

You can get the Cg compiler listing output by calling GetLastListing

Parameters:
program  The ASCII name of the Cg program to compile.
device_handle  The Direct3d device handle.
Author:
John W. Ratcliff

CgVertexShader * CgBinding::CreateVertexShader const char *    program,
VertexBindingFormat    type,
unsigned int    device_handle
 

Create a vertex shader program by compiling a Cg source file.

This method creates a vertex shader on the current device by loading the Cg source code specified. The Cg source file will be compiled and bound to the vertex format specified by the application. If there are any errors it will return a null pointer and you can find out why it failed by calling the method GetLastError.

You can get the Cg compiler listing output by calling GetLastListing

Parameters:
program  The ASCII name of the Cg program to compile.
type  Specifies what vertex format we want to bind the vertex shader to.
device_handle  The Direct3d device handle.
See also:
enum VertexBindingFormat
Author:
John W. Ratcliff

const char* CgBinding::GetLastError void    const [inline]
 

const char* CgBinding::GetLastListing void    const [inline]
 

virtual void* CgBinding::GetPixelBindingType PixelBindingType    type,
void *    context1,
void *    context2
[pure virtual]
 

void * CgBinding::GetVertexAttributes VertexBindingFormat    type
 

Converts the enumerated vertex type into a valid vertex attributes pointer.

Again, this is just a convenience method so that all of our supported vertex formats can reside in one centralized piece of code. This routine accepts the enumerated vertex format type and converts it into a proper vertex definition pointer to be passed down into the Cg program loader routine.

Parameters:
type  Specifies what vertex format we want to bind the vertex shader to.
See also:
enum VertexBindingFormat
Author:
John W. Ratcliff

virtual void* CgBinding::GetVertexBindingType VertexBindingType    type,
void *    context1,
void *    context2
[pure virtual]
 

bool CgBinding::ReleasePixelShader CgPixelShader   shader
 

Release a previously loaded VertexShader program.

Parameters:
shader  Pointer to the previously successfully loaded vertex shader program.
Author:
John W. Ratcliff

bool CgBinding::ReleaseVertexShader CgVertexShader   shader
 

Release a previously loaded VertexShader program.

Parameters:
shader  Pointer to the previously successfully loaded vertex shader program.
Author:
John W. Ratcliff

virtual bool CgBinding::ValidatePixelBindingType VertexBindingType    type [pure virtual]
 

virtual bool CgBinding::ValidateVertexBindingType VertexBindingType    type [pure virtual]
 


The documentation for this class was generated from the following files:
Generated on Sun Jul 21 13:35:16 2002 for CgBinding by doxygen1.2.17