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 "../GrGLGpu.h" | 10 #include "../GrGLGpu.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posV
ar) { | 36 void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posV
ar) { |
37 SkASSERT(!fRtAdjustName); | 37 SkASSERT(!fRtAdjustName); |
38 | 38 |
39 // setup RT Uniform | 39 // setup RT Uniform |
40 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = | 40 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = |
41 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, | 41 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, |
42 kVec4f_GrSLType, kDefault_GrSLPrecision, | 42 kVec4f_GrSLType, kDefault_GrSLPrecision, |
43 fProgramBuilder->rtAdjustment(), | 43 fProgramBuilder->rtAdjustment(), |
44 &fRtAdjustName); | 44 &fRtAdjustName); |
45 | 45 if (this->getProgramBuilder()->desc().header().fSnapVerticesToPixelCenters)
{ |
46 // Transform from Skia's device coords to GL's normalized device coords. Not
e that | 46 if (kVec3f_GrSLType == posVar.getType()) { |
47 // because we want to "nudge" the device space positions we are converting t
o | 47 const char* p = posVar.c_str(); |
48 // non-homogeneous NDC. | 48 this->codeAppendf("{vec2 _posTmp = vec2(%s.x/%s.z, %s.y/%s.z);", p,
p, p, p); |
49 if (kVec3f_GrSLType == posVar.getType()) { | 49 } else { |
| 50 SkASSERT(kVec2f_GrSLType == posVar.getType()); |
| 51 this->codeAppendf("{vec2 _posTmp = %s;", posVar.c_str()); |
| 52 } |
| 53 this->codeAppendf("_posTmp = floor(_posTmp) + vec2(0.5, 0.5);" |
| 54 "gl_Position = vec4(_posTmp.x * %s.x + %s.y, _posTmp.y
* %s.z + %s.w, 0, 1);}", |
| 55 fRtAdjustName, fRtAdjustName, fRtAdjustName, fRtAdjust
Name); |
| 56 } else if (kVec3f_GrSLType == posVar.getType()) { |
50 this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy)/%s.z, dot(%s.yz,
%s.zw)/%s.z, 0, 1);", | 57 this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy)/%s.z, dot(%s.yz,
%s.zw)/%s.z, 0, 1);", |
51 posVar.c_str(), fRtAdjustName, posVar.c_str(), | 58 posVar.c_str(), fRtAdjustName, posVar.c_str(), |
52 posVar.c_str(), fRtAdjustName, posVar.c_str()); | 59 posVar.c_str(), fRtAdjustName, posVar.c_str()); |
53 } else { | 60 } else { |
54 SkASSERT(kVec2f_GrSLType == posVar.getType()); | 61 SkASSERT(kVec2f_GrSLType == posVar.getType()); |
55 this->codeAppendf("gl_Position = vec4(%s.x * %s.x + %s.y, %s.y * %s.z +
%s.w, 0, 1);", | 62 this->codeAppendf("gl_Position = vec4(%s.x * %s.x + %s.y, %s.y * %s.z +
%s.w, 0, 1);", |
56 posVar.c_str(), fRtAdjustName, fRtAdjustName, | 63 posVar.c_str(), fRtAdjustName, fRtAdjustName, |
57 posVar.c_str(), fRtAdjustName, fRtAdjustName); | 64 posVar.c_str(), fRtAdjustName, fRtAdjustName); |
58 } | 65 } |
59 | 66 // We could have the GrGeometryProcessor do this, but its just easier to hav
e it performed |
60 // We could have the GrGeometryProcessor do this, but its just easier to hav
e it performed here. | 67 // here. If we ever need to set variable pointsize, then we can reinvestigat
e |
61 // If we ever need to set variable pointsize, then we can reinvestigate | |
62 this->codeAppend("gl_PointSize = 1.0;"); | 68 this->codeAppend("gl_PointSize = 1.0;"); |
63 } | 69 } |
64 | 70 |
65 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { | 71 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { |
66 const GrPrimitiveProcessor& primProc = fProgramBuilder->primitiveProcessor()
; | 72 const GrPrimitiveProcessor& primProc = fProgramBuilder->primitiveProcessor()
; |
67 | 73 |
68 int vaCount = primProc.numAttribs(); | 74 int vaCount = primProc.numAttribs(); |
69 for (int i = 0; i < vaCount; i++) { | 75 for (int i = 0; i < vaCount; i++) { |
70 GL_CALL(BindAttribLocation(programID, i, primProc.getAttrib(i).fName)); | 76 GL_CALL(BindAttribLocation(programID, i, primProc.getAttrib(i).fName)); |
71 } | 77 } |
(...skipping 14 matching lines...) Expand all Loading... |
86 for (int i = 0; i < fInputs.count(); ++i) { | 92 for (int i = 0; i < fInputs.count(); ++i) { |
87 const GrGLShaderVar& attr = fInputs[i]; | 93 const GrGLShaderVar& attr = fInputs[i]; |
88 // if attribute already added, don't add it again | 94 // if attribute already added, don't add it again |
89 if (attr.getName().equals(var.getName())) { | 95 if (attr.getName().equals(var.getName())) { |
90 return false; | 96 return false; |
91 } | 97 } |
92 } | 98 } |
93 fInputs.push_back(var); | 99 fInputs.push_back(var); |
94 return true; | 100 return true; |
95 } | 101 } |
OLD | NEW |