Line data Source code
1 : /*
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 "GrShaderVar.h"
13 : #include "GrSwizzle.h"
14 :
15 : class GrGLSLProgramBuilder;
16 :
17 : class GrGLSLUniformHandler {
18 : public:
19 0 : virtual ~GrGLSLUniformHandler() {}
20 :
21 : using UniformHandle = GrGLSLProgramDataManager::UniformHandle;
22 : GR_DEFINE_RESOURCE_HANDLE_CLASS(SamplerHandle);
23 : GR_DEFINE_RESOURCE_HANDLE_CLASS(ImageStorageHandle);
24 :
25 : /** Add a uniform variable to the current program, that has visibility in one or more shaders.
26 : visibility is a bitfield of GrShaderFlag values indicating from which shaders the uniform
27 : should be accessible. At least one bit must be set. Geometry shader uniforms are not
28 : supported at this time. The actual uniform name will be mangled. If outName is not nullptr
29 : then it will refer to the final uniform name after return. Use the addUniformArray variant
30 : to add an array of uniforms. */
31 0 : UniformHandle addUniform(uint32_t visibility,
32 : GrSLType type,
33 : GrSLPrecision precision,
34 : const char* name,
35 : const char** outName = nullptr) {
36 0 : SkASSERT(!GrSLTypeIsCombinedSamplerType(type));
37 0 : return this->addUniformArray(visibility, type, precision, name, 0, outName);
38 : }
39 :
40 0 : UniformHandle addUniformArray(uint32_t visibility,
41 : GrSLType type,
42 : GrSLPrecision precision,
43 : const char* name,
44 : int arrayCount,
45 : const char** outName = nullptr) {
46 0 : SkASSERT(!GrSLTypeIsCombinedSamplerType(type));
47 : return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount,
48 0 : outName);
49 : }
50 :
51 : virtual const GrShaderVar& getUniformVariable(UniformHandle u) const = 0;
52 :
53 : /**
54 : * Shortcut for getUniformVariable(u).c_str()
55 : */
56 : virtual const char* getUniformCStr(UniformHandle u) const = 0;
57 :
58 : protected:
59 0 : explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuilder(program) {}
60 :
61 : // This is not owned by the class
62 : GrGLSLProgramBuilder* fProgramBuilder;
63 :
64 : private:
65 : virtual const GrShaderVar& samplerVariable(SamplerHandle) const = 0;
66 : virtual GrSwizzle samplerSwizzle(SamplerHandle) const = 0;
67 :
68 : virtual SamplerHandle addSampler(uint32_t visibility, GrSwizzle, GrSLType, GrSLPrecision,
69 : const char* name) = 0;
70 :
71 : virtual const GrShaderVar& imageStorageVariable(ImageStorageHandle) const = 0;
72 : virtual ImageStorageHandle addImageStorage(uint32_t visibility, GrSLType type,
73 : GrImageStorageFormat, GrSLMemoryModel, GrSLRestrict,
74 : GrIOType, const char* name) = 0;
75 :
76 : virtual UniformHandle internalAddUniformArray(uint32_t visibility,
77 : GrSLType type,
78 : GrSLPrecision precision,
79 : const char* name,
80 : bool mangleName,
81 : int arrayCount,
82 : const char** outName) = 0;
83 :
84 : virtual void appendUniformDecls(GrShaderFlags visibility, SkString*) const = 0;
85 :
86 : friend class GrGLSLProgramBuilder;
87 : };
88 :
89 : #endif
|