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 | struct ParameterPair1f
|
---|
27 | {
|
---|
28 | unsigned int mParameterIdx;
|
---|
29 | float mValue;
|
---|
30 | };
|
---|
31 |
|
---|
32 | class GPUProgramParameters
|
---|
33 | {
|
---|
34 | struct ParameterValue1f
|
---|
35 | {
|
---|
36 | unsigned int mParameterIdx;
|
---|
37 | float mValue;
|
---|
38 | };
|
---|
39 |
|
---|
40 | struct ParameterValue2f
|
---|
41 | {
|
---|
42 | unsigned int mParameterIdx;
|
---|
43 | float mValue;
|
---|
44 | };
|
---|
45 |
|
---|
46 | struct ParameterValue3f
|
---|
47 | {
|
---|
48 | unsigned int mParameterIdx;
|
---|
49 | float mValue;
|
---|
50 | };
|
---|
51 | };
|
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 | class ShaderProgram
|
---|
56 | {
|
---|
57 | public:
|
---|
58 |
|
---|
59 | ShaderProgram(CGprogram program): mProgram(program) {}
|
---|
60 |
|
---|
61 | ShaderProgram(CGcontext context,
|
---|
62 | const std::string &filename,
|
---|
63 | CGprofile profile,
|
---|
64 | const std::string &functionName);
|
---|
65 |
|
---|
66 | ~ShaderProgram() { if (mProgram != NULL) cgDestroyProgram(mProgram); }
|
---|
67 |
|
---|
68 | void SetValue1f(const std::string &name, float value);
|
---|
69 | void SetValue2f(const std::string &name, float val1, float val2);
|
---|
70 | void SetValue3f(const std::string &name, float val1, float val, float val3);
|
---|
71 |
|
---|
72 | void SetArray1f(const std::string &name, float *vals, int numElements);
|
---|
73 | void SetArray2f(const std::string &name, float *vals, int numElements);
|
---|
74 | void SetArray3f(const std::string &name, float *vals, int numElements);
|
---|
75 | /** Sets the matrix parameter.
|
---|
76 | */
|
---|
77 | void SetMatrix(const std::string &name, const Matrix4x4 &mat);
|
---|
78 | /** Sets the texture parameter.
|
---|
79 | */
|
---|
80 | void SetTexture(const std::string &name, unsigned int tex);
|
---|
81 | /** Enable / disable a texture parameter.
|
---|
82 | */
|
---|
83 | void EnableTexture(const std::string &name);
|
---|
84 |
|
---|
85 | void DisableTexture(const std::string &name);
|
---|
86 | /** Binds the program.
|
---|
87 | */
|
---|
88 | void Bind();
|
---|
89 | /** Returns true if this program is valid.
|
---|
90 | */
|
---|
91 | inline bool IsValid() { return mProgram != NULL; }
|
---|
92 |
|
---|
93 |
|
---|
94 | protected:
|
---|
95 |
|
---|
96 | CGparameter GetOrCreateParameter(const std::string &name);
|
---|
97 |
|
---|
98 | CGParameterMap mParamHash;
|
---|
99 | //CGParameterArray mParameters;
|
---|
100 |
|
---|
101 | CGParameterArray mTextureParams;
|
---|
102 |
|
---|
103 | CGprogram mProgram;
|
---|
104 | };
|
---|
105 |
|
---|
106 |
|
---|
107 | typedef std::vector<ShaderProgram *> ShaderContainer;
|
---|
108 |
|
---|
109 | } // namespace
|
---|
110 |
|
---|
111 | #endif // _ShaderProgram_H__ |
---|