blob: 30c4a63ebce6ee39f3ec8dc120dadef73cce2932 [file] [log] [blame]
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +00001/*
2 * Copyright 2012 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
kkinnunen7510b222014-07-30 00:04:16 -07008#ifndef GrGLProgramDataManager_DEFINED
9#define GrGLProgramDataManager_DEFINED
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000010
egdaniel018fb622015-10-28 07:26:40 -070011#include "glsl/GrGLSLProgramDataManager.h"
12
bsalomon@google.com777c3aa2012-07-25 20:58:20 +000013#include "GrAllocator.h"
egdaniel09aa1fc2016-04-20 07:09:46 -070014#include "gl/GrGLSampler.h"
egdanielf5294392015-10-21 07:14:17 -070015#include "gl/GrGLTypes.h"
egdaniel0d3f0612015-10-21 10:45:48 -070016#include "glsl/GrGLSLShaderVar.h"
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000017
18#include "SkTArray.h"
19
bsalomon861e1032014-12-16 07:33:49 -080020class GrGLGpu;
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000021class SkMatrix;
kkinnunendddc18a2014-08-03 23:19:46 -070022class GrGLProgram;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000023
kkinnunen7510b222014-07-30 00:04:16 -070024/** Manages the resources used by a shader program.
25 * The resources are objects the program uses to communicate with the
26 * application code.
27 */
egdaniel018fb622015-10-28 07:26:40 -070028class GrGLProgramDataManager : public GrGLSLProgramDataManager {
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000029public:
joshualitt47bb3822014-10-07 16:43:25 -070030 struct UniformInfo {
egdaniel0d3f0612015-10-21 10:45:48 -070031 GrGLSLShaderVar fVariable;
32 uint32_t fVisibility;
33 GrGLint fLocation;
kkinnunenec56e452014-08-25 22:21:16 -070034 };
35
egdaniel0eafe792015-11-20 14:01:22 -080036 struct VaryingInfo {
egdaniel0d3f0612015-10-21 10:45:48 -070037 GrGLSLShaderVar fVariable;
38 GrGLint fLocation;
joshualittd8dd47b2015-09-11 11:45:01 -070039 };
40
egdaniel0d3f0612015-10-21 10:45:48 -070041 // This uses an allocator rather than array so that the GrGLSLShaderVars don't move in memory
joshualitt47bb3822014-10-07 16:43:25 -070042 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their
43 // name strings. Otherwise, we'd have to hand out copies.
44 typedef GrTAllocator<UniformInfo> UniformInfoArray;
egdaniel0eafe792015-11-20 14:01:22 -080045 typedef GrTAllocator<VaryingInfo> VaryingInfoArray;
joshualitt47bb3822014-10-07 16:43:25 -070046
joshualittd8dd47b2015-09-11 11:45:01 -070047 GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&,
egdaniel0eafe792015-11-20 14:01:22 -080048 const VaryingInfoArray&);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000049
egdanielb8002482016-04-19 15:24:29 -070050
egdaniel09aa1fc2016-04-20 07:09:46 -070051 void setSamplers(const SkTArray<GrGLSampler>& samplers) const;
52
53 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
54 * array of uniforms. arrayCount must be <= the array count of the uniform.
55 */
fmenozzi497e9e22016-06-21 09:42:12 -070056 void set1i(UniformHandle, int32_t) const override;
fmenozzi35a98c72016-07-20 08:26:12 -070057 void set1iv(UniformHandle, int arrayCount, const int v[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070058 void set1f(UniformHandle, float v0) const override;
59 void set1fv(UniformHandle, int arrayCount, const float v[]) const override;
60 void set2f(UniformHandle, float, float) const override;
61 void set2fv(UniformHandle, int arrayCount, const float v[]) const override;
62 void set3f(UniformHandle, float, float, float) const override;
63 void set3fv(UniformHandle, int arrayCount, const float v[]) const override;
64 void set4f(UniformHandle, float, float, float, float) const override;
65 void set4fv(UniformHandle, int arrayCount, const float v[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000066 // matrices are column-major, the first three upload a single matrix, the latter three upload
67 // arrayCount matrices into a uniform array.
cdalton8d988b32016-03-07 15:39:09 -080068 void setMatrix2f(UniformHandle, const float matrix[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070069 void setMatrix3f(UniformHandle, const float matrix[]) const override;
70 void setMatrix4f(UniformHandle, const float matrix[]) const override;
cdalton8d988b32016-03-07 15:39:09 -080071 void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070072 void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override;
73 void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000074
joshualittd8dd47b2015-09-11 11:45:01 -070075 // for nvpr only
egdaniel0eafe792015-11-20 14:01:22 -080076 void setPathFragmentInputTransform(VaryingHandle u, int components,
egdaniel018fb622015-10-28 07:26:40 -070077 const SkMatrix& matrix) const override;
joshualittd8dd47b2015-09-11 11:45:01 -070078
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000079private:
80 enum {
81 kUnusedUniform = -1,
82 };
83
84 struct Uniform {
85 GrGLint fVSLocation;
86 GrGLint fFSLocation;
kkinnunendddc18a2014-08-03 23:19:46 -070087 SkDEBUGCODE(
88 GrSLType fType;
89 int fArrayCount;
90 );
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000091 };
92
joshualittd8dd47b2015-09-11 11:45:01 -070093 enum {
egdaniel0eafe792015-11-20 14:01:22 -080094 kUnusedPathProcVarying = -1,
joshualittd8dd47b2015-09-11 11:45:01 -070095 };
egdaniel0eafe792015-11-20 14:01:22 -080096 struct PathProcVarying {
joshualittd8dd47b2015-09-11 11:45:01 -070097 GrGLint fLocation;
98 SkDEBUGCODE(
99 GrSLType fType;
100 int fArrayCount;
101 );
102 };
103
joshualitt7d022d62015-05-12 12:03:50 -0700104 SkDEBUGCODE(void printUnused(const Uniform&) const;)
joshualittaf2d56d2015-05-11 06:21:34 -0700105
cdalton8d988b32016-03-07 15:39:09 -0800106 template<int N> inline void setMatrices(UniformHandle, int arrayCount,
107 const float matrices[]) const;
108
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000109 SkTArray<Uniform, true> fUniforms;
egdaniel0eafe792015-11-20 14:01:22 -0800110 SkTArray<PathProcVarying, true> fPathProcVaryings;
bsalomon861e1032014-12-16 07:33:49 -0800111 GrGLGpu* fGpu;
joshualittd8dd47b2015-09-11 11:45:01 -0700112 GrGLuint fProgramID;
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +0000113
egdaniel018fb622015-10-28 07:26:40 -0700114 typedef GrGLSLProgramDataManager INHERITED;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000115};
kkinnunen78cff132015-06-21 22:55:12 -0700116
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000117#endif