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
|
#include "../core/configuration.h"
#if defined(jin_graphics)
#include "../utils/macros.h"
#include "canvas.h"
#include "window.h"
namespace JinEngine
{
namespace Graphics
{
Canvas::Canvas(GLuint n)
: fbo(n)
{
++gl.getStats().canvases;
}
Canvas::Canvas(int w, int h)
: Graphic(w, h)
{
GLint current_fbo;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo);
// Generate a new render buffer object.
fbo = gl.genFrameBuffer();
gl.bindFrameBuffer(fbo);
// Render texture.
GLuint texture = getGLTexture();
gl.bindTexture2D(texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
// Unbind framebuffer
gl.bindFrameBuffer(current_fbo);
++gl.getStats().canvases;
}
Canvas::~Canvas()
{
--gl.getStats().canvases;
}
bool Canvas::isBinded(const Canvas* cvs)
{
return gl.getCanvas() == cvs;
}
} // namespace Graphics
} // namespace JinEngine
#endif // defined(jin_graphics)
|