OLD | NEW |
---|---|
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" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 *outName = uni.fVariable.c_str(); | 251 *outName = uni.fVariable.c_str(); |
252 } | 252 } |
253 | 253 |
254 return h; | 254 return h; |
255 } | 255 } |
256 | 256 |
257 const GrGLShaderVar& GrGLShaderBuilder::getUniformVariable(UniformHandle u) cons t { | 257 const GrGLShaderVar& GrGLShaderBuilder::getUniformVariable(UniformHandle u) cons t { |
258 return fUniforms[handle_to_index(u)].fVariable; | 258 return fUniforms[handle_to_index(u)].fVariable; |
259 } | 259 } |
260 | 260 |
261 bool GrGLShaderBuilder::addAttribute(GrSLType type, | |
262 const char* name) { | |
263 for (int i = 0; i < fVSAttrs.count(); ++i) { | |
264 const GrGLShaderVar& attr = fVSAttrs[i]; | |
265 // if attribute already added, don't add it again | |
266 if (attr.getName().equals(name)) { | |
267 GrAssert(attr.getType() == type); | |
268 return false; | |
269 } | |
270 } | |
271 fVSAttrs.push_back().set(type, | |
272 GrGLShaderVar::kAttribute_TypeModifier, | |
273 name); | |
274 return true; | |
275 } | |
276 | |
261 void GrGLShaderBuilder::addVarying(GrSLType type, | 277 void GrGLShaderBuilder::addVarying(GrSLType type, |
262 const char* name, | 278 const char* name, |
263 const char** vsOutName, | 279 const char** vsOutName, |
264 const char** fsInName) { | 280 const char** fsInName) { |
265 fVSOutputs.push_back(); | 281 fVSOutputs.push_back(); |
266 fVSOutputs.back().setType(type); | 282 fVSOutputs.back().setType(type); |
267 fVSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier); | 283 fVSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier); |
268 if (kNonStageIdx == fCurrentStageIdx) { | 284 if (kNonStageIdx == fCurrentStageIdx) { |
269 fVSOutputs.back().accessName()->printf("v%s", name); | 285 fVSOutputs.back().accessName()->printf("v%s", name); |
270 } else { | 286 } else { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 | 498 |
483 const GrEffectRef& effect = *stage.getEffect(); | 499 const GrEffectRef& effect = *stage.getEffect(); |
484 int numTextures = effect->numTextures(); | 500 int numTextures = effect->numTextures(); |
485 SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers; | 501 SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers; |
486 textureSamplers.push_back_n(numTextures); | 502 textureSamplers.push_back_n(numTextures); |
487 for (int i = 0; i < numTextures; ++i) { | 503 for (int i = 0; i < numTextures; ++i) { |
488 textureSamplers[i].init(this, &effect->textureAccess(i), i); | 504 textureSamplers[i].init(this, &effect->textureAccess(i), i); |
489 samplerHandles->push_back(textureSamplers[i].fSamplerUniform); | 505 samplerHandles->push_back(textureSamplers[i].fSamplerUniform); |
490 } | 506 } |
491 | 507 |
508 int numAttributes = stage.getVertexAttribIndexCount(); | |
509 const int* attributeIndices = stage.getVertexAttribIndices(); | |
510 SkSTArray<GrEffect::kMaxVertexAttribs, SkString> attributeNames; | |
511 for (int i = 0; i < numAttributes; ++i) { | |
512 SkString attributeName("aAttr"); | |
bsalomon
2013/03/08 18:27:20
I was thinking the prepend should be done in addAt
| |
513 attributeName.appendS32(attributeIndices[i]); | |
514 | |
515 if (this->addAttribute(effect->vertexAttribType(i), attributeName.c_str( ))) { | |
516 fEffectAttributes.push_back().set(attributeIndices[i], attributeName ); | |
517 } | |
518 } | |
519 | |
492 GrGLEffect* glEffect = effect->getFactory().createGLInstance(effect); | 520 GrGLEffect* glEffect = effect->getFactory().createGLInstance(effect); |
493 | 521 |
494 // Enclose custom code in a block to avoid namespace conflicts | 522 // Enclose custom code in a block to avoid namespace conflicts |
495 this->fVSCode.appendf("\t{ // %s\n", glEffect->name()); | 523 this->fVSCode.appendf("\t{ // %s\n", glEffect->name()); |
496 this->fFSCode.appendf("\t{ // %s \n", glEffect->name()); | 524 this->fFSCode.appendf("\t{ // %s \n", glEffect->name()); |
497 glEffect->emitCode(this, | 525 glEffect->emitCode(this, |
498 stage, | 526 stage, |
499 key, | 527 key, |
500 vsInCoord, | 528 vsInCoord, |
501 fsOutColor, | 529 fsOutColor, |
502 fsInColor, | 530 fsInColor, |
503 textureSamplers); | 531 textureSamplers); |
504 this->fVSCode.appendf("\t}\n"); | 532 this->fVSCode.appendf("\t}\n"); |
505 this->fFSCode.appendf("\t}\n"); | 533 this->fFSCode.appendf("\t}\n"); |
506 | 534 |
507 return glEffect; | 535 return glEffect; |
508 } | 536 } |
537 | |
538 const SkString* GrGLShaderBuilder::getEffectAttributeName(int attributeIndex) co nst { | |
539 const AttributePair* attribEnd = this->getEffectAttributes().end(); | |
540 for (const AttributePair* attrib = this->getEffectAttributes().begin(); | |
541 attrib != attribEnd; | |
542 ++attrib) { | |
543 if (attrib->fIndex == attributeIndex) { | |
544 return &attrib->fName; | |
545 } | |
546 } | |
547 | |
548 return NULL; | |
549 } | |
OLD | NEW |