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. |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 64 | 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.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 68 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 69 | // for nvpr only |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 70 | void setPathFragmentInputTransform(VaryingHandle u, int components, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 71 | const SkMatrix& matrix) const override; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 72 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 73 | private: |
| 74 | enum { |
| 75 | kUnusedUniform = -1, |
| 76 | }; |
| 77 | |
| 78 | struct Uniform { |
| 79 | GrGLint fVSLocation; |
| 80 | GrGLint fFSLocation; |
kkinnunen | dddc18a | 2014-08-03 23:19:46 -0700 | [diff] [blame] | 81 | SkDEBUGCODE( |
| 82 | GrSLType fType; |
| 83 | int fArrayCount; |
| 84 | ); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 87 | enum { |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 88 | kUnusedPathProcVarying = -1, |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 89 | }; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 90 | struct PathProcVarying { |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 91 | GrGLint fLocation; |
| 92 | SkDEBUGCODE( |
| 93 | GrSLType fType; |
| 94 | int fArrayCount; |
| 95 | ); |
| 96 | }; |
| 97 | |
joshualitt | 7d022d6 | 2015-05-12 12:03:50 -0700 | [diff] [blame] | 98 | SkDEBUGCODE(void printUnused(const Uniform&) const;) |
joshualitt | af2d56d | 2015-05-11 06:21:34 -0700 | [diff] [blame] | 99 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 100 | SkTArray<Uniform, true> fUniforms; |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 101 | SkTArray<PathProcVarying, true> fPathProcVaryings; |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 102 | GrGLGpu* fGpu; |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame] | 103 | GrGLuint fProgramID; |
commit-bot@chromium.org | 6eac42e | 2014-05-29 21:29:51 +0000 | [diff] [blame] | 104 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 105 | typedef GrGLSLProgramDataManager INHERITED; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 106 | }; |
kkinnunen | 78cff13 | 2015-06-21 22:55:12 -0700 | [diff] [blame] | 107 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 108 | #endif |