@@ -281,14 +281,20 @@ struct RenderPassData {
281281 gl.Disable (GL_DEPTH_TEST);
282282 }
283283
284+ // Both the viewport and scissor are specified in framebuffer coordinates.
285+ // Impeller's framebuffer coordinate system is top left origin, but OpenGL's
286+ // is bottom left origin, so we convert the coordinates here.
287+ auto target_size = pass_data.color_attachment ->GetSize ();
288+
284289 // --------------------------------------------------------------------------
285290 // / Setup the viewport.
286291 // /
287292 const auto & viewport = command.viewport .value_or (pass_data.viewport );
288- gl.Viewport (viewport.rect .origin .x , // x
289- viewport.rect .origin .y , // y
290- viewport.rect .size .width , // width
291- viewport.rect .size .height // height
293+ gl.Viewport (viewport.rect .origin .x , // x
294+ target_size.height - viewport.rect .origin .y -
295+ viewport.rect .size .height , // y
296+ viewport.rect .size .width , // width
297+ viewport.rect .size .height // height
292298 );
293299 if (pass_data.depth_attachment ) {
294300 gl.DepthRangef (viewport.depth_range .z_near , viewport.depth_range .z_far );
@@ -300,10 +306,11 @@ struct RenderPassData {
300306 if (command.scissor .has_value ()) {
301307 const auto & scissor = command.scissor .value ();
302308 gl.Enable (GL_SCISSOR_TEST);
303- gl.Scissor (scissor.origin .x , // x
304- scissor.origin .y , // y
305- scissor.size .width , // width
306- scissor.size .width // height
309+ gl.Scissor (
310+ scissor.origin .x , // x
311+ target_size.height - scissor.origin .y - scissor.size .height , // y
312+ scissor.size .width , // width
313+ scissor.size .height // height
307314 );
308315 } else {
309316 gl.Disable (GL_SCISSOR_TEST);
0 commit comments