@@ -281,14 +281,20 @@ struct RenderPassData {
281
281
gl.Disable (GL_DEPTH_TEST);
282
282
}
283
283
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
+
284
289
// --------------------------------------------------------------------------
285
290
// / Setup the viewport.
286
291
// /
287
292
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
292
298
);
293
299
if (pass_data.depth_attachment ) {
294
300
gl.DepthRangef (viewport.depth_range .z_near , viewport.depth_range .z_far );
@@ -300,10 +306,11 @@ struct RenderPassData {
300
306
if (command.scissor .has_value ()) {
301
307
const auto & scissor = command.scissor .value ();
302
308
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
307
314
);
308
315
} else {
309
316
gl.Disable (GL_SCISSOR_TEST);
0 commit comments