summaryrefslogtreecommitdiff
path: root/Runtime/GfxDevice/GfxDeviceResources.h
blob: 9cb78254f0b8946f0abe4a848164d35371830824 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#pragma once

#include "GfxDeviceTypes.h"

template<typename T> 
struct memcmp_less 
{
	bool operator () (const T& lhs, const T& rhs) const 
	{
		return memcmp(&lhs, &rhs, sizeof(T)) < 0;
	}
};


struct GfxBlendState
{
	BlendMode	srcBlend;
	BlendMode	dstBlend;
	BlendMode	srcBlendAlpha;
	BlendMode	dstBlendAlpha;
	BlendOp		blendOp;
	BlendOp		blendOpAlpha;
	UInt32		renderTargetWriteMask;
	CompareFunction alphaTest;
	bool		alphaToMask;

	GfxBlendState()
	{
		memset(this, 0, sizeof(*this));
		srcBlend = kBlendOne;
		dstBlend = kBlendZero;
		srcBlendAlpha = kBlendOne;
		dstBlendAlpha = kBlendZero;
		blendOp = kBlendOpAdd;
		blendOpAlpha = kBlendOpAdd;
		renderTargetWriteMask = KColorWriteAll;
		alphaTest = kFuncDisabled;
		alphaToMask = false;
	}
};


struct GfxRasterState
{
	CullMode	cullMode;
	int			depthBias;
	float		slopeScaledDepthBias;

	GfxRasterState()
	{
		memset(this, 0, sizeof(*this));
		cullMode = kCullBack;
		depthBias = 0;
		slopeScaledDepthBias = 0.0f;
	}
};


struct GfxDepthState
{
	bool			depthWrite;
	CompareFunction depthFunc;

	GfxDepthState()
	{
		memset(this, 0, sizeof(*this));
		depthWrite = true;
		depthFunc = kFuncLess;
	}
};

struct GfxStencilState
{
	bool			stencilEnable;
	UInt8			readMask;
	UInt8			writeMask;
	CompareFunction	stencilFuncFront;
	StencilOp		stencilPassOpFront; // stencil and depth pass
	StencilOp		stencilFailOpFront; // stencil fail (depth irrelevant)
	StencilOp		stencilZFailOpFront; // stencil pass, depth fail
	CompareFunction	stencilFuncBack;
	StencilOp		stencilPassOpBack;
	StencilOp		stencilFailOpBack;
	StencilOp		stencilZFailOpBack;

	GfxStencilState()
	{
		memset(this, 0, sizeof(*this));
		stencilEnable = false;
		readMask = 0xFF;
		writeMask = 0xFF;
		stencilFuncFront = kFuncAlways;
		stencilFailOpFront = kStencilOpKeep;
		stencilZFailOpFront = kStencilOpKeep;
		stencilPassOpFront = kStencilOpKeep;
		stencilFuncBack = kFuncAlways;
		stencilFailOpBack = kStencilOpKeep;
		stencilZFailOpBack = kStencilOpKeep;
		stencilPassOpBack = kStencilOpKeep;
	}
};

struct DeviceBlendState
{
	DeviceBlendState(const GfxBlendState& src) : sourceState(src) {}
	DeviceBlendState() {}
	GfxBlendState sourceState;
};

struct DeviceDepthState
{
	DeviceDepthState(const GfxDepthState& src) : sourceState(src) {}
	DeviceDepthState() {}
	GfxDepthState sourceState;
};

struct DeviceStencilState
{
	DeviceStencilState(const GfxStencilState& src) : sourceState(src) {}
	DeviceStencilState() {}
	GfxStencilState sourceState;
};

struct DeviceRasterState
{
	DeviceRasterState(const GfxRasterState& src) : sourceState(src) {}
	DeviceRasterState() {}
	GfxRasterState sourceState;
};