blob: 6b4e4d99bbb4648a781a3d5a8a0d4e59abbea27e [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
bsalomon@google.com777c3aa2012-07-25 20:58:20 +000011#include "GrAllocator.h"
Brian Salomon99938a82016-11-21 13:41:08 -050012#include "GrShaderVar.h"
egdanielf5294392015-10-21 07:14:17 -070013#include "gl/GrGLTypes.h"
Brian Salomon99938a82016-11-21 13:41:08 -050014#include "glsl/GrGLSLProgramDataManager.h"
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000015
16#include "SkTArray.h"
17
bsalomon861e1032014-12-16 07:33:49 -080018class GrGLGpu;
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000019class SkMatrix;
kkinnunendddc18a2014-08-03 23:19:46 -070020class GrGLProgram;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000021
kkinnunen7510b222014-07-30 00:04:16 -070022/** Manages the resources used by a shader program.
23 * The resources are objects the program uses to communicate with the
24 * application code.
25 */
egdaniel018fb622015-10-28 07:26:40 -070026class GrGLProgramDataManager : public GrGLSLProgramDataManager {
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000027public:
joshualitt47bb3822014-10-07 16:43:25 -070028 struct UniformInfo {
Brian Salomon99938a82016-11-21 13:41:08 -050029 GrShaderVar fVariable;
egdaniel0d3f0612015-10-21 10:45:48 -070030 uint32_t fVisibility;
31 GrGLint fLocation;
kkinnunenec56e452014-08-25 22:21:16 -070032 };
33
egdaniel0eafe792015-11-20 14:01:22 -080034 struct VaryingInfo {
Brian Salomon99938a82016-11-21 13:41:08 -050035 GrShaderVar fVariable;
egdaniel0d3f0612015-10-21 10:45:48 -070036 GrGLint fLocation;
joshualittd8dd47b2015-09-11 11:45:01 -070037 };
38
Brian Salomon99938a82016-11-21 13:41:08 -050039 // This uses an allocator rather than array so that the GrShaderVars don't move in memory
joshualitt47bb3822014-10-07 16:43:25 -070040 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their
41 // name strings. Otherwise, we'd have to hand out copies.
42 typedef GrTAllocator<UniformInfo> UniformInfoArray;
egdaniel0eafe792015-11-20 14:01:22 -080043 typedef GrTAllocator<VaryingInfo> VaryingInfoArray;
joshualitt47bb3822014-10-07 16:43:25 -070044
joshualittd8dd47b2015-09-11 11:45:01 -070045 GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&,
egdaniel0eafe792015-11-20 14:01:22 -080046 const VaryingInfoArray&);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000047
Greg Danielbc5d4d72017-05-05 10:28:42 -040048 void setSamplerUniforms(const UniformInfoArray& samplers, int startUnit) const;
49 void setImageStorages(const UniformInfoArray& images) const;
egdaniel09aa1fc2016-04-20 07:09:46 -070050
51 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
52 * array of uniforms. arrayCount must be <= the array count of the uniform.
53 */
fmenozzi497e9e22016-06-21 09:42:12 -070054 void set1i(UniformHandle, int32_t) const override;
fmenozzi35a98c72016-07-20 08:26:12 -070055 void set1iv(UniformHandle, int arrayCount, const int v[]) const override;
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 {
Brian Salomon101b8442016-11-18 11:58:54 -050083 GrGLint fLocation;
84#ifdef SK_DEBUG
85 GrSLType fType;
86 int fArrayCount;
87#endif
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000088 };
89
joshualittd8dd47b2015-09-11 11:45:01 -070090 enum {
egdaniel0eafe792015-11-20 14:01:22 -080091 kUnusedPathProcVarying = -1,
joshualittd8dd47b2015-09-11 11:45:01 -070092 };
egdaniel0eafe792015-11-20 14:01:22 -080093 struct PathProcVarying {
joshualittd8dd47b2015-09-11 11:45:01 -070094 GrGLint fLocation;
95 SkDEBUGCODE(
96 GrSLType fType;
97 int fArrayCount;
98 );
99 };
100
cdalton8d988b32016-03-07 15:39:09 -0800101 template<int N> inline void setMatrices(UniformHandle, int arrayCount,
102 const float matrices[]) const;
103
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000104 SkTArray<Uniform, true> fUniforms;
egdaniel0eafe792015-11-20 14:01:22 -0800105 SkTArray<PathProcVarying, true> fPathProcVaryings;
bsalomon861e1032014-12-16 07:33:49 -0800106 GrGLGpu* fGpu;
joshualittd8dd47b2015-09-11 11:45:01 -0700107 GrGLuint fProgramID;
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +0000108
egdaniel018fb622015-10-28 07:26:40 -0700109 typedef GrGLSLProgramDataManager INHERITED;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000110};
kkinnunen78cff132015-06-21 22:55:12 -0700111
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000112#endif