From 5625b63202797c54ff1f5a40d9ee664ca23cfce8 Mon Sep 17 00:00:00 2001 From: Stephen White Date: Thu, 14 Mar 2019 15:05:53 +0000 Subject: [PATCH] Fix glTexStorage2D errors. If a GL texture is externally-managed, don't make any GL calls during the Texture constructor. Bug: dawn:114 Change-Id: I8ece5cde433fb036f37bda7d18ddb81d9b50a89d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/5640 Commit-Queue: Stephen White Reviewed-by: Kai Ninomiya --- src/dawn_native/opengl/TextureGL.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/dawn_native/opengl/TextureGL.cpp b/src/dawn_native/opengl/TextureGL.cpp index 8d36bd2f43..bf9bac60cc 100644 --- a/src/dawn_native/opengl/TextureGL.cpp +++ b/src/dawn_native/opengl/TextureGL.cpp @@ -89,12 +89,6 @@ namespace dawn_native { namespace opengl { Texture::Texture(Device* device, const TextureDescriptor* descriptor) : Texture(device, descriptor, GenTexture()) { - } - - Texture::Texture(Device* device, const TextureDescriptor* descriptor, GLuint handle) - : TextureBase(device, descriptor), mHandle(handle) { - mTarget = TargetForDimensionAndArrayLayers(GetDimension(), GetArrayLayers()); - uint32_t width = GetSize().width; uint32_t height = GetSize().height; uint32_t levels = GetNumMipLevels(); @@ -102,7 +96,7 @@ namespace dawn_native { namespace opengl { auto formatInfo = GetGLFormatInfo(GetFormat()); - glBindTexture(mTarget, handle); + glBindTexture(mTarget, mHandle); // glTextureView() requires the value of GL_TEXTURE_IMMUTABLE_FORMAT for origtexture to be // GL_TRUE, so the storage of the texture must be allocated with glTexStorage*D. @@ -125,6 +119,11 @@ namespace dawn_native { namespace opengl { glTexParameteri(mTarget, GL_TEXTURE_MAX_LEVEL, levels - 1); } + Texture::Texture(Device* device, const TextureDescriptor* descriptor, GLuint handle) + : TextureBase(device, descriptor), mHandle(handle) { + mTarget = TargetForDimensionAndArrayLayers(GetDimension(), GetArrayLayers()); + } + Texture::~Texture() { // TODO(kainino@chromium.org): delete texture (but only when not using the native texture // constructor?)