scene_renderer.cpp 20 KB

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