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 GrGLSLUniformHandler_DEFINED |
| 9 | #define GrGLSLUniformHandler_DEFINED |
| 10 | |
| 11 | #include "GrGLSLProgramDataManager.h" |
| 12 | #include "GrGLSLShaderVar.h" |
| 13 | |
| 14 | class GrGLSLProgramBuilder; |
| 15 | |
| 16 | class GrGLSLUniformHandler { |
| 17 | public: |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 18 | virtual ~GrGLSLUniformHandler() {} |
| 19 | |
| 20 | typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 21 | typedef GrGLSLProgramDataManager::UniformHandle SamplerHandle; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 22 | |
| 23 | /** Add a uniform variable to the current program, that has visibility in one or more shaders. |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 24 | visibility is a bitfield of GrShaderFlag values indicating from which shaders the uniform |
| 25 | should be accessible. At least one bit must be set. Geometry shader uniforms are not |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 26 | supported at this time. The actual uniform name will be mangled. If outName is not nullptr |
| 27 | then it will refer to the final uniform name after return. Use the addUniformArray variant |
| 28 | to add an array of uniforms. */ |
| 29 | UniformHandle addUniform(uint32_t visibility, |
| 30 | GrSLType type, |
| 31 | GrSLPrecision precision, |
| 32 | const char* name, |
| 33 | const char** outName = nullptr) { |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 34 | SkASSERT(!GrSLTypeIsCombinedSamplerType(type)); |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 35 | return this->addUniformArray(visibility, type, precision, name, 0, outName); |
| 36 | } |
| 37 | |
| 38 | UniformHandle addUniformArray(uint32_t visibility, |
| 39 | GrSLType type, |
| 40 | GrSLPrecision precision, |
| 41 | const char* name, |
| 42 | int arrayCount, |
| 43 | const char** outName = nullptr) { |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 44 | SkASSERT(!GrSLTypeIsCombinedSamplerType(type)); |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 45 | return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount, |
| 46 | outName); |
| 47 | } |
| 48 | |
| 49 | virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0; |
| 50 | |
| 51 | /** |
| 52 | * Shortcut for getUniformVariable(u).c_str() |
| 53 | */ |
| 54 | virtual const char* getUniformCStr(UniformHandle u) const = 0; |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 55 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 56 | protected: |
| 57 | explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuilder(program) {} |
| 58 | |
| 59 | // This is not owned by the class |
| 60 | GrGLSLProgramBuilder* fProgramBuilder; |
| 61 | |
| 62 | private: |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 63 | virtual const GrGLSLShaderVar& samplerVariable(SamplerHandle) const = 0; |
| 64 | virtual GrSwizzle samplerSwizzle(SamplerHandle) const = 0; |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 65 | |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame^] | 66 | virtual SamplerHandle addSampler(uint32_t visibility, GrSwizzle, GrSLType, GrSLPrecision, |
| 67 | const char* name) = 0; |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 68 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 69 | virtual UniformHandle internalAddUniformArray(uint32_t visibility, |
| 70 | GrSLType type, |
| 71 | GrSLPrecision precision, |
| 72 | const char* name, |
| 73 | bool mangleName, |
| 74 | int arrayCount, |
| 75 | const char** outName) = 0; |
| 76 | |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 77 | virtual void appendUniformDecls(GrShaderFlags visibility, SkString*) const = 0; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 78 | |
| 79 | friend class GrGLSLProgramBuilder; |
| 80 | }; |
| 81 | |
| 82 | #endif |