blob: 91ee95cd936f8db7c58fd6a13c29dc1a25f4c4c4 [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;
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000022class GrGLProgramStage;
junov@google.comd31cbc42011-05-17 17:01:17 +000023
bsalomon@google.com4fa66942011-09-20 19:06:12 +000024struct ShaderCodeSegments;
junov@google.comf93e7172011-03-31 21:26:24 +000025
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +000026// optionally compile the experimental GS code. Set to GR_DEBUG
27// so that debug build bots will execute the code.
28#define GR_GL_EXPERIMENTAL_GS GR_DEBUG
29
junov@google.comf93e7172011-03-31 21:26:24 +000030/**
31 * This class manages a GPU program and records per-program information.
32 * We can specify the attribute locations so that they are constant
33 * across our shaders. But the driver determines the uniform locations
34 * at link time. We don't need to remember the sampler uniform location
35 * because we will bind a texture slot to it and never change it
36 * Uniforms are program-local so we can't rely on fHWState to hold the
37 * previous uniform state after a program change.
38 */
39class GrGLProgram {
40public:
bsalomon@google.com4fa66942011-09-20 19:06:12 +000041
junov@google.comf93e7172011-03-31 21:26:24 +000042 class CachedData;
43
44 GrGLProgram();
45 ~GrGLProgram();
46
47 /**
junov@google.comf93e7172011-03-31 21:26:24 +000048 * This is the heavy initilization routine for building a GLProgram.
49 * The result of heavy init is not stored in datamembers of GrGLProgam,
50 * but in a separate cacheable container.
51 */
bsalomon@google.com96399942012-02-13 14:39:16 +000052 bool genProgram(const GrGLContextInfo& gl,
tomhudson@google.com07eecdc2012-04-20 18:35:38 +000053 GrCustomStage** customStages,
bsalomon@google.com0b77d682011-08-19 13:28:54 +000054 CachedData* programData) const;
junov@google.comf93e7172011-03-31 21:26:24 +000055
bsalomon@google.com271cffc2011-05-20 14:13:56 +000056 /**
57 * The shader may modify the blend coeffecients. Params are in/out
58 */
59 void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const;
60
61 /**
bsalomon@google.comb5b5eaf2011-10-19 13:25:46 +000062 * Attribute indices. These should not overlap. Matrices consume 3 slots.
bsalomon@google.com271cffc2011-05-20 14:13:56 +000063 */
bsalomon@google.com91961302011-05-09 18:39:58 +000064 static int PositionAttributeIdx() { return 0; }
65 static int TexCoordAttributeIdx(int tcIdx) { return 1 + tcIdx; }
tomhudson@google.com93813632011-10-27 20:21:16 +000066 static int ColorAttributeIdx() { return 1 + GrDrawState::kMaxTexCoords; }
bsalomon@google.coma3108262011-10-10 14:08:47 +000067 static int CoverageAttributeIdx() {
tomhudson@google.com93813632011-10-27 20:21:16 +000068 return 2 + GrDrawState::kMaxTexCoords;
bsalomon@google.coma3108262011-10-10 14:08:47 +000069 }
tomhudson@google.com93813632011-10-27 20:21:16 +000070 static int EdgeAttributeIdx() { return 3 + GrDrawState::kMaxTexCoords; }
bsalomon@google.comaeb21602011-08-30 18:13:44 +000071
tomhudson@google.com0d831722011-06-02 15:37:14 +000072 static int ViewMatrixAttributeIdx() {
tomhudson@google.com93813632011-10-27 20:21:16 +000073 return 4 + GrDrawState::kMaxTexCoords;
bsalomon@google.com91961302011-05-09 18:39:58 +000074 }
tomhudson@google.com0d831722011-06-02 15:37:14 +000075 static int TextureMatrixAttributeIdx(int stage) {
tomhudson@google.com93813632011-10-27 20:21:16 +000076 return 7 + GrDrawState::kMaxTexCoords + 3 * stage;
bsalomon@google.com91961302011-05-09 18:39:58 +000077 }
78
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +000079public:
junov@google.comf93e7172011-03-31 21:26:24 +000080
tomhudson@google.com0d831722011-06-02 15:37:14 +000081 // Parameters that affect code generation
82 // These structs should be kept compact; they are the input to an
83 // expensive hash key generator.
junov@google.comf93e7172011-03-31 21:26:24 +000084 struct ProgramDesc {
bsalomon@google.com4be283f2011-04-19 21:15:09 +000085 ProgramDesc() {
86 // since we use this as part of a key we can't have any unitialized
87 // padding
88 memset(this, 0, sizeof(ProgramDesc));
89 }
90
bsalomon@google.coma91e9232012-02-23 15:39:54 +000091 enum OutputConfig {
bsalomon@google.comc4364992011-11-07 15:54:49 +000092 // PM-color OR color with no alpha channel
bsalomon@google.coma91e9232012-02-23 15:39:54 +000093 kPremultiplied_OutputConfig,
94 // nonPM-color with alpha channel. Round components up after
95 // dividing by alpha. Assumes output is 8 bits for r, g, and b
96 kUnpremultiplied_RoundUp_OutputConfig,
97 // nonPM-color with alpha channel. Round components down after
98 // dividing by alpha. Assumes output is 8 bits for r, g, and b
99 kUnpremultiplied_RoundDown_OutputConfig,
bsalomon@google.comc4364992011-11-07 15:54:49 +0000100
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000101 kOutputConfigCnt
bsalomon@google.comc4364992011-11-07 15:54:49 +0000102 };
103
tomhudson@google.com0d831722011-06-02 15:37:14 +0000104 struct StageDesc {
105 enum OptFlagBits {
106 kNoPerspective_OptFlagBit = 1 << 0,
107 kIdentityMatrix_OptFlagBit = 1 << 1,
108 kCustomTextureDomain_OptFlagBit = 1 << 2,
109 kIsEnabled_OptFlagBit = 1 << 7
110 };
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 {
epoger@google.com00484692012-04-30 19:02:08 +0000125 kNone_InConfigFlag = 0x0,
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 */
epoger@google.com00484692012-04-30 19:02:08 +0000133 kSwapRAndB_InConfigFlag = 0x1,
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
epoger@google.com00484692012-04-30 19:02:08 +0000137 kSwapRAndB and kMulRGBByAlpha*. It is prefereable to perform
138 the smear outside the shader using GL_ARB_texture_swizzle if
139 possible rather than setting this flag.
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000140 */
epoger@google.com00484692012-04-30 19:02:08 +0000141 kSmearAlpha_InConfigFlag = 0x2,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000142
143 /**
144 Multiply r,g,b by a after texture reads. This flag incompatible
145 with kSmearAlpha and may only be used with FetchMode kSingle.
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000146
147 It is assumed the src texture has 8bit color components. After
148 reading the texture one version rounds up to the next multiple
149 of 1/255.0 and the other rounds down. At most one of these
150 flags may be set.
bsalomon@google.com74b98712011-11-11 19:46:16 +0000151 */
epoger@google.com00484692012-04-30 19:02:08 +0000152 kMulRGBByAlpha_RoundUp_InConfigFlag = 0x4,
153 kMulRGBByAlpha_RoundDown_InConfigFlag = 0x8,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000154
155 kDummyInConfigFlag,
156 kInConfigBitMask = (kDummyInConfigFlag-1) |
157 (kDummyInConfigFlag-2)
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000158 };
tomhudson@google.com0d831722011-06-02 15:37:14 +0000159 enum CoordMapping {
160 kIdentity_CoordMapping,
161 kRadialGradient_CoordMapping,
162 kSweepGradient_CoordMapping,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000163 kRadial2Gradient_CoordMapping,
bsalomon@google.com22c5dea2011-07-07 14:38:03 +0000164 // need different shader computation when quadratic
165 // eq describing the gradient degenerates to a linear eq.
166 kRadial2GradientDegenerate_CoordMapping,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000167 kCoordMappingCnt
tomhudson@google.com0d831722011-06-02 15:37:14 +0000168 };
junov@google.comf93e7172011-03-31 21:26:24 +0000169
tomhudson@google.com0d831722011-06-02 15:37:14 +0000170 uint8_t fOptFlags;
bsalomon@google.com74b98712011-11-11 19:46:16 +0000171 uint8_t fInConfigFlags; // bitfield of InConfigFlags values
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000172 uint8_t fFetchMode; // casts to enum FetchMode
tomhudson@google.com0d831722011-06-02 15:37:14 +0000173 uint8_t fCoordMapping; // casts to enum CoordMapping
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000174 uint8_t fKernelWidth;
tomhudson@google.com0d831722011-06-02 15:37:14 +0000175
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000176 /** Non-zero if user-supplied code will write the stage's
177 contribution to the fragment shader. */
178 uint16_t fCustomStageKey;
179
bsalomon@google.com74b98712011-11-11 19:46:16 +0000180 GR_STATIC_ASSERT((InConfigFlags)(uint8_t)kInConfigBitMask ==
181 kInConfigBitMask);
182
tomhudson@google.com0d831722011-06-02 15:37:14 +0000183 inline bool isEnabled() const {
bsalomon@google.comc2c9b972011-10-03 13:17:22 +0000184 return SkToBool(fOptFlags & kIsEnabled_OptFlagBit);
tomhudson@google.com0d831722011-06-02 15:37:14 +0000185 }
186 inline void setEnabled(bool newValue) {
187 if (newValue) {
188 fOptFlags |= kIsEnabled_OptFlagBit;
189 } else {
190 fOptFlags &= ~kIsEnabled_OptFlagBit;
191 }
192 }
193 };
194
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000195 // Specifies where the intitial color comes from before the stages are
196 // applied.
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000197 enum ColorInput {
198 kSolidWhite_ColorInput,
199 kTransBlack_ColorInput,
200 kAttribute_ColorInput,
201 kUniform_ColorInput,
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000202
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000203 kColorInputCnt
tomhudson@google.com0d831722011-06-02 15:37:14 +0000204 };
205 // Dual-src blending makes use of a secondary output color that can be
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000206 // used as a per-pixel blend coeffecient. This controls whether a
207 // secondary source is output and what value it holds.
208 enum DualSrcOutput {
209 kNone_DualSrcOutput,
210 kCoverage_DualSrcOutput,
211 kCoverageISA_DualSrcOutput,
212 kCoverageISC_DualSrcOutput,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000213
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000214 kDualSrcOutputCnt
tomhudson@google.com0d831722011-06-02 15:37:14 +0000215 };
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000216
tomhudson@google.com93813632011-10-27 20:21:16 +0000217 GrDrawState::VertexEdgeType fVertexEdgeType;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000218
tomhudson@google.com0d831722011-06-02 15:37:14 +0000219 // stripped of bits that don't affect prog generation
220 GrVertexLayout fVertexLayout;
junov@google.comf93e7172011-03-31 21:26:24 +0000221
tomhudson@google.com93813632011-10-27 20:21:16 +0000222 StageDesc fStages[GrDrawState::kNumStages];
Scroggo97c88c22011-05-11 14:05:25 +0000223
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000224 // To enable experimental geometry shader code (not for use in
225 // production)
226#if GR_GL_EXPERIMENTAL_GS
227 bool fExperimentalGS;
228#endif
229
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000230 uint8_t fColorInput; // casts to enum ColorInput
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000231 uint8_t fCoverageInput; // casts to enum CoverageInput
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000232 uint8_t fOutputConfig; // casts to enum OutputConfig
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000233 uint8_t fDualSrcOutput; // casts to enum DualSrcOutput
tomhudson@google.com0d831722011-06-02 15:37:14 +0000234 int8_t fFirstCoverageStage;
235 SkBool8 fEmitsPointSize;
senorblanco@chromium.org129b8e32011-06-15 17:52:09 +0000236 SkBool8 fEdgeAAConcave;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000237 SkBool8 fColorMatrixEnabled;
junov@google.comf93e7172011-03-31 21:26:24 +0000238
tomhudson@google.com0d831722011-06-02 15:37:14 +0000239 int8_t fEdgeAANumEdges;
240 uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000241 int8_t fPadding[3];
junov@google.comf93e7172011-03-31 21:26:24 +0000242
junov@google.comf93e7172011-03-31 21:26:24 +0000243 } fProgramDesc;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000244 GR_STATIC_ASSERT(!(sizeof(ProgramDesc) % 4));
junov@google.comf93e7172011-03-31 21:26:24 +0000245
bsalomon@google.com22c5dea2011-07-07 14:38:03 +0000246 // for code readability
247 typedef ProgramDesc::StageDesc StageDesc;
248
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000249private:
250
251 const ProgramDesc& getDesc() { return fProgramDesc; }
senorblanco@chromium.orgb3a39b52012-01-05 18:28:56 +0000252 const char* adjustInColor(const GrStringBuilder& inColor) const;
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000253
junov@google.comf93e7172011-03-31 21:26:24 +0000254public:
bsalomon@google.com91961302011-05-09 18:39:58 +0000255 enum {
256 kUnusedUniform = -1,
257 kSetAsAttribute = 1000,
258 };
259
junov@google.comf93e7172011-03-31 21:26:24 +0000260 struct StageUniLocations {
261 GrGLint fTextureMatrixUni;
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000262 GrGLint fNormalizedTexelSizeUni;
junov@google.comf93e7172011-03-31 21:26:24 +0000263 GrGLint fSamplerUni;
264 GrGLint fRadial2Uni;
junov@google.com6acc9b32011-05-16 18:32:07 +0000265 GrGLint fTexDomUni;
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000266 GrGLint fKernelUni;
267 GrGLint fImageIncrementUni;
bsalomon@google.com91961302011-05-09 18:39:58 +0000268 void reset() {
269 fTextureMatrixUni = kUnusedUniform;
270 fNormalizedTexelSizeUni = kUnusedUniform;
271 fSamplerUni = kUnusedUniform;
272 fRadial2Uni = kUnusedUniform;
junov@google.com6acc9b32011-05-16 18:32:07 +0000273 fTexDomUni = kUnusedUniform;
senorblanco@chromium.org027de5f2011-07-08 18:03:33 +0000274 fKernelUni = kUnusedUniform;
275 fImageIncrementUni = kUnusedUniform;
bsalomon@google.com91961302011-05-09 18:39:58 +0000276 }
junov@google.comf93e7172011-03-31 21:26:24 +0000277 };
278
279 struct UniLocations {
280 GrGLint fViewMatrixUni;
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000281 GrGLint fColorUni;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000282 GrGLint fCoverageUni;
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000283 GrGLint fEdgesUni;
Scroggo97c88c22011-05-11 14:05:25 +0000284 GrGLint fColorFilterUni;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000285 GrGLint fColorMatrixUni;
286 GrGLint fColorMatrixVecUni;
tomhudson@google.com93813632011-10-27 20:21:16 +0000287 StageUniLocations fStages[GrDrawState::kNumStages];
bsalomon@google.com91961302011-05-09 18:39:58 +0000288 void reset() {
289 fViewMatrixUni = kUnusedUniform;
290 fColorUni = kUnusedUniform;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000291 fCoverageUni = kUnusedUniform;
senorblanco@chromium.org92e0f222011-05-12 15:49:15 +0000292 fEdgesUni = kUnusedUniform;
Scroggo97c88c22011-05-11 14:05:25 +0000293 fColorFilterUni = kUnusedUniform;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000294 fColorMatrixUni = kUnusedUniform;
295 fColorMatrixVecUni = kUnusedUniform;
tomhudson@google.com93813632011-10-27 20:21:16 +0000296 for (int s = 0; s < GrDrawState::kNumStages; ++s) {
bsalomon@google.com91961302011-05-09 18:39:58 +0000297 fStages[s].reset();
298 }
299 }
junov@google.comf93e7172011-03-31 21:26:24 +0000300 };
301
302 class CachedData : public ::GrNoncopyable {
303 public:
304 CachedData() {
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000305 for (int i = 0; i < GrDrawState::kNumStages; ++i) {
306 fCustomStage[i] = NULL;
307 }
junov@google.comf93e7172011-03-31 21:26:24 +0000308 }
309
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000310 ~CachedData();
junov@google.comf93e7172011-03-31 21:26:24 +0000311
312 void copyAndTakeOwnership(CachedData& other) {
bsalomon@google.com2d9ddf92011-05-11 16:52:59 +0000313 memcpy(this, &other, sizeof(*this));
junov@google.comf93e7172011-03-31 21:26:24 +0000314 }
315
junov@google.comf93e7172011-03-31 21:26:24 +0000316 public:
317
318 // IDs
319 GrGLuint fVShaderID;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000320 GrGLuint fGShaderID;
junov@google.comf93e7172011-03-31 21:26:24 +0000321 GrGLuint fFShaderID;
322 GrGLuint fProgramID;
323 // shader uniform locations (-1 if shader doesn't use them)
324 UniLocations fUniLocations;
325
326 GrMatrix fViewMatrix;
327
328 // these reflect the current values of uniforms
329 // (GL uniform values travel with program)
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000330 GrColor fColor;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000331 GrColor fCoverage;
Scroggo97c88c22011-05-11 14:05:25 +0000332 GrColor fColorFilterColor;
tomhudson@google.com93813632011-10-27 20:21:16 +0000333 GrMatrix fTextureMatrices[GrDrawState::kNumStages];
bsalomon@google.com6aef1fb2011-05-05 12:33:22 +0000334 // width and height used for normalized texel size
tomhudson@google.com93813632011-10-27 20:21:16 +0000335 int fTextureWidth[GrDrawState::kNumStages];
336 int fTextureHeight[GrDrawState::kNumStages];
337 GrScalar fRadial2CenterX1[GrDrawState::kNumStages];
338 GrScalar fRadial2Radius0[GrDrawState::kNumStages];
339 bool fRadial2PosRoot[GrDrawState::kNumStages];
340 GrRect fTextureDomain[GrDrawState::kNumStages];
junov@google.comf93e7172011-03-31 21:26:24 +0000341
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000342 GrGLProgramStage* fCustomStage[GrDrawState::kNumStages];
343
junov@google.comf93e7172011-03-31 21:26:24 +0000344 private:
345 enum Constants {
346 kUniLocationPreAllocSize = 8
347 };
348
junov@google.comf93e7172011-03-31 21:26:24 +0000349 }; // CachedData
350
junov@google.comf7c00f62011-08-18 18:15:16 +0000351 enum Constants {
352 kProgramKeySize = sizeof(ProgramDesc)
353 };
354
355 // Provide an opaque ProgramDesc
356 const uint32_t* keyData() const{
357 return reinterpret_cast<const uint32_t*>(&fProgramDesc);
358 }
359
junov@google.comf93e7172011-03-31 21:26:24 +0000360private:
bsalomon@google.com91961302011-05-09 18:39:58 +0000361
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000362 // Determines which uniforms will need to be bound.
bsalomon@google.com96399942012-02-13 14:39:16 +0000363 void genStageCode(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000364 int stageNum,
junov@google.comf93e7172011-03-31 21:26:24 +0000365 const ProgramDesc::StageDesc& desc,
366 const char* fsInColor, // NULL means no incoming color
367 const char* fsOutColor,
368 const char* vsInCoord,
369 ShaderCodeSegments* segments,
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000370 StageUniLocations* locations,
371 GrGLProgramStage* override) const;
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000372
bsalomon@google.com96399942012-02-13 14:39:16 +0000373 void genGeometryShader(const GrGLContextInfo& gl,
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000374 ShaderCodeSegments* segments) const;
375
bsalomon@google.com66105672011-09-15 15:12:00 +0000376 // generates code to compute coverage based on edge AA.
bsalomon@google.com96399942012-02-13 14:39:16 +0000377 void genEdgeCoverage(const GrGLContextInfo& gl,
bsalomon@google.com66105672011-09-15 15:12:00 +0000378 GrVertexLayout layout,
379 CachedData* programData,
380 GrStringBuilder* coverageVar,
381 ShaderCodeSegments* segments) const;
junov@google.comf93e7172011-03-31 21:26:24 +0000382
bsalomon@google.com96399942012-02-13 14:39:16 +0000383 static bool CompileShaders(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000384 const ShaderCodeSegments& segments,
bsalomon@google.com91961302011-05-09 18:39:58 +0000385 CachedData* programData);
386
junov@google.comf93e7172011-03-31 21:26:24 +0000387 // Compiles a GL shader, returns shader ID or 0 if failed
388 // params have same meaning as glShaderSource
bsalomon@google.com96399942012-02-13 14:39:16 +0000389 static GrGLuint CompileShader(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000390 GrGLenum type, int stringCnt,
junov@google.comf93e7172011-03-31 21:26:24 +0000391 const char** strings,
392 int* stringLengths);
393
bsalomon@google.com91961302011-05-09 18:39:58 +0000394 // Creates a GL program ID, binds shader attributes to GL vertex attrs, and
395 // links the program
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000396 bool bindOutputsAttribsAndLinkProgram(
bsalomon@google.com96399942012-02-13 14:39:16 +0000397 const GrGLContextInfo& gl,
tomhudson@google.com93813632011-10-27 20:21:16 +0000398 GrStringBuilder texCoordAttrNames[GrDrawState::kMaxTexCoords],
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000399 bool bindColorOut,
400 bool bindDualSrcOut,
401 CachedData* programData) const;
bsalomon@google.com91961302011-05-09 18:39:58 +0000402
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000403 // Binds uniforms; initializes cache to invalid values.
bsalomon@google.com96399942012-02-13 14:39:16 +0000404 void getUniformLocationsAndInitCache(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000405 CachedData* programData) const;
bsalomon@google.com91961302011-05-09 18:39:58 +0000406
junov@google.comf93e7172011-03-31 21:26:24 +0000407 friend class GrGpuGLShaders;
408};
409
410#endif