blob: bfc0d2e812b50652ce21dbca7cab454f48174ebd [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"
bsalomon@google.com890e3b52012-06-01 19:01:37 +000015#include "GrGLTexture.h"
tomhudson@google.comd8f856c2012-05-10 12:13:36 +000016#include "GrGpu.h"
junov@google.comf93e7172011-03-31 21:26:24 +000017
bsalomon@google.comf0a104e2012-07-10 17:51:07 +000018#include "SkString.h"
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;
tomhudson@google.comf9ad8862012-05-11 20:38:48 +000023class GrGLShaderBuilder;
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 };
bsalomon@google.comb505a122012-05-31 18:40:36 +0000110
bsalomon@google.com0a97be22011-11-08 19:20:57 +0000111 /**
bsalomon@google.com74b98712011-11-11 19:46:16 +0000112 Flags set based on a src texture's pixel config. The operations
113 described are performed after reading a texel.
bsalomon@google.com0a97be22011-11-08 19:20:57 +0000114 */
bsalomon@google.com74b98712011-11-11 19:46:16 +0000115 enum InConfigFlags {
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000116 kNone_InConfigFlag = 0x00,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000117
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000118 /**
bsalomon@google.com74b98712011-11-11 19:46:16 +0000119 Swap the R and B channels. This is incompatible with
120 kSmearAlpha. It is prefereable to perform the swizzle outside
121 the shader using GL_ARB_texture_swizzle if possible rather
122 than setting this flag.
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000123 */
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000124 kSwapRAndB_InConfigFlag = 0x01,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000125
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000126 /**
bsalomon@google.com74b98712011-11-11 19:46:16 +0000127 Smear alpha across all four channels. This is incompatible with
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000128 kSwapRAndB, kMulRGBByAlpha* and kSmearRed. It is prefereable
129 to perform the smear outside the shader using
130 GL_ARB_texture_swizzle if possible rather than setting this
131 flag.
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000132 */
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000133 kSmearAlpha_InConfigFlag = 0x02,
134
135 /**
136 Smear the red channel across all four channels. This flag is
137 incompatible with kSwapRAndB, kMulRGBByAlpha*and kSmearAlpha.
138 It is preferable to use GL_ARB_texture_swizzle instead of this
139 flag.
140 */
141 kSmearRed_InConfigFlag = 0x04,
bsalomon@google.com74b98712011-11-11 19:46:16 +0000142
143 /**
144 Multiply r,g,b by a after texture reads. This flag incompatible
bsalomon@google.comd2ae1fa2012-06-04 20:06:02 +0000145 with kSmearAlpha.
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 */
robertphillips@google.com443e5a52012-04-30 20:01:21 +0000152 kMulRGBByAlpha_RoundUp_InConfigFlag = 0x08,
153 kMulRGBByAlpha_RoundDown_InConfigFlag = 0x10,
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 };
junov@google.comf93e7172011-03-31 21:26:24 +0000159
tomhudson@google.com0d831722011-06-02 15:37:14 +0000160 uint8_t fOptFlags;
bsalomon@google.com74b98712011-11-11 19:46:16 +0000161 uint8_t fInConfigFlags; // bitfield of InConfigFlags values
tomhudson@google.com0d831722011-06-02 15:37:14 +0000162
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000163 /** Non-zero if user-supplied code will write the stage's
164 contribution to the fragment shader. */
165 uint16_t fCustomStageKey;
166
bsalomon@google.com74b98712011-11-11 19:46:16 +0000167 GR_STATIC_ASSERT((InConfigFlags)(uint8_t)kInConfigBitMask ==
168 kInConfigBitMask);
169
tomhudson@google.com0d831722011-06-02 15:37:14 +0000170 inline bool isEnabled() const {
bsalomon@google.comc2c9b972011-10-03 13:17:22 +0000171 return SkToBool(fOptFlags & kIsEnabled_OptFlagBit);
tomhudson@google.com0d831722011-06-02 15:37:14 +0000172 }
173 inline void setEnabled(bool newValue) {
174 if (newValue) {
175 fOptFlags |= kIsEnabled_OptFlagBit;
176 } else {
177 fOptFlags &= ~kIsEnabled_OptFlagBit;
178 }
179 }
180 };
181
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000182 // Specifies where the intitial color comes from before the stages are
183 // applied.
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000184 enum ColorInput {
185 kSolidWhite_ColorInput,
186 kTransBlack_ColorInput,
187 kAttribute_ColorInput,
188 kUniform_ColorInput,
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000189
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000190 kColorInputCnt
tomhudson@google.com0d831722011-06-02 15:37:14 +0000191 };
192 // Dual-src blending makes use of a secondary output color that can be
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000193 // used as a per-pixel blend coeffecient. This controls whether a
194 // secondary source is output and what value it holds.
195 enum DualSrcOutput {
196 kNone_DualSrcOutput,
197 kCoverage_DualSrcOutput,
198 kCoverageISA_DualSrcOutput,
199 kCoverageISC_DualSrcOutput,
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000200
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000201 kDualSrcOutputCnt
tomhudson@google.com0d831722011-06-02 15:37:14 +0000202 };
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000203
tomhudson@google.com93813632011-10-27 20:21:16 +0000204 GrDrawState::VertexEdgeType fVertexEdgeType;
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000205
tomhudson@google.com0d831722011-06-02 15:37:14 +0000206 // stripped of bits that don't affect prog generation
207 GrVertexLayout fVertexLayout;
junov@google.comf93e7172011-03-31 21:26:24 +0000208
tomhudson@google.com93813632011-10-27 20:21:16 +0000209 StageDesc fStages[GrDrawState::kNumStages];
Scroggo97c88c22011-05-11 14:05:25 +0000210
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000211 // To enable experimental geometry shader code (not for use in
212 // production)
213#if GR_GL_EXPERIMENTAL_GS
214 bool fExperimentalGS;
215#endif
216
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000217 uint8_t fColorInput; // casts to enum ColorInput
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000218 uint8_t fCoverageInput; // casts to enum CoverageInput
bsalomon@google.coma91e9232012-02-23 15:39:54 +0000219 uint8_t fOutputConfig; // casts to enum OutputConfig
bsalomon@google.com85b505b2011-11-07 14:56:51 +0000220 uint8_t fDualSrcOutput; // casts to enum DualSrcOutput
tomhudson@google.com0d831722011-06-02 15:37:14 +0000221 int8_t fFirstCoverageStage;
222 SkBool8 fEmitsPointSize;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000223 SkBool8 fColorMatrixEnabled;
junov@google.comf93e7172011-03-31 21:26:24 +0000224
tomhudson@google.com0d831722011-06-02 15:37:14 +0000225 uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode
bsalomon@google.com7ffe6812012-05-11 17:32:43 +0000226 int8_t fPadding[1];
junov@google.comf93e7172011-03-31 21:26:24 +0000227
junov@google.comf93e7172011-03-31 21:26:24 +0000228 } fProgramDesc;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000229 GR_STATIC_ASSERT(!(sizeof(ProgramDesc) % 4));
junov@google.comf93e7172011-03-31 21:26:24 +0000230
bsalomon@google.com22c5dea2011-07-07 14:38:03 +0000231 // for code readability
232 typedef ProgramDesc::StageDesc StageDesc;
233
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000234private:
235
236 const ProgramDesc& getDesc() { return fProgramDesc; }
bsalomon@google.comf0a104e2012-07-10 17:51:07 +0000237 const char* adjustInColor(const SkString& inColor) const;
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000238
junov@google.comf93e7172011-03-31 21:26:24 +0000239public:
bsalomon@google.com91961302011-05-09 18:39:58 +0000240 enum {
241 kUnusedUniform = -1,
bsalomon@google.com91961302011-05-09 18:39:58 +0000242 };
243
junov@google.comf93e7172011-03-31 21:26:24 +0000244 struct StageUniLocations {
245 GrGLint fTextureMatrixUni;
246 GrGLint fSamplerUni;
junov@google.com6acc9b32011-05-16 18:32:07 +0000247 GrGLint fTexDomUni;
bsalomon@google.com91961302011-05-09 18:39:58 +0000248 void reset() {
249 fTextureMatrixUni = kUnusedUniform;
bsalomon@google.com91961302011-05-09 18:39:58 +0000250 fSamplerUni = kUnusedUniform;
junov@google.com6acc9b32011-05-16 18:32:07 +0000251 fTexDomUni = kUnusedUniform;
bsalomon@google.com91961302011-05-09 18:39:58 +0000252 }
junov@google.comf93e7172011-03-31 21:26:24 +0000253 };
254
255 struct UniLocations {
256 GrGLint fViewMatrixUni;
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000257 GrGLint fColorUni;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000258 GrGLint fCoverageUni;
Scroggo97c88c22011-05-11 14:05:25 +0000259 GrGLint fColorFilterUni;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000260 GrGLint fColorMatrixUni;
261 GrGLint fColorMatrixVecUni;
tomhudson@google.com93813632011-10-27 20:21:16 +0000262 StageUniLocations fStages[GrDrawState::kNumStages];
bsalomon@google.com91961302011-05-09 18:39:58 +0000263 void reset() {
264 fViewMatrixUni = kUnusedUniform;
265 fColorUni = kUnusedUniform;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000266 fCoverageUni = kUnusedUniform;
Scroggo97c88c22011-05-11 14:05:25 +0000267 fColorFilterUni = kUnusedUniform;
senorblanco@chromium.org50bdad82012-01-03 20:51:57 +0000268 fColorMatrixUni = kUnusedUniform;
269 fColorMatrixVecUni = kUnusedUniform;
tomhudson@google.com93813632011-10-27 20:21:16 +0000270 for (int s = 0; s < GrDrawState::kNumStages; ++s) {
bsalomon@google.com91961302011-05-09 18:39:58 +0000271 fStages[s].reset();
272 }
273 }
junov@google.comf93e7172011-03-31 21:26:24 +0000274 };
275
276 class CachedData : public ::GrNoncopyable {
277 public:
278 CachedData() {
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000279 for (int i = 0; i < GrDrawState::kNumStages; ++i) {
280 fCustomStage[i] = NULL;
281 }
junov@google.comf93e7172011-03-31 21:26:24 +0000282 }
283
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000284 ~CachedData();
junov@google.comf93e7172011-03-31 21:26:24 +0000285
286 void copyAndTakeOwnership(CachedData& other) {
bsalomon@google.com2d9ddf92011-05-11 16:52:59 +0000287 memcpy(this, &other, sizeof(*this));
tomhudson@google.comd8f856c2012-05-10 12:13:36 +0000288 for (int i = 0; i < GrDrawState::kNumStages; ++i) {
289 other.fCustomStage[i] = NULL;
290 }
junov@google.comf93e7172011-03-31 21:26:24 +0000291 }
292
junov@google.comf93e7172011-03-31 21:26:24 +0000293 public:
294
295 // IDs
296 GrGLuint fVShaderID;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000297 GrGLuint fGShaderID;
junov@google.comf93e7172011-03-31 21:26:24 +0000298 GrGLuint fFShaderID;
299 GrGLuint fProgramID;
300 // shader uniform locations (-1 if shader doesn't use them)
301 UniLocations fUniLocations;
302
bsalomon@google.com4c883782012-06-04 19:05:11 +0000303 // The matrix sent to GL is determined by both the client's matrix and
304 // the size of the viewport.
junov@google.comf93e7172011-03-31 21:26:24 +0000305 GrMatrix fViewMatrix;
bsalomon@google.com4c883782012-06-04 19:05:11 +0000306 SkISize fViewportSize;
junov@google.comf93e7172011-03-31 21:26:24 +0000307
308 // these reflect the current values of uniforms
309 // (GL uniform values travel with program)
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000310 GrColor fColor;
bsalomon@google.com2401ae82012-01-17 21:03:05 +0000311 GrColor fCoverage;
Scroggo97c88c22011-05-11 14:05:25 +0000312 GrColor fColorFilterColor;
tomhudson@google.com93813632011-10-27 20:21:16 +0000313 GrMatrix fTextureMatrices[GrDrawState::kNumStages];
tomhudson@google.com93813632011-10-27 20:21:16 +0000314 GrRect fTextureDomain[GrDrawState::kNumStages];
bsalomon@google.com890e3b52012-06-01 19:01:37 +0000315 // The texture domain and texture matrix sent to GL depend upon the
316 // orientation.
317 GrGLTexture::Orientation fTextureOrientation[GrDrawState::kNumStages];
junov@google.comf93e7172011-03-31 21:26:24 +0000318
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000319 GrGLProgramStage* fCustomStage[GrDrawState::kNumStages];
320
junov@google.comf93e7172011-03-31 21:26:24 +0000321 private:
322 enum Constants {
323 kUniLocationPreAllocSize = 8
324 };
325
junov@google.comf93e7172011-03-31 21:26:24 +0000326 }; // CachedData
327
junov@google.comf7c00f62011-08-18 18:15:16 +0000328 enum Constants {
329 kProgramKeySize = sizeof(ProgramDesc)
330 };
331
332 // Provide an opaque ProgramDesc
333 const uint32_t* keyData() const{
334 return reinterpret_cast<const uint32_t*>(&fProgramDesc);
335 }
336
junov@google.comf93e7172011-03-31 21:26:24 +0000337private:
bsalomon@google.com91961302011-05-09 18:39:58 +0000338
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000339 // Determines which uniforms will need to be bound.
bsalomon@google.com96399942012-02-13 14:39:16 +0000340 void genStageCode(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000341 int stageNum,
junov@google.comf93e7172011-03-31 21:26:24 +0000342 const ProgramDesc::StageDesc& desc,
343 const char* fsInColor, // NULL means no incoming color
344 const char* fsOutColor,
345 const char* vsInCoord,
tomhudson@google.comf9ad8862012-05-11 20:38:48 +0000346 GrGLShaderBuilder* segments,
tomhudson@google.com07eecdc2012-04-20 18:35:38 +0000347 StageUniLocations* locations,
348 GrGLProgramStage* override) const;
bsalomon@google.com4fa66942011-09-20 19:06:12 +0000349
bsalomon@google.com96399942012-02-13 14:39:16 +0000350 void genGeometryShader(const GrGLContextInfo& gl,
tomhudson@google.comf9ad8862012-05-11 20:38:48 +0000351 GrGLShaderBuilder* segments) const;
bsalomon@google.comedfe1aa2011-09-29 14:40:26 +0000352
bsalomon@google.com66105672011-09-15 15:12:00 +0000353 // generates code to compute coverage based on edge AA.
bsalomon@google.com96399942012-02-13 14:39:16 +0000354 void genEdgeCoverage(const GrGLContextInfo& gl,
bsalomon@google.com66105672011-09-15 15:12:00 +0000355 GrVertexLayout layout,
356 CachedData* programData,
bsalomon@google.comf0a104e2012-07-10 17:51:07 +0000357 SkString* coverageVar,
tomhudson@google.comf9ad8862012-05-11 20:38:48 +0000358 GrGLShaderBuilder* segments) const;
junov@google.comf93e7172011-03-31 21:26:24 +0000359
bsalomon@google.com96399942012-02-13 14:39:16 +0000360 static bool CompileShaders(const GrGLContextInfo& gl,
tomhudson@google.comf9ad8862012-05-11 20:38:48 +0000361 const GrGLShaderBuilder& segments,
bsalomon@google.com91961302011-05-09 18:39:58 +0000362 CachedData* programData);
363
junov@google.comf93e7172011-03-31 21:26:24 +0000364 // Compiles a GL shader, returns shader ID or 0 if failed
365 // params have same meaning as glShaderSource
bsalomon@google.com96399942012-02-13 14:39:16 +0000366 static GrGLuint CompileShader(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000367 GrGLenum type, int stringCnt,
junov@google.comf93e7172011-03-31 21:26:24 +0000368 const char** strings,
369 int* stringLengths);
370
bsalomon@google.com91961302011-05-09 18:39:58 +0000371 // Creates a GL program ID, binds shader attributes to GL vertex attrs, and
372 // links the program
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000373 bool bindOutputsAttribsAndLinkProgram(
bsalomon@google.com96399942012-02-13 14:39:16 +0000374 const GrGLContextInfo& gl,
bsalomon@google.comf0a104e2012-07-10 17:51:07 +0000375 SkString texCoordAttrNames[GrDrawState::kMaxTexCoords],
bsalomon@google.com271cffc2011-05-20 14:13:56 +0000376 bool bindColorOut,
377 bool bindDualSrcOut,
378 CachedData* programData) const;
bsalomon@google.com91961302011-05-09 18:39:58 +0000379
tomhudson@google.com2a2e3ef2011-10-25 19:51:09 +0000380 // Binds uniforms; initializes cache to invalid values.
bsalomon@google.com96399942012-02-13 14:39:16 +0000381 void getUniformLocationsAndInitCache(const GrGLContextInfo& gl,
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000382 CachedData* programData) const;
bsalomon@google.com91961302011-05-09 18:39:58 +0000383
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000384 friend class GrGpuGL;
junov@google.comf93e7172011-03-31 21:26:24 +0000385};
386
387#endif