Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1282)

Side by Side Diff: src/gpu/gl/GrGLProgramDataManager.h

Issue 367643004: Implement NVPR on GLES (Closed) Base URL: https://skia.googlesource.com/skia.git@02-path-program-fragment
Patch Set: rebse Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 GrGLProgramDataManager_DEFINED 8 #ifndef GrGLProgramDataManager_DEFINED
9 #define GrGLProgramDataManager_DEFINED 9 #define GrGLProgramDataManager_DEFINED
10 10
11 #include "gl/GrGLShaderVar.h" 11 #include "gl/GrGLShaderVar.h"
12 #include "gl/GrGLSL.h" 12 #include "gl/GrGLSL.h"
13 #include "GrAllocator.h" 13 #include "GrAllocator.h"
14 14
15 #include "SkTArray.h" 15 #include "SkTArray.h"
16 16
17 class GrGpuGL; 17 class GrGpuGL;
18 class SkMatrix; 18 class SkMatrix;
19 class GrGLProgram; 19 class GrGLProgram;
20 class GrGLProgramBuilder; 20 class GrGLProgramBuilder;
21 21
22 /** Manages the resources used by a shader program. 22 /** Manages the resources used by a shader program.
23 * The resources are objects the program uses to communicate with the 23 * The resources are objects the program uses to communicate with the
24 * application code. 24 * application code.
25 */ 25 */
26 class GrGLProgramDataManager : public SkRefCnt { 26 class GrGLProgramDataManager : public SkRefCnt {
27 public: 27 public:
28 // Opaque handle to a uniform 28 // Opaque handle to a uniform
29 class UniformHandle { 29 class ShaderResourceHandle {
30 public:
31 bool isValid() const { return -1 != fValue; }
32 ShaderResourceHandle()
33 : fValue(-1) {
34 }
35 protected:
36 ShaderResourceHandle(int value)
37 : fValue(value) {
38 SkASSERT(isValid());
39 }
40 int fValue;
41 };
42
43 class UniformHandle : public ShaderResourceHandle {
30 public: 44 public:
31 /** Creates a reference to an unifrom of a GrGLShaderBuilder. 45 /** Creates a reference to an unifrom of a GrGLShaderBuilder.
32 * The ref can be used to set the uniform with corresponding the GrGLPro gramDataManager.*/ 46 * The ref can be used to set the uniform with corresponding the GrGLPro gramDataManager.*/
33 static UniformHandle CreateFromUniformIndex(int i); 47 static UniformHandle CreateFromUniformIndex(int i);
34 48 UniformHandle() { }
35 bool isValid() const { return -1 != fValue; }
36
37 bool operator==(const UniformHandle& other) const { return other.fValue == fValue; } 49 bool operator==(const UniformHandle& other) const { return other.fValue == fValue; }
38
39 UniformHandle()
40 : fValue(-1) {
41 }
42
43 private: 50 private:
44 UniformHandle(int value) 51 UniformHandle(int value) : ShaderResourceHandle(value) { }
45 : fValue(value) {
46 SkASSERT(isValid());
47 }
48
49 int toProgramDataIndex() const { SkASSERT(isValid()); return fValue; } 52 int toProgramDataIndex() const { SkASSERT(isValid()); return fValue; }
50 int toShaderBuilderIndex() const { return toProgramDataIndex(); } 53 int toShaderBuilderIndex() const { return toProgramDataIndex(); }
51 54
52 int fValue;
53 friend class GrGLProgramDataManager; // For accessing toProgramDataIndex (). 55 friend class GrGLProgramDataManager; // For accessing toProgramDataIndex ().
54 friend class GrGLProgramBuilder; // For accessing toShaderBuilderIndex() . 56 friend class GrGLProgramBuilder; // For accessing toShaderBuilderIndex() .
55 }; 57 };
56 58
59 class VaryingHandle : public ShaderResourceHandle {
60 public:
61 /** Creates a reference to a varying in separable varyings of a GrGLShad erBuilder.
62 * The ref can be used to set the varying with the corresponding GrGLPro gramDataManager.*/
63 static VaryingHandle CreateFromSeparableVaryingIndex(int i) {
64 return VaryingHandle(i);
65 }
66 VaryingHandle() { }
67 bool operator==(const VaryingHandle& other) const { return other.fValue == fValue; }
68 private:
69 VaryingHandle(int value) : ShaderResourceHandle(value) { }
70 int toProgramDataIndex() const { SkASSERT(isValid()); return fValue; }
71 friend class GrGLProgramDataManager; // For accessing toProgramDataIndex ().
72 };
73
57 GrGLProgramDataManager(GrGpuGL*, GrGLProgram*, const GrGLProgramBuilder&); 74 GrGLProgramDataManager(GrGpuGL*, GrGLProgram*, const GrGLProgramBuilder&);
58 75
59 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an 76 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
60 * array of uniforms. arrayCount must be <= the array count of the uniform. 77 * array of uniforms. arrayCount must be <= the array count of the uniform.
61 */ 78 */
62 void setSampler(UniformHandle, GrGLint texUnit) const; 79 void setSampler(UniformHandle, GrGLint texUnit) const;
63 void set1f(UniformHandle, GrGLfloat v0) const; 80 void set1f(UniformHandle, GrGLfloat v0) const;
64 void set1fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; 81 void set1fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
65 void set2f(UniformHandle, GrGLfloat, GrGLfloat) const; 82 void set2f(UniformHandle, GrGLfloat, GrGLfloat) const;
66 void set2fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; 83 void set2fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
67 void set3f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat) const; 84 void set3f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat) const;
68 void set3fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; 85 void set3fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
69 void set4f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat, GrGLfloat) const; 86 void set4f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat, GrGLfloat) const;
70 void set4fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; 87 void set4fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const;
71 // matrices are column-major, the first three upload a single matrix, the la tter three upload 88 // matrices are column-major, the first three upload a single matrix, the la tter three upload
72 // arrayCount matrices into a uniform array. 89 // arrayCount matrices into a uniform array.
73 void setMatrix3f(UniformHandle, const GrGLfloat matrix[]) const; 90 void setMatrix3f(UniformHandle, const GrGLfloat matrix[]) const;
74 void setMatrix4f(UniformHandle, const GrGLfloat matrix[]) const; 91 void setMatrix4f(UniformHandle, const GrGLfloat matrix[]) const;
75 void setMatrix3fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const; 92 void setMatrix3fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const;
76 void setMatrix4fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const; 93 void setMatrix4fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const;
77 94
78 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform 95 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform
79 void setSkMatrix(UniformHandle, const SkMatrix&) const; 96 void setSkMatrix(UniformHandle, const SkMatrix&) const;
80 97
98 void setProgramPathFragmentInputTransform(VaryingHandle i,
99 unsigned components,
100 const SkMatrix& matrix) const;
101
81 private: 102 private:
82 enum { 103 enum {
83 kUnusedUniform = -1, 104 kUnusedUniform = -1,
84 }; 105 };
85 106
86 struct Uniform { 107 struct Uniform {
87 GrGLint fVSLocation; 108 GrGLint fVSLocation;
88 GrGLint fFSLocation; 109 GrGLint fFSLocation;
89 SkDEBUGCODE( 110 SkDEBUGCODE(
90 GrSLType fType; 111 GrSLType fType;
91 int fArrayCount; 112 int fArrayCount;
92 ); 113 );
93 }; 114 };
115 struct Varying {
116 GrGLint fLocation;
117 SkDEBUGCODE(
118 GrSLType fType;
119 );
120 };
94 121
95 SkTArray<Uniform, true> fUniforms; 122 SkTArray<Uniform, true> fUniforms;
123 SkTArray<Varying, true> fVaryings;
96 GrGpuGL* fGpu; 124 GrGpuGL* fGpu;
125 GrGLProgram* fProgram;
97 126
98 typedef SkRefCnt INHERITED; 127 typedef SkRefCnt INHERITED;
99 }; 128 };
100 129
101 #endif 130 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698