blob: 2c92cece1b774d7aea07bf352fde8bbdb8f73b95 [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"
egdanielf5294392015-10-21 07:14:17 -070014#include "gl/GrGLTypes.h"
egdaniel0d3f0612015-10-21 10:45:48 -070015#include "glsl/GrGLSLShaderVar.h"
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000016
17#include "SkTArray.h"
18
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:
joshualitt47bb3822014-10-07 16:43:25 -070029 struct UniformInfo {
egdaniel0d3f0612015-10-21 10:45:48 -070030 GrGLSLShaderVar fVariable;
31 uint32_t fVisibility;
32 GrGLint fLocation;
kkinnunenec56e452014-08-25 22:21:16 -070033 };
34
egdaniel0eafe792015-11-20 14:01:22 -080035 struct VaryingInfo {
egdaniel0d3f0612015-10-21 10:45:48 -070036 GrGLSLShaderVar fVariable;
37 GrGLint fLocation;
joshualittd8dd47b2015-09-11 11:45:01 -070038 };
39
egdaniel0d3f0612015-10-21 10:45:48 -070040 // This uses an allocator rather than array so that the GrGLSLShaderVars don't move in memory
joshualitt47bb3822014-10-07 16:43:25 -070041 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their
42 // name strings. Otherwise, we'd have to hand out copies.
43 typedef GrTAllocator<UniformInfo> UniformInfoArray;
egdaniel0eafe792015-11-20 14:01:22 -080044 typedef GrTAllocator<VaryingInfo> VaryingInfoArray;
joshualitt47bb3822014-10-07 16:43:25 -070045
joshualittd8dd47b2015-09-11 11:45:01 -070046 GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&,
egdaniel0eafe792015-11-20 14:01:22 -080047 const VaryingInfoArray&);
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000048
49 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
commit-bot@chromium.orgd3baf202013-11-07 22:06:08 +000050 * array of uniforms. arrayCount must be <= the array count of the uniform.
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000051 */
egdaniel018fb622015-10-28 07:26:40 -070052 void setSampler(UniformHandle, int texUnit) const;
53
54 void set1f(UniformHandle, float v0) const override;
55 void set1fv(UniformHandle, int arrayCount, const float v[]) const override;
56 void set2f(UniformHandle, float, float) const override;
57 void set2fv(UniformHandle, int arrayCount, const float v[]) const override;
58 void set3f(UniformHandle, float, float, float) const override;
59 void set3fv(UniformHandle, int arrayCount, const float v[]) const override;
60 void set4f(UniformHandle, float, float, float, float) const override;
61 void set4fv(UniformHandle, int arrayCount, const float v[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000062 // matrices are column-major, the first three upload a single matrix, the latter three upload
63 // arrayCount matrices into a uniform array.
egdaniel018fb622015-10-28 07:26:40 -070064 void setMatrix3f(UniformHandle, const float matrix[]) const override;
65 void setMatrix4f(UniformHandle, const float matrix[]) const override;
66 void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override;
67 void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000068
joshualittd8dd47b2015-09-11 11:45:01 -070069 // for nvpr only
egdaniel0eafe792015-11-20 14:01:22 -080070 void setPathFragmentInputTransform(VaryingHandle u, int components,
egdaniel018fb622015-10-28 07:26:40 -070071 const SkMatrix& matrix) const override;
joshualittd8dd47b2015-09-11 11:45:01 -070072
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000073private:
74 enum {
75 kUnusedUniform = -1,
76 };
77
78 struct Uniform {
79 GrGLint fVSLocation;
80 GrGLint fFSLocation;
kkinnunendddc18a2014-08-03 23:19:46 -070081 SkDEBUGCODE(
82 GrSLType fType;
83 int fArrayCount;
84 );
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000085 };
86
joshualittd8dd47b2015-09-11 11:45:01 -070087 enum {
egdaniel0eafe792015-11-20 14:01:22 -080088 kUnusedPathProcVarying = -1,
joshualittd8dd47b2015-09-11 11:45:01 -070089 };
egdaniel0eafe792015-11-20 14:01:22 -080090 struct PathProcVarying {
joshualittd8dd47b2015-09-11 11:45:01 -070091 GrGLint fLocation;
92 SkDEBUGCODE(
93 GrSLType fType;
94 int fArrayCount;
95 );
96 };
97
joshualitt7d022d62015-05-12 12:03:50 -070098 SkDEBUGCODE(void printUnused(const Uniform&) const;)
joshualittaf2d56d2015-05-11 06:21:34 -070099
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000100 SkTArray<Uniform, true> fUniforms;
egdaniel0eafe792015-11-20 14:01:22 -0800101 SkTArray<PathProcVarying, true> fPathProcVaryings;
bsalomon861e1032014-12-16 07:33:49 -0800102 GrGLGpu* fGpu;
joshualittd8dd47b2015-09-11 11:45:01 -0700103 GrGLuint fProgramID;
commit-bot@chromium.org6eac42e2014-05-29 21:29:51 +0000104
egdaniel018fb622015-10-28 07:26:40 -0700105 typedef GrGLSLProgramDataManager INHERITED;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000106};
kkinnunen78cff132015-06-21 22:55:12 -0700107
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +0000108#endif