From 8b730b889b32c33b85048d7ebdf770c1c6ee71dc Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 12:06:10 +0100 Subject: [PATCH] fix(render): Mouse_Hit() no longer says yes when it doesn't know The base renderer answered true, so the legacy OpenGL renderer and any other one without its own answer told the editor the cursor was over something even over the sky, with a stale Mouse_Position(). The base answers false now; the legacy renderer answers from the depth it reads under the cursor, as the gl33 one does (the gl46 and Vulkan ones of feat/gl46-migration do already). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ --- rendering/openglrenderer.cpp | 3 ++- rendering/openglrenderer.h | 3 +++ rendering/renderer.h | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/rendering/openglrenderer.cpp b/rendering/openglrenderer.cpp index 8c6debdc7..6f807d095 100644 --- a/rendering/openglrenderer.cpp +++ b/rendering/openglrenderer.cpp @@ -4288,7 +4288,8 @@ opengl_renderer::Update_Mouse_Position() { GLfloat pointdepth; ::glReadPixels( mousepos.x, mousepos.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pointdepth ); - if( pointdepth < 1.0 ) { + m_mousehit = pointdepth < 1.0; + if( m_mousehit ) { m_worldmousecoordinates = glm::unProject( glm::vec3{ mousepos, pointdepth }, diff --git a/rendering/openglrenderer.h b/rendering/openglrenderer.h index 15c9e7cdb..681b2a98c 100644 --- a/rendering/openglrenderer.h +++ b/rendering/openglrenderer.h @@ -108,6 +108,8 @@ public: Forget_Node( scene::basic_node const *Node ) override; glm::dvec3 Mouse_Position() const override { return m_worldmousecoordinates; } + bool + Mouse_Hit() const override { return m_mousehit; } glm::mat4 Camera_View_Matrix() const override { return glm::mat4( glm::mat3( m_colorpass.camera.modelview() ) ); } glm::mat4 @@ -377,6 +379,7 @@ private: std::vector m_picksceneryitems; scene::basic_node *m_picksceneryitem { nullptr }; glm::vec3 m_worldmousecoordinates { 0.f }; + bool m_mousehit { false }; // the depth under the cursor was of something drawn, not of the far plane std::vector> m_control_pick_requests; std::vector> m_node_pick_requests; #ifdef EU07_USE_DEBUG_CAMERA diff --git a/rendering/renderer.h b/rendering/renderer.h index dec3f752e..897494a6d 100644 --- a/rendering/renderer.h +++ b/rendering/renderer.h @@ -111,7 +111,9 @@ public: } virtual auto Mouse_Position() const -> glm::dvec3 = 0; - virtual auto Mouse_Hit() const -> bool { return true; } + // whether the cursor was over something drawn when Mouse_Position() was read; a renderer which doesn't read it says no, + // so a caller never takes a stale or empty position for a hit + virtual auto Mouse_Hit() const -> bool { return false; } // editor helpers: matrices/position of the most recent color pass camera. // the view matrix is camera-relative (rotation only, camera at origin), matching the // camera-relative rendering used by the engine; build object matrices relative to Camera_Position().