blob: 42e0656915042c9261896947bf4ed8001daacfb2 [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
egdanielb8002482016-04-19 15:24:29 -070048
Brian Salomon101b8442016-11-18 11:58:54 -050049 void setSamplers(const UniformInfoArray& samplers) const;
Brian Salomonf9f45122016-11-29 11:59:17 -050050 void setImageStorages(const UniformInfoArray &images) const;
egdaniel09aa1fc2016-04-20 07:09:46 -070051
52 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
53 * array of uniforms. arrayCount must be <= the array count of the uniform.
54 */
fmenozzi497e9e22016-06-21 09:42:12 -070055 void set1i(UniformHandle, int32_t) const override;
fmenozzi35a98c72016-07-20 08:26:12 -070056 void set1iv(UniformHandle, int arrayCount, const int v[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070057 void set1f(UniformHandle, float v0) const override;
58 void set1fv(UniformHandle, int arrayCount, const float v[]) const override;
59 void set2f(UniformHandle, float, float) const override;
60 void set2fv(UniformHandle, int arrayCount, const float v[]) const override;
61 void set3f(UniformHandle, float, float, float) const override;
62 void set3fv(UniformHandle, int arrayCount, const float v[]) const override;
63 void set4f(UniformHandle, float, float, float, float) const override;
64 void set4fv(UniformHandle, int arrayCount, const float v[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000065 // matrices are column-major, the first three upload a single matrix, the latter three upload
66 // arrayCount matrices into a uniform array.
cdalton8d988b32016-03-07 15:39:09 -080067 void setMatrix2f(UniformHandle, const float matrix[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070068 void setMatrix3f(UniformHandle, const float matrix[]) const override;
69 void setMatrix4f(UniformHandle, const float matrix[]) const override;
cdalton8d988b32016-03-07 15:39:09 -080070 void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override;
egdaniel018fb622015-10-28 07:26:40 -070071 void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override;
72 void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000073
joshualittd8dd47b2015-09-11 11:45:01 -070074 // for nvpr only
egdaniel0eafe792015-11-20 14:01:22 -080075 void setPathFragmentInputTransform(VaryingHandle u, int components,
egdaniel018fb622015-10-28 07:26:40 -070076 const SkMatrix& matrix) const override;
joshualittd8dd47b2015-09-11 11:45:01 -070077
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000078private:
79 enum {
80 kUnusedUniform = -1,
81 };
82
83 struct Uniform {
Brian Salomon101b8442016-11-18 11:58:54 -050084 GrGLint fLocation;
85#ifdef SK_DEBUG
86 GrSLType fType;
87 int fArrayCount;
88#endif
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
cdalton8d988b32016-03-07 15:39:09 -0800102 template<int N> inline void setMatrices(UniformHandle, int arrayCount,
103 const float matrices[]) const;
104
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000105 SkTArray<Uniform, true> fUniforms;
egdaniel0eafe792015-11-20 14:01:22 -0800106 SkTArray<PathProcVarying, true> fPathProcVaryings;
bsalomon861e1032014-12-16 07:33:49 -0800107 GrGLGpu* fGpu;
joshualittd8dd47b2015-09-11 11:45:01 -0700108 GrGLuint fProgramID;
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +0000109
egdaniel018fb622015-10-28 07:26:40 -0700110 typedef GrGLSLProgramDataManager INHERITED;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000111};
kkinnunen78cff132015-06-21 22:55:12 -0700112
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000113#endif