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" |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 12 | #include "GrShaderVar.h" |
| 13 | #include "GrSwizzle.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 14 | |
| 15 | class GrGLSLProgramBuilder; |
| 16 | |
| 17 | class GrGLSLUniformHandler { |
| 18 | public: |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 19 | virtual ~GrGLSLUniformHandler() {} |
| 20 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 21 | using UniformHandle = GrGLSLProgramDataManager::UniformHandle; |
| 22 | GR_DEFINE_RESOURCE_HANDLE_CLASS(SamplerHandle); |
Greg Daniel | bc5d4d7 | 2017-05-05 10:28:42 -0400 | [diff] [blame] | 23 | GR_DEFINE_RESOURCE_HANDLE_CLASS(TexelBufferHandle); |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 24 | GR_DEFINE_RESOURCE_HANDLE_CLASS(ImageStorageHandle); |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 25 | |
| 26 | /** 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] | 27 | visibility is a bitfield of GrShaderFlag values indicating from which shaders the uniform |
| 28 | 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] | 29 | supported at this time. The actual uniform name will be mangled. If outName is not nullptr |
| 30 | then it will refer to the final uniform name after return. Use the addUniformArray variant |
| 31 | to add an array of uniforms. */ |
| 32 | UniformHandle addUniform(uint32_t visibility, |
| 33 | GrSLType type, |
| 34 | GrSLPrecision precision, |
| 35 | const char* name, |
| 36 | const char** outName = nullptr) { |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 37 | SkASSERT(!GrSLTypeIsCombinedSamplerType(type)); |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 38 | return this->addUniformArray(visibility, type, precision, name, 0, outName); |
| 39 | } |
| 40 | |
| 41 | UniformHandle addUniformArray(uint32_t visibility, |
| 42 | GrSLType type, |
| 43 | GrSLPrecision precision, |
| 44 | const char* name, |
| 45 | int arrayCount, |
| 46 | const char** outName = nullptr) { |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame] | 47 | SkASSERT(!GrSLTypeIsCombinedSamplerType(type)); |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 48 | return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount, |
| 49 | outName); |
| 50 | } |
| 51 | |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 52 | virtual const GrShaderVar& getUniformVariable(UniformHandle u) const = 0; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Shortcut for getUniformVariable(u).c_str() |
| 56 | */ |
| 57 | virtual const char* getUniformCStr(UniformHandle u) const = 0; |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 58 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 59 | protected: |
| 60 | explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuilder(program) {} |
| 61 | |
| 62 | // This is not owned by the class |
| 63 | GrGLSLProgramBuilder* fProgramBuilder; |
| 64 | |
| 65 | private: |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 66 | virtual const GrShaderVar& samplerVariable(SamplerHandle) const = 0; |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 67 | virtual GrSwizzle samplerSwizzle(SamplerHandle) const = 0; |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 68 | |
Brian Salomon | 101b844 | 2016-11-18 11:58:54 -0500 | [diff] [blame] | 69 | virtual SamplerHandle addSampler(uint32_t visibility, GrSwizzle, GrSLType, GrSLPrecision, |
| 70 | const char* name) = 0; |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 71 | |
Greg Daniel | bc5d4d7 | 2017-05-05 10:28:42 -0400 | [diff] [blame] | 72 | virtual const GrShaderVar& texelBufferVariable(TexelBufferHandle) const = 0; |
| 73 | virtual TexelBufferHandle addTexelBuffer(uint32_t visibility, GrSLPrecision, |
| 74 | const char* name) = 0; |
| 75 | |
Brian Salomon | f9f4512 | 2016-11-29 11:59:17 -0500 | [diff] [blame] | 76 | virtual const GrShaderVar& imageStorageVariable(ImageStorageHandle) const = 0; |
| 77 | virtual ImageStorageHandle addImageStorage(uint32_t visibility, GrSLType type, |
| 78 | GrImageStorageFormat, GrSLMemoryModel, GrSLRestrict, |
| 79 | GrIOType, const char* name) = 0; |
| 80 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 81 | virtual UniformHandle internalAddUniformArray(uint32_t visibility, |
| 82 | GrSLType type, |
| 83 | GrSLPrecision precision, |
| 84 | const char* name, |
| 85 | bool mangleName, |
| 86 | int arrayCount, |
| 87 | const char** outName) = 0; |
| 88 | |
cdalton | 5e58cee | 2016-02-11 12:49:47 -0800 | [diff] [blame] | 89 | virtual void appendUniformDecls(GrShaderFlags visibility, SkString*) const = 0; |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 90 | |
| 91 | friend class GrGLSLProgramBuilder; |
| 92 | }; |
| 93 | |
| 94 | #endif |