summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/wasm/qwasmopenglcontext.cpp
Commit message (Collapse)AuthorAgeFilesLines
* wasm: Document and test OpenGLContext limitationsEven Oscar Andersen2024-03-221-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is a limit in WebGL that OpenGL context sharing is not supported. There is a proposal from 2013 (https://www.khronos.org/webgl/wiki/SharedResouces), but it seems that it never was implemented. There is an additional limit in that there is exactly one WebGL context for each canvas (i.e. window). A part of the problem here is that the identifier for an OpenGL context is essentially a surface-thread-context triplet. And the thread part might be more difficult to handle in a javascript setting. Regardless of why, we need to have an opinion about what the consequences are, and what we support to what extent. As such this commit: 1) Adds a comment on the QOpenGLContext describing the limitations 2) Adds a qWarning() on the first activation of a shared context. The second item is not complete. We will have problems with multiple individual contexts also, It is just not possible to warn for these cases. The second item covers, maybe, the most common case. Change-Id: I51550a6acb0a7f6f6fa5e9e2c3da080a1d2b498f Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: Lift restriction on offscreen for fake context sharingEven Oscar Andersen2024-03-161-21/+16
| | | | | | | | | | We only activated our fake context sharing logic for offscreen surfaces. This commit removed that restriction this allows the rendercontrol example to run Fixes: QTBUG-117410 Change-Id: Id86617f57c6a98a920f5dd82332dcd8277f103e4 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: make opengles3 (webgl2) default surface formatLorn Potter2024-02-211-16/+33
| | | | | | | | | | | All major browsers support webgl2 out of the box. [ChangeLog][WebAssmebly] Default OpenGL ES version raised to 3.0 Fixes: QTBUG-110686 Pick-to: 6.7 Change-Id: I875b55c2e0f6e955249f121d92214cf10ed416d7 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* Reuse the existing canvas context for offscreen surfacesMikolaj Boc2023-03-121-26/+48
| | | | | | | | | | | | | Due to the nature of WebGL contexts, which cannot be reassigned to targets other than they were created for, we will now reuse the created canvas context for offscreen surfaces, since those (hopefully) mostly operate on textures anyway. If this is not done, any switch to an offscreen surface for the main RHI context invalidates resources on contexts in a share group with it. Fixes: QTBUG-111617 Change-Id: I9752f7eec396a3ef11414881f5f79f26e1e2c859 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Quasi-support for offscreen surface on WASMMikolaj Boc2023-01-301-22/+33
| | | | | | | | | | | | | | | | | | Since context sharing is not currently supported with WebGL, offscreen contexts have a limited usability on Qt for WASM. If a context is shared, use the same underlaying WebGL context so that the two can actually share resources. This is not full-blown context sharing by any means but it makes e.g. the Open GL widget work as the readback texture for it is 'shared' between the virtual Qt contexts. If no sharing is desired, we use an OffscreenCanvas and actually create a separate WebGL context. Fixes: QTBUG-107558 Pick-to: 6.5 Change-Id: If57e44739ddb57c167d5f8881a74d8dee52531f6 Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
* Use the browser compositor for drawing windows on WASMMikolaj Boc2022-11-261-34/+29
| | | | | | | | | | | | | | | | Make the browser compositor draw the window non-client area (using css + html). Get rid of OpenGL usage in non-OpenGL windows and use canvas 2d context instead to blit the texture (QImage). Also, as part of the change, remove the deprecated canvas element support in QScreen. Fixes: QTBUG-107116 Fixes: QTBUG-107219 Change-Id: I65f0d91831c806315685ca681ac0e416673f5cd5 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io> Reviewed-by: David Skoland <david.skoland@qt.io>
* Fix the workaround in ~QWasmOpenGLContextMikolaj Boc2022-10-211-5/+17
| | | | | | | | | | | | | The workaround stopped working because JSEvents is now not a global object. Update the workaround by exporting the JSEvents object from emscripten runtime and replacing the function that removes the event handlers to a dummy function that does nothing temporarily, only to revert it when the context is destroyed. Fixes: QTBUG-107197 Pick-to: 6.4 Change-Id: Icceae884c85e04fdafcca6cf3c563094d3f6f0dc Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-28/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* wasm: use “specialHtmlTargets” for canvas lookupMorten Johan Sørvig2022-04-051-4/+3
| | | | | | | | | | | | | | | | | | We’d like to support use cases which require using multiple html documents, for example when displaying application content using more than one browser window. Normally Emscripten uses the primary html document when looking up elements by id, which means that targeting elements on secondary documents is not possible. Emscripten does provide a workaround: the application can create custom id mappings to any html element on the “specialHtmlTargets” object, and then use the “!id” syntax instead of normal “#id” lookup. Change-Id: I4dda920868cfbc6f8991425daf8933144c0ffad8 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: Add OpenGL version checkMorten Johan Sørvig2020-03-241-4/+15
| | | | | | | | | | | | | QtQuick3D probes for the supported OpenGL level by testing multiple OpenGL versions in descending order. Context creation must fail for versions not supported by WebGL. It does not appear that Emscripten does this for the 3.x minor versions, at least. Add version check which allows OpenGL (ES) 3.0 and 2.0. Change-Id: Ide8745dd79e69af86812a8d6f5d6cc16ecdd099a Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: fix emsdk 1.39.9 buildLorn Potter2020-03-121-1/+1
| | | | | | | | | Change depreciated and removed preferLowPowerToHighPerformance to the new powerPreference Fixes: QTBUG-82730 Change-Id: I53e4e39626fce75897701b0134adadf00dac2dea Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: Specify event targets by CSS selectors; Support emsdk >= 1.39.5Morten Johan Sørvig2020-02-051-1/+2
| | | | | | | | | | | | | | | | DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR is now on by default, which means that functions like emscripten_set_keydown_callback() now expects CSS selectors (e.g. "#canvas_id" instead of "canvas_id"). In addition, Module.canvas is no more. Add a deprecation warning in case someone is setting it and expects Qt to use it. (qtloader.js sets qtCanvasElements instead). This bumps the minimum supported emsdk version to 1.39.5. Fixes: QTBUG-74601 Change-Id: I8c46ce170143f969e6281824f78b1bb809c267ab Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: do not get canvas as property of js global objectAlexandra Cherdantseva2020-01-131-1/+1
| | | | | | | | | You cannot be sure that property with specified key in a global object is really a canvas. Should use `document.getElementById`. Change-Id: Ife55adaad5517aed64122b0c9bff32489cf19a2f Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* Prevent emscripten_webgl_destroy_context from removing event handlersMorten Johan Sørvig2019-12-031-0/+7
| | | | | | | | | | | | | | | | | | | | The JavaScript implementation of that function has the following code: if (typeof JSEvents === 'object') JSEvents.removeAllHandlersOnTarget(GL.contexts[contextHandle].GLctx.canvas); // Release all // JS event handlers on the DOM element that the GL context is associated with since the context // is now deleted. This breaks mouse/keyboard events, etc. Disable this logic by temporarily setting the JSEvents object to undefined, for the duration of the emscripten_webgl_destroy_context call. Fixes: QTBUG-74850 Change-Id: Ied3177b0ca6e63e8ea07143bf7d6a850b0bce35a Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* Merge remote-tracking branch 'origin/5.13.0' into 5.13Liang Qi2019-06-111-32/+27
|\ | | | | | | | | | | | | | | Conflicts: src/plugins/platforms/wasm/qwasmintegration.cpp src/plugins/platforms/wasm/qwasmintegration.h Change-Id: Idf4c7936513fb1f21daa8f6105b8545f13447bb8
| * wasm: rewrite/simplify OpenglContextMorten Johan Sørvig2019-05-141-32/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We don’t need the contextLost callback since we can poll for the “lost” status in isValid() Recreating the native context is not very helpful, since it destroys all current context state. Remove this logic. Support makeCurrent() on different surfaces, as long as they refer to the same screen. Create the native context (and record which screen) on the first call to makeCurrent() Task-number: QTBUG-75463 Change-Id: I6eb830df14578ffdbed5b0505fe860ce433e4f9b Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* | wasm: fix QSGContext warning messageLorn Potter2019-05-211-2/+14
|/ | | | | | | | | | | When runing the scenegraph example sgengine, gets rid if this error: QSGContext::initialize: stencil buffer support missing, expect rendering errors Change-Id: I7f3a82409bc2cf81cf8217876e527f9c45be3bf4 Fixes: QTBUG-74694 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* wasm: support rendering to multiple canvasesMorten Johan Sørvig2019-03-081-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Qt (via the the qtloader.js API) now supports rendering to multiple canvases. The application sees each canvas as a QScreen. Make qtloader.js support multiple canvases: var qtloader = QtLoader({ canvasElements : [array-of-canvas], showCanvas: function() { // make canvas(es) visible }, }); The canvases were previously created/returned by showCanvas(), however this function is called after the Qt app has been started and adding screens that that point is too late. (This worked before since there was only one screen, and no need to connect each screen instance to specific canvas.) Remove QWasmScreen, QWasmCompositor, and QWasmEventTranslator singletons from QWasmIntegration. These are are now crated per-screen and are owned by the QWasmScreen. Task-number: QTBUG-64079 Change-Id: I24689929fd5bfb7ff0ba076f66937728fa4bc4e4 Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
* wasm: make wasm platform target a specific canvas instead of defaultLorn Potter2019-03-081-5/+7
| | | | | | | | This allows for multi canvas use Task-number: QTBUG-64079 Change-Id: I69c998aa4c2869bb5b7f14ba65bb63284365ad70 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* WebAssembly for QtBaseMorten Johan Sørvig2018-08-301-0/+147
This is the squashed diff from wip/webassembly to dev. Done-with: Peng Wu <peng.wu@intopalo.com> Done-with: Sami Enne <sami.enne@intopalo.com> Done-with: Morten Johan Sørvig <morten.sorvig@qt.io> Started-by: Andrew Knight <andrew.knight@intopalo.com> Change-Id: I6562433c0a38d6ec49ab675e0f104f2665f3392d Reviewed-by: Lorn Potter <lorn.potter@gmail.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>