Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: src/gpu/gl/GrGLProgram.h

Issue 611653002: Cleanup of shader building system (Closed) Base URL: https://skia.googlesource.com/skia.git@solo_gp
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/gl/GrGLProcessor.h ('k') | src/gpu/gl/GrGLProgram.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLProgram.h
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index 21593e351f2528523fec8bb2919dfa317bd789b8..fc441e5d76f9fe3e123fc5dad53ae078e4ffc9db 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/GrGLNvprProgramBuilder.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,13 +40,6 @@ public:
typedef GrGLProgramBuilder::BuiltinUniformHandles BuiltinUniformHandles;
- static GrGLProgram* Create(GrGpuGL* gpu,
- const GrOptDrawState& optState,
- const GrGLProgramDesc& desc,
- const GrGeometryStage* geometryProcessor,
- const GrFragmentStage* colorStages[],
- const GrFragmentStage* coverageStages[]);
-
virtual ~GrGLProgram();
/**
@@ -60,7 +54,10 @@ public:
*/
GrGLuint programID() const { return fProgramID; }
- bool hasVertexShader() const { return fHasVertexShader; }
+ /*
+ * The base class always has a vertex shader, only the NVPR variants may omit a vertex shader
+ */
+ virtual bool hasVertexShader() const { return true; }
/**
* Some GL state that is relevant to programs is not stored per-program. In particular color
@@ -161,15 +158,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.
@@ -179,29 +183,134 @@ private:
// per-vertex coverages.
void setCoverage(const GrOptDrawState&, GrColor coverage, SharedGLState*);
+ // 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);
+ void bindTextures(const GrGLInstalledProcessors*, const GrProcessor&, int effectIdx);
+
+ /*
+ * Legacy NVPR needs a hook here to flush path tex gen settings.
+ * TODO when legacy nvpr is removed, remove this call.
+ */
+ virtual void didSetData(GrGpu::DrawType);
+
// Helper for setData() that sets the view matrix and loads the render target height uniform
- void setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, const GrOptDrawState&);
+ void setMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDrawState&);
+ virtual void onSetMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDrawState&);
// 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;
- BuiltinUniformHandles fBuiltinUniformHandles;
- SkAutoTUnref<GrGLProgramEffects> fGeometryProcessor;
- SkAutoTUnref<GrGLProgramEffects> fColorEffects;
- SkAutoTUnref<GrGLProgramEffects> fCoverageEffects;
- GrGLuint fProgramID;
- bool fHasVertexShader;
- int fTexCoordSetCnt;
+ // the installed effects
+ SkAutoTUnref<GrGLInstalledProcessors> fGeometryProcessor;
+ SkAutoTUnref<GrGLInstalledProcessors> fColorEffects;
+ SkAutoTUnref<GrGLInstalledProcessors> fCoverageEffects;
- GrGLProgramDesc fDesc;
- GrGpuGL* fGpu;
+ GrGLProgramDesc fDesc;
+ GrGpuGL* fGpu;
+ GrGLProgramDataManager fProgramDataManager;
- GrGLProgramDataManager fProgramDataManager;
+ friend class GrGLProgramBuilder;
typedef SkRefCnt INHERITED;
};
+/*
+ * Below are slight specializations of the program object for the different types of programs
+ * The default GrGL programs consist of at the very least a vertex and fragment shader.
+ * Legacy Nvpr only has a fragment shader, 1.3+ Nvpr ignores the vertex shader, but both require
+ * specialized methods for setting transform data. Both types of NVPR also 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 onSetMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDrawState&);
+
+ typedef GrGLProgram INHERITED;
+};
+
+class GrGLNvprProgram : public GrGLNvprProgramBase {
+public:
+ virtual bool hasVertexShader() const SK_OVERRIDE { return true; }
+
+private:
+ typedef GrGLNvprProgramBuilder::SeparableVaryingInfo SeparableVaryingInfo;
+ typedef GrGLNvprProgramBuilder::SeparableVaryingInfoArray SeparableVaryingInfoArray;
+ GrGLNvprProgram(GrGpuGL*,
+ const GrGLProgramDesc&,
+ const BuiltinUniformHandles&,
+ GrGLuint programID,
+ const UniformInfoArray&,
+ GrGLInstalledProcessors* colorProcessors,
+ GrGLInstalledProcessors* coverageProcessors,
+ const SeparableVaryingInfoArray& separableVaryings);
+ virtual void didSetData(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 GrGLNvprProgramBuilder;
+
+ typedef GrGLNvprProgramBase INHERITED;
+};
+
+class GrGLLegacyNvprProgram : public GrGLNvprProgramBase {
+public:
+ virtual bool hasVertexShader() const SK_OVERRIDE { return false; }
+
+private:
+ GrGLLegacyNvprProgram(GrGpuGL* gpu,
+ const GrGLProgramDesc& desc,
+ const BuiltinUniformHandles&,
+ GrGLuint programID,
+ const UniformInfoArray&,
+ GrGLInstalledProcessors* colorProcessors,
+ GrGLInstalledProcessors* coverageProcessors,
+ int texCoordSetCnt);
+ virtual void didSetData(GrGpu::DrawType) SK_OVERRIDE;
+ virtual void setTransformData(const GrProcessorStage&,
+ int effectIdx,
+ GrGLInstalledProcessors*) SK_OVERRIDE;
+
+ int fTexCoordSetCnt;
+
+ friend class GrGLLegacyNvprProgramBuilder;
+
+ typedef GrGLNvprProgramBase INHERITED;
+};
+
#endif
« no previous file with comments | « src/gpu/gl/GrGLProcessor.h ('k') | src/gpu/gl/GrGLProgram.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698