2018-11-07 03:23:38 +00:00
|
|
|
//
|
|
|
|
// ScanTarget.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 05/11/2018.
|
|
|
|
// Copyright © 2018 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ScanTarget_hpp
|
|
|
|
#define ScanTarget_hpp
|
|
|
|
|
2019-02-21 01:21:17 +00:00
|
|
|
#include "../Log.hpp"
|
2019-03-05 02:54:50 +00:00
|
|
|
#include "../DisplayMetrics.hpp"
|
2020-07-23 02:16:47 +00:00
|
|
|
#include "../ScanTargets/BufferingScanTarget.hpp"
|
2019-02-21 01:21:17 +00:00
|
|
|
|
2018-11-08 03:53:46 +00:00
|
|
|
#include "OpenGL.hpp"
|
2018-11-11 20:11:32 +00:00
|
|
|
#include "Primitives/TextureTarget.hpp"
|
2018-11-19 02:39:11 +00:00
|
|
|
#include "Primitives/Rectangle.hpp"
|
2018-11-07 03:23:38 +00:00
|
|
|
|
2018-11-27 03:34:31 +00:00
|
|
|
#include "../../SignalProcessing/FIRFilter.hpp"
|
|
|
|
|
2018-11-07 03:23:38 +00:00
|
|
|
#include <array>
|
|
|
|
#include <atomic>
|
|
|
|
#include <cstdint>
|
2019-03-05 02:54:50 +00:00
|
|
|
#include <chrono>
|
2018-11-24 03:34:38 +00:00
|
|
|
#include <list>
|
|
|
|
#include <memory>
|
2018-11-12 02:41:13 +00:00
|
|
|
#include <string>
|
2018-11-07 03:23:38 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Outputs {
|
|
|
|
namespace Display {
|
|
|
|
namespace OpenGL {
|
|
|
|
|
2020-07-22 02:49:46 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Provides a ScanTarget that uses OpenGL to render its output;
|
|
|
|
this uses various internal buffers so that the only geometry
|
|
|
|
drawn to the target framebuffer is a quad.
|
|
|
|
*/
|
2020-08-08 02:03:27 +00:00
|
|
|
class ScanTarget: public Outputs::Display::BufferingScanTarget { // TODO: use private inheritance and expose only display_metrics() and a custom cast?
|
2020-07-22 02:49:46 +00:00
|
|
|
public:
|
|
|
|
ScanTarget(GLuint target_framebuffer = 0, float output_gamma = 2.2f);
|
|
|
|
~ScanTarget();
|
|
|
|
|
|
|
|
void set_target_framebuffer(GLuint);
|
|
|
|
|
|
|
|
/*! Pushes the current state of output to the target framebuffer. */
|
|
|
|
void draw(int output_width, int output_height);
|
|
|
|
/*! Processes all the latest input, at a resolution suitable for later output to a framebuffer of the specified size. */
|
|
|
|
void update(int output_width, int output_height);
|
|
|
|
|
|
|
|
private:
|
2020-07-27 02:46:03 +00:00
|
|
|
static constexpr int LineBufferWidth = 2048;
|
|
|
|
static constexpr int LineBufferHeight = 2048;
|
|
|
|
|
2020-07-22 02:49:46 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
struct OpenGLVersionDumper {
|
|
|
|
OpenGLVersionDumper() {
|
|
|
|
// Note the OpenGL version, as the first thing this class does prior to construction.
|
|
|
|
LOG("Constructing scan target with OpenGL " << glGetString(GL_VERSION) << "; shading language version " << glGetString(GL_SHADING_LANGUAGE_VERSION));
|
|
|
|
}
|
|
|
|
} dumper_;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GLuint target_framebuffer_;
|
|
|
|
const float output_gamma_;
|
|
|
|
|
|
|
|
int resolution_reduction_level_ = 1;
|
|
|
|
int output_height_ = 0;
|
|
|
|
|
|
|
|
size_t lines_submitted_ = 0;
|
|
|
|
std::chrono::high_resolution_clock::time_point line_submission_begin_time_;
|
|
|
|
|
2018-11-19 02:39:11 +00:00
|
|
|
// Contains the first composition of scans into lines;
|
|
|
|
// they're accumulated prior to output to allow for continuous
|
2019-01-02 02:02:21 +00:00
|
|
|
// application of any necessary conversions — e.g. composite processing.
|
2018-11-11 21:22:14 +00:00
|
|
|
TextureTarget unprocessed_line_texture_;
|
2018-11-19 02:39:11 +00:00
|
|
|
|
2019-02-09 21:54:31 +00:00
|
|
|
// Contains pre-lowpass-filtered chrominance information that is
|
|
|
|
// part-QAM-demoduled, if dealing with a QAM data source.
|
|
|
|
std::unique_ptr<TextureTarget> qam_chroma_texture_;
|
|
|
|
|
2018-11-19 02:39:11 +00:00
|
|
|
// Scans are accumulated to the accumulation texture; the full-display
|
|
|
|
// rectangle is used to ensure untouched pixels properly decay.
|
|
|
|
std::unique_ptr<TextureTarget> accumulation_texture_;
|
|
|
|
Rectangle full_display_rectangle_;
|
2018-11-21 00:51:11 +00:00
|
|
|
bool stencil_is_valid_ = false;
|
2018-11-19 02:39:11 +00:00
|
|
|
|
2018-11-12 23:47:55 +00:00
|
|
|
// OpenGL storage handles for buffer data.
|
|
|
|
GLuint scan_buffer_name_ = 0, scan_vertex_array_ = 0;
|
|
|
|
GLuint line_buffer_name_ = 0, line_vertex_array_ = 0;
|
|
|
|
|
2018-11-13 00:10:48 +00:00
|
|
|
template <typename T> void allocate_buffer(const T &array, GLuint &buffer_name, GLuint &vertex_array_name);
|
2018-11-14 02:15:33 +00:00
|
|
|
template <typename T> void patch_buffer(const T &array, GLuint target, uint16_t submit_pointer, uint16_t read_pointer);
|
2018-11-12 23:47:55 +00:00
|
|
|
|
2018-11-09 04:02:36 +00:00
|
|
|
GLuint write_area_texture_name_ = 0;
|
|
|
|
bool texture_exists_ = false;
|
2018-11-07 03:23:38 +00:00
|
|
|
|
|
|
|
// Receives scan target modals.
|
2018-11-30 03:41:54 +00:00
|
|
|
void setup_pipeline();
|
2018-11-12 02:41:13 +00:00
|
|
|
|
|
|
|
enum class ShaderType {
|
2019-01-14 04:07:50 +00:00
|
|
|
Composition,
|
2019-02-09 21:54:31 +00:00
|
|
|
Conversion,
|
|
|
|
QAMSeparation
|
2018-11-12 02:41:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Calls @c taret.enable_vertex_attribute_with_pointer to attach all
|
|
|
|
globals for shaders of @c type to @c target.
|
|
|
|
*/
|
2018-11-24 21:06:26 +00:00
|
|
|
static void enable_vertex_attributes(ShaderType type, Shader &target);
|
2019-02-11 03:39:24 +00:00
|
|
|
void set_uniforms(ShaderType type, Shader &target) const;
|
|
|
|
std::vector<std::string> bindings(ShaderType type) const;
|
2018-11-12 04:23:42 +00:00
|
|
|
|
2018-11-13 01:15:38 +00:00
|
|
|
GLsync fence_ = nullptr;
|
2019-03-08 00:28:32 +00:00
|
|
|
std::atomic_flag is_drawing_to_accumulation_buffer_;
|
2018-11-13 23:33:44 +00:00
|
|
|
|
2018-11-14 02:15:33 +00:00
|
|
|
std::unique_ptr<Shader> input_shader_;
|
|
|
|
std::unique_ptr<Shader> output_shader_;
|
2019-02-09 21:54:31 +00:00
|
|
|
std::unique_ptr<Shader> qam_separation_shader_;
|
|
|
|
|
2019-01-14 03:49:01 +00:00
|
|
|
/*!
|
|
|
|
Produces a shader that composes fragment of the input stream to a single buffer,
|
|
|
|
normalising the data into one of four forms: RGB, 8-bit luminance,
|
|
|
|
phase-linked luminance or luminance+phase offset.
|
|
|
|
*/
|
2019-01-23 03:20:12 +00:00
|
|
|
std::unique_ptr<Shader> composition_shader() const;
|
2019-01-14 03:49:01 +00:00
|
|
|
/*!
|
|
|
|
Produces a shader that reads from a composition buffer and converts to host
|
|
|
|
output RGB, decoding composite or S-Video as necessary.
|
|
|
|
*/
|
2019-01-23 03:20:12 +00:00
|
|
|
std::unique_ptr<Shader> conversion_shader() const;
|
2019-02-09 21:54:31 +00:00
|
|
|
/*!
|
|
|
|
Produces a shader that writes separated but not-yet filtered QAM components
|
|
|
|
from the unprocessed line texture to the QAM chroma texture, at a fixed
|
|
|
|
size of four samples per colour clock, point sampled.
|
|
|
|
*/
|
|
|
|
std::unique_ptr<Shader> qam_separation_shader() const;
|
|
|
|
|
2019-02-27 03:21:49 +00:00
|
|
|
void set_sampling_window(int output_Width, int output_height, Shader &target);
|
|
|
|
|
2019-02-09 21:54:31 +00:00
|
|
|
std::string sampling_function() const;
|
2019-06-03 19:57:31 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
@returns true if the current display type is a 'soft' one, i.e. one in which
|
|
|
|
contrast tends to be low, such as a composite colour display.
|
|
|
|
*/
|
|
|
|
bool is_soft_display_type();
|
2020-07-24 02:54:40 +00:00
|
|
|
|
2020-07-27 02:46:03 +00:00
|
|
|
// Storage for the various buffers.
|
2020-07-24 02:54:40 +00:00
|
|
|
std::vector<uint8_t> write_area_texture_;
|
2020-07-29 02:36:57 +00:00
|
|
|
std::array<Scan, LineBufferHeight*5> scan_buffer_;
|
2020-07-27 02:46:03 +00:00
|
|
|
std::array<Line, LineBufferHeight> line_buffer_;
|
|
|
|
std::array<LineMetadata, LineBufferHeight> line_metadata_buffer_;
|
2018-11-07 03:23:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ScanTarget_hpp */
|