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

glstate.cpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 495cf9f1931eceeaa8f78dda513913a736026442 (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
#include "drape/glstate.hpp"
#include "drape/glfunctions.hpp"

#include "base/buffer_vector.hpp"
#include "std/bind.hpp"

#define TEXTURE_BIT 0x1

namespace dp
{

Blending::Blending(bool isEnabled)
  : m_isEnabled(isEnabled)
  , m_blendFunction(gl_const::GLAddBlend)
  , m_blendSrcFactor(gl_const::GLSrcAlfa)
  , m_blendDstFactor(gl_const::GLOneMinusSrcAlfa)
{
}

void Blending::Apply() const
{
  if (m_isEnabled)
  {
    GLFunctions::glEnable(gl_const::GLBlending);
    GLFunctions::glBlendEquation(m_blendFunction);
    GLFunctions::glBlendFunc(m_blendSrcFactor, m_blendDstFactor);
  }
  else
    GLFunctions::glDisable(gl_const::GLBlending);
}

bool Blending::operator < (Blending const & other) const
{
  if (m_isEnabled != other.m_isEnabled)
    return m_isEnabled < other.m_isEnabled;
  if (m_blendFunction != other.m_blendFunction)
    return m_blendFunction < other.m_blendFunction;
  if (m_blendSrcFactor != other.m_blendSrcFactor)
    return m_blendSrcFactor < other.m_blendSrcFactor;

  return m_blendDstFactor < other.m_blendDstFactor;
}

bool Blending::operator == (Blending const & other) const
{
  return m_isEnabled == other.m_isEnabled &&
         m_blendFunction == other.m_blendFunction &&
         m_blendSrcFactor == other.m_blendSrcFactor &&
         m_blendDstFactor == other.m_blendDstFactor;
}

GLState::GLState(uint32_t gpuProgramIndex, DepthLayer depthLayer)
  : m_gpuProgramIndex(gpuProgramIndex)
  , m_depthLayer(depthLayer)
{
}

bool GLState::operator<(GLState const & other) const
{
  if (m_depthLayer != other.m_depthLayer)
    return m_depthLayer < other.m_depthLayer;
  if (!(m_blending == other.m_blending))
    return m_blending < other.m_blending;
  if (m_gpuProgramIndex != other.m_gpuProgramIndex)
    return m_gpuProgramIndex < other.m_gpuProgramIndex;
  if (m_colorTexture.GetRaw() != other.m_colorTexture.GetRaw())
    return m_colorTexture.GetRaw() < other.m_colorTexture.GetRaw();

  return m_maskTexture.GetRaw() < other.m_maskTexture.GetRaw();
}

bool GLState::operator==(GLState const & other) const
{
  return m_depthLayer == other.m_depthLayer &&
         m_gpuProgramIndex == other.m_gpuProgramIndex &&
         m_blending == other.m_blending &&
         m_colorTexture == other.m_colorTexture &&
         m_maskTexture == other.m_maskTexture;
}

namespace
{
  void ApplyUniformValue(UniformValue const & value, RefPointer<GpuProgram> program)
  {
    value.Apply(program);
  }
}

void ApplyUniforms(UniformValuesStorage const & uniforms, RefPointer<GpuProgram> program)
{
  uniforms.ForeachValue(bind(&ApplyUniformValue, _1, program));
}

void ApplyState(GLState state, RefPointer<GpuProgram> program)
{
  RefPointer<Texture> tex = state.GetColorTexture();
  if (!tex.IsNull())
  {
    int8_t const colorTexLoc = program->GetUniformLocation("u_colorTex");
    GLFunctions::glActiveTexture(gl_const::GLTexture0);
    tex->Bind();
    GLFunctions::glUniformValuei(colorTexLoc, 0);
  }

  tex = state.GetMaskTexture();
  if (!tex.IsNull())
  {
    int8_t const maskTexLoc = program->GetUniformLocation("u_maskTex");
    GLFunctions::glActiveTexture(gl_const::GLTexture0 + 1);
    tex->Bind();
    GLFunctions::glUniformValuei(maskTexLoc, 1);
  }
  state.GetBlending().Apply();
}

}