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

Side by Side Diff: src/gpu/gl/GrGLUniformManager.cpp

Issue 23636011: Add a GrGpuGL reference for GrGLProgram/GrGLUniformManager (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
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 #include "gl/GrGLShaderBuilder.h" 8 #include "gl/GrGLShaderBuilder.h"
9 #include "gl/GrGLProgram.h" 9 #include "gl/GrGLProgram.h"
10 #include "gl/GrGLUniformHandle.h" 10 #include "gl/GrGLUniformHandle.h"
11 #include "gl/GrGpuGL.h"
11 #include "SkMatrix.h" 12 #include "SkMatrix.h"
12 13
13 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, OFFSET, COUNT) \ 14 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, OFFSET, COUNT) \
14 SkASSERT(offset + arrayCount <= uni.fArrayCount || \ 15 SkASSERT(offset + arrayCount <= uni.fArrayCount || \
15 (0 == offset && 1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount)) 16 (0 == offset && 1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount))
16 17
17 GrGLUniformManager::UniformHandle GrGLUniformManager::appendUniform(GrSLType typ e, int arrayCount) { 18 GrGLUniformManager::UniformHandle GrGLUniformManager::appendUniform(GrSLType typ e, int arrayCount) {
18 int idx = fUniforms.count(); 19 int idx = fUniforms.count();
19 Uniform& uni = fUniforms.push_back(); 20 Uniform& uni = fUniforms.push_back();
20 SkASSERT(GrGLShaderVar::kNonArray == arrayCount || arrayCount > 0); 21 SkASSERT(GrGLShaderVar::kNonArray == arrayCount || arrayCount > 0);
21 uni.fArrayCount = arrayCount; 22 uni.fArrayCount = arrayCount;
22 uni.fType = type; 23 uni.fType = type;
23 uni.fVSLocation = kUnusedUniform; 24 uni.fVSLocation = kUnusedUniform;
24 uni.fFSLocation = kUnusedUniform; 25 uni.fFSLocation = kUnusedUniform;
25 return GrGLUniformManager::UniformHandle::CreateFromUniformIndex(idx); 26 return GrGLUniformManager::UniformHandle::CreateFromUniformIndex(idx);
26 } 27 }
27 28
28 void GrGLUniformManager::setSampler(UniformHandle u, GrGLint texUnit) const { 29 void GrGLUniformManager::setSampler(UniformHandle u, GrGLint texUnit) const {
29 const Uniform& uni = fUniforms[u.toUniformIndex()]; 30 const Uniform& uni = fUniforms[u.toUniformIndex()];
30 SkASSERT(uni.fType == kSampler2D_GrSLType); 31 SkASSERT(uni.fType == kSampler2D_GrSLType);
31 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); 32 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
32 // FIXME: We still insert a single sampler uniform for every stage. If the s hader does not 33 // FIXME: We still insert a single sampler uniform for every stage. If the s hader does not
33 // reference the sampler then the compiler may have optimized it out. Uncomm ent this assert 34 // reference the sampler then the compiler may have optimized it out. Uncomm ent this assert
34 // once stages insert their own samplers. 35 // once stages insert their own samplers.
35 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo cation); 36 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo cation);
36 if (kUnusedUniform != uni.fFSLocation) { 37 if (kUnusedUniform != uni.fFSLocation) {
37 GR_GL_CALL(fContext.interface(), Uniform1i(uni.fFSLocation, texUnit)); 38 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit));
38 } 39 }
39 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 40 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
40 GR_GL_CALL(fContext.interface(), Uniform1i(uni.fVSLocation, texUnit)); 41 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit));
41 } 42 }
42 } 43 }
43 44
44 void GrGLUniformManager::set1f(UniformHandle u, GrGLfloat v0) const { 45 void GrGLUniformManager::set1f(UniformHandle u, GrGLfloat v0) const {
45 const Uniform& uni = fUniforms[u.toUniformIndex()]; 46 const Uniform& uni = fUniforms[u.toUniformIndex()];
46 SkASSERT(uni.fType == kFloat_GrSLType); 47 SkASSERT(uni.fType == kFloat_GrSLType);
47 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); 48 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
48 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion); 49 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion);
49 if (kUnusedUniform != uni.fFSLocation) { 50 if (kUnusedUniform != uni.fFSLocation) {
50 GR_GL_CALL(fContext.interface(), Uniform1f(uni.fFSLocation, v0)); 51 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0));
51 } 52 }
52 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 53 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
53 GR_GL_CALL(fContext.interface(), Uniform1f(uni.fVSLocation, v0)); 54 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0));
54 } 55 }
55 } 56 }
56 57
57 void GrGLUniformManager::set1fv(UniformHandle u, 58 void GrGLUniformManager::set1fv(UniformHandle u,
58 int offset, 59 int offset,
59 int arrayCount, 60 int arrayCount,
60 const GrGLfloat v[]) const { 61 const GrGLfloat v[]) const {
61 const Uniform& uni = fUniforms[u.toUniformIndex()]; 62 const Uniform& uni = fUniforms[u.toUniformIndex()];
62 SkASSERT(uni.fType == kFloat_GrSLType); 63 SkASSERT(uni.fType == kFloat_GrSLType);
63 SkASSERT(arrayCount > 0); 64 SkASSERT(arrayCount > 0);
64 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount); 65 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
65 // This assert fires in some instances of the two-pt gradient for its VSPara ms. 66 // This assert fires in some instances of the two-pt gradient for its VSPara ms.
66 // Once the uniform manager is responsible for inserting the duplicate unifo rm 67 // Once the uniform manager is responsible for inserting the duplicate unifo rm
67 // arrays in VS and FS driver bug workaround, this can be enabled. 68 // arrays in VS and FS driver bug workaround, this can be enabled.
68 //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLoc ation); 69 //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLoc ation);
69 if (kUnusedUniform != uni.fFSLocation) { 70 if (kUnusedUniform != uni.fFSLocation) {
70 GR_GL_CALL(fContext.interface(), Uniform1fv(uni.fFSLocation + offset, ar rayCount, v)); 71 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation + offset, arr ayCount, v));
71 } 72 }
72 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 73 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
73 GR_GL_CALL(fContext.interface(), Uniform1fv(uni.fVSLocation + offset, ar rayCount, v)); 74 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation + offset, arr ayCount, v));
74 } 75 }
75 } 76 }
76 77
77 void GrGLUniformManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) cons t { 78 void GrGLUniformManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) cons t {
78 const Uniform& uni = fUniforms[u.toUniformIndex()]; 79 const Uniform& uni = fUniforms[u.toUniformIndex()];
79 SkASSERT(uni.fType == kVec2f_GrSLType); 80 SkASSERT(uni.fType == kVec2f_GrSLType);
80 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); 81 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
81 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion); 82 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion);
82 if (kUnusedUniform != uni.fFSLocation) { 83 if (kUnusedUniform != uni.fFSLocation) {
83 GR_GL_CALL(fContext.interface(), Uniform2f(uni.fFSLocation, v0, v1)); 84 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1));
84 } 85 }
85 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 86 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
86 GR_GL_CALL(fContext.interface(), Uniform2f(uni.fVSLocation, v0, v1)); 87 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1));
87 } 88 }
88 } 89 }
89 90
90 void GrGLUniformManager::set2fv(UniformHandle u, 91 void GrGLUniformManager::set2fv(UniformHandle u,
91 int offset, 92 int offset,
92 int arrayCount, 93 int arrayCount,
93 const GrGLfloat v[]) const { 94 const GrGLfloat v[]) const {
94 const Uniform& uni = fUniforms[u.toUniformIndex()]; 95 const Uniform& uni = fUniforms[u.toUniformIndex()];
95 SkASSERT(uni.fType == kVec2f_GrSLType); 96 SkASSERT(uni.fType == kVec2f_GrSLType);
96 SkASSERT(arrayCount > 0); 97 SkASSERT(arrayCount > 0);
97 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount); 98 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
98 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion); 99 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion);
99 if (kUnusedUniform != uni.fFSLocation) { 100 if (kUnusedUniform != uni.fFSLocation) {
100 GR_GL_CALL(fContext.interface(), Uniform2fv(uni.fFSLocation + offset, ar rayCount, v)); 101 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation + offset, arr ayCount, v));
101 } 102 }
102 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 103 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
103 GR_GL_CALL(fContext.interface(), Uniform2fv(uni.fVSLocation + offset, ar rayCount, v)); 104 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation + offset, arr ayCount, v));
104 } 105 }
105 } 106 }
106 107
107 void GrGLUniformManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, GrGL float v2) const { 108 void GrGLUniformManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, GrGL float v2) const {
108 const Uniform& uni = fUniforms[u.toUniformIndex()]; 109 const Uniform& uni = fUniforms[u.toUniformIndex()];
109 SkASSERT(uni.fType == kVec3f_GrSLType); 110 SkASSERT(uni.fType == kVec3f_GrSLType);
110 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); 111 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
111 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion); 112 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion);
112 if (kUnusedUniform != uni.fFSLocation) { 113 if (kUnusedUniform != uni.fFSLocation) {
113 GR_GL_CALL(fContext.interface(), Uniform3f(uni.fFSLocation, v0, v1, v2)) ; 114 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2));
114 } 115 }
115 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 116 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
116 GR_GL_CALL(fContext.interface(), Uniform3f(uni.fVSLocation, v0, v1, v2)) ; 117 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2));
117 } 118 }
118 } 119 }
119 120
120 void GrGLUniformManager::set3fv(UniformHandle u, 121 void GrGLUniformManager::set3fv(UniformHandle u,
121 int offset, 122 int offset,
122 int arrayCount, 123 int arrayCount,
123 const GrGLfloat v[]) const { 124 const GrGLfloat v[]) const {
124 const Uniform& uni = fUniforms[u.toUniformIndex()]; 125 const Uniform& uni = fUniforms[u.toUniformIndex()];
125 SkASSERT(uni.fType == kVec3f_GrSLType); 126 SkASSERT(uni.fType == kVec3f_GrSLType);
126 SkASSERT(arrayCount > 0); 127 SkASSERT(arrayCount > 0);
127 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount); 128 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
128 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion); 129 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion);
129 if (kUnusedUniform != uni.fFSLocation) { 130 if (kUnusedUniform != uni.fFSLocation) {
130 GR_GL_CALL(fContext.interface(), Uniform3fv(uni.fFSLocation + offset, ar rayCount, v)); 131 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation + offset, arr ayCount, v));
131 } 132 }
132 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 133 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
133 GR_GL_CALL(fContext.interface(), Uniform3fv(uni.fVSLocation + offset, ar rayCount, v)); 134 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation + offset, arr ayCount, v));
134 } 135 }
135 } 136 }
136 137
137 void GrGLUniformManager::set4f(UniformHandle u, 138 void GrGLUniformManager::set4f(UniformHandle u,
138 GrGLfloat v0, 139 GrGLfloat v0,
139 GrGLfloat v1, 140 GrGLfloat v1,
140 GrGLfloat v2, 141 GrGLfloat v2,
141 GrGLfloat v3) const { 142 GrGLfloat v3) const {
142 const Uniform& uni = fUniforms[u.toUniformIndex()]; 143 const Uniform& uni = fUniforms[u.toUniformIndex()];
143 SkASSERT(uni.fType == kVec4f_GrSLType); 144 SkASSERT(uni.fType == kVec4f_GrSLType);
144 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); 145 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
145 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion); 146 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion);
146 if (kUnusedUniform != uni.fFSLocation) { 147 if (kUnusedUniform != uni.fFSLocation) {
147 GR_GL_CALL(fContext.interface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v3)); 148 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v 3));
148 } 149 }
149 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 150 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
150 GR_GL_CALL(fContext.interface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v3)); 151 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v 3));
151 } 152 }
152 } 153 }
153 154
154 void GrGLUniformManager::set4fv(UniformHandle u, 155 void GrGLUniformManager::set4fv(UniformHandle u,
155 int offset, 156 int offset,
156 int arrayCount, 157 int arrayCount,
157 const GrGLfloat v[]) const { 158 const GrGLfloat v[]) const {
158 const Uniform& uni = fUniforms[u.toUniformIndex()]; 159 const Uniform& uni = fUniforms[u.toUniformIndex()];
159 SkASSERT(uni.fType == kVec4f_GrSLType); 160 SkASSERT(uni.fType == kVec4f_GrSLType);
160 SkASSERT(arrayCount > 0); 161 SkASSERT(arrayCount > 0);
161 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion); 162 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion);
162 if (kUnusedUniform != uni.fFSLocation) { 163 if (kUnusedUniform != uni.fFSLocation) {
163 GR_GL_CALL(fContext.interface(), Uniform4fv(uni.fFSLocation + offset, ar rayCount, v)); 164 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation + offset, arr ayCount, v));
164 } 165 }
165 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 166 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
166 GR_GL_CALL(fContext.interface(), Uniform4fv(uni.fVSLocation + offset, ar rayCount, v)); 167 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation + offset, arr ayCount, v));
167 } 168 }
168 } 169 }
169 170
170 void GrGLUniformManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix[]) const { 171 void GrGLUniformManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix[]) const {
171 const Uniform& uni = fUniforms[u.toUniformIndex()]; 172 const Uniform& uni = fUniforms[u.toUniformIndex()];
172 SkASSERT(uni.fType == kMat33f_GrSLType); 173 SkASSERT(uni.fType == kMat33f_GrSLType);
173 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); 174 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
174 // TODO: Re-enable this assert once texture matrices aren't forced on all ef fects 175 // TODO: Re-enable this assert once texture matrices aren't forced on all ef fects
175 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo cation); 176 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLo cation);
176 if (kUnusedUniform != uni.fFSLocation) { 177 if (kUnusedUniform != uni.fFSLocation) {
177 GR_GL_CALL(fContext.interface(), UniformMatrix3fv(uni.fFSLocation, 1, fa lse, matrix)); 178 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, fal se, matrix));
178 } 179 }
179 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 180 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
180 GR_GL_CALL(fContext.interface(), UniformMatrix3fv(uni.fVSLocation, 1, fa lse, matrix)); 181 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, fal se, matrix));
181 } 182 }
182 } 183 }
183 184
184 void GrGLUniformManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[]) const { 185 void GrGLUniformManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[]) const {
185 const Uniform& uni = fUniforms[u.toUniformIndex()]; 186 const Uniform& uni = fUniforms[u.toUniformIndex()];
186 SkASSERT(uni.fType == kMat44f_GrSLType); 187 SkASSERT(uni.fType == kMat44f_GrSLType);
187 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount); 188 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
188 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion); 189 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion);
189 if (kUnusedUniform != uni.fFSLocation) { 190 if (kUnusedUniform != uni.fFSLocation) {
190 GR_GL_CALL(fContext.interface(), UniformMatrix4fv(uni.fFSLocation, 1, fa lse, matrix)); 191 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, fal se, matrix));
191 } 192 }
192 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 193 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
193 GR_GL_CALL(fContext.interface(), UniformMatrix4fv(uni.fVSLocation, 1, fa lse, matrix)); 194 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, fal se, matrix));
194 } 195 }
195 } 196 }
196 197
197 void GrGLUniformManager::setMatrix3fv(UniformHandle u, 198 void GrGLUniformManager::setMatrix3fv(UniformHandle u,
198 int offset, 199 int offset,
199 int arrayCount, 200 int arrayCount,
200 const GrGLfloat matrices[]) const { 201 const GrGLfloat matrices[]) const {
201 const Uniform& uni = fUniforms[u.toUniformIndex()]; 202 const Uniform& uni = fUniforms[u.toUniformIndex()];
202 SkASSERT(uni.fType == kMat33f_GrSLType); 203 SkASSERT(uni.fType == kMat33f_GrSLType);
203 SkASSERT(arrayCount > 0); 204 SkASSERT(arrayCount > 0);
204 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount); 205 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
205 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion); 206 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion);
206 if (kUnusedUniform != uni.fFSLocation) { 207 if (kUnusedUniform != uni.fFSLocation) {
207 GR_GL_CALL(fContext.interface(), 208 GR_GL_CALL(fGpu->glInterface(),
208 UniformMatrix3fv(uni.fFSLocation + offset, arrayCount, false, matrices)); 209 UniformMatrix3fv(uni.fFSLocation + offset, arrayCount, false, matrices));
209 } 210 }
210 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 211 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
211 GR_GL_CALL(fContext.interface(), 212 GR_GL_CALL(fGpu->glInterface(),
212 UniformMatrix3fv(uni.fVSLocation + offset, arrayCount, false, matrices)); 213 UniformMatrix3fv(uni.fVSLocation + offset, arrayCount, false, matrices));
213 } 214 }
214 } 215 }
215 216
216 void GrGLUniformManager::setMatrix4fv(UniformHandle u, 217 void GrGLUniformManager::setMatrix4fv(UniformHandle u,
217 int offset, 218 int offset,
218 int arrayCount, 219 int arrayCount,
219 const GrGLfloat matrices[]) const { 220 const GrGLfloat matrices[]) const {
220 const Uniform& uni = fUniforms[u.toUniformIndex()]; 221 const Uniform& uni = fUniforms[u.toUniformIndex()];
221 SkASSERT(uni.fType == kMat44f_GrSLType); 222 SkASSERT(uni.fType == kMat44f_GrSLType);
222 SkASSERT(arrayCount > 0); 223 SkASSERT(arrayCount > 0);
223 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount); 224 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, offset, arrayCount);
224 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion); 225 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocat ion);
225 if (kUnusedUniform != uni.fFSLocation) { 226 if (kUnusedUniform != uni.fFSLocation) {
226 GR_GL_CALL(fContext.interface(), 227 GR_GL_CALL(fGpu->glInterface(),
227 UniformMatrix4fv(uni.fFSLocation + offset, arrayCount, false, matrices)); 228 UniformMatrix4fv(uni.fFSLocation + offset, arrayCount, false, matrices));
228 } 229 }
229 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) { 230 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
230 GR_GL_CALL(fContext.interface(), 231 GR_GL_CALL(fGpu->glInterface(),
231 UniformMatrix4fv(uni.fVSLocation + offset, arrayCount, false, matrices)); 232 UniformMatrix4fv(uni.fVSLocation + offset, arrayCount, false, matrices));
232 } 233 }
233 } 234 }
234 235
235 void GrGLUniformManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) co nst { 236 void GrGLUniformManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) co nst {
236 // GR_STATIC_ASSERT(SK_SCALAR_IS_FLOAT); 237 // GR_STATIC_ASSERT(SK_SCALAR_IS_FLOAT);
237 GrGLfloat mt[] = { 238 GrGLfloat mt[] = {
238 matrix.get(SkMatrix::kMScaleX), 239 matrix.get(SkMatrix::kMScaleX),
239 matrix.get(SkMatrix::kMSkewY), 240 matrix.get(SkMatrix::kMSkewY),
240 matrix.get(SkMatrix::kMPersp0), 241 matrix.get(SkMatrix::kMPersp0),
241 matrix.get(SkMatrix::kMSkewX), 242 matrix.get(SkMatrix::kMSkewX),
242 matrix.get(SkMatrix::kMScaleY), 243 matrix.get(SkMatrix::kMScaleY),
243 matrix.get(SkMatrix::kMPersp1), 244 matrix.get(SkMatrix::kMPersp1),
244 matrix.get(SkMatrix::kMTransX), 245 matrix.get(SkMatrix::kMTransX),
245 matrix.get(SkMatrix::kMTransY), 246 matrix.get(SkMatrix::kMTransY),
246 matrix.get(SkMatrix::kMPersp2), 247 matrix.get(SkMatrix::kMPersp2),
247 }; 248 };
248 this->setMatrix3f(u, mt); 249 this->setMatrix3f(u, mt);
249 } 250 }
250 251
251 252
252 void GrGLUniformManager::getUniformLocations(GrGLuint programID, const BuilderUn iformArray& uniforms) { 253 void GrGLUniformManager::getUniformLocations(GrGLuint programID, const BuilderUn iformArray& uniforms) {
253 SkASSERT(uniforms.count() == fUniforms.count()); 254 SkASSERT(uniforms.count() == fUniforms.count());
254 int count = fUniforms.count(); 255 int count = fUniforms.count();
255 for (int i = 0; i < count; ++i) { 256 for (int i = 0; i < count; ++i) {
256 SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType); 257 SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType);
257 SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCou nt); 258 SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCou nt);
258 GrGLint location; 259 GrGLint location;
259 // TODO: Move the Xoom uniform array in both FS and VS bug workaround he re. 260 // TODO: Move the Xoom uniform array in both FS and VS bug workaround he re.
260 GR_GL_CALL_RET(fContext.interface(), location, 261 GR_GL_CALL_RET(fGpu->glInterface(), location,
261 GetUniformLocation(programID, uniforms[i].fVariable.c_str ())); 262 GetUniformLocation(programID, uniforms[i].fVariable.c_str ()));
262 if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) { 263 if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) {
263 fUniforms[i].fVSLocation = location; 264 fUniforms[i].fVSLocation = location;
264 } 265 }
265 if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) { 266 if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) {
266 fUniforms[i].fFSLocation = location; 267 fUniforms[i].fFSLocation = location;
267 } 268 }
268 } 269 }
269 } 270 }
270 271
271 const GrGLUniformManager::BuilderUniform& 272 const GrGLUniformManager::BuilderUniform&
272 GrGLUniformManager::getBuilderUniform(const BuilderUniformArray& array, UniformH andle handle) const { 273 GrGLUniformManager::getBuilderUniform(const BuilderUniformArray& array, UniformH andle handle) const {
273 return array[handle.toUniformIndex()]; 274 return array[handle.toUniformIndex()];
274 } 275 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLUniformManager.h ('k') | src/gpu/gl/GrGpuGL.h » ('j') | src/gpu/gl/GrGpuGL.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698