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

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

Issue 23018003: Rename GrGLUniformManager to GrGLUniform and ref GrGLUniforms directly Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 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
« no previous file with comments | « src/gpu/gl/GrGLUniform.h ('k') | src/gpu/gl/GrGLUniformHandle.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 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 #include "gl/GrGLShaderBuilder.h"
9 #include "gl/GrGLProgram.h"
10 #include "SkMatrix.h"
11
12 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(OFFSET, COUNT) \
13 GrAssert(offset + arrayCount <= fArrayCount || \
14 (0 == offset && 1 == arrayCount && GrGLShaderVar::kNonArray == fArrayCount))
15
16 void GrGLUniform::initLocations(const GrGLContext& context, GrGLuint programID, const char* name, uint32_t visibility) {
17 GrGLint location;
18 // TODO: Move the Xoom uniform array in both FS and VS bug workaround here.
19 GR_GL_CALL_RET(context.interface(), location, GetUniformLocation(programID, name));
20 if (GrGLShaderBuilder::kVertex_ShaderType & visibility) {
21 fVSLocation = location;
22 }
23 if (GrGLShaderBuilder::kFragment_ShaderType & visibility) {
24 fFSLocation = location;
25 }
26 }
27
28 void GrGLUniform::setSampler(const GrGLContext& context, GrGLint texUnit) const {
29 GrAssert(fType == kSampler2D_GrSLType);
30 GrAssert(GrGLShaderVar::kNonArray == fArrayCount);
31 // FIXME: We still insert a single sampler uniform for every stage. If the s hader does not
32 // reference the sampler then the compiler may have optimized it out. Uncomm ent this assert
33 // once stages insert their own samplers.
34 // GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
35 if (kUnusedUniform != fFSLocation) {
36 GR_GL_CALL(context.interface(), Uniform1i(fFSLocation, texUnit));
37 }
38 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
39 GR_GL_CALL(context.interface(), Uniform1i(fVSLocation, texUnit));
40 }
41 }
42
43 void GrGLUniform::set1f(const GrGLContext& context, GrGLfloat v0) const {
44 GrAssert(fType == kFloat_GrSLType);
45 GrAssert(GrGLShaderVar::kNonArray == fArrayCount);
46 GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
47 if (kUnusedUniform != fFSLocation) {
48 GR_GL_CALL(context.interface(), Uniform1f(fFSLocation, v0));
49 }
50 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
51 GR_GL_CALL(context.interface(), Uniform1f(fVSLocation, v0));
52 }
53 }
54
55 void GrGLUniform::set1fv(const GrGLContext& context,
56 int offset,
57 int arrayCount,
58 const GrGLfloat v[]) const {
59 GrAssert(fType == kFloat_GrSLType);
60 GrAssert(arrayCount > 0);
61 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(offset, arrayCount);
62 // This assert fires in some instances of the two-pt gradient for its VSPara ms.
63 // Once the uniform is responsible for inserting the duplicate uniform
64 // arrays in VS and FS driver bug workaround, this can be enabled.
65 //GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
66 if (kUnusedUniform != fFSLocation) {
67 GR_GL_CALL(context.interface(), Uniform1fv(fFSLocation + offset, arrayCo unt, v));
68 }
69 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
70 GR_GL_CALL(context.interface(), Uniform1fv(fVSLocation + offset, arrayCo unt, v));
71 }
72 }
73
74 void GrGLUniform::set2f(const GrGLContext& context, GrGLfloat v0, GrGLfloat v1) const {
75 GrAssert(fType == kVec2f_GrSLType);
76 GrAssert(GrGLShaderVar::kNonArray == fArrayCount);
77 GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
78 if (kUnusedUniform != fFSLocation) {
79 GR_GL_CALL(context.interface(), Uniform2f(fFSLocation, v0, v1));
80 }
81 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
82 GR_GL_CALL(context.interface(), Uniform2f(fVSLocation, v0, v1));
83 }
84 }
85
86 void GrGLUniform::set2fv(const GrGLContext& context,
87 int offset,
88 int arrayCount,
89 const GrGLfloat v[]) const {
90 GrAssert(fType == kVec2f_GrSLType);
91 GrAssert(arrayCount > 0);
92 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(offset, arrayCount);
93 GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
94 if (kUnusedUniform != fFSLocation) {
95 GR_GL_CALL(context.interface(), Uniform2fv(fFSLocation + offset, arrayCo unt, v));
96 }
97 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
98 GR_GL_CALL(context.interface(), Uniform2fv(fVSLocation + offset, arrayCo unt, v));
99 }
100 }
101
102 void GrGLUniform::set3f(const GrGLContext& context, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2) const {
103 GrAssert(fType == kVec3f_GrSLType);
104 GrAssert(GrGLShaderVar::kNonArray == fArrayCount);
105 GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
106 if (kUnusedUniform != fFSLocation) {
107 GR_GL_CALL(context.interface(), Uniform3f(fFSLocation, v0, v1, v2));
108 }
109 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
110 GR_GL_CALL(context.interface(), Uniform3f(fVSLocation, v0, v1, v2));
111 }
112 }
113
114 void GrGLUniform::set3fv(const GrGLContext& context,
115 int offset,
116 int arrayCount,
117 const GrGLfloat v[]) const {
118 GrAssert(fType == kVec3f_GrSLType);
119 GrAssert(arrayCount > 0);
120 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(offset, arrayCount);
121 GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
122 if (kUnusedUniform != fFSLocation) {
123 GR_GL_CALL(context.interface(), Uniform3fv(fFSLocation + offset, arrayCo unt, v));
124 }
125 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
126 GR_GL_CALL(context.interface(), Uniform3fv(fVSLocation + offset, arrayCo unt, v));
127 }
128 }
129
130 void GrGLUniform::set4f(const GrGLContext& context,
131 GrGLfloat v0,
132 GrGLfloat v1,
133 GrGLfloat v2,
134 GrGLfloat v3) const {
135 GrAssert(fType == kVec4f_GrSLType);
136 GrAssert(GrGLShaderVar::kNonArray == fArrayCount);
137 GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
138 if (kUnusedUniform != fFSLocation) {
139 GR_GL_CALL(context.interface(), Uniform4f(fFSLocation, v0, v1, v2, v3));
140 }
141 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
142 GR_GL_CALL(context.interface(), Uniform4f(fVSLocation, v0, v1, v2, v3));
143 }
144 }
145
146 void GrGLUniform::set4fv(const GrGLContext& context,
147 int offset,
148 int arrayCount,
149 const GrGLfloat v[]) const {
150 GrAssert(fType == kVec4f_GrSLType);
151 GrAssert(arrayCount > 0);
152 GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
153 if (kUnusedUniform != fFSLocation) {
154 GR_GL_CALL(context.interface(), Uniform4fv(fFSLocation + offset, arrayCo unt, v));
155 }
156 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
157 GR_GL_CALL(context.interface(), Uniform4fv(fVSLocation + offset, arrayCo unt, v));
158 }
159 }
160
161 void GrGLUniform::setMatrix3f(const GrGLContext& context, const GrGLfloat matrix []) const {
162 GrAssert(fType == kMat33f_GrSLType);
163 GrAssert(GrGLShaderVar::kNonArray == fArrayCount);
164 // TODO: Re-enable this assert once texture matrices aren't forced on all ef fects
165 // GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
166 if (kUnusedUniform != fFSLocation) {
167 GR_GL_CALL(context.interface(), UniformMatrix3fv(fFSLocation, 1, false, matrix));
168 }
169 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
170 GR_GL_CALL(context.interface(), UniformMatrix3fv(fVSLocation, 1, false, matrix));
171 }
172 }
173
174 void GrGLUniform::setMatrix4f(const GrGLContext& context, const GrGLfloat matrix []) const {
175 GrAssert(fType == kMat44f_GrSLType);
176 GrAssert(GrGLShaderVar::kNonArray == fArrayCount);
177 GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
178 if (kUnusedUniform != fFSLocation) {
179 GR_GL_CALL(context.interface(), UniformMatrix4fv(fFSLocation, 1, false, matrix));
180 }
181 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
182 GR_GL_CALL(context.interface(), UniformMatrix4fv(fVSLocation, 1, false, matrix));
183 }
184 }
185
186 void GrGLUniform::setMatrix3fv(const GrGLContext& context,
187 int offset,
188 int arrayCount,
189 const GrGLfloat matrices[]) const {
190 GrAssert(fType == kMat33f_GrSLType);
191 GrAssert(arrayCount > 0);
192 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(offset, arrayCount);
193 GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
194 if (kUnusedUniform != fFSLocation) {
195 GR_GL_CALL(context.interface(),
196 UniformMatrix3fv(fFSLocation + offset, arrayCount, false, mat rices));
197 }
198 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
199 GR_GL_CALL(context.interface(),
200 UniformMatrix3fv(fVSLocation + offset, arrayCount, false, mat rices));
201 }
202 }
203
204 void GrGLUniform::setMatrix4fv(const GrGLContext& context,
205 int offset,
206 int arrayCount,
207 const GrGLfloat matrices[]) const {
208 GrAssert(fType == kMat44f_GrSLType);
209 GrAssert(arrayCount > 0);
210 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(offset, arrayCount);
211 GrAssert(kUnusedUniform != fFSLocation || kUnusedUniform != fVSLocation);
212 if (kUnusedUniform != fFSLocation) {
213 GR_GL_CALL(context.interface(),
214 UniformMatrix4fv(fFSLocation + offset, arrayCount, false, mat rices));
215 }
216 if (kUnusedUniform != fVSLocation && fVSLocation != fFSLocation) {
217 GR_GL_CALL(context.interface(),
218 UniformMatrix4fv(fVSLocation + offset, arrayCount, false, mat rices));
219 }
220 }
221
222 void GrGLUniform::setSkMatrix(const GrGLContext& context, const SkMatrix& matrix ) const {
223 // GR_STATIC_ASSERT(SK_SCALAR_IS_FLOAT);
224 GrGLfloat mt[] = {
225 matrix.get(SkMatrix::kMScaleX),
226 matrix.get(SkMatrix::kMSkewY),
227 matrix.get(SkMatrix::kMPersp0),
228 matrix.get(SkMatrix::kMSkewX),
229 matrix.get(SkMatrix::kMScaleY),
230 matrix.get(SkMatrix::kMPersp1),
231 matrix.get(SkMatrix::kMTransX),
232 matrix.get(SkMatrix::kMTransY),
233 matrix.get(SkMatrix::kMPersp2),
234 };
235 this->setMatrix3f(context, mt);
236 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLUniform.h ('k') | src/gpu/gl/GrGLUniformHandle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698