[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;
|
---|
[3034] | 16 | class Material;
|
---|
[3028] | 17 |
|
---|
[2769] | 18 | /** The current render state.
|
---|
| 19 | */
|
---|
| 20 | class RenderState
|
---|
| 21 | {
|
---|
| 22 | public:
|
---|
| 23 |
|
---|
| 24 | enum Mode
|
---|
| 25 | {
|
---|
| 26 | QUERY,
|
---|
| 27 | RENDER
|
---|
| 28 | };
|
---|
| 29 |
|
---|
[2955] | 30 | /// the used render type for this render pass
|
---|
| 31 | enum RenderPassType
|
---|
[2825] | 32 | {
|
---|
| 33 | FIXED,
|
---|
| 34 | DEPTH_PASS,
|
---|
[2955] | 35 | DEFERRED
|
---|
[2825] | 36 | };
|
---|
| 37 |
|
---|
[2769] | 38 | /** Constructor setting render as default state.
|
---|
| 39 | */
|
---|
| 40 | RenderState();
|
---|
| 41 |
|
---|
| 42 | ~RenderState() { Reset(); };
|
---|
| 43 | /** This must be called each time before and after an occlusion test.
|
---|
| 44 | Mode is one of render mode or query mode. Returns true if a state
|
---|
| 45 | change was issued.
|
---|
| 46 | */
|
---|
[3031] | 47 | bool SetMode(Mode mode);
|
---|
[2769] | 48 | /** Sets the current render state.
|
---|
| 49 | */
|
---|
[3034] | 50 | void SetState(Material *mat);
|
---|
[2854] | 51 | /** Returns either query or render mode
|
---|
[2769] | 52 | */
|
---|
| 53 | inline Mode GetMode() const { return mMode; }
|
---|
| 54 | /** Reset the state.
|
---|
| 55 | */
|
---|
| 56 | void Reset();
|
---|
[2773] | 57 | /** Stores the current vbo id.
|
---|
| 58 | */
|
---|
| 59 | inline void SetCurrentVboId(int id) { mCurrentVboId = id; }
|
---|
| 60 | /** Returns the current vbo id.
|
---|
| 61 | */
|
---|
[2854] | 62 | inline int GetCurrentVboId() const { return mCurrentVboId; }
|
---|
[2955] | 63 | /** Sets the type of rendering used (foreward, depth pass, deferred)
|
---|
| 64 | */
|
---|
| 65 | void SetRenderPassType(RenderPassType t);
|
---|
| 66 | /** See Set
|
---|
| 67 | */
|
---|
| 68 | RenderPassType GetRenderPassType() const;
|
---|
[3034] | 69 | /** If alpha to coverage is instead of alpha testing
|
---|
| 70 | */
|
---|
| 71 | void SetUseAlphaToCoverage(bool useAlphaToCoverage);
|
---|
[2955] | 72 | /** If true, the current value of cull face enabled / disable will
|
---|
| 73 | not be changed by the render state.
|
---|
| 74 | */
|
---|
| 75 | void LockCullFaceEnabled(bool lockCull);
|
---|
[3034] | 76 |
|
---|
| 77 |
|
---|
[2825] | 78 | ///////////////////
|
---|
[2854] | 79 | //-- for deferred shading, we have to switch shaders on and off
|
---|
| 80 |
|
---|
[2818] | 81 | static CGprofile sCgFragmentProfile;
|
---|
| 82 | static CGprofile sCgVertexProfile;
|
---|
| 83 |
|
---|
[3028] | 84 | static ShaderProgram *sCgMrtFragmentProgram;
|
---|
| 85 | static ShaderProgram *sCgMrtFragmentTexProgram;
|
---|
[3031] | 86 | static ShaderProgram *sCgMrtVertexProgram;
|
---|
[2818] | 87 |
|
---|
[3028] | 88 | static int sTexParam;
|
---|
[2819] | 89 |
|
---|
[3028] | 90 |
|
---|
[2769] | 91 | protected:
|
---|
| 92 |
|
---|
[3034] | 93 | //////////////////
|
---|
| 94 |
|
---|
[2769] | 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;
|
---|
[3034] | 108 |
|
---|
| 109 | int mCurrentTexId;
|
---|
| 110 |
|
---|
| 111 | ShaderProgram *mCurrentVertexProgram;
|
---|
| 112 | ShaderProgram *mCurrentFragmentProgram;
|
---|
[2769] | 113 | };
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | #endif // __RENDERSTATE_H |
---|