Merge pull request #55869 from dsnopek/webxr-internal-textures-3.x
This commit is contained in:
commit
8098d16644
|
@ -65,8 +65,7 @@ extern int godot_webxr_get_view_count();
|
||||||
extern int *godot_webxr_get_render_targetsize();
|
extern int *godot_webxr_get_render_targetsize();
|
||||||
extern float *godot_webxr_get_transform_for_eye(int p_eye);
|
extern float *godot_webxr_get_transform_for_eye(int p_eye);
|
||||||
extern float *godot_webxr_get_projection_for_eye(int p_eye);
|
extern float *godot_webxr_get_projection_for_eye(int p_eye);
|
||||||
extern int godot_webxr_get_external_texture_for_eye(int p_eye);
|
extern void godot_webxr_commit_for_eye(int p_eye, unsigned int p_texture_id);
|
||||||
extern void godot_webxr_commit_for_eye(int p_eye);
|
|
||||||
|
|
||||||
extern void godot_webxr_sample_controller_data();
|
extern void godot_webxr_sample_controller_data();
|
||||||
extern int godot_webxr_get_controller_count();
|
extern int godot_webxr_get_controller_count();
|
||||||
|
|
|
@ -33,9 +33,6 @@ const GodotWebXR = {
|
||||||
$GodotWebXR: {
|
$GodotWebXR: {
|
||||||
gl: null,
|
gl: null,
|
||||||
|
|
||||||
texture_ids: [null, null],
|
|
||||||
textures: [null, null],
|
|
||||||
|
|
||||||
session: null,
|
session: null,
|
||||||
space: null,
|
space: null,
|
||||||
frame: null,
|
frame: null,
|
||||||
|
@ -371,22 +368,6 @@ const GodotWebXR = {
|
||||||
.catch((e) => { });
|
.catch((e) => { });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean-up the textures we allocated for each view.
|
|
||||||
const gl = GodotWebXR.gl;
|
|
||||||
for (let i = 0; i < GodotWebXR.textures.length; i++) {
|
|
||||||
const texture = GodotWebXR.textures[i];
|
|
||||||
if (texture !== null) {
|
|
||||||
gl.deleteTexture(texture);
|
|
||||||
}
|
|
||||||
GodotWebXR.textures[i] = null;
|
|
||||||
|
|
||||||
const texture_id = GodotWebXR.texture_ids[i];
|
|
||||||
if (texture_id !== null) {
|
|
||||||
GL.textures[texture_id] = null;
|
|
||||||
}
|
|
||||||
GodotWebXR.texture_ids[i] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
GodotWebXR.session = null;
|
GodotWebXR.session = null;
|
||||||
GodotWebXR.space = null;
|
GodotWebXR.space = null;
|
||||||
GodotWebXR.frame = null;
|
GodotWebXR.frame = null;
|
||||||
|
@ -461,50 +442,9 @@ const GodotWebXR = {
|
||||||
return buf;
|
return buf;
|
||||||
},
|
},
|
||||||
|
|
||||||
godot_webxr_get_external_texture_for_eye__proxy: 'sync',
|
|
||||||
godot_webxr_get_external_texture_for_eye__sig: 'ii',
|
|
||||||
godot_webxr_get_external_texture_for_eye: function (p_eye) {
|
|
||||||
if (!GodotWebXR.session) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const view_index = (p_eye === 2 /* ARVRInterface::EYE_RIGHT */) ? 1 : 0;
|
|
||||||
if (GodotWebXR.texture_ids[view_index]) {
|
|
||||||
return GodotWebXR.texture_ids[view_index];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check pose separately and after returning the cached texture id,
|
|
||||||
// because we won't get a pose in some cases if we lose tracking, and
|
|
||||||
// we don't want to return 0 just because tracking was lost.
|
|
||||||
if (!GodotWebXR.pose) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const glLayer = GodotWebXR.session.renderState.baseLayer;
|
|
||||||
const view = GodotWebXR.pose.views[view_index];
|
|
||||||
const viewport = glLayer.getViewport(view);
|
|
||||||
const gl = GodotWebXR.gl;
|
|
||||||
|
|
||||||
const texture = gl.createTexture();
|
|
||||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
||||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, viewport.width, viewport.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
|
||||||
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
||||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
||||||
|
|
||||||
const texture_id = GL.getNewId(GL.textures);
|
|
||||||
GL.textures[texture_id] = texture;
|
|
||||||
GodotWebXR.textures[view_index] = texture;
|
|
||||||
GodotWebXR.texture_ids[view_index] = texture_id;
|
|
||||||
return texture_id;
|
|
||||||
},
|
|
||||||
|
|
||||||
godot_webxr_commit_for_eye__proxy: 'sync',
|
godot_webxr_commit_for_eye__proxy: 'sync',
|
||||||
godot_webxr_commit_for_eye__sig: 'vi',
|
godot_webxr_commit_for_eye__sig: 'vii',
|
||||||
godot_webxr_commit_for_eye: function (p_eye) {
|
godot_webxr_commit_for_eye: function (p_eye, p_texture_id) {
|
||||||
if (!GodotWebXR.session || !GodotWebXR.pose) {
|
if (!GodotWebXR.session || !GodotWebXR.pose) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -522,7 +462,7 @@ const GodotWebXR = {
|
||||||
gl.bindFramebuffer(gl.FRAMEBUFFER, glLayer.framebuffer);
|
gl.bindFramebuffer(gl.FRAMEBUFFER, glLayer.framebuffer);
|
||||||
gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
|
gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
|
||||||
|
|
||||||
GodotWebXR.blitTexture(gl, GodotWebXR.textures[view_index]);
|
GodotWebXR.blitTexture(gl, GL.textures[p_texture_id]);
|
||||||
|
|
||||||
// Restore state.
|
// Restore state.
|
||||||
gl.bindFramebuffer(gl.FRAMEBUFFER, orig_framebuffer);
|
gl.bindFramebuffer(gl.FRAMEBUFFER, orig_framebuffer);
|
||||||
|
|
|
@ -349,18 +349,15 @@ CameraMatrix WebXRInterfaceJS::get_projection_for_eye(ARVRInterface::Eyes p_eye,
|
||||||
return eye;
|
return eye;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int WebXRInterfaceJS::get_external_texture_for_eye(ARVRInterface::Eyes p_eye) {
|
|
||||||
if (!initialized) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return godot_webxr_get_external_texture_for_eye(p_eye);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebXRInterfaceJS::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) {
|
void WebXRInterfaceJS::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
godot_webxr_commit_for_eye(p_eye);
|
|
||||||
|
RID texture = VSG::storage->render_target_get_texture(p_render_target);
|
||||||
|
uint32_t texture_id = VSG::storage->texture_get_texid(texture);
|
||||||
|
|
||||||
|
godot_webxr_commit_for_eye(p_eye, texture_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
void WebXRInterfaceJS::process() {
|
void WebXRInterfaceJS::process() {
|
||||||
|
|
|
@ -86,7 +86,6 @@ public:
|
||||||
virtual bool is_stereo();
|
virtual bool is_stereo();
|
||||||
virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform);
|
virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform);
|
||||||
virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far);
|
virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far);
|
||||||
virtual unsigned int get_external_texture_for_eye(ARVRInterface::Eyes p_eye);
|
|
||||||
virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect);
|
virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect);
|
||||||
|
|
||||||
virtual void process();
|
virtual void process();
|
||||||
|
|
Loading…
Reference in New Issue