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

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr.kuznetsov <r.kuznetsov@corp.mail.ru>2018-06-27 14:32:21 +0300
committerDaria Volvenkova <d.volvenkova@corp.mail.ru>2018-06-28 18:04:46 +0300
commitfa65b1a203134bec37371fe818067f9ae7c821c8 (patch)
tree57406af369ecd9c6535b971d065701bcbe9b6123 /shaders/gl_program_pool.cpp
parent68f4e87b2cd1ab60484d2802f6a4da6bb56a07a2 (diff)
Added shaders library
Diffstat (limited to 'shaders/gl_program_pool.cpp')
-rw-r--r--shaders/gl_program_pool.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/shaders/gl_program_pool.cpp b/shaders/gl_program_pool.cpp
new file mode 100644
index 0000000000..8816e6d72a
--- /dev/null
+++ b/shaders/gl_program_pool.cpp
@@ -0,0 +1,62 @@
+#include "shaders/gl_program_pool.hpp"
+#include "shaders/program_params.hpp"
+#include "shaders/gl_shaders.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()
+{
+ ProgramParams::Uninit();
+}
+
+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 textureSlotsCount = std::max(m_minTextureSlotsCount, programInfo.m_textureSlotsCount);
+ auto const name = DebugPrint(program);
+ return make_unique_dp<dp::GpuProgram>(name, vertexShader, fragmentShader, textureSlotsCount);
+}
+
+void GLProgramPool::SetDefines(std::string const & defines)
+{
+ m_defines = defines;
+}
+
+void GLProgramPool::SetMinTextureSlotsCount(uint8_t slotsCount)
+{
+ m_minTextureSlotsCount = slotsCount;
+}
+
+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