1 | #ifndef _SHADERPROGRAM_H__
|
---|
2 | #define _SHADERPROGRAM_H__
|
---|
3 |
|
---|
4 | #include "common.h"
|
---|
5 | #include "glInterface.h"
|
---|
6 |
|
---|
7 | #include <Cg/cg.h>
|
---|
8 | #include <Cg/cgGL.h>
|
---|
9 | #include <string>
|
---|
10 | #include <map>
|
---|
11 |
|
---|
12 |
|
---|
13 | namespace CHCDemoEngine
|
---|
14 | {
|
---|
15 |
|
---|
16 | class FrameBufferObject;
|
---|
17 | class Vector3;
|
---|
18 | class Camera;
|
---|
19 | class Matrix4x4;
|
---|
20 | class ShadowMap;
|
---|
21 | class DirectionalLight;
|
---|
22 |
|
---|
23 | typedef std::map<std::string, CGparameter> CGParameterMap;
|
---|
24 | typedef std::vector<CGparameter> CGParameterArray;
|
---|
25 |
|
---|
26 |
|
---|
27 | class ShaderProgram
|
---|
28 | {
|
---|
29 | public:
|
---|
30 |
|
---|
31 | ShaderProgram(CGprogram program): mProgram(program) {}
|
---|
32 |
|
---|
33 | ShaderProgram(CGcontext context,
|
---|
34 | const std::string &filename,
|
---|
35 | CGprofile profile,
|
---|
36 | const std::string &functionName);
|
---|
37 |
|
---|
38 | ~ShaderProgram() { if (mProgram != NULL) cgDestroyProgram(mProgram); }
|
---|
39 |
|
---|
40 | void SetValue1f(const std::string &name, float value);
|
---|
41 | void SetValue2f(const std::string &name, float val1, float val2);
|
---|
42 | void SetValue3f(const std::string &name, float val1, float val, float val3);
|
---|
43 |
|
---|
44 | void SetArray1f(const std::string &name, float *vals, int numElements);
|
---|
45 | void SetArray2f(const std::string &name, float *vals, int numElements);
|
---|
46 | void SetArray3f(const std::string &name, float *vals, int numElements);
|
---|
47 |
|
---|
48 | void SetMatrix(const std::string &name, const Matrix4x4 &mat);
|
---|
49 |
|
---|
50 | void SetTexture(const std::string &name, unsigned int tex);
|
---|
51 |
|
---|
52 | void Release();
|
---|
53 |
|
---|
54 | void Bind();
|
---|
55 |
|
---|
56 | inline bool IsValid() { return mProgram != NULL; }
|
---|
57 |
|
---|
58 |
|
---|
59 | protected:
|
---|
60 |
|
---|
61 | CGparameter GetOrCreateParameter(const std::string &name);
|
---|
62 |
|
---|
63 | CGParameterMap mParamHash;
|
---|
64 | //CGParameterArray mParameters;
|
---|
65 |
|
---|
66 | CGParameterArray mTextureParams;
|
---|
67 |
|
---|
68 | CGprogram mProgram;
|
---|
69 | };
|
---|
70 |
|
---|
71 |
|
---|
72 | typedef std::vector<ShaderProgram *> ShaderContainer;
|
---|
73 |
|
---|
74 | } // namespace
|
---|
75 |
|
---|
76 | #endif // _ShaderProgram_H__ |
---|