egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 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 "glsl/GrGLSLUniformHandler.h" |
| 12 | |
| 13 | #include "gl/GrGLProgramDataManager.h" |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame^] | 14 | #include "gl/GrGLSampler.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 15 | |
| 16 | class GrGLCaps; |
| 17 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 18 | class GrGLUniformHandler : public GrGLSLUniformHandler { |
| 19 | public: |
jvanverth | 633b356 | 2016-03-23 11:01:22 -0700 | [diff] [blame] | 20 | static const int kUniformsPerBlock = 8; |
| 21 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 22 | const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const override { |
| 23 | return fUniforms[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 | |
| 34 | UniformHandle internalAddUniformArray(uint32_t visibility, |
| 35 | GrSLType type, |
| 36 | GrSLPrecision precision, |
| 37 | const char* name, |
| 38 | bool mangleName, |
| 39 | int arrayCount, |
| 40 | const char** outName) override; |
| 41 | |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame^] | 42 | SamplerHandle internalAddSampler(uint32_t visibility, |
| 43 | GrPixelConfig config, |
| 44 | GrSLType type, |
| 45 | GrSLPrecision precision, |
| 46 | const char* name) override; |
| 47 | |
| 48 | int numSamplers() const override { return fSamplers.count(); } |
| 49 | const GrGLSLSampler& getSampler(SamplerHandle handle) const override { |
| 50 | return fSamplers[handle.toIndex()]; |
| 51 | } |
| 52 | |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 53 | void appendUniformDecls(GrShaderFlags visibility, SkString*) const override; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 54 | |
| 55 | // Manually set uniform locations for all our uniforms. |
| 56 | void bindUniformLocations(GrGLuint programID, const GrGLCaps& caps); |
| 57 | |
| 58 | // Updates the loction of the Uniforms if we cannot bind uniform locations manually |
| 59 | void getUniformLocations(GrGLuint programID, const GrGLCaps& caps); |
| 60 | |
| 61 | const GrGLGpu* glGpu() const; |
| 62 | |
| 63 | typedef GrGLProgramDataManager::UniformInfo UniformInfo; |
| 64 | typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; |
| 65 | |
| 66 | UniformInfoArray fUniforms; |
| 67 | |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame^] | 68 | SkTArray<GrGLSampler> fSamplers; |
| 69 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 70 | friend class GrGLProgramBuilder; |
| 71 | |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 72 | typedef GrGLSLUniformHandler INHERITED; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | #endif |