blob: bc90769295cb63c5f195734b6dd5e47e447760dd [file] [log] [blame]
cdalton3f6f76f2016-04-11 12:18:09 -07001/*
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"
egdaniel09aa1fc2016-04-20 07:09:46 -070012#include "GrTypesPriv.h"
13#include "SkString.h"
cdalton3f6f76f2016-04-11 12:18:09 -070014
15class GrGLSLSampler {
16public:
egdaniel09aa1fc2016-04-20 07:09:46 -070017 virtual ~GrGLSLSampler() {}
cdalton3f6f76f2016-04-11 12:18:09 -070018
egdaniel09aa1fc2016-04-20 07:09:46 -070019 explicit GrGLSLSampler(uint32_t visibility, GrPixelConfig config)
20 : fVisibility(visibility)
cdalton3f6f76f2016-04-11 12:18:09 -070021 , fConfig(config) {
22 SkASSERT(kUnknown_GrPixelConfig != fConfig);
23 }
24
egdaniel09aa1fc2016-04-20 07:09:46 -070025 uint32_t visibility() const { return fVisibility; }
cdalton3f6f76f2016-04-11 12:18:09 -070026 GrPixelConfig config() const { return fConfig; }
egdaniel09aa1fc2016-04-20 07:09:46 -070027 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 {
egdaniel990dbc82016-07-13 14:09:30 -070032 SkASSERT(GrSLTypeIs2DCombinedSamplerType(this->type()));
egdaniel09aa1fc2016-04-20 07:09:46 -070033 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;
cdalton3f6f76f2016-04-11 12:18:09 -070038
39private:
egdaniel09aa1fc2016-04-20 07:09:46 -070040 virtual const char* onGetSamplerNameForTexture2D() const = 0;
41 uint32_t fVisibility;
cdalton3f6f76f2016-04-11 12:18:09 -070042 GrPixelConfig fConfig;
cdalton3f6f76f2016-04-11 12:18:09 -070043};
44
45#endif