Skip to content

Commit 714935e

Browse files
authored
Fix framebuffer mapping for viewport and scissor (flutter#33706)
1 parent 59bf20c commit 714935e

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

impeller/geometry/matrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace impeller {
2727
/// * Left-handed coordinate system. Positive rotation is
2828
/// clockwise about axis of rotation.
2929
/// * Lower left corner is -1.0, -1.0.
30-
/// * Upper left corner is 1.0, 1.0.
30+
/// * Upper right corner is 1.0, 1.0.
3131
/// * Visible z-space is from 0.0 to 1.0.
3232
/// * This is NOT the same as OpenGL! Be careful.
3333
/// * NDC origin is at (0.0, 0.0, 0.5).

impeller/renderer/backend/gles/render_pass_gles.cc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)