diff --git a/src/dawn_node/binding/CMakeLists.txt b/src/dawn_node/binding/CMakeLists.txt index f75ec08192..4287e13206 100644 --- a/src/dawn_node/binding/CMakeLists.txt +++ b/src/dawn_node/binding/CMakeLists.txt @@ -49,6 +49,7 @@ add_library(dawn_node_binding STATIC "GPUShaderModule.h" "GPUSupportedLimits.cpp" "GPUSupportedLimits.h" + "GPUTexture.cpp" "GPUTexture.h" "GPUTextureView.cpp" "GPUTextureView.h" diff --git a/src/dawn_node/binding/GPUTexture.cpp b/src/dawn_node/binding/GPUTexture.cpp new file mode 100644 index 0000000000..2ebb7850b6 --- /dev/null +++ b/src/dawn_node/binding/GPUTexture.cpp @@ -0,0 +1,68 @@ +// Copyright 2021 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/dawn_node/binding/GPUTexture.h" + +#include "src/dawn_node/binding/Converter.h" +#include "src/dawn_node/binding/Errors.h" +#include "src/dawn_node/binding/GPUTextureView.h" +#include "src/dawn_node/utils/Debug.h" + +namespace wgpu { namespace binding { + + //////////////////////////////////////////////////////////////////////////////// + // wgpu::bindings::GPUTexture + //////////////////////////////////////////////////////////////////////////////// + GPUTexture::GPUTexture(wgpu::Texture texture) : texture_(std::move(texture)) { + } + + interop::Interface GPUTexture::createView( + Napi::Env env, + std::optional descriptor) { + if (!texture_) { + Errors::OperationError(env).ThrowAsJavaScriptException(); + return {}; + } + + if (descriptor.has_value()) { + wgpu::TextureViewDescriptor desc{}; + Converter conv(env); + if (!conv(desc.baseMipLevel, descriptor->baseMipLevel) || + !conv(desc.mipLevelCount, descriptor->mipLevelCount) || + !conv(desc.baseArrayLayer, descriptor->baseArrayLayer) || + !conv(desc.arrayLayerCount, descriptor->arrayLayerCount) || + !conv(desc.format, descriptor->format) || + !conv(desc.dimension, descriptor->dimension) || + !conv(desc.aspect, descriptor->aspect)) { + return {}; + } + return interop::GPUTextureView::Create(env, texture_.CreateView(&desc)); + } + + return interop::GPUTextureView::Create(env, texture_.CreateView()); + } + + void GPUTexture::destroy(Napi::Env) { + texture_.Destroy(); + } + + std::optional GPUTexture::getLabel(Napi::Env) { + UNIMPLEMENTED(); + } + + void GPUTexture::setLabel(Napi::Env, std::optional value) { + UNIMPLEMENTED(); + } + +}} // namespace wgpu::binding