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 | f529439 | 2015-10-21 07:14:17 -0700 | [diff] [blame] | 14 | #include "gl/GrGLTypes.h" |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 15 | #include "glsl/GrGLSLShaderVar.h" |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 16 | |
| 17 | #include "SkTArray.h" |
| 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: |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 29 | struct UniformInfo { |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 30 | GrGLSLShaderVar fVariable; |
| 31 | uint32_t fVisibility; |
| 32 | GrGLint fLocation; |
kkinnunen | ec56e45 | 2014-08-25 22:21:16 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 35 | struct VaryingInfo { |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 36 | GrGLSLShaderVar fVariable; |
| 37 | GrGLint fLocation; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
egdaniel | 0d3f061 | 2015-10-21 10:45:48 -0700 | [diff] [blame] | 40 | // 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] | 41 | // 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; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 44 | typedef GrTAllocator<VaryingInfo> VaryingInfoArray; |
joshualitt | 47bb382 | 2014-10-07 16:43:25 -0700 | [diff] [blame] | 45 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 46 | GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 47 | const VaryingInfoArray&); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 48 | |
| 49 | /** Functions for uploading uniform values. The varities ending in v can be used to upload to an |
commit-bot@chromium.org | d3baf20 | 2013-11-07 22:06:08 +0000 | [diff] [blame] | 50 | * array of uniforms. arrayCount must be <= the array count of the uniform. |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 51 | */ |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 52 | 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.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 62 | // matrices are column-major, the first three upload a single matrix, the latter three upload |
| 63 | // arrayCount matrices into a uniform array. |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame^] | 64 | void setMatrix2f(UniformHandle, const float matrix[]) const override; |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 65 | void setMatrix3f(UniformHandle, const float matrix[]) const override; |
| 66 | void setMatrix4f(UniformHandle, const float matrix[]) const override; |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame^] | 67 | void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 68 | void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
| 69 | void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 70 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 71 | // for nvpr only |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 72 | void setPathFragmentInputTransform(VaryingHandle u, int components, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 73 | const SkMatrix& matrix) const override; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 74 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 75 | private: |
| 76 | enum { |
| 77 | kUnusedUniform = -1, |
| 78 | }; |
| 79 | |
| 80 | struct Uniform { |
| 81 | GrGLint fVSLocation; |
| 82 | GrGLint fFSLocation; |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 83 | SkDEBUGCODE( |
| 84 | GrSLType fType; |
| 85 | int fArrayCount; |
| 86 | ); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 89 | enum { |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 90 | kUnusedPathProcVarying = -1, |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 91 | }; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 92 | struct PathProcVarying { |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 93 | GrGLint fLocation; |
| 94 | SkDEBUGCODE( |
| 95 | GrSLType fType; |
| 96 | int fArrayCount; |
| 97 | ); |
| 98 | }; |
| 99 | |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 100 | SkDEBUGCODE(void printUnused(const Uniform&) const;) |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 101 | |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame^] | 102 | template<int N> inline void setMatrices(UniformHandle, int arrayCount, |
| 103 | const float matrices[]) const; |
| 104 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 105 | SkTArray<Uniform, true> fUniforms; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 106 | SkTArray<PathProcVarying, true> fPathProcVaryings; |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 107 | GrGLGpu* fGpu; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 108 | GrGLuint fProgramID; |
commit-bot@chromium.org | 6eac42e | 2014-05-29 21:29:51 +0000 | [diff] [blame] | 109 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 110 | typedef GrGLSLProgramDataManager INHERITED; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 111 | }; |
kkinnunen | 78cff13 | 2015-06-21 22:55:12 -0700 | [diff] [blame] | 112 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 113 | #endif |