Changeset 3033 for GTP/trunk/App/Demos/Vis/FriendlyCulling
- Timestamp:
- 10/16/08 02:55:11 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
r3031 r3033 7 7 namespace CHCDemoEngine 8 8 { 9 10 11 GPUProgramParameters::GPUProgramParameters(ShaderProgram *p) 12 : mProgram(p) 13 { 14 } 15 16 void GPUProgramParameters::SetValue1f(int idx, float value) 17 { 18 } 19 20 21 void GPUProgramParameters::SetValue2f(int idx, float val1, float val2) 22 { 23 } 24 25 26 void GPUProgramParameters::SetValue3f(int idx, float val1, float val, float val3) 27 { 28 } 29 30 31 void GPUProgramParameters::SetArray1f(int idx, float *vals, int numElements) 32 { 33 } 34 35 36 void GPUProgramParameters::SetArray2f(int idx, float *vals, int numElements) 37 { 38 } 39 40 41 void GPUProgramParameters::SetArray3f(int idx, float *vals, int numElements) 42 { 43 } 44 45 46 void GPUProgramParameters::SetTexture(int idx, unsigned int tex) 47 { 48 } 49 50 51 void GPUProgramParameters::SetMatrix(int idx, Matrix4x4 *mat) 52 { 53 } 54 55 56 void GPUProgramParameters::SetValue1f(const string &name, float val) 57 { 58 SetValue1f(mProgram->GetParameter(name), val); 59 } 60 61 62 void ShaderProgram::SetValue2f(const string &name, float val1, float val2) 63 { 64 SetValue2f(mProgram->GetParameter(name), val1, val2); 65 } 66 67 68 void GPUProgramParameters::SetValue3f(const string &name, float val1, float val2, float val3) 69 { 70 SetValue3f(mProgram->GetParameter(name), val1, val2, val3); 71 } 72 73 74 void GPUProgramParameters::SetArray1f(const string &name, float *vals, int numElements) 75 { 76 SetArray1f(mProgram->GetParameter(name), numElements, (const float *)vals); 77 } 78 79 80 void GPUProgramParameters::GetParameter(const string &name, float *vals, int numElements) 81 { 82 SetArray2f(mProgram->GetParameter(name, numElements, (const float *)vals); 83 } 84 85 86 void GPUProgramParameters::SetArray3f(const string &name, float *vals, int numElements) 87 { 88 SetArray3f(mProgram->GetParameter(name), numElements, (const float *)vals); 89 } 90 91 92 void GPUProgramParameters::SetMatrix(const string &name, Matrix4x4 *mat) 93 { 94 SetMatrix(mProgram->GetParameter(name), mat); 95 } 96 97 98 void GPUProgramParameters::SetTexture(const string &name, unsigned int tex) 99 { 100 SetTexture(mProgram->GetOrCreateParameter(name), tex); 101 } 9 102 10 103 … … 22 115 23 116 if (mProgram) cgGLLoadProgram(mProgram); 117 118 mParameters.resize(64); 119 120 for (int i = 0; i < 64; ++ i) 121 { 122 mParameters[i] = NULL; 123 } 124 } 125 126 127 void ShaderProgram::Bind() 128 { 129 cgGLBindProgram(mProgram); 130 131 // enable all texture parameters 132 CGParameterArray::const_iterator it, it_end = mTextureParams.end(); 133 134 for (it = mTextureParams.begin(); it != it_end; ++ it) 135 cgGLEnableTextureParameter(*it); 136 } 137 138 139 /*void ShaderProgram::Release() 140 { 141 CGParameterArray::const_iterator it, it_end = mTextureParams.end(); 142 143 // disable all texture parameters 144 for (it = mTextureParams.begin(); it != it_end; ++ it) 145 cgGLDisableTextureParameter(*it); 146 }*/ 147 148 149 CGparameter ShaderProgram::AddParameter(const string &name, int idx) 150 { 151 CGparameter p = GetOrCreateParameter(name); 152 153 mParameters[idx] = p; 154 return p; 24 155 } 25 156 … … 33 164 { 34 165 p = cgGetNamedParameter(mProgram, name.c_str()); 35 mParamHash[name] = p;166 mParamHash[name] = i; 36 167 } 37 168 else 38 169 { 39 p = (*it).second;170 p = mParameters[(*it).second]; 40 171 } 41 172 … … 45 176 46 177 47 void ShaderProgram::SetValue1f(const string &name, float val) 48 { 49 cgGLSetParameter1f(GetOrCreateParameter(name), val); 50 } 51 52 53 void ShaderProgram::SetValue2f(const string &name, float val1, float val2) 54 { 55 cgGLSetParameter2f(GetOrCreateParameter(name), val1, val2); 56 } 57 58 59 void ShaderProgram::SetValue3f(const string &name, float val1, float val2, float val3) 60 { 61 cgGLSetParameter3f(GetOrCreateParameter(name), val1, val2, val3); 62 } 63 64 65 void ShaderProgram::SetArray1f(const string &name, float *vals, int numElements) 66 { 67 cgGLSetParameterArray1f(GetOrCreateParameter(name), 0, numElements, (const float *)vals); 68 } 69 70 71 void ShaderProgram::SetArray2f(const string &name, float *vals, int numElements) 72 { 73 cgGLSetParameterArray2f(GetOrCreateParameter(name), 0, numElements, (const float *)vals); 74 } 75 76 77 void ShaderProgram::SetArray3f(const string &name, float *vals, int numElements) 78 { 79 cgGLSetParameterArray3f(GetOrCreateParameter(name), 0, numElements, (const float *)vals); 80 } 81 82 83 void ShaderProgram::SetMatrix(const string &name, const Matrix4x4 &mat) 84 { 85 cgGLSetMatrixParameterfc(GetOrCreateParameter(name), (const float *)mat.x); 86 } 87 88 89 void ShaderProgram::SetTexture(const string &name, unsigned int tex) 90 { 91 CGparameter p = GetOrCreateParameter(name); 178 CGparameter ShaderProgram::GetParameter(int idx) const 179 { 180 CGparameter p = mParameters[idx]; 181 return p; 182 } 183 184 185 void ShaderProgram::SetValue1f(int idx, float val) 186 { 187 cgGLSetParameter1f(GetParameter(idx), val); 188 } 189 190 191 void ShaderProgram::SetValue2f(int idx, float val1, float val2) 192 { 193 cgGLSetParameter2f(GetParameter(idx), val1, val2); 194 } 195 196 197 void ShaderProgram::SetValue3f(int idx, float val1, float val2, float val3) 198 { 199 cgGLSetParameter3f(GetParameter(idx), val1, val2, val3); 200 } 201 202 203 void ShaderProgram::SetArray1f(int idx, float *vals, int numElements) 204 { 205 cgGLSetParameterArray1f(GetParameter(idx), 0, numElements, (const float *)vals); 206 } 207 208 209 void ShaderProgram::SetArray2f(int idx, float *vals, int numElements) 210 { 211 cgGLSetParameterArray2f(GetParameter(idx), 0, numElements, (const float *)vals); 212 } 213 214 215 void ShaderProgram::SetArray3f(int idx, float *vals, int numElements) 216 { 217 cgGLSetParameterArray3f(GetParameter(idx), 0, numElements, (const float *)vals); 218 } 219 220 221 void ShaderProgram::SetMatrix(int idx, const Matrix4x4 &mat) 222 { 223 cgGLSetMatrixParameterfc(GetParameter(idx), (const float *)mat.x); 224 } 225 226 227 void ShaderProgram::SetTexture(int idx, unsigned int tex) 228 { 229 CGparameter p = GetParameter(idx); 92 230 93 231 cgGLSetTextureParameter(p, tex); … … 98 236 99 237 100 void ShaderProgram::Bind() 101 { 102 cgGLBindProgram(mProgram); 103 104 // enable all texture parameters 105 CGParameterArray::const_iterator it, it_end = mTextureParams.end(); 106 107 for (it = mTextureParams.begin(); it != it_end; ++ it) 108 cgGLEnableTextureParameter(*it); 109 } 110 111 /* 112 void ShaderProgram::Release() 113 { 114 CGParameterArray::const_iterator it, it_end = mTextureParams.end(); 115 116 // disable all texture parameters 117 for (it = mTextureParams.begin(); it != it_end; ++ it) 118 cgGLDisableTextureParameter(*it); 119 } 120 */ 238 int ShaderProgram::GetParameter(const std::string &name) 239 { 240 return mParamHash[name]; 241 } 242 121 243 122 244 } // namespace -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
r3032 r3033 20 20 class ShadowMap; 21 21 class DirectionalLight; 22 class ShaderProgram; 22 23 23 typedef std::map<std::string, CGparameter> CGParameterMap; 24 25 typedef std::map<std::string, int> CGParameterMap; 24 26 typedef std::vector<CGparameter> CGParameterArray; 25 27 … … 32 34 class GPUProgramParameters 33 35 { 36 void SetValue1f(int idx, float value); 37 void SetValue2f(int idx, float val1, float val2); 38 void SetValue3f(int idx, float val1, float val, float val3); 39 40 void SetArray1f(int idx, float *vals, int numElements); 41 void SetArray2f(int idx, float *vals, int numElements); 42 void SetArray3f(int idx, float *vals, int numElements); 43 44 /** Sets the texture parameter. 45 */ 46 void SetTexture(int idx, unsigned int tex); 47 /** Sets the matrix parameter. 48 */ 49 void SetMatrix(int idx, Matrix4x4 *mat); 50 51 void SetValue1f(const std::string &name, float value); 52 void SetValue2f(const std::string &name, float val1, float val2); 53 void SetValue3f(const std::string &name, float val1, float val, float val3); 54 55 void SetArray1f(const std::string &name, float *vals, int numElements); 56 void SetArray2f(const std::string &name, float *vals, int numElements); 57 void SetArray3f(const std::string &name, float *vals, int numElements); 58 /** Sets the texture parameter. 59 */ 60 void SetTexture(const std::string &name, unsigned int tex); 61 /** Sets the matrix parameter. 62 */ 63 void SetMatrix(const std::string &name, Matrix4x4 *mat); 64 34 65 struct ParameterFloat 35 66 { 67 int mIndex; 36 68 float mValues[4]; 37 int numEntries; 69 float mNumComponents; 70 }; 71 72 struct ParameterValueInt 73 { 74 int mIndex; 75 float mValue; 76 }; 77 78 struct ParameterValueMatrix 79 { 80 int mIndex; 81 Matrix4x4 *mValue; 38 82 }; 39 83 40 84 struct ParameterValueArray 41 85 { 42 float mValues[256]; 43 int numEntries; 86 int mIndex; 44 87 45 float numComponents; 88 float *mValues; 89 int mNumEntries; 90 91 float mNumComponents; 46 92 }; 47 93 48 94 49 std::map<int, ParameterFloat> mParametersFloat;95 GPUProgramParameters(ShaderProgram *p); 50 96 51 std::map<int, int> mParametersTex; 52 std::map<int, Matrix4x4 *> mParametersMatrix; 97 98 protected: 99 100 ShaderProgram *mProgram; 101 102 std::vector<ParameterFloat> mFloats; 103 104 std::vector<ParameterValueInt> mTextures; 105 std::vector<ParameterValueMatrix> mMatrices; 53 106 }; 54 107 … … 57 110 class ShaderProgram 58 111 { 112 friend class GPUProgramParameters; 113 59 114 public: 60 115 … … 68 123 ~ShaderProgram() { if (mProgram != NULL) cgDestroyProgram(mProgram); } 69 124 70 void SetValue1f( const std::string &name, float value);71 void SetValue2f( const std::string &name, float val1, float val2);72 void SetValue3f( const std::string &name, float val1, float val, float val3);125 void SetValue1f(int idx, float value); 126 void SetValue2f(int idx, float val1, float val2); 127 void SetValue3f(int idx, float val1, float val, float val3); 73 128 74 void SetArray1f( const std::string &name, float *vals, int numElements);75 void SetArray2f( const std::string &name, float *vals, int numElements);76 void SetArray3f( const std::string &name, float *vals, int numElements);77 /** Sets the matrix parameter.78 */ 79 void Set Matrix(const std::string &name, const Matrix4x4 &mat);80 /** Sets the texture parameter. 81 */82 void SetTexture(const std::string &name, unsigned int tex); 129 void SetArray1f(int idx, float *vals, int numElements); 130 void SetArray2f(int idx, float *vals, int numElements); 131 void SetArray3f(int idx, float *vals, int numElements); 132 void SetMatrix(int idx, const Matrix4x4 &mat); 133 134 void SetTexture(int idx, unsigned int tex); 135 136 CGparameter AddParameter(const std::string &name, int idx); 137 83 138 /** Enable / disable a texture parameter. 84 139 */ 85 void EnableTexture(const std::string &name); 140 //void EnableTexture(const std::string &name); 141 //void DisableTexture(const std::string &name); 86 142 87 void DisableTexture(const std::string &name);88 143 /** Binds the program. 89 144 */ … … 91 146 /** Returns true if this program is valid. 92 147 */ 93 inline bool IsValid() { return mProgram != NULL; } 148 inline bool IsValid() const { return mProgram != NULL; } 149 150 inline int GetParameter(const std::string &name); 94 151 95 152 96 153 protected: 97 154 155 inline CGparameter GetParameter(int idx); 156 98 157 CGparameter GetOrCreateParameter(const std::string &name); 99 158 159 160 /////////////// 161 100 162 CGParameterMap mParamHash; 101 //CGParameterArray mParameters; 163 164 CGprogram mProgram; 102 165 103 166 CGParameterArray mTextureParams; 104 105 CGprogram mProgram;106 107 167 CGParameterArray mParameters; 108 168 };
Note: See TracChangeset
for help on using the changeset viewer.