2016-11-16 04:31:32 +00:00
|
|
|
//
|
2016-11-16 14:57:17 +00:00
|
|
|
// TextureBuilder.hpp
|
2016-11-16 04:31:32 +00:00
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 08/03/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2016-11-16 14:57:17 +00:00
|
|
|
#ifndef Outputs_CRT_Internals_TextureBuilder_hpp
|
|
|
|
#define Outputs_CRT_Internals_TextureBuilder_hpp
|
2016-11-16 04:31:32 +00:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "OpenGL.hpp"
|
|
|
|
#include "CRTConstants.hpp"
|
|
|
|
|
|
|
|
namespace Outputs {
|
|
|
|
namespace CRT {
|
|
|
|
|
|
|
|
/*!
|
2016-11-16 15:14:15 +00:00
|
|
|
Owns an OpenGL texture resource and provides mechanisms to fill it from bottom left to top right
|
2016-11-16 04:31:32 +00:00
|
|
|
with runs of data, ensuring each run is neighboured immediately to the left and right by copies of its
|
|
|
|
first and last pixels.
|
|
|
|
*/
|
2016-11-16 14:57:17 +00:00
|
|
|
class TextureBuilder {
|
2016-11-16 04:31:32 +00:00
|
|
|
public:
|
2016-11-16 15:13:06 +00:00
|
|
|
/// Constructs an instance of InputTextureBuilder that contains a texture of colour depth @c bytes_per_pixel;
|
|
|
|
/// this creates a new texture and binds it to the current active texture unit.
|
2016-11-17 04:26:04 +00:00
|
|
|
TextureBuilder(size_t bytes_per_pixel, GLenum texture_unit);
|
2016-11-16 15:13:06 +00:00
|
|
|
virtual ~TextureBuilder();
|
2016-11-16 04:31:32 +00:00
|
|
|
|
|
|
|
/// Finds the first available space of at least @c required_length pixels in size. Calls must be paired off
|
|
|
|
/// with calls to @c reduce_previous_allocation_to.
|
2016-11-16 05:15:50 +00:00
|
|
|
/// @returns a pointer to the allocated space if any was available; @c nullptr otherwise.
|
|
|
|
uint8_t *allocate_write_area(size_t required_length);
|
2016-11-16 04:31:32 +00:00
|
|
|
|
|
|
|
/// Announces that the owner is finished with the region created by the most recent @c allocate_write_area
|
|
|
|
/// and indicates that its actual final size was @c actual_length.
|
|
|
|
void reduce_previous_allocation_to(size_t actual_length);
|
|
|
|
|
2016-11-16 05:15:50 +00:00
|
|
|
/// @returns the start column for the most recent allocated write area.
|
2016-11-16 04:31:32 +00:00
|
|
|
uint16_t get_last_write_x_position();
|
|
|
|
|
2016-11-16 05:15:50 +00:00
|
|
|
/// @returns the row of the most recent allocated write area.
|
2016-11-16 04:31:32 +00:00
|
|
|
uint16_t get_last_write_y_position();
|
|
|
|
|
2016-11-16 05:15:50 +00:00
|
|
|
/// @returns @c true if all future calls to @c allocate_write_area will fail on account of the input texture
|
|
|
|
/// being full; @c false if calls may succeed.
|
2016-11-16 04:31:32 +00:00
|
|
|
bool is_full();
|
|
|
|
|
2016-11-16 15:13:06 +00:00
|
|
|
/// Updates the currently-bound texture with all new data provided since the last @c submit.
|
|
|
|
void submit();
|
|
|
|
|
2016-11-16 04:31:32 +00:00
|
|
|
private:
|
|
|
|
// where pixel data will be put to the next time a write is requested
|
2016-11-16 15:13:06 +00:00
|
|
|
uint16_t next_write_x_position_, next_write_y_position_;
|
2016-11-16 04:31:32 +00:00
|
|
|
|
|
|
|
// the most recent position returned for pixel data writing
|
2016-11-16 15:13:06 +00:00
|
|
|
uint16_t write_x_position_, write_y_position_;
|
2016-11-16 04:31:32 +00:00
|
|
|
|
|
|
|
// details of the most recent allocation
|
2016-11-16 15:13:06 +00:00
|
|
|
size_t write_target_pointer_;
|
|
|
|
size_t last_allocation_amount_;
|
2016-11-16 04:31:32 +00:00
|
|
|
|
|
|
|
// the buffer size
|
2016-11-16 15:13:06 +00:00
|
|
|
size_t bytes_per_pixel_;
|
2016-11-16 04:31:32 +00:00
|
|
|
|
|
|
|
// the buffer
|
2016-11-16 15:13:06 +00:00
|
|
|
std::vector<uint8_t> image_;
|
|
|
|
GLuint texture_name_;
|
2016-11-16 04:31:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-16 15:14:56 +00:00
|
|
|
#endif /* Outputs_CRT_Internals_TextureBuilder_hpp */
|