blob: df5729fb18bca0e40f48eb72f210ebee893915a0 [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,
bsalomon@google.com31ec7982013-03-27 18:14:57 +000042 const GrEffectStage stages[GrDrawState::kNumStages]);
43
44 /**
45 * Builds a program descriptor from a GrDrawState. Whether the primitive type is points, the
46 * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also inputs.
47 */
48 static void Build(const GrDrawState&,
49 bool isPoints,
50 GrDrawState::BlendOptFlags,
51 GrBlendCoeff srcCoeff,
52 GrBlendCoeff dstCoeff,
53 const GrGpuGL* gpu,
bsalomon@google.com26e18b52013-03-29 19:22:36 +000054 const GrDeviceCoordTexture* dstCopy,
bsalomon@google.com31ec7982013-03-27 18:14:57 +000055 GrGLProgramDesc* outDesc);
56
57private:
58 // Specifies where the initial color comes from before the stages are applied.
59 enum ColorInput {
60 kSolidWhite_ColorInput,
61 kTransBlack_ColorInput,
62 kAttribute_ColorInput,
63 kUniform_ColorInput,
64
65 kColorInputCnt
66 };
67 // Dual-src blending makes use of a secondary output color that can be
68 // used as a per-pixel blend coefficient. This controls whether a
69 // secondary source is output and what value it holds.
70 enum DualSrcOutput {
71 kNone_DualSrcOutput,
72 kCoverage_DualSrcOutput,
73 kCoverageISA_DualSrcOutput,
74 kCoverageISC_DualSrcOutput,
75
76 kDualSrcOutputCnt
77 };
78
79 // should the FS discard if the coverage is zero (to avoid stencil manipulation)
80 bool fDiscardIfZeroCoverage;
81
82 // stripped of bits that don't affect program generation
83 GrAttribBindings fAttribBindings;
84
85 /** Non-zero if this stage has an effect */
86 GrGLEffect::EffectKey fEffectKeys[GrDrawState::kNumStages];
87
88 // To enable experimental geometry shader code (not for use in
89 // production)
90#if GR_GL_EXPERIMENTAL_GS
91 bool fExperimentalGS;
92#endif
bsalomon@google.com26e18b52013-03-29 19:22:36 +000093 GrGLShaderBuilder::DstReadKey fDstRead; // set by GrGLShaderBuilder if there
94 // are effects that must read the dst.
95 // Otherwise, 0.
96
bsalomon@google.com31ec7982013-03-27 18:14:57 +000097 uint8_t fColorInput; // casts to enum ColorInput
98 uint8_t fCoverageInput; // casts to enum ColorInput
99 uint8_t fDualSrcOutput; // casts to enum DualSrcOutput
100 int8_t fFirstCoverageStage;
101 SkBool8 fEmitsPointSize;
102 uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode
103
104 int8_t fPositionAttributeIndex;
105 int8_t fColorAttributeIndex;
106 int8_t fCoverageAttributeIndex;
107 int8_t fLocalCoordsAttributeIndex;
108
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000109 // GrGLProgram and GrGLShaderBuilder read the private fields to generate code. TODO: Move all
110 // code generation to GrGLShaderBuilder (and maybe add getters rather than friending).
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000111 friend class GrGLProgram;
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000112 friend class GrGLShaderBuilder;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000113};
114
115#endif