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

Side by Side Diff: src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp

Issue 543623004: Removing vertex attrib indices (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: warning fixed 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
« no previous file with comments | « src/gpu/gl/builders/GrGLVertexShaderBuilder.h ('k') | tests/GLProgramsTest.cpp » ('j') | 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 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "GrGLVertexShaderBuilder.h" 8 #include "GrGLVertexShaderBuilder.h"
9 #include "GrGLProgramBuilder.h" 9 #include "GrGLProgramBuilder.h"
10 #include "GrGLShaderStringBuilder.h" 10 #include "GrGLShaderStringBuilder.h"
11 #include "../GrGpuGL.h" 11 #include "../GrGpuGL.h"
12 12
13 #define GL_CALL(X) GR_GL_CALL(gpu->glInterface(), X) 13 #define GL_CALL(X) GR_GL_CALL(gpu->glInterface(), X)
14 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(gpu->glInterface(), R, X) 14 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(gpu->glInterface(), R, X)
15 15
16 namespace { 16 namespace {
17 inline const char* color_attribute_name() { return "aColor"; } 17 inline const char* color_attribute_name() { return "inColor"; }
18 inline const char* coverage_attribute_name() { return "aCoverage"; } 18 inline const char* coverage_attribute_name() { return "inCoverage"; }
19 } 19 }
20 20
21 GrGLVertexShaderBuilder::GrGLVertexShaderBuilder(GrGLFullProgramBuilder* program ) 21 GrGLVertexShaderBuilder::GrGLVertexShaderBuilder(GrGLFullProgramBuilder* program )
22 : INHERITED(program) 22 : INHERITED(program)
23 , fPositionVar(NULL) 23 , fPositionVar(NULL)
24 , fLocalCoordsVar(NULL) { 24 , fLocalCoordsVar(NULL) {
25 } 25 }
26 bool GrGLVertexShaderBuilder::addAttribute(GrSLType type, const char* name) { 26 bool GrGLVertexShaderBuilder::addAttribute(const GrShaderVar& var) {
27 SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier());
27 for (int i = 0; i < fInputs.count(); ++i) { 28 for (int i = 0; i < fInputs.count(); ++i) {
28 const GrGLShaderVar& attr = fInputs[i]; 29 const GrGLShaderVar& attr = fInputs[i];
29 // if attribute already added, don't add it again 30 // if attribute already added, don't add it again
30 if (attr.getName().equals(name)) { 31 if (attr.getName().equals(var.getName())) {
31 return false; 32 return false;
32 } 33 }
33 } 34 }
34 fInputs.push_back().set(type, GrGLShaderVar::kAttribute_TypeModifier, name); 35 fInputs.push_back(var);
35 return true;
36 }
37
38 bool GrGLVertexShaderBuilder::addEffectAttribute(int attributeIndex,
39 GrSLType type,
40 const SkString& name) {
41 if (!this->addAttribute(type, name.c_str())) {
42 return false;
43 }
44
45 fEffectAttributes.push_back().set(attributeIndex, name);
46 return true; 36 return true;
47 } 37 }
48 38
49 void GrGLVertexShaderBuilder::emitAttributes(const GrEffectStage& stage) { 39 void GrGLVertexShaderBuilder::emitAttributes(const GrEffectStage& stage) {
50 int numAttributes = stage.getVertexAttribIndexCount(); 40 const GrEffect& effect = *stage.getEffect();
51 const int* attributeIndices = stage.getVertexAttribIndices(); 41 const GrEffect::VertexAttribArray& vars =
42 effect.getVertexAttribs();
43 int numAttributes = vars.count();
52 for (int a = 0; a < numAttributes; ++a) { 44 for (int a = 0; a < numAttributes; ++a) {
53 // TODO: Make addAttribute mangle the name. 45 this->addAttribute(vars[a]);
54 SkString attributeName("aAttr");
55 attributeName.appendS32(attributeIndices[a]);
56 this->addEffectAttribute(attributeIndices[a],
57 stage.getEffect()->vertexAttribType(a),
58 attributeName);
59 } 46 }
60 } 47 }
61 48
62 const SkString* GrGLVertexShaderBuilder::getEffectAttributeName(int attributeInd ex) const {
63 const AttributePair* attribEnd = fEffectAttributes.end();
64 for (const AttributePair* attrib = fEffectAttributes.begin(); attrib != attr ibEnd; ++attrib) {
65 if (attrib->fIndex == attributeIndex) {
66 return &attrib->fName;
67 }
68 }
69
70 return NULL;
71 }
72
73 void GrGLVertexShaderBuilder::addVarying(GrSLType type, const char* name, const char** vsOutName) { 49 void GrGLVertexShaderBuilder::addVarying(GrSLType type, const char* name, const char** vsOutName) {
74 fOutputs.push_back(); 50 fOutputs.push_back();
75 fOutputs.back().setType(type); 51 fOutputs.back().setType(type);
76 fOutputs.back().setTypeModifier(GrGLShaderVar::kVaryingOut_TypeModifier); 52 fOutputs.back().setTypeModifier(GrGLShaderVar::kVaryingOut_TypeModifier);
77 fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'v', name); 53 fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'v', name);
78 54
79 if (vsOutName) { 55 if (vsOutName) {
80 *vsOutName = fOutputs.back().getName().c_str(); 56 *vsOutName = fOutputs.back().getName().c_str();
81 } 57 }
82 } 58 }
(...skipping 17 matching lines...) Expand all
100 GL_CALL(BindAttribLocation(programId, 76 GL_CALL(BindAttribLocation(programId,
101 header.fColorAttributeIndex, 77 header.fColorAttributeIndex,
102 color_attribute_name())); 78 color_attribute_name()));
103 } 79 }
104 if (-1 != header.fCoverageAttributeIndex) { 80 if (-1 != header.fCoverageAttributeIndex) {
105 GL_CALL(BindAttribLocation(programId, 81 GL_CALL(BindAttribLocation(programId,
106 header.fCoverageAttributeIndex, 82 header.fCoverageAttributeIndex,
107 coverage_attribute_name())); 83 coverage_attribute_name()));
108 } 84 }
109 85
110 const AttributePair* attribEnd = fEffectAttributes.end(); 86 // We pull the current state of attributes off of drawstate and bind them in order
111 for (const AttributePair* attrib = fEffectAttributes.begin(); attrib != attr ibEnd; ++attrib) { 87 const GrRODrawState* ds = fProgramBuilder->gpu()->drawState();
112 GL_CALL(BindAttribLocation(programId, attrib->fIndex, attrib->fName.c_s tr())); 88 const GrVertexAttrib* vaPtr = ds->getVertexAttribs();
89 const int vaCount = ds->getVertexAttribCount();
90
91 int i = fEffectAttribOffset;
92 for (int index = 0; index < vaCount; index++) {
93 if (kEffect_GrVertexAttribBinding != vaPtr[index].fBinding) {
94 continue;
95 }
96 SkASSERT(index != header.fPositionAttributeIndex &&
97 index != header.fLocalCoordAttributeIndex &&
98 index != header.fColorAttributeIndex &&
99 index != header.fCoverageAttributeIndex);
100 // We should never find another effect attribute if we have bound everyt hing
101 SkASSERT(i < fInputs.count());
102 GL_CALL(BindAttribLocation(programId, index, fInputs[i].c_str()));
103 i++;
113 } 104 }
105 // Make sure we bound everything
106 SkASSERT(fInputs.count() == i);
114 } 107 }
115 108
116 bool GrGLVertexShaderBuilder::compileAndAttachShaders(GrGLuint programId, 109 bool GrGLVertexShaderBuilder::compileAndAttachShaders(GrGLuint programId,
117 SkTDArray<GrGLuint>* shaderIds) const { 110 SkTDArray<GrGLuint>* shaderIds) const {
118 GrGpuGL* gpu = fProgramBuilder->gpu(); 111 GrGpuGL* gpu = fProgramBuilder->gpu();
119 const GrGLContext& glCtx = gpu->glContext(); 112 const GrGLContext& glCtx = gpu->glContext();
120 const GrGLContextInfo& ctxInfo = gpu->ctxInfo(); 113 const GrGLContextInfo& ctxInfo = gpu->ctxInfo();
121 SkString vertShaderSrc(GrGetGLSLVersionDecl(ctxInfo)); 114 SkString vertShaderSrc(GrGetGLSLVersionDecl(ctxInfo));
122 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kVertex_Visibility, &vertShaderSrc); 115 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kVertex_Visibility, &vertShaderSrc);
123 fProgramBuilder->appendDecls(fInputs, &vertShaderSrc); 116 fProgramBuilder->appendDecls(fInputs, &vertShaderSrc);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // we output point size in the GS if present 169 // we output point size in the GS if present
177 if (header.fEmitsPointSize 170 if (header.fEmitsPointSize
178 #if GR_GL_EXPERIMENTAL_GS 171 #if GR_GL_EXPERIMENTAL_GS
179 && !header.fExperimentalGS 172 && !header.fExperimentalGS
180 #endif 173 #endif
181 ) { 174 ) {
182 this->codeAppend("\tgl_PointSize = 1.0;\n"); 175 this->codeAppend("\tgl_PointSize = 1.0;\n");
183 } 176 }
184 177
185 if (GrGLProgramDesc::kAttribute_ColorInput == header.fColorInput) { 178 if (GrGLProgramDesc::kAttribute_ColorInput == header.fColorInput) {
186 this->addAttribute(kVec4f_GrSLType, color_attribute_name()); 179 this->addAttribute(GrShaderVar(color_attribute_name(),
180 kVec4f_GrSLType,
181 GrShaderVar::kAttribute_TypeModifier));
187 const char *vsName, *fsName; 182 const char *vsName, *fsName;
188 fFullProgramBuilder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsNa me); 183 fFullProgramBuilder->addVarying(kVec4f_GrSLType, "Color", &vsName, &fsNa me);
189 this->codeAppendf("\t%s = %s;\n", vsName, color_attribute_name()); 184 this->codeAppendf("\t%s = %s;\n", vsName, color_attribute_name());
190 *color = fsName; 185 *color = fsName;
191 } 186 }
192 187
193 if (GrGLProgramDesc::kAttribute_ColorInput == header.fCoverageInput) { 188 if (GrGLProgramDesc::kAttribute_ColorInput == header.fCoverageInput) {
194 this->addAttribute(kVec4f_GrSLType, coverage_attribute_name()); 189 this->addAttribute(GrShaderVar(coverage_attribute_name(),
190 kVec4f_GrSLType,
191 GrShaderVar::kAttribute_TypeModifier));
195 const char *vsName, *fsName; 192 const char *vsName, *fsName;
196 fFullProgramBuilder->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &f sName); 193 fFullProgramBuilder->addVarying(kVec4f_GrSLType, "Coverage", &vsName, &f sName);
197 this->codeAppendf("\t%s = %s;\n", vsName, coverage_attribute_name()); 194 this->codeAppendf("\t%s = %s;\n", vsName, coverage_attribute_name());
198 *coverage = fsName; 195 *coverage = fsName;
199 } 196 }
197 fEffectAttribOffset = fInputs.count();
200 } 198 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLVertexShaderBuilder.h ('k') | tests/GLProgramsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698