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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#pragma once
#include "Runtime/Camera/Lighting.h"
#include "Runtime/Math/Matrix4x4.h"
#include "Runtime/Math/Vector4.h"
#include "GfxDeviceTypes.h"
// --------------------------------------------------------------------------
// A type safe opaque pointer to something.
// ID type is used just so that you can have handles to different types, all type safe.
template<typename ID, typename ObjectPtrType=void*>
struct ObjectHandle
{
explicit ObjectHandle(ObjectPtrType obj = 0) : object(obj) {}
bool IsValid() const { return object != 0; }
void Reset() { object = 0; }
bool operator==( const ObjectHandle<ID,ObjectPtrType>& o ) const { return object == o.object; }
bool operator!=( const ObjectHandle<ID,ObjectPtrType>& o ) const { return object != o.object; }
ObjectPtrType object;
};
#define OBJECT_FROM_HANDLE(handle,type) reinterpret_cast<type*>((handle).object)
// --------------------------------------------------------------------------
struct RenderSurfaceBase;
struct RenderSurface_Tag;
typedef ObjectHandle<RenderSurface_Tag, RenderSurfaceBase*> RenderSurfaceHandle;
struct GraphicsContext_Tag;
typedef ObjectHandle<GraphicsContext_Tag> GraphicsContextHandle;
struct TextureCombiners_Tag;
typedef ObjectHandle<TextureCombiners_Tag> TextureCombinersHandle;
struct ComputeProgram_Tag;
typedef ObjectHandle<ComputeProgram_Tag> ComputeProgramHandle;
struct ConstantBuffer_Tag;
typedef ObjectHandle<ConstantBuffer_Tag> ConstantBufferHandle;
// --------------------------------------------------------------------------
struct SimpleVec4
{
float val[4];
void set( const float *v )
{
val[0] = v[0];
val[1] = v[1];
val[2] = v[2];
val[3] = v[3];
}
void set( float v0, float v1, float v2, float v3 )
{
val[0] = v0;
val[1] = v1;
val[2] = v2;
val[3] = v3;
}
bool operator==(const SimpleVec4& o) const {
return val[0] == o.val[0] && val[1] == o.val[1] && val[2] == o.val[2] && val[3] == o.val[3];
}
bool operator!=(const SimpleVec4& o) const {
return val[0] != o.val[0] || val[1] != o.val[1] || val[2] != o.val[2] || val[3] != o.val[3];
}
bool operator==(const float* o) const {
return val[0] == o[0] && val[1] == o[1] && val[2] == o[2] && val[3] == o[3];
}
bool operator!=(const float* o) const {
return val[0] != o[0] || val[1] != o[1] || val[2] != o[2] || val[3] != o[3];
}
const float* GetPtr() const { return val; }
};
// --------------------------------------------------------------------------
struct GfxVertexLight
{
Vector4f position; // directional: direction (w=0); others: position (w=1)
Vector4f spotDirection; // w = 0
Vector4f color; // diffuse&specular color
float range; // range
float quadAtten; // quadratic attenuation (constant = 1, linear = 0)
float spotAngle; // in degrees of full cone; -1 if not spot light
LightType type;
GfxVertexLight()
: position(Vector3f::zero,1.0f)
, spotDirection (Vector3f::zAxis,1.0f)
, color (Vector3f::zero,1.0f)
, range (0.0f)
, quadAtten (0.0f)
, spotAngle (0.0f)
, type (kLightDirectional)
{}
};
struct GfxMaterialParams
{
Vector4f ambient;
Vector4f diffuse;
Vector4f specular;
Vector4f emissive;
float shininess;
void Invalidate()
{
ambient.Set( -1, -1, -1, -1 );
diffuse.Set( -1, -1, -1, -1 );
specular.Set( -1, -1, -1, -1 );
emissive.Set( -1, -1, -1, -1 );
shininess = -1.0f;
}
};
struct GfxFogParams
{
FogMode mode;
Vector4f color;
float start;
float end;
float density;
void Invalidate()
{
mode = kFogUnknown;
color.Set( -1, -1, -1, -1 );
start = -1.0f;
end = -1.0f;
density = -1.0f;
}
};
|