Title: PGraphics loadPixels() seems to not set/check .loaded flag in P2D · Issue #6214 · processing/processing · GitHub
Open Graph Title: PGraphics loadPixels() seems to not set/check .loaded flag in P2D · Issue #6214 · processing/processing
X Title: PGraphics loadPixels() seems to not set/check .loaded flag in P2D · Issue #6214 · processing/processing
Description: Description Whenever loadPixels() is used on a PGraphics object in a P2D context, it seems to literally download the texture every time, regardless of whether it's been called/downloaded before. In the standard renderer, it seems like su...
Open Graph Description: Description Whenever loadPixels() is used on a PGraphics object in a P2D context, it seems to literally download the texture every time, regardless of whether it's been called/downloaded before. In...
X Description: Description Whenever loadPixels() is used on a PGraphics object in a P2D context, it seems to literally download the texture every time, regardless of whether it's been called/downloaded before...
Opengraph URL: https://github.com/processing/processing/issues/6214
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PGraphics loadPixels() seems to not set/check .loaded flag in P2D ","articleBody":"## Description\r\nWhenever loadPixels() is used **on a PGraphics object** in a P2D context, it seems to literally download the texture every time, regardless of whether it's been called/downloaded before. In the standard renderer, it seems like subsequent loadPixels() calls do not result in numerous texture downloads.\r\n\r\n## Expected Behavior\r\nI was expecting the loadPixels() function to check the isLoaded() / loaded flag before deciding on whether the pixel array has to be recreated or not.\r\n\r\n## Current Behavior\r\nIn P2D, calling loadPixels on a large PGraphics texture numerous times a frame absolutely wrecks the frame rate, as it should if it recreates/downloads the buffer every time. The standard renderer seems to ignore subsequent loadPixels() calls to the same PGraphics texture. On standard PImage files this issue does not exist. Only PGraphics objects passed into / converted to PImage objects, see example below.\r\n\r\n## Steps to Reproduce\r\n```\r\nPGraphics pg;\r\n\r\nvoid setup()\r\n{\r\n size(500, 500, P2D);\r\n frameRate(60);\r\n\r\n //pg = createGraphics(width, height); // 60fps - works as expected; PImage.loadPixels() call in sampleColour ignored \r\n pg = createGraphics(width, height, P2D); // 2fps - performance seemingly wrecked by pg.loadPixels() in sampleColour() \r\n}\r\n\r\nvoid draw()\r\n{\r\n surface.setTitle(\"FPS: \"+nf(frameRate, 1, 1));\r\n\r\n /*\r\n This example replicates the PImage.get() behaviour\r\n creating a 'sampleColour' method to illustrate the issue\r\n */\r\n \r\n // update offscreen pg \u0026 prepare texture for sampling\r\n pg.beginDraw();\r\n pg.background(0);\r\n pg.fill(255);\r\n pg.ellipse(pg.width/2, pg.height/2, pg.width, pg.height);\r\n pg.endDraw();\r\n \r\n pg.loadPixels(); // safeguard for removing/commenting the loadPixels in the sampleColour function below\r\n\r\n int numX = 20;\r\n int numY = 20;\r\n\r\n for(int i = 0; i \u003c numX; i++)\r\n for(int j = 0; j \u003c numY; j++)\r\n {\r\n float normX = (i+0.5f)/float(numX);\r\n float normY = (j+0.5f)/float(numY);\r\n color c = sampleColour(pg, normX, normY);\r\n \r\n fill(c);\r\n rectMode(CENTER);\r\n rect(normX*width, normY*height, width/numX, height/numY);\r\n }\r\n}\r\n\r\ncolor sampleColour(PImage img, float normX, float normY)\r\n{\r\n img.loadPixels(); // with this uncommented, this function wrecks the sketch in P2D - but not in the standard renderer\r\n return img.pixels[int(normY * img.height) * img.width + int(normX * img.width)];\r\n}\r\n```\r\n\r\n## Your Environment\r\n* Processing version: Both 3.5.4 and 4.0b1\r\n* Operating System and OS version: macOS Big Sur 11.4 (20F71)\r\n* Other information:\r\n","author":{"url":"https://github.com/rapatski","@type":"Person","name":"rapatski"},"datePublished":"2021-08-26T12:36:06.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/6214/processing/issues/6214"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:260e5c0c-fb25-0bde-09d5-030bd49dea7d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E010:287A4D:4E8668:6CCBB1:696FE185 |
| html-safe-nonce | 87e97480aa5c15477fde59968649128fe55fee4ed849f8d4a459635cf505a6be |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDEwOjI4N0E0RDo0RTg2Njg6NkNDQkIxOjY5NkZFMTg1IiwidmlzaXRvcl9pZCI6IjU3MDQ1NjAzOTAxOTY2ODMxNDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | da4ea4cf40188339de71519388232bb2f57539e6dc37af00ba73333e19dff2fa |
| hovercard-subject-tag | issue:980195445 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/processing/processing/6214/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d9f858f00a25079eb38c3bdce9471d35710ee8d3b02db311a4852e3e2605c50a/processing/processing/issues/6214 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d9f858f00a25079eb38c3bdce9471d35710ee8d3b02db311a4852e3e2605c50a/processing/processing/issues/6214 |
| og:image:alt | Description Whenever loadPixels() is used on a PGraphics object in a P2D context, it seems to literally download the texture every time, regardless of whether it's been called/downloaded before. In... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rapatski |
| hostname | github.com |
| expected-hostname | github.com |
| None | a5d30ba41f7d9acded2fd135aa830ac2f5c7e52dca0e776e658d37eaf9dfb033 |
| turbo-cache-control | no-preview |
| go-import | github.com/processing/processing git https://github.com/processing/processing.git |
| octolytics-dimension-user_id | 1617169 |
| octolytics-dimension-user_login | processing |
| octolytics-dimension-repository_id | 7807399 |
| octolytics-dimension-repository_nwo | processing/processing |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7807399 |
| octolytics-dimension-repository_network_root_nwo | processing/processing |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2f945b7bb88421600e89dfefbb1548ad0a44781a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width