Skip to content

Commit 6806d93

Browse files
authored
Merge pull request #252 from De-Panther/more_webcam_performance_teximage2d
Fixed webcam performance
2 parents e8fbfa8 + 659e875 commit 6806d93

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Packages/webxr-interactions/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Fixed
1010
- SceneHitTest right controller issue.
11+
- Webcam performance.
1112

1213
## [0.16.2] - 2023-02-04
1314
### Fixed

Packages/webxr-interactions/Runtime/Plugins/WebGL/FixWebCamWebGL.jslib

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ var LibraryFixWebCamWebGL = {
2626

2727
JS_WebCamVideo_SetLatestTextureId: function(textureId) {
2828
webcamLatestTextureId = textureId;
29+
// Webcam texture is created with texStorage2D so we have to recreate it
30+
GLctx.deleteTexture(GL.textures[textureId]);
31+
GL.textures[textureId] = GLctx.createTexture();
32+
GL.textures[textureId].name = textureId;
33+
GLctx.bindTexture(GLctx.TEXTURE_2D, GL.textures[textureId]);
34+
GLctx.texParameteri(GLctx.TEXTURE_2D, GLctx.TEXTURE_WRAP_S, GLctx.CLAMP_TO_EDGE);
35+
GLctx.texParameteri(GLctx.TEXTURE_2D, GLctx.TEXTURE_WRAP_T, GLctx.CLAMP_TO_EDGE);
36+
GLctx.texParameteri(GLctx.TEXTURE_2D, GLctx.TEXTURE_MIN_FILTER, GLctx.LINEAR);
2937
},
3038

3139
JS_WebCamVideo_RemoveWhereTextureId: function(textureId) {
@@ -67,7 +75,7 @@ var LibraryFixWebCamWebGL = {
6775
}
6876
GLctx.bindTexture(GLctx.TEXTURE_2D, GL.textures[webcamBufferToTextureTable[buffer]]);
6977
GLctx.pixelStorei(GLctx.UNPACK_FLIP_Y_WEBGL, true);
70-
GLctx.texSubImage2D(GLctx.TEXTURE_2D, 0, 0, 0, GLctx.RGBA, GLctx.UNSIGNED_BYTE, videoElement);
78+
GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, GLctx.UNSIGNED_BYTE, videoElement);
7179
GLctx.pixelStorei(GLctx.UNPACK_FLIP_Y_WEBGL, false);
7280
disableNextSubImage = true;
7381
return 1;

0 commit comments

Comments
 (0)