OLD | NEW |
(Empty) | |
| 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 |
| 13 /** Manages the resources used by a shader program. |
| 14 * The resources are objects the program uses to communicate with the |
| 15 * application code. |
| 16 */ |
| 17 class GrGLSLProgramDataManager : SkNoncopyable { |
| 18 public: |
| 19 // Opaque handle to a resource |
| 20 class ShaderResourceHandle { |
| 21 public: |
| 22 ShaderResourceHandle(int value) |
| 23 : fValue(value) { |
| 24 SkASSERT(this->isValid()); |
| 25 } |
| 26 |
| 27 ShaderResourceHandle() |
| 28 : fValue(kInvalid_ShaderResourceHandle) { |
| 29 } |
| 30 |
| 31 bool operator==(const ShaderResourceHandle& other) const { return other.
fValue == fValue; } |
| 32 bool isValid() const { return kInvalid_ShaderResourceHandle != fValue; } |
| 33 int toIndex() const { SkASSERT(this->isValid()); return fValue; } |
| 34 |
| 35 private: |
| 36 static const int kInvalid_ShaderResourceHandle = -1; |
| 37 int fValue; |
| 38 }; |
| 39 |
| 40 typedef ShaderResourceHandle UniformHandle; |
| 41 |
| 42 virtual ~GrGLSLProgramDataManager() {} |
| 43 |
| 44 /** Functions for uploading uniform values. The varities ending in v can be
used to upload to an |
| 45 * array of uniforms. arrayCount must be <= the array count of the uniform. |
| 46 */ |
| 47 virtual void set1f(UniformHandle, float v0) const = 0; |
| 48 virtual void set1fv(UniformHandle, int arrayCount, const float v[]) const =
0; |
| 49 virtual void set2f(UniformHandle, float, float) const = 0; |
| 50 virtual void set2fv(UniformHandle, int arrayCount, const float v[]) const =
0; |
| 51 virtual void set3f(UniformHandle, float, float, float) const = 0; |
| 52 virtual void set3fv(UniformHandle, int arrayCount, const float v[]) const =
0; |
| 53 virtual void set4f(UniformHandle, float, float, float, float) const = 0; |
| 54 virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const =
0; |
| 55 // matrices are column-major, the first three upload a single matrix, the la
tter three upload |
| 56 // arrayCount matrices into a uniform array. |
| 57 virtual void setMatrix3f(UniformHandle, const float matrix[]) const = 0; |
| 58 virtual void setMatrix4f(UniformHandle, const float matrix[]) const = 0; |
| 59 virtual void setMatrix3fv(UniformHandle, int arrayCount, const float matrice
s[]) const = 0; |
| 60 virtual void setMatrix4fv(UniformHandle, int arrayCount, const float matrice
s[]) const = 0; |
| 61 |
| 62 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform |
| 63 virtual void setSkMatrix(UniformHandle, const SkMatrix&) const = 0; |
| 64 |
| 65 // for nvpr only |
| 66 typedef ShaderResourceHandle SeparableVaryingHandle; |
| 67 virtual void setPathFragmentInputTransform(SeparableVaryingHandle u, int com
ponents, |
| 68 const SkMatrix& matrix) const = 0
; |
| 69 |
| 70 protected: |
| 71 GrGLSLProgramDataManager() {} |
| 72 |
| 73 private: |
| 74 |
| 75 typedef SkNoncopyable INHERITED; |
| 76 }; |
| 77 |
| 78 #endif |
OLD | NEW |