mirror of https://github.com/mosra/magnum.git
2 changed files with 145 additions and 0 deletions
@ -0,0 +1,33 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 |
||||||
|
Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
Copyright © 2016 Jonathan Hale <squareys@googlemail.com> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Texture.h" |
||||||
|
|
||||||
|
|
||||||
|
namespace Magnum { namespace Vk { |
||||||
|
|
||||||
|
|
||||||
|
}} |
||||||
@ -0,0 +1,112 @@ |
|||||||
|
#ifndef Magnum_Vk_Texture_h |
||||||
|
#define Magnum_Vk_Texture_h |
||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 |
||||||
|
Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
Copyright © 2016 Jonathan Hale <squareys@googlemail.com> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Class @ref Magnum::Vk::Texture, @ref Magnum::Vk::Texture1D, @ref Magnum::Vk::Texture2D, @ref Magnum::Vk::Texture3D |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Magnum/Magnum.h" |
||||||
|
#include "Magnum/Math/Vector.h" |
||||||
|
#include "Magnum/Vk/Image.h" |
||||||
|
#include "Magnum/Vk/ImageView.h" |
||||||
|
#include "Magnum/Vk/visibility.h" |
||||||
|
|
||||||
|
#include "vulkan.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Vk { |
||||||
|
|
||||||
|
template<UnsignedInt dimensions> |
||||||
|
class MAGNUM_VK_EXPORT Texture { |
||||||
|
public: |
||||||
|
|
||||||
|
Texture(Device& device): _device{device} { |
||||||
|
int mipLevels = 0; |
||||||
|
VkSamplerCreateInfo sampler{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, nullptr, 0}; |
||||||
|
sampler.magFilter = VK_FILTER_LINEAR; |
||||||
|
sampler.minFilter = VK_FILTER_LINEAR; |
||||||
|
sampler.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; |
||||||
|
sampler.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; |
||||||
|
sampler.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; |
||||||
|
sampler.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; |
||||||
|
sampler.mipLodBias = 0.0f; |
||||||
|
sampler.compareOp = VK_COMPARE_OP_NEVER; |
||||||
|
sampler.minLod = 0.0f; |
||||||
|
sampler.maxLod = float(mipLevels); |
||||||
|
sampler.maxAnisotropy = 8; |
||||||
|
sampler.anisotropyEnable = VK_TRUE; |
||||||
|
sampler.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; |
||||||
|
|
||||||
|
VkResult err = vkCreateSampler(device, &sampler, nullptr, &_sampler); |
||||||
|
MAGNUM_VK_ASSERT_ERROR(err); |
||||||
|
} |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
Texture(const Texture&) = delete; |
||||||
|
|
||||||
|
/** @brief Move constructor */ |
||||||
|
Texture(Texture&& other); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destructor |
||||||
|
* |
||||||
|
* @see @fn_vk{DestroyBuffer} |
||||||
|
*/ |
||||||
|
~Texture() { |
||||||
|
vkDestroySampler(_device, _sampler, nullptr); |
||||||
|
} |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
Texture& operator=(const Texture&) = delete; |
||||||
|
|
||||||
|
/** @brief Move assignment is not allowed */ |
||||||
|
Texture& operator=(Texture&&) = delete; |
||||||
|
|
||||||
|
Math::Vector<dimensions, UnsignedInt> size() const { |
||||||
|
return _size; |
||||||
|
} |
||||||
|
|
||||||
|
private: |
||||||
|
|
||||||
|
Device& _device; |
||||||
|
|
||||||
|
VkSampler _sampler; |
||||||
|
Vk::Image _image; |
||||||
|
VkImageLayout _imageLayout; |
||||||
|
Vk::DeviceMemory _deviceMemory; |
||||||
|
Vk::ImageView _view; |
||||||
|
Math::Vector<dimensions, UnsignedInt> _size; |
||||||
|
UnsignedInt _mipLevels; |
||||||
|
}; |
||||||
|
|
||||||
|
typedef Texture<1> Texture1D; |
||||||
|
typedef Texture<2> Texture2D; |
||||||
|
typedef Texture<3> Texture3D; |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
Loading…
Reference in new issue