summaryrefslogtreecommitdiffstats
path: root/src/RendererSection.cpp
blob: 429a8bd0db926c033d95ad7d604b9c1145982e40 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "RendererSection.hpp"

#include <cstddef>

#include <easylogging++.h>
#include <optick.h>

#include "Utility.hpp"
#include "RendererSectionData.hpp"


RendererSection::RendererSection(const RendererSectionData& data, std::shared_ptr<Gal::Pipeline> pipeline, std::shared_ptr<Gal::BufferBinding> bufferBinding) {
	OPTICK_EVENT();

	auto gal = Gal::GetImplementation();
	buffer = gal->CreateBuffer();

	pipelineInstance = pipeline->CreateInstance({
		{bufferBinding, buffer}
		});
	pipelineInstance->SetInstancesCount(4);
	
	UpdateData(data);
}

RendererSection::RendererSection(RendererSection && other) {
    using std::swap;
    swap(*this, other);
}

RendererSection::~RendererSection() {
    
}

void swap(RendererSection & lhs, RendererSection & rhs) {
    std::swap(lhs.pipelineInstance, rhs.pipelineInstance);
	std::swap(lhs.buffer, rhs.buffer);
    std::swap(lhs.hash, rhs.hash);
    std::swap(lhs.numOfFaces, rhs.numOfFaces);
    std::swap(lhs.sectionPos, rhs.sectionPos);
}

void RendererSection::Render() {
	OPTICK_EVENT();
	pipelineInstance->Activate();
	pipelineInstance->Render(0, numOfFaces);
}

Vector RendererSection::GetPosition() {
    return sectionPos;
}

size_t RendererSection::GetHash() {
    return hash;
}

void RendererSection::UpdateData(const RendererSectionData & data) {
	OPTICK_EVENT();

	buffer->SetData({ reinterpret_cast<const std::byte*>(data.vertices.data()), reinterpret_cast<const std::byte*>(data.vertices.data() + data.vertices.size())});

	numOfFaces = data.vertices.size();
	sectionPos = data.sectionPos;
	hash = data.hash;
}