1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
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 
16 #include "gles/gpu_resource_util_gles.h"
17 
18 #include <base/containers/byte_array.h>
19 #include <base/containers/string_view.h>
20 #include <render/gles/intf_device_gles.h>
21 #include <render/namespace.h>
22 
23 #include "gles/device_gles.h"
24 #include "gles/gl_functions.h"
25 #include "gles/gpu_buffer_gles.h"
26 #include "gles/gpu_image_gles.h"
27 #include "gles/gpu_sampler_gles.h"
28 
29 using namespace BASE_NS;
30 
31 RENDER_BEGIN_NAMESPACE()
32 namespace GpuResourceUtil {
33 
CopyGpuBufferGLES(GpuBuffer & buffer,ByteArray & byteArray)34 void CopyGpuBufferGLES(GpuBuffer& buffer, ByteArray& byteArray)
35 {
36     GpuBufferGLES& glesBuffer = (GpuBufferGLES&)buffer;
37     if (const void* resData = glesBuffer.MapMemory(); resData) {
38         const GpuBufferDesc& desc = glesBuffer.GetDesc();
39         CloneData(byteArray.GetData().data(), byteArray.GetData().size_bytes(), (const uint8_t*)resData, desc.byteSize);
40         glesBuffer.Unmap();
41     }
42 }
43 
DebugBufferNameGLES(const IDevice & device,const GpuBuffer & buffer,const string_view name)44 void DebugBufferNameGLES(const IDevice& device, const GpuBuffer& buffer, const string_view name)
45 {
46     const GpuBufferPlatformDataGL& cplat = (static_cast<const GpuBufferGLES&>(buffer)).GetPlatformData();
47     GpuBufferPlatformDataGL& plat = const_cast<GpuBufferPlatformDataGL&>(cplat);
48     if (plat.buffer) {
49         glObjectLabel(GL_BUFFER, plat.buffer, (GLsizei)name.length(), name.data());
50     }
51 }
52 
DebugImageNameGLES(const IDevice & device,const GpuImage & image,const string_view name)53 void DebugImageNameGLES(const IDevice& device, const GpuImage& image, const string_view name)
54 {
55     const GpuImagePlatformDataGL& plat = (static_cast<const GpuImageGLES&>(image)).GetPlatformData();
56     if (plat.image) {
57         glObjectLabel(GL_TEXTURE, plat.image, (GLsizei)name.length(), name.data());
58     }
59 }
60 
DebugSamplerNameGLES(const IDevice & device,const GpuSampler & sampler,const string_view name)61 void DebugSamplerNameGLES(const IDevice& device, const GpuSampler& sampler, const string_view name)
62 {
63     const GpuSamplerPlatformDataGL& plat = (static_cast<const GpuSamplerGLES&>(sampler)).GetPlatformData();
64     if (plat.sampler) {
65         glObjectLabel(GL_SAMPLER, plat.sampler, (GLsizei)name.length(), name.data());
66     }
67 }
68 } // namespace GpuResourceUtil
69 RENDER_END_NAMESPACE()
70