egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
| 8 | #ifndef GrGLSLProgramDataManager_DEFINED |
| 9 | #define GrGLSLProgramDataManager_DEFINED |
| 10 | |
| 11 | #include "SkTypes.h" |
| 12 | |
egdaniel | 7dc4bd0 | 2015-10-29 07:57:01 -0700 | [diff] [blame] | 13 | class SkMatrix; |
| 14 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 15 | /** Manages the resources used by a shader program. |
| 16 | * The resources are objects the program uses to communicate with the |
| 17 | * application code. |
| 18 | */ |
| 19 | class GrGLSLProgramDataManager : SkNoncopyable { |
| 20 | public: |
| 21 | // Opaque handle to a resource |
| 22 | class ShaderResourceHandle { |
| 23 | public: |
| 24 | ShaderResourceHandle(int value) |
| 25 | : fValue(value) { |
| 26 | SkASSERT(this->isValid()); |
| 27 | } |
| 28 | |
| 29 | ShaderResourceHandle() |
| 30 | : fValue(kInvalid_ShaderResourceHandle) { |
| 31 | } |
| 32 | |
| 33 | bool operator==(const ShaderResourceHandle& other) const { return other.fValue == fValue; } |
| 34 | bool isValid() const { return kInvalid_ShaderResourceHandle != fValue; } |
| 35 | int toIndex() const { SkASSERT(this->isValid()); return fValue; } |
| 36 | |
| 37 | private: |
| 38 | static const int kInvalid_ShaderResourceHandle = -1; |
| 39 | int fValue; |
| 40 | }; |
| 41 | |
| 42 | typedef ShaderResourceHandle UniformHandle; |
| 43 | |
| 44 | virtual ~GrGLSLProgramDataManager() {} |
| 45 | |
| 46 | /** Functions for uploading uniform values. The varities ending in v can be used to upload to an |
| 47 | * array of uniforms. arrayCount must be <= the array count of the uniform. |
| 48 | */ |
| 49 | virtual void set1f(UniformHandle, float v0) const = 0; |
| 50 | virtual void set1fv(UniformHandle, int arrayCount, const float v[]) const = 0; |
| 51 | virtual void set2f(UniformHandle, float, float) const = 0; |
| 52 | virtual void set2fv(UniformHandle, int arrayCount, const float v[]) const = 0; |
| 53 | virtual void set3f(UniformHandle, float, float, float) const = 0; |
| 54 | virtual void set3fv(UniformHandle, int arrayCount, const float v[]) const = 0; |
| 55 | virtual void set4f(UniformHandle, float, float, float, float) const = 0; |
| 56 | virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const = 0; |
| 57 | // matrices are column-major, the first three upload a single matrix, the latter three upload |
| 58 | // arrayCount matrices into a uniform array. |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame^] | 59 | virtual void setMatrix2f(UniformHandle, const float matrix[]) const = 0; |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 60 | virtual void setMatrix3f(UniformHandle, const float matrix[]) const = 0; |
| 61 | virtual void setMatrix4f(UniformHandle, const float matrix[]) const = 0; |
cdalton | 8d988b3 | 2016-03-07 15:39:09 -0800 | [diff] [blame^] | 62 | virtual void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const = 0; |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 63 | virtual void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const = 0; |
| 64 | virtual void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const = 0; |
| 65 | |
| 66 | // convenience method for uploading a SkMatrix to a 3x3 matrix uniform |
egdaniel | 2829bb7 | 2016-02-03 09:52:51 -0800 | [diff] [blame] | 67 | void setSkMatrix(UniformHandle, const SkMatrix&) const; |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 68 | |
| 69 | // for nvpr only |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 70 | typedef ShaderResourceHandle VaryingHandle; |
| 71 | virtual void setPathFragmentInputTransform(VaryingHandle u, int components, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 72 | const SkMatrix& matrix) const = 0; |
| 73 | |
| 74 | protected: |
| 75 | GrGLSLProgramDataManager() {} |
| 76 | |
| 77 | private: |
| 78 | |
| 79 | typedef SkNoncopyable INHERITED; |
| 80 | }; |
| 81 | |
| 82 | #endif |