1 | #ifndef __RENDERSTATE_H
|
---|
2 | #define __RENDERSTATE_H
|
---|
3 |
|
---|
4 |
|
---|
5 | #include "common.h"
|
---|
6 | #include "glInterface.h"
|
---|
7 | #include <Cg/cg.h>
|
---|
8 | #include <Cg/cgGL.h>
|
---|
9 |
|
---|
10 |
|
---|
11 | namespace CHCDemoEngine
|
---|
12 | {
|
---|
13 |
|
---|
14 | class ShaderProgram;
|
---|
15 | class Texture;
|
---|
16 |
|
---|
17 | /** The current render state.
|
---|
18 | */
|
---|
19 | class RenderState
|
---|
20 | {
|
---|
21 | public:
|
---|
22 |
|
---|
23 | enum Mode
|
---|
24 | {
|
---|
25 | QUERY,
|
---|
26 | RENDER
|
---|
27 | };
|
---|
28 |
|
---|
29 | /// the used render type for this render pass
|
---|
30 | enum RenderPassType
|
---|
31 | {
|
---|
32 | FIXED,
|
---|
33 | DEPTH_PASS,
|
---|
34 | DEFERRED
|
---|
35 | };
|
---|
36 |
|
---|
37 | /** Constructor setting render as default state.
|
---|
38 | */
|
---|
39 | RenderState();
|
---|
40 |
|
---|
41 | ~RenderState() { Reset(); };
|
---|
42 | /** This must be called each time before and after an occlusion test.
|
---|
43 | Mode is one of render mode or query mode. Returns true if a state
|
---|
44 | change was issued.
|
---|
45 | */
|
---|
46 | bool SetMode(Mode mode);
|
---|
47 | /** Sets the current render state.
|
---|
48 | */
|
---|
49 | void SetState(Texture *tex, bool alphaTest, bool cullFace);
|
---|
50 | /** Returns either query or render mode
|
---|
51 | */
|
---|
52 | inline Mode GetMode() const { return mMode; }
|
---|
53 | /** Reset the state.
|
---|
54 | */
|
---|
55 | void Reset();
|
---|
56 | /** Stores the current vbo id.
|
---|
57 | */
|
---|
58 | inline void SetCurrentVboId(int id) { mCurrentVboId = id; }
|
---|
59 | /** Returns the current vbo id.
|
---|
60 | */
|
---|
61 | inline int GetCurrentVboId() const { return mCurrentVboId; }
|
---|
62 | /** If alpha to coverage is instead of alpha testing
|
---|
63 | */
|
---|
64 | void SetUseAlphaToCoverage(bool useAlphaToCoverage);
|
---|
65 | /** Sets the type of rendering used (foreward, depth pass, deferred)
|
---|
66 | */
|
---|
67 | void SetRenderPassType(RenderPassType t);
|
---|
68 | /** See Set
|
---|
69 | */
|
---|
70 | RenderPassType GetRenderPassType() const;
|
---|
71 | /** If true, the current value of cull face enabled / disable will
|
---|
72 | not be changed by the render state.
|
---|
73 | */
|
---|
74 | void LockCullFaceEnabled(bool lockCull);
|
---|
75 | /** Set a new texture.
|
---|
76 | */
|
---|
77 | void SetTexture(Texture *tex);
|
---|
78 |
|
---|
79 |
|
---|
80 | ///////////////////
|
---|
81 | //-- for deferred shading, we have to switch shaders on and off
|
---|
82 |
|
---|
83 | static CGprofile sCgFragmentProfile;
|
---|
84 | static CGprofile sCgVertexProfile;
|
---|
85 |
|
---|
86 | static ShaderProgram *sCgMrtFragmentProgram;
|
---|
87 | static ShaderProgram *sCgMrtFragmentTexProgram;
|
---|
88 | static ShaderProgram *sCgMrtVertexProgram;
|
---|
89 |
|
---|
90 | static int sTexParam;
|
---|
91 |
|
---|
92 |
|
---|
93 | protected:
|
---|
94 |
|
---|
95 | bool mAlphaTestEnabled;
|
---|
96 | bool mCullFaceEnabled;
|
---|
97 | bool mTexturesEnabled;
|
---|
98 |
|
---|
99 | Mode mMode;
|
---|
100 |
|
---|
101 | int mCurrentVboId;
|
---|
102 |
|
---|
103 | RenderPassType mRenderType;
|
---|
104 |
|
---|
105 | bool mUseAlphaToCoverage;
|
---|
106 |
|
---|
107 | bool mLockCullFaceEnabled;
|
---|
108 | };
|
---|
109 |
|
---|
110 |
|
---|
111 | }
|
---|
112 |
|
---|
113 | #endif // __RENDERSTATE_H |
---|