2016-02-07 20:42:02 +00:00
|
|
|
//
|
|
|
|
// TextureTarget.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 07/02/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-02-07 20:42:02 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef TextureTarget_hpp
|
|
|
|
#define TextureTarget_hpp
|
|
|
|
|
2019-01-26 00:19:23 +00:00
|
|
|
#include "../OpenGL.hpp"
|
2018-11-08 00:11:01 +00:00
|
|
|
#include "Shader.hpp"
|
2016-05-01 17:52:35 +00:00
|
|
|
#include <memory>
|
2016-02-07 20:42:02 +00:00
|
|
|
|
2018-11-11 20:11:32 +00:00
|
|
|
namespace Outputs {
|
|
|
|
namespace Display {
|
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
|
|
|
/*!
|
2018-11-19 02:39:11 +00:00
|
|
|
Creates a new texture target. Contents are initially undefined.
|
2016-04-20 00:51:34 +00:00
|
|
|
|
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.
|
2018-11-17 20:51:12 +00:00
|
|
|
@param has_stencil_buffer A 1-bit stencil buffer is attached if this is @c true; no stencil buffer is attached otherwise.
|
2016-04-20 00:51:34 +00:00
|
|
|
*/
|
2018-11-17 20:51:12 +00:00
|
|
|
TextureTarget(GLsizei width, GLsizei height, GLenum texture_unit, GLint mag_filter, bool has_stencil_buffer);
|
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.
|
|
|
|
*/
|
2018-11-24 03:33:28 +00:00
|
|
|
void bind_texture() const;
|
2016-02-07 20:42:02 +00:00
|
|
|
|
2016-05-01 20:17:52 +00:00
|
|
|
/*!
|
|
|
|
@returns the width of the texture target.
|
|
|
|
*/
|
2018-11-24 03:33:28 +00:00
|
|
|
GLsizei get_width() const {
|
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.
|
|
|
|
*/
|
2018-11-24 03:33:28 +00:00
|
|
|
GLsizei get_height() const {
|
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
|
|
|
/*!
|
2018-06-15 00:40:27 +00:00
|
|
|
Draws this texture to the currently-bound framebuffer, which has the aspect ratio
|
|
|
|
@c aspect_ratio. This texture will fill the height of the frame buffer, and pick
|
2018-07-11 23:52:55 +00:00
|
|
|
an appropriate width based on the aspect ratio.
|
2018-06-15 00:40:27 +00:00
|
|
|
|
|
|
|
@c colour_threshold sets a threshold test that each colour must satisfy to be
|
|
|
|
output. A threshold of 0.0f means that all colours will pass through. A threshold
|
|
|
|
of 0.5f means that only colour components above 0.5f will pass through, with
|
|
|
|
0.5f being substituted elsewhere. This provides a way to ensure that the sort of
|
|
|
|
persistent low-value errors that can result from an IIR are hidden.
|
2016-05-01 17:52:35 +00:00
|
|
|
*/
|
2018-11-24 03:33:28 +00:00
|
|
|
void draw(float aspect_ratio, float colour_threshold = 0.0f) const;
|
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:
|
2018-11-19 03:22:43 +00:00
|
|
|
GLuint framebuffer_ = 0, texture_ = 0, renderbuffer_ = 0;
|
2017-11-14 03:04:13 +00:00
|
|
|
GLsizei width_ = 0, height_ = 0;
|
|
|
|
GLsizei expanded_width_ = 0, expanded_height_ = 0;
|
|
|
|
GLenum texture_unit_ = 0;
|
|
|
|
|
2018-11-24 03:33:28 +00:00
|
|
|
mutable std::unique_ptr<Shader> pixel_shader_;
|
|
|
|
mutable GLuint drawing_vertex_array_ = 0, drawing_array_buffer_ = 0;
|
|
|
|
mutable float set_aspect_ratio_ = 0.0f;
|
2018-06-15 00:40:27 +00:00
|
|
|
|
2018-11-24 03:33:28 +00:00
|
|
|
mutable GLint threshold_uniform_;
|
2016-02-07 20:42:02 +00:00
|
|
|
};
|
|
|
|
|
2018-11-11 20:11:32 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-07 20:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* TextureTarget_hpp */
|