~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to GPU/Common/GPUStateUtils.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#pragma once
 
2
 
 
3
#include "GPU/ge_constants.h"
 
4
 
 
5
enum StencilValueType {
 
6
        STENCIL_VALUE_UNIFORM,
 
7
        STENCIL_VALUE_ZERO,
 
8
        STENCIL_VALUE_ONE,
 
9
        STENCIL_VALUE_KEEP,
 
10
        STENCIL_VALUE_INVERT,
 
11
        STENCIL_VALUE_INCR_4,
 
12
        STENCIL_VALUE_INCR_8,
 
13
        STENCIL_VALUE_DECR_4,
 
14
        STENCIL_VALUE_DECR_8,
 
15
};
 
16
 
 
17
enum ReplaceAlphaType {
 
18
        REPLACE_ALPHA_NO = 0,
 
19
        REPLACE_ALPHA_YES = 1,
 
20
        REPLACE_ALPHA_DUALSOURCE = 2,
 
21
};
 
22
 
 
23
enum ReplaceBlendType {
 
24
        REPLACE_BLEND_NO,
 
25
        REPLACE_BLEND_STANDARD,
 
26
        REPLACE_BLEND_PRE_SRC,
 
27
        REPLACE_BLEND_PRE_SRC_2X_ALPHA,
 
28
        REPLACE_BLEND_2X_ALPHA,
 
29
        REPLACE_BLEND_2X_SRC,
 
30
        REPLACE_BLEND_COPY_FBO,
 
31
};
 
32
 
 
33
enum LogicOpReplaceType {
 
34
        LOGICOPTYPE_NORMAL,
 
35
        LOGICOPTYPE_ONE,
 
36
        LOGICOPTYPE_INVERT,
 
37
};
 
38
 
 
39
bool IsAlphaTestTriviallyTrue();
 
40
bool IsColorTestAgainstZero();
 
41
bool IsColorTestTriviallyTrue();
 
42
bool IsAlphaTestAgainstZero();
 
43
 
 
44
StencilValueType ReplaceAlphaWithStencilType();
 
45
ReplaceAlphaType ReplaceAlphaWithStencil(ReplaceBlendType replaceBlend);
 
46
ReplaceBlendType ReplaceBlendWithShader(bool allowShaderBlend, GEBufferFormat bufferFormat);
 
47
 
 
48
bool CanUseHardwareTransform(int prim);
 
49
LogicOpReplaceType ReplaceLogicOpType();
 
50
 
 
51
 
 
52
// Common representation, should be able to set this directly with any modern API.
 
53
struct ViewportAndScissor {
 
54
        bool scissorEnable;
 
55
        int scissorX;
 
56
        int scissorY;
 
57
        int scissorW;
 
58
        int scissorH;
 
59
        float viewportX;
 
60
        float viewportY;
 
61
        float viewportW;
 
62
        float viewportH;
 
63
        float depthRangeMin;
 
64
        float depthRangeMax;
 
65
        bool dirtyProj;
 
66
        bool dirtyDepth;
 
67
};
 
68
void ConvertViewportAndScissor(bool useBufferedRendering, float renderWidth, float renderHeight, int bufferWidth, int bufferHeight, ViewportAndScissor &out);
 
69
float ToScaledDepth(u16 z);
 
70
float FromScaledDepth(float z);
 
71
float DepthSliceFactor();
 
72
 
 
73
// These are common to all modern APIs and can be easily converted with a lookup table.
 
74
enum class BlendFactor : uint8_t {
 
75
        ZERO,
 
76
        ONE,
 
77
        SRC_COLOR,
 
78
        ONE_MINUS_SRC_COLOR,
 
79
        DST_COLOR,
 
80
        ONE_MINUS_DST_COLOR,
 
81
        SRC_ALPHA,
 
82
        ONE_MINUS_SRC_ALPHA,
 
83
        DST_ALPHA,
 
84
        ONE_MINUS_DST_ALPHA,
 
85
        CONSTANT_COLOR,
 
86
        ONE_MINUS_CONSTANT_COLOR,
 
87
        CONSTANT_ALPHA,
 
88
        ONE_MINUS_CONSTANT_ALPHA,
 
89
        SRC1_ALPHA,
 
90
        ONE_MINUS_SRC1_ALPHA,
 
91
        INVALID,
 
92
        COUNT,
 
93
};
 
94
 
 
95
enum class BlendEq : uint8_t {
 
96
        ADD,
 
97
        SUBTRACT,
 
98
        REVERSE_SUBTRACT,
 
99
        MIN,
 
100
        MAX,
 
101
        COUNT
 
102
};
 
103
 
 
104
struct GenericBlendState {
 
105
        bool enabled;
 
106
        bool resetShaderBlending;
 
107
        bool applyShaderBlending;
 
108
        bool dirtyShaderBlend;
 
109
        ReplaceAlphaType replaceAlphaWithStencil;
 
110
 
 
111
        BlendFactor srcColor;
 
112
        BlendFactor dstColor;
 
113
        BlendFactor srcAlpha;
 
114
        BlendFactor dstAlpha;
 
115
 
 
116
        BlendEq eqColor;
 
117
        BlendEq eqAlpha;
 
118
 
 
119
        bool useBlendColor;
 
120
        u32 blendColor;
 
121
 
 
122
        void setFactors(BlendFactor srcC, BlendFactor dstC, BlendFactor srcA, BlendFactor dstA) {
 
123
                srcColor = srcC;
 
124
                dstColor = dstC;
 
125
                srcAlpha = srcA;
 
126
                dstAlpha = dstA;
 
127
        }
 
128
        void setEquation(BlendEq eqC, BlendEq eqA) {
 
129
                eqColor = eqC;
 
130
                eqAlpha = eqA;
 
131
        }
 
132
        void setBlendColor(uint32_t color, uint8_t alpha) {
 
133
                blendColor = color | ((uint32_t)alpha << 24);
 
134
                useBlendColor = true;
 
135
        }
 
136
        void defaultBlendColor(uint8_t alpha) {
 
137
                blendColor = 0xFFFFFF | ((uint32_t)alpha << 24);
 
138
                useBlendColor = true;
 
139
        }
 
140
};
 
141
 
 
142
void ConvertBlendState(GenericBlendState &blendState, bool allowShaderBlend);
 
143
void ApplyStencilReplaceAndLogicOp(ReplaceAlphaType replaceAlphaWithStencil, GenericBlendState &blendState);
 
144
 
 
145
struct GenericStencilFuncState {
 
146
        bool enabled;
 
147
        GEComparison testFunc;
 
148
        u8 testRef;
 
149
        u8 testMask;
 
150
        u8 writeMask;
 
151
        GEStencilOp sFail;
 
152
        GEStencilOp zFail;
 
153
        GEStencilOp zPass;
 
154
};
 
155
 
 
156
void ConvertStencilFuncState(GenericStencilFuncState &stencilFuncState);