Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/PatchRData.cpp
Show All 21 Lines | |||||
#include "graphics/GameView.h" | #include "graphics/GameView.h" | ||||
#include "graphics/LightEnv.h" | #include "graphics/LightEnv.h" | ||||
#include "graphics/LOSTexture.h" | #include "graphics/LOSTexture.h" | ||||
#include "graphics/Patch.h" | #include "graphics/Patch.h" | ||||
#include "graphics/ShaderManager.h" | #include "graphics/ShaderManager.h" | ||||
#include "graphics/Terrain.h" | #include "graphics/Terrain.h" | ||||
#include "graphics/TerrainTextureEntry.h" | #include "graphics/TerrainTextureEntry.h" | ||||
#include "graphics/TextRenderer.h" | #include "graphics/TextRenderer.h" | ||||
#include "graphics/WaterManager.h" | |||||
#include "lib/allocators/DynamicArena.h" | #include "lib/allocators/DynamicArena.h" | ||||
#include "lib/allocators/STLAllocators.h" | #include "lib/allocators/STLAllocators.h" | ||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/GameSetup/Config.h" | #include "ps/GameSetup/Config.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "ps/Pyrogenesis.h" | #include "ps/Pyrogenesis.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "renderer/AlphaMapCalculator.h" | #include "renderer/AlphaMapCalculator.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/TerrainRenderer.h" | #include "renderer/TerrainRenderer.h" | ||||
#include "renderer/WaterManager.h" | |||||
#include "simulation2/components/ICmpWaterManager.h" | #include "simulation2/components/ICmpWaterManager.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <numeric> | #include <numeric> | ||||
#include <set> | #include <set> | ||||
const ssize_t BlendOffsets[9][2] = { | const ssize_t BlendOffsets[9][2] = { | ||||
▲ Show 20 Lines • Show All 1,188 Lines • ▼ Show 20 Lines | void CPatchRData::BuildWater() | ||||
memset(water_index_map, 0xFF, sizeof(water_index_map)); | memset(water_index_map, 0xFF, sizeof(water_index_map)); | ||||
// Build data for shore | // Build data for shore | ||||
std::vector<SWaterVertex> water_vertex_data_shore; | std::vector<SWaterVertex> water_vertex_data_shore; | ||||
std::vector<GLushort> water_indices_shore; | std::vector<GLushort> water_indices_shore; | ||||
u16 water_shore_index_map[PATCH_SIZE+1][PATCH_SIZE+1]; | u16 water_shore_index_map[PATCH_SIZE+1][PATCH_SIZE+1]; | ||||
memset(water_shore_index_map, 0xFF, sizeof(water_shore_index_map)); | memset(water_shore_index_map, 0xFF, sizeof(water_shore_index_map)); | ||||
WaterManager* WaterMgr = g_Renderer.GetWaterManager(); | const WaterManager& waterMgr = g_Game->GetView()->GetWaterManager(); | ||||
CPatch* patch = m_Patch; | CPatch* patch = m_Patch; | ||||
CTerrain* terrain = patch->m_Parent; | CTerrain* terrain = patch->m_Parent; | ||||
ssize_t mapSize = terrain->GetVerticesPerSide(); | ssize_t mapSize = terrain->GetVerticesPerSide(); | ||||
// Top-left coordinates of our patch. | // Top-left coordinates of our patch. | ||||
ssize_t px = m_Patch->m_X * PATCH_SIZE; | ssize_t px = m_Patch->m_X * PATCH_SIZE; | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | for (ssize_t x = 0; x < PATCH_SIZE; x += water_cell_size) | ||||
SWaterVertex vertex; | SWaterVertex vertex; | ||||
terrain->CalcPosition(xx,zz, vertex.m_Position); | terrain->CalcPosition(xx,zz, vertex.m_Position); | ||||
float depth = waterHeight - vertex.m_Position.Y; | float depth = waterHeight - vertex.m_Position.Y; | ||||
vertex.m_Position.Y = waterHeight; | vertex.m_Position.Y = waterHeight; | ||||
m_WaterBounds += vertex.m_Position; | m_WaterBounds += vertex.m_Position; | ||||
vertex.m_WaterData = CVector2D(WaterMgr->m_WindStrength[xx + zz*mapSize], depth); | vertex.m_WaterData = CVector2D(waterMgr.GetWindStrength(xx, zz), depth); | ||||
water_index_map[z+moves[i][1]][x+moves[i][0]] = static_cast<u16>(water_vertex_data.size()); | water_index_map[z+moves[i][1]][x+moves[i][0]] = static_cast<u16>(water_vertex_data.size()); | ||||
water_vertex_data.push_back(vertex); | water_vertex_data.push_back(vertex); | ||||
} | } | ||||
water_indices.push_back(water_index_map[z + moves[2][1]][x + moves[2][0]]); | water_indices.push_back(water_index_map[z + moves[2][1]][x + moves[2][0]]); | ||||
water_indices.push_back(water_index_map[z + moves[0][1]][x + moves[0][0]]); | water_indices.push_back(water_index_map[z + moves[0][1]][x + moves[0][0]]); | ||||
water_indices.push_back(water_index_map[z + moves[1][1]][x + moves[1][0]]); | water_indices.push_back(water_index_map[z + moves[1][1]][x + moves[1][0]]); | ||||
water_indices.push_back(water_index_map[z + moves[1][1]][x + moves[1][0]]); | water_indices.push_back(water_index_map[z + moves[1][1]][x + moves[1][0]]); | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | if (m_VBWater && !onlyShore) | ||||
u8* indexBase = m_VBWaterIndices->m_Owner->Bind(); | u8* indexBase = m_VBWaterIndices->m_Owner->Bind(); | ||||
glDrawElements(GL_TRIANGLES, (GLsizei) m_VBWaterIndices->m_Count, | glDrawElements(GL_TRIANGLES, (GLsizei) m_VBWaterIndices->m_Count, | ||||
GL_UNSIGNED_SHORT, indexBase + sizeof(u16)*(m_VBWaterIndices->m_Index)); | GL_UNSIGNED_SHORT, indexBase + sizeof(u16)*(m_VBWaterIndices->m_Index)); | ||||
g_Renderer.m_Stats.m_DrawCalls++; | g_Renderer.m_Stats.m_DrawCalls++; | ||||
g_Renderer.m_Stats.m_WaterTris += m_VBWaterIndices->m_Count / 3; | g_Renderer.m_Stats.m_WaterTris += m_VBWaterIndices->m_Count / 3; | ||||
} | } | ||||
if (m_VBWaterShore && | if (m_VBWaterShore && g_RenderingOptions.GetWaterEffects() && g_RenderingOptions.GetWaterFancyEffects()) | ||||
g_Renderer.GetWaterManager()->m_WaterEffects && | |||||
g_Renderer.GetWaterManager()->m_WaterFancyEffects) | |||||
{ | { | ||||
SWaterVertex *base=(SWaterVertex *)m_VBWaterShore->m_Owner->Bind(); | SWaterVertex *base=(SWaterVertex *)m_VBWaterShore->m_Owner->Bind(); | ||||
GLsizei stride = sizeof(SWaterVertex); | GLsizei stride = sizeof(SWaterVertex); | ||||
shader->VertexPointer(3, GL_FLOAT, stride, &base[m_VBWaterShore->m_Index].m_Position); | shader->VertexPointer(3, GL_FLOAT, stride, &base[m_VBWaterShore->m_Index].m_Position); | ||||
if (!fixedPipeline) | if (!fixedPipeline) | ||||
shader->VertexAttribPointer(str_a_waterInfo, 2, GL_FLOAT, false, stride, &base[m_VBWaterShore->m_Index].m_WaterData); | shader->VertexAttribPointer(str_a_waterInfo, 2, GL_FLOAT, false, stride, &base[m_VBWaterShore->m_Index].m_WaterData); | ||||
Show All 17 Lines |
Wildfire Games · Phabricator