blob: 531f7f048aef467713130c2d3eefc89fe4089b3b [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/gl/GrGLTypes.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/GrShaderVar.h"
Michael Ludwigcc848b52020-07-22 16:36:49 -040013#include "src/gpu/GrTBlockList.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
Ethan Nicholas16464c32020-04-06 13:53:05 -040015#include "src/gpu/glsl/GrGLSLUniformHandler.h"
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000016
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "include/private/SkTArray.h"
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000018
bsalomon861e1032014-12-16 07:33:49 -080019class GrGLGpu;
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000020class SkMatrix;
kkinnunendddc18a2014-08-03 23:19:46 -070021class GrGLProgram;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000022
kkinnunen7510b222014-07-30 00:04:16 -070023/** Manages the resources used by a shader program.
24 * The resources are objects the program uses to communicate with the
25 * application code.
26 */
egdaniel018fb622015-10-28 07:26:40 -070027class GrGLProgramDataManager : public GrGLSLProgramDataManager {
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000028public:
Ethan Nicholas16464c32020-04-06 13:53:05 -040029 struct GLUniformInfo : public GrGLSLUniformHandler::UniformInfo {
30 GrGLint fLocation;
kkinnunenec56e452014-08-25 22:21:16 -070031 };
32
egdaniel0eafe792015-11-20 14:01:22 -080033 struct VaryingInfo {
Brian Salomon99938a82016-11-21 13:41:08 -050034 GrShaderVar fVariable;
Ethan Nicholas16464c32020-04-06 13:53:05 -040035 GrGLint fLocation;
joshualittd8dd47b2015-09-11 11:45:01 -070036 };
37
Michael Ludwigcc848b52020-07-22 16:36:49 -040038 // This uses a GrTBlockList rather than SkTArray/std::vector so that the GrShaderVars
39 // don't move in memory after they are inserted. Users of GrGLShaderBuilder get refs to the vars
40 // and ptrs to their name strings. Otherwise, we'd have to hand out copies.
41 typedef GrTBlockList<GLUniformInfo> UniformInfoArray;
42 typedef GrTBlockList<VaryingInfo> VaryingInfoArray;
joshualitt47bb3822014-10-07 16:43:25 -070043
joshualittd8dd47b2015-09-11 11:45:01 -070044 GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&,
egdaniel0eafe792015-11-20 14:01:22 -080045 const VaryingInfoArray&);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000046
Greg Danielbc5d4d72017-05-05 10:28:42 -040047 void setSamplerUniforms(const UniformInfoArray& samplers, int startUnit) const;
egdaniel09aa1fc2016-04-20 07:09:46 -070048
49 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
50 * array of uniforms. arrayCount must be <= the array count of the uniform.
51 */
fmenozzi497e9e22016-06-21 09:42:12 -070052 void set1i(UniformHandle, int32_t) const override;
Michael Ludwig779ed022018-08-28 17:20:07 -040053 void set1iv(UniformHandle, int arrayCount, const int32_t v[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070054 void set1f(UniformHandle, float v0) const override;
55 void set1fv(UniformHandle, int arrayCount, const float v[]) const override;
Michael Ludwig779ed022018-08-28 17:20:07 -040056 void set2i(UniformHandle, int32_t, int32_t) const override;
57 void set2iv(UniformHandle, int arrayCount, const int32_t v[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070058 void set2f(UniformHandle, float, float) const override;
59 void set2fv(UniformHandle, int arrayCount, const float v[]) const override;
Michael Ludwig779ed022018-08-28 17:20:07 -040060 void set3i(UniformHandle, int32_t, int32_t, int32_t) const override;
61 void set3iv(UniformHandle, int arrayCount, const int32_t v[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070062 void set3f(UniformHandle, float, float, float) const override;
63 void set3fv(UniformHandle, int arrayCount, const float v[]) const override;
Michael Ludwig779ed022018-08-28 17:20:07 -040064 void set4i(UniformHandle, int32_t, int32_t, int32_t, int32_t) const override;
65 void set4iv(UniformHandle, int arrayCount, const int32_t v[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070066 void set4f(UniformHandle, float, float, float, float) const override;
67 void set4fv(UniformHandle, int arrayCount, const float v[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000068 // matrices are column-major, the first three upload a single matrix, the latter three upload
69 // arrayCount matrices into a uniform array.
cdalton8d988b32016-03-07 15:39:09 -080070 void setMatrix2f(UniformHandle, const float matrix[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070071 void setMatrix3f(UniformHandle, const float matrix[]) const override;
72 void setMatrix4f(UniformHandle, const float matrix[]) const override;
cdalton8d988b32016-03-07 15:39:09 -080073 void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070074 void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override;
75 void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000076
joshualittd8dd47b2015-09-11 11:45:01 -070077 // for nvpr only
egdaniel0eafe792015-11-20 14:01:22 -080078 void setPathFragmentInputTransform(VaryingHandle u, int components,
egdaniel018fb622015-10-28 07:26:40 -070079 const SkMatrix& matrix) const override;
joshualittd8dd47b2015-09-11 11:45:01 -070080
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000081private:
82 enum {
83 kUnusedUniform = -1,
84 };
85
86 struct Uniform {
Brian Salomon101b8442016-11-18 11:58:54 -050087 GrGLint fLocation;
88#ifdef SK_DEBUG
89 GrSLType fType;
90 int fArrayCount;
91#endif
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000092 };
93
joshualittd8dd47b2015-09-11 11:45:01 -070094 enum {
egdaniel0eafe792015-11-20 14:01:22 -080095 kUnusedPathProcVarying = -1,
joshualittd8dd47b2015-09-11 11:45:01 -070096 };
egdaniel0eafe792015-11-20 14:01:22 -080097 struct PathProcVarying {
joshualittd8dd47b2015-09-11 11:45:01 -070098 GrGLint fLocation;
99 SkDEBUGCODE(
100 GrSLType fType;
101 int fArrayCount;
102 );
103 };
104
cdalton8d988b32016-03-07 15:39:09 -0800105 template<int N> inline void setMatrices(UniformHandle, int arrayCount,
106 const float matrices[]) const;
107
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000108 SkTArray<Uniform, true> fUniforms;
egdaniel0eafe792015-11-20 14:01:22 -0800109 SkTArray<PathProcVarying, true> fPathProcVaryings;
bsalomon861e1032014-12-16 07:33:49 -0800110 GrGLGpu* fGpu;
joshualittd8dd47b2015-09-11 11:45:01 -0700111 GrGLuint fProgramID;
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +0000112
John Stiles7571f9e2020-09-02 22:42:33 -0400113 using INHERITED = GrGLSLProgramDataManager;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000114};
kkinnunen78cff132015-06-21 22:55:12 -0700115
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000116#endif