OLD | NEW |
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(fProgramBuilder->gpu()->glInterface(), X) | 13 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) |
14 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(),
R, X) | 14 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(),
R, X) |
15 | 15 |
16 static const char* color_attribute_name() { return "inColor"; } | 16 static const char* color_attribute_name() { return "inColor"; } |
17 static const char* coverage_attribute_name() { return "inCoverage"; } | 17 static const char* coverage_attribute_name() { return "inCoverage"; } |
18 | 18 |
19 GrGLVertexBuilder::GrGLVertexBuilder(GrGLProgramBuilder* program) | 19 GrGLVertexBuilder::GrGLVertexBuilder(GrGLProgramBuilder* program) |
20 : INHERITED(program) | 20 : INHERITED(program) |
21 , fPositionVar(NULL) | 21 , fPositionVar(NULL) |
22 , fLocalCoordsVar(NULL) | 22 , fLocalCoordsVar(NULL) |
23 , fEffectAttribOffset(0) { | 23 , fEffectAttribOffset(0) { |
24 } | 24 } |
25 | 25 |
26 void GrGLVertexBuilder::addVarying(const char* name, GrGLVarying* v) { | 26 SkString* GrGLVertexBuilder::addVarying(GrSLType type, const char* name, |
| 27 const char** vsOutName) { |
27 fOutputs.push_back(); | 28 fOutputs.push_back(); |
28 fOutputs.back().setType(v->fType); | 29 fOutputs.back().setType(type); |
29 fOutputs.back().setTypeModifier(GrGLShaderVar::kVaryingOut_TypeModifier); | 30 fOutputs.back().setTypeModifier(GrGLShaderVar::kVaryingOut_TypeModifier); |
30 fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'v', name); | 31 fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'v', name); |
31 v->fVsOut = fOutputs.back().getName().c_str(); | 32 |
| 33 if (vsOutName) { |
| 34 *vsOutName = fOutputs.back().getName().c_str(); |
| 35 } |
| 36 return fOutputs.back().accessName(); |
32 } | 37 } |
33 | 38 |
34 void GrGLVertexBuilder::setupLocalCoords() { | 39 void GrGLVertexBuilder::setupLocalCoords() { |
35 fPositionVar = &fInputs.push_back(); | 40 fPositionVar = &fInputs.push_back(); |
36 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "
inPosition"); | 41 fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "
inPosition"); |
37 if (-1 != fProgramBuilder->header().fLocalCoordAttributeIndex) { | 42 if (-1 != fProgramBuilder->header().fLocalCoordAttributeIndex) { |
38 fLocalCoordsVar = &fInputs.push_back(); | 43 fLocalCoordsVar = &fInputs.push_back(); |
39 fLocalCoordsVar->set(kVec2f_GrSLType, | 44 fLocalCoordsVar->set(kVec2f_GrSLType, |
40 GrGLShaderVar::kAttribute_TypeModifier, | 45 GrGLShaderVar::kAttribute_TypeModifier, |
41 "inLocalCoords"); | 46 "inLocalCoords"); |
42 } else { | 47 } else { |
43 fLocalCoordsVar = fPositionVar; | 48 fLocalCoordsVar = fPositionVar; |
44 } | 49 } |
45 fEffectAttribOffset = fInputs.count(); | 50 fEffectAttribOffset = fInputs.count(); |
46 } | 51 } |
47 | 52 |
48 void GrGLVertexBuilder::transformGLToSkiaCoords() { | 53 void GrGLVertexBuilder::transformGLToSkiaCoords() { |
49 const char* viewMName; | 54 const char* viewMName; |
50 fProgramBuilder->fUniformHandles.fViewMatrixUni = | 55 fProgramBuilder->fUniformHandles.fViewMatrixUni = |
51 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, | 56 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, |
52 kMat33f_GrSLType, | 57 kMat33f_GrSLType, |
53 "ViewM", | 58 "ViewM", |
54 &viewMName); | 59 &viewMName); |
55 | 60 |
56 // Transform the position into Skia's device coords. | 61 // Transform the position into Skia's device coords. |
57 this->codeAppendf("vec3 pos3 = %s * vec3(%s, 1);", viewMName, fPositionVar->
c_str()); | 62 this->codeAppendf("vec3 pos3 = %s * vec3(%s, 1);", viewMName, fPositionVar->
c_str()); |
58 } | 63 } |
59 | 64 |
60 void GrGLVertexBuilder::setupBuiltinVertexAttribute(const char* inName, GrGLSLEx
pr4* out) { | 65 void GrGLVertexBuilder::setupBuiltinVertexAttribute(const char* inName, GrGLSLEx
pr4* out) { |
61 GrGLVertToFrag v(kVec4f_GrSLType); | |
62 fProgramBuilder->addVarying(inName, &v); | |
63 SkString name(inName); | 66 SkString name(inName); |
| 67 const char *vsName, *fsName; |
| 68 fProgramBuilder->addVarying(kVec4f_GrSLType, name.c_str(), &vsName, &fsName)
; |
64 name.prepend("in"); | 69 name.prepend("in"); |
65 this->addAttribute(GrShaderVar(name.c_str(), | 70 this->addAttribute(GrShaderVar(name.c_str(), |
66 kVec4f_GrSLType, | 71 kVec4f_GrSLType, |
67 GrShaderVar::kAttribute_TypeModifier)); | 72 GrShaderVar::kAttribute_TypeModifier)); |
68 this->codeAppendf("%s = %s;", v.vsOut(), name.c_str()); | 73 this->codeAppendf("%s = %s;", vsName, name.c_str()); |
69 *out = v.fsIn(); | 74 *out = fsName; |
70 fEffectAttribOffset++; | 75 fEffectAttribOffset++; |
71 } | 76 } |
72 | 77 |
73 void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) { | 78 void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) { |
74 const GrGeometryProcessor::VertexAttribArray& vars = gp.getVertexAttribs(); | 79 const GrGeometryProcessor::VertexAttribArray& vars = gp.getVertexAttribs(); |
75 int numAttributes = vars.count(); | 80 int numAttributes = vars.count(); |
76 for (int a = 0; a < numAttributes; ++a) { | 81 for (int a = 0; a < numAttributes; ++a) { |
77 this->addAttribute(vars[a]); | 82 this->addAttribute(vars[a]); |
78 } | 83 } |
79 } | 84 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 for (int i = 0; i < fInputs.count(); ++i) { | 169 for (int i = 0; i < fInputs.count(); ++i) { |
165 const GrGLShaderVar& attr = fInputs[i]; | 170 const GrGLShaderVar& attr = fInputs[i]; |
166 // if attribute already added, don't add it again | 171 // if attribute already added, don't add it again |
167 if (attr.getName().equals(var.getName())) { | 172 if (attr.getName().equals(var.getName())) { |
168 return false; | 173 return false; |
169 } | 174 } |
170 } | 175 } |
171 fInputs.push_back(var); | 176 fInputs.push_back(var); |
172 return true; | 177 return true; |
173 } | 178 } |
OLD | NEW |