2016-02-07 20:42:02 +00:00
|
|
|
//
|
|
|
|
// TextureTarget.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 07/02/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "TextureTarget.hpp"
|
|
|
|
|
|
|
|
using namespace OpenGL;
|
|
|
|
|
2016-03-07 23:55:15 +00:00
|
|
|
TextureTarget::TextureTarget(GLsizei width, GLsizei height) : _width(width), _height(height)
|
2016-02-07 20:42:02 +00:00
|
|
|
{
|
|
|
|
glGenFramebuffers(1, &_framebuffer);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer);
|
|
|
|
|
|
|
|
glGenTextures(1, &_texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, _texture);
|
2016-04-19 01:32:48 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
2016-02-07 20:42:02 +00:00
|
|
|
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0);
|
|
|
|
|
2016-03-07 23:55:15 +00:00
|
|
|
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
throw ErrorFramebufferIncomplete;
|
2016-02-07 20:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TextureTarget::~TextureTarget()
|
|
|
|
{
|
|
|
|
glDeleteFramebuffers(1, &_framebuffer);
|
|
|
|
glDeleteTextures(1, &_texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureTarget::bind_framebuffer()
|
|
|
|
{
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer);
|
2016-03-07 23:55:15 +00:00
|
|
|
glViewport(0, 0, _width, _height);
|
2016-02-07 20:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextureTarget::bind_texture()
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, _texture);
|
|
|
|
}
|