2016-02-07 20:42:02 +00:00
|
|
|
//
|
|
|
|
// TextureTarget.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 07/02/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef TextureTarget_hpp
|
|
|
|
#define TextureTarget_hpp
|
|
|
|
|
2016-02-07 22:32:38 +00:00
|
|
|
#include "OpenGL.hpp"
|
2016-05-01 17:52:35 +00:00
|
|
|
#include "Shaders/Shader.hpp"
|
|
|
|
#include <memory>
|
2016-02-07 20:42:02 +00:00
|
|
|
|
|
|
|
namespace OpenGL {
|
|
|
|
|
2016-04-20 00:51:34 +00:00
|
|
|
/*!
|
|
|
|
A @c TextureTarget is a framebuffer that can be bound as a texture. So this class
|
|
|
|
handles render-to-texture framebuffer objects.
|
|
|
|
*/
|
2016-02-07 20:42:02 +00:00
|
|
|
class TextureTarget {
|
|
|
|
public:
|
2016-04-20 00:51:34 +00:00
|
|
|
/*!
|
|
|
|
Creates a new texture target.
|
|
|
|
|
2016-05-01 20:17:52 +00:00
|
|
|
Throws ErrorFramebufferIncomplete if creation fails. Leaves both the generated texture and framebuffer bound.
|
2016-04-20 00:51:34 +00:00
|
|
|
|
|
|
|
@param width The width of target to create.
|
|
|
|
@param height The height of target to create.
|
2016-05-01 20:17:52 +00:00
|
|
|
@param texture_unit A texture unit on which to bind the texture.
|
2016-04-20 00:51:34 +00:00
|
|
|
*/
|
2017-01-11 03:08:07 +00:00
|
|
|
TextureTarget(GLsizei width, GLsizei height, GLenum texture_unit, GLint mag_filter);
|
2016-02-07 20:42:02 +00:00
|
|
|
~TextureTarget();
|
|
|
|
|
2016-04-20 00:51:34 +00:00
|
|
|
/*!
|
|
|
|
Binds this target as a framebuffer and sets the @c glViewport accordingly.
|
|
|
|
*/
|
2016-02-07 20:42:02 +00:00
|
|
|
void bind_framebuffer();
|
2016-04-20 00:51:34 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Binds this target as a texture.
|
|
|
|
*/
|
2016-02-07 20:42:02 +00:00
|
|
|
void bind_texture();
|
|
|
|
|
2016-05-01 20:17:52 +00:00
|
|
|
/*!
|
|
|
|
@returns the width of the texture target.
|
|
|
|
*/
|
2017-03-26 18:34:47 +00:00
|
|
|
GLsizei get_width() {
|
2017-11-14 03:04:13 +00:00
|
|
|
return width_;
|
2016-05-01 20:17:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns the height of the texture target.
|
|
|
|
*/
|
2017-03-26 18:34:47 +00:00
|
|
|
GLsizei get_height() {
|
2017-11-14 03:04:13 +00:00
|
|
|
return height_;
|
2016-05-01 20:17:52 +00:00
|
|
|
}
|
|
|
|
|
2016-05-01 17:52:35 +00:00
|
|
|
/*!
|
|
|
|
|
|
|
|
*/
|
2016-05-01 20:17:52 +00:00
|
|
|
void draw(float aspect_ratio);
|
2016-05-01 17:52:35 +00:00
|
|
|
|
2016-03-07 23:55:15 +00:00
|
|
|
enum {
|
|
|
|
ErrorFramebufferIncomplete
|
|
|
|
};
|
|
|
|
|
2016-02-07 20:42:02 +00:00
|
|
|
private:
|
2017-11-14 03:04:13 +00:00
|
|
|
GLuint framebuffer_ = 0, texture_ = 0;
|
|
|
|
GLsizei width_ = 0, height_ = 0;
|
|
|
|
GLsizei expanded_width_ = 0, expanded_height_ = 0;
|
|
|
|
GLenum texture_unit_ = 0;
|
|
|
|
|
|
|
|
std::unique_ptr<Shader> pixel_shader_;
|
|
|
|
GLuint drawing_vertex_array_ = 0, drawing_array_buffer_ = 0;
|
|
|
|
float set_aspect_ratio_ = 0.0f;
|
2016-02-07 20:42:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* TextureTarget_hpp */
|