Commit f05ba610 authored by Brandon Jones's avatar Brandon Jones Committed by Commit Bot

Let XRWebGLBinding.getReflectionCubeMap() restore the cube map binding

Bug: 1079007
Change-Id: If8e0addde48f51d5b02b79cb268740a752f98b9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2204549Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Commit-Queue: Brandon Jones <bajones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#769912}
parent a2775326
...@@ -6814,6 +6814,15 @@ void WebGLRenderingContextBase::DrawingBufferClientRestoreTexture2DBinding() { ...@@ -6814,6 +6814,15 @@ void WebGLRenderingContextBase::DrawingBufferClientRestoreTexture2DBinding() {
RestoreCurrentTexture2D(); RestoreCurrentTexture2D();
} }
void WebGLRenderingContextBase::
DrawingBufferClientRestoreTextureCubeMapBinding() {
if (destruction_in_progress_)
return;
if (!ContextGL())
return;
RestoreCurrentTextureCubeMap();
}
void WebGLRenderingContextBase:: void WebGLRenderingContextBase::
DrawingBufferClientRestoreRenderbufferBinding() { DrawingBufferClientRestoreRenderbufferBinding() {
if (destruction_in_progress_) if (destruction_in_progress_)
...@@ -8238,6 +8247,12 @@ void WebGLRenderingContextBase::RestoreCurrentTexture2D() { ...@@ -8238,6 +8247,12 @@ void WebGLRenderingContextBase::RestoreCurrentTexture2D() {
texture_units_[active_texture_unit_].texture2d_binding_.Get()); texture_units_[active_texture_unit_].texture2d_binding_.Get());
} }
void WebGLRenderingContextBase::RestoreCurrentTextureCubeMap() {
bindTexture(
GL_TEXTURE_CUBE_MAP,
texture_units_[active_texture_unit_].texture_cube_map_binding_.Get());
}
void WebGLRenderingContextBase::FindNewMaxNonDefaultTextureUnit() { void WebGLRenderingContextBase::FindNewMaxNonDefaultTextureUnit() {
// Trace backwards from the current max to find the new max non-default // Trace backwards from the current max to find the new max non-default
// texture unit // texture unit
......
...@@ -681,6 +681,7 @@ class MODULES_EXPORT WebGLRenderingContextBase : public CanvasRenderingContext, ...@@ -681,6 +681,7 @@ class MODULES_EXPORT WebGLRenderingContextBase : public CanvasRenderingContext,
void DrawingBufferClientRestoreMaskAndClearValues() override; void DrawingBufferClientRestoreMaskAndClearValues() override;
void DrawingBufferClientRestorePixelPackParameters() override; void DrawingBufferClientRestorePixelPackParameters() override;
void DrawingBufferClientRestoreTexture2DBinding() override; void DrawingBufferClientRestoreTexture2DBinding() override;
void DrawingBufferClientRestoreTextureCubeMapBinding() override;
void DrawingBufferClientRestoreRenderbufferBinding() override; void DrawingBufferClientRestoreRenderbufferBinding() override;
void DrawingBufferClientRestoreFramebufferBinding() override; void DrawingBufferClientRestoreFramebufferBinding() override;
void DrawingBufferClientRestorePixelUnpackBufferBinding() override; void DrawingBufferClientRestorePixelUnpackBufferBinding() override;
...@@ -1593,6 +1594,7 @@ class MODULES_EXPORT WebGLRenderingContextBase : public CanvasRenderingContext, ...@@ -1593,6 +1594,7 @@ class MODULES_EXPORT WebGLRenderingContextBase : public CanvasRenderingContext,
virtual void RestoreCurrentFramebuffer(); virtual void RestoreCurrentFramebuffer();
void RestoreCurrentTexture2D(); void RestoreCurrentTexture2D();
void RestoreCurrentTextureCubeMap();
void FindNewMaxNonDefaultTextureUnit(); void FindNewMaxNonDefaultTextureUnit();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "third_party/blink/renderer/modules/webgl/webgl_texture.h" #include "third_party/blink/renderer/modules/webgl/webgl_texture.h"
#include "third_party/blink/renderer/modules/xr/xr_cube_map.h" #include "third_party/blink/renderer/modules/xr/xr_cube_map.h"
#include "third_party/blink/renderer/platform/bindings/exception_code.h" #include "third_party/blink/renderer/platform/bindings/exception_code.h"
#include "third_party/blink/renderer/platform/graphics/gpu/drawing_buffer.h"
namespace { namespace {
bool IsPowerOfTwo(uint32_t value) { bool IsPowerOfTwo(uint32_t value) {
...@@ -84,7 +85,9 @@ WebGLTexture* XRCubeMap::updateWebGLEnvironmentCube( ...@@ -84,7 +85,9 @@ WebGLTexture* XRCubeMap::updateWebGLEnvironmentCube(
} }
// TODO(https://crbug.com/1079007): Restore the texture binding // TODO(https://crbug.com/1079007): Restore the texture binding
gl->BindTexture(GL_TEXTURE_CUBE_MAP, 0); // gl->BindTexture(GL_TEXTURE_CUBE_MAP, 0);
DrawingBuffer::Client* client = static_cast<DrawingBuffer::Client*>(context);
client->DrawingBufferClientRestoreTextureCubeMapBinding();
// Debug check for success // Debug check for success
DCHECK(gl->GetError() == GL_NO_ERROR); DCHECK(gl->GetError() == GL_NO_ERROR);
......
...@@ -1382,6 +1382,7 @@ void DrawingBuffer::RestoreAllState() { ...@@ -1382,6 +1382,7 @@ void DrawingBuffer::RestoreAllState() {
client_->DrawingBufferClientRestoreMaskAndClearValues(); client_->DrawingBufferClientRestoreMaskAndClearValues();
client_->DrawingBufferClientRestorePixelPackParameters(); client_->DrawingBufferClientRestorePixelPackParameters();
client_->DrawingBufferClientRestoreTexture2DBinding(); client_->DrawingBufferClientRestoreTexture2DBinding();
client_->DrawingBufferClientRestoreTextureCubeMapBinding();
client_->DrawingBufferClientRestoreRenderbufferBinding(); client_->DrawingBufferClientRestoreRenderbufferBinding();
client_->DrawingBufferClientRestoreFramebufferBinding(); client_->DrawingBufferClientRestoreFramebufferBinding();
client_->DrawingBufferClientRestorePixelUnpackBufferBinding(); client_->DrawingBufferClientRestorePixelUnpackBufferBinding();
......
...@@ -98,6 +98,8 @@ class PLATFORM_EXPORT DrawingBuffer : public cc::TextureLayerClient, ...@@ -98,6 +98,8 @@ class PLATFORM_EXPORT DrawingBuffer : public cc::TextureLayerClient,
virtual void DrawingBufferClientRestorePixelPackParameters() = 0; virtual void DrawingBufferClientRestorePixelPackParameters() = 0;
// Restores the GL_TEXTURE_2D binding for the active texture unit only. // Restores the GL_TEXTURE_2D binding for the active texture unit only.
virtual void DrawingBufferClientRestoreTexture2DBinding() = 0; virtual void DrawingBufferClientRestoreTexture2DBinding() = 0;
// Restores the GL_TEXTURE_CUBE_MAP binding for the active texture unit.
virtual void DrawingBufferClientRestoreTextureCubeMapBinding() = 0;
virtual void DrawingBufferClientRestoreRenderbufferBinding() = 0; virtual void DrawingBufferClientRestoreRenderbufferBinding() = 0;
virtual void DrawingBufferClientRestoreFramebufferBinding() = 0; virtual void DrawingBufferClientRestoreFramebufferBinding() = 0;
virtual void DrawingBufferClientRestorePixelUnpackBufferBinding() = 0; virtual void DrawingBufferClientRestorePixelUnpackBufferBinding() = 0;
......
...@@ -92,6 +92,8 @@ class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub, ...@@ -92,6 +92,8 @@ class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub,
void BindTexture(GLenum target, GLuint texture) override { void BindTexture(GLenum target, GLuint texture) override {
if (target == GL_TEXTURE_2D) if (target == GL_TEXTURE_2D)
state_.active_texture2d_binding = texture; state_.active_texture2d_binding = texture;
if (target == GL_TEXTURE_CUBE_MAP)
state_.active_texturecubemap_binding = texture;
bound_textures_.insert(target, texture); bound_textures_.insert(target, texture);
} }
...@@ -318,6 +320,10 @@ class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub, ...@@ -318,6 +320,10 @@ class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub,
void DrawingBufferClientRestoreTexture2DBinding() override { void DrawingBufferClientRestoreTexture2DBinding() override {
state_.active_texture2d_binding = saved_state_.active_texture2d_binding; state_.active_texture2d_binding = saved_state_.active_texture2d_binding;
} }
void DrawingBufferClientRestoreTextureCubeMapBinding() override {
state_.active_texturecubemap_binding =
saved_state_.active_texturecubemap_binding;
}
void DrawingBufferClientRestoreRenderbufferBinding() override { void DrawingBufferClientRestoreRenderbufferBinding() override {
state_.renderbuffer_binding = saved_state_.renderbuffer_binding; state_.renderbuffer_binding = saved_state_.renderbuffer_binding;
} }
...@@ -367,6 +373,8 @@ class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub, ...@@ -367,6 +373,8 @@ class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub,
EXPECT_EQ(state_.pack_alignment, saved_state_.pack_alignment); EXPECT_EQ(state_.pack_alignment, saved_state_.pack_alignment);
EXPECT_EQ(state_.active_texture2d_binding, EXPECT_EQ(state_.active_texture2d_binding,
saved_state_.active_texture2d_binding); saved_state_.active_texture2d_binding);
EXPECT_EQ(state_.active_texturecubemap_binding,
saved_state_.active_texturecubemap_binding);
EXPECT_EQ(state_.renderbuffer_binding, saved_state_.renderbuffer_binding); EXPECT_EQ(state_.renderbuffer_binding, saved_state_.renderbuffer_binding);
EXPECT_EQ(state_.draw_framebuffer_binding, EXPECT_EQ(state_.draw_framebuffer_binding,
saved_state_.draw_framebuffer_binding); saved_state_.draw_framebuffer_binding);
...@@ -408,6 +416,8 @@ class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub, ...@@ -408,6 +416,8 @@ class GLES2InterfaceForTests : public gpu::gles2::GLES2InterfaceStub,
// The bound 2D texture for the active texture unit. // The bound 2D texture for the active texture unit.
GLuint active_texture2d_binding = 0; GLuint active_texture2d_binding = 0;
// The bound cube map texture for the active texture unit.
GLuint active_texturecubemap_binding = 0;
GLuint renderbuffer_binding = 0; GLuint renderbuffer_binding = 0;
GLuint draw_framebuffer_binding = 0; GLuint draw_framebuffer_binding = 0;
GLuint read_framebuffer_binding = 0; GLuint read_framebuffer_binding = 0;
......
...@@ -35,6 +35,44 @@ function verifyXRLightEstimate(lightEstimate) { ...@@ -35,6 +35,44 @@ function verifyXRLightEstimate(lightEstimate) {
assert_equals(lightEstimate.primaryLightIntensity.w, 1); assert_equals(lightEstimate.primaryLightIntensity.w, 1);
} }
// Verifies the behavior of querying reflection cube maps
// Defined in 'third_party/blink/renderer/modules/xr/xr_webgl_binding.idl'
function verifyReflectionCubeMap(session, lightProbe) {
// Currently reflection cube maps only work on WebGL 2.
const gl2Canvas = document.createElement('canvas');
const gl = gl2Canvas.getContext('webgl2', { xrCompatible: true });
if (!gl) {
return;
}
const glBinding = new XRWebGLBinding(session, gl);
assert_true(glBinding instanceof XRWebGLBinding);
assert_defined(glBinding.getReflectionCubeMap, "getReflectionCubeMap was not defined on XRWebGLBinding");
// Bind a different cube map prior to fetching the reflection cube map so we
// can ensure the binding is preserved.
const tmpCubeMap = gl.createTexture();
gl.bindTexture(gl.TEXTURE_CUBE_MAP, tmpCubeMap);
// Make sure we get back a valid cube map
const cubeMap = glBinding.getReflectionCubeMap(lightProbe);
assert_true(cubeMap instanceof WebGLTexture);
const boundCubeMap = gl.getParameter(gl.TEXTURE_BINDING_CUBE_MAP);
assert_equals(boundCubeMap, tmpCubeMap);
// Ensure that we can't bind the returned cube map to the TEXTURE_2D bind
// target but can bind it to the TEXTURE_CUBE_MAP bind point. This effectively
// tests that the texture was created as a cube map.
gl.bindTexture(gl.TEXTURE_2D, cubeMap);
assert_equals(gl.getError(), gl.INVALID_OPERATION);
gl.bindTexture(gl.TEXTURE_CUBE_MAP, cubeMap);
assert_equals(gl.getError(), gl.NO_ERROR);
}
// Verifies the structure of |XRFrame| (as it relates to light estimation) // Verifies the structure of |XRFrame| (as it relates to light estimation)
// for a session that's expected to suppot light estimation. // for a session that's expected to suppot light estimation.
// Defined in 'third_party/blink/renderer/modules/xr/xr_frame.idl' // Defined in 'third_party/blink/renderer/modules/xr/xr_frame.idl'
...@@ -51,6 +89,7 @@ function verifyXRLightEstimateExists(t, resolve, count, session, frame, lightPro ...@@ -51,6 +89,7 @@ function verifyXRLightEstimateExists(t, resolve, count, session, frame, lightPro
}); });
} else { } else {
verifyXRLightEstimate(lightEstimate); verifyXRLightEstimate(lightEstimate);
verifyReflectionCubeMap(session, lightProbe);
resolve(); resolve();
} }
}); });
...@@ -63,7 +102,7 @@ function verifyXRLightProbe(lightProbe) { ...@@ -63,7 +102,7 @@ function verifyXRLightProbe(lightProbe) {
} }
const lightingInformationExistsName = "Ensures lighting estimation feature works when enabled"; const lightingInformationExistsName = "Ensures lighting estimation feature works when enabled";
function lightingInformationExists(session, fakeDeviceController, t) { function lightingInformationExists(session, fakeDeviceController, t, sessionObjects) {
t.step(() => { t.step(() => {
assert_defined(session.requestLightProbe, "requestLightProbe was not defined on XRSession"); assert_defined(session.requestLightProbe, "requestLightProbe was not defined on XRSession");
}); });
...@@ -80,7 +119,7 @@ function lightingInformationExists(session, fakeDeviceController, t) { ...@@ -80,7 +119,7 @@ function lightingInformationExists(session, fakeDeviceController, t) {
} }
const lightingInformationDoesNotExistName = "Ensure lighting estimation feature does not work when not explicitly enabled"; const lightingInformationDoesNotExistName = "Ensure lighting estimation feature does not work when not explicitly enabled";
function lightingInformationDoesNotExist(session, fakeDeviceController, t) { function lightingInformationDoesNotExist(session, fakeDeviceController, t, sessionObjects) {
t.step(() => { t.step(() => {
assert_defined(session.requestLightProbe, "requestLightProbe was not defined on XRSession"); assert_defined(session.requestLightProbe, "requestLightProbe was not defined on XRSession");
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment