11 #ifndef hifi_gpu_Shader_h
12 #define hifi_gpu_Shader_h
18 #include <unordered_set>
19 #include <unordered_map>
22 #include <shaders/Shaders.h>
43 typedef std::shared_ptr<Shader> Pointer;
44 typedef std::vector<Pointer> Shaders;
46 using Source = shader::Source;
47 using Reflection = shader::Reflection;
48 using Dialect = shader::Dialect;
49 using Variant = shader::Variant;
62 using CompilationLogs = std::vector<CompilationLog>;
70 static const Source& getShaderSource(uint32_t
id);
80 static const Source& getVertexShaderSource(uint32_t
id) {
return getShaderSource(
id); }
90 static const Source& getFragmentShaderSource(uint32_t
id) {
return getShaderSource(
id); }
99 static Pointer createVertex(
const Source& source);
108 static Pointer createPixel(
const Source& source);
117 static Pointer createVertex(uint32_t shaderId);
126 static Pointer createPixel(uint32_t shaderId);
136 static Pointer createProgram(uint32_t programId);
145 static Pointer createProgram(
const Pointer& vertexShader,
const Pointer& pixelShader);
164 Type getType()
const {
return _type; }
169 bool isProgram()
const {
return getType() > NUM_DOMAINS; }
174 bool isDomain()
const {
return getType() < NUM_DOMAINS; }
179 const Source& getSource()
const {
return _source; }
186 const Shaders& getShaders()
const {
return _shaders; }
195 Reflection getReflection(shader::Dialect dialect, shader::Variant variant)
const;
204 Reflection getReflection()
const;
216 using CompilationHandler = std::function<bool(
const Shader&,
const std::string&, CompilationLog&, std::string&)>;
221 bool compilationHasFailed()
const {
return _compilationHasFailed; }
226 const CompilationLogs& getCompilationLogs()
const {
return _compilationLogs; }
234 void setCompilationHasFailed(
bool compilationHasFailed) { _compilationHasFailed = compilationHasFailed; }
242 void setCompilationLogs(
const CompilationLogs& logs)
const;
245 const GPUObjectPointer gpuObject{};
255 Shader(Type type,
const Source& source,
bool dynamic);
265 Shader(Type type,
const Pointer& vertex,
const Pointer& geometry,
const Pointer& pixel);
268 const Source _source;
271 const Shaders _shaders;
278 mutable CompilationLogs _compilationLogs;
281 bool _compilationHasFailed{
false };
291 static ShaderPointer createOrReuseDomainShader(Type type, uint32_t sourceId);
294 using ProgramMapKey = glm::uvec3;
299 bool operator()(
const ProgramMapKey& l,
const ProgramMapKey& r)
const {
311 using ProgramMap = std::map<ProgramMapKey, std::weak_ptr<Shader>,
ProgramKeyLess>;
314 static ProgramMap _programMap;
326 static ShaderPointer createOrReuseProgramShader(Type type,
327 const Pointer& vertexShader,
328 const Pointer& geometryShader,
329 const Pointer& pixelShader);
330 friend class Serializer;
331 friend class Deserializer;
334 typedef Shader::Pointer ShaderPointer;
335 typedef std::vector<ShaderPointer> Shaders;
Used for sorting program keys in the map.
Definition: Shader.h:297
Helper class containing compilation log and variable stating if compilation was successful.
Definition: Shader.h:52
bool compiled
true if compilation was successful.
Definition: Shader.h:57
std::string message
Log from shader compilation.
Definition: Shader.h:54