[2769] | 1 | #include "RenderState.h"
|
---|
| 2 | #include "glInterface.h"
|
---|
| 3 | #include "Geometry.h"
|
---|
| 4 | #include "Material.h"
|
---|
| 5 |
|
---|
| 6 |
|
---|
[2776] | 7 | namespace CHCDemoEngine
|
---|
[2769] | 8 | {
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | RenderState::RenderState():
|
---|
[2773] | 12 | mAlphaTestEnabled(false),
|
---|
| 13 | mTexturesEnabled(false),
|
---|
[2801] | 14 | mMode(RENDER),
|
---|
| 15 | mIsDepthPass(false)
|
---|
[2769] | 16 | {
|
---|
| 17 | Reset();
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | bool RenderState::SetState(Mode mode)
|
---|
| 22 | {
|
---|
[2800] | 23 | ///////////
|
---|
[2769] | 24 | //-- just change the modewhen necessary
|
---|
[2800] | 25 |
|
---|
[2769] | 26 | if (mode == mMode) return false;
|
---|
| 27 |
|
---|
| 28 | mMode = mode;
|
---|
| 29 |
|
---|
| 30 | if (mode == QUERY)
|
---|
| 31 | {
|
---|
[2801] | 32 | if (!mIsDepthPass)
|
---|
| 33 | {
|
---|
| 34 | glDisable(GL_LIGHTING);
|
---|
| 35 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[2769] | 38 | glDepthMask(GL_FALSE);
|
---|
| 39 |
|
---|
| 40 | SetState(false, false);
|
---|
| 41 | }
|
---|
| 42 | else // mode returns to render
|
---|
| 43 | {
|
---|
| 44 | /////////////
|
---|
| 45 | //-- restore render state
|
---|
| 46 |
|
---|
[2801] | 47 | if (!mIsDepthPass)
|
---|
| 48 | {
|
---|
| 49 | glEnable(GL_LIGHTING);
|
---|
| 50 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[2769] | 53 | glDepthMask(GL_TRUE);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | return true;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | void RenderState::SetState(bool texturing, bool alphaTest)
|
---|
| 61 | {
|
---|
| 62 | if (mAlphaTestEnabled && !alphaTest)
|
---|
| 63 | {
|
---|
| 64 | mAlphaTestEnabled = false;
|
---|
| 65 | glDisable(GL_ALPHA_TEST);
|
---|
| 66 | }
|
---|
| 67 | else if (!mAlphaTestEnabled && alphaTest)
|
---|
| 68 | {
|
---|
| 69 | mAlphaTestEnabled = true;
|
---|
[2816] | 70 | //glEnable(GL_ALPHA_TEST);
|
---|
[2769] | 71 | }
|
---|
[2801] | 72 |
|
---|
| 73 | // allow only alpha textures in depth pass
|
---|
| 74 | if (mTexturesEnabled &&
|
---|
| 75 | (!texturing || mIsDepthPass && !mAlphaTestEnabled))
|
---|
| 76 | {
|
---|
| 77 | mTexturesEnabled = false;
|
---|
| 78 | glDisable(GL_TEXTURE_2D);
|
---|
| 79 | glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
---|
| 80 | }
|
---|
| 81 | else if (!mTexturesEnabled && texturing)
|
---|
| 82 | {
|
---|
| 83 | if (!mIsDepthPass || mAlphaTestEnabled)
|
---|
| 84 | {
|
---|
| 85 | mTexturesEnabled = true;
|
---|
| 86 | glEnable(GL_TEXTURE_2D);
|
---|
| 87 | glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
[2769] | 90 | }
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 | void RenderState::Reset()
|
---|
| 94 | {
|
---|
[2773] | 95 | mCurrentVboId = -1;
|
---|
[2769] | 96 | SetState(false, false);
|
---|
| 97 | SetState(RENDER);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | } |
---|