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