Changeset 25314
- Timestamp:
- Apr 25, 2021, 10:48:44 PM (3 years ago)
- Location:
- ps/trunk/source
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/graphics/Overlay.h
r24352 r25314 1 /* Copyright (C) 202 0Wildfire Games.1 /* Copyright (C) 202 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 36 36 /** 37 37 * Line-based overlay, with world-space coordinates, rendered in the world 38 * potentially behind other objects. Designed for selection circles anddebug info.38 * potentially behind other objects. Designed for debug info. 39 39 */ 40 40 struct SOverlayLine 41 41 { 42 SOverlayLine() : m_Thickness(1) { } 43 44 CColor m_Color; 45 std::vector<float> m_Coords; // (x, y, z) vertex coordinate triples; shape is not automatically closed 46 u8 m_Thickness; // in pixels 47 48 void PushCoords(const CVector3D& v) { PushCoords(v.X, v.Y, v.Z); } 42 SOverlayLine() : m_Thickness(0.1f) { } 43 44 CColor m_Color; 45 // Shape is not automatically closed. 46 std::vector<CVector3D> m_Coords; 47 // Half-width of the line, in world-space units. 48 float m_Thickness; 49 50 void PushCoords(const CVector3D& v) { m_Coords.emplace_back(v); } 51 49 52 void PushCoords(const float x, const float y, const float z) 50 53 { 51 m_Coords.push_back(x); 52 m_Coords.push_back(y); 53 m_Coords.push_back(z); 54 m_Coords.emplace_back(x, y, z); 54 55 } 55 56 }; -
ps/trunk/source/renderer/DebugRenderer.cpp
r25271 r25314 37 37 return; 38 38 39 40 41 42 43 39 44 #if CONFIG2_GLES 40 45 #warning TODO: implement drawing line for GLES … … 49 54 debugLineShader->Uniform(str_color, color); 50 55 51 // Basis to set a line with the width in R^3 space. 52 const CVector3D direction = (to - from).Normalized(); 53 const CVector3D upCandidate = direction.Dot(CVector3D(0.0f, 1.0f, 0.0f)) > 0.9f ? 54 CVector3D(1.0f, 0.0f, 0.0f) : 55 CVector3D(0.0f, 1.0f, 0.0f); 56 const CVector3D right = direction.Cross(upCandidate).Normalized(); 57 const CVector3D up = direction.Cross(right); 56 const CVector3D cameraIn = g_Renderer.GetViewCamera().GetOrientation().GetIn(); 58 57 59 58 std::vector<float> vertices; 60 const size_t splits = 3; 61 float angle = 0.0f; 62 const float step = static_cast<float>(M_PI * 2.0f / splits); 63 for (size_t idx = 0; idx <= splits; ++idx, angle += step) 64 { 65 const CVector3D offset = (right * std::cos(angle) + up * std::sin(angle)) * width; 66 const CVector3D a = from + offset; 67 const CVector3D b = to + offset; 68 vertices.emplace_back(a.X); 69 vertices.emplace_back(a.Y); 70 vertices.emplace_back(a.Z); 71 vertices.emplace_back(b.X); 72 vertices.emplace_back(b.Y); 73 vertices.emplace_back(b.Z); 74 } 75 debugLineShader->VertexPointer(3, GL_FLOAT, sizeof(float) * 3, vertices.data()); 59 #define ADD(position) \ 60 vertices.emplace_back((position).X); \ 61 vertices.emplace_back((position).Y); \ 62 vertices.emplace_back((position).Z); 63 64 for (size_t idx = 1; idx < line.size(); ++idx) 65 { 66 const CVector3D from = line[idx - 1]; 67 const CVector3D to = line[idx]; 68 const CVector3D direction = (to - from).Normalized(); 69 const CVector3D view = direction.Dot(cameraIn) > 0.9f ? 70 CVector3D(0.0f, 1.0f, 0.0f) : 71 cameraIn; 72 const CVector3D offset = view.Cross(direction).Normalized() * width; 73 74 ADD(from + offset) 75 ADD(to - offset) 76 ADD(to + offset) 77 ADD(from + offset) 78 ADD(from - offset) 79 ADD(to - offset) 80 } 81 82 #undef ADD 83 84 debugLineShader->VertexPointer(3, GL_FLOAT, 0, vertices.data()); 76 85 debugLineShader->AssertPointersBound(); 77 glDrawArrays(GL_TRIANGLE _STRIP, 0, vertices.size() / 3);86 glDrawArrays(GL_TRIANGLE, 0, vertices.size() / 3); 78 87 79 88 debugLineShader->Unbind(); -
ps/trunk/source/renderer/DebugRenderer.h
r25271 r25314 21 21 #include "graphics/ShaderProgramPtr.h" 22 22 23 24 23 25 class CBoundingBoxAligned; 24 26 class CBrush; … … 37 39 */ 38 40 void DrawLine(const CVector3D& from, const CVector3D& to, const CColor& color, const float width); 41 39 42 40 43 /** -
ps/trunk/source/renderer/OverlayRenderer.cpp
r25285 r25314 31 31 #include "ps/Game.h" 32 32 #include "ps/Profile.h" 33 33 34 #include "renderer/Renderer.h" 34 35 #include "renderer/TexturedLineRData.h" … … 225 226 void OverlayRenderer::Submit(SOverlayLine* line) 226 227 { 227 ENSURE(line->m_Coords.size() % 3 == 0);228 229 228 m->lines.push_back(line); 230 229 } … … 382 381 #warning TODO: implement OverlayRenderer::RenderOverlaysBeforeWater for GLES 383 382 #else 384 if (g_Renderer.GetOverlayRenderMode() == WIREFRAME)385 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);386 387 pglActiveTextureARB(GL_TEXTURE0);388 glDisable(GL_TEXTURE_2D);389 383 glEnable(GL_BLEND); 390 391 384 // Ignore z so that we draw behind terrain (but don't disable GL_DEPTH_TEST 392 385 // since we still want to write to the z buffer) 393 386 glDepthFunc(GL_ALWAYS); 394 387 395 for (size_t i = 0; i < m->lines.size(); ++i) 396 { 397 SOverlayLine* line = m->lines[i]; 388 for (SOverlayLine* line : m->lines) 389 { 398 390 if (line->m_Coords.empty()) 399 391 continue; 400 392 401 ENSURE(line->m_Coords.size() % 3 == 0); 402 403 glColor4fv(line->m_Color.FloatArray()); 404 glLineWidth((float)line->m_Thickness); 405 406 glInterleavedArrays(GL_V3F, sizeof(float)*3, &line->m_Coords[0]); 407 glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)line->m_Coords.size()/3); 408 } 409 410 glDisableClientState(GL_VERTEX_ARRAY); 411 412 glLineWidth(1.f); 393 g_Renderer.GetDebugRenderer().DrawLine(line->m_Coords, line->m_Color, static_cast<float>(line->m_Thickness)); 394 } 395 413 396 glDepthFunc(GL_LEQUAL); 414 397 glDisable(GL_BLEND); 415 416 if (g_Renderer.GetOverlayRenderMode() == WIREFRAME)417 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);418 398 #endif 419 399 } -
ps/trunk/source/renderer/PatchRData.cpp
r24870 r25314 38 38 #include "ps/World.h" 39 39 #include "renderer/AlphaMapCalculator.h" 40 40 41 #include "renderer/Renderer.h" 41 42 #include "renderer/TerrainRenderer.h" … … 1122 1123 } 1123 1124 1124 #if CONFIG2_GLES 1125 #warning TODO: implement CPatchRData::RenderOutlines for GLES 1126 #else 1127 glVertexPointer(3, GL_FLOAT, sizeof(CVector3D), &line[0]); 1128 glDrawArrays(GL_LINE_STRIP, 0, line.size()); 1129 #endif 1125 g_Renderer.GetDebugRenderer().DrawLine(line, CColor(0.0f, 0.0f, 1.0f, 1.0f), 0.1f); 1130 1126 } 1131 1127 -
ps/trunk/source/renderer/TerrainRenderer.cpp
r25114 r25314 354 354 return; 355 355 356 #if CONFIG2_GLES357 #warning TODO: implement TerrainRenderer::RenderOutlines for GLES358 #else359 glEnableClientState(GL_VERTEX_ARRAY);360 356 for (size_t i = 0; i < visiblePatches.size(); ++i) 361 357 visiblePatches[i]->RenderOutline(); 362 glDisableClientState(GL_VERTEX_ARRAY);363 #endif364 358 } 365 359 -
ps/trunk/source/simulation2/components/CCmpRallyPointRenderer.cpp
r25228 r25314 442 442 SOverlayLine overlayLine; 443 443 overlayLine.m_Color = CColor(1.0f, 0.0f, 0.0f, 1.0f); 444 overlayLine.m_Thickness = 2;444 overlayLine.m_Thickness = ; 445 445 SimRender::ConstructSquareOnGround(GetSimContext(), point.X, point.Y, 0.2f, 0.2f, 1.0f, overlayLine, true); 446 446 m_DebugNodeOverlays[index].push_back(overlayLine); -
ps/trunk/source/simulation2/components/CCmpSelectable.cpp
r25228 r25314 671 671 { 672 672 SimRender::ConstructBoxOutline(cmpVisual->GetBounds(), *m_DebugBoundingBoxOverlay); 673 m_DebugBoundingBoxOverlay->m_Thickness = 2;673 m_DebugBoundingBoxOverlay->m_Thickness = ; 674 674 m_DebugBoundingBoxOverlay->m_Color = CColor(1.f, 0.f, 0.f, 1.f); 675 675 676 676 SimRender::ConstructBoxOutline(cmpVisual->GetSelectionBox(), *m_DebugSelectionBoxOverlay); 677 m_DebugSelectionBoxOverlay->m_Thickness = 2;677 m_DebugSelectionBoxOverlay->m_Thickness = ; 678 678 m_DebugSelectionBoxOverlay->m_Color = CColor(0.f, 1.f, 0.f, 1.f); 679 679 -
ps/trunk/source/simulation2/components/CCmpTerritoryManager.cpp
r24487 r25314 1 /* Copyright (C) 202 0Wildfire Games.1 /* Copyright (C) 202 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 661 661 overlayNode.m_Color = CColor(1.0f, 1.0f, 1.0f, 1.0f); 662 662 663 overlayNode.m_Thickness = 1;663 overlayNode.m_Thickness = ; 664 664 SimRender::ConstructCircleOnGround(GetSimContext(), boundaries[i].points[j].X, boundaries[i].points[j].Y, 0.1f, overlayNode, true); 665 665 m_DebugBoundaryLineNodes.push_back(overlayNode); -
ps/trunk/source/simulation2/helpers/Render.cpp
r24227 r25314 1 /* Copyright (C) 20 19Wildfire Games.1 /* Copyright (C) 20 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * … … 58 58 for (size_t i = 0; i < xz.size(); i += 2) 59 59 { 60 float px = xz[i]; 61 float pz = xz[i+1]; 62 float py = std::max(water, cmpTerrain->GetExactGroundLevel(px, pz)) + heightOffset; 63 overlay.m_Coords.push_back(px); 64 overlay.m_Coords.push_back(py); 65 overlay.m_Coords.push_back(pz); 60 const float px = xz[i]; 61 const float pz = xz[i+1]; 62 const float py = std::max(water, cmpTerrain->GetExactGroundLevel(px, pz)) + heightOffset; 63 overlay.PushCoords(px, py, pz); 66 64 } 67 65 } … … 100 98 // Start at the center point 101 99 cy = std::max(water, cmpTerrain->GetExactGroundLevel(x, z)) + heightOffset; 102 overlay.m_Coords.push_back(x); 103 overlay.m_Coords.push_back(cy); 104 overlay.m_Coords.push_back(z); 100 overlay.PushCoords(x, cy, z); 105 101 } 106 102 … … 111 107 float pz = z + radius * sinf(a); 112 108 float py = std::max(water, cmpTerrain->GetExactGroundLevel(px, pz)) + heightOffset; 113 overlay.m_Coords.push_back(px); 114 overlay.m_Coords.push_back(py); 115 overlay.m_Coords.push_back(pz); 109 overlay.PushCoords(px, py, pz); 116 110 } 117 111 … … 119 113 { 120 114 // Return to the center point 121 overlay.m_Coords.push_back(x); 122 overlay.m_Coords.push_back(cy); 123 overlay.m_Coords.push_back(z); 115 overlay.PushCoords(x, cy, z); 124 116 } 125 117 } … … 196 188 float pz = coords[i].second; 197 189 float py = std::max(water, cmpTerrain->GetExactGroundLevel(px, pz)) + heightOffset; 198 overlay.m_Coords.push_back(px); 199 overlay.m_Coords.push_back(py); 200 overlay.m_Coords.push_back(pz); 190 overlay.PushCoords(px, py, pz); 201 191 } 202 192 } … … 327 317 outZ.m_Color = CColor(0, 0, 1, .5f); // Z axis; blue 328 318 329 outX.m_Thickness = 2;330 outY.m_Thickness = 2;331 outZ.m_Thickness = 2;319 outX.m_Thickness = ; 320 outY.m_Thickness = ; 321 outZ.m_Thickness = ; 332 322 333 323 CVector3D origin = coordSystem.GetTranslation(); -
ps/trunk/source/tools/atlas/GameInterface/ActorViewer.cpp
r25222 r25314 131 131 { 132 132 SelectionBoxOverlay.m_Color = CColor(35/255.f, 86/255.f, 188/255.f, .75f); // pretty blue 133 SelectionBoxOverlay.m_Thickness = 2;133 SelectionBoxOverlay.m_Thickness = ; 134 134 135 135 SimRender::ConstructBoxOutline(cmpVisual->GetSelectionBox(), SelectionBoxOverlay);
Note:
See TracChangeset
for help on using the changeset viewer.