| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 } | 27 } |
| 28 | 28 |
| 29 void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) { | 29 void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) { |
| 30 int vaCount = gp.numAttribs(); | 30 int vaCount = gp.numAttribs(); |
| 31 for (int i = 0; i < vaCount; i++) { | 31 for (int i = 0; i < vaCount; i++) { |
| 32 this->addAttribute(&gp.getAttrib(i)); | 32 this->addAttribute(&gp.getAttrib(i)); |
| 33 } | 33 } |
| 34 return; | 34 return; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const char* pos3) { | 37 void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posV
ar) { |
| 38 SkASSERT(!fRtAdjustName); | 38 SkASSERT(!fRtAdjustName); |
| 39 | 39 |
| 40 // setup RT Uniform | 40 // setup RT Uniform |
| 41 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = | 41 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = |
| 42 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, | 42 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, |
| 43 kVec4f_GrSLType, kDefault_GrSLPrecision, | 43 kVec4f_GrSLType, kDefault_GrSLPrecision, |
| 44 fProgramBuilder->rtAdjustment(), | 44 fProgramBuilder->rtAdjustment(), |
| 45 &fRtAdjustName); | 45 &fRtAdjustName); |
| 46 | 46 |
| 47 // Transform from Skia's device coords to GL's normalized device coords. | 47 // Transform from Skia's device coords to GL's normalized device coords. Not
e that |
| 48 this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw),
0, %s.z);", | 48 // because we want to "nudge" the device space positions we are converting t
o |
| 49 pos3, fRtAdjustName, pos3, fRtAdjustName, pos3); | 49 // non-homogeneous NDC. |
| 50 if (kVec3f_GrSLType == posVar.getType()) { |
| 51 this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy)/%s.z, dot(%s.yz,
%s.zw)/%s.z, 0, 1);", |
| 52 posVar.c_str(), fRtAdjustName, posVar.c_str(), |
| 53 posVar.c_str(), fRtAdjustName, posVar.c_str()); |
| 54 } else { |
| 55 SkASSERT(kVec2f_GrSLType == posVar.getType()); |
| 56 this->codeAppendf("gl_Position = vec4(%s.x * %s.x + %s.y, %s.y * %s.z +
%s.w, 0, 1);", |
| 57 posVar.c_str(), fRtAdjustName, fRtAdjustName, |
| 58 posVar.c_str(), fRtAdjustName, fRtAdjustName); |
| 59 } |
| 50 | 60 |
| 51 // We could have the GrGeometryProcessor do this, but its just easier to hav
e it performed here. | 61 // We could have the GrGeometryProcessor do this, but its just easier to hav
e it performed here. |
| 52 // If we ever need to set variable pointsize, then we can reinvestigate | 62 // If we ever need to set variable pointsize, then we can reinvestigate |
| 53 this->codeAppend("gl_PointSize = 1.0;"); | 63 this->codeAppend("gl_PointSize = 1.0;"); |
| 54 } | 64 } |
| 55 | 65 |
| 56 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { | 66 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { |
| 57 const GrPrimitiveProcessor* primProc = fProgramBuilder->fOptState.getPrimiti
veProcessor(); | 67 const GrPrimitiveProcessor* primProc = fProgramBuilder->fOptState.getPrimiti
veProcessor(); |
| 58 | 68 |
| 59 int vaCount = primProc->numAttribs(); | 69 int vaCount = primProc->numAttribs(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 90 for (int i = 0; i < fInputs.count(); ++i) { | 100 for (int i = 0; i < fInputs.count(); ++i) { |
| 91 const GrGLShaderVar& attr = fInputs[i]; | 101 const GrGLShaderVar& attr = fInputs[i]; |
| 92 // if attribute already added, don't add it again | 102 // if attribute already added, don't add it again |
| 93 if (attr.getName().equals(var.getName())) { | 103 if (attr.getName().equals(var.getName())) { |
| 94 return false; | 104 return false; |
| 95 } | 105 } |
| 96 } | 106 } |
| 97 fInputs.push_back(var); | 107 fInputs.push_back(var); |
| 98 return true; | 108 return true; |
| 99 } | 109 } |
| OLD | NEW |