diff options
Diffstat (limited to 'src/graphics/engine/engine.cpp')
-rw-r--r-- | src/graphics/engine/engine.cpp | 87 |
1 files changed, 56 insertions, 31 deletions
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index c170922..e34034d 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -186,6 +186,8 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_updateGeometry = false; + m_interfaceMode = false; + m_mice[ENG_MOUSE_NORM] = EngineMouse( 0, 1, 32, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 1.0f, 1.0f)); m_mice[ENG_MOUSE_WAIT] = EngineMouse( 2, 3, 33, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 8.0f, 12.0f)); m_mice[ENG_MOUSE_HAND] = EngineMouse( 4, 5, 34, ENG_RSTATE_TTEXTURE_WHITE, ENG_RSTATE_TTEXTURE_BLACK, Math::Point( 7.0f, 2.0f)); @@ -215,6 +217,11 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app) m_defaultTexParams.minFilter = TEX_MIN_FILTER_LINEAR_MIPMAP_LINEAR; m_defaultTexParams.magFilter = TEX_MAG_FILTER_LINEAR; + m_terrainTexParams.format = TEX_IMG_AUTO; + m_terrainTexParams.mipmap = false; + m_terrainTexParams.minFilter = TEX_MIN_FILTER_LINEAR; + m_terrainTexParams.magFilter = TEX_MAG_FILTER_LINEAR; + m_objectTree.reserve(LEVEL1_PREALLOCATE_COUNT); m_objects.reserve(OBJECT_PREALLOCATE_COUNT); m_shadows.reserve(SHADOW_PREALLOCATE_COUNT); @@ -1947,13 +1954,8 @@ void CEngine::SetState(int state, const Color& color) m_device->SetBlendFunc(BLEND_SRC_ALPHA, BLEND_INV_SRC_ALPHA); m_device->SetRenderState(RENDER_STATE_TEXTURING, true); - - TextureStageParams params; - params.colorOperation = TEX_MIX_OPER_DEFAULT; // default modulate operation - params.alphaOperation = TEX_MIX_OPER_DEFAULT; // default modulate operation - m_device->SetTextureEnabled(0, true); - m_device->SetTextureStageParams(0, params); + m_device->SetTextureStageParams(0, TextureStageParams()); // default operation } else if (state & ENG_RSTATE_ALPHA) // image with alpha channel? { @@ -2014,7 +2016,7 @@ void CEngine::SetState(int state, const Color& color) params.colorArg1 = TEX_MIX_ARG_TEXTURE; params.colorArg2 = TEX_MIX_ARG_COMPUTED_COLOR; params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: ??? - m_device->SetTextureEnabled(0, true); + m_device->SetTextureEnabled(1, true); m_device->SetTextureStageParams(1, params); } else if ((state & ENG_RSTATE_DUAL_WHITE) && second) @@ -2024,7 +2026,7 @@ void CEngine::SetState(int state, const Color& color) params.colorArg1 = TEX_MIX_ARG_TEXTURE; params.colorArg2 = TEX_MIX_ARG_COMPUTED_COLOR; params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: ??? - m_device->SetTextureEnabled(0, true); + m_device->SetTextureEnabled(1, true); m_device->SetTextureStageParams(1, params); } else @@ -2034,25 +2036,13 @@ void CEngine::SetState(int state, const Color& color) if (state & ENG_RSTATE_WRAP) { - // TODO: separate function for setting wrap mode? - - TextureStageParams p1 = m_device->GetTextureStageParams(0); - p1.wrapS = p1.wrapT = TEX_WRAP_REPEAT; - m_device->SetTextureStageParams(0, p1); - - TextureStageParams p2 = m_device->GetTextureStageParams(1); - p2.wrapS = p2.wrapT = TEX_WRAP_REPEAT; - m_device->SetTextureStageParams(1, p2); + m_device->SetTextureStageWrap(0, TEX_WRAP_REPEAT, TEX_WRAP_REPEAT); + m_device->SetTextureStageWrap(1, TEX_WRAP_REPEAT, TEX_WRAP_REPEAT); } else // if (state & ENG_RSTATE_CLAMP) or otherwise { - TextureStageParams p1 = m_device->GetTextureStageParams(0); - p1.wrapS = p1.wrapT = TEX_WRAP_CLAMP; - m_device->SetTextureStageParams(0, p1); - - TextureStageParams p2 = m_device->GetTextureStageParams(1); - p2.wrapS = p2.wrapT = TEX_WRAP_CLAMP; - m_device->SetTextureStageParams(1, p2); + m_device->SetTextureStageWrap(0, TEX_WRAP_CLAMP, TEX_WRAP_CLAMP); + m_device->SetTextureStageWrap(1, TEX_WRAP_CLAMP, TEX_WRAP_CLAMP); } if (state & ENG_RSTATE_2FACE) @@ -2069,6 +2059,13 @@ void CEngine::SetState(int state, const Color& color) m_device->SetGlobalAmbient(Color(1.0f, 1.0f, 1.0f, 1.0f)); else m_device->SetGlobalAmbient(m_ambientColor[m_rankView]); + + + // In interface mode, disable lighting + if (m_interfaceMode) + { + m_device->SetRenderState(RENDER_STATE_LIGHTING, false); + } } void CEngine::SetMaterial(const Material& mat) @@ -2177,16 +2174,35 @@ bool CEngine::LoadAllTextures() EngineObjLevel1& p1 = m_objectTree[l1]; if (! p1.used) continue; + bool terrain = false; + + for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) + { + EngineObjLevel2& p2 = p1.next[l2]; + if (! p2.used) continue; + + if (m_objects[p2.objRank].type == ENG_OBJTYPE_TERRAIN) + terrain = true; + } + if (! p1.tex1Name.empty()) { - p1.tex1 = LoadTexture(p1.tex1Name); + if (terrain) + p1.tex1 = LoadTexture(p1.tex1Name, m_terrainTexParams); + else + p1.tex1 = LoadTexture(p1.tex1Name); + if (! p1.tex1.Valid()) ok = false; } if (! p1.tex2Name.empty()) { - p1.tex2 = LoadTexture(p1.tex2Name); + if (terrain) + p1.tex2 = LoadTexture(p1.tex2Name, m_terrainTexParams); + else + p1.tex2 = LoadTexture(p1.tex2Name); + if (! p1.tex2.Valid()) ok = false; } @@ -2810,7 +2826,7 @@ void CEngine::Draw3DScene() if (m_shadowVisible) { - m_lightMan->UpdateLightsEnableState(ENG_OBJTYPE_TERRAIN); + m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); // Draw the terrain @@ -2910,7 +2926,7 @@ void CEngine::Draw3DScene() if (! IsVisible(objRank)) continue; - m_lightMan->UpdateLightsEnableState(m_objects[objRank].type); + m_lightMan->UpdateDeviceLights(m_objects[objRank].type); for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { @@ -2999,7 +3015,7 @@ void CEngine::Draw3DScene() if (! IsVisible(objRank)) continue; - m_lightMan->UpdateLightsEnableState(m_objects[objRank].type); + m_lightMan->UpdateDeviceLights(m_objects[objRank].type); for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { @@ -3041,7 +3057,7 @@ void CEngine::Draw3DScene() } } - m_lightMan->UpdateLightsEnableState(ENG_OBJTYPE_TERRAIN); + m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN); if (m_waterMode) m_water->DrawSurf(); // draws water surface @@ -3064,11 +3080,20 @@ void CEngine::DrawInterface() m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface); m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface); + // Force new state to disable lighting + m_interfaceMode = true; + m_lastState = -1; + SetState(Gfx::ENG_RSTATE_NORMAL); + // Draw the entire interface Ui::CInterface* interface = static_cast<Ui::CInterface*>( m_iMan->SearchInstance(CLASS_INTERFACE) ); if (interface != nullptr) interface->Draw(); + m_interfaceMode = false; + m_lastState = -1; + SetState(Gfx::ENG_RSTATE_NORMAL); + m_particle->DrawParticle(SH_INTERFACE); // draws the particles of the interface // 3D objects drawn in front of interface @@ -3117,7 +3142,7 @@ void CEngine::DrawInterface() if (! IsVisible(objRank)) continue; - m_lightMan->UpdateLightsEnableState(m_objects[objRank].type); + m_lightMan->UpdateDeviceLights(m_objects[objRank].type); for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++) { |