Changeset 2911 for trunk/packages
- Timestamp:
- Apr 1, 2012, 12:26:04 PM (13 years ago)
- Location:
- trunk/packages/vizservers/nanovis
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/nanovis/NvShader.cpp
r2877 r2911 11 11 #include "Trace.h" 12 12 13 CGprofile NvShader::_defaultVertexProfile = CG_PROFILE_VP40; 14 CGprofile NvShader::_defaultFragmentProfile = CG_PROFILE_FP40; 13 15 CGcontext NvShader::_cgContext = NULL; 14 16 15 void NvShader::initCg() 17 void NvShader::initCg(CGprofile defaultVertexProfile, 18 CGprofile defaultFragmentProfile) 16 19 { 20 _defaultVertexProfile = defaultVertexProfile; 21 _defaultFragmentProfile = defaultFragmentProfile; 17 22 _cgContext = cgCreateContext(); 18 23 } … … 23 28 printErrorInfo(); 24 29 if (_cgContext != NULL) { 30 TRACE("Before DestroyContext"); 25 31 cgDestroyContext(_cgContext); 32 TRACE("After DestroyContext"); 26 33 _cgContext = NULL; 27 34 } … … 42 49 43 50 CGprogram 44 LoadCgSourceProgram(CGcontext context, const char *fileName, CGprofile profile, 45 const char *entryPoint) 51 LoadCgSourceProgram(CGcontext context, const char *fileName, 52 CGprofile profile, const char *entryPoint) 53 { 54 return NvShader::loadCgSourceProgram(context, fileName, 55 profile, entryPoint); 56 } 57 58 CGprogram 59 NvShader::loadCgSourceProgram(CGcontext context, const char *fileName, 60 CGprofile profile, const char *entryPoint) 46 61 { 47 62 const char *path = R2FilePath::getInstance()->getPath(fileName); … … 64 79 65 80 NvShader::NvShader(): 81 _vertexProfile(_defaultVertexProfile), 82 _fragmentProfile(_defaultFragmentProfile), 66 83 _cgVP(NULL), 67 84 _cgFP(NULL) … … 71 88 NvShader::~NvShader() 72 89 { 73 resetPrograms(); 90 TRACE("In ~NvShader"); 91 if (_cgContext == NULL) { 92 TRACE("Lost Cg context"); 93 } else { 94 resetPrograms(); 95 } 74 96 } 75 97 76 98 void NvShader::loadVertexProgram(const char *fileName, const char *entryPoint) 77 99 { 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); 81 105 } 82 106 83 107 void NvShader::loadFragmentProgram(const char *fileName, const char *entryPoint) 84 108 { 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); 86 114 } 87 115 -
trunk/packages/vizservers/nanovis/NvShader.h
r2870 r2911 3 3 #define NV_SHADER_H 4 4 5 #include <GL/glew.h> 5 6 #include <Cg/cg.h> 7 #include <Cg/cgGL.h> 6 8 7 extern CGprogram LoadCgSourceProgram(CGcontext context, const char *filename, 8 CGprofile profile, const char *entryPoint); 9 #include "Trace.h" 10 11 extern CGprogram 12 LoadCgSourceProgram(CGcontext context, const char *fileName, 13 CGprofile profile, const char *entryPoint) 9 14 10 15 class NvShader … … 47 52 } 48 53 54 void setTextureParameter(CGparameter param, GLuint texobj) 55 { 56 cgGLSetTextureParameter(param, texobj); 57 } 58 49 59 CGprogram getVP() const 50 60 { … … 57 67 } 58 68 59 static void initCg(); 69 virtual void bind() 70 { 71 if (_cgVP) { 72 cgGLBindProgram(_cgVP); 73 enableVertexProfile(); 74 } 75 if (_cgFP) { 76 cgGLBindProgram(_cgFP); 77 enableFragmentProfile(); 78 } 79 } 80 81 virtual void unbind() 82 { 83 if (_cgVP) 84 disableVertexProfile(); 85 if (_cgFP) 86 disableFragmentProfile(); 87 } 88 89 void enableVertexProfile() 90 { 91 cgGLEnableProfile(_vertexProfile); 92 } 93 94 void disableVertexProfile() 95 { 96 cgGLDisableProfile(_vertexProfile); 97 } 98 99 void enableFragmentProfile() 100 { 101 cgGLEnableProfile(_fragmentProfile); 102 } 103 104 void disableFragmentProfile() 105 { 106 cgGLDisableProfile(_fragmentProfile); 107 } 108 109 static void initCg(CGprofile defaultVertexProfile = CG_PROFILE_VP40, 110 CGprofile defaultFragmentProfile = CG_PROFILE_FP40); 60 111 61 112 static void exitCg(); … … 73 124 void resetPrograms(); 74 125 126 CGprofile _vertexProfile; 127 CGprofile _fragmentProfile; 75 128 CGprogram _cgVP; 76 129 CGprogram _cgFP; 77 130 131 static CGprofile _defaultVertexProfile; 132 static CGprofile _defaultFragmentProfile; 78 133 static CGcontext _cgContext; 134 135 private: 136 static CGprogram 137 loadCgSourceProgram(CGcontext context, const char *filename, 138 CGprofile profile, const char *entryPoint); 79 139 }; 80 140
Note: See TracChangeset
for help on using the changeset viewer.