WINTERMUTE: Introduce struct to pass fog parameters

This commit is contained in:
Gunnar Birke 2020-08-02 23:39:17 +02:00 committed by Paweł Kołodziejski
parent 9749a6aeae
commit 532573ecd3
9 changed files with 51 additions and 48 deletions

View File

@ -1738,16 +1738,12 @@ Wintermute::TShadowType Wintermute::AdGame::getMaxShadowType(Wintermute::BaseObj
return MIN(ret, _scene->_maxShadowType);
}
bool Wintermute::AdGame::getFogParams(bool *fogEnabled, uint32 *fogColor, float *fogStart, float *fogEnd) {
bool Wintermute::AdGame::getFogParams(FogParameters &fogParameters) {
if (_scene) {
*fogEnabled = _scene->_fogEnabled;
*fogColor = _scene->_fogColor;
*fogStart = _scene->_fogStart;
*fogEnd = _scene->_fogEnd;
fogParameters = _scene->_fogParameters;
return true;
} else {
return BaseGame::getFogParams(fogEnabled, fogColor, fogStart, fogEnd);
return BaseGame::getFogParams(fogParameters);
}
}
#endif

View File

@ -98,7 +98,7 @@ public:
TShadowType getMaxShadowType(BaseObject *object) override;
bool getFogParams(bool *fogEnabled, uint32 *fogColor, float *fogStart, float *fogEnd) override;
bool getFogParams(FogParameters &fogParameters) override;
#endif
bool getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) const override;

View File

