Repository: godotengine/godot (language: cpp)

Issue:
draw_line() in compatibility mode is broken with light2d
### Tested versions

4.3.rc2

### System information

win11

### Issue description

`draw_line(Vector2.ZERO, Vector2.RIGHT * 800.0, line2d.default_color, 32, true);`
the line here looks wrong with light2d
![QQ图片20240812172753](https://github.com/user-attachments/assets/0c09b563-c485-41b5-aa09-87543819fb28)

This only present in compatibility mode. 
It happened in previous versions, to my memery.
### Steps to reproduce

Draw any line using draw functions with a width over 0, place it with light2d, and you can see the triangle.

### Minimal reproduction project (MRP)

[4.3test (2).zip](https://github.com/user-attachments/files/16579824/4.3test.2.zip)



Discussion / hints:
I can confirm this on 4.4.beta3 (Linux, GeForce RTX 4090 with NVIDIA 565.77). The issue is not present in Forward+/Mobile.

The issue remains if you disable antialiasing in `draw_line()` in the MRP's script. The stripes' direction are independent of the line's rotation, so I suspect some kind of polygon winding order issue in the CanvasItem polygon generation methods used for `draw_line()` with thickness above `1`:

![Image](https://github.com/user-attachments/assets/1db68487-c48c-4b51-be43-0459a27c346c)

If you leave antialiasing enabled and zoom to very high levels in the 2D editor (3000% or more), you'll see the winding order artifacts more clearly as they also happen on the feathers generated for line antialiasing:

![Image](https://github.com/user-attachments/assets/fb7183c9-995a-4f3f-8a19-36473ef966a8)
Can also confirm on v4.4.beta3.official [06acfccf8] (Windows, AMD Radeon RX6600)

Could this be linked to https://github.com/godotengine/godot/issues/16466 ?

`Line2D` is using the `LineBuilder` to draw the line, but `add_line` implements it differently.

https://github.com/godotengine/godot/blob/96cdbbe5bd5e068953b5e972daaee37850686c31/servers/rendering/renderer_canvas_cull.cpp#L717-L900
I swapped the current `canvas_item_add_line` implementation with a LineBuilder and it seems to fix the issue : 

![Image](https://github.com/user-attachments/assets/2781f091-abfd-4f4c-a00d-69854226002d)

```gdscript
void RendererCanvasCull::canvas_item_add_line(RID p_item, const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width, bool p_antialiased) {
	Vector<Vector2> points;
	points.push_back(p_from);
	points.push_back(p_to);

	LineBuilder lb;
	lb.width = p_width;
	lb.default_color = p_color;
	lb.points = points;

	lb.build();
	if (lb.indices.is_empty()) {
		return;
	}

	canvas_item_add_triangle_array(p_item, lb.indices, lb.vertices, lb.colors, lb.uvs);
}
```

It's my first time so I'm not familiar with the engine, I don't know if doing this breaks things elsewhere.

> Also to be noted: the `p_antialiased` parameter was not used since there's not any in the LineBuilder (Is it by default ? Implemented differently ?)

Fix patch:
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp
index 0ca013abd1a0..441636cd26db 100644
--- a/drivers/gles3/rasterizer_canvas_gles3.cpp
+++ b/drivers/gles3/rasterizer_canvas_gles3.cpp
@@ -1152,6 +1152,12 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend
 					// Reset base data.
 					_update_transform_2d_to_mat2x3(base_transform * draw_transform, state.instance_data_array[r_index].world);
 					_prepare_canvas_texture(state.canvas_instance_batches[state.current_batch_index].tex, state.canvas_instance_batches[state.current_batch_index].filter, state.canvas_instance_batches[state.current_batch_index].repeat, r_index, texpixel_size);
+					state.instance_data_array[r_index].lights[0] = lights[0];
+					state.instance_data_array[r_index].lights[1] = lights[1];
+					state.instance_data_array[r_index].lights[2] = lights[2];
+					state.instance_data_array[r_index].lights[3] = lights[3];
+					state.instance_data_array[r_index].flags = base_flags;
+					state.instance_data_array[r_index].instance_uniforms_ofs = p_item->instance_allocated_shader_uniforms_offset;
 
 					for (uint32_t j = 0; j < 3; j++) {
 						int offset = j == 0 ? 0 : 1;


Test patch: