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 "src/gpu/GrPipeline.h" 12 #include "src/gpu/gl/GrGLProgram.h" 13 #include "src/gpu/gl/GrGLProgramDataManager.h" 14 #include "src/gpu/gl/GrGLUniformHandler.h" 15 #include "src/gpu/gl/GrGLVaryingHandler.h" 16 #include "src/gpu/glsl/GrGLSLProgramBuilder.h" 17 #include "src/gpu/glsl/GrGLSLProgramDataManager.h" 18 #include "src/sksl/ir/SkSLProgram.h" 19 20 class GrFragmentProcessor; 21 class GrGLContextInfo; 22 class GrProgramDesc; 23 class GrGLSLShaderBuilder; 24 class GrShaderCaps; 25 26 class GrGLProgramBuilder : public GrGLSLProgramBuilder { 27 public: 28 /** Generates a shader program. 29 * 30 * The program implements what is specified in the stages given as input. 31 * After successful generation, the builder result objects are available 32 * to be used. 33 * This function may modify the GrProgramDesc by setting the surface origin 34 * key to 0 (unspecified) if it turns out the program does not care about 35 * the surface origin. 36 * @return true if generation was successful. 37 */ 38 static GrGLProgram* CreateProgram(GrRenderTarget*, GrSurfaceOrigin, 39 const GrPrimitiveProcessor&, 40 const GrTextureProxy* const primProcProxies[], 41 const GrPipeline&, 42 GrProgramDesc*, 43 GrGLGpu*); 44 45 const GrCaps* caps() const override; 46 gpu()47 GrGLGpu* gpu() const { return fGpu; } 48 49 private: 50 GrGLProgramBuilder(GrGLGpu*, GrRenderTarget*, GrSurfaceOrigin, 51 const GrPipeline&, const GrPrimitiveProcessor&, 52 const GrTextureProxy* const primProcProxies[], GrProgramDesc*); 53 54 void addInputVars(const SkSL::Program::Inputs& inputs); 55 bool compileAndAttachShaders(const SkSL::String& glsl, 56 GrGLuint programId, 57 GrGLenum type, 58 SkTDArray<GrGLuint>* shaderIds, 59 GrContextOptions::ShaderErrorHandler* errorHandler); 60 61 void computeCountsAndStrides(GrGLuint programID, const GrPrimitiveProcessor& primProc, 62 bool bindAttribLocations); 63 void storeShaderInCache(const SkSL::Program::Inputs& inputs, GrGLuint programID, 64 const SkSL::String shaders[], bool isSkSL); 65 GrGLProgram* finalize(); 66 void bindProgramResourceLocations(GrGLuint programID); 67 bool checkLinkStatus(GrGLuint programID, GrContextOptions::ShaderErrorHandler* errorHandler, 68 SkSL::String* sksl[], const SkSL::String glsl[]); 69 void resolveProgramResourceLocations(GrGLuint programID, bool force); 70 void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs); 71 void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs); 72 73 // Subclasses create different programs 74 GrGLProgram* createProgram(GrGLuint programID); 75 uniformHandler()76 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } uniformHandler()77 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } varyingHandler()78 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } 79 80 GrGLGpu* fGpu; 81 GrGLVaryingHandler fVaryingHandler; 82 GrGLUniformHandler fUniformHandler; 83 84 std::unique_ptr<GrGLProgram::Attribute[]> fAttributes; 85 int fVertexAttributeCnt; 86 int fInstanceAttributeCnt; 87 size_t fVertexStride; 88 size_t fInstanceStride; 89 90 // shader pulled from cache. Data is organized as: 91 // SkSL::Program::Inputs inputs 92 // int binaryFormat 93 // (all remaining bytes) char[] binary 94 sk_sp<SkData> fCached; 95 96 typedef GrGLSLProgramBuilder INHERITED; 97 }; 98 #endif 99