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

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

#include "../drape/shader_def.hpp"

GLWidget::GLWidget()
{
  m_batcher = new Batcher(ReferencePoiner<IBatchFlush>(this));
  m_programManager = new GpuProgramManager();
}

void GLWidget::FlushFullBucket(const GLState & state, OwnedPointer<VertexArrayBuffer> bucket)
{
  ReferencePoiner<GpuProgram> program = m_programManager->GetProgram(state.GetProgramIndex());
  bucket->Build(program);
  m_frames[state].push_back(bucket);
}

void GLWidget::UseIncompleteBucket(const GLState &state, ReferencePoiner<VertexArrayBuffer> bucket)
{
  ReferencePoiner<GpuProgram> program = m_programManager->GetProgram(state.GetProgramIndex());
  bucket->Build(program);
  renderBucket(state, bucket);
}

void GLWidget::initializeGL()
{
  glClearColor(0.8, 0.8, 0.8, 1.0);

  GLFunctions::Init();
  glEnable(GL_DEPTH_TEST);
  glDepthMask(GL_TRUE);
  glDepthFunc(GL_LEQUAL);
  glClearDepth(0.0);

  vector<UniformValue> uniforms;
  float model[16] =
  {
    -1.0, 0.0,  0.0, 0.0,
     0.0, 1.0,  0.0, 0.0,
     0.0, 0.0, -1.0, 0.0,
     0.0, 0.0, -1.0, 1.0
  };

  uniforms.push_back(UniformValue("modelView", model));
  float p[16] =
  {
    0.5,  0.0, 0.0, 0.0,
    0.0, -0.5, 0.0, 0.0,
    0.0,  0.0, 1.0, 0.0,
    0.0,  0.0, 0.0, 1.0
  };

  uniforms.push_back(UniformValue("projection", p));

  float color[4] = { 1.0, 0.0, 0.0, 1.0 };
  uniforms.push_back(UniformValue("color", color[0], color[1], color[2], color[3]));

  ListGenerator gen;
  gen.SetDepth(0.5);
  gen.SetProgram(gpu::SOLID_AREA_PROGRAM);
  gen.SetViewport(-1.0f, -1.0f, 2.0f, 2.0f);
  gen.SetUniforms(uniforms);
  gen.Generate(30, *m_batcher);
}

void GLWidget::paintGL()
{
  glClearDepth(1.0);
  glDepthFunc(GL_LEQUAL);
  glDepthMask(GL_TRUE);
  glEnable(GL_DEPTH_TEST);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  if (!m_frames.empty())
  {
    frames_t::iterator it = m_frames.begin();
    for (; it != m_frames.end(); ++it)
    {
      for (size_t i = 0; i < it->second.size(); ++i)
      {
        renderBucket(it->first, it->second[i].GetWeakPointer());
      }
    }
  }
}

void GLWidget::renderBucket(const GLState & state, ReferencePoiner<VertexArrayBuffer> bucket)
{
  ReferencePoiner<GpuProgram> program = m_programManager->GetProgram(state.GetProgramIndex());
  ApplyState(state, program);
  bucket->Render();
}

void GLWidget::resizeGL(int w, int h)
{
  glViewport(0, 0, w, h);
}