blob: 0b24144d8459542a7192bdf24005b7c2d6171b4e [file] [log] [blame]
commit-bot@chromium.org261dc562013-10-04 15:42:56 +00001/*
2 * Copyright 2013 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
joshualitt249af152014-09-15 11:41:13 -07008#ifndef GrGLGeometryProcessor_DEFINED
9#define GrGLGeometryProcessor_DEFINED
commit-bot@chromium.org261dc562013-10-04 15:42:56 +000010
joshualittb0a8a372014-09-23 09:50:21 -070011#include "GrGLProcessor.h"
commit-bot@chromium.org261dc562013-10-04 15:42:56 +000012
joshualitt87f48d92014-12-04 10:41:40 -080013class GrBatchTracker;
joshualitta5305a12014-10-10 17:47:00 -070014class GrGLGPBuilder;
15
commit-bot@chromium.org261dc562013-10-04 15:42:56 +000016/**
17 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, then it must inherit
18 * from this class. Since paths don't have vertices, this class is only meant to be used internally
19 * by skia, for special cases.
20 */
joshualitteb2a6762014-12-04 11:35:33 -080021class GrGLGeometryProcessor {
commit-bot@chromium.org261dc562013-10-04 15:42:56 +000022public:
joshualittee2af952014-12-30 09:04:15 -080023 GrGLGeometryProcessor() : fViewMatrixName(NULL) { fViewMatrix = SkMatrix::InvalidMatrix(); }
joshualitteb2a6762014-12-04 11:35:33 -080024 virtual ~GrGLGeometryProcessor() {}
commit-bot@chromium.org261dc562013-10-04 15:42:56 +000025
joshualitt9b989322014-12-15 14:16:27 -080026 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
joshualitteb2a6762014-12-04 11:35:33 -080027 typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray;
joshualitt9b989322014-12-15 14:16:27 -080028
joshualittc369e7c2014-10-22 10:56:26 -070029 struct EmitArgs {
30 EmitArgs(GrGLGPBuilder* pb,
joshualitt9b989322014-12-15 14:16:27 -080031 const GrPrimitiveProcessor& gp,
joshualitt87f48d92014-12-04 10:41:40 -080032 const GrBatchTracker& bt,
joshualitt2dd1ae02014-12-03 06:24:10 -080033 const char* outputColor,
34 const char* outputCoverage,
joshualittc369e7c2014-10-22 10:56:26 -070035 const TextureSamplerArray& samplers)
joshualitt2dd1ae02014-12-03 06:24:10 -080036 : fPB(pb)
37 , fGP(gp)
joshualitt87f48d92014-12-04 10:41:40 -080038 , fBT(bt)
joshualitt2dd1ae02014-12-03 06:24:10 -080039 , fOutputColor(outputColor)
40 , fOutputCoverage(outputCoverage)
41 , fSamplers(samplers) {}
joshualittc369e7c2014-10-22 10:56:26 -070042 GrGLGPBuilder* fPB;
joshualitt9b989322014-12-15 14:16:27 -080043 const GrPrimitiveProcessor& fGP;
joshualitt87f48d92014-12-04 10:41:40 -080044 const GrBatchTracker& fBT;
joshualitt2dd1ae02014-12-03 06:24:10 -080045 const char* fOutputColor;
46 const char* fOutputCoverage;
joshualittc369e7c2014-10-22 10:56:26 -070047 const TextureSamplerArray& fSamplers;
48 };
joshualitt9b989322014-12-15 14:16:27 -080049
commit-bot@chromium.org261dc562013-10-04 15:42:56 +000050 /**
51 * This is similar to emitCode() in the base class, except it takes a full shader builder.
52 * This allows the effect subclass to emit vertex code.
53 */
joshualittc369e7c2014-10-22 10:56:26 -070054 virtual void emitCode(const EmitArgs&) = 0;
joshualitt30ba4362014-08-21 20:18:45 -070055
joshualitt87f48d92014-12-04 10:41:40 -080056 /** A GrGLGeometryProcessor instance can be reused with any GrGLGeometryProcessor that produces
57 the same stage key; this function reads data from a GrGLGeometryProcessor and uploads any
58 uniform variables required by the shaders created in emitCode(). The GrGeometryProcessor
59 parameter is guaranteed to be of the same type that created this GrGLGeometryProcessor and
60 to have an identical processor key as the one that created this GrGLGeometryProcessor. */
61 virtual void setData(const GrGLProgramDataManager&,
joshualitt9b989322014-12-15 14:16:27 -080062 const GrPrimitiveProcessor&,
joshualitt87f48d92014-12-04 10:41:40 -080063 const GrBatchTracker&) = 0;
64
joshualitt9b989322014-12-15 14:16:27 -080065protected:
66 /** a helper which can setup vertex, constant, or uniform color depending on inputType.
67 * This function will only do the minimum required to emit the correct shader code. If
68 * inputType == attribute, then colorAttr must not be NULL. Likewise, if inputType == Uniform
69 * then colorUniform must not be NULL.
70 */
71 void setupColorPassThrough(GrGLGPBuilder* pb,
72 GrGPInput inputType,
73 const char* inputName,
74 const GrGeometryProcessor::GrAttribute* colorAttr,
75 UniformHandle* colorUniform);
76
joshualittee2af952014-12-30 09:04:15 -080077 const char* uViewM() const { return fViewMatrixName; }
78
79 /** a helper function to setup the uniform handle for the uniform view matrix */
80 void addUniformViewMatrix(GrGLGPBuilder*);
81
82
83 /** a helper function to upload a uniform viewmatrix.
84 * TODO we can remove this function when we have deferred geometry in place
85 */
86 void setUniformViewMatrix(const GrGLProgramDataManager&,
87 const SkMatrix& viewMatrix);
88
commit-bot@chromium.org261dc562013-10-04 15:42:56 +000089private:
joshualittee2af952014-12-30 09:04:15 -080090 UniformHandle fViewMatrixUniform;
91 SkMatrix fViewMatrix;
92 const char* fViewMatrixName;
93
joshualittb0a8a372014-09-23 09:50:21 -070094 typedef GrGLProcessor INHERITED;
commit-bot@chromium.org261dc562013-10-04 15:42:56 +000095};
96
97#endif