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