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