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 #ifndef GLES_GPU_BUFFER_GLES_H 17 #define GLES_GPU_BUFFER_GLES_H 18 19 #include <cstdint> 20 21 #include <render/device/gpu_resource_desc.h> 22 #include <render/gles/intf_device_gles.h> 23 #include <render/namespace.h> 24 25 #include "device/gpu_buffer.h" 26 27 RENDER_BEGIN_NAMESPACE() 28 class Device; 29 class DeviceGLES; 30 struct GpuBufferPlatformDataGL final : public GpuBufferPlatformData { 31 uint32_t buffer { 0 }; 32 uint32_t alignedBindByteSize { 0 }; 33 uint32_t alignedByteSize { 0 }; 34 // map changes offset if buffered 35 uint32_t currentByteOffset { 0 }; 36 // alignedByteSize / mapBufferingCount (if no buffering alignedByteSize == bindMemoryByteSize) 37 uint32_t bindMemoryByteSize { 0 }; 38 }; 39 40 class GpuBufferGLES final : public GpuBuffer { 41 public: 42 GpuBufferGLES(Device& device, const GpuBufferDesc& desc); 43 ~GpuBufferGLES(); 44 45 const GpuBufferDesc& GetDesc() const override; 46 const GpuBufferPlatformDataGL& GetPlatformData() const; 47 48 void* Map() override; 49 void* MapMemory() override; 50 void Unmap() const override; 51 52 private: 53 DeviceGLES& device_; 54 55 GpuBufferPlatformDataGL plat_; 56 GpuBufferDesc desc_; 57 58 // debug assert usage only 59 mutable bool isMapped_ { false }; 60 61 bool isPersistantlyMapped_ { false }; 62 bool isMappable_ { false }; 63 bool isRingBuffer_ { false }; 64 65 uint8_t* data_ { nullptr }; 66 }; 67 RENDER_END_NAMESPACE() 68 69 #endif // GLES_GPU_BUFFER_GLES_H 70