GrGLProgram.h revision 6177e6999d23a4268ffd98dedfb1da00e272a89b
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" 146177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com#include "GrGLContext.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 586177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com static GrGLProgram* Create(const GrGLContext& 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 /** 8291207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * Some GL state that is relevant to programs is not stored per-program. In particular vertex 8391207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * attributes are global state. This struct is read and updated by GrGLProgram::setData to 8491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * allow us to avoid setting this state redundantly. 8591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com */ 8691207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com struct SharedGLState { 8791207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com GrColor fConstAttribColor; 8891207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com GrColor fConstAttribCoverage; 8991207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 9091207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com SharedGLState() { this->invalidate(); } 9191207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com void invalidate() { 9291207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com fConstAttribColor = GrColor_ILLEGAL; 9391207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com fConstAttribCoverage = GrColor_ILLEGAL; 9491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com } 9591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com }; 9691207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 9791207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com /** 986a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com * The GrDrawState's view matrix along with the aspects of the render target determine the 996a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com * matrix sent to GL. The size of the render target affects the GL matrix because we must 1006a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com * convert from Skia device coords to GL's normalized coords. Also the origin of the render 1016a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com * target may require us to perform a mirror-flip. 1026a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com */ 1036a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com struct MatrixState { 1046a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com SkMatrix fViewMatrix; 1056a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com SkISize fRenderTargetSize; 1066a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com GrSurfaceOrigin fRenderTargetOrigin; 1076a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com 1086a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com MatrixState() { this->invalidate(); } 1096a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com void invalidate() { 1106a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com fViewMatrix = SkMatrix::InvalidMatrix(); 11145a412ee365694c61b50f6177382b509d1e2462bbsalomon@google.com fRenderTargetSize.fWidth = -1; 11245a412ee365694c61b50f6177382b509d1e2462bbsalomon@google.com fRenderTargetSize.fHeight = -1; 1136a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com fRenderTargetOrigin = (GrSurfaceOrigin) -1; 1146a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com } 1156a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com }; 1166a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com 1176a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com /** 11834cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com * This function uploads uniforms and calls each GrGLEffect's setData. It is called before a 11934cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com * draw occurs using the program after the program has already been bound. It also uses the 12034cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com * GrGpuGL object to bind the textures required by the GrGLEffects. 12191207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * 12291207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com * The color and coverage params override the GrDrawState's getColor() and getCoverage() values. 1234285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com */ 12491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com void setData(GrGpuGL*, GrColor color, GrColor coverage, SharedGLState*); 1259196130af83782fcac4334117142475a837dd74dbsalomon@google.com 1260d831725f6d3e68650c8d3cbcafd7f4986b4b2cctomhudson@google.com // Parameters that affect code generation 127dbe49f735484f8862e378b63d0a074a301093dd0bsalomon@google.com // This structs should be kept compact; it is input to an expensive hash key generator. 12891207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com class Desc { 12991207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com public: 1309ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com Desc() { 1314285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com // since we use this as part of a key we can't have any uninitialized 1324be283f3a82895530d1b70372cd48ddb1c663fd8bsalomon@google.com // padding 1339ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com memset(this, 0, sizeof(Desc)); 1349ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com } 1359ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 1369ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com // returns this as a uint32_t array to be used as a key in the program cache 1379ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com const uint32_t* asKey() const { 1389ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com return reinterpret_cast<const uint32_t*>(this); 1394be283f3a82895530d1b70372cd48ddb1c663fd8bsalomon@google.com } 1404be283f3a82895530d1b70372cd48ddb1c663fd8bsalomon@google.com 14191207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com // For unit testing. 14291207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com void setRandom(SkMWCRandom*, 14391207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com const GrGpuGL* gpu, 14491207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com const GrEffectStage stages[GrDrawState::kNumStages]); 14591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 14691207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com private: 1474285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com // Specifies where the initial color comes from before the stages are applied. 14885b505bedc35369283ca3aa4449962622842b720bsalomon@google.com enum ColorInput { 14985b505bedc35369283ca3aa4449962622842b720bsalomon@google.com kSolidWhite_ColorInput, 15085b505bedc35369283ca3aa4449962622842b720bsalomon@google.com kTransBlack_ColorInput, 15185b505bedc35369283ca3aa4449962622842b720bsalomon@google.com kAttribute_ColorInput, 15285b505bedc35369283ca3aa4449962622842b720bsalomon@google.com kUniform_ColorInput, 15386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com 15485b505bedc35369283ca3aa4449962622842b720bsalomon@google.com kColorInputCnt 1550d831725f6d3e68650c8d3cbcafd7f4986b4b2cctomhudson@google.com }; 1560d831725f6d3e68650c8d3cbcafd7f4986b4b2cctomhudson@google.com // Dual-src blending makes use of a secondary output color that can be 1574285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com // used as a per-pixel blend coefficient. This controls whether a 158271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com // secondary source is output and what value it holds. 159271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com enum DualSrcOutput { 160271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com kNone_DualSrcOutput, 161271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com kCoverage_DualSrcOutput, 162271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com kCoverageISA_DualSrcOutput, 163271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com kCoverageISC_DualSrcOutput, 1641e257a5db32e1c9e3b0dba80f43470816ef948afbsalomon@google.com 165271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com kDualSrcOutputCnt 1660d831725f6d3e68650c8d3cbcafd7f4986b4b2cctomhudson@google.com }; 167f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 16845a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com // TODO: remove these two members when edge-aa can be rewritten as a GrEffect. 1699381363050ec9d3e724076a8e9152bfa9a8de1d1tomhudson@google.com GrDrawState::VertexEdgeType fVertexEdgeType; 17045a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com // should the FS discard if the edge-aa coverage is zero (to avoid stencil manipulation) 17145a15f551b5b3c6c747d8eaf6466b7d3b76a8faebsalomon@google.com bool fDiscardIfOutsideEdge; 172aeb2160b1dd34f8e640e8e56544fe407d4ff6311bsalomon@google.com 1734285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com // stripped of bits that don't affect program generation 174b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com GrAttribBindings fAttribBindings; 17597c88c255cff3dbb8343c5d090526fdbedad6dd6Scroggo 176dbe49f735484f8862e378b63d0a074a301093dd0bsalomon@google.com /** Non-zero if this stage has an effect */ 17734cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com GrGLEffect::EffectKey fEffectKeys[GrDrawState::kNumStages]; 178f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 179edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com // To enable experimental geometry shader code (not for use in 180edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com // production) 181edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com#if GR_GL_EXPERIMENTAL_GS 18234cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com bool fExperimentalGS; 183edfe1aac5c6f3a3f3830e86ddea8dbceeb0e6df4bsalomon@google.com#endif 18434cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com uint8_t fColorInput; // casts to enum ColorInput 18534cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com uint8_t fCoverageInput; // casts to enum ColorInput 18634cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com uint8_t fDualSrcOutput; // casts to enum DualSrcOutput 18734cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com int8_t fFirstCoverageStage; 18834cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com SkBool8 fEmitsPointSize; 18934cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode 19091207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 191b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com int8_t fPositionAttributeIndex; 192b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com int8_t fColorAttributeIndex; 193b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com int8_t fCoverageAttributeIndex; 194b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com int8_t fEdgeAttributeIndex; 195b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com int8_t fTexCoordAttributeIndex; 196b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com 19791207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com friend class GrGLProgram; 1989ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com }; 1996a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com 200b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com // Layout information for OpenGL vertex attributes 201b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com struct AttribLayout { 202b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com GrGLint fCount; 203b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com GrGLenum fType; 204b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com GrGLboolean fNormalized; 205b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com }; 206b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com static const AttribLayout kAttribLayouts[kGrVertexAttribTypeCount]; 207b8b705b1b983a2ee3a254bed4dd03f926101e4e7jvanverth@google.com 2082a2e3ef5b84de3347aedaf1f7dd93cfcdb53d7f1tomhudson@google.comprivate: 2096177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com GrGLProgram(const GrGLContext& gl, 210ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com const Desc& desc, 2112eaaefd7e6a58339b3f93333f1e9cc92252cc303bsalomon@google.com const GrEffectStage* stages[]); 212ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com 213ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com bool succeeded() const { return 0 != fProgramID; } 214ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com 215ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com /** 2164285accf5af574e6c826d5d09f0359c6149fd717bsalomon@google.com * This is the heavy initialization routine for building a GLProgram. 217ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com */ 2182eaaefd7e6a58339b3f93333f1e9cc92252cc303bsalomon@google.com bool genProgram(const GrEffectStage* stages[]); 219ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com 2209ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com void genInputColor(GrGLShaderBuilder* builder, SkString* inColor); 2212a2e3ef5b84de3347aedaf1f7dd93cfcdb53d7f1tomhudson@google.com 222ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com void genGeometryShader(GrGLShaderBuilder* segments) const; 2239ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 224dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com typedef GrGLUniformManager::UniformHandle UniformHandle; 225dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com 2269ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com void genUniformCoverage(GrGLShaderBuilder* segments, SkString* inOutCoverage); 2279ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 228d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com // generates code to compute coverage based on edge AA. Returns true if edge coverage was 229d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com // inserted in which case coverageVar will be updated to refer to a scalar. Otherwise, 230d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com // coverageVar is set to an empty string. 231d472620458e2383e6dd949f4e1aaf61160717ffebsalomon@google.com bool genEdgeCoverage(SkString* coverageVar, GrGLShaderBuilder* builder) const; 2329ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 2339ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com // Creates a GL program ID, binds shader attributes to GL vertex attrs, and links the program 23417504f5d5ea2550d29d2118193627129beb7f8b2bsalomon@google.com bool bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder, 2359ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com bool bindColorOut, 2369ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com bool bindDualSrcOut); 2379ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 238dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com // Sets the texture units for samplers 239dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com void initSamplerUniforms(); 2409ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 241ecb60aad5c6fe5b1dbcfc86ac00bfc9326103c8dbsalomon@google.com bool compileShaders(const GrGLShaderBuilder& builder); 2429ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 2439ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com const char* adjustInColor(const SkString& inColor) const; 2449196130af83782fcac4334117142475a837dd74dbsalomon@google.com 24591207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com // Helper for setData(). Makes GL calls to specify the initial color when there is not 24691207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com // per-vertex colors. 24791207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com void setColor(const GrDrawState&, GrColor color, SharedGLState*); 24891207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 24991207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com // Helper for setData(). Makes GL calls to specify the initial coverage when there is not 25091207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com // per-vertex coverages. 25191207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*); 25291207482c9398944fc997aeb99ed5f8674be58cbbsalomon@google.com 2536a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com // Helper for setData() that sets the view matrix and loads the render target height uniform 2546a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com void setMatrixAndRenderTargetHeight(const GrDrawState&); 2556a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com 25634cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com typedef SkSTArray<4, UniformHandle, true> SamplerUniSArray; 2578ae714b186ae5f4eaddee239281fbfe7282320c9skia.committer@gmail.com 25834cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com struct UniformHandles { 25934cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandle fViewMatrixUni; 26034cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandle fColorUni; 26134cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandle fCoverageUni; 26234cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandle fColorFilterUni; 263706f66831a575bdc2b1ab1331b48b793cd487356bsalomon@google.com // We use the render target height to provide a y-down frag coord when specifying 264706f66831a575bdc2b1ab1331b48b793cd487356bsalomon@google.com // origin_upper_left is not supported. 26534cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandle fRTHeightUni; 26634cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com // An array of sampler uniform handles for each effect. 26734cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com SamplerUniSArray fSamplerUnis[GrDrawState::kNumStages]; 2688ae714b186ae5f4eaddee239281fbfe7282320c9skia.committer@gmail.com 26934cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandles() { 270dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com fViewMatrixUni = GrGLUniformManager::kInvalidUniformHandle; 271dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com fColorUni = GrGLUniformManager::kInvalidUniformHandle; 272dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com fCoverageUni = GrGLUniformManager::kInvalidUniformHandle; 273dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com fColorFilterUni = GrGLUniformManager::kInvalidUniformHandle; 27434cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com fRTHeightUni = GrGLUniformManager::kInvalidUniformHandle; 2759196130af83782fcac4334117142475a837dd74dbsalomon@google.com } 276f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com }; 277f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 27834cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com // GL IDs 27934cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com GrGLuint fVShaderID; 28034cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com GrGLuint fGShaderID; 28134cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com GrGLuint fFShaderID; 28234cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com GrGLuint fProgramID; 2839ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 28434cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com // these reflect the current values of uniforms (GL uniform values travel with program) 2856a51dcbf81cff6d92996ab3f4c7457478e441896bsalomon@google.com MatrixState fMatrixState; 2869ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com GrColor fColor; 2879ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com GrColor fCoverage; 2889ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com GrColor fColorFilterColor; 2899ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 29046fba0d79335f17429bb71d87a04d93fb2ee992bbsalomon@google.com GrGLEffect* fEffects[GrDrawState::kNumStages]; 2919ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 29234cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com Desc fDesc; 2936177e6999d23a4268ffd98dedfb1da00e272a89brobertphillips@google.com const GrGLContext& fContext; 2949ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com 295dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com GrGLUniformManager fUniformManager; 29634cccde630fc618649b9737bee464203d042bfbbbsalomon@google.com UniformHandles fUniformHandles; 297dbbc4e2da93cef5c0cfb0b3c92ff6c2c80f6e67absalomon@google.com 2989ba4fa6f0fb8ef496d81ccac36e780aa806fea83bsalomon@google.com typedef GrRefCnt INHERITED; 299f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com}; 300f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com 301f93e717c7f7ca679a80acbfda6a34013ae1e2b8djunov@google.com#endif 302