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 GrGLUniformHandler_DEFINED |
9 | #define GrGLUniformHandler_DEFINED |
10 | |
11 | #include "src/gpu/gl/GrGLProgramDataManager.h" |
12 | #include "src/gpu/glsl/GrGLSLUniformHandler.h" |
13 | |
14 | #include <vector> |
15 | |
16 | class GrGLCaps; |
17 | |
18 | class GrGLUniformHandler : public GrGLSLUniformHandler { |
19 | public: |
20 | static const int kUniformsPerBlock = 8; |
21 | |
22 | const GrShaderVar& getUniformVariable(UniformHandle u) const override { |
23 | return fUniforms.item(u.toIndex()).fVariable; |
24 | } |
25 | |
26 | const char* getUniformCStr(UniformHandle u) const override { |
27 | return this->getUniformVariable(u).c_str(); |
28 | } |
29 | private: |
30 | explicit GrGLUniformHandler(GrGLSLProgramBuilder* program) |
31 | : INHERITED(program) |
32 | , fUniforms(kUniformsPerBlock) |
33 | , fSamplers(kUniformsPerBlock) {} |
34 | |
35 | UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner, |
36 | uint32_t visibility, |
37 | GrSLType type, |
38 | const char* name, |
39 | bool mangleName, |
40 | int arrayCount, |
41 | const char** outName) override; |
42 | |
43 | SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const GrSwizzle&, |
44 | const char* name, const GrShaderCaps*) override; |
45 | |
46 | const char* samplerVariable(SamplerHandle handle) const override { |
47 | return fSamplers.item(handle.toIndex()).fVariable.c_str(); |
48 | } |
49 | |
50 | GrSwizzle samplerSwizzle(SamplerHandle handle) const override { |
51 | return fSamplerSwizzles[handle.toIndex()]; |
52 | } |
53 | |
54 | void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; |
55 | |
56 | // Manually set uniform locations for all our uniforms. |
57 | void bindUniformLocations(GrGLuint programID, const GrGLCaps& caps); |
58 | |
59 | // Updates the loction of the Uniforms if we cannot bind uniform locations manually |
60 | void getUniformLocations(GrGLuint programID, const GrGLCaps& caps, bool force); |
61 | |
62 | const GrGLGpu* glGpu() const; |
63 | |
64 | typedef GrGLProgramDataManager::GLUniformInfo GLUniformInfo; |
65 | typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; |
66 | |
67 | UniformInfoArray fUniforms; |
68 | UniformInfoArray fSamplers; |
69 | SkTArray<GrSwizzle> fSamplerSwizzles; |
70 | |
71 | friend class GrGLProgramBuilder; |
72 | |
73 | typedef GrGLSLUniformHandler INHERITED; |
74 | }; |
75 | |
76 | #endif |
77 | |