source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp @ 2816

Revision 2816, 1.7 KB checked in by mattausch, 16 years ago (diff)
Line 
1#include "RenderState.h"
2#include "glInterface.h"
3#include "Geometry.h"
4#include "Material.h"
5
6
7namespace CHCDemoEngine
8{
9
10
11RenderState::RenderState():
12mAlphaTestEnabled(false),
13mTexturesEnabled(false),
14mMode(RENDER),
15mIsDepthPass(false)
16{
17        Reset();
18}
19
20       
21bool RenderState::SetState(Mode mode)
22{
23        ///////////
24        //-- just change the modewhen necessary
25
26        if (mode == mMode) return false;
27
28        mMode = mode;
29
30        if (mode == QUERY)
31        {
32                if (!mIsDepthPass)
33                {
34                        glDisable(GL_LIGHTING);
35                        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
36                }
37
38                glDepthMask(GL_FALSE);
39
40                SetState(false, false);
41        }
42        else // mode returns to render
43        {
44                /////////////
45                //-- restore render state
46
47                if (!mIsDepthPass)
48                {
49                        glEnable(GL_LIGHTING);
50                        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
51                }
52
53                glDepthMask(GL_TRUE);
54        }
55
56        return true;
57}
58
59       
60void 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;
70                //glEnable(GL_ALPHA_TEST);
71        }
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        }
90}
91
92
93void RenderState::Reset()
94{
95        mCurrentVboId = -1;
96        SetState(false, false);
97        SetState(RENDER);
98}
99
100
101}
Note: See TracBrowser for help on using the repository browser.