blob: d2167c758b0112d9bb03f8be8b55fb1fd198d407 [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 };
68 // Dual-src blending makes use of a secondary output color that can be
69 // used as a per-pixel blend coefficient. This controls whether a
70 // secondary source is output and what value it holds.
71 enum DualSrcOutput {
72 kNone_DualSrcOutput,
73 kCoverage_DualSrcOutput,
74 kCoverageISA_DualSrcOutput,
75 kCoverageISC_DualSrcOutput,
76
77 kDualSrcOutputCnt
78 };
79
bsalomon@google.com31ec7982013-03-27 18:14:57 +000080 /** Non-zero if this stage has an effect */
81 GrGLEffect::EffectKey fEffectKeys[GrDrawState::kNumStages];
82
skia.committer@gmail.com05a2ee02013-04-02 07:01:34 +000083 // To enable experimental geometry shader code (not for use in
84 // production)
85#if GR_GL_EXPERIMENTAL_GS
86 bool fExperimentalGS;
87#endif
jvanverth@google.com054ae992013-04-01 20:06:51 +000088
bsalomon@google.com26e18b52013-03-29 19:22:36 +000089 GrGLShaderBuilder::DstReadKey fDstRead; // set by GrGLShaderBuilder if there
90 // are effects that must read the dst.
91 // Otherwise, 0.
92
jvanverth@google.com054ae992013-04-01 20:06:51 +000093 // should the FS discard if the coverage is zero (to avoid stencil manipulation)
94 SkBool8 fDiscardIfZeroCoverage;
95
bsalomon@google.com31ec7982013-03-27 18:14:57 +000096 uint8_t fColorInput; // casts to enum ColorInput
97 uint8_t fCoverageInput; // casts to enum ColorInput
98 uint8_t fDualSrcOutput; // casts to enum DualSrcOutput
jvanverth@google.com054ae992013-04-01 20:06:51 +000099
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000100 int8_t fFirstCoverageStage;
101 SkBool8 fEmitsPointSize;
102 uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode
103
104 int8_t fPositionAttributeIndex;
jvanverth@google.com054ae992013-04-01 20:06:51 +0000105 int8_t fLocalCoordAttributeIndex;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000106 int8_t fColorAttributeIndex;
107 int8_t fCoverageAttributeIndex;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000108
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