@ -106,10 +106,10 @@ void AdScene::setDefaults() {
_maxShadowType = SHADOW_FLAT;
_ambientLightColor = 0x00000000;
_fogEnabled = false;
_fogColor = 0x00FFFFFF;
_fogStart = 0.0f;
_fogEnd = 0.0f;
_fogParameters._enabled = false;
_fogParameters._color = 0x00FFFFFF;
_fogParameters._start = 0.0f;
_fogParameters._end = 0.0f;
#endif
_pfPointsNum = 0;
@ -2114,10 +2114,10 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack,
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "EnableFog") == 0) {
stack->correctParams(3);
_fogEnabled = true;
_fogColor = stack->pop()->getInt();
_fogStart = stack->pop()->getFloat();
_fogEnd = stack->pop()->getFloat();
_fogParameters._enabled = true;
_fogParameters._color = stack->pop()->getInt();
_fogParameters._start = stack->pop()->getFloat();
_fogParameters._end = stack->pop()->getFloat();
stack->pushNULL();
return STATUS_OK;
@ -2128,7 +2128,7 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack,
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "DisableFog") == 0) {
stack->correctParams(0);
_fogEnabled = false;
_fogParameters._enabled = false;
stack->pushNULL();
return STATUS_OK;
@ -2965,13 +2965,13 @@ bool AdScene::persist(BasePersistenceManager *persistMgr) {
persistMgr->transferFloat(TMEMBER(_farPlane));
persistMgr->transferSint32(TMEMBER_INT(_maxShadowType));
persistMgr->transferUint32(TMEMBER(_ambientLightColor));
persistMgr->transferBool(TMEMBER(_fogEnabled));
persistMgr->transferUint32(TMEMBER(_fogColor));
persistMgr->transferFloat(TMEMBER(_fogStart));
persistMgr->transferFloat(TMEMBER(_fogEnd));
persistMgr->transferBool(TMEMBER(_fogParameters._enabled));
persistMgr->transferUint32(TMEMBER(_fogParameters._color));
persistMgr->transferFloat(TMEMBER(_fogParameters._start));
persistMgr->transferFloat(TMEMBER(_fogParameters._end));
} else {
_sceneGeometry = nullptr;
_fogEnabled = false;
_fogParameters._enabled = false;
}
#endif

View File

@ -68,10 +68,7 @@ public:
float _nearPlane;
float _farPlane;
bool _fogEnabled;
uint32 _fogColor;
float _fogStart;
float _fogEnd;
FogParameters _fogParameters;
#endif
bool afterLoad();

View File

@ -621,8 +621,8 @@ uint32 BaseGame::getAmbientLightColor() {
return 0x00000000;
}
bool BaseGame::getFogParams(bool *fogEnabled, uint32 *fogColor, float *fogStart, float *fogEnd) {
*fogEnabled = false;
bool BaseGame::getFogParams(FogParameters &fogParameters) {
fogParameters._enabled = false;
return true;
}
#endif

View File

@ -70,6 +70,7 @@ class SaveThumbHelper;
#ifdef ENABLE_WME3D
class BaseRenderer3D;
class FogParameters;
#endif
class BaseGame: public BaseObject {
@ -170,7 +171,7 @@ public:
virtual uint32 getAmbientLightColor();
virtual bool getFogParams(bool *fogEnabled, uint32 *fogColor, float *fogStart, float *fogEnd);
virtual bool getFogParams(FogParameters &fogParameters);
#endif
BaseSoundMgr *_soundMgr;
#if EXTENDED_DEBUGGER_ENABLED

View File

@ -374,19 +374,16 @@ bool BaseRenderOpenGL3D::setup3D(Camera3D *camera, bool force) {
glGetFloatv(GL_MODELVIEW_MATRIX, _lastViewMatrix.getData());
}
bool fogEnabled;
uint32 fogColor;
float fogStart;
float fogEnd;
FogParameters fogParameters;
_gameRef->getFogParams(fogParameters);
_gameRef->getFogParams(&fogEnabled, &fogColor, &fogStart, &fogEnd);
if (fogEnabled) {
if (fogParameters._enabled) {
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_START, fogStart);
glFogf(GL_FOG_END, fogEnd);
glFogf(GL_FOG_START, fogParameters._start);
glFogf(GL_FOG_END, fogParameters._end);
uint32 fogColor = fogParameters._color;
GLfloat color[4] = { RGBCOLGetR(fogColor) / 255.0f, RGBCOLGetG(fogColor) / 255.0f, RGBCOLGetB(fogColor) / 255.0f, RGBCOLGetA(fogColor) / 255.0f };
glFogfv(GL_FOG_COLOR, color);
} else {

View File

@ -419,20 +419,17 @@ bool BaseRenderOpenGL3DShader::setup3D(Camera3D *camera, bool force) {
_lastViewMatrix = viewMatrix;
}
bool fogEnabled;
uint32 fogColor;
float fogStart;
float fogEnd;
FogParameters fogParameters;
_gameRef->getFogParams(&fogEnabled, &fogColor, &fogStart, &fogEnd);
_gameRef->getFogParams(fogParameters);
if (fogEnabled) {
if (fogParameters._enabled) {
// TODO: Implement fog
GLfloat color[4];
color[0] = RGBCOLGetR(fogColor) / 255.0f;
color[1] = RGBCOLGetG(fogColor) / 255.0f;
color[2] = RGBCOLGetB(fogColor) / 255.0f;
color[3] = RGBCOLGetA(fogColor) / 255.0f;
color[0] = RGBCOLGetR(fogParameters._color) / 255.0f;
color[1] = RGBCOLGetG(fogParameters._color) / 255.0f;
color[2] = RGBCOLGetB(fogParameters._color) / 255.0f;
color[3] = RGBCOLGetA(fogParameters._color) / 255.0f;
} else {
// TODO: Disable fog in shader
}

View File

@ -232,6 +232,21 @@ enum TShadowType {
SHADOW_STENCIL = 3
};
#ifdef ENABLE_WME3D
struct FogParameters {
FogParameters() : _start(0.0f), _end(0.0f), _color(0x00000000), _enabled(false) {
}
float _start;
float _end;
uint32 _color;
bool _enabled;
};
#endif
} // End of namespace Wintermute
#endif