[2769] | 1 | #ifndef __RENDERSTATE_H
|
---|
| 2 | #define __RENDERSTATE_H
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 | #include "common.h"
|
---|
[2818] | 6 | #include "glInterface.h"
|
---|
| 7 | #include <Cg/cg.h>
|
---|
| 8 | #include <Cg/cgGL.h>
|
---|
[2769] | 9 |
|
---|
| 10 |
|
---|
[2776] | 11 | namespace CHCDemoEngine
|
---|
[2769] | 12 | {
|
---|
| 13 |
|
---|
[3028] | 14 | class ShaderProgram;
|
---|
| 15 | class Texture;
|
---|
| 16 |
|
---|
[2769] | 17 | /** The current render state.
|
---|
| 18 | */
|
---|
| 19 | class RenderState
|
---|
| 20 | {
|
---|
| 21 | public:
|
---|
| 22 |
|
---|
| 23 | enum Mode
|
---|
| 24 | {
|
---|
| 25 | QUERY,
|
---|
| 26 | RENDER
|
---|
| 27 | };
|
---|
| 28 |
|
---|
[2955] | 29 | /// the used render type for this render pass
|
---|
| 30 | enum RenderPassType
|
---|
[2825] | 31 | {
|
---|
| 32 | FIXED,
|
---|
| 33 | DEPTH_PASS,
|
---|
[2955] | 34 | DEFERRED
|
---|
[2825] | 35 | };
|
---|
| 36 |
|
---|
[2769] | 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 | */
|
---|
[3031] | 46 | bool SetMode(Mode mode);
|
---|
[2769] | 47 | /** Sets the current render state.
|
---|
| 48 | */
|
---|
[3031] | 49 | void SetState(Texture *tex, bool alphaTest, bool cullFace);
|
---|
[2854] | 50 | /** Returns either query or render mode
|
---|
[2769] | 51 | */
|
---|
| 52 | inline Mode GetMode() const { return mMode; }
|
---|
| 53 | /** Reset the state.
|
---|
| 54 | */
|
---|
| 55 | void Reset();
|
---|
[2773] | 56 | /** Stores the current vbo id.
|
---|
| 57 | */
|
---|
| 58 | inline void SetCurrentVboId(int id) { mCurrentVboId = id; }
|
---|
| 59 | /** Returns the current vbo id.
|
---|
| 60 | */
|
---|
[2854] | 61 | inline int GetCurrentVboId() const { return mCurrentVboId; }
|
---|
[2943] | 62 | /** If alpha to coverage is instead of alpha testing
|
---|
| 63 | */
|
---|
| 64 | void SetUseAlphaToCoverage(bool useAlphaToCoverage);
|
---|
[2955] | 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);
|
---|
[3028] | 75 | /** Set a new texture.
|
---|
| 76 | */
|
---|
| 77 | void SetTexture(Texture *tex);
|
---|
[2769] | 78 |
|
---|
[2800] | 79 |
|
---|
[2825] | 80 | ///////////////////
|
---|
[2854] | 81 | //-- for deferred shading, we have to switch shaders on and off
|
---|
| 82 |
|
---|
[2818] | 83 | static CGprofile sCgFragmentProfile;
|
---|
| 84 | static CGprofile sCgVertexProfile;
|
---|
| 85 |
|
---|
[3028] | 86 | static ShaderProgram *sCgMrtFragmentProgram;
|
---|
| 87 | static ShaderProgram *sCgMrtFragmentTexProgram;
|
---|
[3031] | 88 | static ShaderProgram *sCgMrtVertexProgram;
|
---|
[2818] | 89 |
|
---|
[3028] | 90 | static int sTexParam;
|
---|
[2819] | 91 |
|
---|
[3028] | 92 |
|
---|
[2769] | 93 | protected:
|
---|
| 94 |
|
---|
| 95 | bool mAlphaTestEnabled;
|
---|
[2844] | 96 | bool mCullFaceEnabled;
|
---|
[2769] | 97 | bool mTexturesEnabled;
|
---|
| 98 |
|
---|
| 99 | Mode mMode;
|
---|
[2773] | 100 |
|
---|
| 101 | int mCurrentVboId;
|
---|
[2801] | 102 |
|
---|
[2955] | 103 | RenderPassType mRenderType;
|
---|
[2943] | 104 |
|
---|
| 105 | bool mUseAlphaToCoverage;
|
---|
[2955] | 106 |
|
---|
| 107 | bool mLockCullFaceEnabled;
|
---|
[2769] | 108 | };
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | #endif // __RENDERSTATE_H |
---|