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

gl_program_pool.cpp « shaders - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 80ac3cbbab7c586d8f6635fe777433dc81b6f026 (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
#include "shaders/gl_program_pool.hpp"
#include "shaders/program_params.hpp"
#include "shaders/gl_shaders.hpp"

#include "drape/gl_gpu_program.hpp"
#include "drape/gl_functions.hpp"

namespace gpu
{
GLProgramPool::GLProgramPool(dp::ApiVersion apiVersion)
  : m_apiVersion(apiVersion)
{
  ProgramParams::Init();

  if (m_apiVersion == dp::ApiVersion::OpenGLES3)
  {
#ifdef OMIM_OS_DESKTOP
    m_baseDefines = std::string(GL3_SHADER_VERSION) + "#define GLES3\n";
#else
    m_baseDefines = std::string(GLES3_SHADER_VERSION);
#endif
  }
}

GLProgramPool::~GLProgramPool()
{
  GLFunctions::glUseProgram(0);
  ProgramParams::Destroy();
}

drape_ptr<dp::GpuProgram> GLProgramPool::Get(Program program)
{
  auto const programInfo = GetProgramInfo(m_apiVersion, program);
  auto vertexShader = GetShader(programInfo.m_vertexShaderName, programInfo.m_vertexShaderSource,
                                dp::Shader::Type::VertexShader);
  auto fragmentShader = GetShader(programInfo.m_fragmentShaderName, programInfo.m_fragmentShaderSource,
                                  dp::Shader::Type::FragmentShader);

  auto const name = DebugPrint(program);
  return make_unique_dp<dp::GLGpuProgram>(name, vertexShader, fragmentShader);
}

void GLProgramPool::SetDefines(std::string const & defines)
{
  m_defines = defines;
}

ref_ptr<dp::Shader> GLProgramPool::GetShader(std::string const & name, std::string const & source,
                                             dp::Shader::Type type)
{
  auto const it = m_shaders.find(name);
  if (it != m_shaders.end())
    return make_ref(it->second);

  auto shader = make_unique_dp<dp::Shader>(name, source, m_baseDefines + m_defines, type);
  auto result = make_ref(shader);
  m_shaders[name] = std::move(shader);
  return result;
}
}  // namespace gpu