-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderTexture.cpp
More file actions
74 lines (60 loc) · 2.07 KB
/
renderTexture.cpp
File metadata and controls
74 lines (60 loc) · 2.07 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
#include "renderTexture.h"
#include "shaderProgram.h"
#include "Scene.h"
#include "texture.h"
#include <iostream>
renderTexture::renderTexture()
{
glGenFramebuffers(1, &frameBufferId);
if (!frameBufferId) { throw std::exception(); }
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
tex = std::make_shared<texture>(glm::ivec2(512,512));
renderTextureId = tex->getId();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderTextureId, 0);
glGenRenderbuffers(1, &renderBufferId);
glBindRenderbuffer(GL_RENDERBUFFER, renderBufferId);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 512,512);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, renderBufferId);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
textureSize = glm::ivec2(256,256);
}
renderTexture::renderTexture(glm::ivec2 _size)
{
glGenFramebuffers(1, &frameBufferId);
if (!frameBufferId) { throw std::exception(); }
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
tex = std::make_shared<texture>(glm::ivec2(_size.x, _size.y));
renderTextureId = tex->getId();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderTextureId, 0);
glGenRenderbuffers(1, &renderBufferId);
glBindRenderbuffer(GL_RENDERBUFFER, renderBufferId);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, _size.x,
_size.y);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, renderBufferId);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
textureSize = _size;
}
void renderTexture::drawToTexture(shaderProgram shader)
{
//glUseProgram()
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void renderTexture::bind()
{
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
}
void renderTexture::unBind()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
GLuint renderTexture::getTexture()
{
return renderTextureId;
}