webgl webcam test driver
doesn't work on firefox, see https://bugzilla.mozilla.org/show_bug.cgi?id=917314
This commit is contained in:
parent
22ebf14787
commit
2fdfcc94d3
|
@ -59,7 +59,7 @@ libretro = libretro_emscripten.bc
|
||||||
|
|
||||||
LIBS = -lm
|
LIBS = -lm
|
||||||
DEFINES = -DHAVE_SCREENSHOTS -DHAVE_NULLAUDIO -DHAVE_BSV_MOVIE
|
DEFINES = -DHAVE_SCREENSHOTS -DHAVE_NULLAUDIO -DHAVE_BSV_MOVIE
|
||||||
LDFLAGS = -L. -s TOTAL_MEMORY=$(MEMORY) --js-library emscripten/library_rwebaudio.js --js-library emscripten/library_rwebinput.js
|
LDFLAGS = -L. -s TOTAL_MEMORY=$(MEMORY) --js-library emscripten/library_rwebaudio.js --js-library emscripten/library_rwebinput.js --js-library emscripten/library_rwebcam.js
|
||||||
|
|
||||||
ifeq ($(PERF_TEST), 1)
|
ifeq ($(PERF_TEST), 1)
|
||||||
DEFINES += -DPERF_TEST
|
DEFINES += -DPERF_TEST
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
//"use strict";
|
||||||
|
|
||||||
|
var LibraryRWebCam = {
|
||||||
|
$RWC: {
|
||||||
|
/*
|
||||||
|
run modes:
|
||||||
|
0: not running
|
||||||
|
1: waiting for user to confirm webcam
|
||||||
|
2: running
|
||||||
|
*/
|
||||||
|
runMode: 0,
|
||||||
|
videoElement: null
|
||||||
|
},
|
||||||
|
|
||||||
|
RWebCamInit: function() {
|
||||||
|
RWC.runMode = 0;
|
||||||
|
|
||||||
|
if (!navigator) return 0;
|
||||||
|
|
||||||
|
navigator.getMedia = navigator.getUserMedia ||
|
||||||
|
navigator.webkitGetUserMedia ||
|
||||||
|
navigator.mozGetUserMedia ||
|
||||||
|
navigator.msGetUserMedia;
|
||||||
|
|
||||||
|
if (!navigator.getMedia) return 0;
|
||||||
|
|
||||||
|
RWC.videoElement = document.createElement("video");
|
||||||
|
|
||||||
|
RWC.runMode = 1;
|
||||||
|
|
||||||
|
navigator.getMedia({video: true, audio: false}, function(stream) {
|
||||||
|
RWC.videoElement.autoplay = true;
|
||||||
|
RWC.videoElement.src = URL.createObjectURL(stream);
|
||||||
|
RWC.runMode = 2;
|
||||||
|
}, function (err) {
|
||||||
|
console.log("webcam request failed", err);
|
||||||
|
RWC.runMode = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
},
|
||||||
|
|
||||||
|
RWebCamTexImage2D: function(width, height) {
|
||||||
|
if (RWC.runMode != 2 || RWC.videoElement.paused) return 0;
|
||||||
|
|
||||||
|
Module.ctx.texImage2D(Module.ctx.TEXTURE_2D, 0, Module.ctx.RGB, Module.ctx.RGB, Module.ctx.UNSIGNED_BYTE, RWC.videoElement);
|
||||||
|
|
||||||
|
if (width) {{{ makeSetValue('width', '0', 'RWC.videoElement.videoWidth', 'i32') }}};
|
||||||
|
if (height) {{{ makeSetValue('height', '0', 'RWC.videoElement.videoHeight', 'i32') }}};
|
||||||
|
},
|
||||||
|
|
||||||
|
RWebCamTexSubImage2D: function(x, y) {
|
||||||
|
if (RWC.runMode != 2 || RWC.videoElement.paused) return 0;
|
||||||
|
|
||||||
|
Module.ctx.texSubImage2D(Module.ctx.TEXTURE_2D, 0, x, y, Module.ctx.RGB, Module.ctx.UNSIGNED_BYTE, RWC.videoElement);
|
||||||
|
},
|
||||||
|
|
||||||
|
RWebCamReady: function() {
|
||||||
|
return RWC.runMode == 2 ? 1 : 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
RWebCamFree: function() {
|
||||||
|
RWC.videoElement.pause();
|
||||||
|
RWC.videoElement = null;
|
||||||
|
RWC.runMode = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
autoAddDeps(LibraryRWebCam, '$RWC');
|
||||||
|
mergeInto(LibraryManager.library, LibraryRWebCam);
|
Loading…
Reference in New Issue