source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h @ 3029

Revision 3029, 2.3 KB checked in by mattausch, 16 years ago (diff)
Line 
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
13namespace CHCDemoEngine
14{
15
16class FrameBufferObject;
17class Vector3;
18class Camera;
19class Matrix4x4;
20class ShadowMap;
21class DirectionalLight;
22
23typedef std::map<std::string, CGparameter> CGParameterMap;
24typedef std::vector<CGparameter> CGParameterArray;
25
26struct ParameterPair1f
27{
28        unsigned int mParameterIdx;
29        float mValue;
30};
31
32class 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
55class ShaderProgram
56{
57public:
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
94protected:
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
107typedef  std::vector<ShaderProgram *> ShaderContainer;
108
109} // namespace
110
111#endif // _ShaderProgram_H__
Note: See TracBrowser for help on using the repository browser.