PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
lighting.h
1/* Copyright (C) 2000,2001,2002 Sony Computer Entertainment America
2
3 This file is subject to the terms and conditions of the GNU Lesser
4 General Public License Version 2.1. See the file "COPYING" in the
5 main directory of this archive for more details. */
6
7#ifndef ps2gl_lighting_h
8#define ps2gl_lighting_h
9
10#include "GL/gl.h"
11
12#include "ps2s/cpu_vector.h"
13
14#include "ps2gl/debug.h"
15#include "ps2gl/dlgmanager.h"
16#include "ps2gl/glcontext.h"
17#include "ps2gl/immgmanager.h"
18
19class CGLContext;
20
21/********************************************
22 * CLight
23 */
24
25class CLight {
26protected:
27 CGLContext& GLContext;
28 int LightNum;
29
30public:
31 CLight(CGLContext& context, int lightNum)
32 : GLContext(context)
33 , LightNum(lightNum)
34 {
35 }
36
37 virtual void SetAmbient(cpu_vec_xyzw ambient) = 0;
38 virtual void SetDiffuse(cpu_vec_xyzw diffuse) = 0;
39 virtual void SetSpecular(cpu_vec_xyzw specular) = 0;
40 virtual void SetPosition(cpu_vec_xyzw position) = 0;
41 virtual void SetDirection(cpu_vec_xyzw direction) = 0;
42 virtual void SetSpotDirection(cpu_vec_xyzw dir) = 0;
43 virtual void SetSpotCutoff(float cutoff) = 0;
44 virtual void SetSpotExponent(float exp) = 0;
45 virtual void SetConstantAtten(float atten) = 0;
46 virtual void SetLinearAtten(float atten) = 0;
47 virtual void SetQuadAtten(float atten) = 0;
48
49 virtual void SetEnabled(bool yesNo) = 0;
50};
51
52/********************************************
53 * CImmLight
54 */
55
56class CImmLight : public CLight {
57 cpu_vec_xyzw Ambient, Diffuse, Specular;
58 cpu_vec_xyzw Position, SpotDirection;
59 float SpotCutoff, SpotExponent;
60 float ConstantAtten, LinearAtten, QuadAtten;
61 bool bIsEnabled;
62
63 // tLightType is defined in rendervsm.h
64 tLightType Type;
65
66 static int NumLights[3];
67
68 inline void TellRendererLightPropChanged()
69 {
70 GLContext.LightPropChanged();
71 }
72
73 void CheckTypeChange(tLightType oldType);
74
75public:
76 CImmLight(CGLContext& context, int lightNum);
77
78 void SetAmbient(cpu_vec_xyzw ambient)
79 {
80 Ambient = ambient;
81 TellRendererLightPropChanged();
82 }
83 void SetDiffuse(cpu_vec_xyzw diffuse)
84 {
85 Diffuse = diffuse;
86 TellRendererLightPropChanged();
87 }
88 void SetSpecular(cpu_vec_xyzw specular);
89 void SetPosition(cpu_vec_xyzw position);
90 void SetDirection(cpu_vec_xyzw direction);
91
92 void SetSpotDirection(cpu_vec_xyzw dir)
93 {
94 SpotDirection = dir;
95 TellRendererLightPropChanged();
96 }
97 void SetSpotCutoff(float cutoff)
98 {
99 tLightType oldType = Type;
100 if (Type != kDirectional)
101 Type = (cutoff == 180.0f) ? kPoint : kSpot;
102 CheckTypeChange(oldType);
103 SpotCutoff = cutoff;
104 TellRendererLightPropChanged();
105 }
106 void SetSpotExponent(float exp)
107 {
108 SpotExponent = exp;
109 TellRendererLightPropChanged();
110 }
111
112 void SetConstantAtten(float atten)
113 {
114 ConstantAtten = atten;
115 TellRendererLightPropChanged();
116 }
117 void SetLinearAtten(float atten)
118 {
119 LinearAtten = atten;
120 TellRendererLightPropChanged();
121 }
122 void SetQuadAtten(float atten)
123 {
124 QuadAtten = atten;
125 TellRendererLightPropChanged();
126 }
127
128 void SetEnabled(bool enabled);
129
130 inline cpu_vec_xyzw GetAmbient() const { return Ambient; }
131 inline cpu_vec_xyzw GetDiffuse() const { return Diffuse; }
132 inline cpu_vec_xyzw GetSpecular() const { return Specular; }
133 inline cpu_vec_xyzw GetPosition() const { return Position; }
134
135 inline cpu_vec_xyzw GetSpotDir() const { return SpotDirection; }
136 inline float GetSpotCutoff() const { return SpotCutoff; }
137 inline float GetSpotExponent() const { return SpotExponent; }
138
139 inline float GetConstantAtten() const { return ConstantAtten; }
140 inline float GetLinearAtten() const { return LinearAtten; }
141 inline float GetQuadAtten() const { return QuadAtten; }
142
143 inline bool IsEnabled() const { return bIsEnabled; }
144 inline bool IsDirectional() const { return (Type == kDirectional); }
145 inline bool IsPoint() const { return (Type == kPoint); }
146 inline bool IsSpot() const { return (Type == kSpot); }
147};
148
149/********************************************
150 * CDListLight
151 */
152
153class CDListLight : public CLight {
154 inline void TellRendererLightPropChanged()
155 {
156 GLContext.LightPropChanged();
157 }
158 inline void TellRendererLightsEnabledChanged()
159 {
160 GLContext.NumLightsChanged();
161 }
162
163public:
164 CDListLight(CGLContext& context, int lightNum)
165 : CLight(context, lightNum)
166 {
167 }
168
169 void SetAmbient(cpu_vec_xyzw ambient);
170 void SetDiffuse(cpu_vec_xyzw diffuse);
171 void SetSpecular(cpu_vec_xyzw specular);
172 void SetPosition(cpu_vec_xyzw position);
173 void SetDirection(cpu_vec_xyzw direction);
174
175 void SetSpotDirection(cpu_vec_xyzw dir);
176 void SetSpotCutoff(float cutoff);
177 void SetSpotExponent(float exp);
178
179 void SetConstantAtten(float atten);
180 void SetLinearAtten(float atten);
181 void SetQuadAtten(float atten);
182
183 void SetEnabled(bool yesNo);
184};
185
186/********************************************
187 * CLighting
188 */
189
191protected:
192 CGLContext& GLContext;
193 static const int NumLights = 8;
194
195public:
196 CLighting(CGLContext& context)
197 : GLContext(context)
198 {
199 }
200 virtual ~CLighting()
201 {
202 }
203
204 virtual CLight& GetLight(int num) = 0;
205
206 virtual void SetLightingEnabled(bool enabled) = 0;
207 virtual void SetGlobalAmbient(cpu_vec_xyzw newAmb) = 0;
208};
209
210/********************************************
211 * CImmLighting
212 */
213
214class CImmLighting : public CLighting {
215 cpu_vec_xyzw CurrentColor;
216 cpu_vec_xyzw GlobalAmbient;
217 CImmLight Light0, Light1, Light2, Light3, Light4, Light5, Light6, Light7;
218 CImmLight* Lights[NumLights];
219 bool IsEnabled;
220 int NumLightsWithNonzeroSpecular;
221
222 inline void TellRendererLightPropChanged()
223 {
224 GLContext.LightPropChanged();
225 }
226
227public:
228 CImmLighting(CGLContext& context);
229
230 CImmLight& GetImmLight(int num)
231 {
232 mAssert(num < NumLights);
233 return *Lights[num];
234 }
235 CLight& GetLight(int num) { return GetImmLight(num); }
236
237 void SetLightingEnabled(bool enabled)
238 {
239 GLContext.LightingEnabledChanged();
240 GLContext.GetImmGeomManager().GetRendererManager().LightingEnabledChanged(enabled);
241 IsEnabled = enabled;
242 }
243 bool GetLightingEnabled() const { return IsEnabled; }
244
245 void SetGlobalAmbient(cpu_vec_xyzw newAmb)
246 {
247 GlobalAmbient = newAmb;
248 TellRendererLightPropChanged();
249 }
250 cpu_vec_xyzw GetGlobalAmbient() { return GlobalAmbient; }
251
252 void SpecularChanged();
253 void MaterialHasSpecular();
254};
255
256/********************************************
257 * CDListLighting
258 */
259
260class CDListLighting : public CLighting {
261 CDListLight Light0, Light1, Light2, Light3, Light4, Light5, Light6, Light7;
262 CDListLight* Lights[NumLights];
263
264 inline void TellRendererLightPropChanged()
265 {
266 GLContext.LightPropChanged();
267 }
268
269public:
270 CDListLighting(CGLContext& context);
271
272 CDListLight& GetDListLight(int num)
273 {
274 mAssert(num < NumLights);
275 return *Lights[num];
276 }
277 CLight& GetLight(int num) { return GetDListLight(num); }
278
279 void SetLightingEnabled(bool enabled);
280 void SetGlobalAmbient(cpu_vec_xyzw newAmb);
281};
282
283#endif // ps2gl_lighting_h