1 /* 2 * Copyright (C) 2023 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 uint32_t mipLevel { PipelineStateConstants::GPU_IMAGE_ALL_MIP_LEVELS }; 49 }; 50 51 class GpuImageGLES final : public GpuImage { 52 public: 53 GpuImageGLES(Device& device, const GpuImageDesc& desc); 54 GpuImageGLES(Device& device, const GpuImageDesc& desc, const GpuImagePlatformData& platformData); 55 ~GpuImageGLES(); 56 57 const GpuImageDesc& GetDesc() const override; 58 const GpuImagePlatformData& GetBasePlatformData() const override; 59 const GpuImagePlatformDataGL& GetPlatformData() const; 60 61 static GpuImagePlatformDataGL GetPlatformData(const DeviceGLES& device, BASE_NS::Format format); 62 63 AdditionalFlags GetAdditionalFlags() const override; 64 65 private: 66 DeviceGLES& device_; 67 68 GpuImagePlatformDataGL plat_; 69 GpuImageDesc desc_; 70 // in normal situations owns all the vulkan resources 71 bool ownsResources_ { true }; 72 }; 73 RENDER_END_NAMESPACE() 74 75 #endif // GLES_GPU_IMAGE_GLES_H 76