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 | |
30 | int numUniforms() const override { |
31 | return fUniforms.count(); |
32 | } |
33 | |
34 | UniformInfo& uniform(int idx) override { |
35 | return fUniforms.item(idx); |
36 | } |
37 | const UniformInfo& uniform(int idx) const override { |
38 | return fUniforms.item(idx); |
39 | } |
40 | |
41 | private: |
42 | explicit GrGLUniformHandler(GrGLSLProgramBuilder* program) |
43 | : INHERITED(program) |
44 | , fUniforms(kUniformsPerBlock) |
45 | , fSamplers(kUniformsPerBlock) {} |
46 | |
47 | UniformHandle internalAddUniformArray(const GrFragmentProcessor* owner, |
48 | uint32_t visibility, |
49 | GrSLType type, |
50 | const char* name, |
51 | bool mangleName, |
52 | int arrayCount, |
53 | const char** outName) override; |
54 | |
55 | SamplerHandle addSampler(const GrBackendFormat&, GrSamplerState, const GrSwizzle&, |
56 | const char* name, const GrShaderCaps*) override; |
57 | |
58 | const char* samplerVariable(SamplerHandle handle) const override { |
59 | return fSamplers.item(handle.toIndex()).fVariable.c_str(); |
60 | } |
61 | |
62 | GrSwizzle samplerSwizzle(SamplerHandle handle) const override { |
63 | return fSamplerSwizzles[handle.toIndex()]; |
64 | } |
65 | |
66 | void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; |
67 | |
68 | // Manually set uniform locations for all our uniforms. |
69 | void bindUniformLocations(GrGLuint programID, const GrGLCaps& caps); |
70 | |
71 | // Updates the loction of the Uniforms if we cannot bind uniform locations manually |
72 | void getUniformLocations(GrGLuint programID, const GrGLCaps& caps, bool force); |
73 | |
74 | const GrGLGpu* glGpu() const; |
75 | |
76 | typedef GrGLProgramDataManager::GLUniformInfo GLUniformInfo; |
77 | typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; |
78 | |
79 | UniformInfoArray fUniforms; |
80 | UniformInfoArray fSamplers; |
81 | SkTArray<GrSwizzle> fSamplerSwizzles; |
82 | |
83 | friend class GrGLProgramBuilder; |
84 | |
85 | typedef GrGLSLUniformHandler INHERITED; |
86 | }; |
87 | |
88 | #endif |
89 | |