scene_renderer.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. #include "scene_renderer.h"
  2. #include "../game/map/terrain_service.h"
  3. #include "../game/map/visibility_service.h"
  4. #include "../game/systems/nation_registry.h"
  5. #include "../game/systems/troop_profile_service.h"
  6. #include "../game/units/spawn_type.h"
  7. #include "../game/units/troop_config.h"
  8. #include "draw_queue.h"
  9. #include "entity/registry.h"
  10. #include "equipment/equipment_registry.h"
  11. #include "game/core/component.h"
  12. #include "game/core/world.h"
  13. #include "gl/backend.h"
  14. #include "gl/buffer.h"
  15. #include "gl/camera.h"
  16. #include "gl/primitives.h"
  17. #include "gl/resources.h"
  18. #include "graphics_settings.h"
  19. #include "ground/firecamp_gpu.h"
  20. #include "ground/grass_gpu.h"
  21. #include "ground/pine_gpu.h"
  22. #include "ground/plant_gpu.h"
  23. #include "ground/stone_gpu.h"
  24. #include "ground/terrain_gpu.h"
  25. #include "horse/rig.h"
  26. #include "humanoid/rig.h"
  27. #include "primitive_batch.h"
  28. #include "submitter.h"
  29. #include <QDebug>
  30. #include <algorithm>
  31. #include <cmath>
  32. #include <cstddef>
  33. #include <cstdint>
  34. #include <memory>
  35. #include <mutex>
  36. #include <qvectornd.h>
  37. #include <string>
  38. namespace Render::GL {
  39. namespace {
  40. const QVector3D k_axis_x(1.0F, 0.0F, 0.0F);
  41. const QVector3D k_axis_y(0.0F, 1.0F, 0.0F);
  42. const QVector3D k_axis_z(0.0F, 0.0F, 1.0F);
  43. } // namespace
  44. Renderer::Renderer() { m_active_queue = &m_queues[m_fill_queue_index]; }
  45. Renderer::~Renderer() { shutdown(); }
  46. auto Renderer::initialize() -> bool {
  47. if (!m_backend) {
  48. m_backend = std::make_shared<Backend>();
  49. }
  50. m_backend->initialize();
  51. m_entity_registry = std::make_unique<EntityRendererRegistry>();
  52. registerBuiltInEntityRenderers(*m_entity_registry);
  53. registerBuiltInEquipment();
  54. return true;
  55. }
  56. void Renderer::shutdown() { m_backend.reset(); }
  57. void Renderer::begin_frame() {
  58. advance_pose_cache_frame();
  59. reset_humanoid_render_stats();
  60. reset_horse_render_stats();
  61. m_active_queue = &m_queues[m_fill_queue_index];
  62. m_active_queue->clear();
  63. if (m_camera != nullptr) {
  64. m_view_proj = m_camera->getProjectionMatrix() * m_camera->getViewMatrix();
  65. }
  66. if (m_backend) {
  67. m_backend->beginFrame();
  68. }
  69. }
  70. void Renderer::end_frame() {
  71. if (m_paused.load()) {
  72. return;
  73. }
  74. if (m_backend && (m_camera != nullptr)) {
  75. std::swap(m_fill_queue_index, m_render_queue_index);
  76. DrawQueue &render_queue = m_queues[m_render_queue_index];
  77. render_queue.sort_for_batching();
  78. m_backend->setAnimationTime(m_accumulated_time);
  79. m_backend->execute(render_queue, *m_camera);
  80. }
  81. }
  82. void Renderer::set_camera(Camera *camera) { m_camera = camera; }
  83. void Renderer::set_clear_color(float r, float g, float b, float a) {
  84. if (m_backend) {
  85. m_backend->setClearColor(r, g, b, a);
  86. }
  87. }
  88. void Renderer::set_viewport(int width, int height) {
  89. m_viewport_width = width;
  90. m_viewport_height = height;
  91. if (m_backend) {
  92. m_backend->setViewport(width, height);
  93. }
  94. if ((m_camera != nullptr) && height > 0) {
  95. float const aspect = float(width) / float(height);
  96. m_camera->setPerspective(m_camera->getFOV(), aspect, m_camera->getNear(),
  97. m_camera->getFar());
  98. }
  99. }
  100. void Renderer::mesh(Mesh *mesh, const QMatrix4x4 &model, const QVector3D &color,
  101. Texture *texture, float alpha, int material_id) {
  102. if (mesh == nullptr) {
  103. return;
  104. }
  105. if (mesh == getUnitCylinder() && (texture == nullptr) &&
  106. (m_current_shader == nullptr)) {
  107. QVector3D start;
  108. QVector3D end;
  109. float radius = 0.0F;
  110. if (detail::decompose_unit_cylinder(model, start, end, radius)) {
  111. cylinder(start, end, radius, color, alpha);
  112. return;
  113. }
  114. }
  115. MeshCmd cmd;
  116. cmd.mesh = mesh;
  117. cmd.texture = texture;
  118. cmd.model = model;
  119. cmd.mvp = m_view_proj * model;
  120. cmd.color = color;
  121. cmd.alpha = alpha;
  122. cmd.material_id = material_id;
  123. cmd.shader = m_current_shader;
  124. if (m_active_queue != nullptr) {
  125. m_active_queue->submit(cmd);
  126. }
  127. }
  128. void Renderer::cylinder(const QVector3D &start, const QVector3D &end,
  129. float radius, const QVector3D &color, float alpha) {
  130. CylinderCmd cmd;
  131. cmd.start = start;
  132. cmd.end = end;
  133. cmd.radius = radius;
  134. cmd.color = color;
  135. cmd.alpha = alpha;
  136. if (m_active_queue != nullptr) {
  137. m_active_queue->submit(cmd);
  138. }
  139. }
  140. void Renderer::fog_batch(const FogInstanceData *instances, std::size_t count) {
  141. if ((instances == nullptr) || count == 0 || (m_active_queue == nullptr)) {
  142. return;
  143. }
  144. FogBatchCmd cmd;
  145. cmd.instances = instances;
  146. cmd.count = count;
  147. m_active_queue->submit(cmd);
  148. }
  149. void Renderer::grass_batch(Buffer *instance_buffer, std::size_t instance_count,
  150. const GrassBatchParams &params) {
  151. if ((instance_buffer == nullptr) || instance_count == 0 ||
  152. (m_active_queue == nullptr)) {
  153. return;
  154. }
  155. GrassBatchCmd cmd;
  156. cmd.instance_buffer = instance_buffer;
  157. cmd.instance_count = instance_count;
  158. cmd.params = params;
  159. cmd.params.time = m_accumulated_time;
  160. m_active_queue->submit(cmd);
  161. }
  162. void Renderer::stone_batch(Buffer *instance_buffer, std::size_t instance_count,
  163. const StoneBatchParams &params) {
  164. if ((instance_buffer == nullptr) || instance_count == 0 ||
  165. (m_active_queue == nullptr)) {
  166. return;
  167. }
  168. StoneBatchCmd cmd;
  169. cmd.instance_buffer = instance_buffer;
  170. cmd.instance_count = instance_count;
  171. cmd.params = params;
  172. m_active_queue->submit(cmd);
  173. }
  174. void Renderer::plant_batch(Buffer *instance_buffer, std::size_t instance_count,
  175. const PlantBatchParams &params) {
  176. if ((instance_buffer == nullptr) || instance_count == 0 ||
  177. (m_active_queue == nullptr)) {
  178. return;
  179. }
  180. PlantBatchCmd cmd;
  181. cmd.instance_buffer = instance_buffer;
  182. cmd.instance_count = instance_count;
  183. cmd.params = params;
  184. cmd.params.time = m_accumulated_time;
  185. m_active_queue->submit(cmd);
  186. }
  187. void Renderer::pine_batch(Buffer *instance_buffer, std::size_t instance_count,
  188. const PineBatchParams &params) {
  189. if ((instance_buffer == nullptr) || instance_count == 0 ||
  190. (m_active_queue == nullptr)) {
  191. return;
  192. }
  193. PineBatchCmd cmd;
  194. cmd.instance_buffer = instance_buffer;
  195. cmd.instance_count = instance_count;
  196. cmd.params = params;
  197. cmd.params.time = m_accumulated_time;
  198. m_active_queue->submit(cmd);
  199. }
  200. void Renderer::olive_batch(Buffer *instance_buffer, std::size_t instance_count,
  201. const OliveBatchParams &params) {
  202. if ((instance_buffer == nullptr) || instance_count == 0 ||
  203. (m_active_queue == nullptr)) {
  204. return;
  205. }
  206. OliveBatchCmd cmd;
  207. cmd.instance_buffer = instance_buffer;
  208. cmd.instance_count = instance_count;
  209. cmd.params = params;
  210. cmd.params.time = m_accumulated_time;
  211. m_active_queue->submit(cmd);
  212. }
  213. void Renderer::firecamp_batch(Buffer *instance_buffer,
  214. std::size_t instance_count,
  215. const FireCampBatchParams &params) {
  216. if ((instance_buffer == nullptr) || instance_count == 0 ||
  217. (m_active_queue == nullptr)) {
  218. return;
  219. }
  220. FireCampBatchCmd cmd;
  221. cmd.instance_buffer = instance_buffer;
  222. cmd.instance_count = instance_count;
  223. cmd.params = params;
  224. cmd.params.time = m_accumulated_time;
  225. m_active_queue->submit(cmd);
  226. }
  227. void Renderer::terrain_chunk(Mesh *mesh, const QMatrix4x4 &model,
  228. const TerrainChunkParams &params,
  229. std::uint16_t sort_key, bool depth_write,
  230. float depth_bias) {
  231. if ((mesh == nullptr) || (m_active_queue == nullptr)) {
  232. return;
  233. }
  234. TerrainChunkCmd cmd;
  235. cmd.mesh = mesh;
  236. cmd.model = model;
  237. cmd.params = params;
  238. cmd.sort_key = sort_key;
  239. cmd.depth_write = depth_write;
  240. cmd.depth_bias = depth_bias;
  241. m_active_queue->submit(cmd);
  242. }
  243. void Renderer::selection_ring(const QMatrix4x4 &model, float alpha_inner,
  244. float alpha_outer, const QVector3D &color) {
  245. SelectionRingCmd cmd;
  246. cmd.model = model;
  247. cmd.mvp = m_view_proj * model;
  248. cmd.alpha_inner = alpha_inner;
  249. cmd.alpha_outer = alpha_outer;
  250. cmd.color = color;
  251. if (m_active_queue != nullptr) {
  252. m_active_queue->submit(cmd);
  253. }
  254. }
  255. void Renderer::grid(const QMatrix4x4 &model, const QVector3D &color,
  256. float cell_size, float thickness, float extent) {
  257. GridCmd cmd;
  258. cmd.model = model;
  259. cmd.mvp = m_view_proj * model;
  260. cmd.color = color;
  261. cmd.cell_size = cell_size;
  262. cmd.thickness = thickness;
  263. cmd.extent = extent;
  264. if (m_active_queue != nullptr) {
  265. m_active_queue->submit(cmd);
  266. }
  267. }
  268. void Renderer::selection_smoke(const QMatrix4x4 &model, const QVector3D &color,
  269. float base_alpha) {
  270. SelectionSmokeCmd cmd;
  271. cmd.model = model;
  272. cmd.mvp = m_view_proj * model;
  273. cmd.color = color;
  274. cmd.base_alpha = base_alpha;
  275. if (m_active_queue != nullptr) {
  276. m_active_queue->submit(cmd);
  277. }
  278. }
  279. void Renderer::enqueue_selection_ring(
  280. Engine::Core::Entity *, Engine::Core::TransformComponent *transform,
  281. Engine::Core::UnitComponent *unit_comp, bool selected, bool hovered) {
  282. if ((!selected && !hovered) || (transform == nullptr)) {
  283. return;
  284. }
  285. float ring_size = 0.5F;
  286. float ring_offset = 0.05F;
  287. float ground_offset = 0.0F;
  288. float scale_y = 1.0F;
  289. if (unit_comp != nullptr) {
  290. auto troop_type_opt =
  291. Game::Units::spawn_typeToTroopType(unit_comp->spawn_type);
  292. if (troop_type_opt) {
  293. const auto &nation_reg = Game::Systems::NationRegistry::instance();
  294. const Game::Systems::Nation *nation =
  295. nation_reg.get_nation_for_player(unit_comp->owner_id);
  296. Game::Systems::NationID nation_id =
  297. nation != nullptr ? nation->id : nation_reg.default_nation_id();
  298. const auto profile =
  299. Game::Systems::TroopProfileService::instance().get_profile(
  300. nation_id, *troop_type_opt);
  301. ring_size = profile.visuals.selection_ring_size;
  302. ring_offset += profile.visuals.selection_ring_y_offset;
  303. ground_offset = profile.visuals.selection_ring_ground_offset;
  304. } else {
  305. auto &config = Game::Units::TroopConfig::instance();
  306. ring_size = config.getSelectionRingSize(unit_comp->spawn_type);
  307. ring_offset += config.getSelectionRingYOffset(unit_comp->spawn_type);
  308. ground_offset =
  309. config.getSelectionRingGroundOffset(unit_comp->spawn_type);
  310. }
  311. }
  312. if (transform != nullptr) {
  313. scale_y = transform->scale.y;
  314. }
  315. QVector3D pos(transform->position.x, transform->position.y,
  316. transform->position.z);
  317. auto &terrain_service = Game::Map::TerrainService::instance();
  318. float terrain_y = transform->position.y;
  319. if (terrain_service.is_initialized()) {
  320. terrain_y = terrain_service.get_terrain_height(pos.x(), pos.z());
  321. } else {
  322. terrain_y -= ground_offset * scale_y;
  323. }
  324. pos.setY(terrain_y);
  325. QMatrix4x4 ring_model;
  326. ring_model.translate(pos.x(), pos.y() + ring_offset, pos.z());
  327. ring_model.scale(ring_size, 1.0F, ring_size);
  328. if (selected) {
  329. selection_ring(ring_model, 0.6F, 0.25F, QVector3D(0.2F, 0.4F, 1.0F));
  330. } else if (hovered) {
  331. selection_ring(ring_model, 0.35F, 0.15F, QVector3D(0.90F, 0.90F, 0.25F));
  332. }
  333. }
  334. void Renderer::render_world(Engine::Core::World *world) {
  335. if (m_paused.load()) {
  336. return;
  337. }
  338. if (world == nullptr) {
  339. return;
  340. }
  341. std::lock_guard<std::recursive_mutex> const guard(world->get_entity_mutex());
  342. auto &vis = Game::Map::VisibilityService::instance();
  343. const bool visibility_enabled = vis.is_initialized();
  344. auto renderable_entities =
  345. world->get_entities_with<Engine::Core::RenderableComponent>();
  346. const auto &gfxSettings = Render::GraphicsSettings::instance();
  347. const auto &batch_config = gfxSettings.batching_config();
  348. float cameraHeight = 0.0F;
  349. if (m_camera != nullptr) {
  350. cameraHeight = m_camera->get_position().y();
  351. }
  352. int visibleUnitCount = 0;
  353. for (auto *entity : renderable_entities) {
  354. if (entity->has_component<Engine::Core::PendingRemovalComponent>()) {
  355. continue;
  356. }
  357. auto *unit_comp = entity->get_component<Engine::Core::UnitComponent>();
  358. if (unit_comp != nullptr && unit_comp->health > 0) {
  359. auto *transform =
  360. entity->get_component<Engine::Core::TransformComponent>();
  361. if (transform != nullptr && m_camera != nullptr) {
  362. QVector3D const unit_pos(transform->position.x, transform->position.y,
  363. transform->position.z);
  364. if (m_camera->isInFrustum(unit_pos, 4.0F)) {
  365. ++visibleUnitCount;
  366. }
  367. }
  368. }
  369. }
  370. float batching_ratio =
  371. gfxSettings.calculate_batching_ratio(visibleUnitCount, cameraHeight);
  372. PrimitiveBatcher batcher;
  373. if (batching_ratio > 0.0F) {
  374. batcher.reserve(2000, 4000, 500);
  375. }
  376. float fullShaderMaxDistance = 30.0F * (1.0F - batching_ratio * 0.7F);
  377. if (batch_config.force_batching) {
  378. fullShaderMaxDistance = 0.0F;
  379. }
  380. BatchingSubmitter batchSubmitter(this, &batcher);
  381. for (auto *entity : renderable_entities) {
  382. if (entity->has_component<Engine::Core::PendingRemovalComponent>()) {
  383. continue;
  384. }
  385. auto *renderable =
  386. entity->get_component<Engine::Core::RenderableComponent>();
  387. auto *transform = entity->get_component<Engine::Core::TransformComponent>();
  388. if (!renderable->visible || (transform == nullptr)) {
  389. continue;
  390. }
  391. auto *unit_comp = entity->get_component<Engine::Core::UnitComponent>();
  392. if ((unit_comp != nullptr) && unit_comp->health <= 0) {
  393. continue;
  394. }
  395. float distanceToCamera = 0.0F;
  396. if ((m_camera != nullptr) && (unit_comp != nullptr)) {
  397. float cull_radius = 3.0F;
  398. if (unit_comp->spawn_type == Game::Units::SpawnType::MountedKnight) {
  399. cull_radius = 4.0F;
  400. } else if (unit_comp->spawn_type == Game::Units::SpawnType::Spearman ||
  401. unit_comp->spawn_type == Game::Units::SpawnType::Archer ||
  402. unit_comp->spawn_type == Game::Units::SpawnType::Knight) {
  403. cull_radius = 2.5F;
  404. }
  405. QVector3D const unit_pos(transform->position.x, transform->position.y,
  406. transform->position.z);
  407. if (!m_camera->isInFrustum(unit_pos, cull_radius)) {
  408. continue;
  409. }
  410. QVector3D camPos = m_camera->get_position();
  411. float dx = unit_pos.x() - camPos.x();
  412. float dz = unit_pos.z() - camPos.z();
  413. distanceToCamera = std::sqrt(dx * dx + dz * dz);
  414. }
  415. if ((unit_comp != nullptr) && unit_comp->owner_id != m_local_owner_id) {
  416. if (visibility_enabled) {
  417. if (!vis.isVisibleWorld(transform->position.x, transform->position.z)) {
  418. continue;
  419. }
  420. }
  421. }
  422. bool const is_selected =
  423. (m_selected_ids.find(entity->get_id()) != m_selected_ids.end());
  424. bool const is_hovered = (entity->get_id() == m_hovered_entity_id);
  425. QMatrix4x4 model_matrix;
  426. model_matrix.translate(transform->position.x, transform->position.y,
  427. transform->position.z);
  428. model_matrix.rotate(transform->rotation.x, k_axis_x);
  429. model_matrix.rotate(transform->rotation.y, k_axis_y);
  430. model_matrix.rotate(transform->rotation.z, k_axis_z);
  431. model_matrix.scale(transform->scale.x, transform->scale.y,
  432. transform->scale.z);
  433. bool drawn_by_registry = false;
  434. if (m_entity_registry) {
  435. std::string renderer_key;
  436. if (!renderable->renderer_id.empty()) {
  437. renderer_key = renderable->renderer_id;
  438. } else if (unit_comp != nullptr) {
  439. renderer_key = Game::Units::spawn_typeToString(unit_comp->spawn_type);
  440. }
  441. auto fn = m_entity_registry->get(renderer_key);
  442. if (fn) {
  443. DrawContext ctx{resources(), entity, world, model_matrix};
  444. ctx.selected = is_selected;
  445. ctx.hovered = is_hovered;
  446. ctx.animation_time = m_accumulated_time;
  447. ctx.renderer_id = renderer_key;
  448. ctx.backend = m_backend.get();
  449. ctx.camera = m_camera;
  450. bool useBatching = (batching_ratio > 0.0F) &&
  451. (distanceToCamera > fullShaderMaxDistance) &&
  452. !is_selected && !is_hovered &&
  453. !batch_config.never_batch;
  454. if (useBatching) {
  455. fn(ctx, batchSubmitter);
  456. } else {
  457. fn(ctx, *this);
  458. }
  459. enqueue_selection_ring(entity, transform, unit_comp, is_selected,
  460. is_hovered);
  461. drawn_by_registry = true;
  462. }
  463. }
  464. if (drawn_by_registry) {
  465. continue;
  466. }
  467. Mesh *mesh_to_draw = nullptr;
  468. ResourceManager *res = resources();
  469. switch (renderable->mesh) {
  470. case Engine::Core::RenderableComponent::MeshKind::Quad:
  471. mesh_to_draw = (res != nullptr) ? res->quad() : nullptr;
  472. break;
  473. case Engine::Core::RenderableComponent::MeshKind::Plane:
  474. mesh_to_draw = (res != nullptr) ? res->ground() : nullptr;
  475. break;
  476. case Engine::Core::RenderableComponent::MeshKind::Cube:
  477. mesh_to_draw = (res != nullptr) ? res->unit() : nullptr;
  478. break;
  479. case Engine::Core::RenderableComponent::MeshKind::Capsule:
  480. mesh_to_draw = nullptr;
  481. break;
  482. case Engine::Core::RenderableComponent::MeshKind::Ring:
  483. mesh_to_draw = nullptr;
  484. break;
  485. case Engine::Core::RenderableComponent::MeshKind::None:
  486. default:
  487. break;
  488. }
  489. if ((mesh_to_draw == nullptr) && (res != nullptr)) {
  490. mesh_to_draw = res->unit();
  491. }
  492. if ((mesh_to_draw == nullptr) && (res != nullptr)) {
  493. mesh_to_draw = res->quad();
  494. }
  495. QVector3D const color = QVector3D(
  496. renderable->color[0], renderable->color[1], renderable->color[2]);
  497. if (res != nullptr) {
  498. Mesh *contact_quad = res->quad();
  499. Texture *white = res->white();
  500. if ((contact_quad != nullptr) && (white != nullptr)) {
  501. QMatrix4x4 contact_base;
  502. contact_base.translate(transform->position.x,
  503. transform->position.y + 0.03F,
  504. transform->position.z);
  505. constexpr float k_contact_shadow_rotation = -90.0F;
  506. contact_base.rotate(k_contact_shadow_rotation, 1.0F, 0.0F, 0.0F);
  507. float const footprint =
  508. std::max({transform->scale.x, transform->scale.z, 0.6F});
  509. float size_ratio = 1.0F;
  510. if (auto *unit = entity->get_component<Engine::Core::UnitComponent>()) {
  511. int const mh = std::max(1, unit->max_health);
  512. size_ratio = std::clamp(unit->health / float(mh), 0.0F, 1.0F);
  513. }
  514. float const eased = 0.25F + 0.75F * size_ratio;
  515. float const base_scale_x = footprint * 0.55F * eased;
  516. float const base_scale_y = footprint * 0.35F * eased;
  517. QVector3D const col(0.03F, 0.03F, 0.03F);
  518. float const center_alpha = 0.32F * eased;
  519. float const mid_alpha = 0.16F * eased;
  520. float const outer_alpha = 0.07F * eased;
  521. QMatrix4x4 c0 = contact_base;
  522. c0.scale(base_scale_x * 0.60F, base_scale_y * 0.60F, 1.0F);
  523. mesh(contact_quad, c0, col, white, center_alpha);
  524. QMatrix4x4 c1 = contact_base;
  525. c1.scale(base_scale_x * 0.95F, base_scale_y * 0.95F, 1.0F);
  526. mesh(contact_quad, c1, col, white, mid_alpha);
  527. QMatrix4x4 c2 = contact_base;
  528. c2.scale(base_scale_x * 1.35F, base_scale_y * 1.35F, 1.0F);
  529. mesh(contact_quad, c2, col, white, outer_alpha);
  530. }
  531. }
  532. enqueue_selection_ring(entity, transform, unit_comp, is_selected,
  533. is_hovered);
  534. mesh(mesh_to_draw, model_matrix, color,
  535. (res != nullptr) ? res->white() : nullptr, 1.0F);
  536. }
  537. if ((m_active_queue != nullptr) && batcher.total_count() > 0) {
  538. PrimitiveBatchParams params;
  539. params.view_proj = m_view_proj;
  540. if (batcher.sphere_count() > 0) {
  541. PrimitiveBatchCmd cmd;
  542. cmd.type = PrimitiveType::Sphere;
  543. cmd.instances = batcher.sphere_data();
  544. cmd.params = params;
  545. m_active_queue->submit(cmd);
  546. }
  547. if (batcher.cylinder_count() > 0) {
  548. PrimitiveBatchCmd cmd;
  549. cmd.type = PrimitiveType::Cylinder;
  550. cmd.instances = batcher.cylinder_data();
  551. cmd.params = params;
  552. m_active_queue->submit(cmd);
  553. }
  554. if (batcher.cone_count() > 0) {
  555. PrimitiveBatchCmd cmd;
  556. cmd.type = PrimitiveType::Cone;
  557. cmd.instances = batcher.cone_data();
  558. cmd.params = params;
  559. m_active_queue->submit(cmd);
  560. }
  561. }
  562. }
  563. } // namespace Render::GL