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 18 class GrFragmentProcessor; 19 class GrGLContextInfo; 20 class GrGLSLShaderBuilder; 21 class GrGLSLCaps; 22 23 class GrGLProgramBuilder : public GrGLSLProgramBuilder { 24 public: 25 /** Generates a shader program. 26 * 27 * The program implements what is specified in the stages given as input. 28 * After successful generation, the builder result objects are available 29 * to be used. 30 * @return true if generation was successful. 31 */ 32 static GrGLProgram* CreateProgram(const DrawArgs&, GrGLGpu*); 33 34 const GrCaps* caps() const override; 35 const GrGLSLCaps* glslCaps() const override; 36 gpu()37 GrGLGpu* gpu() const { return fGpu; } 38 39 private: 40 GrGLProgramBuilder(GrGLGpu*, const DrawArgs&); 41 42 void emitSamplers(const GrProcessor&, 43 GrGLSLTextureSampler::TextureSamplerArray* outSamplers) override; 44 45 bool compileAndAttachShaders(GrGLSLShaderBuilder& shader, 46 GrGLuint programId, 47 GrGLenum type, 48 SkTDArray<GrGLuint>* shaderIds); 49 GrGLProgram* finalize(); 50 void bindProgramResourceLocations(GrGLuint programID); 51 bool checkLinkStatus(GrGLuint programID); 52 void resolveProgramResourceLocations(GrGLuint programID); 53 void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs); 54 void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs); 55 56 // Subclasses create different programs 57 GrGLProgram* createProgram(GrGLuint programID); 58 uniformHandler()59 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; } uniformHandler()60 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; } varyingHandler()61 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; } 62 63 64 GrGLGpu* fGpu; 65 typedef GrGLSLUniformHandler::UniformHandle UniformHandle; 66 SkTArray<UniformHandle> fSamplerUniforms; 67 68 GrGLVaryingHandler fVaryingHandler; 69 GrGLUniformHandler fUniformHandler; 70 71 typedef GrGLSLProgramBuilder INHERITED; 72 }; 73 #endif 74