• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/dawn_node/binding/GPUTexture.h"
16 
17 #include "src/dawn_node/binding/Converter.h"
18 #include "src/dawn_node/binding/Errors.h"
19 #include "src/dawn_node/binding/GPUTextureView.h"
20 #include "src/dawn_node/utils/Debug.h"
21 
22 namespace wgpu { namespace binding {
23 
24     ////////////////////////////////////////////////////////////////////////////////
25     // wgpu::bindings::GPUTexture
26     ////////////////////////////////////////////////////////////////////////////////
GPUTexture(wgpu::Texture texture)27     GPUTexture::GPUTexture(wgpu::Texture texture) : texture_(std::move(texture)) {
28     }
29 
createView(Napi::Env env,interop::GPUTextureViewDescriptor descriptor)30     interop::Interface<interop::GPUTextureView> GPUTexture::createView(
31         Napi::Env env,
32         interop::GPUTextureViewDescriptor descriptor) {
33         if (!texture_) {
34             Errors::OperationError(env).ThrowAsJavaScriptException();
35             return {};
36         }
37 
38         wgpu::TextureViewDescriptor desc{};
39         Converter conv(env);
40         if (!conv(desc.baseMipLevel, descriptor.baseMipLevel) ||        //
41             !conv(desc.mipLevelCount, descriptor.mipLevelCount) ||      //
42             !conv(desc.baseArrayLayer, descriptor.baseArrayLayer) ||    //
43             !conv(desc.arrayLayerCount, descriptor.arrayLayerCount) ||  //
44             !conv(desc.format, descriptor.format) ||                    //
45             !conv(desc.dimension, descriptor.dimension) ||              //
46             !conv(desc.aspect, descriptor.aspect)) {
47             return {};
48         }
49         return interop::GPUTextureView::Create<GPUTextureView>(env, texture_.CreateView(&desc));
50     }
51 
destroy(Napi::Env)52     void GPUTexture::destroy(Napi::Env) {
53         texture_.Destroy();
54     }
55 
getLabel(Napi::Env)56     std::optional<std::string> GPUTexture::getLabel(Napi::Env) {
57         UNIMPLEMENTED();
58     }
59 
setLabel(Napi::Env,std::optional<std::string> value)60     void GPUTexture::setLabel(Napi::Env, std::optional<std::string> value) {
61         UNIMPLEMENTED();
62     }
63 
64 }}  // namespace wgpu::binding
65