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 "../GrGLGpu.h" | 11 #include "../GrGLGpu.h" |
11 | 12 |
12 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) | 13 #define GL_CALL(X) GR_GL_CALL(fProgramBuilder->gpu()->glInterface(), X) |
13 #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) |
14 | 15 |
15 GrGLVertexBuilder::GrGLVertexBuilder(GrGLProgramBuilder* program) | 16 GrGLVertexBuilder::GrGLVertexBuilder(GrGLProgramBuilder* program) |
16 : INHERITED(program) | 17 : INHERITED(program) |
17 , fRtAdjustName(NULL) { | 18 , fRtAdjustName(NULL) { |
18 } | 19 } |
19 | 20 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { | 66 void GrGLVertexBuilder::bindVertexAttributes(GrGLuint programID) { |
66 const GrPrimitiveProcessor& primProc = fProgramBuilder->primitiveProcessor()
; | 67 const GrPrimitiveProcessor& primProc = fProgramBuilder->primitiveProcessor()
; |
67 | 68 |
68 int vaCount = primProc.numAttribs(); | 69 int vaCount = primProc.numAttribs(); |
69 for (int i = 0; i < vaCount; i++) { | 70 for (int i = 0; i < vaCount; i++) { |
70 GL_CALL(BindAttribLocation(programID, i, primProc.getAttrib(i).fName)); | 71 GL_CALL(BindAttribLocation(programID, i, primProc.getAttrib(i).fName)); |
71 } | 72 } |
72 return; | 73 return; |
73 } | 74 } |
74 | 75 |
75 bool | 76 bool GrGLVertexBuilder::compileAndAttachShaders(GrGLuint programId, |
76 GrGLVertexBuilder::compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuin
t>* shaderIds) { | 77 SkTDArray<GrGLuint>* shaderIds) const { |
77 this->versionDecl() = GrGetGLSLVersionDecl(fProgramBuilder->ctxInfo()); | 78 GrGLGpu* gpu = fProgramBuilder->gpu(); |
78 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kVertex_Visibility,
&this->uniforms()); | 79 const GrGLContext& glCtx = gpu->glContext(); |
79 this->appendDecls(fInputs, &this->inputs()); | 80 const GrGLContextInfo& ctxInfo = gpu->ctxInfo(); |
80 this->appendDecls(fOutputs, &this->outputs()); | 81 SkString vertShaderSrc(GrGetGLSLVersionDecl(ctxInfo)); |
81 return this->finalize(programId, GR_GL_VERTEX_SHADER, shaderIds); | 82 fProgramBuilder->appendUniformDecls(GrGLProgramBuilder::kVertex_Visibility,
&vertShaderSrc); |
| 83 this->appendDecls(fInputs, &vertShaderSrc); |
| 84 this->appendDecls(fOutputs, &vertShaderSrc); |
| 85 vertShaderSrc.append("void main() {"); |
| 86 vertShaderSrc.append(fCode); |
| 87 vertShaderSrc.append("}\n"); |
| 88 GrGLuint vertShaderId = GrGLCompileAndAttachShader(glCtx, programId, GR_GL_V
ERTEX_SHADER, |
| 89 vertShaderSrc, gpu->stats
()); |
| 90 if (!vertShaderId) { |
| 91 return false; |
| 92 } |
| 93 *shaderIds->append() = vertShaderId; |
| 94 return true; |
82 } | 95 } |
83 | 96 |
84 bool GrGLVertexBuilder::addAttribute(const GrShaderVar& var) { | 97 bool GrGLVertexBuilder::addAttribute(const GrShaderVar& var) { |
85 SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier()); | 98 SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier()); |
86 for (int i = 0; i < fInputs.count(); ++i) { | 99 for (int i = 0; i < fInputs.count(); ++i) { |
87 const GrGLShaderVar& attr = fInputs[i]; | 100 const GrGLShaderVar& attr = fInputs[i]; |
88 // if attribute already added, don't add it again | 101 // if attribute already added, don't add it again |
89 if (attr.getName().equals(var.getName())) { | 102 if (attr.getName().equals(var.getName())) { |
90 return false; | 103 return false; |
91 } | 104 } |
92 } | 105 } |
93 fInputs.push_back(var); | 106 fInputs.push_back(var); |
94 return true; | 107 return true; |
95 } | 108 } |
OLD | NEW |