blob: 8d7ca8d1bc8257970e3ac0d8141a615f7da59b27 [file] [log] [blame]
bsalomon@google.com31ec7982013-03-27 18:14:57 +00001/*
2 * Copyright 2013 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.
6 */
7
8#ifndef GrGLProgramDesc_DEFINED
9#define GrGLProgramDesc_DEFINED
10
11#include "GrGLEffect.h"
bsalomon@google.com798c8c42013-03-27 19:50:27 +000012#include "GrDrawState.h"
bsalomon@google.com26e18b52013-03-29 19:22:36 +000013#include "GrGLShaderBuilder.h"
bsalomon@google.com31ec7982013-03-27 18:14:57 +000014
15class GrGpuGL;
16
17// optionally compile the experimental GS code. Set to GR_DEBUG so that debug build bots will
18// execute the code.
19#define GR_GL_EXPERIMENTAL_GS GR_DEBUG
20
21
bsalomon@google.com26e18b52013-03-29 19:22:36 +000022/** This class describes a program to generate. It also serves as a program cache key. Very little
23 of this is GL-specific. There is the generation of GrGLEffect::EffectKeys and the dst-read part
24 of the key set by GrGLShaderBuilder. If the interfaces that set those portions were abstracted
25 to be API-neutral then so could this class. */
bsalomon@google.com31ec7982013-03-27 18:14:57 +000026class GrGLProgramDesc {
27public:
28 GrGLProgramDesc() {
29 // since we use this as part of a key we can't have any uninitialized padding
30 memset(this, 0, sizeof(GrGLProgramDesc));
31 }
32
33 // Returns this as a uint32_t array to be used as a key in the program cache
34 const uint32_t* asKey() const {
35 return reinterpret_cast<const uint32_t*>(this);
36 }
37
38 // For unit testing.
39 void setRandom(SkMWCRandom*,
40 const GrGpuGL* gpu,
bsalomon@google.comb79d8652013-03-29 20:30:50 +000041 const GrTexture* dummyDstTexture,
jvanverth@google.com054ae992013-04-01 20:06:51 +000042 const GrEffectStage stages[GrDrawState::kNumStages],
43 int currAttribIndex);
bsalomon@google.com31ec7982013-03-27 18:14:57 +000044
45 /**
46 * Builds a program descriptor from a GrDrawState. Whether the primitive type is points, the
47 * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also inputs.
48 */
49 static void Build(const GrDrawState&,
50 bool isPoints,
51 GrDrawState::BlendOptFlags,
52 GrBlendCoeff srcCoeff,
53 GrBlendCoeff dstCoeff,
54 const GrGpuGL* gpu,
bsalomon@google.com26e18b52013-03-29 19:22:36 +000055 const GrDeviceCoordTexture* dstCopy,
bsalomon@google.com31ec7982013-03-27 18:14:57 +000056 GrGLProgramDesc* outDesc);
57
58private:
59 // Specifies where the initial color comes from before the stages are applied.
60 enum ColorInput {
61 kSolidWhite_ColorInput,
62 kTransBlack_ColorInput,
63 kAttribute_ColorInput,
64 kUniform_ColorInput,
65
66 kColorInputCnt
67 };
bsalomon@google.com31ec7982013-03-27 18:14:57 +000068
bsalomon@google.com5920ac22013-04-19 13:14:45 +000069 enum CoverageOutput {
70 // modulate color and coverage, write result as the color output.
71 kModulate_CoverageOutput,
72 // Writes color*coverage as the primary color output and also writes coverage as the
73 // secondary output. Only set if dual source blending is supported.
74 kSecondaryCoverage_CoverageOutput,
75 // Writes color*coverage as the primary color output and also writes coverage * (1 - colorA)
76 // as the secondary output. Only set if dual source blending is supported.
77 kSecondaryCoverageISA_CoverageOutput,
78 // Writes color*coverage as the primary color output and also writes coverage *
79 // (1 - colorRGB) as the secondary output. Only set if dual source blending is supported.
80 kSecondaryCoverageISC_CoverageOutput,
81 // Combines the coverage, dst, and color as coverage * color + (1 - coverage) * dst. This
82 // can only be set if fDstRead is set.
83 kCombineWithDst_CoverageOutput,
84
85 kCoverageOutputCnt
bsalomon@google.com31ec7982013-03-27 18:14:57 +000086 };
87
bsalomon@google.com5920ac22013-04-19 13:14:45 +000088 static bool CoverageOutputUsesSecondaryOutput(CoverageOutput co) {
89 switch (co) {
90 case kSecondaryCoverage_CoverageOutput: // fallthru
91 case kSecondaryCoverageISA_CoverageOutput:
92 case kSecondaryCoverageISC_CoverageOutput:
93 return true;
94 default:
95 return false;
96 }
97 }
98
bsalomon@google.com31ec7982013-03-27 18:14:57 +000099 /** Non-zero if this stage has an effect */
100 GrGLEffect::EffectKey fEffectKeys[GrDrawState::kNumStages];
101
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +0000102 // To enable experimental geometry shader code (not for use in
103 // production)
104#if GR_GL_EXPERIMENTAL_GS
105 bool fExperimentalGS;
106#endif
jvanverth@google.com054ae992013-04-01 20:06:51 +0000107
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000108 GrGLShaderBuilder::DstReadKey fDstRead; // set by GrGLShaderBuilder if there
109 // are effects that must read the dst.
110 // Otherwise, 0.
111
jvanverth@google.com054ae992013-04-01 20:06:51 +0000112 // should the FS discard if the coverage is zero (to avoid stencil manipulation)
113 SkBool8 fDiscardIfZeroCoverage;
114
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000115 uint8_t fColorInput; // casts to enum ColorInput
116 uint8_t fCoverageInput; // casts to enum ColorInput
bsalomon@google.com5920ac22013-04-19 13:14:45 +0000117 uint8_t fCoverageOutput; // casts to enum CoverageOutput
jvanverth@google.com054ae992013-04-01 20:06:51 +0000118
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000119 int8_t fFirstCoverageStage;
120 SkBool8 fEmitsPointSize;
121 uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode
122
123 int8_t fPositionAttributeIndex;
jvanverth@google.com054ae992013-04-01 20:06:51 +0000124 int8_t fLocalCoordAttributeIndex;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000125 int8_t fColorAttributeIndex;
126 int8_t fCoverageAttributeIndex;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000127
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000128 // GrGLProgram and GrGLShaderBuilder read the private fields to generate code. TODO: Move all
129 // code generation to GrGLShaderBuilder (and maybe add getters rather than friending).
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000130 friend class GrGLProgram;
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000131 friend class GrGLShaderBuilder;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000132};
133
134#endif