blob: e72716d04e437c682145c33abf76f3338a782972 [file] [log] [blame]
egdaniel7ea439b2015-12-03 09:20:44 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrGLSLUniformHandler_DEFINED
9#define GrGLSLUniformHandler_DEFINED
10
11#include "GrGLSLProgramDataManager.h"
12#include "GrGLSLShaderVar.h"
13
14class GrGLSLProgramBuilder;
15
16class GrGLSLUniformHandler {
17public:
18 enum ShaderVisibility {
19 kVertex_Visibility = 1 << kVertex_GrShaderType,
20 kGeometry_Visibility = 1 << kGeometry_GrShaderType,
21 kFragment_Visibility = 1 << kFragment_GrShaderType,
22 };
23
24 virtual ~GrGLSLUniformHandler() {}
25
26 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
27
28 /** Add a uniform variable to the current program, that has visibility in one or more shaders.
29 visibility is a bitfield of ShaderVisibility values indicating from which shaders the
30 uniform should be accessible. At least one bit must be set. Geometry shader uniforms are not
31 supported at this time. The actual uniform name will be mangled. If outName is not nullptr
32 then it will refer to the final uniform name after return. Use the addUniformArray variant
33 to add an array of uniforms. */
34 UniformHandle addUniform(uint32_t visibility,
35 GrSLType type,
36 GrSLPrecision precision,
37 const char* name,
38 const char** outName = nullptr) {
39 return this->addUniformArray(visibility, type, precision, name, 0, outName);
40 }
41
42 UniformHandle addUniformArray(uint32_t visibility,
43 GrSLType type,
44 GrSLPrecision precision,
45 const char* name,
46 int arrayCount,
47 const char** outName = nullptr) {
48 return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount,
49 outName);
50 }
51
52 virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0;
53
54 /**
55 * Shortcut for getUniformVariable(u).c_str()
56 */
57 virtual const char* getUniformCStr(UniformHandle u) const = 0;
58protected:
59 explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuilder(program) {}
60
61 // This is not owned by the class
62 GrGLSLProgramBuilder* fProgramBuilder;
63
64private:
65 virtual UniformHandle internalAddUniformArray(uint32_t visibility,
66 GrSLType type,
67 GrSLPrecision precision,
68 const char* name,
69 bool mangleName,
70 int arrayCount,
71 const char** outName) = 0;
72
73 virtual void appendUniformDecls(ShaderVisibility, SkString*) const = 0;
74
75 friend class GrGLSLProgramBuilder;
76};
77
78#endif
79