bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 8 | #ifndef GrGLProgramDataManager_DEFINED |
| 9 | #define GrGLProgramDataManager_DEFINED |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 10 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 11 | #include "glsl/GrGLSLProgramDataManager.h" |
| 12 | |
bsalomon@google.com | 777c3aa | 2012-07-25 20:58:20 +0000 | [diff] [blame] | 13 | #include "GrAllocator.h" |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 14 | #include "gl/GrGLSampler.h" |
egdaniel | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 15 | #include "gl/GrGLTypes.h" |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 16 | #include "glsl/GrGLSLShaderVar.h" |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 17 | |
| 18 | #include "SkTArray.h" |
| 19 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 20 | class GrGLGpu; |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 21 | class SkMatrix; |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 22 | class GrGLProgram; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 23 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 24 | /** Manages the resources used by a shader program. |
| 25 | * The resources are objects the program uses to communicate with the |
| 26 | * application code. |
| 27 | */ |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 28 | class GrGLProgramDataManager : public GrGLSLProgramDataManager { |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 29 | public: |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 30 | struct UniformInfo { |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 31 | GrGLSLShaderVar fVariable; |
| 32 | uint32_t fVisibility; |
| 33 | GrGLint fLocation; |
kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 36 | struct VaryingInfo { |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 37 | GrGLSLShaderVar fVariable; |
| 38 | GrGLint fLocation; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 41 | // This uses an allocator rather than array so that the GrGLSLShaderVars don't move in memory |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 42 | // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their |
| 43 | // name strings. Otherwise, we'd have to hand out copies. |
| 44 | typedef GrTAllocator<UniformInfo> UniformInfoArray; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 45 | typedef GrTAllocator<VaryingInfo> VaryingInfoArray; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 46 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 47 | GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 48 | const VaryingInfoArray&); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 49 | |
egdaniel | b800248 | 2016-04-19 15:24:29 -0700 | [diff] [blame] | 50 | |
egdaniel | 09aa1fc | 2016-04-20 07:09:46 -0700 | [diff] [blame] | 51 | void setSamplers(const SkTArray<GrGLSampler>& samplers) const; |
| 52 | |
| 53 | /** Functions for uploading uniform values. The varities ending in v can be used to upload to an |
| 54 | * array of uniforms. arrayCount must be <= the array count of the uniform. |
| 55 | */ |
fmenozzi | 497e9e2 | 2016-06-21 09:42:12 -0700 | [diff] [blame] | 56 | void set1i(UniformHandle, int32_t) const override; |
fmenozzi | 35a98c7 | 2016-07-20 08:26:12 -0700 | [diff] [blame^] | 57 | void set1iv(UniformHandle, int arrayCount, const int v[]) const override; |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 58 | void set1f(UniformHandle, float v0) const override; |
| 59 | void set1fv(UniformHandle, int arrayCount, const float v[]) const override; |
| 60 | void set2f(UniformHandle, float, float) const override; |
| 61 | void set2fv(UniformHandle, int arrayCount, const float v[]) const override; |
| 62 | void set3f(UniformHandle, float, float, float) const override; |
| 63 | void set3fv(UniformHandle, int arrayCount, const float v[]) const override; |
| 64 | void set4f(UniformHandle, float, float, float, float) const override; |
| 65 | void set4fv(UniformHandle, int arrayCount, const float v[]) const override; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 66 | // matrices are column-major, the first three upload a single matrix, the latter three upload |
| 67 | // arrayCount matrices into a uniform array. |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 68 | void setMatrix2f(UniformHandle, const float matrix[]) const override; |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 69 | void setMatrix3f(UniformHandle, const float matrix[]) const override; |
| 70 | void setMatrix4f(UniformHandle, const float matrix[]) const override; |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 71 | void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 72 | void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
| 73 | void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 74 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 75 | // for nvpr only |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 76 | void setPathFragmentInputTransform(VaryingHandle u, int components, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 77 | const SkMatrix& matrix) const override; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 78 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 79 | private: |
| 80 | enum { |
| 81 | kUnusedUniform = -1, |
| 82 | }; |
| 83 | |
| 84 | struct Uniform { |
| 85 | GrGLint fVSLocation; |
| 86 | GrGLint fFSLocation; |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 87 | SkDEBUGCODE( |
| 88 | GrSLType fType; |
| 89 | int fArrayCount; |
| 90 | ); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 93 | enum { |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 94 | kUnusedPathProcVarying = -1, |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 95 | }; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 96 | struct PathProcVarying { |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 97 | GrGLint fLocation; |
| 98 | SkDEBUGCODE( |
| 99 | GrSLType fType; |
| 100 | int fArrayCount; |
| 101 | ); |
| 102 | }; |
| 103 | |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 104 | SkDEBUGCODE(void printUnused(const Uniform&) const;) |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 105 | |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame] | 106 | template<int N> inline void setMatrices(UniformHandle, int arrayCount, |
| 107 | const float matrices[]) const; |
| 108 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 109 | SkTArray<Uniform, true> fUniforms; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 110 | SkTArray<PathProcVarying, true> fPathProcVaryings; |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 111 | GrGLGpu* fGpu; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 112 | GrGLuint fProgramID; |
commit-bot@chromium.org | 6eac42e | 2014-05-29 21:29:51 +0000 | [diff] [blame] | 113 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 114 | typedef GrGLSLProgramDataManager INHERITED; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 115 | }; |
kkinnunen | 78cff13 | 2015-06-21 22:55:12 -0700 | [diff] [blame] | 116 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 117 | #endif |