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

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

Issue 822423004: Move most of the transform logic into the primitive processors (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cleanup Created 5 years, 11 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') | no next file » | 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"
(...skipping 17 matching lines...) Expand all
28 28
29 void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) { 29 void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) {
30 const GrGeometryProcessor::VertexAttribArray& v = gp.getAttribs(); 30 const GrGeometryProcessor::VertexAttribArray& v = gp.getAttribs();
31 int vaCount = v.count(); 31 int vaCount = v.count();
32 for (int i = 0; i < vaCount; i++) { 32 for (int i = 0; i < vaCount; i++) {
33 this->addAttribute(&v[i]); 33 this->addAttribute(&v[i]);
34 } 34 }
35 return; 35 return;
36 } 36 }
37 37
38 void GrGLVertexBuilder::transformToNormalizedDeviceSpace() { 38 void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const char* pos3) {
39 SkASSERT(!fRtAdjustName);
40
39 // setup RT Uniform 41 // setup RT Uniform
40 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = 42 fProgramBuilder->fUniformHandles.fRTAdjustmentUni =
41 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, 43 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility,
42 kVec4f_GrSLType, kDefault_GrSLPrecision, 44 kVec4f_GrSLType, kDefault_GrSLPrecision,
43 fProgramBuilder->rtAdjustment(), 45 fProgramBuilder->rtAdjustment(),
44 &fRtAdjustName); 46 &fRtAdjustName);
45 // Wire transforms
46 SkTArray<GrGLProgramBuilder::TransformVarying, true>& transVs = fProgramBuil der->fCoordVaryings;
47 int transformCount = transVs.count();
48 for (int i = 0; i < transformCount; i++) {
49 GrCoordSet coordSet = transVs[i].fCoordSet;
50 const char* coords = NULL;
51 switch (coordSet) {
52 case kLocal_GrCoordSet:
53 coords = this->localCoords();
54 break;
55 case kDevice_GrCoordSet:
56 coords = this->glPosition();
57 break;
58 }
59
60 // varying = matrix * coords (logically)
61 const GrGLVarying& v = transVs[i].fV;
62 if (kDevice_GrCoordSet == coordSet) {
63 if (kVec2f_GrSLType == v.fType) {
64 this->codeAppendf("%s = (%s * %s).xy;", v.fVsOut, transVs[i].fUn iName.c_str(),
65 coords);
66 } else {
67 this->codeAppendf("%s = %s * %s;", v.fVsOut, transVs[i].fUniName .c_str(), coords);
68 }
69 } else {
70 if (kVec2f_GrSLType == v.fType) {
71 this->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.fVsOut, trans Vs[i].fUniName.c_str(),
72 coords);
73 } else {
74 this->codeAppendf("%s = %s * vec3(%s, 1);", v.fVsOut, transVs[i] .fUniName.c_str(),
75 coords);
76 }
77 }
78 }
79 47
80 // Transform from Skia's device coords to GL's normalized device coords. 48 // Transform from Skia's device coords to GL's normalized device coords.
81 this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw), 0, %s.z);", 49 this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw), 0, %s.z);",
82 this->glPosition(), fRtAdjustName, this->glPosition(), fRt AdjustName, 50 pos3, fRtAdjustName, pos3, fRtAdjustName, pos3);
83 this->glPosition()); 51
52 // We could have the GrGeometryProcessor do this, but its just easier to hav e it performed here.
53 // If we ever need to set variable pointsize, then we can reinvestigate
54 this->codeAppend("gl_PointSize = 1.0;");
84 } 55 }
85 56
86 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { 57 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) {
87 const GrGeometryProcessor* gp = fProgramBuilder->fOptState.getGeometryProces sor(); 58 const GrGeometryProcessor* gp = fProgramBuilder->fOptState.getGeometryProces sor();
88 59
89 const GrGeometryProcessor::VertexAttribArray& v = gp->getAttribs(); 60 const GrGeometryProcessor::VertexAttribArray& v = gp->getAttribs();
90 int vaCount = v.count(); 61 int vaCount = v.count();
91 for (int i = 0; i < vaCount; i++) { 62 for (int i = 0; i < vaCount; i++) {
92 GL_CALL(BindAttribLocation(programID, i, v[i].fName)); 63 GL_CALL(BindAttribLocation(programID, i, v[i].fName));
93 } 64 }
(...skipping 27 matching lines...) Expand all
121 for (int i = 0; i < fInputs.count(); ++i) { 92 for (int i = 0; i < fInputs.count(); ++i) {
122 const GrGLShaderVar& attr = fInputs[i]; 93 const GrGLShaderVar& attr = fInputs[i];
123 // if attribute already added, don't add it again 94 // if attribute already added, don't add it again
124 if (attr.getName().equals(var.getName())) { 95 if (attr.getName().equals(var.getName())) {
125 return false; 96 return false;
126 } 97 }
127 } 98 }
128 fInputs.push_back(var); 99 fInputs.push_back(var);
129 return true; 100 return true;
130 } 101 }
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLVertexShaderBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698