Skip to content

Commit 3fea49d

Browse files
committed
src: Rule of 5 fixes.
1 parent ffcca49 commit 3fea49d

4 files changed

Lines changed: 100 additions & 13 deletions

File tree

src/tests/hello_xr/graphicsplugin_opengl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ static const char* FragmentShaderGlsl = R"_(
4141
struct OpenGLGraphicsPlugin : public IGraphicsPlugin {
4242
OpenGLGraphicsPlugin(const std::shared_ptr<Options>&, std::shared_ptr<IPlatformPlugin>){};
4343

44+
OpenGLGraphicsPlugin(const OpenGLGraphicsPlugin&) = delete;
45+
OpenGLGraphicsPlugin& operator=(const OpenGLGraphicsPlugin&) = delete;
46+
OpenGLGraphicsPlugin(OpenGLGraphicsPlugin&&) = delete;
47+
OpenGLGraphicsPlugin& operator=(OpenGLGraphicsPlugin&&) = delete;
48+
4449
~OpenGLGraphicsPlugin() override {
4550
if (m_swapchainFramebuffer != 0) {
4651
glDeleteFramebuffers(1, &m_swapchainFramebuffer);

src/tests/hello_xr/graphicsplugin_vulkan.cpp

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,12 @@ struct CmdBuffer {
183183
VkCommandBuffer buf{VK_NULL_HANDLE};
184184
VkFence execFence{VK_NULL_HANDLE};
185185

186-
CmdBuffer() {}
186+
CmdBuffer() = default;
187187

188-
CmdBuffer(const CmdBuffer& that) = delete;
188+
CmdBuffer(const CmdBuffer&) = delete;
189+
CmdBuffer& operator=(const CmdBuffer&) = delete;
190+
CmdBuffer(CmdBuffer&&) = delete;
191+
CmdBuffer& operator=(CmdBuffer&&) = delete;
189192

190193
~CmdBuffer() {
191194
SetState(CmdBufferState::Undefined);
@@ -330,6 +333,11 @@ struct ShaderProgram {
330333
shaderInfo = {};
331334
}
332335

336+
ShaderProgram(const ShaderProgram&) = delete;
337+
ShaderProgram& operator=(const ShaderProgram&) = delete;
338+
ShaderProgram(ShaderProgram&&) = delete;
339+
ShaderProgram& operator=(ShaderProgram&&) = delete;
340+
333341
void LoadVertexShader(const std::vector<uint32_t>& code) { Load(0, code); }
334342

335343
void LoadFragmentShader(const std::vector<uint32_t>& code) { Load(1, code); }
@@ -339,7 +347,7 @@ struct ShaderProgram {
339347
private:
340348
VkDevice m_vkDevice{VK_NULL_HANDLE};
341349

342-
const void Load(uint32_t index, const std::vector<uint32_t>& code) {
350+
void Load(uint32_t index, const std::vector<uint32_t>& code) {
343351
VkShaderModuleCreateInfo modInfo{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO};
344352

345353
auto& si = shaderInfo[index];
@@ -400,6 +408,10 @@ struct VertexBufferBase {
400408
count = {0, 0};
401409
}
402410

411+
VertexBufferBase(const VertexBufferBase&) = delete;
412+
VertexBufferBase& operator=(const VertexBufferBase&) = delete;
413+
VertexBufferBase(VertexBufferBase&&) = delete;
414+
VertexBufferBase& operator=(VertexBufferBase&&) = delete;
403415
void Init(VkDevice device, const MemoryAllocator* memAllocator, const std::vector<VkVertexInputAttributeDescription>& attr) {
404416
m_vkDevice = device;
405417
m_memAllocator = memAllocator;
@@ -465,7 +477,7 @@ struct RenderPass {
465477
VkFormat depthFmt{};
466478
VkRenderPass pass{VK_NULL_HANDLE};
467479

468-
RenderPass() {}
480+
RenderPass() = default;
469481

470482
bool Create(VkDevice device, VkFormat aColorFmt, VkFormat aDepthFmt) {
471483
m_vkDevice = device;
@@ -529,6 +541,11 @@ struct RenderPass {
529541
pass = VK_NULL_HANDLE;
530542
}
531543

544+
RenderPass(const RenderPass&) = delete;
545+
RenderPass& operator=(const RenderPass&) = delete;
546+
RenderPass(RenderPass&&) = delete;
547+
RenderPass& operator=(RenderPass&&) = delete;
548+
532549
private:
533550
VkDevice m_vkDevice{VK_NULL_HANDLE};
534551
};
@@ -541,7 +558,7 @@ struct RenderTarget {
541558
VkImageView depthView{VK_NULL_HANDLE};
542559
VkFramebuffer fb{VK_NULL_HANDLE};
543560

544-
RenderTarget() {}
561+
RenderTarget() = default;
545562

546563
~RenderTarget() {
547564
if (m_vkDevice) {
@@ -556,8 +573,33 @@ struct RenderTarget {
556573
colorView = VK_NULL_HANDLE;
557574
depthView = VK_NULL_HANDLE;
558575
fb = VK_NULL_HANDLE;
576+
m_vkDevice = VK_NULL_HANDLE;
559577
}
560578

579+
RenderTarget(RenderTarget&& other) : RenderTarget() {
580+
using std::swap;
581+
swap(colorImage, other.colorImage);
582+
swap(depthImage, other.depthImage);
583+
swap(colorView, other.colorView);
584+
swap(depthView, other.depthView);
585+
swap(fb, other.fb);
586+
swap(m_vkDevice, other.m_vkDevice);
587+
}
588+
RenderTarget& operator=(RenderTarget&& other) {
589+
if (&other == this) {
590+
return *this;
591+
}
592+
// Clean up ourselves.
593+
this->~RenderTarget();
594+
using std::swap;
595+
swap(colorImage, other.colorImage);
596+
swap(depthImage, other.depthImage);
597+
swap(colorView, other.colorView);
598+
swap(depthView, other.depthView);
599+
swap(fb, other.fb);
600+
swap(m_vkDevice, other.m_vkDevice);
601+
return *this;
602+
}
561603
void Create(VkDevice device, VkImage aColorImage, VkImage aDepthImage, VkExtent2D size, RenderPass& renderPass) {
562604
m_vkDevice = device;
563605

@@ -615,6 +657,9 @@ struct RenderTarget {
615657
CHECK_VKCMD(vkCreateFramebuffer(m_vkDevice, &fbInfo, nullptr, &fb));
616658
}
617659

660+
RenderTarget(const RenderTarget&) = delete;
661+
RenderTarget& operator=(const RenderTarget&) = delete;
662+
618663
private:
619664
VkDevice m_vkDevice{VK_NULL_HANDLE};
620665
};
@@ -623,13 +668,14 @@ struct RenderTarget {
623668
struct PipelineLayout {
624669
VkPipelineLayout layout{VK_NULL_HANDLE};
625670

626-
PipelineLayout() {}
671+
PipelineLayout() = default;
627672

628673
~PipelineLayout() {
629674
if (m_vkDevice) {
630675
if (layout) vkDestroyPipelineLayout(m_vkDevice, layout, nullptr);
631676
}
632677
layout = VK_NULL_HANDLE;
678+
m_vkDevice = VK_NULL_HANDLE;
633679
}
634680

635681
void Create(VkDevice device) {
@@ -647,6 +693,11 @@ struct PipelineLayout {
647693
CHECK_VKCMD(vkCreatePipelineLayout(m_vkDevice, &pipelineLayoutCreateInfo, nullptr, &layout));
648694
}
649695

696+
PipelineLayout(const PipelineLayout&) = delete;
697+
PipelineLayout& operator=(const PipelineLayout&) = delete;
698+
PipelineLayout(PipelineLayout&&) = delete;
699+
PipelineLayout& operator=(PipelineLayout&&) = delete;
700+
650701
private:
651702
VkDevice m_vkDevice{VK_NULL_HANDLE};
652703
};
@@ -778,11 +829,37 @@ struct DepthBuffer {
778829
VkDeviceMemory depthMemory{VK_NULL_HANDLE};
779830
VkImage depthImage{VK_NULL_HANDLE};
780831

781-
DepthBuffer() {}
832+
DepthBuffer() = default;
782833

783834
~DepthBuffer() {
784-
if (depthImage) vkDestroyImage(m_vkDevice, depthImage, nullptr);
785-
if (depthMemory) vkFreeMemory(m_vkDevice, depthMemory, nullptr);
835+
if (m_vkDevice) {
836+
if (depthImage) vkDestroyImage(m_vkDevice, depthImage, nullptr);
837+
if (depthMemory) vkFreeMemory(m_vkDevice, depthMemory, nullptr);
838+
}
839+
depthImage = VK_NULL_HANDLE;
840+
depthMemory = VK_NULL_HANDLE;
841+
m_vkDevice = VK_NULL_HANDLE;
842+
}
843+
844+
DepthBuffer(DepthBuffer&& other) : DepthBuffer() {
845+
using std::swap;
846+
847+
swap(depthImage, other.depthImage);
848+
swap(depthMemory, other.depthMemory);
849+
swap(m_vkDevice, other.m_vkDevice);
850+
}
851+
DepthBuffer& operator=(DepthBuffer&& other) {
852+
if (&other == this) {
853+
return *this;
854+
}
855+
// clean up self
856+
this->~DepthBuffer();
857+
using std::swap;
858+
859+
swap(depthImage, other.depthImage);
860+
swap(depthMemory, other.depthMemory);
861+
swap(m_vkDevice, other.m_vkDevice);
862+
return *this;
786863
}
787864

788865
void Create(VkDevice device, MemoryAllocator* memAllocator, VkFormat depthFormat,
@@ -813,6 +890,9 @@ struct DepthBuffer {
813890
CHECK_VKCMD(vkBindImageMemory(device, depthImage, depthMemory, 0));
814891
}
815892

893+
DepthBuffer(const DepthBuffer&) = delete;
894+
DepthBuffer& operator=(const DepthBuffer&) = delete;
895+
816896
private:
817897
VkDevice m_vkDevice{VK_NULL_HANDLE};
818898
};
@@ -1332,7 +1412,7 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
13321412
// Allocate and initialize the buffer of image structs (must be sequential in memory for xrEnumerateSwapchainImages).
13331413
// Return back an array of pointers to each swapchain image struct so the consumer doesn't need to know the type/size.
13341414
// Keep the buffer alive by adding it into the list of buffers.
1335-
m_swapchainImageContexts.push_back({});
1415+
m_swapchainImageContexts.emplace_back();
13361416
SwapchainImageContext& swapchainImageContext = m_swapchainImageContexts.back();
13371417

13381418
std::vector<XrSwapchainImageBaseHeader*> bases = swapchainImageContext.Create(
@@ -1433,7 +1513,6 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
14331513
uint32_t m_queueFamilyIndex = 0;
14341514
VkQueue m_vkQueue{VK_NULL_HANDLE};
14351515
VkSemaphore m_vkDrawDone{VK_NULL_HANDLE};
1436-
uint32_t m_vkDeviceLocalHeap = 0;
14371516

14381517
MemoryAllocator m_memAllocator{};
14391518
ShaderProgram m_shaderProgram{};

src/tests/hello_xr/platformplugin_xlib.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ namespace {
77
struct XlibPlatformPlugin : public IPlatformPlugin {
88
XlibPlatformPlugin(const std::shared_ptr<Options>&) {}
99

10-
virtual ~XlibPlatformPlugin() {}
11-
1210
std::vector<std::string> GetInstanceExtensions() const override { return {}; }
1311

1412
XrBaseInStructure* GetInstanceCreateExtension() const override { return nullptr; }

src/tests/list/list.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ struct Program {
4444
instance = XR_NULL_HANDLE;
4545
}
4646
}
47+
48+
Program(const Program&) = delete;
49+
Program& operator=(const Program&) = delete;
50+
Program(Program&&) = delete;
51+
Program& operator=(Program&&) = delete;
4752
};
4853

4954
// This below function is written in as close to "C style" as

0 commit comments

Comments
 (0)