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