-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrendertarget.cpp
More file actions
81 lines (66 loc) · 1.78 KB
/
rendertarget.cpp
File metadata and controls
81 lines (66 loc) · 1.78 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <fea/rendering/rendertarget.hpp>
#include <fea/assert.hpp>
#include <string>
namespace fea
{
RenderTarget::RenderTarget() : mId(0)
{
}
RenderTarget::RenderTarget(RenderTarget&& other) : mId(0)
{
std::swap(mId, other.mId);
std::swap(mSize, other.mSize);
std::swap(mTexture, other.mTexture);
}
RenderTarget& RenderTarget::operator=(RenderTarget&& other)
{
std::swap(mId, other.mId);
std::swap(mSize, other.mSize);
std::swap(mTexture, other.mTexture);
return *this;
}
GLuint RenderTarget::getId() const
{
return mId;
}
const glm::ivec2& RenderTarget::getSize() const
{
return mSize;
}
const Texture& RenderTarget::getTexture() const
{
return mTexture;
}
void RenderTarget::create(const glm::ivec2& size, bool smooth)
{
FEA_ASSERT(size.x > 0 && size.y > 0, "Size must be greater than zero in both dimensions. " + std::to_string(size.x) + " " + std::to_string(size.y) + " provided.");
if(mId)
{
destroy();
}
mSize = size;
glGenFramebuffers(1, &mId);
glBindFramebuffer(GL_FRAMEBUFFER, mId);
mTexture.create(size, nullptr);
glBindTexture(GL_TEXTURE_2D, mTexture.getId());
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture.getId(), 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
}
void RenderTarget::destroy()
{
if(mId)
{
mTexture.destroy();
glDeleteFramebuffers(1, &mId);
mId = 0;
}
}
RenderTarget::~RenderTarget()
{
if(mId)
{
destroy();
}
}
}