blob: d49fbd482041a4eb5aa7c09ff4781b542048595c [file] [log] [blame]
egdaniel7ea439b2015-12-03 09:20:44 -08001/*
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 Salomon99938a82016-11-21 13:41:08 -050012#include "GrShaderVar.h"
13#include "GrSwizzle.h"
egdaniel7ea439b2015-12-03 09:20:44 -080014
15class GrGLSLProgramBuilder;
16
17class GrGLSLUniformHandler {
18public:
egdaniel7ea439b2015-12-03 09:20:44 -080019 virtual ~GrGLSLUniformHandler() {}
20
Brian Salomon59dc4112016-11-23 01:02:43 +000021 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
22 typedef GrGLSLProgramDataManager::UniformHandle SamplerHandle;
egdaniel7ea439b2015-12-03 09:20:44 -080023
24 /** Add a uniform variable to the current program, that has visibility in one or more shaders.
cdalton5e58cee2016-02-11 12:49:47 -080025 visibility is a bitfield of GrShaderFlag values indicating from which shaders the uniform
26 should be accessible. At least one bit must be set. Geometry shader uniforms are not
egdaniel7ea439b2015-12-03 09:20:44 -080027 supported at this time. The actual uniform name will be mangled. If outName is not nullptr
28 then it will refer to the final uniform name after return. Use the addUniformArray variant
29 to add an array of uniforms. */
30 UniformHandle addUniform(uint32_t visibility,
31 GrSLType type,
32 GrSLPrecision precision,
33 const char* name,
34 const char** outName = nullptr) {
egdaniel990dbc82016-07-13 14:09:30 -070035 SkASSERT(!GrSLTypeIsCombinedSamplerType(type));
egdaniel7ea439b2015-12-03 09:20:44 -080036 return this->addUniformArray(visibility, type, precision, name, 0, outName);
37 }
38
39 UniformHandle addUniformArray(uint32_t visibility,
40 GrSLType type,
41 GrSLPrecision precision,
42 const char* name,
43 int arrayCount,
44 const char** outName = nullptr) {
egdaniel990dbc82016-07-13 14:09:30 -070045 SkASSERT(!GrSLTypeIsCombinedSamplerType(type));
egdaniel7ea439b2015-12-03 09:20:44 -080046 return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount,
47 outName);
48 }
49
Brian Salomon99938a82016-11-21 13:41:08 -050050 virtual const GrShaderVar& getUniformVariable(UniformHandle u) const = 0;
egdaniel7ea439b2015-12-03 09:20:44 -080051
52 /**
53 * Shortcut for getUniformVariable(u).c_str()
54 */
55 virtual const char* getUniformCStr(UniformHandle u) const = 0;
egdaniel09aa1fc2016-04-20 07:09:46 -070056
egdaniel7ea439b2015-12-03 09:20:44 -080057protected:
58 explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuilder(program) {}
59
60 // This is not owned by the class
61 GrGLSLProgramBuilder* fProgramBuilder;
62
63private:
Brian Salomon99938a82016-11-21 13:41:08 -050064 virtual const GrShaderVar& samplerVariable(SamplerHandle) const = 0;
Brian Salomon101b8442016-11-18 11:58:54 -050065 virtual GrSwizzle samplerSwizzle(SamplerHandle) const = 0;
egdaniel09aa1fc2016-04-20 07:09:46 -070066
Brian Salomon101b8442016-11-18 11:58:54 -050067 virtual SamplerHandle addSampler(uint32_t visibility, GrSwizzle, GrSLType, GrSLPrecision,
68 const char* name) = 0;
egdaniel09aa1fc2016-04-20 07:09:46 -070069
egdaniel7ea439b2015-12-03 09:20:44 -080070 virtual UniformHandle internalAddUniformArray(uint32_t visibility,
71 GrSLType type,
72 GrSLPrecision precision,
73 const char* name,
74 bool mangleName,
75 int arrayCount,
76 const char** outName) = 0;
77
cdalton5e58cee2016-02-11 12:49:47 -080078 virtual void appendUniformDecls(GrShaderFlags visibility, SkString*) const = 0;
egdaniel7ea439b2015-12-03 09:20:44 -080079
80 friend class GrGLSLProgramBuilder;
81};
82
83#endif