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 "../GrGLGpu.h" | 11 #include "../GrGLGpu.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 GrGLVertexBuilder::GrGLVertexBuilder(GrGLProgramBuilder* program) | 16 GrGLVertexBuilder::GrGLVertexBuilder(GrGLProgramBuilder* program) |
17 : INHERITED(program) | 17 : INHERITED(program) |
18 , fRtAdjustName(NULL) { | 18 , fRtAdjustName(NULL) { |
19 } | 19 } |
20 | 20 |
21 void GrGLVertexBuilder::addVarying(const char* name, GrGLVarying* v) { | 21 void GrGLVertexBuilder::addVarying(const char* name, GrGLVarying* v) { |
22 fOutputs.push_back(); | 22 fOutputs.push_back(); |
23 fOutputs.back().setType(v->fType); | 23 fOutputs.back().setType(v->fType); |
24 fOutputs.back().setTypeModifier(GrGLShaderVar::kVaryingOut_TypeModifier); | 24 fOutputs.back().setTypeModifier(GrGLShaderVar::kVaryingOut_TypeModifier); |
25 fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'v', name); | 25 fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'v', name); |
26 v->fVsOut = fOutputs.back().getName().c_str(); | 26 v->fVsOut = fOutputs.back().getName().c_str(); |
27 } | 27 } |
28 | 28 |
29 void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) { | 29 void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) { |
30 const GrGeometryProcessor::VertexAttribArray& v = gp.getAttribs(); | 30 int vaCount = gp.numAttribs(); |
31 int vaCount = v.count(); | |
32 for (int i = 0; i < vaCount; i++) { | 31 for (int i = 0; i < vaCount; i++) { |
33 this->addAttribute(&v[i]); | 32 this->addAttribute(&gp.getAttrib(i)); |
34 } | 33 } |
35 return; | 34 return; |
36 } | 35 } |
37 | 36 |
38 void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const char* pos3) { | 37 void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const char* pos3) { |
39 SkASSERT(!fRtAdjustName); | 38 SkASSERT(!fRtAdjustName); |
40 | 39 |
41 // setup RT Uniform | 40 // setup RT Uniform |
42 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = | 41 fProgramBuilder->fUniformHandles.fRTAdjustmentUni = |
43 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, | 42 fProgramBuilder->addUniform(GrGLProgramBuilder::kVertex_Visibility, |
44 kVec4f_GrSLType, kDefault_GrSLPrecision, | 43 kVec4f_GrSLType, kDefault_GrSLPrecision, |
45 fProgramBuilder->rtAdjustment(), | 44 fProgramBuilder->rtAdjustment(), |
46 &fRtAdjustName); | 45 &fRtAdjustName); |
47 | 46 |
48 // 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. |
49 this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw),
0, %s.z);", | 48 this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw),
0, %s.z);", |
50 pos3, fRtAdjustName, pos3, fRtAdjustName, pos3); | 49 pos3, fRtAdjustName, pos3, fRtAdjustName, pos3); |
51 | 50 |
52 // We could have the GrGeometryProcessor do this, but its just easier to hav
e it performed here. | 51 // 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 | 52 // If we ever need to set variable pointsize, then we can reinvestigate |
54 this->codeAppend("gl_PointSize = 1.0;"); | 53 this->codeAppend("gl_PointSize = 1.0;"); |
55 } | 54 } |
56 | 55 |
57 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { | 56 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { |
58 const GrGeometryProcessor* gp = fProgramBuilder->fOptState.getGeometryProces
sor(); | 57 const GrPrimitiveProcessor* primProc = fProgramBuilder->fOptState.getPrimiti
veProcessor(); |
59 | 58 |
60 const GrGeometryProcessor::VertexAttribArray& v = gp->getAttribs(); | 59 int vaCount = primProc->numAttribs(); |
61 int vaCount = v.count(); | |
62 for (int i = 0; i < vaCount; i++) { | 60 for (int i = 0; i < vaCount; i++) { |
63 GL_CALL(BindAttribLocation(programID, i, v[i].fName)); | 61 GL_CALL(BindAttribLocation(programID, i, primProc->getAttrib(i).fName)); |
64 } | 62 } |
65 return; | 63 return; |
66 } | 64 } |
67 | 65 |
68 bool GrGLVertexBuilder::compileAndAttachShaders(GrGLuint programId, | 66 bool GrGLVertexBuilder::compileAndAttachShaders(GrGLuint programId, |
69 SkTDArray<GrGLuint>* shaderIds) const { | 67 SkTDArray<GrGLuint>* shaderIds) const { |
70 GrGLGpu* gpu = fProgramBuilder->gpu(); | 68 GrGLGpu* gpu = fProgramBuilder->gpu(); |
71 const GrGLContext& glCtx = gpu->glContext(); | 69 const GrGLContext& glCtx = gpu->glContext(); |
72 const GrGLContextInfo& ctxInfo = gpu->ctxInfo(); | 70 const GrGLContextInfo& ctxInfo = gpu->ctxInfo(); |
73 SkString vertShaderSrc(GrGetGLSLVersionDecl(ctxInfo)); | 71 SkString vertShaderSrc(GrGetGLSLVersionDecl(ctxInfo)); |
(...skipping 18 matching lines...) Expand all Loading... |
92 for (int i = 0; i < fInputs.count(); ++i) { | 90 for (int i = 0; i < fInputs.count(); ++i) { |
93 const GrGLShaderVar& attr = fInputs[i]; | 91 const GrGLShaderVar& attr = fInputs[i]; |
94 // if attribute already added, don't add it again | 92 // if attribute already added, don't add it again |
95 if (attr.getName().equals(var.getName())) { | 93 if (attr.getName().equals(var.getName())) { |
96 return false; | 94 return false; |
97 } | 95 } |
98 } | 96 } |
99 fInputs.push_back(var); | 97 fInputs.push_back(var); |
100 return true; | 98 return true; |
101 } | 99 } |
OLD | NEW |