question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebGL-renderer: implement preRender and postRender

See original GitHub issue

Description

Currently, Heatmaps don’t fire prerender or postrender events. This is because a.t.m. only CanvasLayerRenderer implements the preRender and postRender methods.

Here’s a minimum working example: note how only the OSM’s render-events are being logged:

const layers = [
    new TileLayer({
        source: new OSM(),
    }),
    new Heatmap({
        source: new VectorSource({
            features: new GeoJSON().readFeatures({
                "type": "FeatureCollection",
                "features": [{
                    "type": "Feature",
                    "properties": {},
                    "geometry": {
                      "type": "Point",
                      "coordinates": [13.38134765625, 52.50953477032727]
                    }
                }]
              })
        })
    })
];

const view = new View({
    center: [15, 52],
    zoom: 7,
    projection: 'EPSG:4326'
});


const map = new Map({
    layers, view, target
});


for (const layer of layers) {
    layer.on('postrender', (event) => {
        console.log(event);
    });
}

Solution

I believe we can literally just copy-paste the source code of CanvasLayerRenderer’s preRender and postRender methods into WebGLLayerRenderer. We’d then only have to call preRender and postRender from WebGLPointsLayerRenderer inside of renderFrame.

Would this be appropriate? It is my understanding that WebGl-support is still somewhat experimental (is that still true?). But if this is something we’d like to see, I’d like to try myself on a pull-request over the weekend.

Keep up the great work and thanks a lot! 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
MichaelLangbeincommented, Aug 31, 2020

Hi! Alright, thanks a lot @ahocevar and @jahow for all the help! And thanks also for the PR. Given that the build issue described above doesn’t occur anymore, either, I have run out of things to complain about and guess we could close this issue 😃

1reaction
jahowcommented, Aug 25, 2020

I think we might as well not provide any context at all in the event. Having a webgl context isn’t as useful as a canvas2d one, since the application code won’t be able to do much with it anyway (without an immediate rendering API like in canvas2d).

Then using something like this should work for building the inverse transform: https://github.com/openlayers/openlayers/blob/f3a67e818289282ac71b6d13df96434dd44ace61/src/ol/renderer/canvas/TileLayer.js#L272-L289

Although I’m not sure that would be even useful considering there will be no drawing context provided anyway. @ahocevar what’s your opinion on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inside PixiJS: WebGL Renderer. What's hidden in this gem?
PixiJS has the concept of a “system-wide” renderer that fires every frame and makes the root display-object render itself.
Read more >
How to use post-processing
After all files are successfully imported, we can create our composer by passing in an instance of WebGLRenderer. const composer = new EffectComposer(...
Read more >
PIXI.WebGLRenderer
The WebGLRenderer draws the scene and all its content onto a webGL enabled canvas. This renderer should be used for browsers that support...
Read more >
Phaser 3 API Documentation - Class: WebGLRenderer
An array of blend modes supported by the WebGL Renderer. ... Stores the current WebGL component formats for further use. ... The Camera...
Read more >
Add a render pipeline to WebGLRenderer #6464
But if you wanted to do it at end of frame post render you'd do: ... whether a modular rendering system should use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found