summaryrefslogtreecommitdiff
path: root/Runtime/GfxDevice/opengles20/FixedFunctionStateGLES20.h
blob: 9fe723efd45616ecfc67dba4c4bf59a78b57c2d0 (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
#ifndef FIXEDFUNCTIONSTATE_GLES20_H
#define FIXEDFUNCTIONSTATE_GLES20_H

#include "IncludesGLES20.h"
#include "Runtime/GfxDevice/GfxDeviceTypes.h"
#include <string>

// we can use one var to determine both shift and mask, but let help out the compiler ;-)
#define FFPSTATE_SET_MASK(target, idx, val, shift_mul, mask)	\
do{																\
	target &= ~(mask << ((idx)*shift_mul));						\
	target |= (val << ((idx)*shift_mul));						\
}while(0)														\



class FixedFunctionStateGLES20
{
public:
	FixedFunctionStateGLES20();

	UInt32			texUnitColorCombiner[kMaxSupportedTextureUnitsGLES];
	UInt32			texUnitAlphaCombiner[kMaxSupportedTextureUnitsGLES];
	bool			texUnitCube[kMaxSupportedTextureUnitsGLES];
	int				texUnitGen[kMaxSupportedTextureUnitsGLES];
	int				texUnitCount;

	// we will use 4bits per light - this way we can handle up to 8 lights (though kMaxEmulatedVertexLights = 4)
	UInt32			lightType;
	// we will use 2 bits per tex unit - one for perspective divide, the other one for if we need matrix mul at all
	// this way we can store 16 texunit info (though kMaxSupportedTextureUnitsGLES = 8)
	UInt32			texUnitMatrix;

	int					lightCount : 8;
	FogMode				fogMode : 8;
	CompareFunction		alphaTest : 8;

	bool			lightingEnabled;
	bool			specularEnabled;
	bool			onlyDirectionalLights;
	bool			setupPointSize;

	bool			useUniformInsteadOfVertexColor;
	bool			useVertexColorAsAmbientAndDiffuse;
	bool			useVertexColorAsEmission;
	bool			addSpecularAfterTexturing;

	unsigned		GetLightType(int i) const			{ return (lightType >> (i*4)) & 0xF; }
	void			SetLightType(int i, unsigned type)	{ FFPSTATE_SET_MASK(lightType, i, type, 4, 0xF); }

	bool			NeedTexUnitMatrix(int i) const		{ return ((texUnitMatrix >> (i*2)) & 0x1) != 0; }
	bool			IsTexUnitProjected(int i) const		{ return ((texUnitMatrix >> (i*2)) & 0x2) != 0; }

	void 			SetTexUnitMatrixParam(int i, bool hasMatrix, bool isProjected)
	{
		int mask = (hasMatrix ? 1 : 0) | (isProjected ? 2 : 0);
		FFPSTATE_SET_MASK(texUnitMatrix, i, mask, 2, 0x3);
	}

	std::string		ToString	() const;
};


#undef FFPSTATE_SET_MASK

#endif /* FIXEDFUNCTIONSTATE_GLES20_H */