Ignore:
Timestamp:
Apr 1, 2012, 12:26:04 PM (13 years ago)
Author:
ldelgass
Message:

Begin to isolate Cg code in NvShader? and subclasses. Add Cg profile defaults
and instance members to centralize profile. Add bind/unbind methods to
NvShader? that bind/unbind programs with the appropriate profile. Add a
private static method loadCgSourceProgram to replace the global
LoadCgSourceProgram? after all users are converted to using NvShader? and its
loader methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/NvShader.cpp

    r2877 r2911  
    1111#include "Trace.h"
    1212
     13CGprofile NvShader::_defaultVertexProfile = CG_PROFILE_VP40;
     14CGprofile NvShader::_defaultFragmentProfile = CG_PROFILE_FP40;
    1315CGcontext NvShader::_cgContext = NULL;
    1416
    15 void NvShader::initCg()
     17void NvShader::initCg(CGprofile defaultVertexProfile,
     18                      CGprofile defaultFragmentProfile)
    1619{
     20    _defaultVertexProfile = defaultVertexProfile;
     21    _defaultFragmentProfile = defaultFragmentProfile;
    1722    _cgContext = cgCreateContext();
    1823}
     
    2328    printErrorInfo();
    2429    if (_cgContext != NULL) {
     30        TRACE("Before DestroyContext");
    2531        cgDestroyContext(_cgContext);
     32        TRACE("After DestroyContext");
    2633        _cgContext = NULL;
    2734    }
     
    4249
    4350CGprogram
    44 LoadCgSourceProgram(CGcontext context, const char *fileName, CGprofile profile,
    45                     const char *entryPoint)
     51LoadCgSourceProgram(CGcontext context, const char *fileName,
     52                    CGprofile profile, const char *entryPoint)
     53{
     54    return NvShader::loadCgSourceProgram(context, fileName,
     55                                         profile, entryPoint);
     56}
     57
     58CGprogram
     59NvShader::loadCgSourceProgram(CGcontext context, const char *fileName,
     60                              CGprofile profile, const char *entryPoint)
    4661{
    4762    const char *path = R2FilePath::getInstance()->getPath(fileName);
     
    6479
    6580NvShader::NvShader():
     81    _vertexProfile(_defaultVertexProfile),
     82    _fragmentProfile(_defaultFragmentProfile),
    6683    _cgVP(NULL),
    6784    _cgFP(NULL)
     
    7188NvShader::~NvShader()
    7289{
    73     resetPrograms();
     90    TRACE("In ~NvShader");
     91    if (_cgContext == NULL) {
     92        TRACE("Lost Cg context");
     93    } else {
     94        resetPrograms();
     95    }
    7496}
    7597
    7698void NvShader::loadVertexProgram(const char *fileName, const char *entryPoint)
    7799{
    78     resetPrograms();
    79 
    80     _cgVP = LoadCgSourceProgram(_cgContext, fileName, CG_PROFILE_VP40, entryPoint);
     100    if (_cgVP != NULL) {
     101        cgDestroyProgram(_cgVP);
     102    }
     103    _cgVP = loadCgSourceProgram(_cgContext, fileName,
     104                                _vertexProfile, entryPoint);
    81105}
    82106
    83107void NvShader::loadFragmentProgram(const char *fileName, const char *entryPoint)
    84108{
    85     _cgFP = LoadCgSourceProgram(_cgContext, fileName, CG_PROFILE_FP40, entryPoint);
     109    if (_cgFP != NULL) {
     110        cgDestroyProgram(_cgFP);
     111    }
     112    _cgFP = loadCgSourceProgram(_cgContext, fileName,
     113                                _fragmentProfile, entryPoint);
    86114}
    87115
Note: See TracChangeset for help on using the changeset viewer.