cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 GrGLSLSampler_DEFINED |
| 9 | #define GrGLSLSampler_DEFINED |
| 10 | |
| 11 | #include "GrTypes.h" |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 12 | #include "GrTypesPriv.h" |
| 13 | #include "SkString.h" |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 14 | |
| 15 | class GrGLSLSampler { |
| 16 | public: |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 17 | virtual ~GrGLSLSampler() {} |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 18 | |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 19 | explicit GrGLSLSampler(uint32_t visibility, GrPixelConfig config) |
| 20 | : fVisibility(visibility) |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 21 | , fConfig(config) { |
| 22 | SkASSERT(kUnknown_GrPixelConfig != fConfig); |
| 23 | } |
| 24 | |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 25 | uint32_t visibility() const { return fVisibility; } |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 26 | GrPixelConfig config() const { return fConfig; } |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 27 | virtual GrSLType type() const = 0; |
| 28 | |
| 29 | // Returns the string to be used for the sampler in glsl 2D texture functions (texture, |
| 30 | // texture2D, etc.) |
| 31 | const char* getSamplerNameForTexture2D() const { |
egdaniel | 990dbc8 | 2016-07-13 14:09:30 -0700 | [diff] [blame^] | 32 | SkASSERT(GrSLTypeIs2DCombinedSamplerType(this->type())); |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 33 | return this->onGetSamplerNameForTexture2D(); |
| 34 | } |
| 35 | |
| 36 | // Returns the string to be used for the sampler in glsl texelFetch. |
| 37 | virtual const char* getSamplerNameForTexelFetch() const = 0; |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 38 | |
| 39 | private: |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 40 | virtual const char* onGetSamplerNameForTexture2D() const = 0; |
| 41 | uint32_t fVisibility; |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 42 | GrPixelConfig fConfig; |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | #endif |