Skip to content

Commit

Permalink
UPBGE: Encapsulate light update in KX_LightObject.
Browse files Browse the repository at this point in the history
  • Loading branch information
panzergame committed Dec 17, 2017
1 parent 149f33e commit e8a9322
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion source/gameengine/Ketsji/KX_KetsjiEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ void KX_KetsjiEngine::RenderShadowBuffers(KX_Scene *scene)

for (KX_LightObject *light : lightlist) {
RAS_ILightObject *raslight = light->GetLightData();

This comment has been minimized.

Copy link
@lordloki

lordloki Dec 17, 2017

Member

Should be remove this line too? As raslight->Update is replaced by light->Update, it doesn't have any sense now....

raslight->Update();
light->Update();
}

if (m_rasterizer->GetDrawingMode() == RAS_Rasterizer::RAS_TEXTURED) {
Expand Down
5 changes: 5 additions & 0 deletions source/gameengine/Ketsji/KX_Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ void KX_LightObject::SetShowShadowFrustum(bool show)
m_showShadowFrustum = show;
}

void KX_LightObject::Update()
{
m_lightobj->Update(NodeGetWorldTransform(), !m_bVisible);
}

void KX_LightObject::UpdateScene(KX_Scene *kxscene)
{
m_lightobj->m_scene = (void *)kxscene;
Expand Down
3 changes: 3 additions & 0 deletions source/gameengine/Ketsji/KX_Light.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class KX_LightObject : public KX_GameObject
bool GetShowShadowFrustum() const;
void SetShowShadowFrustum(bool show);

// Update rasterizer light settings.
void Update();

void UpdateScene(KX_Scene *kxscene);
virtual void SetLayer(int layer);

Expand Down
4 changes: 2 additions & 2 deletions source/gameengine/Rasterizer/RAS_ILightObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class RAS_ILightObject
bool m_staticShadow;
bool m_requestShadowUpdate;

virtual ~RAS_ILightObject() {}
virtual ~RAS_ILightObject() = default;
virtual RAS_ILightObject* Clone() = 0;

virtual bool HasShadowBuffer() = 0;
Expand All @@ -94,7 +94,7 @@ class RAS_ILightObject
virtual void BindShadowBuffer(RAS_ICanvas *canvas, KX_Camera *cam, mt::mat3x4& camtrans) = 0;
virtual void UnbindShadowBuffer() = 0;
virtual Image *GetTextureImage(short texslot) = 0;
virtual void Update() = 0;
virtual void Update(const mt::mat3x4& trans, bool hide) = 0;
};

#endif /* __RAS_LIGHTOBJECT_H__ */
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,14 @@ Image *RAS_OpenGLLight::GetTextureImage(short texslot)
return nullptr;
}

void RAS_OpenGLLight::Update()
void RAS_OpenGLLight::Update(const mt::mat3x4& trans, bool hide)
{
GPULamp *lamp;
KX_LightObject *kxlight = (KX_LightObject *)m_light;
GPULamp *lamp = GetGPULamp();

if ((lamp = GetGPULamp()) != nullptr && kxlight->GetSGNode()) {
if (lamp) {
float obmat[4][4];
const mt::mat3x4 trans = kxlight->NodeGetWorldTransform();
trans.PackFromAffineTransform(obmat);

int hide = kxlight->GetVisible() ? 0 : 1;
GPU_lamp_update(lamp, m_layer, hide, obmat);
GPU_lamp_update_colors(lamp, m_color[0], m_color[1],
m_color[2], m_energy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ class RAS_OpenGLLight : public RAS_ILightObject
void BindShadowBuffer(RAS_ICanvas *canvas, KX_Camera *cam, mt::mat3x4& camtrans);
void UnbindShadowBuffer();
Image *GetTextureImage(short texslot);
void Update();
void Update(const mt::mat3x4& trans, bool hide);
void SetShadowUpdateState(short state);
};

0 comments on commit e8a9322

Please sign in to comment.