bool GrGLGeometryShaderBuilder::compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) const { const GrGLContext& glCtx = fProgramBuilder->gpu()->glContext(); SkASSERT(fProgramBuilder->ctxInfo().glslGeneration() >= k150_GrGLSLGeneration); SkString geomShaderSrc(GrGetGLSLVersionDecl(fProgramBuilder->ctxInfo())); geomShaderSrc.append("layout(triangles) in;\n" "layout(triangle_strip, max_vertices = 6) out;\n"); fProgramBuilder->appendDecls(fInputs, &geomShaderSrc); fProgramBuilder->appendDecls(fOutputs, &geomShaderSrc); geomShaderSrc.append("void main() {\n"); geomShaderSrc.append("\tfor (int i = 0; i < 3; ++i) {\n" "\t\tgl_Position = gl_in[i].gl_Position;\n"); if (fProgramBuilder->desc().getHeader().fEmitsPointSize) { geomShaderSrc.append("\t\tgl_PointSize = 1.0;\n"); } SkASSERT(fInputs.count() == fOutputs.count()); for (int i = 0; i < fInputs.count(); ++i) { geomShaderSrc.appendf("\t\t%s = %s[i];\n", fOutputs[i].getName().c_str(), fInputs[i].getName().c_str()); } geomShaderSrc.append("\t\tEmitVertex();\n" "\t}\n" "\tEndPrimitive();\n"); geomShaderSrc.append("}\n"); GrGLuint geomShaderId = GrGLCompileAndAttachShader(glCtx, programId, GR_GL_GEOMETRY_SHADER, geomShaderSrc, fProgramBuilder->gpu()->gpuStats()); if (!geomShaderId) { return false; } *shaderIds->append() = geomShaderId; return true; }
bool GrGLFullShaderBuilder::compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shaderIds) const { const GrGLContext& glCtx = this->gpu()->glContext(); SkString vertShaderSrc(GrGetGLSLVersionDecl(this->ctxInfo())); this->appendUniformDecls(kVertex_Visibility, &vertShaderSrc); this->appendDecls(fVSAttrs, &vertShaderSrc); this->appendDecls(fVSOutputs, &vertShaderSrc); vertShaderSrc.append("void main() {\n"); vertShaderSrc.append(fVSCode); vertShaderSrc.append("}\n"); GrGLuint vertShaderId = attach_shader(glCtx, programId, GR_GL_VERTEX_SHADER, vertShaderSrc); if (!vertShaderId) { return false; } *shaderIds->append() = vertShaderId; #if GR_GL_EXPERIMENTAL_GS if (this->desc().getHeader().fExperimentalGS) { SkASSERT(this->ctxInfo().glslGeneration() >= k150_GrGLSLGeneration); SkString geomShaderSrc(GrGetGLSLVersionDecl(this->ctxInfo())); geomShaderSrc.append("layout(triangles) in;\n" "layout(triangle_strip, max_vertices = 6) out;\n"); this->appendDecls(fGSInputs, &geomShaderSrc); this->appendDecls(fGSOutputs, &geomShaderSrc); geomShaderSrc.append("void main() {\n"); geomShaderSrc.append("\tfor (int i = 0; i < 3; ++i) {\n" "\t\tgl_Position = gl_in[i].gl_Position;\n"); if (this->desc().getHeader().fEmitsPointSize) { geomShaderSrc.append("\t\tgl_PointSize = 1.0;\n"); } SkASSERT(fGSInputs.count() == fGSOutputs.count()); for (int i = 0; i < fGSInputs.count(); ++i) { geomShaderSrc.appendf("\t\t%s = %s[i];\n", fGSOutputs[i].getName().c_str(), fGSInputs[i].getName().c_str()); } geomShaderSrc.append("\t\tEmitVertex();\n" "\t}\n" "\tEndPrimitive();\n"); geomShaderSrc.append("}\n"); GrGLuint geomShaderId = attach_shader(glCtx, programId, GR_GL_GEOMETRY_SHADER, geomShaderSrc); if (!geomShaderId) { return false; } *shaderIds->append() = geomShaderId; } #endif return this->INHERITED::compileAndAttachShaders(programId, shaderIds); }