1 | #include "RenderState.h"
|
---|
2 | #include "glInterface.h"
|
---|
3 | #include "Geometry.h"
|
---|
4 | #include "Material.h"
|
---|
5 |
|
---|
6 |
|
---|
7 | namespace CHCDemoEngine
|
---|
8 | {
|
---|
9 |
|
---|
10 |
|
---|
11 | /** Constructor setting render as default state.
|
---|
12 | */
|
---|
13 | RenderState::RenderState():
|
---|
14 | mAlphaTestEnabled(false),
|
---|
15 | mTexturesEnabled(false),
|
---|
16 | mMode(RENDER)
|
---|
17 | {
|
---|
18 | Reset();
|
---|
19 | }
|
---|
20 |
|
---|
21 |
|
---|
22 | bool RenderState::SetState(Mode mode)
|
---|
23 | {
|
---|
24 | //-- just change the modewhen necessary
|
---|
25 | if (mode == mMode) return false;
|
---|
26 |
|
---|
27 | mMode = mode;
|
---|
28 | //++ state_changes;
|
---|
29 |
|
---|
30 | if (mode == QUERY)
|
---|
31 | {
|
---|
32 | //glDisableClientState(GL_NORMAL_ARRAY);
|
---|
33 | glDisable(GL_LIGHTING);
|
---|
34 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
---|
35 | glDepthMask(GL_FALSE);
|
---|
36 |
|
---|
37 | SetState(false, false);
|
---|
38 | }
|
---|
39 | else // mode returns to render
|
---|
40 | {
|
---|
41 | /////////////
|
---|
42 | //-- restore render state
|
---|
43 |
|
---|
44 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
---|
45 | glDepthMask(GL_TRUE);
|
---|
46 | glEnable(GL_LIGHTING);
|
---|
47 | }
|
---|
48 |
|
---|
49 | return true;
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | void RenderState::SetState(bool texturing, bool alphaTest)
|
---|
54 | {
|
---|
55 | if (mTexturesEnabled && !texturing)
|
---|
56 | {
|
---|
57 | mTexturesEnabled = false;
|
---|
58 | glDisable(GL_TEXTURE_2D);
|
---|
59 | glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
---|
60 | }
|
---|
61 | else if (!mTexturesEnabled && texturing)
|
---|
62 | {
|
---|
63 | mTexturesEnabled = true;
|
---|
64 | glEnable(GL_TEXTURE_2D);
|
---|
65 | glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
---|
66 | }
|
---|
67 |
|
---|
68 | if (mAlphaTestEnabled && !alphaTest)
|
---|
69 | {
|
---|
70 | mAlphaTestEnabled = false;
|
---|
71 | glDisable(GL_ALPHA_TEST);
|
---|
72 | }
|
---|
73 | else if (!mAlphaTestEnabled && alphaTest)
|
---|
74 | {
|
---|
75 | mAlphaTestEnabled = true;
|
---|
76 | glEnable(GL_ALPHA_TEST);
|
---|
77 | glAlphaFunc(GL_GEQUAL, 0.5f);
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | void RenderState::Reset()
|
---|
83 | {
|
---|
84 | mCurrentVboId = -1;
|
---|
85 | SetState(false, false);
|
---|
86 | SetState(RENDER);
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | } |
---|