If you want to do it on the actual geometry, plenty of polygon triangulation libraries (e.g. earcut.hpp) let you specify holes. That's not something you want to do every frame, though, so if the boat moves, it's not suitable.
Another classic option for this kind of thing is to make use of the stencil buffer. I can't find a good guide on doing this for OpenGL (although a couple exist for Unity, and I've seen it in the wild), but the gist is that you draw some invisible geometry for the top deck of the boat (so something that ends up between the camera and all the bits of the lower deck you want to see, effectively forming a cap on the volume you'll cut out of the water) that has depth writes enabled and also writes a particular value to the stencil buffer. You then draw the lower decks with depth writes disabled and the depth test disabled, too, but the stencil test enabled so it only ends up in pixels your other mesh was drawn in. This can put some annoying restrictions on the geometry for your lower decks, though, as you need to make sure they draw okay with depth writes and the depth test disabled.
A potentially less restrictive option, if you can control, or at least test, whether the boat is drawn after the water, would be to either:
- Guarantee the water is drawn before the boat. Right before drawing the boat, draw the upper deck cap mesh with depth writes on and the depth test off, but the depth set to a far value (it's better to do this by altering the vertex position in the vertex shader than altering the depth in the fragment shader as modern GPUs don't like doing the latter). This will cut a hole in the depth buffer representation of the water, so when you draw the boat normally, it'll be as if the water was never there.
- Guarantee the boat is drawn before the water. Right after drawing the boat, draw an invisible upper deck cap mesh with depth writes and the depth test on as normal. This will mean there's something in the depth buffer preventing the water being drawn there.
- Determine whether the boat or water is drawn first each frame, and pick one of the above as appropriate.
Hope this gives you some ideas.