1 | #include "ShaderProgram.h"
|
---|
2 | #include "Matrix4x4.h"
|
---|
3 | #include "Timer/PerfTimer.h"
|
---|
4 | #include "Vector3.h"
|
---|
5 | #include "Camera.h"
|
---|
6 | #include "Light.h"
|
---|
7 | #include "SceneEntity.h"
|
---|
8 | #include "Transform3.h"
|
---|
9 |
|
---|
10 | using namespace std;
|
---|
11 |
|
---|
12 | namespace CHCDemoEngine
|
---|
13 | {
|
---|
14 |
|
---|
15 | //////////
|
---|
16 | //-- changing shader parameters
|
---|
17 |
|
---|
18 | static float sCurrentTimer = 0;
|
---|
19 | static float sOldTimer = 0;
|
---|
20 | static Matrix4x4 sCurrentViewMatrix = IdentityMatrix();
|
---|
21 | static Vector3 sCurrentViewDir = Vector3::UNIT_Y();
|
---|
22 | static Vector3 sCurrentLightDir = Vector3::UNIT_Y();
|
---|
23 |
|
---|
24 |
|
---|
25 |
|
---|
26 | /*********************************************************/
|
---|
27 | /* GPUProgramParameters implementation */
|
---|
28 | /*********************************************************/
|
---|
29 |
|
---|
30 |
|
---|
31 | GPUProgramParameters::GPUProgramParameters(ShaderProgram *p):
|
---|
32 | mProgram(p)
|
---|
33 | {
|
---|
34 | Reset();
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | GPUProgramParameters::GPUProgramParameters():
|
---|
39 | mProgram(NULL)
|
---|
40 | {
|
---|
41 | Reset();
|
---|
42 | }
|
---|
43 |
|
---|
44 |
|
---|
45 | void GPUProgramParameters::Reset()
|
---|
46 | {
|
---|
47 | mFloats.clear();
|
---|
48 | mTextures.clear();
|
---|
49 | mMatrices.clear();
|
---|
50 | mArrays.clear();
|
---|
51 | mMatrixArrays.clear();
|
---|
52 |
|
---|
53 | mTimerParam = -1;
|
---|
54 | mOldTimerParam = -1;
|
---|
55 | mViewDirParam = -1;
|
---|
56 | mLightDirParam = -1;
|
---|
57 | mViewMatrixParam = -1;
|
---|
58 |
|
---|
59 | mModelMatrixParam = -1;
|
---|
60 | mOldModelMatrixParam = -1;
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | void GPUProgramParameters::SetValue1f(int idx, float value)
|
---|
65 | {
|
---|
66 | if (mFloats.size() < idx + 1)
|
---|
67 | mFloats.resize(idx + 1);
|
---|
68 |
|
---|
69 | mFloats[idx] = FloatParam(&value, 1);
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | void GPUProgramParameters::SetValue2f(int idx, float val1, float val2)
|
---|
74 | {
|
---|
75 | if (mFloats.size() < idx + 1)
|
---|
76 | mFloats.resize(idx + 1);
|
---|
77 |
|
---|
78 | float vals[] = {val1, val2};
|
---|
79 |
|
---|
80 | mFloats[idx] = FloatParam(vals, 2);
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | void GPUProgramParameters::SetValue3f(int idx, float val1, float val2, float val3)
|
---|
85 | {
|
---|
86 | if (mFloats.size() < idx + 1)
|
---|
87 | mFloats.resize(idx + 1);
|
---|
88 |
|
---|
89 | float vals[] = {val1, val2, val3};
|
---|
90 |
|
---|
91 | mFloats[idx] = FloatParam(vals, 3);
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | void GPUProgramParameters::SetArray1f(int idx, float *vals, int numElements)
|
---|
96 | {
|
---|
97 | if (mArrays.size() < idx + 1)
|
---|
98 | mArrays.resize(idx + 1);
|
---|
99 |
|
---|
100 | mArrays[idx] = ArrayParam(vals, 1, numElements);
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | void GPUProgramParameters::SetArray2f(int idx, float *vals, int numElements)
|
---|
105 | {
|
---|
106 | if (mArrays.size() < idx + 1)
|
---|
107 | mArrays.resize(idx + 1);
|
---|
108 |
|
---|
109 | mArrays[idx] = ArrayParam(vals, 2, numElements);
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | void GPUProgramParameters::SetArray3f(int idx, float *vals, int numElements)
|
---|
114 | {
|
---|
115 | if (mArrays.size() < idx + 1)
|
---|
116 | mArrays.resize(idx + 1);
|
---|
117 |
|
---|
118 | mArrays[idx] = ArrayParam(vals, 3, numElements);
|
---|
119 | }
|
---|
120 |
|
---|
121 |
|
---|
122 | void GPUProgramParameters::SetMatrixArray(int idx, float *mats, int numElements)
|
---|
123 | {
|
---|
124 | if (mMatrixArrays.size() < idx + 1)
|
---|
125 | mMatrixArrays.resize(idx + 1);
|
---|
126 |
|
---|
127 | mMatrixArrays[idx] = MatrixArrayParam(mats, numElements);
|
---|
128 | }
|
---|
129 |
|
---|
130 |
|
---|
131 | void GPUProgramParameters::SetTexture(int idx, unsigned int tex)
|
---|
132 | {
|
---|
133 | if (mTextures.size() < idx + 1)
|
---|
134 | mTextures.resize(idx + 1);
|
---|
135 |
|
---|
136 | mTextures[idx] = IntParam(tex);
|
---|
137 | }
|
---|
138 |
|
---|
139 |
|
---|
140 | void GPUProgramParameters::SetMatrix(int idx, const Matrix4x4 &mat)
|
---|
141 | {
|
---|
142 | if (mMatrices.size() < idx + 1)
|
---|
143 | mMatrices.resize(idx + 1);
|
---|
144 |
|
---|
145 | mMatrices[idx] = MatrixParam(mat);
|
---|
146 | }
|
---|
147 |
|
---|
148 |
|
---|
149 | void GPUProgramParameters::SetTimerParam(int idx)
|
---|
150 | {
|
---|
151 | mTimerParam = idx;
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | void GPUProgramParameters::SetOldTimerParam(int idx)
|
---|
156 | {
|
---|
157 | mOldTimerParam = idx;
|
---|
158 | }
|
---|
159 |
|
---|
160 |
|
---|
161 | void GPUProgramParameters::SetViewMatrixParam(int idx)
|
---|
162 | {
|
---|
163 | mViewMatrixParam = idx;
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | void GPUProgramParameters::SetViewDirParam(int idx)
|
---|
168 | {
|
---|
169 | mViewDirParam = idx;
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 | void GPUProgramParameters::SetLightDirParam(int idx)
|
---|
174 | {
|
---|
175 | mLightDirParam = idx;
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 | void GPUProgramParameters::SetModelMatrixParam(int idx)
|
---|
180 | {
|
---|
181 | mModelMatrixParam = idx;
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | void GPUProgramParameters::SetOldModelMatrixParam(int idx)
|
---|
186 | {
|
---|
187 | mOldModelMatrixParam = idx;
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | void GPUProgramParameters::SetValue1f(const string &name, float val)
|
---|
192 | {
|
---|
193 | SetValue1f(mProgram->GetParamIdxByName(name), val);
|
---|
194 | }
|
---|
195 |
|
---|
196 |
|
---|
197 | void GPUProgramParameters::SetValue2f(const string &name, float val1, float val2)
|
---|
198 | {
|
---|
199 | SetValue2f(mProgram->GetParamIdxByName(name), val1, val2);
|
---|
200 | }
|
---|
201 |
|
---|
202 |
|
---|
203 | void GPUProgramParameters::SetValue3f(const string &name, float val1, float val2, float val3)
|
---|
204 | {
|
---|
205 | SetValue3f(mProgram->GetParamIdxByName(name), val1, val2, val3);
|
---|
206 | }
|
---|
207 |
|
---|
208 |
|
---|
209 | void GPUProgramParameters::SetArray1f(const string &name, float *vals, int numElements)
|
---|
210 | {
|
---|
211 | SetArray1f(mProgram->GetParamIdxByName(name), vals, numElements);
|
---|
212 | }
|
---|
213 |
|
---|
214 |
|
---|
215 | void GPUProgramParameters::SetArray2f(const string &name, float *vals, int numElements)
|
---|
216 | {
|
---|
217 | SetArray2f(mProgram->GetParamIdxByName(name), vals, numElements);
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 | void GPUProgramParameters::SetArray3f(const string &name, float *vals, int numElements)
|
---|
222 | {
|
---|
223 | SetArray3f(mProgram->GetParamIdxByName(name), vals, numElements);
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | void GPUProgramParameters::SetMatrix(const string &name, const Matrix4x4 &mat)
|
---|
228 | {
|
---|
229 | SetMatrix(mProgram->GetParamIdxByName(name), mat);
|
---|
230 | }
|
---|
231 |
|
---|
232 |
|
---|
233 | void GPUProgramParameters::SetMatrixArray(const string &name, float *mats, int numElements)
|
---|
234 | {
|
---|
235 | SetMatrixArray(mProgram->GetParamIdxByName(name), mats, numElements);
|
---|
236 | }
|
---|
237 |
|
---|
238 |
|
---|
239 | void GPUProgramParameters::SetTexture(const string &name, unsigned int tex)
|
---|
240 | {
|
---|
241 | SetTexture(mProgram->GetParamIdxByName(name), tex);
|
---|
242 | }
|
---|
243 |
|
---|
244 |
|
---|
245 | void GPUProgramParameters::UpdateParameters(SceneEntity *ent)
|
---|
246 | {
|
---|
247 | if (!mProgram) return;
|
---|
248 |
|
---|
249 | for (int i = 0; i < (int)mFloats.size(); ++ i)
|
---|
250 | {
|
---|
251 | const FloatParam &p = mFloats[i];
|
---|
252 |
|
---|
253 | if (!p.mValid) continue;
|
---|
254 |
|
---|
255 | switch (p.mNumComponents)
|
---|
256 | {
|
---|
257 | case 1:
|
---|
258 | mProgram->SetValue1f(i, p.mValues[0]);
|
---|
259 | break;
|
---|
260 | case 2:
|
---|
261 | mProgram->SetValue2f(i, p.mValues[0], p.mValues[1]);
|
---|
262 | break;
|
---|
263 | case 3:
|
---|
264 | mProgram->SetValue3f(i, p.mValues[0], p.mValues[1], p.mValues[2]);
|
---|
265 | break;
|
---|
266 | default:
|
---|
267 | mProgram->SetValue1f(i, p.mValues[0]);
|
---|
268 | }
|
---|
269 | }
|
---|
270 |
|
---|
271 | for (int i = 0; i < (int)mTextures.size(); ++ i)
|
---|
272 | {
|
---|
273 | const IntParam &p = mTextures[i];
|
---|
274 |
|
---|
275 | if (p.mValid)
|
---|
276 | mProgram->SetTexture(i, p.mValue);
|
---|
277 | }
|
---|
278 |
|
---|
279 | for (int i = 0; i < (int)mMatrices.size(); ++ i)
|
---|
280 | {
|
---|
281 | const MatrixParam &p = mMatrices[i];
|
---|
282 |
|
---|
283 | if (p.mValid) mProgram->SetMatrix(i, p.mValue);
|
---|
284 | }
|
---|
285 |
|
---|
286 | for (int i = 0; i < (int)mArrays.size(); ++ i)
|
---|
287 | {
|
---|
288 | const ArrayParam &p = mArrays[i];
|
---|
289 |
|
---|
290 | if (!p.mValid) continue;
|
---|
291 |
|
---|
292 | switch (p.mNumComponents)
|
---|
293 | {
|
---|
294 | case 1:
|
---|
295 | mProgram->SetArray1f(i, p.mValues, p.mNumEntries);
|
---|
296 | break;
|
---|
297 | case 2:
|
---|
298 | mProgram->SetArray2f(i, p.mValues, p.mNumEntries);
|
---|
299 | break;
|
---|
300 | case 3:
|
---|
301 | mProgram->SetArray3f(i, p.mValues, p.mNumEntries);
|
---|
302 | break;
|
---|
303 | default:
|
---|
304 | mProgram->SetArray1f(i, p.mValues, p.mNumEntries);
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | for (int i = 0; i < (int)mMatrixArrays.size(); ++ i)
|
---|
309 | {
|
---|
310 | const MatrixArrayParam &p = mMatrixArrays[i];
|
---|
311 |
|
---|
312 | if (p.mValid)
|
---|
313 | mProgram->SetMatrixArray(i, p.mValues, p.mNumEntries);
|
---|
314 | }
|
---|
315 |
|
---|
316 | if (mTimerParam >= 0)
|
---|
317 | mProgram->SetValue1f(mTimerParam, sCurrentTimer);
|
---|
318 | if (mOldTimerParam >= 0)
|
---|
319 | mProgram->SetValue1f(mOldTimerParam, sOldTimer);
|
---|
320 | if (mViewDirParam >= 0)
|
---|
321 | mProgram->SetValue3f(mViewDirParam, sCurrentViewDir.x, sCurrentViewDir.y, sCurrentViewDir.z);
|
---|
322 | if (mLightDirParam >= 0)
|
---|
323 | mProgram->SetValue3f(mLightDirParam, sCurrentLightDir.x, sCurrentLightDir.y, sCurrentLightDir.z);
|
---|
324 | if (mViewMatrixParam >= 0)
|
---|
325 | mProgram->SetMatrix(mViewMatrixParam, sCurrentViewMatrix);
|
---|
326 |
|
---|
327 | if (ent)
|
---|
328 | {
|
---|
329 | if (mModelMatrixParam >= 0)
|
---|
330 | mProgram->SetMatrix(mModelMatrixParam, ent->GetTransform()->GetMatrix());
|
---|
331 | if (mOldModelMatrixParam >= 0)
|
---|
332 | mProgram->SetMatrix(mOldModelMatrixParam, ent->GetTransform()->GetOldMatrix());
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 |
|
---|
337 | void GPUProgramParameters::InitFrame(Camera *cam, DirectionalLight *light)
|
---|
338 | {
|
---|
339 | static PerfTimer mytimer;
|
---|
340 | sOldTimer = sCurrentTimer;
|
---|
341 | sCurrentTimer = mytimer.Elapsedms(false) * M_PI / 180.0f;
|
---|
342 |
|
---|
343 | cam->GetModelViewMatrix(sCurrentViewMatrix);
|
---|
344 | sCurrentViewDir = cam->GetDirection();
|
---|
345 |
|
---|
346 | Matrix4x4 vo;
|
---|
347 | // transform to view space
|
---|
348 | cam->GetViewOrientationMatrix(vo);
|
---|
349 | sCurrentLightDir = vo * -light->GetDirection();
|
---|
350 | }
|
---|
351 |
|
---|
352 |
|
---|
353 |
|
---|
354 | /********************************************************/
|
---|
355 | /* ShaderProgram implementation */
|
---|
356 | /********************************************************/
|
---|
357 |
|
---|
358 |
|
---|
359 | ShaderProgram::ShaderProgram(CGcontext context,
|
---|
360 | const std::string &filename,
|
---|
361 | CGprofile profile,
|
---|
362 | const std::string &functionName,
|
---|
363 | PROGRAM_TYPE programType):
|
---|
364 | mProgramType(programType)
|
---|
365 | {
|
---|
366 | mProgram = cgCreateProgramFromFile(context,
|
---|
367 | CG_SOURCE,
|
---|
368 | filename.c_str(),
|
---|
369 | profile,
|
---|
370 | functionName.c_str(),
|
---|
371 | NULL);
|
---|
372 |
|
---|
373 | if (mProgram) cgGLLoadProgram(mProgram);
|
---|
374 |
|
---|
375 | const int maxParams = 64;
|
---|
376 | mParameters.resize(maxParams);
|
---|
377 |
|
---|
378 | for (int i = 0; i < maxParams; ++ i)
|
---|
379 | mParameters[i] = NULL;
|
---|
380 | }
|
---|
381 |
|
---|
382 |
|
---|
383 | void ShaderProgram::Bind()
|
---|
384 | {
|
---|
385 | cgGLBindProgram(mProgram);
|
---|
386 |
|
---|
387 | // enable all texture parameters
|
---|
388 | CGParameterArray::const_iterator it, it_end = mTextureParams.end();
|
---|
389 |
|
---|
390 | for (it = mTextureParams.begin(); it != it_end; ++ it)
|
---|
391 | cgGLEnableTextureParameter(*it);
|
---|
392 | }
|
---|
393 |
|
---|
394 |
|
---|
395 | void ShaderProgram::Release()
|
---|
396 | {
|
---|
397 | CGParameterArray::const_iterator it, it_end = mTextureParams.end();
|
---|
398 |
|
---|
399 | // disable all texture parameters
|
---|
400 | for (it = mTextureParams.begin(); it != it_end; ++ it)
|
---|
401 | cgGLDisableTextureParameter(*it);
|
---|
402 | }
|
---|
403 |
|
---|
404 |
|
---|
405 | CGparameter ShaderProgram::AddParameter(const string &name, int idx)
|
---|
406 | {
|
---|
407 | CGparameter p = GetOrCreateParameter(name);
|
---|
408 |
|
---|
409 | mParamHash[name] = idx;
|
---|
410 | mParameters[idx] = p;
|
---|
411 |
|
---|
412 | return p;
|
---|
413 | }
|
---|
414 |
|
---|
415 |
|
---|
416 | void ShaderProgram::AddParameters(std::string params[],
|
---|
417 | int startIdx,
|
---|
418 | int numElements)
|
---|
419 | {
|
---|
420 | for (int i = 0; i < numElements; ++ i)
|
---|
421 | AddParameter(params[i], startIdx + i);
|
---|
422 | }
|
---|
423 |
|
---|
424 |
|
---|
425 | CGparameter ShaderProgram::GetOrCreateParameter(const string &name)
|
---|
426 | {
|
---|
427 | CGparameter p;
|
---|
428 | CGParameterMap::const_iterator it = mParamHash.find(name);
|
---|
429 |
|
---|
430 | if (it == mParamHash.end())
|
---|
431 | p = cgGetNamedParameter(mProgram, name.c_str());
|
---|
432 | else
|
---|
433 | p = mParameters[(*it).second];
|
---|
434 |
|
---|
435 | //cout << "name: " << name << " " << p << " " << mProgram << endl;
|
---|
436 | return p;
|
---|
437 | }
|
---|
438 |
|
---|
439 |
|
---|
440 | CGparameter ShaderProgram::GetParameter(int idx) const
|
---|
441 | {
|
---|
442 | return mParameters[idx];
|
---|
443 | }
|
---|
444 |
|
---|
445 |
|
---|
446 | void ShaderProgram::SetValue1f(int idx, float val)
|
---|
447 | {
|
---|
448 | cgGLSetParameter1f(GetParameter(idx), val);
|
---|
449 | }
|
---|
450 |
|
---|
451 |
|
---|
452 | void ShaderProgram::SetValue2f(int idx, float val1, float val2)
|
---|
453 | {
|
---|
454 | cgGLSetParameter2f(GetParameter(idx), val1, val2);
|
---|
455 | }
|
---|
456 |
|
---|
457 |
|
---|
458 | void ShaderProgram::SetValue3f(int idx, float val1, float val2, float val3)
|
---|
459 | {
|
---|
460 | cgGLSetParameter3f(GetParameter(idx), val1, val2, val3);
|
---|
461 | }
|
---|
462 |
|
---|
463 |
|
---|
464 | void ShaderProgram::SetArray1f(int idx, float *vals, int numElements)
|
---|
465 | {
|
---|
466 | cgGLSetParameterArray1f(GetParameter(idx), 0, numElements, (const float *)vals);
|
---|
467 | }
|
---|
468 |
|
---|
469 |
|
---|
470 | void ShaderProgram::SetArray2f(int idx, float *vals, int numElements)
|
---|
471 | {
|
---|
472 | cgGLSetParameterArray2f(GetParameter(idx), 0, numElements, (const float *)vals);
|
---|
473 | }
|
---|
474 |
|
---|
475 |
|
---|
476 | void ShaderProgram::SetArray3f(int idx, float *vals, int numElements)
|
---|
477 | {
|
---|
478 | cgGLSetParameterArray3f(GetParameter(idx), 0, numElements, (const float *)vals);
|
---|
479 | }
|
---|
480 |
|
---|
481 |
|
---|
482 | void ShaderProgram::SetMatrix(int idx, const Matrix4x4 &mat)
|
---|
483 | {
|
---|
484 | cgGLSetMatrixParameterfc(GetParameter(idx), (const float *)mat.x);
|
---|
485 | }
|
---|
486 |
|
---|
487 |
|
---|
488 | void ShaderProgram::SetMatrixArray(int idx, float *mats, int numElements)
|
---|
489 | {
|
---|
490 | cgGLSetMatrixParameterArrayfc(GetParameter(idx), 0, numElements, (const float *)mats);
|
---|
491 | }
|
---|
492 |
|
---|
493 |
|
---|
494 |
|
---|
495 | void ShaderProgram::SetTexture(int idx, unsigned int tex)
|
---|
496 | {
|
---|
497 | CGparameter p = GetParameter(idx);
|
---|
498 |
|
---|
499 | cgGLSetTextureParameter(p, tex);
|
---|
500 | cgGLEnableTextureParameter(p);
|
---|
501 | }
|
---|
502 |
|
---|
503 |
|
---|
504 | void ShaderProgram::SetValue1f(const string &name, float val)
|
---|
505 | {
|
---|
506 | cgGLSetParameter1f(GetOrCreateParameter(name), val);
|
---|
507 | }
|
---|
508 |
|
---|
509 |
|
---|
510 | void ShaderProgram::SetValue2f(const string &name, float val1, float val2)
|
---|
511 | {
|
---|
512 | cgGLSetParameter2f(GetOrCreateParameter(name), val1, val2);
|
---|
513 | }
|
---|
514 |
|
---|
515 |
|
---|
516 | void ShaderProgram::SetValue3f(const string &name, float val1, float val2, float val3)
|
---|
517 | {
|
---|
518 | cgGLSetParameter3f(GetOrCreateParameter(name), val1, val2, val3);
|
---|
519 | }
|
---|
520 |
|
---|
521 |
|
---|
522 | void ShaderProgram::SetArray1f(const string &name, float *vals, int numElements)
|
---|
523 | {
|
---|
524 | cgGLSetParameterArray1f(GetOrCreateParameter(name), 0, numElements, (const float *)vals);
|
---|
525 | }
|
---|
526 |
|
---|
527 |
|
---|
528 | void ShaderProgram::SetArray2f(const string &name, float *vals, int numElements)
|
---|
529 | {
|
---|
530 | cgGLSetParameterArray2f(GetOrCreateParameter(name), 0, numElements, (const float *)vals);
|
---|
531 | }
|
---|
532 |
|
---|
533 |
|
---|
534 | void ShaderProgram::SetArray3f(const string &name, float *vals, int numElements)
|
---|
535 | {
|
---|
536 | cgGLSetParameterArray3f(GetOrCreateParameter(name), 0, numElements, (const float *)vals);
|
---|
537 | }
|
---|
538 |
|
---|
539 |
|
---|
540 | void ShaderProgram::SetMatrix(const string &name, const Matrix4x4 &mat)
|
---|
541 | {
|
---|
542 | cgGLSetMatrixParameterfc(GetOrCreateParameter(name), (const float *)mat.x);
|
---|
543 | }
|
---|
544 |
|
---|
545 |
|
---|
546 | void ShaderProgram::SetTexture(const string &name, unsigned int tex)
|
---|
547 | {
|
---|
548 | CGparameter p = GetOrCreateParameter(name);
|
---|
549 |
|
---|
550 | cgGLSetTextureParameter(p, tex);
|
---|
551 | cgGLEnableTextureParameter(p);
|
---|
552 |
|
---|
553 | mTextureParams.push_back(p);
|
---|
554 | }
|
---|
555 |
|
---|
556 |
|
---|
557 | int ShaderProgram::GetParamIdxByName(const std::string &name) const
|
---|
558 | {
|
---|
559 | CGParameterMap::const_iterator it = mParamHash.find(name);
|
---|
560 | return (*it).second;
|
---|
561 | }
|
---|
562 |
|
---|
563 |
|
---|
564 | } // namespace |
---|