Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
GrGLProgram Class Reference

#include <GrGLProgram.h>

Inheritance diagram for GrGLProgram:
SkRefCnt SkRefCntBase

Classes

struct  Attribute
 
struct  RenderTargetState
 

Public Types

using UniformHandle = GrGLSLProgramDataManager::UniformHandle
 
using UniformInfoArray = GrGLProgramDataManager::UniformInfoArray
 
using VaryingInfoArray = GrGLProgramDataManager::VaryingInfoArray
 

Public Member Functions

 ~GrGLProgram () override
 
void abandon ()
 
GrGLuint programID () const
 
void updateUniforms (const GrRenderTarget *, const GrProgramInfo &)
 
void bindTextures (const GrGeometryProcessor &, const GrSurfaceProxy *const geomProcTextures[], const GrPipeline &)
 
int vertexStride () const
 
int instanceStride () const
 
int numVertexAttributes () const
 
const AttributevertexAttribute (int i) const
 
int numInstanceAttributes () const
 
const AttributeinstanceAttribute (int i) const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< GrGLProgramMake (GrGLGpu *, const GrGLSLBuiltinUniformHandles &, GrGLuint programID, const UniformInfoArray &uniforms, const UniformInfoArray &textureSamplers, std::unique_ptr< GrGeometryProcessor::ProgramImpl >, std::unique_ptr< GrXferProcessor::ProgramImpl >, std::vector< std::unique_ptr< GrFragmentProcessor::ProgramImpl > > fps, std::unique_ptr< Attribute[]>, int vertexAttributeCnt, int instanceAttributeCnt, int vertexStride, int instanceStride)
 

Detailed Description

This class manages a GPU program and records per-program information. It also records the vertex and instance attribute layouts that are to be used with the program.

Definition at line 31 of file GrGLProgram.h.

Member Typedef Documentation

◆ UniformHandle

using GrGLProgram::UniformHandle = GrGLSLProgramDataManager::UniformHandle

Definition at line 45 of file GrGLProgram.h.

◆ UniformInfoArray

Definition at line 46 of file GrGLProgram.h.

◆ VaryingInfoArray

Definition at line 47 of file GrGLProgram.h.

Constructor & Destructor Documentation

◆ ~GrGLProgram()

GrGLProgram::~GrGLProgram ( )
override

Definition at line 87 of file GrGLProgram.cpp.

87 {
88 if (fProgramID) {
89 GL_CALL(DeleteProgram(fProgramID));
90 }
91}
#define GL_CALL(X)

Member Function Documentation

◆ abandon()

void GrGLProgram::abandon ( )

Call to abandon GL objects owned by this program.

Definition at line 93 of file GrGLProgram.cpp.

93 {
94 fProgramID = 0;
95}

◆ bindTextures()

void GrGLProgram::bindTextures ( const GrGeometryProcessor geomProc,
const GrSurfaceProxy *const  geomProcTextures[],
const GrPipeline pipeline 
)

Binds all geometry processor and fragment processor textures.

Definition at line 123 of file GrGLProgram.cpp.

125 {
126 // Bind textures from the geometry processor.
127 for (int i = 0; i < geomProc.numTextureSamplers(); ++i) {
128 SkASSERT(geomProcTextures[i]->asTextureProxy());
129 auto* overrideTexture = static_cast<GrGLTexture*>(geomProcTextures[i]->peekTexture());
130 fGpu->bindTexture(i, geomProc.textureSampler(i).samplerState(),
131 geomProc.textureSampler(i).swizzle(), overrideTexture);
132 }
133 int nextTexSamplerIdx = geomProc.numTextureSamplers();
134 // Bind texture from the destination proxy view.
135 GrTexture* dstTexture = pipeline.peekDstTexture();
136 if (dstTexture) {
137 fGpu->bindTexture(nextTexSamplerIdx++, GrSamplerState::Filter::kNearest,
138 pipeline.dstProxyView().swizzle(), static_cast<GrGLTexture*>(dstTexture));
139 }
140 // Bind textures from all of the fragment processors.
141 pipeline.visitTextureEffects([&](const GrTextureEffect& te) {
142 GrSamplerState samplerState = te.samplerState();
143 skgpu::Swizzle swizzle = te.view().swizzle();
144 auto* texture = static_cast<GrGLTexture*>(te.texture());
145 fGpu->bindTexture(nextTexSamplerIdx++, samplerState, swizzle, texture);
146 });
147
148 SkASSERT(nextTexSamplerIdx == fNumTextureSamplers);
149}
#define SkASSERT(cond)
Definition SkAssert.h:116
void bindTexture(int unitIdx, GrSamplerState samplerState, const skgpu::Swizzle &, GrGLTexture *)
Definition GrGLGpu.cpp:2815
const skgpu::Swizzle & swizzle() const
const TextureSampler & textureSampler(int index) const
void visitTextureEffects(const std::function< void(const GrTextureEffect &)> &) const
const GrSurfaceProxyView & dstProxyView() const
Definition GrPipeline.h:138
GrTexture * peekDstTexture() const
Definition GrPipeline.h:145
skgpu::Swizzle swizzle() const
GrTexture * peekTexture() const
const GrSurfaceProxyView & view() const
GrTexture * texture() const
GrSamplerState samplerState() const
FlTexture * texture

◆ instanceAttribute()

const Attribute & GrGLProgram::instanceAttribute ( int  i) const
inline

