All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GLState.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Graphics.h"
7 #include "GLStateTypes.h"
8 
9 #include <vector>
10 
11 namespace Eegeo
12 {
13  namespace Rendering
14  {
20  class GLState
21  {
22  private:
23  static const int NumOfTextureUnits = 8;
24  std::vector<GLStateFunc2<GLenum, GLuint> > m_boundTextures;
25 
26  public:
27  GLState();
28 
33  GLBoolState<GL_STENCIL_TEST> StencilTest;
35  GLBoolState<GL_SCISSOR_TEST> ScissorTest;
36  GLBoolState<GL_POLYGON_OFFSET_FILL> PolygonOffsetFill;
37  GLBoolState<GL_SAMPLE_ALPHA_TO_COVERAGE> SampleAlphaToCoverage;
38  GLBoolState<GL_SAMPLE_COVERAGE> SampleCoverage;
39 
40  GLStateFunc1<GLenum> ActiveTexture;
41 
42  inline void BindTexture2D(const GLuint textureId)
43  {
44  int textureUnit = (ActiveTexture.GetValue() - GL_TEXTURE0);
45  Eegeo_ASSERT(textureUnit < NumOfTextureUnits);
46  m_boundTextures[textureUnit].TrySet(GL_TEXTURE_2D, textureId);
47  }
48 
49  inline void BindTextureCubeMap(const GLuint textureId)
50  {
51  int textureUnit = (ActiveTexture.GetValue() - GL_TEXTURE0);
52  Eegeo_ASSERT(textureUnit < NumOfTextureUnits);
53  m_boundTextures[textureUnit].TrySet(GL_TEXTURE_CUBE_MAP, textureId);
54  }
55 
56  GLStateFunc1<GLuint> UseProgram;
57 
58  // no longer cached by GLState - now always makes gl call. Method kept for legacy support
59  inline void BindArrayBuffer(GLuint bufferId)
60  {
61  Eegeo_GL(glBindBuffer(GL_ARRAY_BUFFER, bufferId));
62  }
63 
64  // no longer cached by GLState - now always makes gl call. Method kept for legacy support
65  inline void BindElementArrayBuffer(GLuint bufferId)
66  {
67  Eegeo_GL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId));
68  }
69 
72 
73  GLStateFunc1<GLboolean> DepthMask;
74  GLStateFunc1<GLenum> DepthFunc;
75 
76  #ifdef EEGEO_OSX
78  #else
80  #endif
81 
82  GLStateFunc1<GLenum> BlendEquation;
84 
87  GLStateFunc1<GLuint> StencilMask;
90  GLStateFunc2<GLenum, GLuint> StencilMaskSeparate;
91 
92 
93  GLStateFunc1<GLenum> CullFaceMode;
94  GLStateFunc1<GLenum> FrontFace;
95 
98  GLStateFunc1<GLint> ClearStencil;
100 
101  GLStateFunc2<GLfloat, GLfloat> PolygonOffset;
102 
103  void InvalidateAll();
104  u32 TrySet(const GLState& stateToSet);
105 
106  void SetDefaultState();
107 
108  void ResetCounters();
109  int GetNumOfAttemptedSets() const;
110  int GetNumOfActualSets() const;
111  int GetNumOfValid() const;
112 
113  void ClearTrySetAttempted();
114  u32 TrySetIfNotAttempted(const GLState& stateToSet);
115  };
116  }
117 }