blob: f756a2a2e92c5e198ae2178a852da3d2313d6408 [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;
egdaniel09aa1fc2016-04-20 07:09:46 -070049
50 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
51 * array of uniforms. arrayCount must be <= the array count of the uniform.
52 */
fmenozzi497e9e22016-06-21 09:42:12 -070053 void set1i(UniformHandle, int32_t) const override;
fmenozzi35a98c72016-07-20 08:26:12 -070054 void set1iv(UniformHandle, int arrayCount, const int v[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070055 void set1f(UniformHandle, float v0) const override;
56 void set1fv(UniformHandle, int arrayCount, const float v[]) const override;
57 void set2f(UniformHandle, float, float) const override;
58 void set2fv(UniformHandle, int arrayCount, const float v[]) const override;
59 void set3f(UniformHandle, float, float, float) const override;
60 void set3fv(UniformHandle, int arrayCount, const float v[]) const override;
61 void set4f(UniformHandle, float, float, float, float) const override;
62 void set4fv(UniformHandle, int arrayCount, const float v[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000063 // matrices are column-major, the first three upload a single matrix, the latter three upload
64 // arrayCount matrices into a uniform array.
cdalton8d988b32016-03-07 15:39:09 -080065 void setMatrix2f(UniformHandle, const float matrix[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070066 void setMatrix3f(UniformHandle, const float matrix[]) const override;
67 void setMatrix4f(UniformHandle, const float matrix[]) const override;
cdalton8d988b32016-03-07 15:39:09 -080068 void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070069 void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override;
70 void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000071
joshualittd8dd47b2015-09-11 11:45:01 -070072 // for nvpr only
egdaniel0eafe792015-11-20 14:01:22 -080073 void setPathFragmentInputTransform(VaryingHandle u, int components,
egdaniel018fb622015-10-28 07:26:40 -070074 const SkMatrix& matrix) const override;
joshualittd8dd47b2015-09-11 11:45:01 -070075
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000076private:
77 enum {
78 kUnusedUniform = -1,
79 };
80
81 struct Uniform {
Brian Salomon101b8442016-11-18 11:58:54 -050082 GrGLint fLocation;
83#ifdef SK_DEBUG
84 GrSLType fType;
85 int fArrayCount;
86#endif
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000087 };
88
joshualittd8dd47b2015-09-11 11:45:01 -070089 enum {
egdaniel0eafe792015-11-20 14:01:22 -080090 kUnusedPathProcVarying = -1,
joshualittd8dd47b2015-09-11 11:45:01 -070091 };
egdaniel0eafe792015-11-20 14:01:22 -080092 struct PathProcVarying {
joshualittd8dd47b2015-09-11 11:45:01 -070093 GrGLint fLocation;
94 SkDEBUGCODE(
95 GrSLType fType;
96 int fArrayCount;
97 );
98 };
99
cdalton8d988b32016-03-07 15:39:09 -0800100 template<int N> inline void setMatrices(UniformHandle, int arrayCount,
101 const float matrices[]) const;
102
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000103 SkTArray<Uniform, true> fUniforms;
egdaniel0eafe792015-11-20 14:01:22 -0800104 SkTArray<PathProcVarying, true> fPathProcVaryings;
bsalomon861e1032014-12-16 07:33:49 -0800105 GrGLGpu* fGpu;
joshualittd8dd47b2015-09-11 11:45:01 -0700106 GrGLuint fProgramID;
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +0000107
egdaniel018fb622015-10-28 07:26:40 -0700108 typedef GrGLSLProgramDataManager INHERITED;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000109};
kkinnunen78cff132015-06-21 22:55:12 -0700110
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000111#endif