GrGLProgram.h revision 45a412ee365694c61b50f6177382b509d1e2462b
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 6f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com */ 7f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 9f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com#ifndef GrGLProgram_DEFINED 10f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com#define GrGLProgram_DEFINED 11f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 12d8f856c32b679d9f5a9926feac005e2c0186f83ftomhudson@google.com#include "GrDrawState.h" 13dbe49f735484f8862e378b63d0a074a301093dd0bsalomon@google.com#include "GrGLEffect.h" 1496399948dc2f1afd2e9d9e5be7d646c01d17f82bbsalomon@google.com#include "GrGLContextInfo.h" 15086e5354fe7ae60e69c42bdfbc3d03bd8559b44ftomhudson@google.com#include "GrGLSL.h" 16890e3b58e78c0825820f75f1f0c5a5d71e855aa6bsalomon@google.com#include "GrGLTexture.h" 17dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com#include "GrGLUniformManager.h" 18f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 19f0a104e6f16dc095286d32f1e104894ae0b2b19fbsalomon@google.com#include "SkString.h" 2097c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo#include "SkXfermode.h" 2197c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo 22f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.comclass GrBinHashKeyBuilder; 23d698f77c13d97c61109b861eac4d25b14a5de935bsalomon@google.comclass GrGLEffect; 24f9ad8867f2bcd8563862b0a5a90b473ad020d465tomhudson@google.comclass GrGLShaderBuilder; 2591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.comclass SkMWCRandom; 26f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 27edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com// optionally compile the experimental GS code. Set to GR_DEBUG 28edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com// so that debug build bots will execute the code. 29edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com#define GR_GL_EXPERIMENTAL_GS GR_DEBUG 30edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com 31f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com/** 32f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com * This class manages a GPU program and records per-program information. 33f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com * We can specify the attribute locations so that they are constant 34f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com * across our shaders. But the driver determines the uniform locations 35f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com * at link time. We don't need to remember the sampler uniform location 36f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com * because we will bind a texture slot to it and never change it 37f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com * Uniforms are program-local so we can't rely on fHWState to hold the 38f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com * previous uniform state after a program change. 39f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com */ 409ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.comclass GrGLProgram : public GrRefCnt { 41f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.compublic: 429ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com SK_DECLARE_INST_COUNT(GrGLProgram) 434fa6694c587b3830932429766c99d08c8dd9b723bsalomon@google.com 4491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com class Desc; 4591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 4691207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com /** 4791207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * Builds a program descriptor from a GrDrawState. Whether the primitive type is points, the 4891207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also inputs. 4991207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com */ 5091207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com static void BuildDesc(const GrDrawState&, 5191207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com bool isPoints, 5291207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com GrDrawState::BlendOptFlags, 5391207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com GrBlendCoeff srcCoeff, 5491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com GrBlendCoeff dstCoeff, 5591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com const GrGpuGL* gpu, 5691207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com Desc* outDesc); 57f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 58ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com static GrGLProgram* Create(const GrGLContextInfo& gl, 59ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com const Desc& desc, 602eaaefd7e6a58339b3f93333f1e9cc92252cc303bsalomon@google.com const GrEffectStage* stages[]); 61ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com 629ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com virtual ~GrGLProgram(); 63f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 6434cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com /** 6534cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com * Call to abandon GL objects owned by this program. 6634cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com */ 67ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com void abandon(); 68ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com 69f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com /** 704285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com * The shader may modify the blend coefficients. Params are in/out 71f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com */ 72ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const; 73f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 74ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com const Desc& getDesc() { return fDesc; } 759ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 76271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com /** 776a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com * Gets the GL program ID for this program. 786a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com */ 796a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com GrGLuint programID() const { return fProgramID; } 806a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com 816a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com /** 8228f6ab4b6e63c7d1d8d46cc6998f91fbb39bfef9bsalomon@google.com * Attribute indices. These should not overlap. 83271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com */ 849196130af83782fcac4334117142475a837dd74dbsalomon@google.com static int PositionAttributeIdx() { return 0; } 8528f6ab4b6e63c7d1d8d46cc6998f91fbb39bfef9bsalomon@google.com static int ColorAttributeIdx() { return 1; } 8628f6ab4b6e63c7d1d8d46cc6998f91fbb39bfef9bsalomon@google.com static int CoverageAttributeIdx() { return 2; } 8728f6ab4b6e63c7d1d8d46cc6998f91fbb39bfef9bsalomon@google.com static int EdgeAttributeIdx() { return 3; } 8828f6ab4b6e63c7d1d8d46cc6998f91fbb39bfef9bsalomon@google.com static int TexCoordAttributeIdx(int tcIdx) { return 4 + tcIdx; } 89aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com 904285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com /** 9191207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * Some GL state that is relevant to programs is not stored per-program. In particular vertex 9291207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * attributes are global state. This struct is read and updated by GrGLProgram::setData to 9391207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * allow us to avoid setting this state redundantly. 9491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com */ 9591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com struct SharedGLState { 9691207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com GrColor fConstAttribColor; 9791207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com GrColor fConstAttribCoverage; 9891207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 9991207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com SharedGLState() { this->invalidate(); } 10091207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com void invalidate() { 10191207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com fConstAttribColor = GrColor_ILLEGAL; 10291207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com fConstAttribCoverage = GrColor_ILLEGAL; 10391207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com } 10491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com }; 10591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 10691207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com /** 1076a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com * The GrDrawState's view matrix along with the aspects of the render target determine the 1086a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com * matrix sent to GL. The size of the render target affects the GL matrix because we must 1096a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com * convert from Skia device coords to GL's normalized coords. Also the origin of the render 1106a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com * target may require us to perform a mirror-flip. 1116a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com */ 1126a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com struct MatrixState { 1136a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com SkMatrix fViewMatrix; 1146a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com SkISize fRenderTargetSize; 1156a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com GrSurfaceOrigin fRenderTargetOrigin; 1166a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com 1176a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com MatrixState() { this->invalidate(); } 1186a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com void invalidate() { 1196a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com fViewMatrix = SkMatrix::InvalidMatrix(); 12045a412ee365694c61b50f6177382b509d1e2462bbsalomon@google.com fRenderTargetSize.fWidth = -1; 12145a412ee365694c61b50f6177382b509d1e2462bbsalomon@google.com fRenderTargetSize.fHeight = -1; 1226a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com fRenderTargetOrigin = (GrSurfaceOrigin) -1; 1236a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com } 1246a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com }; 1256a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com 1266a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com /** 12734cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com * This function uploads uniforms and calls each GrGLEffect's setData. It is called before a 12834cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com * draw occurs using the program after the program has already been bound. It also uses the 12934cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com * GrGpuGL object to bind the textures required by the GrGLEffects. 13091207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * 13191207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * The color and coverage params override the GrDrawState's getColor() and getCoverage() values. 1324285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com */ 13391207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com void setData(GrGpuGL*, GrColor color, GrColor coverage, SharedGLState*); 1349196130af83782fcac4334117142475a837dd74dbsalomon@google.com 1350d831725f6d3e68650c8d3cbcafd7f4986b4b2cctomhudson@google.com // Parameters that affect code generation 136dbe49f735484f8862e378b63d0a074a301093dd0bsalomon@google.com // This structs should be kept compact; it is input to an expensive hash key generator. 13791207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com class Desc { 13891207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com public: 1399ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com Desc() { 1404285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com // since we use this as part of a key we can't have any uninitialized 1414be283f3a82895530d1b70372cd48ddb1c663fd8bsalomon@google.com // padding 1429ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com memset(this, 0, sizeof(Desc)); 1439ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com } 1449ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 1459ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com // returns this as a uint32_t array to be used as a key in the program cache 1469ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com const uint32_t* asKey() const { 1479ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com return reinterpret_cast<const uint32_t*>(this); 1484be283f3a82895530d1b70372cd48ddb1c663fd8bsalomon@google.com } 1494be283f3a82895530d1b70372cd48ddb1c663fd8bsalomon@google.com 15091207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com // For unit testing. 15191207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com void setRandom(SkMWCRandom*, 15291207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com const GrGpuGL* gpu, 15391207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com const GrEffectStage stages[GrDrawState::kNumStages]); 15491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 15591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com private: 1564285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com // Specifies where the initial color comes from before the stages are applied. 15785b505bedc35369283ca3aa4449962622842b720bsalomon@google.com enum ColorInput { 15885b505bedc35369283ca3aa4449962622842b720bsalomon@google.com kSolidWhite_ColorInput, 15985b505bedc35369283ca3aa4449962622842b720bsalomon@google.com kTransBlack_ColorInput, 16085b505bedc35369283ca3aa4449962622842b720bsalomon@google.com kAttribute_ColorInput, 16185b505bedc35369283ca3aa4449962622842b720bsalomon@google.com kUniform_ColorInput, 16286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com 16385b505bedc35369283ca3aa4449962622842b720bsalomon@google.com kColorInputCnt 1640d831725f6d3e68650c8d3cbcafd7f4986b4b2cctomhudson@google.com }; 1650d831725f6d3e68650c8d3cbcafd7f4986b4b2cctomhudson@google.com // Dual-src blending makes use of a secondary output color that can be 1664285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com // used as a per-pixel blend coefficient. This controls whether a 167271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com // secondary source is output and what value it holds. 168271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com enum DualSrcOutput { 169271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com kNone_DualSrcOutput, 170271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com kCoverage_DualSrcOutput, 171271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com kCoverageISA_DualSrcOutput, 172271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com kCoverageISC_DualSrcOutput, 1731e257a5db32e1c9e3b0dba80f43470816ef948afbsalomon@google.com 174271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com kDualSrcOutputCnt 1750d831725f6d3e68650c8d3cbcafd7f4986b4b2cctomhudson@google.com }; 176f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 17745a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com // TODO: remove these two members when edge-aa can be rewritten as a GrEffect. 1789381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrDrawState::VertexEdgeType fVertexEdgeType; 17945a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com // should the FS discard if the edge-aa coverage is zero (to avoid stencil manipulation) 18045a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com bool fDiscardIfOutsideEdge; 181aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com 1824285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com // stripped of bits that don't affect program generation 18334cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com GrVertexLayout fVertexLayout; 18497c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo 185dbe49f735484f8862e378b63d0a074a301093dd0bsalomon@google.com /** Non-zero if this stage has an effect */ 18634cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com GrGLEffect::EffectKey fEffectKeys[GrDrawState::kNumStages]; 187f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 188edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com // To enable experimental geometry shader code (not for use in 189edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com // production) 190edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com#if GR_GL_EXPERIMENTAL_GS 19134cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com bool fExperimentalGS; 192edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com#endif 19334cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com uint8_t fColorInput; // casts to enum ColorInput 19434cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com uint8_t fCoverageInput; // casts to enum ColorInput 19534cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com uint8_t fDualSrcOutput; // casts to enum DualSrcOutput 19634cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com int8_t fFirstCoverageStage; 19734cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com SkBool8 fEmitsPointSize; 19834cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode 19991207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 20091207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com friend class GrGLProgram; 2019ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com }; 2026a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com 2032a2e3ef5b84de3347aedaf1f7dd93cfcdb53d7f1tomhudson@google.comprivate: 204ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com GrGLProgram(const GrGLContextInfo& gl, 205ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com const Desc& desc, 2062eaaefd7e6a58339b3f93333f1e9cc92252cc303bsalomon@google.com const GrEffectStage* stages[]); 207ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com 208ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com bool succeeded() const { return 0 != fProgramID; } 209ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com 210ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com /** 2114285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com * This is the heavy initialization routine for building a GLProgram. 212ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com */ 2132eaaefd7e6a58339b3f93333f1e9cc92252cc303bsalomon@google.com bool genProgram(const GrEffectStage* stages[]); 214ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com 2159ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com void genInputColor(GrGLShaderBuilder* builder, SkString* inColor); 2162a2e3ef5b84de3347aedaf1f7dd93cfcdb53d7f1tomhudson@google.com 217ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com void genGeometryShader(GrGLShaderBuilder* segments) const; 2189ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 219dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com typedef GrGLUniformManager::UniformHandle UniformHandle; 220dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com 2219ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com void genUniformCoverage(GrGLShaderBuilder* segments, SkString* inOutCoverage); 2229ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 223d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com // generates code to compute coverage based on edge AA. Returns true if edge coverage was 224d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com // inserted in which case coverageVar will be updated to refer to a scalar. Otherwise, 225d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com // coverageVar is set to an empty string. 226d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com bool genEdgeCoverage(SkString* coverageVar, GrGLShaderBuilder* builder) const; 2279ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 2289ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com // Creates a GL program ID, binds shader attributes to GL vertex attrs, and links the program 22917504f5d5ea2550d29d2118193627129beb7f8b2bsalomon@google.com bool bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder, 23017504f5d5ea2550d29d2118193627129beb7f8b2bsalomon@google.com SkString texCoordAttrNames[GrDrawState::kMaxTexCoords], 2319ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com bool bindColorOut, 2329ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com bool bindDualSrcOut); 2339ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 234dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com // Sets the texture units for samplers 235dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com void initSamplerUniforms(); 2369ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 237ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com bool compileShaders(const GrGLShaderBuilder& builder); 2389ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 2399ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com const char* adjustInColor(const SkString& inColor) const; 2409196130af83782fcac4334117142475a837dd74dbsalomon@google.com 24191207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com // Helper for setData(). Makes GL calls to specify the initial color when there is not 24291207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com // per-vertex colors. 24391207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com void setColor(const GrDrawState&, GrColor color, SharedGLState*); 24491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 24591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com // Helper for setData(). Makes GL calls to specify the initial coverage when there is not 24691207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com // per-vertex coverages. 24791207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*); 24891207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 2496a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com // Helper for setData() that sets the view matrix and loads the render target height uniform 2506a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com void setMatrixAndRenderTargetHeight(const GrDrawState&); 2516a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com 25234cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com typedef SkSTArray<4, UniformHandle, true> SamplerUniSArray; 2538ae714b186ae5f4eaddee239281fbfe7282320c9skia.committer@gmail.com 25434cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com struct UniformHandles { 25534cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandle fViewMatrixUni; 25634cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandle fColorUni; 25734cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandle fCoverageUni; 25834cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandle fColorFilterUni; 259706f66831a575bdc2b1ab1331b48b793cd487356bsalomon@google.com // We use the render target height to provide a y-down frag coord when specifying 260706f66831a575bdc2b1ab1331b48b793cd487356bsalomon@google.com // origin_upper_left is not supported. 26134cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandle fRTHeightUni; 26234cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com // An array of sampler uniform handles for each effect. 26334cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com SamplerUniSArray fSamplerUnis[GrDrawState::kNumStages]; 2648ae714b186ae5f4eaddee239281fbfe7282320c9skia.committer@gmail.com 26534cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandles() { 266dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com fViewMatrixUni = GrGLUniformManager::kInvalidUniformHandle; 267dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com fColorUni = GrGLUniformManager::kInvalidUniformHandle; 268dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com fCoverageUni = GrGLUniformManager::kInvalidUniformHandle; 269dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com fColorFilterUni = GrGLUniformManager::kInvalidUniformHandle; 27034cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com fRTHeightUni = GrGLUniformManager::kInvalidUniformHandle; 2719196130af83782fcac4334117142475a837dd74dbsalomon@google.com } 272f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com }; 273f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 27434cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com // GL IDs 27534cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com GrGLuint fVShaderID; 27634cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com GrGLuint fGShaderID; 27734cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com GrGLuint fFShaderID; 27834cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com GrGLuint fProgramID; 2799ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 28034cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com // these reflect the current values of uniforms (GL uniform values travel with program) 2816a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com MatrixState fMatrixState; 2829ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com GrColor fColor; 2839ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com GrColor fCoverage; 2849ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com GrColor fColorFilterColor; 2859ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 28646fba0d79335f17429bb71d87a04d93fb2ee992bbsalomon@google.com GrGLEffect* fEffects[GrDrawState::kNumStages]; 2879ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 28834cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com Desc fDesc; 289ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com const GrGLContextInfo& fContextInfo; 2909ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 291dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com GrGLUniformManager fUniformManager; 29234cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandles fUniformHandles; 293dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com 2949ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com typedef GrRefCnt INHERITED; 295f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com}; 296f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 297f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com#endif 298