-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fixes tint in 2d canvas with webgl p5.Graphics #5060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hi, @montoyamoraga @stalgiag Can you please review my PR |
Hi @ShenpaiSharma this is a good start! We might want to take a slightly different approach to make sure we don't repeat code unnecessarily. This will make it easier to fix problems that might arise in the future. Read my comment here where I outline why this might be better handled in a slightly different way. |
I am sorry, @stalgiag. I had my mid-semester exams, so I thought before going on a break, I should try this quick fix first. |
No worries! I am having a bit of trouble following. Can you try explaining in another way? Thank you! |
Hi, @stalgiag well, I tried this code initially:
but it showed the same error as previously and the code that you have given : What I feel is that instead, the tint has been made available in WebGL, but most of the tint property is not inherited by rendererGL class, which is used by renderer2D like _getTintedImageCanvas, etc... |
Hi @ShenpaiSharma -- I think I understand. Have you tried passing only the renderer: Filters._toPixels = function(renderer) {
const data;
if (!renderer.isP3D) {
data = renderer.canvas.data;
} else {
data = new Uint8Array(len);
gl.readPixels(
0,
0,
canvas.width,
canvas.height,
gl.RGBA,
gl.UNSIGNED_BYTE,
data
);
}
return data;
}; Note that this is very much untested and I wrote it quickly so it would be up to you to see if that general approach worked. Also this still repeats a lot of code from loadPixels but I think that could be okay. |
…g CanvasRenderingContext2D.
Hi, @stalgiag. I have tried a completely different approach, and it worked perfectly. Can you please review it? |
Well, I have tried passing renderer only too, but it was always showing some error. As I said earlier in my comment, maybe it could be due to that. |
Hi @ShenpaiSharma I forgot to include that line. You can access gl as a property on the renderer when it is RendererGL with I don't think we need to create a new 2d canvas for getting the pixels. |
Hi @stalgiag yeah I have seen that but problem is that whenever I am passing renderer it is showing bunch of error in console. |
Hi @ShenpaiSharma I took some time to look at this in detail today. Changing things around so that a renderer is passed instead of a canvas object would require changing a number of different functions. This is too much work for what should be a fix. Thanks for trying anyway though! I don't think we need to draw to the offscreen canvas. The first suggestion I made in the issue and the first commit that you made both work well enough. If you add a comment explaining that 'this approach is not ideal but put in place as a quick fix for a bug' then I think it will be okay to merge. |
Hi @stalgiag, I tried to go through the whole rendering pipeline and tried to change the files according to it, but I still got some errors while passing renderer in the function. |
@ShenpaiSharma I think the first commit is the better approach of the two. It is easier to understand what is happening. It is unfortunate to |
Hi @stalgiag, I understand, then it will be okay to merge the first commit. Thanks |
Oh, sorry forgot to revert the last commit. Now I think it should be ready to get merged |
Thank you @ShenpaiSharma ! |
Resolves #5046
Changes:
Added condition while rendering webgl such that it reads a block of pixels from a specified shape of the current color framebuffer into an ArrayBufferView object.
Screenshots of the change:

After change:
PR Checklist
npm run lint
passes