Fixed interaction between dynamic texture and context.clip() #1185
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Allows Dynamic Texture context
context.drawImage
context.clearRect
andcontext.fillRect
to properly work withcontext.clip
.Implementation
When calling
Babylon::Polyfills::Internal::Context::DrawImage
thenvgBeginPath
is been called every time. This will discard any path that was previously set by the user. The correct behavior should be to not callnvgBeginPath
ifBabylon::Polyfills::Internal::Context::Clip
was previously called.Also, in
Babylon::Polyfills::Internal::Context::Clip
them_rectangleClipping
is been used to set the Scissor values even whenm_rectangleClipping
was never set before (with default values 0, 0, 0, 0). This will make some of the following operations to produce no result. The correct behavior should be to only usem_rectangleClipping
if the were set, otherwise use the width and height of the render target.Finally, when creating Babylon::Polyfills::Internal::NativeCanvasImage the resulting data might be in RGB instead of RGBA. However, during
NativeCanvasImage::CreateNVGImageForContext
NVG always assumes the format to be RGBA, which might cause a memory out of bounds read if the image was originally RGB. This PR forcesbimg::imageParse
to always convert the image to RGBA.More information
Allows the following code to work in Babylon Native: https://playground.babylonjs.com/#FU0ES5#27
Fixes issue #1184