1 /* 2 * Copyright 2014 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrGLProgramBuilder_DEFINED 9 #define GrGLProgramBuilder_DEFINED 10 11 #include "GrPipeline.h" 12 #include "gl/GrGLProgramDataManager.h" 13 #include "gl/GrGLUniformHandler.h" 14 #include "gl/GrGLVaryingHandler.h" 15 #include "glsl/GrGLSLProgramBuilder.h" 16 #include "glsl/GrGLSLProgramDataManager.h" 17 #include "ir/SkSLProgram.h" 18 19 class GrFragmentProcessor; 20 class GrGLContextInfo; 21 class GrProgramDesc; 22 class GrGLSLShaderBuilder; 23 class GrShaderCaps; 24 25 class GrGLProgramBuilder : public GrGLSLProgramBuilder { 26 public: 27 /** Generates a shader program. 28 * 29 * The program implements what is specified in the stages given as input. 30 * After successful generation, the builder result objects are available 31 * to be used. 32 * This function may modify the GrProgramDesc by setting the surface origin 33 * key to 0 (unspecified) if it turns out the program does not care about 34 * the surface origin. 35 * @return true if generation was successful. 36 */ 37 static GrGLProgram* CreateProgram(const GrPipeline&, 38 const GrPrimitiveProcessor&, 39 GrProgramDesc*, 40 GrGLGpu*); 41 42 const GrCaps* caps() const override; 43 44 GrGLGpu* gpu() const { return fGpu; } 45 46 private: 47 GrGLProgramBuilder(GrGLGpu*, const GrPipeline&, const GrPrimitiveProcessor&, 48 GrProgramDesc*); 49 50 bool compileAndAttachShaders(GrGLSLShaderBuilder& shader, 51 GrGLuint programId, 52 GrGLenum type, 53 SkTDArray<GrGLuint>* shaderIds, 54 const SkSL::Program::Settings& settings, 55 SkSL::Program::Inputs* outInputs); 56 GrGLProgram* finalize(); 57 void bindProgramResourceLocations(GrGLuint programID); 58 bool checkLinkStatus(GrGLuint programID); 59 void resolveProgramResourceLocations(GrGLuint programID); 60 void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs); 61 void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs); 62 63 // Subclasses create different programs 64 GrGLProgram* createProgram(GrGLuint programID); 65 66 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } 67 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } 68 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } 69 70 71 GrGLGpu* fGpu; 72 GrGLVaryingHandler fVaryingHandler; 73 GrGLUniformHandler fUniformHandler; 74 75 typedef GrGLSLProgramBuilder INHERITED; 76 }; 77 #endif 78