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

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

Issue 1416423003: Make GrGLSLProgramBuilder base class for ProgramBuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 5 years, 1 month 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') | src/gpu/glsl/GrGLSLCaps.h » ('j') | 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 "glsl/GrGLSLProgramBuilder.h"
10 #include "../GrGLGLSL.h"
11 #include "../GrGLGpu.h"
12 10
13 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) 11 GrGLVertexBuilder::GrGLVertexBuilder(GrGLSLProgramBuilder* program)
14 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fProgramBuilder->gpu()->glInterface(), R, X)
15
16 GrGLVertexBuilder::GrGLVertexBuilder(GrGLProgramBuilder* program)
17 : INHERITED(program) 12 : INHERITED(program)
18 , fRtAdjustName(nullptr) { 13 , fRtAdjustName(nullptr) {
19 } 14 }
20 15
21 void GrGLVertexBuilder::addVarying(const char* name, GrSLPrecision precision, Gr GLVarying* v) { 16 void GrGLVertexBuilder::addVarying(const char* name, GrSLPrecision precision, Gr GLSLVarying* v) {
22 fOutputs.push_back(); 17 fOutputs.push_back();
23 fOutputs.back().setType(v->fType); 18 fOutputs.back().setType(v->fType);
24 fOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier); 19 fOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier);
25 fOutputs.back().setPrecision(precision); 20 fOutputs.back().setPrecision(precision);
26 fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'v', name); 21 fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'v', name);
27 v->fVsOut = fOutputs.back().getName().c_str(); 22 v->fVsOut = fOutputs.back().getName().c_str();
28 } 23 }
29 24
30 void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) { 25 void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) {
31 int vaCount = gp.numAttribs(); 26 int vaCount = gp.numAttribs();
32 for (int i = 0; i < vaCount; i++) { 27 for (int i = 0; i < vaCount; i++) {
33 this->addAttribute(&gp.getAttrib(i)); 28 this->addAttribute(&gp.getAttrib(i));
34 } 29 }
35 return; 30 return;
36 } 31 }
37 32
38 void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posV ar) { 33 void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posV ar) {
39 SkASSERT(!fRtAdjustName); 34 SkASSERT(!fRtAdjustName);
40 35
41 GrSLPrecision precision = kDefault_GrSLPrecision; 36 GrSLPrecision precision = kDefault_GrSLPrecision;
42 if (fProgramBuilder->glslCaps()->forceHighPrecisionNDSTransform()) { 37 if (fProgramBuilder->glslCaps()->forceHighPrecisionNDSTransform()) {
43 precision = kHigh_GrSLPrecision; 38 precision = kHigh_GrSLPrecision;
44 } 39 }
45 40
46 // setup RT Uniform 41 // setup RT Uniform
47 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = 42 fProgramBuilder->fUniformHandles.fRTAdjustmentUni =
48 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, 43 fProgramBuilder->addUniform(GrGLSLProgramBuilder::kVertex_Visibility ,
49 kVec4f_GrSLType, precision, 44 kVec4f_GrSLType, precision,
50 fProgramBuilder->rtAdjustment(), 45 fProgramBuilder->rtAdjustment(),
51 &fRtAdjustName); 46 &fRtAdjustName);
52 if (this->getProgramBuilder()->desc().header().fSnapVerticesToPixelCenters) { 47 if (this->getProgramBuilder()->desc().header().fSnapVerticesToPixelCenters) {
53 if (kVec3f_GrSLType == posVar.getType()) { 48 if (kVec3f_GrSLType == posVar.getType()) {
54 const char* p = posVar.c_str(); 49 const char* p = posVar.c_str();
55 this->codeAppendf("{vec2 _posTmp = vec2(%s.x/%s.z, %s.y/%s.z);", p, p, p, p); 50 this->codeAppendf("{vec2 _posTmp = vec2(%s.x/%s.z, %s.y/%s.z);", p, p, p, p);
56 } else { 51 } else {
57 SkASSERT(kVec2f_GrSLType == posVar.getType()); 52 SkASSERT(kVec2f_GrSLType == posVar.getType());
58 this->codeAppendf("{vec2 _posTmp = %s;", posVar.c_str()); 53 this->codeAppendf("{vec2 _posTmp = %s;", posVar.c_str());
(...skipping 11 matching lines...) Expand all
70 SkASSERT(kVec2f_GrSLType == posVar.getType()); 65 SkASSERT(kVec2f_GrSLType == posVar.getType());
71 this->codeAppendf("gl_Position = vec4(%s.x * %s.x + %s.y, %s.y * %s.z + %s.w, 0, 1);", 66 this->codeAppendf("gl_Position = vec4(%s.x * %s.x + %s.y, %s.y * %s.z + %s.w, 0, 1);",
72 posVar.c_str(), fRtAdjustName, fRtAdjustName, 67 posVar.c_str(), fRtAdjustName, fRtAdjustName,
73 posVar.c_str(), fRtAdjustName, fRtAdjustName); 68 posVar.c_str(), fRtAdjustName, fRtAdjustName);
74 } 69 }
75 // We could have the GrGeometryProcessor do this, but its just easier to hav e it performed 70 // We could have the GrGeometryProcessor do this, but its just easier to hav e it performed
76 // here. If we ever need to set variable pointsize, then we can reinvestigat e 71 // here. If we ever need to set variable pointsize, then we can reinvestigat e
77 this->codeAppend("gl_PointSize = 1.0;"); 72 this->codeAppend("gl_PointSize = 1.0;");
78 } 73 }
79 74
80 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) {
81 const GrPrimitiveProcessor& primProc = fProgramBuilder->primitiveProcessor() ;
82
83 int vaCount = primProc.numAttribs();
84 for (int i = 0; i < vaCount; i++) {
85 GL_CALL(BindAttribLocation(programID, i, primProc.getAttrib(i).fName));
86 }
87 return;
88 }
89
90 bool GrGLVertexBuilder::addAttribute(const GrShaderVar& var) { 75 bool GrGLVertexBuilder::addAttribute(const GrShaderVar& var) {
91 SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier()); 76 SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier());
92 for (int i = 0; i < fInputs.count(); ++i) { 77 for (int i = 0; i < fInputs.count(); ++i) {
93 const GrGLSLShaderVar& attr = fInputs[i]; 78 const GrGLSLShaderVar& attr = fInputs[i];
94 // if attribute already added, don't add it again 79 // if attribute already added, don't add it again
95 if (attr.getName().equals(var.getName())) { 80 if (attr.getName().equals(var.getName())) {
96 return false; 81 return false;
97 } 82 }
98 } 83 }
99 fInputs.push_back(var); 84 fInputs.push_back(var);
100 return true; 85 return true;
101 } 86 }
87
OLDNEW
« no previous file with comments | « src/gpu/gl/builders/GrGLVertexShaderBuilder.h ('k') | src/gpu/glsl/GrGLSLCaps.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698