Jim Van Verth | be259dc | 2020-05-19 11:40:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 Google LLC |
| 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 | |
| 8 | #ifndef GrUniformDataManager_DEFINED |
| 9 | #define GrUniformDataManager_DEFINED |
| 10 | |
| 11 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 12 | |
| 13 | #include "include/private/GrTypesPriv.h" |
| 14 | #include "include/private/SkTArray.h" |
| 15 | #include "src/core/SkAutoMalloc.h" |
| 16 | |
| 17 | class GrUniformDataManager : public GrGLSLProgramDataManager { |
| 18 | public: |
| 19 | GrUniformDataManager(uint32_t uniformCount, uint32_t uniformSize); |
| 20 | |
| 21 | void set1i(UniformHandle, int32_t) const override; |
| 22 | void set1iv(UniformHandle, int arrayCount, const int32_t v[]) const override; |
| 23 | void set1f(UniformHandle, float v0) const override; |
| 24 | void set1fv(UniformHandle, int arrayCount, const float v[]) const override; |
| 25 | void set2i(UniformHandle, int32_t, int32_t) const override; |
| 26 | void set2iv(UniformHandle, int arrayCount, const int32_t v[]) const override; |
| 27 | void set2f(UniformHandle, float, float) const override; |
| 28 | void set2fv(UniformHandle, int arrayCount, const float v[]) const override; |
| 29 | void set3i(UniformHandle, int32_t, int32_t, int32_t) const override; |
| 30 | void set3iv(UniformHandle, int arrayCount, const int32_t v[]) const override; |
| 31 | void set3f(UniformHandle, float, float, float) const override; |
| 32 | void set3fv(UniformHandle, int arrayCount, const float v[]) const override; |
| 33 | void set4i(UniformHandle, int32_t, int32_t, int32_t, int32_t) const override; |
| 34 | void set4iv(UniformHandle, int arrayCount, const int32_t v[]) const override; |
| 35 | void set4f(UniformHandle, float, float, float, float) const override; |
| 36 | void set4fv(UniformHandle, int arrayCount, const float v[]) const override; |
| 37 | // matrices are column-major, the first two upload a single matrix, the latter two upload |
| 38 | // arrayCount matrices into a uniform array. |
| 39 | void setMatrix2f(UniformHandle, const float matrix[]) const override; |
| 40 | void setMatrix3f(UniformHandle, const float matrix[]) const override; |
| 41 | void setMatrix4f(UniformHandle, const float matrix[]) const override; |
| 42 | void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
| 43 | void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
| 44 | void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override; |
| 45 | |
| 46 | // for nvpr only |
| 47 | void setPathFragmentInputTransform(VaryingHandle u, int components, |
| 48 | const SkMatrix& matrix) const override { |
| 49 | SK_ABORT("Only supported in NVPR, which is only available in GL"); |
| 50 | } |
| 51 | |
Greg Daniel | a581a8b | 2020-06-19 15:22:18 -0400 | [diff] [blame^] | 52 | // For the uniform data to be dirty so that we will reupload on the next use. |
| 53 | void markDirty() { fUniformsDirty = true; } |
| 54 | |
Jim Van Verth | be259dc | 2020-05-19 11:40:31 -0400 | [diff] [blame] | 55 | protected: |
| 56 | struct Uniform { |
| 57 | uint32_t fOffset; |
| 58 | SkDEBUGCODE( |
| 59 | GrSLType fType; |
| 60 | int fArrayCount; |
| 61 | ); |
| 62 | }; |
| 63 | |
| 64 | template<int N> inline void setMatrices(UniformHandle, int arrayCount, |
| 65 | const float matrices[]) const; |
| 66 | |
| 67 | void* getBufferPtrAndMarkDirty(const Uniform& uni) const; |
| 68 | |
| 69 | uint32_t fUniformSize; |
| 70 | |
| 71 | SkTArray<Uniform, true> fUniforms; |
| 72 | |
| 73 | mutable SkAutoMalloc fUniformData; |
| 74 | mutable bool fUniformsDirty; |
| 75 | }; |
| 76 | |
| 77 | #endif |