| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #include "Canvas.hpp"
- Canvas::Canvas(GLuint width, GLuint height) :
- m_width(width), m_height(height)
- {
- }
- Canvas::~Canvas()
- {
- }
- void Canvas::create()
- {
- /* Generation de la texture */
- glGenTextures(1, &m_texture);
- glBindTexture(GL_TEXTURE_2D, m_texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
- m_width, m_height, 0, GL_RGBA,
- GL_UNSIGNED_BYTE, NULL);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
-
- /* Generation du Frame Buffer */
- glGenFramebuffers(1, &m_FBO);
- glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
- glFramebufferTexture(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_texture, 0);
-
- glReadBuffer(GL_COLOR_ATTACHMENT0);
- }
- void Canvas::bind()
- {
- glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);
- glBindImageTexture(0, m_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
- }
- void Canvas::unbind()
- {
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- // glBindTexture(GL_TEXTURE_2D, 0);
- }
- void Canvas::draw()
- {
- glBindFramebuffer(GL_READ_FRAMEBUFFER, m_FBO);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
- glBlitFramebuffer(
- 0, 0, m_width, m_height,
- 0, 0, m_width, m_height,
- GL_COLOR_BUFFER_BIT, GL_NEAREST);
- glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
- glBindTexture(GL_TEXTURE_2D, 0);
- }
- void Canvas::release()
- {
- glDeleteTextures(1, &m_texture);
- glDeleteFramebuffers(1, &m_FBO);
- }
|