OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGLSLProgramDataManager_DEFINED | 8 #ifndef GrGLSLProgramDataManager_DEFINED |
9 #define GrGLSLProgramDataManager_DEFINED | 9 #define GrGLSLProgramDataManager_DEFINED |
10 | 10 |
| 11 #include "GrResourceHandle.h" |
11 #include "SkTypes.h" | 12 #include "SkTypes.h" |
12 | 13 |
13 class SkMatrix; | 14 class SkMatrix; |
14 | 15 |
15 /** Manages the resources used by a shader program. | 16 /** Manages the resources used by a shader program. |
16 * The resources are objects the program uses to communicate with the | 17 * The resources are objects the program uses to communicate with the |
17 * application code. | 18 * application code. |
18 */ | 19 */ |
19 class GrGLSLProgramDataManager : SkNoncopyable { | 20 class GrGLSLProgramDataManager : SkNoncopyable { |
20 public: | 21 public: |
21 // Opaque handle to a resource | 22 GR_DEFINE_RESOURCE_HANDLE_CLASS(UniformHandle); |
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 | 23 |
44 virtual ~GrGLSLProgramDataManager() {} | 24 virtual ~GrGLSLProgramDataManager() {} |
45 | 25 |
46 /** Functions for uploading uniform values. The varities ending in v can be
used to upload to an | 26 /** 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. | 27 * array of uniforms. arrayCount must be <= the array count of the uniform. |
48 */ | 28 */ |
49 virtual void set1f(UniformHandle, float v0) const = 0; | 29 virtual void set1f(UniformHandle, float v0) const = 0; |
50 virtual void set1fv(UniformHandle, int arrayCount, const float v[]) const =
0; | 30 virtual void set1fv(UniformHandle, int arrayCount, const float v[]) const =
0; |
51 virtual void set2f(UniformHandle, float, float) const = 0; | 31 virtual void set2f(UniformHandle, float, float) const = 0; |
52 virtual void set2fv(UniformHandle, int arrayCount, const float v[]) const =
0; | 32 virtual void set2fv(UniformHandle, int arrayCount, const float v[]) const =
0; |
53 virtual void set3f(UniformHandle, float, float, float) const = 0; | 33 virtual void set3f(UniformHandle, float, float, float) const = 0; |
54 virtual void set3fv(UniformHandle, int arrayCount, const float v[]) const =
0; | 34 virtual void set3fv(UniformHandle, int arrayCount, const float v[]) const =
0; |
55 virtual void set4f(UniformHandle, float, float, float, float) const = 0; | 35 virtual void set4f(UniformHandle, float, float, float, float) const = 0; |
56 virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const =
0; | 36 virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const =
0; |
57 // matrices are column-major, the first three upload a single matrix, the la
tter three upload | 37 // matrices are column-major, the first three upload a single matrix, the la
tter three upload |
58 // arrayCount matrices into a uniform array. | 38 // arrayCount matrices into a uniform array. |
59 virtual void setMatrix2f(UniformHandle, const float matrix[]) const = 0; | 39 virtual void setMatrix2f(UniformHandle, const float matrix[]) const = 0; |
60 virtual void setMatrix3f(UniformHandle, const float matrix[]) const = 0; | 40 virtual void setMatrix3f(UniformHandle, const float matrix[]) const = 0; |
61 virtual void setMatrix4f(UniformHandle, const float matrix[]) const = 0; | 41 virtual void setMatrix4f(UniformHandle, const float matrix[]) const = 0; |
62 virtual void setMatrix2fv(UniformHandle, int arrayCount, const float matrice
s[]) const = 0; | 42 virtual void setMatrix2fv(UniformHandle, int arrayCount, const float matrice
s[]) const = 0; |
63 virtual void setMatrix3fv(UniformHandle, int arrayCount, const float matrice
s[]) const = 0; | 43 virtual void setMatrix3fv(UniformHandle, int arrayCount, const float matrice
s[]) const = 0; |
64 virtual void setMatrix4fv(UniformHandle, int arrayCount, const float matrice
s[]) const = 0; | 44 virtual void setMatrix4fv(UniformHandle, int arrayCount, const float matrice
s[]) const = 0; |
65 | 45 |
66 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform | 46 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform |
67 void setSkMatrix(UniformHandle, const SkMatrix&) const; | 47 void setSkMatrix(UniformHandle, const SkMatrix&) const; |
68 | 48 |
69 // for nvpr only | 49 // for nvpr only |
70 typedef ShaderResourceHandle VaryingHandle; | 50 GR_DEFINE_RESOURCE_HANDLE_CLASS(VaryingHandle); |
71 virtual void setPathFragmentInputTransform(VaryingHandle u, int components, | 51 virtual void setPathFragmentInputTransform(VaryingHandle u, int components, |
72 const SkMatrix& matrix) const = 0
; | 52 const SkMatrix& matrix) const = 0
; |
73 | 53 |
74 protected: | 54 protected: |
75 GrGLSLProgramDataManager() {} | 55 GrGLSLProgramDataManager() {} |
76 | 56 |
77 private: | 57 private: |
78 | |
79 typedef SkNoncopyable INHERITED; | 58 typedef SkNoncopyable INHERITED; |
80 }; | 59 }; |
81 | 60 |
82 #endif | 61 #endif |
OLD | NEW |