Skip to content
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

Add contextAttributes map option #5196

Merged
merged 7 commits into from
Dec 13, 2024
Merged

Conversation

ibesora
Copy link
Collaborator

@ibesora ibesora commented Dec 12, 2024

This PR fixes #5135 by adding a contextAttributes property to the map constructor that supports all WebGLContextAttributes, so now you can do something like:

const map = new maplibregl.Map({
  container: 'map',
  style: 'https://demotiles.maplibre.org/style.json',
  center: [0, 0],
  zoom: 2,
  contextAttributes: {
    powerPreference: 'default',
    antialias: true
});

Note that some WebGLContextAttributes can't be overwritten because Maplibre relies on it. These are alpha, depth, stencil and premultipliedAlpha which are always set to true.

This PR also sets the default WebGL powerPreference to high-performance instead of default, which defaults to using dedicated GPUs on multi-GPU systems.

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Post benchmark scores.
  • Add an entry to CHANGELOG.md under the ## main section.

@ibesora
Copy link
Collaborator Author

ibesora commented Dec 12, 2024

I'm working on enabling setting which WebGL version do you want to use but since that requires some changes on how shaders are compiled, I'm working on a branch on top of this to keep changes separated

@ibesora ibesora requested a review from HarelM December 12, 2024 15:17
Copy link

codecov bot commented Dec 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.82%. Comparing base (3a3ed23) to head (a886440).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5196   +/-   ##
=======================================
  Coverage   91.82%   91.82%           
=======================================
  Files         281      281           
  Lines       38776    38777    +1     
  Branches     6758     6758           
=======================================
+ Hits        35605    35606    +1     
  Misses       3044     3044           
  Partials      127      127           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

CHANGELOG.md Outdated Show resolved Hide resolved
src/ui/map.ts Show resolved Hide resolved
src/ui/map.ts Show resolved Hide resolved
src/ui/map.ts Outdated Show resolved Hide resolved
@HarelM
Copy link
Collaborator

HarelM commented Dec 12, 2024

I've added a few comments.
From my point of view this can be merged without the addition of "forcing" webgl2 as this PR has its merit.

@ibesora ibesora requested a review from HarelM December 12, 2024 19:21
@ibesora ibesora merged commit f1a70c0 into maplibre:main Dec 13, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add powerPreference support to MapLibre GL
2 participants