PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
material.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_material_h
8#define ps2gl_material_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
21class CMaterial {
22protected:
23 CGLContext& GLContext;
24
25public:
26 CMaterial(CGLContext& context)
27 : GLContext(context)
28 {
29 }
30
31 virtual void SetAmbient(cpu_vec_xyzw ambient) = 0;
32 virtual void SetDiffuse(cpu_vec_xyzw diffuse) = 0;
33 virtual void SetSpecular(cpu_vec_xyzw specular) = 0;
34 virtual void SetEmission(cpu_vec_xyzw emission) = 0;
35 virtual void SetShininess(float shine) = 0;
36};
37
38class CImmMaterial : public CMaterial {
39 cpu_vec_xyzw Ambient, Diffuse, Specular, Emission;
40 float Shininess;
41
42 inline void TellRendererMaterialChanged()
43 {
44 GLContext.CurMaterialChanged();
45 }
46
47public:
48 CImmMaterial(CGLContext& context);
49
50 void SetAmbient(cpu_vec_xyzw ambient)
51 {
52 Ambient = ambient;
53 TellRendererMaterialChanged();
54 }
55 void SetDiffuse(cpu_vec_xyzw diffuse)
56 {
57 Diffuse = diffuse;
58 TellRendererMaterialChanged();
59 }
60 void SetSpecular(cpu_vec_xyzw specular);
61 void SetEmission(cpu_vec_xyzw emission)
62 {
63 Emission = emission;
64 TellRendererMaterialChanged();
65 }
66 void SetShininess(float shine)
67 {
68 Shininess = shine;
69 TellRendererMaterialChanged();
70 }
71
72 inline cpu_vec_xyzw GetAmbient() const { return Ambient; }
73 inline cpu_vec_xyzw GetDiffuse() const { return Diffuse; }
74 inline cpu_vec_xyzw GetSpecular() const { return Specular; }
75 inline cpu_vec_xyzw GetEmission() const { return Emission; }
76 inline float GetShininess() const { return Shininess; }
77
78 void LightsHaveSpecular();
79};
80
81class CDListMaterial : public CMaterial {
82 inline void TellRendererMaterialChanged()
83 {
84 GLContext.CurMaterialChanged();
85 }
86
87public:
89 : CMaterial(context)
90 {
91 }
92
93 void SetAmbient(cpu_vec_xyzw ambient);
94 void SetDiffuse(cpu_vec_xyzw diffuse);
95 void SetSpecular(cpu_vec_xyzw specular);
96 void SetEmission(cpu_vec_xyzw emission);
97 void SetShininess(float shine);
98};
99
101 CGLContext& GLContext;
102
103 CImmMaterial ImmMaterial;
104 CDListMaterial DListMaterial;
105 CMaterial* CurMaterial;
106
107 cpu_vec_xyzw CurColor;
108 GLenum ColorMaterialMode;
109 bool UseColorMaterial;
110 bool InDListDef;
111
112public:
114 : GLContext(context)
115 , ImmMaterial(context)
116 , DListMaterial(context)
117 , CurMaterial(&ImmMaterial)
118 , CurColor(1, 1, 1, 1)
119 , ColorMaterialMode(GL_AMBIENT_AND_DIFFUSE)
120 , UseColorMaterial(false)
121 , InDListDef(false)
122 {
123 ImmMaterial.SetDiffuse(cpu_vec_xyzw(0.8f, 0.8f, 0.8f, 1.0f));
124 }
125
126 CMaterial& GetCurMaterial() { return *CurMaterial; }
127 CImmMaterial& GetImmMaterial() { return ImmMaterial; }
128 CDListMaterial& GetDListMaterial() { return DListMaterial; }
129 cpu_vec_xyzw GetCurColor() const { return CurColor; }
130 GLenum GetColorMaterialMode() const { return ColorMaterialMode; }
131 bool GetColorMaterialEnabled() const { return UseColorMaterial; }
132
133 void Color(cpu_vec_xyzw color);
134 void SetUseColorMaterial(bool yesNo);
135 void SetColorMaterialMode(GLenum mode);
136
137 void BeginDListDef()
138 {
139 CurMaterial = &DListMaterial;
140 InDListDef = true;
141 }
142 void EndDListDef()
143 {
144 CurMaterial = &ImmMaterial;
145 InDListDef = false;
146 }
147};
148
149#endif // ps2gl_material_h