blob: 513b6a4ce6fe60cf150675944d2511544a903a40 [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 */
egdaniel018fb622015-10-28 07:26:40 -070056 void set1f(UniformHandle, float v0) const override;
57 void set1fv(UniformHandle, int arrayCount, const float v[]) const override;
58 void set2f(UniformHandle, float, float) const override;
59 void set2fv(UniformHandle, int arrayCount, const float v[]) const override;
60 void set3f(UniformHandle, float, float, float) const override;
61 void set3fv(UniformHandle, int arrayCount, const float v[]) const override;
62 void set4f(UniformHandle, float, float, float, float) const override;
63 void set4fv(UniformHandle, int arrayCount, const float v[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000064 // matrices are column-major, the first three upload a single matrix, the latter three upload
65 // arrayCount matrices into a uniform array.
cdalton8d988b32016-03-07 15:39:09 -080066 void setMatrix2f(UniformHandle, const float matrix[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070067 void setMatrix3f(UniformHandle, const float matrix[]) const override;
68 void setMatrix4f(UniformHandle, const float matrix[]) const override;
cdalton8d988b32016-03-07 15:39:09 -080069 void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070070 void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override;
71 void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000072
joshualittd8dd47b2015-09-11 11:45:01 -070073 // for nvpr only
egdaniel0eafe792015-11-20 14:01:22 -080074 void setPathFragmentInputTransform(VaryingHandle u, int components,
egdaniel018fb622015-10-28 07:26:40 -070075 const SkMatrix& matrix) const override;
joshualittd8dd47b2015-09-11 11:45:01 -070076
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000077private:
78 enum {
79 kUnusedUniform = -1,
80 };
81
82 struct Uniform {
83 GrGLint fVSLocation;
84 GrGLint fFSLocation;
kkinnunendddc18a2014-08-03 23:19:46 -070085 SkDEBUGCODE(
86 GrSLType fType;
87 int fArrayCount;
88 );
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000089 };
90
joshualittd8dd47b2015-09-11 11:45:01 -070091 enum {
egdaniel0eafe792015-11-20 14:01:22 -080092 kUnusedPathProcVarying = -1,
joshualittd8dd47b2015-09-11 11:45:01 -070093 };
egdaniel0eafe792015-11-20 14:01:22 -080094 struct PathProcVarying {
joshualittd8dd47b2015-09-11 11:45:01 -070095 GrGLint fLocation;
96 SkDEBUGCODE(
97 GrSLType fType;
98 int fArrayCount;
99 );
100 };
101
joshualitt7d022d62015-05-12 12:03:50 -0700102 SkDEBUGCODE(void printUnused(const Uniform&) const;)
joshualittaf2d56d2015-05-11 06:21:34 -0700103
cdalton8d988b32016-03-07 15:39:09 -0800104 template<int N> inline void setMatrices(UniformHandle, int arrayCount,
105 const float matrices[]) const;
106
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000107 SkTArray<Uniform, true> fUniforms;
egdaniel0eafe792015-11-20 14:01:22 -0800108 SkTArray<PathProcVarying, true> fPathProcVaryings;
bsalomon861e1032014-12-16 07:33:49 -0800109 GrGLGpu* fGpu;
joshualittd8dd47b2015-09-11 11:45:01 -0700110 GrGLuint fProgramID;
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +0000111
egdaniel018fb622015-10-28 07:26:40 -0700112 typedef GrGLSLProgramDataManager INHERITED;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000113};
kkinnunen78cff132015-06-21 22:55:12 -0700114
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000115#endif