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(const char* glsl, 51 int length, 52 GrGLuint programId, 53 GrGLenum type, 54 SkTDArray<GrGLuint>* shaderIds, 55 const SkSL::Program::Settings& settings, 56 const SkSL::Program::Inputs& inputs); 57 58 bool compileAndAttachShaders(GrGLSLShaderBuilder& shader, 59 GrGLuint programId, 60 GrGLenum type, 61 SkTDArray<GrGLuint>* shaderIds, 62 const SkSL::Program::Settings& settings, 63 SkSL::Program::Inputs* outInputs); 64 GrGLProgram* finalize(); 65 void bindProgramResourceLocations(GrGLuint programID); 66 bool checkLinkStatus(GrGLuint programID); 67 void resolveProgramResourceLocations(GrGLuint programID); 68 void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs); 69 void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs); 70 71 // Subclasses create different programs 72 GrGLProgram* createProgram(GrGLuint programID); 73 74 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } 75 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } 76 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } 77 78 GrGLGpu* fGpu; 79 GrGLVaryingHandler fVaryingHandler; 80 GrGLUniformHandler fUniformHandler; 81 82 // shader pulled from cache. Data is organized as: 83 // SkSL::Program::Inputs inputs 84 // int binaryFormat 85 // (all remaining bytes) char[] binary 86 sk_sp<SkData> fCached; 87 88 typedef GrGLSLProgramBuilder INHERITED; 89 }; 90 #endif 91