blob: 9e2ee7e3f5c1860c91942157820ba5d2492adbd2 [file] [log] [blame]
junov@google.comf93e7172011-03-31 21:26:24 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 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.
junov@google.comf93e7172011-03-31 21:26:24 +00006 */
7
epoger@google.comec3ed6a2011-07-28 14:26:00 +00008
junov@google.comf93e7172011-03-31 21:26:24 +00009#ifndef GrGLProgram_DEFINED
10#define GrGLProgram_DEFINED
11
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000012#include "GrDrawState.h"
bsalomon@google.com96399942012-02-13 14:39:16 +000013#include "GrGLContextInfo.h"
tomhudson@google.com086e5352011-12-08 14:44:10 +000014#include "GrGLSL.h"
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000015#include "GrStringBuilder.h"
16#include "GrGpu.h"
junov@google.comf93e7172011-03-31 21:26:24 +000017
Scroggo97c88c22011-05-11 14:05:25 +000018#include "SkXfermode.h"
19
junov@google.comf93e7172011-03-31 21:26:24 +000020class GrBinHashKeyBuilder;
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000021class GrGLProgramStage;
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,
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000052 GrCustomStage** customStages,
bsalomon@google.com0b77d682011-08-19 13:28:54 +000053 CachedData* programData) const;
junov@google.comf93e7172011-03-31 21:26:24 +000054
bsalomon@google.com271cffc2011-05-20 14:13:56 +000055 /**
56 * The shader may modify the blend coeffecients. Params are in/out
57 */
58 void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const;
59
60 /**
bsalomon@google.comb5b5eaf2011-10-19 13:25:46 +000061 * Attribute indices. These should not overlap. Matrices consume 3 slots.
bsalomon@google.com271cffc2011-05-20 14:13:56 +000062 */
bsalomon@google.com91961302011-05-09 18:39:58 +000063 static int PositionAttributeIdx() { return 0; }
64 static int TexCoordAttributeIdx(int tcIdx) { return 1 + tcIdx; }
tomhudson@google.com93813632011-10-27 20:21:16 +000065 static int ColorAttributeIdx() { return 1 + GrDrawState::kMaxTexCoords; }
bsalomon@google.coma3108262011-10-10 14:08:47 +000066 static int CoverageAttributeIdx() {
tomhudson@google.com93813632011-10-27 20:21:16 +000067 return 2 + GrDrawState::kMaxTexCoords;
bsalomon@google.coma3108262011-10-10 14:08:47 +000068 }
tomhudson@google.com93813632011-10-27 20:21:16 +000069 static int EdgeAttributeIdx() { return 3 + GrDrawState::kMaxTexCoords; }
bsalomon@google.comaeb21602011-08-30 18:13:44 +000070
tomhudson@google.com0d831722011-06-02 15:37:14 +000071 static int ViewMatrixAttributeIdx() {
tomhudson@google.com93813632011-10-27 20:21:16 +000072 return 4 + GrDrawState::kMaxTexCoords;
bsalomon@google.com91961302011-05-09 18:39:58 +000073 }
tomhudson@google.com0d831722011-06-02 15:37:14 +000074 static int TextureMatrixAttributeIdx(int stage) {
tomhudson@google.com93813632011-10-27 20:21:16 +000075 return 7 + GrDrawState::kMaxTexCoords + 3 * stage;
bsalomon@google.com91961302011-05-09 18:39:58 +000076 }
77
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +000078public:
junov@google.comf93e7172011-03-31 21:26:24 +000079
tomhudson@google.com0d831722011-06-02 15:37:14 +000080 // Parameters that affect code generation
81 // These structs should be kept compact; they are the input to an
82 // expensive hash key generator.
junov@google.comf93e7172011-03-31 21:26:24 +000083 struct ProgramDesc {
bsalomon@google.com4be283f2011-04-19 21:15:09 +000084 ProgramDesc() {
85 // since we use this as part of a key we can't have any unitialized
86 // padding
87 memset(this, 0, sizeof(ProgramDesc));
88 }
89
bsalomon@google.coma91e9232012-02-23 15:39:54 +000090 enum OutputConfig {
bsalomon@google.comc4364992011-11-07 15:54:49 +000091 // PM-color OR color with no alpha channel
bsalomon@google.coma91e9232012-02-23 15:39:54 +000092 kPremultiplied_OutputConfig,
93 // nonPM-color with alpha channel. Round components up after
94 // dividing by alpha. Assumes output is 8 bits for r, g, and b
95 kUnpremultiplied_RoundUp_OutputConfig,
96 // nonPM-color with alpha channel. Round components down after
97 // dividing by alpha. Assumes output is 8 bits for r, g, and b
98 kUnpremultiplied_RoundDown_OutputConfig,
bsalomon@google.comc4364992011-11-07 15:54:49 +000099
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000100 kOutputConfigCnt
bsalomon@google.comc4364992011-11-07 15:54:49 +0000101 };
102
tomhudson@google.com0d831722011-06-02 15:37:14 +0000103 struct StageDesc {
104 enum OptFlagBits {
105 kNoPerspective_OptFlagBit = 1 << 0,
106 kIdentityMatrix_OptFlagBit = 1 << 1,
107 kCustomTextureDomain_OptFlagBit = 1 << 2,
108 kIsEnabled_OptFlagBit = 1 << 7
109 };
tomhudson@google.comd8f856c2012-05-10 12:13:36 +0000110 // Convolution is obsolete; left in for testing only
tomhudson@google.com0d831722011-06-02 15:37:14 +0000111 enum FetchMode {
112 kSingle_FetchMode,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000113 k2x2_FetchMode,
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000114 kConvolution_FetchMode,
senorblanco@chromium.org05054f12012-03-02 21:05:45 +0000115 kErode_FetchMode,
116 kDilate_FetchMode,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000117
118 kFetchModeCnt,
tomhudson@google.com0d831722011-06-02 15:37:14 +0000119 };
bsalomon@google.com0a97be22011-11-08 19:20:57 +0000120 /**
bsalomon@google.com74b98712011-11-11 19:46:16 +0000121 Flags set based on a src texture's pixel config. The operations
122 described are performed after reading a texel.
bsalomon@google.com0a97be22011-11-08 19:20:57 +0000123 */
bsalomon@google.com74b98712011-11-11 19:46:16 +0000124 enum InConfigFlags {
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000125 kNone_InConfigFlag = 0x00,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000126
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000127 /**
bsalomon@google.com74b98712011-11-11 19:46:16 +0000128 Swap the R and B channels. This is incompatible with
129 kSmearAlpha. It is prefereable to perform the swizzle outside
130 the shader using GL_ARB_texture_swizzle if possible rather
131 than setting this flag.
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000132 */
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000133 kSwapRAndB_InConfigFlag = 0x01,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000134
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000135 /**
bsalomon@google.com74b98712011-11-11 19:46:16 +0000136 Smear alpha across all four channels. This is incompatible with
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000137 kSwapRAndB, kMulRGBByAlpha* and kSmearRed. It is prefereable
138 to perform the smear outside the shader using
139 GL_ARB_texture_swizzle if possible rather than setting this
140 flag.
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000141 */
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000142 kSmearAlpha_InConfigFlag = 0x02,
143
144 /**
145 Smear the red channel across all four channels. This flag is
146 incompatible with kSwapRAndB, kMulRGBByAlpha*and kSmearAlpha.
147 It is preferable to use GL_ARB_texture_swizzle instead of this
148 flag.
149 */
150 kSmearRed_InConfigFlag = 0x04,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000151
152 /**
153 Multiply r,g,b by a after texture reads. This flag incompatible
154 with kSmearAlpha and may only be used with FetchMode kSingle.
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000155
156 It is assumed the src texture has 8bit color components. After
157 reading the texture one version rounds up to the next multiple
158 of 1/255.0 and the other rounds down. At most one of these
159 flags may be set.
bsalomon@google.com74b98712011-11-11 19:46:16 +0000160 */
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000161 kMulRGBByAlpha_RoundUp_InConfigFlag = 0x08,
162 kMulRGBByAlpha_RoundDown_InConfigFlag = 0x10,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000163
164 kDummyInConfigFlag,
165 kInConfigBitMask = (kDummyInConfigFlag-1) |
166 (kDummyInConfigFlag-2)
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000167 };
tomhudson@google.com0d831722011-06-02 15:37:14 +0000168 enum CoordMapping {
169 kIdentity_CoordMapping,
170 kRadialGradient_CoordMapping,
171 kSweepGradient_CoordMapping,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000172 kRadial2Gradient_CoordMapping,
bsalomon@google.com22c5dea2011-07-07 14:38:03 +0000173 // need different shader computation when quadratic
174 // eq describing the gradient degenerates to a linear eq.
175 kRadial2GradientDegenerate_CoordMapping,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000176 kCoordMappingCnt
tomhudson@google.com0d831722011-06-02 15:37:14 +0000177 };
junov@google.comf93e7172011-03-31 21:26:24 +0000178
tomhudson@google.com0d831722011-06-02 15:37:14 +0000179 uint8_t fOptFlags;
bsalomon@google.com74b98712011-11-11 19:46:16 +0000180 uint8_t fInConfigFlags; // bitfield of InConfigFlags values
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000181 uint8_t fFetchMode; // casts to enum FetchMode
tomhudson@google.com0d831722011-06-02 15:37:14 +0000182 uint8_t fCoordMapping; // casts to enum CoordMapping
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000183 uint8_t fKernelWidth;
tomhudson@google.com0d831722011-06-02 15:37:14 +0000184
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000185 /** Non-zero if user-supplied code will write the stage's
186 contribution to the fragment shader. */
187 uint16_t fCustomStageKey;
188
bsalomon@google.com74b98712011-11-11 19:46:16 +0000189 GR_STATIC_ASSERT((InConfigFlags)(uint8_t)kInConfigBitMask ==
190 kInConfigBitMask);
191
tomhudson@google.com0d831722011-06-02 15:37:14 +0000192 inline bool isEnabled() const {
bsalomon@google.comc2c9b972011-10-03 13:17:22 +0000193 return SkToBool(fOptFlags & kIsEnabled_OptFlagBit);
tomhudson@google.com0d831722011-06-02 15:37:14 +0000194 }
195 inline void setEnabled(bool newValue) {
196 if (newValue) {
197 fOptFlags |= kIsEnabled_OptFlagBit;
198 } else {
199 fOptFlags &= ~kIsEnabled_OptFlagBit;
200 }
201 }
202 };
203
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000204 // Specifies where the intitial color comes from before the stages are
205 // applied.
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000206 enum ColorInput {
207 kSolidWhite_ColorInput,
208 kTransBlack_ColorInput,
209 kAttribute_ColorInput,
210 kUniform_ColorInput,
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000211
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000212 kColorInputCnt
tomhudson@google.com0d831722011-06-02 15:37:14 +0000213 };
214 // Dual-src blending makes use of a secondary output color that can be
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000215 // used as a per-pixel blend coeffecient. This controls whether a
216 // secondary source is output and what value it holds.
217 enum DualSrcOutput {
218 kNone_DualSrcOutput,
219 kCoverage_DualSrcOutput,
220 kCoverageISA_DualSrcOutput,
221 kCoverageISC_DualSrcOutput,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000222
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000223 kDualSrcOutputCnt
tomhudson@google.com0d831722011-06-02 15:37:14 +0000224 };
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000225
tomhudson@google.com93813632011-10-27 20:21:16 +0000226 GrDrawState::VertexEdgeType fVertexEdgeType;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000227
tomhudson@google.com0d831722011-06-02 15:37:14 +0000228 // stripped of bits that don't affect prog generation
229 GrVertexLayout fVertexLayout;
junov@google.comf93e7172011-03-31 21:26:24 +0000230
tomhudson@google.com93813632011-10-27 20:21:16 +0000231 StageDesc fStages[GrDrawState::kNumStages];
Scroggo97c88c22011-05-11 14:05:25 +0000232
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000233 // To enable experimental geometry shader code (not for use in
234 // production)
235#if GR_GL_EXPERIMENTAL_GS
236 bool fExperimentalGS;
237#endif
238
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000239 uint8_t fColorInput; // casts to enum ColorInput
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000240 uint8_t fCoverageInput; // casts to enum CoverageInput
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000241 uint8_t fOutputConfig; // casts to enum OutputConfig
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000242 uint8_t fDualSrcOutput; // casts to enum DualSrcOutput
tomhudson@google.com0d831722011-06-02 15:37:14 +0000243 int8_t fFirstCoverageStage;
244 SkBool8 fEmitsPointSize;
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +0000245 SkBool8 fEdgeAAConcave;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000246 SkBool8 fColorMatrixEnabled;
junov@google.comf93e7172011-03-31 21:26:24 +0000247
tomhudson@google.com0d831722011-06-02 15:37:14 +0000248 int8_t fEdgeAANumEdges;
249 uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000250 int8_t fPadding[3];
junov@google.comf93e7172011-03-31 21:26:24 +0000251
junov@google.comf93e7172011-03-31 21:26:24 +0000252 } fProgramDesc;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000253 GR_STATIC_ASSERT(!(sizeof(ProgramDesc) % 4));
junov@google.comf93e7172011-03-31 21:26:24 +0000254
bsalomon@google.com22c5dea2011-07-07 14:38:03 +0000255 // for code readability
256 typedef ProgramDesc::StageDesc StageDesc;
257
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000258private:
259
260 const ProgramDesc& getDesc() { return fProgramDesc; }
senorblanco@chromium.orgb3a39b52012-01-05 18:28:56 +0000261 const char* adjustInColor(const GrStringBuilder& inColor) const;
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000262
junov@google.comf93e7172011-03-31 21:26:24 +0000263public:
bsalomon@google.com91961302011-05-09 18:39:58 +0000264 enum {
265 kUnusedUniform = -1,
266 kSetAsAttribute = 1000,
267 };
268
junov@google.comf93e7172011-03-31 21:26:24 +0000269 struct StageUniLocations {
270 GrGLint fTextureMatrixUni;
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000271 GrGLint fNormalizedTexelSizeUni;
junov@google.comf93e7172011-03-31 21:26:24 +0000272 GrGLint fSamplerUni;
273 GrGLint fRadial2Uni;
junov@google.com6acc9b32011-05-16 18:32:07 +0000274 GrGLint fTexDomUni;
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000275 GrGLint fKernelUni;
276 GrGLint fImageIncrementUni;
bsalomon@google.com91961302011-05-09 18:39:58 +0000277 void reset() {
278 fTextureMatrixUni = kUnusedUniform;
279 fNormalizedTexelSizeUni = kUnusedUniform;
280 fSamplerUni = kUnusedUniform;
281 fRadial2Uni = kUnusedUniform;
junov@google.com6acc9b32011-05-16 18:32:07 +0000282 fTexDomUni = kUnusedUniform;
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000283 fKernelUni = kUnusedUniform;
284 fImageIncrementUni = kUnusedUniform;
bsalomon@google.com91961302011-05-09 18:39:58 +0000285 }
junov@google.comf93e7172011-03-31 21:26:24 +0000286 };
287
288 struct UniLocations {
289 GrGLint fViewMatrixUni;
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000290 GrGLint fColorUni;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000291 GrGLint fCoverageUni;
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000292 GrGLint fEdgesUni;
Scroggo97c88c22011-05-11 14:05:25 +0000293 GrGLint fColorFilterUni;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000294 GrGLint fColorMatrixUni;
295 GrGLint fColorMatrixVecUni;
tomhudson@google.com93813632011-10-27 20:21:16 +0000296 StageUniLocations fStages[GrDrawState::kNumStages];
bsalomon@google.com91961302011-05-09 18:39:58 +0000297 void reset() {
298 fViewMatrixUni = kUnusedUniform;
299 fColorUni = kUnusedUniform;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000300 fCoverageUni = kUnusedUniform;
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000301 fEdgesUni = kUnusedUniform;
Scroggo97c88c22011-05-11 14:05:25 +0000302 fColorFilterUni = kUnusedUniform;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000303 fColorMatrixUni = kUnusedUniform;
304 fColorMatrixVecUni = kUnusedUniform;
tomhudson@google.com93813632011-10-27 20:21:16 +0000305 for (int s = 0; s < GrDrawState::kNumStages; ++s) {
bsalomon@google.com91961302011-05-09 18:39:58 +0000306 fStages[s].reset();
307 }
308 }
junov@google.comf93e7172011-03-31 21:26:24 +0000309 };
310
311 class CachedData : public ::GrNoncopyable {
312 public:
313 CachedData() {
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000314 for (int i = 0; i < GrDrawState::kNumStages; ++i) {
315 fCustomStage[i] = NULL;
316 }
junov@google.comf93e7172011-03-31 21:26:24 +0000317 }
318
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000319 ~CachedData();
junov@google.comf93e7172011-03-31 21:26:24 +0000320
321 void copyAndTakeOwnership(CachedData& other) {
bsalomon@google.com2d9ddf92011-05-11 16:52:59 +0000322 memcpy(this, &other, sizeof(*this));
tomhudson@google.comd8f856c2012-05-10 12:13:36 +0000323 for (int i = 0; i < GrDrawState::kNumStages; ++i) {
324 other.fCustomStage[i] = NULL;
325 }
junov@google.comf93e7172011-03-31 21:26:24 +0000326 }
327
junov@google.comf93e7172011-03-31 21:26:24 +0000328 public:
329
330 // IDs
331 GrGLuint fVShaderID;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000332 GrGLuint fGShaderID;
junov@google.comf93e7172011-03-31 21:26:24 +0000333 GrGLuint fFShaderID;
334 GrGLuint fProgramID;
335 // shader uniform locations (-1 if shader doesn't use them)
336 UniLocations fUniLocations;
337
338 GrMatrix fViewMatrix;
339
340 // these reflect the current values of uniforms
341 // (GL uniform values travel with program)
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000342 GrColor fColor;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000343 GrColor fCoverage;
Scroggo97c88c22011-05-11 14:05:25 +0000344 GrColor fColorFilterColor;
tomhudson@google.com93813632011-10-27 20:21:16 +0000345 GrMatrix fTextureMatrices[GrDrawState::kNumStages];
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000346 // width and height used for normalized texel size
tomhudson@google.com93813632011-10-27 20:21:16 +0000347 int fTextureWidth[GrDrawState::kNumStages];
348 int fTextureHeight[GrDrawState::kNumStages];
349 GrScalar fRadial2CenterX1[GrDrawState::kNumStages];
350 GrScalar fRadial2Radius0[GrDrawState::kNumStages];
351 bool fRadial2PosRoot[GrDrawState::kNumStages];
352 GrRect fTextureDomain[GrDrawState::kNumStages];
junov@google.comf93e7172011-03-31 21:26:24 +0000353
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000354 GrGLProgramStage* fCustomStage[GrDrawState::kNumStages];
355
junov@google.comf93e7172011-03-31 21:26:24 +0000356 private:
357 enum Constants {
358 kUniLocationPreAllocSize = 8
359 };
360
junov@google.comf93e7172011-03-31 21:26:24 +0000361 }; // CachedData
362
junov@google.comf7c00f62011-08-18 18:15:16 +0000363 enum Constants {
364 kProgramKeySize = sizeof(ProgramDesc)
365 };
366
367 // Provide an opaque ProgramDesc
368 const uint32_t* keyData() const{
369 return reinterpret_cast<const uint32_t*>(&fProgramDesc);
370 }
371
junov@google.comf93e7172011-03-31 21:26:24 +0000372private:
bsalomon@google.com91961302011-05-09 18:39:58 +0000373
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000374 // Determines which uniforms will need to be bound.
bsalomon@google.com96399942012-02-13 14:39:16 +0000375 void genStageCode(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000376 int stageNum,
junov@google.comf93e7172011-03-31 21:26:24 +0000377 const ProgramDesc::StageDesc& desc,
378 const char* fsInColor, // NULL means no incoming color
379 const char* fsOutColor,
380 const char* vsInCoord,
381 ShaderCodeSegments* segments,
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000382 StageUniLocations* locations,
383 GrGLProgramStage* override) const;
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000384
bsalomon@google.com96399942012-02-13 14:39:16 +0000385 void genGeometryShader(const GrGLContextInfo& gl,
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000386 ShaderCodeSegments* segments) const;
387
bsalomon@google.com66105672011-09-15 15:12:00 +0000388 // generates code to compute coverage based on edge AA.
bsalomon@google.com96399942012-02-13 14:39:16 +0000389 void genEdgeCoverage(const GrGLContextInfo& gl,
bsalomon@google.com66105672011-09-15 15:12:00 +0000390 GrVertexLayout layout,
391 CachedData* programData,
392 GrStringBuilder* coverageVar,
393 ShaderCodeSegments* segments) const;
junov@google.comf93e7172011-03-31 21:26:24 +0000394
bsalomon@google.com96399942012-02-13 14:39:16 +0000395 static bool CompileShaders(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000396 const ShaderCodeSegments& segments,
bsalomon@google.com91961302011-05-09 18:39:58 +0000397 CachedData* programData);
398
junov@google.comf93e7172011-03-31 21:26:24 +0000399 // Compiles a GL shader, returns shader ID or 0 if failed
400 // params have same meaning as glShaderSource
bsalomon@google.com96399942012-02-13 14:39:16 +0000401 static GrGLuint CompileShader(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000402 GrGLenum type, int stringCnt,
junov@google.comf93e7172011-03-31 21:26:24 +0000403 const char** strings,
404 int* stringLengths);
405
bsalomon@google.com91961302011-05-09 18:39:58 +0000406 // Creates a GL program ID, binds shader attributes to GL vertex attrs, and
407 // links the program
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000408 bool bindOutputsAttribsAndLinkProgram(
bsalomon@google.com96399942012-02-13 14:39:16 +0000409 const GrGLContextInfo& gl,
tomhudson@google.com93813632011-10-27 20:21:16 +0000410 GrStringBuilder texCoordAttrNames[GrDrawState::kMaxTexCoords],
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000411 bool bindColorOut,
412 bool bindDualSrcOut,
413 CachedData* programData) const;
bsalomon@google.com91961302011-05-09 18:39:58 +0000414
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000415 // Binds uniforms; initializes cache to invalid values.
bsalomon@google.com96399942012-02-13 14:39:16 +0000416 void getUniformLocationsAndInitCache(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000417 CachedData* programData) const;
bsalomon@google.com91961302011-05-09 18:39:58 +0000418
junov@google.comf93e7172011-03-31 21:26:24 +0000419 friend class GrGpuGLShaders;
420};
421
422#endif