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

Side by Side Diff: tests/GLProgramsTest.cpp

Issue 761563002: First step to moving vertex attributes to the geometryProcessor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: adding test to ignore Created 6 years 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
« no previous file with comments | « src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 // This is a GPU-backend specific test. It relies on static intializers to work 9 // This is a GPU-backend specific test. It relies on static intializers to work
10 10
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 SkAutoTUnref<GrTexture> texture(context->findAndRefTexture(texDesc, cacheId, &params)); 111 SkAutoTUnref<GrTexture> texture(context->findAndRefTexture(texDesc, cacheId, &params));
112 if (!texture) { 112 if (!texture) {
113 texture.reset(context->createTexture(&params, texDesc, cacheId, 0, 0)); 113 texture.reset(context->createTexture(&params, texDesc, cacheId, 0, 0));
114 if (!texture) { 114 if (!texture) {
115 return NULL; 115 return NULL;
116 } 116 }
117 } 117 }
118 return SkRef(texture->asRenderTarget()); 118 return SkRef(texture->asRenderTarget());
119 } 119 }
120 120
121 // TODO clean this up, we have to do this to test geometry processors but there has got to be
122 // a better way. In the mean time, we actually fill out these generic vertex at tribs below with
123 // the correct vertex attribs from the GP. We have to ensure, however, we don't try to add more
124 // than two attributes. In addition, we 'pad' the below array with GPs up to 6 entries, 4 fixed
125 // function vertex attributes and 2 GP custom attributes.
126 GrVertexAttrib kGenericVertexAttribs[] = {
127 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding },
128 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding } ,
129 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding } ,
130 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding } ,
131 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding } ,
132 { kVec2f_GrVertexAttribType, 0, kGeometryProcessor_GrVertexAttribBinding }
133 };
134
135 /*
136 * convert sl type to vertexattrib type, not a complete implementation, only use for debugging
137 */
138 static GrVertexAttribType convert_sltype_to_attribtype(GrSLType type) {
139 switch (type) {
140 case kFloat_GrSLType:
141 return kFloat_GrVertexAttribType;
142 case kVec2f_GrSLType:
143 return kVec2f_GrVertexAttribType;
144 case kVec3f_GrSLType:
145 return kVec3f_GrVertexAttribType;
146 case kVec4f_GrSLType:
147 return kVec4f_GrVertexAttribType;
148 default:
149 SkFAIL("Type isn't convertible");
150 return kFloat_GrVertexAttribType;
151 }
152 }
153 // end test hack
154
155 static void setup_random_ff_attribute(GrVertexAttribBinding binding, GrVertexAtt ribType type,
156 SkRandom* random, int* attribIndex, int* r unningStride) {
157 if (random->nextBool()) {
158 kGenericVertexAttribs[*attribIndex].fType = type;
159 kGenericVertexAttribs[*attribIndex].fOffset = *runningStride;
160 kGenericVertexAttribs[*attribIndex].fBinding = binding;
161 *runningStride += GrVertexAttribTypeSize(kGenericVertexAttribs[(*attribI ndex)++].fType);
162 }
163 }
164
165 static void set_random_gp(GrContext* context, 121 static void set_random_gp(GrContext* context,
166 const GrDrawTargetCaps& caps, 122 const GrDrawTargetCaps& caps,
167 GrDrawState* ds, 123 GrDrawState* ds,
168 SkRandom* random, 124 SkRandom* random,
169 GrTexture* dummyTextures[]) { 125 GrTexture* dummyTextures[]) {
170 SkAutoTUnref<const GrGeometryProcessor> gp( 126 SkAutoTUnref<const GrGeometryProcessor> gp(
171 GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random, 127 GrProcessorTestFactory<GrGeometryProcessor>::CreateStage(random,
172 context, 128 context,
173 caps, 129 caps,
174 dummyTextur es)); 130 dummyTextur es));
175 SkASSERT(gp); 131 SkASSERT(gp);
176 132
177 // we have to set dummy vertex attributes, first we setup the fixed function attributes
178 // always leave the position attribute untouched in the array
179 int attribIndex = 1;
180 int runningStride = GrVertexAttribTypeSize(kGenericVertexAttribs[0].fType);
181
182 // local coords
183 setup_random_ff_attribute(kLocalCoord_GrVertexAttribBinding, kVec2f_GrVertex AttribType,
184 random, &attribIndex, &runningStride);
185
186 // color
187 setup_random_ff_attribute(kColor_GrVertexAttribBinding, kVec4f_GrVertexAttri bType,
188 random, &attribIndex, &runningStride);
189
190 // coverage
191 setup_random_ff_attribute(kCoverage_GrVertexAttribBinding, kUByte_GrVertexAt tribType,
192 random, &attribIndex, &runningStride);
193
194 // Update the geometry processor attributes
195 const GrGeometryProcessor::VertexAttribArray& v = gp->getVertexAttribs();
196 int numGPAttribs = v.count();
197 SkASSERT(numGPAttribs <= GrGeometryProcessor::kMaxVertexAttribs &&
198 GrGeometryProcessor::kMaxVertexAttribs == 2);
199
200 // we actually can't overflow if kMaxVertexAttribs == 2, but GCC 4.8 wants m ore proof
201 int maxIndex = SK_ARRAY_COUNT(kGenericVertexAttribs);
202 for (int i = 0; i < numGPAttribs && i + attribIndex < maxIndex; i++) {
203 kGenericVertexAttribs[i + attribIndex].fType =
204 convert_sltype_to_attribtype(v[i].getType());
205 kGenericVertexAttribs[i + attribIndex].fOffset = runningStride;
206 kGenericVertexAttribs[i + attribIndex].fBinding = kGeometryProcessor_GrV ertexAttribBinding;
207 runningStride += GrVertexAttribTypeSize(kGenericVertexAttribs[i + attrib Index].fType);
208 }
209
210 // update the vertex attributes with the ds
211 ds->setVertexAttribs<kGenericVertexAttribs>(attribIndex + numGPAttribs, runn ingStride);
212 ds->setGeometryProcessor(gp); 133 ds->setGeometryProcessor(gp);
213 } 134 }
214 135
215 static void set_random_color_coverage_stages(GrGpuGL* gpu, 136 static void set_random_color_coverage_stages(GrGpuGL* gpu,
216 GrDrawState* ds, 137 GrDrawState* ds,
217 int maxStages, 138 int maxStages,
218 bool usePathRendering, 139 bool usePathRendering,
219 SkRandom* random, 140 SkRandom* random,
220 GrTexture* dummyTextures[]) { 141 GrTexture* dummyTextures[]) {
221 int numProcs = random->nextULessThan(maxStages + 1); 142 int numProcs = random->nextULessThan(maxStages + 1);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } 429 }
509 #endif 430 #endif
510 GrTestTarget target; 431 GrTestTarget target;
511 context->getTestTarget(&target); 432 context->getTestTarget(&target);
512 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages )); 433 REPORTER_ASSERT(reporter, target.target()->programUnitTest(maxStages ));
513 } 434 }
514 } 435 }
515 } 436 }
516 437
517 #endif 438 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698