Welcome to mirror list, hosted at ThFree Co, Russian Federation.

oglcontext.cpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 01594c18c7625a4deb5daa600f79c77edec677e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "drape/oglcontext.hpp"
#include "drape/gl_functions.hpp"

#include "base/macros.hpp"

namespace dp
{
namespace
{
glConst DecodeTestFunction(TestFunction depthFunction)
{
  switch (depthFunction)
  {
  case TestFunction::Never: return gl_const::GLNever;
  case TestFunction::Less: return gl_const::GLLess;
  case TestFunction::Equal: return gl_const::GLEqual;
  case TestFunction::LessOrEqual: return gl_const::GLLessOrEqual;
  case TestFunction::Greater: return gl_const::GLGreat;
  case TestFunction::NotEqual: return gl_const::GLNotEqual;
  case TestFunction::GreaterOrEqual: return gl_const::GLGreatOrEqual;
  case TestFunction::Always: return gl_const::GLAlways;
  }
  UNREACHABLE();
}

glConst DecodeStencilFace(StencilFace stencilFace)
{
  switch (stencilFace)
  {
  case StencilFace::Front: return gl_const::GLFront;
  case StencilFace::Back: return gl_const::GLBack;
  case StencilFace::FrontAndBack: return gl_const::GLFrontAndBack;
  }
  UNREACHABLE();
}

glConst DecodeStencilAction(StencilAction stencilAction)
{
  switch (stencilAction)
  {
  case StencilAction::Keep: return gl_const::GLKeep;
  case StencilAction::Zero: return gl_const::GLZero;
  case StencilAction::Replace: return gl_const::GLReplace;
  case StencilAction::Increment: return gl_const::GLIncr;
  case StencilAction::IncrementWrap: return gl_const::GLIncrWrap;
  case StencilAction::Decrement: return gl_const::GLDecr;
  case StencilAction::DecrementWrap: return gl_const::GLDecrWrap;
  case StencilAction::Invert: return gl_const::GLInvert;
  }
  UNREACHABLE();
}
}  // namespace

void OGLContext::Init(ApiVersion apiVersion)
{
  GLFunctions::Init(apiVersion);

  GLFunctions::glPixelStore(gl_const::GLUnpackAlignment, 1);

  GLFunctions::glClearDepthValue(1.0);
  GLFunctions::glDepthFunc(gl_const::GLLessOrEqual);
  GLFunctions::glDepthMask(true);

  GLFunctions::glFrontFace(gl_const::GLClockwise);
  GLFunctions::glCullFace(gl_const::GLBack);
  GLFunctions::glEnable(gl_const::GLCullFace);
  GLFunctions::glEnable(gl_const::GLScissorTest);
}

ApiVersion OGLContext::GetApiVersion() const
{
  return GLFunctions::CurrentApiVersion;
}

std::string OGLContext::GetRendererName() const
{
  return GLFunctions::glGetString(gl_const::GLRenderer);
}

std::string OGLContext::GetRendererVersion() const
{
  return GLFunctions::glGetString(gl_const::GLVersion);
}

void OGLContext::DebugSynchronizeWithCPU()
{
  GLFunctions::glFinish();
}

void OGLContext::SetClearColor(dp::Color const & color)
{
  GLFunctions::glClearColor(color.GetRedF(), color.GetGreenF(), color.GetBlueF(), color.GetAlphaF());
}

void OGLContext::Clear(uint32_t clearBits, uint32_t storeBits)
{
  UNUSED_VALUE(storeBits);
  
  glConst glBits = 0;
  if (clearBits & ClearBits::ColorBit)
    glBits |= gl_const::GLColorBit;
  if (clearBits & ClearBits::DepthBit)
    glBits |= gl_const::GLDepthBit;
  if (clearBits & ClearBits::StencilBit)
    glBits |= gl_const::GLStencilBit;

  GLFunctions::glClear(glBits);
}

void OGLContext::Flush()
{
  GLFunctions::glFlush();
}

void OGLContext::SetViewport(uint32_t x, uint32_t y, uint32_t w, uint32_t h)
{
  GLCHECK(GLFunctions::glViewport(x, y, w, h));
  GLCHECK(GLFunctions::glScissor(x, y, w, h));
}

void OGLContext::SetDepthTestEnabled(bool enabled)
{
  if (enabled)
    GLFunctions::glEnable(gl_const::GLDepthTest);
  else
    GLFunctions::glDisable(gl_const::GLDepthTest);
}

void OGLContext::SetDepthTestFunction(TestFunction depthFunction)
{
  GLFunctions::glDepthFunc(DecodeTestFunction(depthFunction));
};

void OGLContext::SetStencilTestEnabled(bool enabled)
{
  if (enabled)
    GLFunctions::glEnable(gl_const::GLStencilTest);
  else
    GLFunctions::glDisable(gl_const::GLStencilTest);
}

void OGLContext::SetStencilFunction(StencilFace face, TestFunction stencilFunction)
{
  GLFunctions::glStencilFuncSeparate(DecodeStencilFace(face), DecodeTestFunction(stencilFunction), 1, 1);
}

void OGLContext::SetStencilActions(StencilFace face, StencilAction stencilFailAction, StencilAction depthFailAction,
                                   StencilAction passAction)
{
  GLFunctions::glStencilOpSeparate(DecodeStencilFace(face),
                                   DecodeStencilAction(stencilFailAction),
                                   DecodeStencilAction(depthFailAction),
                                   DecodeStencilAction(passAction));
}
}  // namespace dp