CMSC23740 Common Code Library
Support code for CS23740 programming projects
Loading...
Searching...
No Matches
texture.hpp
Go to the documentation of this file.
1
9/*
10 * COPYRIGHT (c) 2024 John Reppy (https://cs.uchicago.edu/~jhr)
11 * All rights reserved.
12 */
13
14#ifndef _CS237_TEXTURE_HPP_
15#define _CS237_TEXTURE_HPP_
16
17#ifndef _CS237_HPP_
18# error "cs237/texture.hpp should not be included directly"
19#endif
20
21namespace cs237 {
22
23namespace __detail {
24
26public:
28 vk::ImageView view () const { return this->_view; }
29
31 vk::Format format () const { return this->_fmt; }
32
33protected:
35 vk::Image _img;
36 vk::DeviceMemory _mem;
37 vk::ImageView _view;
38 uint32_t _wid;
39 uint32_t _ht;
40 uint32_t _nMipLevels;
41 vk::Format _fmt;
42
44 Application *app,
45 uint32_t wid, uint32_t ht, uint32_t mipLvls,
48
53 vk::Buffer _createBuffer (size_t size, vk::BufferUsageFlags usage)
54 {
55 return this->_app->_createBuffer (size, usage);
56 }
57
62 vk::DeviceMemory _allocBufferMemory (vk::Buffer buf, vk::MemoryPropertyFlags props)
63 {
64 return this->_app->_allocBufferMemory (buf, props);
65 }
66
70
71};
72
73} // namespace __detail
74
75// 1D Textures
77public:
78
82 Texture1D (Application *app, Image1D const *img);
83
84};
85
86// 2D Textures
88public:
89
94 Texture2D (Application *app, Image2D const *img, bool mipmap = false);
95
96private:
99 void _generateMipMaps (cs237::Image2D const *img);
100
101};
102
103} // namespace cs237
104
105#endif // !_CS237_TEXTURE_HPP_
Definition image.hpp:58
Definition texture.hpp:25
vk::Format format() const
get the texel format
Definition texture.hpp:31
vk::DeviceMemory _allocBufferMemory(vk::Buffer buf, vk::MemoryPropertyFlags props)
A helper function for allocating and binding device memory for a buffer.
Definition texture.hpp:62
uint32_t _ht
teture height (1 for 1D textures)
Definition texture.hpp:39
void _init(cs237::__detail::ImageBase const *img)
initialize a texture by copying data into it using a staging buffer.
vk::ImageView _view
image view for texture image
Definition texture.hpp:37
uint32_t _wid
texture width
Definition texture.hpp:38
Application * _app
the owning application
Definition texture.hpp:34
vk::Buffer _createBuffer(size_t size, vk::BufferUsageFlags usage)
create a vk::Buffer object
Definition texture.hpp:53
uint32_t _nMipLevels
number of mipmap levels
Definition texture.hpp:40
vk::ImageView view() const
return the image view for the texture
Definition texture.hpp:28
vk::Image _img
Vulkan image to hold the texture.
Definition texture.hpp:35
vk::DeviceMemory _mem
device memory for the texture image
Definition texture.hpp:36
TextureBase(Application *app, uint32_t wid, uint32_t ht, uint32_t mipLvls, cs237::__detail::ImageBase const *img)
vk::Format _fmt
the texel format
Definition texture.hpp:41
the base class for applications
Definition application.hpp:25
vk::DeviceMemory _allocBufferMemory(vk::Buffer buf, vk::MemoryPropertyFlags props)
A helper function for allocating and binding device memory for a buffer.
vk::Buffer _createBuffer(size_t size, vk::BufferUsageFlags usage)
create a vk::Buffer object
Definition image.hpp:112
Definition image.hpp:139
Definition texture.hpp:76
Texture1D(Application *app, Image1D const *img)
Construct a 1D texture from a 1D image.
Definition texture.hpp:87
Texture2D(Application *app, Image2D const *img, bool mipmap=false)
Construct a 2D texture from a 2D image.
Definition aabb.hpp:22