1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
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 #ifndef VK_IMAGE_VIEW_HPP_
16 #define VK_IMAGE_VIEW_HPP_
17 
18 #include "VkDebug.hpp"
19 #include "VkObject.hpp"
20 #include "VkImage.hpp"
21 
22 namespace vk
23 {
24 
25 class ImageView : public Object<ImageView, VkImageView>
26 {
27 public:
28 	ImageView(const VkImageViewCreateInfo* pCreateInfo, void* mem);
29 	~ImageView() = delete;
30 	void destroy(const VkAllocationCallbacks* pAllocator);
31 
32 	static size_t ComputeRequiredAllocationSize(const VkImageViewCreateInfo* pCreateInfo);
33 
34 	void clear(const VkClearValue& clearValues, const VkImageAspectFlags aspectMask, const VkRect2D& renderArea);
35 	void clear(const VkClearValue& clearValue, const VkImageAspectFlags aspectMask, const VkClearRect& renderArea);
36 
37 private:
38 	bool                       imageTypesMatch(VkImageType imageType) const;
39 
40 	Image*                     image = nullptr;
41 	VkImageViewType            viewType = VK_IMAGE_VIEW_TYPE_2D;
42 	VkFormat                   format = VK_FORMAT_UNDEFINED;
43 	VkComponentMapping         components = {};
44 	VkImageSubresourceRange    subresourceRange = {};
45 };
46 
Cast(VkImageView object)47 static inline ImageView* Cast(VkImageView object)
48 {
49 	return reinterpret_cast<ImageView*>(object);
50 }
51 
52 } // namespace vk
53 
54 #endif // VK_IMAGE_VIEW_HPP_