Overte C++ Documentation
GLShader.h
1 //
2 // Created by Bradley Austin Davis on 2016/05/15
3 // Copyright 2013-2016 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 #ifndef hifi_gpu_gl_GLShader_h
9 #define hifi_gpu_gl_GLShader_h
10 
11 #include "GLShared.h"
12 #include <gl/GLShaders.h>
13 
14 namespace gpu { namespace gl {
15 
16 struct ShaderObject {
17  enum class BindingType
18  {
19  INPUT,
20  OUTPUT,
21  TEXTURE,
22  SAMPLER,
23  UNIFORM_BUFFER,
24  RESOURCE_BUFFER,
25  UNIFORM,
26  };
27 
28  using LocationMap = std::unordered_map<std::string, int32_t>;
29  using ReflectionMap = std::map<BindingType, LocationMap>;
30  using UniformMap = std::unordered_map<GLuint, GLuint>;
31 
32  GLuint glshader{ 0 };
33  GLuint glprogram{ 0 };
34 
35  UniformMap uniformRemap;
36 };
37 
38 class GLShader : public GPUObject {
39 public:
40  static GLShader* sync(GLBackend& backend, const Shader& shader, const Shader::CompilationHandler& handler = nullptr);
41  using ShaderObject = gpu::gl::ShaderObject;
42  using ShaderObjects = std::array<ShaderObject, shader::NUM_VARIANTS>;
43 
44  GLShader(const std::weak_ptr<GLBackend>& backend);
45  ~GLShader();
46 
47  ShaderObjects _shaderObjects;
48 
49  GLuint getProgram(shader::Variant version = shader::Variant::Mono) const {
50  return _shaderObjects[static_cast<uint32_t>(version)].glprogram;
51  }
52 
53  const std::weak_ptr<GLBackend> _backend;
54 };
55 
56 }} // namespace gpu::gl
57 
58 #endif