Chromium Code Reviews| Index: src/gpu/gl/GrGLProgram.h |
| diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h |
| index ce7e6b0987fa985e30386d73b95370c93b6685bc..b0692fc2f90c69a9de773d3f5904bb38fbcc2fec 100644 |
| --- a/src/gpu/gl/GrGLProgram.h |
| +++ b/src/gpu/gl/GrGLProgram.h |
| @@ -10,6 +10,7 @@ |
| #define GrGLProgram_DEFINED |
| #include "builders/GrGLProgramBuilder.h" |
| +#include "builders/GrGLESNvprProgramBuilder.h" |
| #include "GrDrawState.h" |
| #include "GrGLContext.h" |
| #include "GrGLProgramDesc.h" |
| @@ -21,7 +22,7 @@ |
| #include "SkXfermode.h" |
| class GrGLProcessor; |
| -class GrGLProgramEffects; |
| +class GrGLInstalledProcessors; |
| class GrGLProgramBuilder; |
| /** |
| @@ -39,12 +40,6 @@ public: |
| typedef GrGLProgramBuilder::BuiltinUniformHandles BuiltinUniformHandles; |
| - static GrGLProgram* Create(GrGpuGL* gpu, |
| - const GrGLProgramDesc& desc, |
| - const GrGeometryStage* geometryProcessor, |
| - const GrFragmentStage* colorStages[], |
| - const GrFragmentStage* coverageStages[]); |
| - |
| virtual ~GrGLProgram(); |
| /** |
| @@ -59,7 +54,7 @@ public: |
| */ |
| GrGLuint programID() const { return fProgramID; } |
| - bool hasVertexShader() const { return fHasVertexShader; } |
| + virtual bool hasVertexShader() const = 0; |
| /** |
| * Some GL state that is relevant to programs is not stored per-program. In particular color |
| @@ -160,15 +155,22 @@ public: |
| const GrDeviceCoordTexture* dstCopy, // can be NULL |
| SharedGLState*); |
| -private: |
| +protected: |
| typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| + typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; |
| GrGLProgram(GrGpuGL*, |
| const GrGLProgramDesc&, |
| - const GrGLProgramBuilder&); |
| + const BuiltinUniformHandles&, |
| + GrGLuint programID, |
| + const UniformInfoArray&, |
| + GrGLInstalledProcessors* geometryProcessor, |
| + GrGLInstalledProcessors* colorProcessors, |
| + GrGLInstalledProcessors* coverageProcessors); |
| // Sets the texture units for samplers. |
| void initSamplerUniforms(); |
| + void initSamplers(GrGLInstalledProcessors* processors, int* texUnitIdx); |
| // Helper for setData(). Makes GL calls to specify the initial color when there is not |
| // per-vertex colors. |
| @@ -178,29 +180,164 @@ private: |
| // per-vertex coverages. |
| void setCoverage(const GrOptDrawState&, GrColor coverage, SharedGLState*); |
| + virtual void postSetData(GrGpu::DrawType) = 0; |
| + |
| + // A templated helper to loop over effects, set the transforms(via subclass) and bind textures |
| + template <class ProcessorStage> |
| + void setData(const ProcessorStage* effectStages[], |
| + GrGLInstalledProcessors* installedProcessors) { |
| + int numEffects = installedProcessors->fGLProcessors.count(); |
| + SkASSERT(numEffects == installedProcessors->fTransforms.count()); |
| + SkASSERT(numEffects == installedProcessors->fSamplers.count()); |
| + for (int e = 0; e < numEffects; ++e) { |
| + const GrProcessor& effect = *effectStages[e]->getProcessor(); |
| + installedProcessors->fGLProcessors[e]->setData(fProgramDataManager, effect); |
| + this->setTransformData(*effectStages[e], e, installedProcessors); |
| + this->bindTextures(installedProcessors, effect, e); |
| + } |
| + } |
| + virtual void setTransformData(const GrProcessorStage& effectStage, |
| + int effectIdx, |
| + GrGLInstalledProcessors* pe) = 0; |
| + void bindTextures(const GrGLInstalledProcessors*, const GrProcessor&, int effectIdx); |
| + |
| // Helper for setData() that sets the view matrix and loads the render target height uniform |
| void setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, const GrOptDrawState&); |
| + virtual void setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, |
| + const GrOptDrawState& optState, |
| + const GrRenderTarget*, |
| + const SkISize&) = 0; |
| // these reflect the current values of uniforms (GL uniform values travel with program) |
| - MatrixState fMatrixState; |
| - GrColor fColor; |
| - GrColor fCoverage; |
| - int fDstCopyTexUnit; |
| + MatrixState fMatrixState; |
| + GrColor fColor; |
| + GrColor fCoverage; |
| + int fDstCopyTexUnit; |
| + BuiltinUniformHandles fBuiltinUniformHandles; |
| + GrGLuint fProgramID; |
| + |
| + // the installed effects |
| + SkAutoTUnref<GrGLInstalledProcessors> fGeometryProcessor; |
|
bsalomon
2014/09/29 15:43:19
Let's either line up all the members or none of th
joshua.litt
2014/09/29 21:05:22
done
|
| + SkAutoTUnref<GrGLInstalledProcessors> fColorEffects; |
| + SkAutoTUnref<GrGLInstalledProcessors> fCoverageEffects; |
| + |
| + GrGLProgramDesc fDesc; |
| + GrGpuGL* fGpu; |
| + GrGLProgramDataManager fProgramDataManager; |
| - BuiltinUniformHandles fBuiltinUniformHandles; |
| - SkAutoTUnref<GrGLProgramEffects> fGeometryProcessor; |
| - SkAutoTUnref<GrGLProgramEffects> fColorEffects; |
| - SkAutoTUnref<GrGLProgramEffects> fCoverageEffects; |
| - GrGLuint fProgramID; |
| - bool fHasVertexShader; |
| - int fTexCoordSetCnt; |
| + typedef SkRefCnt INHERITED; |
| +}; |
| - GrGLProgramDesc fDesc; |
| - GrGpuGL* fGpu; |
| +/* |
| + * Below are slight specializations of the program object for the different types of programs Skia |
| + * supports. Skia programs consist of at the very least a vertex and fragment shader. Old school |
| + * Nvpr only has a fragment shader, NvprES ignores the vertex shader, but both require specialized |
|
bsalomon
2014/09/29 15:43:19
Can we say NVPR 1.3+ rather than NvprES since the
joshua.litt
2014/09/29 21:05:22
done
|
| + * methods for setting transform data. |
| + */ |
| +class GrGLSkiaProgram : public GrGLProgram { |
| +public: |
| + virtual bool hasVertexShader() const SK_OVERRIDE { return true; } |
| - GrGLProgramDataManager fProgramDataManager; |
| +private: |
| + GrGLSkiaProgram(GrGpuGL*, |
| + const GrGLProgramDesc&, |
| + const BuiltinUniformHandles&, |
| + GrGLuint programID, |
| + const UniformInfoArray&, |
| + GrGLInstalledProcessors* geometryProcessor, |
| + GrGLInstalledProcessors* colorProcessors, |
| + GrGLInstalledProcessors* coverageProcessors); |
| + |
| + virtual void postSetData(GrGpu::DrawType) SK_OVERRIDE; |
| + virtual void setTransformData(const GrProcessorStage&, |
| + int effectIdx, |
| + GrGLInstalledProcessors*) SK_OVERRIDE; |
| + virtual void setMatrixAndRenderTargetHeight(GrGpu::DrawType, |
| + const GrOptDrawState&, |
| + const GrRenderTarget*, |
| + const SkISize&) SK_OVERRIDE; |
| + |
| + friend class GrGLSkiaProgramBuilder; |
| + |
| + typedef GrGLProgram INHERITED; |
| +}; |
| - typedef SkRefCnt INHERITED; |
| +/* |
| + * Both types of NVPR require setting the projection matrix through a special function call |
| + */ |
| +class GrGLNvprProgramBase : public GrGLProgram { |
| +protected: |
| + GrGLNvprProgramBase(GrGpuGL*, |
| + const GrGLProgramDesc&, |
| + const BuiltinUniformHandles&, |
| + GrGLuint programID, |
| + const UniformInfoArray&, |
| + GrGLInstalledProcessors* colorProcessors, |
| + GrGLInstalledProcessors* coverageProcessors); |
| + virtual void setMatrixAndRenderTargetHeight(GrGpu::DrawType, |
| + const GrOptDrawState&, |
| + const GrRenderTarget*, |
| + const SkISize&); |
| + |
| + typedef GrGLProgram INHERITED; |
| +}; |
| + |
| +class GrGLESNvprProgram : public GrGLNvprProgramBase { |
| +public: |
| + virtual bool hasVertexShader() const SK_OVERRIDE { return true; } |
| + |
| +private: |
| + typedef GrGLESNvprProgramBuilder::SeparableVaryingInfo SeparableVaryingInfo; |
| + typedef GrGLESNvprProgramBuilder::SeparableVaryingInfoArray SeparableVaryingInfoArray; |
| + GrGLESNvprProgram(GrGpuGL*, |
| + const GrGLProgramDesc&, |
| + const BuiltinUniformHandles&, |
| + GrGLuint programID, |
| + const UniformInfoArray&, |
| + GrGLInstalledProcessors* colorProcessors, |
| + GrGLInstalledProcessors* coverageProcessors, |
| + const SeparableVaryingInfoArray& separableVaryings); |
| + virtual void postSetData(GrGpu::DrawType) SK_OVERRIDE; |
| + virtual void setTransformData(const GrProcessorStage&, |
| + int effectIdx, |
| + GrGLInstalledProcessors*) SK_OVERRIDE; |
| + |
| + struct Varying { |
| + GrGLint fLocation; |
| + SkDEBUGCODE( |
| + GrSLType fType; |
| + ); |
| + }; |
| + SkTArray<Varying, true> fVaryings; |
| + |
| + friend class GrGLESNvprProgramBuilder; |
| + |
| + typedef GrGLNvprProgramBase INHERITED; |
| +}; |
| + |
| +class GrGLNvprProgram : public GrGLNvprProgramBase { |
| +public: |
| + virtual bool hasVertexShader() const SK_OVERRIDE { return false; } |
| + |
| +private: |
| + GrGLNvprProgram(GrGpuGL* gpu, |
| + const GrGLProgramDesc& desc, |
| + const BuiltinUniformHandles&, |
| + GrGLuint programID, |
| + const UniformInfoArray&, |
| + GrGLInstalledProcessors* colorProcessors, |
| + GrGLInstalledProcessors* coverageProcessors, |
| + int texCoordSetCnt); |
| + virtual void postSetData(GrGpu::DrawType) SK_OVERRIDE; |
| + virtual void setTransformData(const GrProcessorStage&, |
| + int effectIdx, |
| + GrGLInstalledProcessors*) SK_OVERRIDE; |
| + |
| + int fTexCoordSetCnt; |
| + |
| + friend class GrGLNvprProgramBuilder; |
| + |
| + typedef GrGLNvprProgramBase INHERITED; |
| }; |
| #endif |