| 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 "GrGLGeometryShaderBuilder.h" | 8 #include "GrGLGeometryShaderBuilder.h" |
| 9 #include "GrGLShaderStringBuilder.h" | 9 #include "GrGLShaderStringBuilder.h" |
| 10 #include "GrGLProgramBuilder.h" | 10 #include "GrGLProgramBuilder.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 fOutputs.back().setTypeModifier(GrGLShaderVar::kVaryingOut_TypeModifier); | 30 fOutputs.back().setTypeModifier(GrGLShaderVar::kVaryingOut_TypeModifier); |
| 31 fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'g', name); | 31 fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'g', name); |
| 32 if (gsOutName) { | 32 if (gsOutName) { |
| 33 *gsOutName = fOutputs.back().getName().c_str(); | 33 *gsOutName = fOutputs.back().getName().c_str(); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 | 37 |
| 38 bool GrGLGeometryShaderBuilder::compileAndAttachShaders(GrGLuint programId, | 38 bool GrGLGeometryShaderBuilder::compileAndAttachShaders(GrGLuint programId, |
| 39 SkTDArray<GrGLuint>* shaderIds) const { | 39 SkTDArray<GrGLuint>* shaderIds) const { |
| 40 const GrGLContext& glCtx = fProgramBuilder->gpu()->glContext(); | |
| 41 SkASSERT(fProgramBuilder->ctxInfo().glslGeneration() >= k150_GrGLSLGeneratio
n); | 40 SkASSERT(fProgramBuilder->ctxInfo().glslGeneration() >= k150_GrGLSLGeneratio
n); |
| 42 SkString geomShaderSrc(GrGetGLSLVersionDecl(fProgramBuilder->ctxInfo())); | 41 SkString geomShaderSrc(GrGetGLSLVersionDecl(fProgramBuilder->ctxInfo())); |
| 43 geomShaderSrc.append("layout(triangles) in;\n" | 42 geomShaderSrc.append("layout(triangles) in;\n" |
| 44 "layout(triangle_strip, max_vertices = 6) out;\n"); | 43 "layout(triangle_strip, max_vertices = 6) out;\n"); |
| 45 fProgramBuilder->appendDecls(fInputs, &geomShaderSrc); | 44 fProgramBuilder->appendDecls(fInputs, &geomShaderSrc); |
| 46 fProgramBuilder->appendDecls(fOutputs, &geomShaderSrc); | 45 fProgramBuilder->appendDecls(fOutputs, &geomShaderSrc); |
| 47 geomShaderSrc.append("void main() {\n"); | 46 geomShaderSrc.append("void main() {\n"); |
| 48 geomShaderSrc.append("\tfor (int i = 0; i < 3; ++i) {\n" | 47 geomShaderSrc.append("\tfor (int i = 0; i < 3; ++i) {\n" |
| 49 "\t\tgl_Position = gl_in[i].gl_Position;\n"); | 48 "\t\tgl_Position = gl_in[i].gl_Position;\n"); |
| 50 if (fProgramBuilder->desc().getHeader().fEmitsPointSize) { | 49 if (fProgramBuilder->desc().getHeader().fEmitsPointSize) { |
| 51 geomShaderSrc.append("\t\tgl_PointSize = 1.0;\n"); | 50 geomShaderSrc.append("\t\tgl_PointSize = 1.0;\n"); |
| 52 } | 51 } |
| 53 SkASSERT(fInputs.count() == fOutputs.count()); | 52 SkASSERT(fInputs.count() == fOutputs.count()); |
| 54 for (int i = 0; i < fInputs.count(); ++i) { | 53 for (int i = 0; i < fInputs.count(); ++i) { |
| 55 geomShaderSrc.appendf("\t\t%s = %s[i];\n", | 54 geomShaderSrc.appendf("\t\t%s = %s[i];\n", |
| 56 fOutputs[i].getName().c_str(), | 55 fOutputs[i].getName().c_str(), |
| 57 fInputs[i].getName().c_str()); | 56 fInputs[i].getName().c_str()); |
| 58 } | 57 } |
| 59 geomShaderSrc.append("\t\tEmitVertex();\n" | 58 geomShaderSrc.append("\t\tEmitVertex();\n" |
| 60 "\t}\n" | 59 "\t}\n" |
| 61 "\tEndPrimitive();\n"); | 60 "\tEndPrimitive();\n"); |
| 62 geomShaderSrc.append("}\n"); | 61 geomShaderSrc.append("}\n"); |
| 63 GrGLuint geomShaderId = | 62 GrGLuint geomShaderId = |
| 64 GrGLCompileAndAttachShader(glCtx, programId, GR_GL_GEOMETRY_SHADER,
geomShaderSrc); | 63 GrGLCompileAndAttachShader(fProgramBuilder->gpu(), programId, |
| 64 GR_GL_GEOMETRY_SHADER, geomShaderSrc); |
| 65 if (!geomShaderId) { | 65 if (!geomShaderId) { |
| 66 return false; | 66 return false; |
| 67 } | 67 } |
| 68 *shaderIds->append() = geomShaderId; | 68 *shaderIds->append() = geomShaderId; |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| OLD | NEW |