@@ -296,20 +296,32 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
296296 // Clip read area to framebuffer.
297297 const gl::Extents &fbSize = getState ().getReadAttachment ()->getSize ();
298298 const gl::Rectangle fbRect (0 , 0 , fbSize.width , fbSize.height );
299+ ContextVk *contextVk = vk::GetImpl (context);
300+ RendererVk *renderer = contextVk->getRenderer ();
301+
299302 gl::Rectangle clippedArea;
300303 if (!ClipRectangle (area, fbRect, &clippedArea))
301304 {
302305 // nothing to read
303306 return gl::NoError ();
304307 }
308+ gl::Rectangle flippedArea = clippedArea;
309+ if (contextVk->isViewportFlipEnabled ())
310+ {
311+ flippedArea.y = fbRect.height - flippedArea.y - flippedArea.height ;
312+ }
305313
306314 const gl::State &glState = context->getGLState ();
307- RendererVk *renderer = vk::GetImpl (context)->getRenderer ();
308315
309316 vk::CommandBuffer *commandBuffer = nullptr ;
310317 ANGLE_TRY (beginWriteResource (renderer, &commandBuffer));
311318
312- const gl::PixelPackState &packState = context->getGLState ().getPackState ();
319+ gl::PixelPackState packState (context->getGLState ().getPackState ());
320+ if (contextVk->isViewportFlipEnabled ())
321+ {
322+ packState.reverseRowOrder = !packState.reverseRowOrder ;
323+ }
324+
313325 const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo (format, type);
314326
315327 GLuint outputPitch = 0 ;
@@ -324,14 +336,14 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
324336 (clippedArea.y - area.y ) * outputPitch;
325337
326338 PackPixelsParams params;
327- params.area = clippedArea ;
339+ params.area = flippedArea ;
328340 params.format = format;
329341 params.type = type;
330342 params.outputPitch = outputPitch;
331343 params.packBuffer = glState.getTargetBuffer (gl::BufferBinding::PixelPack);
332344 params.pack = glState.getPackState ();
333345
334- ANGLE_TRY (readPixelsImpl (context, clippedArea , params,
346+ ANGLE_TRY (readPixelsImpl (context, flippedArea , params,
335347 static_cast <uint8_t *>(pixels) + outputSkipBytes));
336348 mReadPixelsBuffer .releaseRetainedBuffers (renderer);
337349 return gl::NoError ();
@@ -877,7 +889,7 @@ gl::Error FramebufferVk::clearWithDraw(const gl::Context *context,
877889 pipelineDesc.updateColorWriteMask (colorMaskFlags, getEmulatedAlphaAttachmentMask ());
878890 pipelineDesc.updateRenderPassDesc (getRenderPassDesc ());
879891 pipelineDesc.updateShaders (fullScreenQuad->queueSerial (), pushConstantColor->queueSerial ());
880- pipelineDesc.updateViewport (renderArea, 0 .0f , 1 .0f );
892+ pipelineDesc.updateViewport (renderArea, 0 .0f , 1 .0f , contextVk-> isViewportFlipEnabled () );
881893
882894 const gl::State &glState = contextVk->getGLState ();
883895 if (glState.isScissorTestEnabled ())
@@ -888,11 +900,11 @@ gl::Error FramebufferVk::clearWithDraw(const gl::Context *context,
888900 return gl::NoError ();
889901 }
890902
891- pipelineDesc.updateScissor (intersection);
903+ pipelineDesc.updateScissor (intersection, contextVk-> isViewportFlipEnabled (), renderArea );
892904 }
893905 else
894906 {
895- pipelineDesc.updateScissor (renderArea);
907+ pipelineDesc.updateScissor (renderArea, contextVk-> isViewportFlipEnabled (), renderArea );
896908 }
897909
898910 vk::PipelineAndSerial *pipeline = nullptr ;
0 commit comments