3
#include "base/basictypes.h"
5
// TODO: There will be additional bits, indicating that groups of these will be
6
// sent to the shader and processed there. This will cut down the number of shaders ("ubershader approach")
7
// This is probably only really worth doing for lighting and bones.
10
VS_BIT_IS_THROUGH = 1,
11
VS_BIT_ENABLE_FOG = 2,
13
VS_BIT_DO_TEXTURE = 4,
14
VS_BIT_DO_TEXTURE_PROJ = 6,
15
VS_BIT_USE_HW_TRANSFORM = 8,
16
VS_BIT_HAS_NORMAL = 9, // conditioned on hw transform
17
VS_BIT_NORM_REVERSE = 10,
18
VS_BIT_HAS_TEXCOORD = 11, // 5 free after
19
VS_BIT_UVGEN_MODE = 16,
20
VS_BIT_UVPROJ_MODE = 18, // 2, can overlap with LS0
23
VS_BIT_BONES = 22, // 3 should be enough, not 8
24
VS_BIT_ENABLE_BONES = 30,
25
VS_BIT_LIGHT0_COMP = 32, // 2 bits
26
VS_BIT_LIGHT0_TYPE = 34, // 2 bits
27
VS_BIT_LIGHT1_COMP = 36, // 2 bits
28
VS_BIT_LIGHT1_TYPE = 38, // 2 bits
29
VS_BIT_LIGHT2_COMP = 40, // 2 bits
30
VS_BIT_LIGHT2_TYPE = 42, // 2 bits
31
VS_BIT_LIGHT3_COMP = 44, // 2 bits
32
VS_BIT_LIGHT3_TYPE = 46, // 2 bits
33
VS_BIT_MATERIAL_UPDATE = 48, // 3 bits, 1 free after
34
VS_BIT_LIGHT0_ENABLE = 52,
35
VS_BIT_LIGHT1_ENABLE = 53,
36
VS_BIT_LIGHT2_ENABLE = 54,
37
VS_BIT_LIGHT3_ENABLE = 55,
38
VS_BIT_LIGHTING_ENABLE = 56,
39
VS_BIT_WEIGHT_FMTSCALE = 57, // only two bits, 1 free after
40
VS_BIT_TEXCOORD_FMTSCALE = 60,
41
VS_BIT_FLATSHADE = 62, // 1 free after
48
FS_BIT_DO_TEXTURE = 1,
49
FS_BIT_TEXFUNC = 2, // 3 bits
51
FS_BIT_SHADER_TEX_CLAMP = 7,
54
FS_BIT_TEXTURE_AT_OFFSET = 10,
56
FS_BIT_ALPHA_TEST = 12,
57
FS_BIT_ALPHA_TEST_FUNC = 13, // 3 bits
58
FS_BIT_ALPHA_AGAINST_ZERO = 16,
59
FS_BIT_COLOR_TEST = 17,
60
FS_BIT_COLOR_TEST_FUNC = 18, // 2 bits
61
FS_BIT_COLOR_AGAINST_ZERO = 20,
62
FS_BIT_ENABLE_FOG = 21,
63
FS_BIT_DO_TEXTURE_PROJ = 22,
64
FS_BIT_COLOR_DOUBLE = 23,
65
FS_BIT_STENCIL_TO_ALPHA = 24, // 2 bits
66
FS_BIT_REPLACE_ALPHA_WITH_STENCIL_TYPE = 26, // 4 bits
67
FS_BIT_REPLACE_LOGIC_OP_TYPE = 30, // 2 bits
68
FS_BIT_REPLACE_BLEND = 32, // 3 bits
69
FS_BIT_BLENDEQ = 35, // 3 bits
70
FS_BIT_BLENDFUNC_A = 38, // 4 bits
71
FS_BIT_BLENDFUNC_B = 42,
72
FS_BIT_FLATSHADE = 46,
73
FS_BIT_BGRA_TEXTURE = 47,
81
for (size_t i = 0; i < ARRAY_SIZE(d); i++) {
86
for (size_t i = 0; i < ARRAY_SIZE(d); i++) {
92
bool operator < (const ShaderID &other) const {
93
for (size_t i = 0; i < sizeof(d) / sizeof(u32); i++) {
94
if (d[i] < other.d[i])
96
if (d[i] > other.d[i])
101
bool operator == (const ShaderID &other) const {
102
for (size_t i = 0; i < sizeof(d) / sizeof(u32); i++) {
103
if (d[i] != other.d[i])
109
bool Bit(int bit) const {
110
return (d[bit >> 5] >> (bit & 31)) & 1;
112
// Does not handle crossing 32-bit boundaries
113
int Bits(int bit, int count) const {
114
const int mask = (1 << count) - 1;
115
return (d[bit >> 5] >> (bit & 31)) & mask;
117
void SetBit(int bit, bool value = true) {
119
d[bit >> 5] |= 1 << (bit & 31);
122
void SetBits(int bit, int count, int value) {
124
const int mask = (1 << count) - 1;
125
d[bit >> 5] |= (value & mask) << (bit & 31);
129
void ToString(std::string *dest) const {
130
dest->resize(sizeof(d));
131
memcpy(&(*dest)[0], d, sizeof(d));
133
void FromString(std::string src) {
134
memcpy(d, &(src)[0], sizeof(d));
139
bool CanUseHardwareTransform(int prim);
140
void ComputeVertexShaderID(ShaderID *id, u32 vertexType, bool useHWTransform);
141
// Generates a compact string that describes the shader. Useful in a list to get an overview
142
// of the current flora of shaders.
143
std::string VertexShaderDesc(const ShaderID &id);
145
void ComputeFragmentShaderID(ShaderID *id);
146
std::string FragmentShaderDesc(const ShaderID &id);