Fillwave  10.0.0
Program.h
1 #pragma once
2 
3 /*
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2018 Filip Wasil and Fillwave community members
7  *
8  * Permission is hereby granted, free of charge, to any person
9  * obtaining a copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
12  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include <flw/flc/pipeline/Uniform.h>
25 #include <flw/flc/pipeline/Shader.h>
26 #include <flw/flc/extended/pipeline/UniformBuffer.h>
27 #include <flw/cmn/Aliases.h>
28 
29 class Attribute;
30 
31 namespace flw {
32 namespace flc {
33 
37 class Program final {
38 public:
39 
40  static constexpr const char* LIGHTS_BINDING_POINT_NAME = "uSpotLightsUBO";
41 
42  Program(const std::vector<flc::Shader *> &shaders, GLboolean skipLinking = GL_FALSE);
43 
44  ~Program();
45 
46  void link();
47 
48  /* Shaders */
49  void use() const;
50 
51  static void useProgram(GLuint handle);
52 
53  static void disusePrograms();
54 
55  /* Uniforms */
56  void uniformPush(const std::string& name, GLint data);
57 
58  void uniformPush(const std::string& name, GLint *data, GLint count);
59 
60  void uniformPush(const std::string& name, GLfloat data);
61 
62  void uniformPush(const std::string& name, GLfloat *data, GLint count);
63 
64  void uniformPush(const std::string& name, glm::mat3 data);
65 
66  void uniformPush(const std::string& name, glm::mat4 data);
67 
68  void uniformPush(const std::string& name, glm::mat4 *data, GLuint size);
69 
70  void uniformPush(const std::string& name, glm::vec2 data);
71 
72  void uniformPush(const std::string& name, glm::vec3 data);
73 
74  void uniformPush(const std::string& name, glm::vec3 *data, GLuint size);
75 
76  void uniformPush(const std::string& name, glm::vec4 data);
77 
78  /* Uniform blocks */
79  GLint getUniformLocation(const std::string& name);
80 
81  GLuint getHandle() const;
82 
83  void reload();
84 
85  void log(const std::string& programName) const;
86 
87 private:
88  const bool mDelayedLinking;
89  GLuint mHandle;
90  std::vector<Uniform> mUniforms;
91  std::vector<flc::Shader*> mShaders;
92 
93  inline void getUniforms();
94 
95  inline void attach(flc::Shader* shader);
96 
97  inline void detach(flc::Shader* shader);
98 
99  inline void load();
100 
101  inline void unload();
102 
103 #if defined(FILLWAVE_BACKEND_OPENGL_ES_20)
104 #else
105  public:
106  void getUniformBlock(const std::string& name, GLuint bindingPoint);
107  void uniformBlockPush(const std::string& name, GLfloat* data, size_t size = 0);
108 
109  private:
110  std::vector<pu<flc::UniformBuffer>> mUniformBuffers;
111 
112 #endif
113 };
114 
115 } /* flc */
116 } /* flw */
Definition: Aliases.h:30
Single GLSL program object.
Definition: Program.h:37
Single GLSL shader object.
Definition: Shader.h:44