7#include "ps2gl/material.h"
8#include "ps2gl/dlist.h"
9#include "ps2gl/glcontext.h"
10#include "ps2gl/lighting.h"
18 , Ambient(0.2f, 0.2f, 0.2f, 1.0f)
19 , Diffuse(0.8f, 0.8f, 0.8f, 1.0f)
20 , Specular(0.0f, 0.0f, 0.0f, 1.0f)
21 , Emission(0.0f, 0.0f, 0.0f, 1.0f)
26void CImmMaterial::SetSpecular(cpu_vec_xyzw specular)
28 TellRendererMaterialChanged();
31 if (Specular != cpu_vec_4(0, 0, 0, 0))
32 GLContext.GetImmLighting().MaterialHasSpecular();
34 GLContext.SpecularEnabledChanged();
35 GLContext.GetImmGeomManager().GetRendererManager().SpecularEnabledChanged(
false);
39void CImmMaterial::LightsHaveSpecular()
41 if (Specular != cpu_vec_4(0, 0, 0, 0)) {
42 GLContext.SpecularEnabledChanged();
43 GLContext.GetImmGeomManager().GetRendererManager().SpecularEnabledChanged(
true);
63 glMaterialfv(GL_FRONT, Property,
reinterpret_cast<float*
>(&Value));
64 return CDListCmd::GetNextCmd(
this);
68void CDListMaterial::SetAmbient(cpu_vec_xyzw ambient)
70 CDList& dlist = pGLContext->GetDListManager().GetOpenDList();
72 TellRendererMaterialChanged();
75void CDListMaterial::SetDiffuse(cpu_vec_xyzw diffuse)
77 CDList& dlist = pGLContext->GetDListManager().GetOpenDList();
79 TellRendererMaterialChanged();
82void CDListMaterial::SetSpecular(cpu_vec_xyzw specular)
84 CDList& dlist = pGLContext->GetDListManager().GetOpenDList();
86 TellRendererMaterialChanged();
87 GLContext.SpecularEnabledChanged();
90void CDListMaterial::SetEmission(cpu_vec_xyzw emission)
92 CDList& dlist = pGLContext->GetDListManager().GetOpenDList();
94 TellRendererMaterialChanged();
97void CDListMaterial::SetShininess(
float shine)
99 CDList& dlist = pGLContext->GetDListManager().GetOpenDList();
101 TellRendererMaterialChanged();
108void CMaterialManager::Color(cpu_vec_xyzw color)
112 if (UseColorMaterial) {
113 switch (ColorMaterialMode) {
115 CurMaterial->SetEmission(color);
118 CurMaterial->SetAmbient(color);
121 CurMaterial->SetDiffuse(color);
124 CurMaterial->SetSpecular(color);
126 case GL_AMBIENT_AND_DIFFUSE:
127 CurMaterial->SetAmbient(color);
128 CurMaterial->SetDiffuse(color);
132 GLContext.CurMaterialChanged();
145 pGLContext->GetMaterialManager().SetUseColorMaterial(UseCM);
146 return CDListCmd::GetNextCmd(
this);
150void CMaterialManager::SetUseColorMaterial(
bool yesNo)
153 UseColorMaterial = yesNo;
156 GLContext.CurMaterialChanged();
158 CDList& dlist = GLContext.GetDListManager().GetOpenDList();
160 GLContext.CurMaterialChanged();
174 pGLContext->GetMaterialManager().SetColorMaterialMode(Mode);
175 return CDListCmd::GetNextCmd(
this);
179void CMaterialManager::SetColorMaterialMode(GLenum mode)
182 ColorMaterialMode = mode;
184 GLContext.CurMaterialChanged();
186 CDList& dlist = GLContext.GetDListManager().GetOpenDList();
188 GLContext.CurMaterialChanged();
196void glMaterialfv(GLenum face, GLenum pname,
const GLfloat* params)
198 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
200 CMaterial& material = pGLContext->GetMaterialManager().GetCurMaterial();
204 mNotImplemented(
"GL_BACK - only front material is available");
206 case GL_FRONT_AND_BACK:
207 mNotImplemented(
"GL_FRONT_AND_BACK - only front material is available");
211 material.SetAmbient(cpu_vec_xyzw(params[0], params[1], params[2], params[3]));
214 material.SetDiffuse(cpu_vec_xyzw(params[0], params[1], params[2], params[3]));
217 material.SetSpecular(cpu_vec_xyzw(params[0], params[1], params[2], params[3]));
220 material.SetEmission(cpu_vec_xyzw(params[0], params[1], params[2], params[3]));
223 material.SetShininess(*params);
225 case GL_AMBIENT_AND_DIFFUSE:
226 material.SetAmbient(cpu_vec_xyzw(params[0], params[1], params[2], params[3]));
227 material.SetDiffuse(cpu_vec_xyzw(params[0], params[1], params[2], params[3]));
230 mError(
"shouldn't get here");
234 mError(
"shouldn't get here");
238void glMaterialf(GLenum face, GLenum pname, GLfloat param)
240 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
242 CMaterial& material = pGLContext->GetMaterialManager().GetCurMaterial();
246 mNotImplemented(
"GL_BACK - only front material is available");
248 case GL_FRONT_AND_BACK:
249 mNotImplemented(
"GL_FRONT_AND_BACK - only front material is available");
251 if (pname == GL_SHININESS)
252 material.SetShininess(param);
254 mError(
"shoudn't get here");
258 mError(
"shouldn't get here");
262void glColorMaterial(GLenum face, GLenum mode)
264 GL_FUNC_DEBUG(
"%s\n", __FUNCTION__);
266 pGLContext->GetMaterialManager().SetColorMaterialMode(mode);