Flutter Engine
The Flutter Engine
GrGLProgramBuilder.h
Go to the documentation of this file.
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
21
23class GrGLContextInfo;
24class GrProgramDesc;
26struct GrShaderCaps;
27
31 : fProgramID(programID), fInterface(intf) {}
32
35};
36
38public:
39 /** Generates a shader program.
40 *
41 * The program implements what is specified in the stages given as input.
42 * After successful generation, the builder result objects are available
43 * to be used.
44 * If a GL program has already been created, the program ID and interface can
45 * be supplied to skip the shader compilation.
46 * @return the created program if generation was successful.
47 */
49 const GrProgramDesc&,
50 const GrProgramInfo&,
51 const GrGLPrecompiledProgram* = nullptr);
52
54
55 const GrCaps* caps() const override;
56
57 GrGLGpu* gpu() const { return fGpu; }
58
59private:
61
62 void addInputVars(const SkSL::Program::Interface&);
63 bool compileAndAttachShaders(const std::string& glsl,
64 GrGLuint programId,
66 SkTDArray<GrGLuint>* shaderIds,
67 bool shaderWasCached,
69
70 void computeCountsAndStrides(GrGLuint programID,
72 bool bindAttribLocations);
73 void storeShaderInCache(const SkSL::Program::Interface&,
74 GrGLuint programID,
75 const std::string shaders[],
76 bool isSkSL,
79 void bindProgramResourceLocations(GrGLuint programID);
80 void resolveProgramResourceLocations(GrGLuint programID, bool force);
81
82 // Subclasses create different programs
83 sk_sp<GrGLProgram> createProgram(GrGLuint programID);
84
85 GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
86 const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
87 GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
88
89 GrGLGpu* fGpu;
90 GrGLVaryingHandler fVaryingHandler;
91 GrGLUniformHandler fUniformHandler;
92
93 std::unique_ptr<GrGLProgram::Attribute[]> fAttributes;
94 int fVertexAttributeCnt;
95 int fInstanceAttributeCnt;
96 size_t fVertexStride;
97 size_t fInstanceStride;
98
99 // shader pulled from cache. Data is organized as:
100 // SkSL::Program::Interface interface
101 // int binaryFormat
102 // (all remaining bytes) char[] binary
103 sk_sp<SkData> fCached;
104
105 using INHERITED = GrGLSLProgramBuilder;
106};
107#endif
unsigned int GrGLuint
Definition: GrGLTypes.h:113
unsigned int GrGLenum
Definition: GrGLTypes.h:102
GLenum type
Definition: GrCaps.h:57
const GrCaps * caps() const override
static bool PrecompileProgram(GrDirectContext *, GrGLPrecompiledProgram *, const SkData &)
static sk_sp< GrGLProgram > CreateProgram(GrDirectContext *, const GrProgramDesc &, const GrProgramInfo &, const GrGLPrecompiledProgram *=nullptr)
GrGLGpu * gpu() const
GrGLSLProgramBuilder(const GrProgramDesc &, const GrProgramInfo &)
Definition: SkData.h:25
GrGLPrecompiledProgram(GrGLuint programID=0, SkSL::Program::Interface intf=SkSL::Program::Interface())
SkSL::Program::Interface fInterface