Definition at line 121 of file GrGLProgram.h.

121 {
122 SkASSERT(i >= 0 && i < fInstanceAttributeCnt);
123 return fAttributes[i + fVertexAttributeCnt];
124 }

◆ instanceStride()

int GrGLProgram::instanceStride ( ) const
inline

Definition at line 112 of file GrGLProgram.h.

112{ return fInstanceStride; }

◆ Make()

sk_sp< GrGLProgram > GrGLProgram::Make ( GrGLGpu gpu,
const GrGLSLBuiltinUniformHandles builtinUniforms,
GrGLuint  programID,
const UniformInfoArray uniforms,
const UniformInfoArray textureSamplers,
std::unique_ptr< GrGeometryProcessor::ProgramImpl gpImpl,
std::unique_ptr< GrXferProcessor::ProgramImpl xpImpl,
std::vector< std::unique_ptr< GrFragmentProcessor::ProgramImpl > >  fps,
std::unique_ptr< Attribute[]>  attributes,
int  vertexAttributeCnt,
int  instanceAttributeCnt,
int  vertexStride,
int  instanceStride 
)
static

The attribute array consists of vertexAttributeCnt + instanceAttributeCnt elements with the vertex attributes preceding the instance attributes.

Definition at line 27 of file GrGLProgram.cpp.

40 {
41 sk_sp<GrGLProgram> program(new GrGLProgram(gpu,
42 builtinUniforms,
44 uniforms,
45 textureSamplers,
46 std::move(gpImpl),
47 std::move(xpImpl),
48 std::move(fpImpls),
49 std::move(attributes),
50 vertexAttributeCnt,
51 instanceAttributeCnt,
54 // Assign texture units to sampler uniforms one time up front.
55 gpu->flushProgram(program);
56 program->fProgramDataManager.setSamplerUniforms(textureSamplers, 0);
57 return program;
58}
void flushProgram(sk_sp< GrGLProgram >)
Definition GrGLGpu.cpp:2106
int instanceStride() const
GrGLuint programID() const
Definition GrGLProgram.h:78
int vertexStride() const

◆ numInstanceAttributes()

int GrGLProgram::numInstanceAttributes ( ) const
inline

Definition at line 120 of file GrGLProgram.h.

120{ return fInstanceAttributeCnt; }

◆ numVertexAttributes()

int GrGLProgram::numVertexAttributes ( ) const
inline

Definition at line 114 of file GrGLProgram.h.

114{ return fVertexAttributeCnt; }

◆ programID()

GrGLuint GrGLProgram::programID ( ) const
inline

Gets the GL program ID for this program.

Definition at line 78 of file GrGLProgram.h.

78{ return fProgramID; }

◆ updateUniforms()

void GrGLProgram::updateUniforms ( const GrRenderTarget renderTarget,
const GrProgramInfo programInfo 
)

This function uploads uniforms and calls each GrGLSL*Processor's setData.

It is the caller's responsibility to ensure the program is bound before calling.

Definition at line 99 of file GrGLProgram.cpp.

100 {
101 this->setRenderTargetState(renderTarget, programInfo.origin(), programInfo.geomProc());
102
103 // we set the uniforms for installed processors in a generic way, but subclasses of GLProgram
104 // determine how to set coord transforms
105
106 // We must bind to texture units in the same order in which we set the uniforms in
107 // GrGLProgramDataManager. That is, we bind textures for processors in this order:
108 // primProc, fragProcs, XP.
109 fGPImpl->setData(fProgramDataManager, *fGpu->caps()->shaderCaps(), programInfo.geomProc());
110
111 for (int i = 0; i < programInfo.pipeline().numFragmentProcessors(); ++i) {
112 const auto& fp = programInfo.pipeline().getFragmentProcessor(i);
113 fp.visitWithImpls([&](const GrFragmentProcessor& fp,
115 impl.setData(fProgramDataManager, fp);
116 }, *fFPImpls[i]);
117 }
118
119 programInfo.pipeline().setDstTextureUniforms(fProgramDataManager, &fBuiltinUniformHandles);
120 fXPImpl->setData(fProgramDataManager, programInfo.pipeline().getXferProcessor());
121}
const GrShaderCaps * shaderCaps() const
Definition GrCaps.h:63
void setData(const GrGLSLProgramDataManager &pdman, const GrFragmentProcessor &processor)
const GrCaps * caps() const
Definition GrGpu.h:73
void setDstTextureUniforms(const GrGLSLProgramDataManager &pdm, GrGLSLBuiltinUniformHandles *fBuiltinUniformHandles) const
const GrFragmentProcessor & getFragmentProcessor(int idx) const
Definition GrPipeline.h:157
const GrXferProcessor & getXferProcessor() const
Definition GrPipeline.h:116
GrSurfaceOrigin origin() const
const GrPipeline & pipeline() const
const GrGeometryProcessor & geomProc() const
const uint32_t fp

◆ vertexAttribute()

const Attribute & GrGLProgram::vertexAttribute ( int  i) const
inline

Definition at line 115 of file GrGLProgram.h.

115 {
116 SkASSERT(i >= 0 && i < fVertexAttributeCnt);
117 return fAttributes[i];
118 }

◆ vertexStride()

int GrGLProgram::vertexStride ( ) const
inline

Definition at line 111 of file GrGLProgram.h.

111{ return fVertexStride; }

The documentation for this class was generated from the following files: