blob: 76f9c9006f217d5cc9c49a3f67949f6198d5fa04 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
junov@google.comf93e7172011-03-31 21:26:24 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
junov@google.comf93e7172011-03-31 21:26:24 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
junov@google.comf93e7172011-03-31 21:26:24 +000010#ifndef GrGLProgram_DEFINED
11#define GrGLProgram_DEFINED
12
tomhudson@google.comdd182cb2012-02-10 21:01:00 +000013#include "../GrDrawState.h"
bsalomon@google.com96399942012-02-13 14:39:16 +000014#include "GrGLContextInfo.h"
tomhudson@google.com086e5352011-12-08 14:44:10 +000015#include "GrGLSL.h"
tomhudson@google.comdd182cb2012-02-10 21:01:00 +000016#include "../GrStringBuilder.h"
17#include "../GrGpu.h"
junov@google.comf93e7172011-03-31 21:26:24 +000018
Scroggo97c88c22011-05-11 14:05:25 +000019#include "SkXfermode.h"
20
junov@google.comf93e7172011-03-31 21:26:24 +000021class GrBinHashKeyBuilder;
junov@google.comd31cbc42011-05-17 17:01:17 +000022
bsalomon@google.com4fa66942011-09-20 19:06:12 +000023struct ShaderCodeSegments;
junov@google.comf93e7172011-03-31 21:26:24 +000024
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000025// optionally compile the experimental GS code. Set to GR_DEBUG
26// so that debug build bots will execute the code.
27#define GR_GL_EXPERIMENTAL_GS GR_DEBUG
28
junov@google.comf93e7172011-03-31 21:26:24 +000029/**
30 * This class manages a GPU program and records per-program information.
31 * We can specify the attribute locations so that they are constant
32 * across our shaders. But the driver determines the uniform locations
33 * at link time. We don't need to remember the sampler uniform location
34 * because we will bind a texture slot to it and never change it
35 * Uniforms are program-local so we can't rely on fHWState to hold the
36 * previous uniform state after a program change.
37 */
38class GrGLProgram {
39public:
bsalomon@google.com4fa66942011-09-20 19:06:12 +000040
junov@google.comf93e7172011-03-31 21:26:24 +000041 class CachedData;
42
43 GrGLProgram();
44 ~GrGLProgram();
45
46 /**
junov@google.comf93e7172011-03-31 21:26:24 +000047 * This is the heavy initilization routine for building a GLProgram.
48 * The result of heavy init is not stored in datamembers of GrGLProgam,
49 * but in a separate cacheable container.
50 */
bsalomon@google.com96399942012-02-13 14:39:16 +000051 bool genProgram(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +000052 CachedData* programData) const;
junov@google.comf93e7172011-03-31 21:26:24 +000053
bsalomon@google.com271cffc2011-05-20 14:13:56 +000054 /**
55 * The shader may modify the blend coeffecients. Params are in/out
56 */
57 void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const;
58
59 /**
bsalomon@google.comb5b5eaf2011-10-19 13:25:46 +000060 * Attribute indices. These should not overlap. Matrices consume 3 slots.
bsalomon@google.com271cffc2011-05-20 14:13:56 +000061 */
bsalomon@google.com91961302011-05-09 18:39:58 +000062 static int PositionAttributeIdx() { return 0; }
63 static int TexCoordAttributeIdx(int tcIdx) { return 1 + tcIdx; }
tomhudson@google.com93813632011-10-27 20:21:16 +000064 static int ColorAttributeIdx() { return 1 + GrDrawState::kMaxTexCoords; }
bsalomon@google.coma3108262011-10-10 14:08:47 +000065 static int CoverageAttributeIdx() {
tomhudson@google.com93813632011-10-27 20:21:16 +000066 return 2 + GrDrawState::kMaxTexCoords;
bsalomon@google.coma3108262011-10-10 14:08:47 +000067 }
tomhudson@google.com93813632011-10-27 20:21:16 +000068 static int EdgeAttributeIdx() { return 3 + GrDrawState::kMaxTexCoords; }
bsalomon@google.comaeb21602011-08-30 18:13:44 +000069
tomhudson@google.com0d831722011-06-02 15:37:14 +000070 static int ViewMatrixAttributeIdx() {
tomhudson@google.com93813632011-10-27 20:21:16 +000071 return 4 + GrDrawState::kMaxTexCoords;
bsalomon@google.com91961302011-05-09 18:39:58 +000072 }
tomhudson@google.com0d831722011-06-02 15:37:14 +000073 static int TextureMatrixAttributeIdx(int stage) {
tomhudson@google.com93813632011-10-27 20:21:16 +000074 return 7 + GrDrawState::kMaxTexCoords + 3 * stage;
bsalomon@google.com91961302011-05-09 18:39:58 +000075 }
76
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +000077public:
junov@google.comf93e7172011-03-31 21:26:24 +000078
tomhudson@google.com0d831722011-06-02 15:37:14 +000079 // Parameters that affect code generation
80 // These structs should be kept compact; they are the input to an
81 // expensive hash key generator.
junov@google.comf93e7172011-03-31 21:26:24 +000082 struct ProgramDesc {
bsalomon@google.com4be283f2011-04-19 21:15:09 +000083 ProgramDesc() {
84 // since we use this as part of a key we can't have any unitialized
85 // padding
86 memset(this, 0, sizeof(ProgramDesc));
87 }
88
bsalomon@google.coma91e9232012-02-23 15:39:54 +000089 enum OutputConfig {
bsalomon@google.comc4364992011-11-07 15:54:49 +000090 // PM-color OR color with no alpha channel
bsalomon@google.coma91e9232012-02-23 15:39:54 +000091 kPremultiplied_OutputConfig,
92 // nonPM-color with alpha channel. Round components up after
93 // dividing by alpha. Assumes output is 8 bits for r, g, and b
94 kUnpremultiplied_RoundUp_OutputConfig,
95 // nonPM-color with alpha channel. Round components down after
96 // dividing by alpha. Assumes output is 8 bits for r, g, and b
97 kUnpremultiplied_RoundDown_OutputConfig,
bsalomon@google.comc4364992011-11-07 15:54:49 +000098
bsalomon@google.coma91e9232012-02-23 15:39:54 +000099 kOutputConfigCnt
bsalomon@google.comc4364992011-11-07 15:54:49 +0000100 };
101
tomhudson@google.com0d831722011-06-02 15:37:14 +0000102 struct StageDesc {
103 enum OptFlagBits {
104 kNoPerspective_OptFlagBit = 1 << 0,
105 kIdentityMatrix_OptFlagBit = 1 << 1,
106 kCustomTextureDomain_OptFlagBit = 1 << 2,
107 kIsEnabled_OptFlagBit = 1 << 7
108 };
tomhudson@google.com0d831722011-06-02 15:37:14 +0000109 enum FetchMode {
110 kSingle_FetchMode,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000111 k2x2_FetchMode,
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000112 kConvolution_FetchMode,
senorblanco@chromium.org05054f12012-03-02 21:05:45 +0000113 kErode_FetchMode,
114 kDilate_FetchMode,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000115
116 kFetchModeCnt,
tomhudson@google.com0d831722011-06-02 15:37:14 +0000117 };
bsalomon@google.com0a97be22011-11-08 19:20:57 +0000118 /**
bsalomon@google.com74b98712011-11-11 19:46:16 +0000119 Flags set based on a src texture's pixel config. The operations
120 described are performed after reading a texel.
bsalomon@google.com0a97be22011-11-08 19:20:57 +0000121 */
bsalomon@google.com74b98712011-11-11 19:46:16 +0000122 enum InConfigFlags {
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000123 kNone_InConfigFlag = 0x0,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000124
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000125 /**
bsalomon@google.com74b98712011-11-11 19:46:16 +0000126 Swap the R and B channels. This is incompatible with
127 kSmearAlpha. It is prefereable to perform the swizzle outside
128 the shader using GL_ARB_texture_swizzle if possible rather
129 than setting this flag.
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000130 */
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000131 kSwapRAndB_InConfigFlag = 0x1,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000132
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000133 /**
bsalomon@google.com74b98712011-11-11 19:46:16 +0000134 Smear alpha across all four channels. This is incompatible with
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000135 kSwapRAndB and kMulRGBByAlpha*. It is prefereable to perform
136 the smear outside the shader using GL_ARB_texture_swizzle if
bsalomon@google.com74b98712011-11-11 19:46:16 +0000137 possible rather than setting this flag.
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000138 */
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000139 kSmearAlpha_InConfigFlag = 0x2,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000140
141 /**
142 Multiply r,g,b by a after texture reads. This flag incompatible
143 with kSmearAlpha and may only be used with FetchMode kSingle.
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000144
145 It is assumed the src texture has 8bit color components. After
146 reading the texture one version rounds up to the next multiple
147 of 1/255.0 and the other rounds down. At most one of these
148 flags may be set.
bsalomon@google.com74b98712011-11-11 19:46:16 +0000149 */
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000150 kMulRGBByAlpha_RoundUp_InConfigFlag = 0x4,
151 kMulRGBByAlpha_RoundDown_InConfigFlag = 0x8,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000152
153 kDummyInConfigFlag,
154 kInConfigBitMask = (kDummyInConfigFlag-1) |
155 (kDummyInConfigFlag-2)
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000156 };
tomhudson@google.com0d831722011-06-02 15:37:14 +0000157 enum CoordMapping {
158 kIdentity_CoordMapping,
159 kRadialGradient_CoordMapping,
160 kSweepGradient_CoordMapping,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000161 kRadial2Gradient_CoordMapping,
bsalomon@google.com22c5dea2011-07-07 14:38:03 +0000162 // need different shader computation when quadratic
163 // eq describing the gradient degenerates to a linear eq.
164 kRadial2GradientDegenerate_CoordMapping,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000165 kCoordMappingCnt
tomhudson@google.com0d831722011-06-02 15:37:14 +0000166 };
junov@google.comf93e7172011-03-31 21:26:24 +0000167
tomhudson@google.com0d831722011-06-02 15:37:14 +0000168 uint8_t fOptFlags;
bsalomon@google.com74b98712011-11-11 19:46:16 +0000169 uint8_t fInConfigFlags; // bitfield of InConfigFlags values
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000170 uint8_t fFetchMode; // casts to enum FetchMode
tomhudson@google.com0d831722011-06-02 15:37:14 +0000171 uint8_t fCoordMapping; // casts to enum CoordMapping
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000172 uint8_t fKernelWidth;
tomhudson@google.com0d831722011-06-02 15:37:14 +0000173
bsalomon@google.com74b98712011-11-11 19:46:16 +0000174 GR_STATIC_ASSERT((InConfigFlags)(uint8_t)kInConfigBitMask ==
175 kInConfigBitMask);
176
tomhudson@google.com0d831722011-06-02 15:37:14 +0000177 inline bool isEnabled() const {
bsalomon@google.comc2c9b972011-10-03 13:17:22 +0000178 return SkToBool(fOptFlags & kIsEnabled_OptFlagBit);
tomhudson@google.com0d831722011-06-02 15:37:14 +0000179 }
180 inline void setEnabled(bool newValue) {
181 if (newValue) {
182 fOptFlags |= kIsEnabled_OptFlagBit;
183 } else {
184 fOptFlags &= ~kIsEnabled_OptFlagBit;
185 }
186 }
187 };
188
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000189 // Specifies where the intitial color comes from before the stages are
190 // applied.
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000191 enum ColorInput {
192 kSolidWhite_ColorInput,
193 kTransBlack_ColorInput,
194 kAttribute_ColorInput,
195 kUniform_ColorInput,
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000196
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000197 kColorInputCnt
tomhudson@google.com0d831722011-06-02 15:37:14 +0000198 };
199 // Dual-src blending makes use of a secondary output color that can be
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000200 // used as a per-pixel blend coeffecient. This controls whether a
201 // secondary source is output and what value it holds.
202 enum DualSrcOutput {
203 kNone_DualSrcOutput,
204 kCoverage_DualSrcOutput,
205 kCoverageISA_DualSrcOutput,
206 kCoverageISC_DualSrcOutput,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000207
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000208 kDualSrcOutputCnt
tomhudson@google.com0d831722011-06-02 15:37:14 +0000209 };
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000210
tomhudson@google.com93813632011-10-27 20:21:16 +0000211 GrDrawState::VertexEdgeType fVertexEdgeType;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000212
tomhudson@google.com0d831722011-06-02 15:37:14 +0000213 // stripped of bits that don't affect prog generation
214 GrVertexLayout fVertexLayout;
junov@google.comf93e7172011-03-31 21:26:24 +0000215
tomhudson@google.com93813632011-10-27 20:21:16 +0000216 StageDesc fStages[GrDrawState::kNumStages];
Scroggo97c88c22011-05-11 14:05:25 +0000217
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000218 // To enable experimental geometry shader code (not for use in
219 // production)
220#if GR_GL_EXPERIMENTAL_GS
221 bool fExperimentalGS;
222#endif
223
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000224 uint8_t fColorInput; // casts to enum ColorInput
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000225 uint8_t fCoverageInput; // casts to enum CoverageInput
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000226 uint8_t fOutputConfig; // casts to enum OutputConfig
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000227 uint8_t fDualSrcOutput; // casts to enum DualSrcOutput
tomhudson@google.com0d831722011-06-02 15:37:14 +0000228 int8_t fFirstCoverageStage;
229 SkBool8 fEmitsPointSize;
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +0000230 SkBool8 fEdgeAAConcave;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000231 SkBool8 fColorMatrixEnabled;
junov@google.comf93e7172011-03-31 21:26:24 +0000232
tomhudson@google.com0d831722011-06-02 15:37:14 +0000233 int8_t fEdgeAANumEdges;
234 uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000235 int8_t fPadding[3];
junov@google.comf93e7172011-03-31 21:26:24 +0000236
junov@google.comf93e7172011-03-31 21:26:24 +0000237 } fProgramDesc;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000238 GR_STATIC_ASSERT(!(sizeof(ProgramDesc) % 4));
junov@google.comf93e7172011-03-31 21:26:24 +0000239
bsalomon@google.com22c5dea2011-07-07 14:38:03 +0000240 // for code readability
241 typedef ProgramDesc::StageDesc StageDesc;
242
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000243private:
244
245 const ProgramDesc& getDesc() { return fProgramDesc; }
senorblanco@chromium.orgb3a39b52012-01-05 18:28:56 +0000246 const char* adjustInColor(const GrStringBuilder& inColor) const;
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000247
junov@google.comf93e7172011-03-31 21:26:24 +0000248public:
bsalomon@google.com91961302011-05-09 18:39:58 +0000249 enum {
250 kUnusedUniform = -1,
251 kSetAsAttribute = 1000,
252 };
253
junov@google.comf93e7172011-03-31 21:26:24 +0000254 struct StageUniLocations {
255 GrGLint fTextureMatrixUni;
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000256 GrGLint fNormalizedTexelSizeUni;
junov@google.comf93e7172011-03-31 21:26:24 +0000257 GrGLint fSamplerUni;
258 GrGLint fRadial2Uni;
junov@google.com6acc9b32011-05-16 18:32:07 +0000259 GrGLint fTexDomUni;
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000260 GrGLint fKernelUni;
261 GrGLint fImageIncrementUni;
bsalomon@google.com91961302011-05-09 18:39:58 +0000262 void reset() {
263 fTextureMatrixUni = kUnusedUniform;
264 fNormalizedTexelSizeUni = kUnusedUniform;
265 fSamplerUni = kUnusedUniform;
266 fRadial2Uni = kUnusedUniform;
junov@google.com6acc9b32011-05-16 18:32:07 +0000267 fTexDomUni = kUnusedUniform;
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000268 fKernelUni = kUnusedUniform;
269 fImageIncrementUni = kUnusedUniform;
bsalomon@google.com91961302011-05-09 18:39:58 +0000270 }
junov@google.comf93e7172011-03-31 21:26:24 +0000271 };
272
273 struct UniLocations {
274 GrGLint fViewMatrixUni;
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000275 GrGLint fColorUni;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000276 GrGLint fCoverageUni;
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000277 GrGLint fEdgesUni;
Scroggo97c88c22011-05-11 14:05:25 +0000278 GrGLint fColorFilterUni;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000279 GrGLint fColorMatrixUni;
280 GrGLint fColorMatrixVecUni;
tomhudson@google.com93813632011-10-27 20:21:16 +0000281 StageUniLocations fStages[GrDrawState::kNumStages];
bsalomon@google.com91961302011-05-09 18:39:58 +0000282 void reset() {
283 fViewMatrixUni = kUnusedUniform;
284 fColorUni = kUnusedUniform;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000285 fCoverageUni = kUnusedUniform;
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000286 fEdgesUni = kUnusedUniform;
Scroggo97c88c22011-05-11 14:05:25 +0000287 fColorFilterUni = kUnusedUniform;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000288 fColorMatrixUni = kUnusedUniform;
289 fColorMatrixVecUni = kUnusedUniform;
tomhudson@google.com93813632011-10-27 20:21:16 +0000290 for (int s = 0; s < GrDrawState::kNumStages; ++s) {
bsalomon@google.com91961302011-05-09 18:39:58 +0000291 fStages[s].reset();
292 }
293 }
junov@google.comf93e7172011-03-31 21:26:24 +0000294 };
295
296 class CachedData : public ::GrNoncopyable {
297 public:
298 CachedData() {
junov@google.comf93e7172011-03-31 21:26:24 +0000299 }
300
301 ~CachedData() {
junov@google.comf93e7172011-03-31 21:26:24 +0000302 }
303
304 void copyAndTakeOwnership(CachedData& other) {
bsalomon@google.com2d9ddf92011-05-11 16:52:59 +0000305 memcpy(this, &other, sizeof(*this));
junov@google.comf93e7172011-03-31 21:26:24 +0000306 }
307
junov@google.comf93e7172011-03-31 21:26:24 +0000308 public:
309
310 // IDs
311 GrGLuint fVShaderID;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000312 GrGLuint fGShaderID;
junov@google.comf93e7172011-03-31 21:26:24 +0000313 GrGLuint fFShaderID;
314 GrGLuint fProgramID;
315 // shader uniform locations (-1 if shader doesn't use them)
316 UniLocations fUniLocations;
317
318 GrMatrix fViewMatrix;
319
320 // these reflect the current values of uniforms
321 // (GL uniform values travel with program)
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000322 GrColor fColor;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000323 GrColor fCoverage;
Scroggo97c88c22011-05-11 14:05:25 +0000324 GrColor fColorFilterColor;
tomhudson@google.com93813632011-10-27 20:21:16 +0000325 GrMatrix fTextureMatrices[GrDrawState::kNumStages];
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000326 // width and height used for normalized texel size
tomhudson@google.com93813632011-10-27 20:21:16 +0000327 int fTextureWidth[GrDrawState::kNumStages];
328 int fTextureHeight[GrDrawState::kNumStages];
329 GrScalar fRadial2CenterX1[GrDrawState::kNumStages];
330 GrScalar fRadial2Radius0[GrDrawState::kNumStages];
331 bool fRadial2PosRoot[GrDrawState::kNumStages];
332 GrRect fTextureDomain[GrDrawState::kNumStages];
junov@google.comf93e7172011-03-31 21:26:24 +0000333
334 private:
335 enum Constants {
336 kUniLocationPreAllocSize = 8
337 };
338
junov@google.comf93e7172011-03-31 21:26:24 +0000339 }; // CachedData
340
junov@google.comf7c00f62011-08-18 18:15:16 +0000341 enum Constants {
342 kProgramKeySize = sizeof(ProgramDesc)
343 };
344
345 // Provide an opaque ProgramDesc
346 const uint32_t* keyData() const{
347 return reinterpret_cast<const uint32_t*>(&fProgramDesc);
348 }
349
junov@google.comf93e7172011-03-31 21:26:24 +0000350private:
bsalomon@google.com91961302011-05-09 18:39:58 +0000351
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000352 // Determines which uniforms will need to be bound.
bsalomon@google.com96399942012-02-13 14:39:16 +0000353 void genStageCode(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000354 int stageNum,
junov@google.comf93e7172011-03-31 21:26:24 +0000355 const ProgramDesc::StageDesc& desc,
356 const char* fsInColor, // NULL means no incoming color
357 const char* fsOutColor,
358 const char* vsInCoord,
359 ShaderCodeSegments* segments,
360 StageUniLocations* locations) const;
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000361
bsalomon@google.com96399942012-02-13 14:39:16 +0000362 void genGeometryShader(const GrGLContextInfo& gl,
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000363 ShaderCodeSegments* segments) const;
364
bsalomon@google.com66105672011-09-15 15:12:00 +0000365 // generates code to compute coverage based on edge AA.
bsalomon@google.com96399942012-02-13 14:39:16 +0000366 void genEdgeCoverage(const GrGLContextInfo& gl,
bsalomon@google.com66105672011-09-15 15:12:00 +0000367 GrVertexLayout layout,
368 CachedData* programData,
369 GrStringBuilder* coverageVar,
370 ShaderCodeSegments* segments) const;
junov@google.comf93e7172011-03-31 21:26:24 +0000371
bsalomon@google.com96399942012-02-13 14:39:16 +0000372 static bool CompileShaders(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000373 const ShaderCodeSegments& segments,
bsalomon@google.com91961302011-05-09 18:39:58 +0000374 CachedData* programData);
375
junov@google.comf93e7172011-03-31 21:26:24 +0000376 // Compiles a GL shader, returns shader ID or 0 if failed
377 // params have same meaning as glShaderSource
bsalomon@google.com96399942012-02-13 14:39:16 +0000378 static GrGLuint CompileShader(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000379 GrGLenum type, int stringCnt,
junov@google.comf93e7172011-03-31 21:26:24 +0000380 const char** strings,
381 int* stringLengths);
382
bsalomon@google.com91961302011-05-09 18:39:58 +0000383 // Creates a GL program ID, binds shader attributes to GL vertex attrs, and
384 // links the program
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000385 bool bindOutputsAttribsAndLinkProgram(
bsalomon@google.com96399942012-02-13 14:39:16 +0000386 const GrGLContextInfo& gl,
tomhudson@google.com93813632011-10-27 20:21:16 +0000387 GrStringBuilder texCoordAttrNames[GrDrawState::kMaxTexCoords],
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000388 bool bindColorOut,
389 bool bindDualSrcOut,
390 CachedData* programData) const;
bsalomon@google.com91961302011-05-09 18:39:58 +0000391
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000392 // Binds uniforms; initializes cache to invalid values.
bsalomon@google.com96399942012-02-13 14:39:16 +0000393 void getUniformLocationsAndInitCache(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000394 CachedData* programData) const;
bsalomon@google.com91961302011-05-09 18:39:58 +0000395
junov@google.comf93e7172011-03-31 21:26:24 +0000396 friend class GrGpuGLShaders;
397};
398
399#endif