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_IMAGE_GLES_H 17 #define GLES_GPU_IMAGE_GLES_H 18 19 #include <base/math/vector.h> 20 #include <render/device/gpu_resource_desc.h> 21 #include <render/gles/intf_device_gles.h> 22 #include <render/namespace.h> 23 24 #include "device/gpu_image.h" 25 26 RENDER_BEGIN_NAMESPACE() 27 class Device; 28 class DeviceGLES; 29 struct GpuImageDesc; 30 struct GpuImagePlatformDataGL final : public GpuImagePlatformData { 31 // GL_TEXTURE_2D,GL_TEXTURE_CUBE_MAP,GL_TEXTURE_2D_MULTISAMPLE etc. 32 // (ie. viewtype, can be 0. (no view, used for backbuffer "images" and renderbuffers)) 33 uint32_t type; 34 uint32_t image; // Texture handle (0 for "no view") 35 uint32_t format; // GL_RGB etc 36 uint32_t internalFormat; // GL_RGBA16F etc.. 37 uint32_t dataType; // GL_FLOAT etc 38 uint32_t bytesperpixel; 39 struct { 40 bool compressed; 41 uint8_t blockW; 42 uint8_t blockH; 43 uint32_t bytesperblock; 44 } compression; 45 BASE_NS::Math::UVec4 swizzle; 46 uint32_t renderBuffer; // For render targets... (can not be sampled or used in compute) 47 uintptr_t eglImage; // For creating image from EGLImage 48 uintptr_t hwBuffer; // For creating image from AHardwareBuffer 49 uint32_t mipLevel { PipelineStateConstants::GPU_IMAGE_ALL_MIP_LEVELS }; 50 }; 51 52 class GpuImageGLES final : public GpuImage { 53 public: 54 GpuImageGLES(Device& device, const GpuImageDesc& desc); 55 GpuImageGLES(Device& device, const GpuImageDesc& desc, const GpuImagePlatformData& platformData); 56 ~GpuImageGLES(); 57 58 const GpuImageDesc& GetDesc() const override; 59 const GpuImagePlatformData& GetBasePlatformData() const override; 60 const GpuImagePlatformDataGL& GetPlatformData() const; 61 62 static GpuImagePlatformDataGL GetPlatformData(const DeviceGLES& device, BASE_NS::Format format); 63 64 AdditionalFlags GetAdditionalFlags() const override; 65 66 private: 67 DeviceGLES& device_; 68 69 GpuImagePlatformDataGL plat_; 70 GpuImageDesc desc_; 71 // in normal situations owns all the vulkan resources 72 bool ownsResources_ { true }; 73 }; 74 RENDER_END_NAMESPACE() 75 76 #endif // GLES_GPU_IMAGE_GLES_H 77