2018-11-12 02:41:13 +00:00
|
|
|
//
|
|
|
|
// ScanTargetVertexArrayAttributs.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 11/11/2018.
|
|
|
|
// Copyright © 2018 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "ScanTarget.hpp"
|
|
|
|
|
|
|
|
using namespace Outputs::Display::OpenGL;
|
|
|
|
|
2018-11-12 23:56:54 +00:00
|
|
|
std::string ScanTarget::glsl_globals(ShaderType type) {
|
2018-11-12 02:41:13 +00:00
|
|
|
switch(type) {
|
|
|
|
case ShaderType::Scan:
|
|
|
|
return
|
2018-11-12 04:23:42 +00:00
|
|
|
"#version 150\n"
|
|
|
|
|
2018-11-12 02:41:13 +00:00
|
|
|
"uniform vec2 scale;"
|
|
|
|
"uniform float rowHeight;"
|
|
|
|
"uniform mat3 lumaChromaToRGB;"
|
|
|
|
"uniform mat3 rgbToLumaChroma;"
|
2018-11-14 02:15:33 +00:00
|
|
|
"uniform float processingWidth;"
|
2018-11-12 02:41:13 +00:00
|
|
|
|
|
|
|
"in vec2 startPoint;"
|
|
|
|
"in float startDataX;"
|
|
|
|
"in float startCompositeAngle;"
|
|
|
|
|
|
|
|
"in vec2 endPoint;"
|
|
|
|
"in float endDataX;"
|
|
|
|
"in float endCompositeAngle;"
|
|
|
|
|
|
|
|
"in float dataY;"
|
2018-11-22 18:22:04 +00:00
|
|
|
"in float lineY;"
|
|
|
|
|
|
|
|
"uniform usampler2D textureName;";
|
2018-11-12 04:23:42 +00:00
|
|
|
|
2018-11-12 23:56:54 +00:00
|
|
|
case ShaderType::Line:
|
|
|
|
return
|
|
|
|
"#version 150\n"
|
|
|
|
|
|
|
|
"uniform vec2 scale;"
|
|
|
|
"uniform float rowHeight;"
|
2018-11-14 02:15:33 +00:00
|
|
|
"uniform float processingWidth;"
|
2018-11-12 23:56:54 +00:00
|
|
|
|
|
|
|
"in vec2 startPoint;"
|
2018-11-14 02:15:33 +00:00
|
|
|
"in vec2 endPoint;"
|
|
|
|
|
2018-11-22 18:22:04 +00:00
|
|
|
"in float lineY;"
|
|
|
|
|
|
|
|
"uniform sampler2D textureName;"
|
|
|
|
"uniform vec2 origin;"
|
|
|
|
"uniform vec2 size;";
|
2018-11-12 23:56:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-16 02:21:54 +00:00
|
|
|
std::string ScanTarget::glsl_default_vertex_shader(ShaderType type) {
|
2018-11-13 01:15:38 +00:00
|
|
|
switch(type) {
|
|
|
|
case ShaderType::Scan:
|
2018-11-13 03:52:26 +00:00
|
|
|
return
|
|
|
|
"out vec2 textureCoordinate;"
|
|
|
|
|
|
|
|
"void main(void) {"
|
|
|
|
"float lateral = float(gl_VertexID & 1);"
|
|
|
|
"float longitudinal = float((gl_VertexID & 2) >> 1);"
|
|
|
|
|
|
|
|
"textureCoordinate = vec2(mix(startDataX, endDataX, lateral), dataY) / textureSize(textureName, 0);"
|
|
|
|
|
2018-11-14 02:15:33 +00:00
|
|
|
"vec2 eyePosition = vec2(mix(startPoint.x, endPoint.x, lateral) * processingWidth, lineY + longitudinal) / vec2(scale.x, 2048.0);"
|
2018-11-13 03:52:26 +00:00
|
|
|
"gl_Position = vec4(eyePosition*2 - vec2(1.0), 0.0, 1.0);"
|
|
|
|
"}";
|
2018-11-13 01:15:38 +00:00
|
|
|
|
|
|
|
case ShaderType::Line:
|
2018-11-12 23:56:54 +00:00
|
|
|
return
|
2018-11-14 02:15:33 +00:00
|
|
|
"out vec2 textureCoordinate;"
|
|
|
|
|
2018-11-12 04:23:42 +00:00
|
|
|
"void main(void) {"
|
|
|
|
"float lateral = float(gl_VertexID & 1);"
|
|
|
|
"float longitudinal = float((gl_VertexID & 2) >> 1);"
|
|
|
|
|
2018-11-17 22:31:32 +00:00
|
|
|
"textureCoordinate = vec2(lateral * processingWidth, lineY + 0.5) / vec2(1.0, textureSize(textureName, 0).y);"
|
2018-11-14 02:15:33 +00:00
|
|
|
|
2018-11-12 23:23:45 +00:00
|
|
|
"vec2 centrePoint = mix(startPoint, endPoint, lateral) / scale;"
|
|
|
|
"vec2 height = normalize(endPoint - startPoint).yx * (longitudinal - 0.5) * rowHeight;"
|
2018-11-22 18:22:04 +00:00
|
|
|
"vec2 eyePosition = vec2(-1.0, 1.0) + vec2(2.0, -2.0) * (((centrePoint + height) - origin) / size);"
|
2018-11-12 23:28:09 +00:00
|
|
|
"gl_Position = vec4(eyePosition, 0.0, 1.0);"
|
2018-11-12 04:23:42 +00:00
|
|
|
"}";
|
2018-11-13 01:15:38 +00:00
|
|
|
}
|
2018-11-12 02:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScanTarget::enable_vertex_attributes(ShaderType type, Shader &target) {
|
|
|
|
switch(type) {
|
|
|
|
case ShaderType::Scan:
|
|
|
|
for(int c = 0; c < 2; ++c) {
|
|
|
|
const std::string prefix = c ? "end" : "start";
|
|
|
|
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
prefix + "Point",
|
|
|
|
2, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Scan),
|
|
|
|
reinterpret_cast<void *>(offsetof(Scan, scan.end_points[c].x)),
|
|
|
|
1);
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
prefix + "DataX",
|
|
|
|
1, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Scan),
|
|
|
|
reinterpret_cast<void *>(offsetof(Scan, scan.end_points[c].data_offset)),
|
|
|
|
1);
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
prefix + "CompositeAngle",
|
|
|
|
1, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Scan),
|
|
|
|
reinterpret_cast<void *>(offsetof(Scan, scan.end_points[c].composite_angle)),
|
|
|
|
1);
|
|
|
|
}
|
|
|
|
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
"dataY",
|
|
|
|
1, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Scan),
|
|
|
|
reinterpret_cast<void *>(offsetof(Scan, data_y)),
|
|
|
|
1);
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
"lineY",
|
|
|
|
1, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Scan),
|
|
|
|
reinterpret_cast<void *>(offsetof(Scan, line)),
|
|
|
|
1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ShaderType::Line:
|
|
|
|
for(int c = 0; c < 2; ++c) {
|
|
|
|
const std::string prefix = c ? "end" : "start";
|
|
|
|
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
prefix + "Point",
|
|
|
|
2, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Line),
|
|
|
|
reinterpret_cast<void *>(offsetof(Line, end_points[c].x)),
|
|
|
|
1);
|
|
|
|
}
|
2018-11-14 02:15:33 +00:00
|
|
|
|
|
|
|
target.enable_vertex_attribute_with_pointer(
|
|
|
|
"lineY",
|
|
|
|
1, GL_UNSIGNED_SHORT, GL_FALSE,
|
|
|
|
sizeof(Line),
|
|
|
|
reinterpret_cast<void *>(offsetof(Line, line)),
|
|
|
|
1);
|
2018-11-12 02:41:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-11-16 02:02:46 +00:00
|
|
|
|
2018-11-22 19:36:46 +00:00
|
|
|
std::unique_ptr<Shader> ScanTarget::input_shader(InputDataType input_data_type, DisplayType display_type) {
|
2018-11-16 02:02:46 +00:00
|
|
|
std::string fragment_shader =
|
|
|
|
"#version 150\n"
|
|
|
|
|
|
|
|
"out vec4 fragColour;"
|
|
|
|
"in vec2 textureCoordinate;";
|
|
|
|
|
|
|
|
switch(input_data_type) {
|
|
|
|
case InputDataType::Luminance1:
|
|
|
|
fragment_shader +=
|
2018-11-16 02:21:54 +00:00
|
|
|
"uniform usampler2D textureName;"
|
2018-11-16 02:02:46 +00:00
|
|
|
"void main(void) {";
|
|
|
|
|
2018-11-22 19:36:46 +00:00
|
|
|
switch(display_type) {
|
|
|
|
case DisplayType::RGB:
|
2018-11-16 02:02:46 +00:00
|
|
|
fragment_shader += "fragColour = vec4(texture(textureName, textureCoordinate).rrr, 1.0);";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fragment_shader += "fragColour = vec4(texture(textureName, textureCoordinate).r, 0.0, 0.0, 1.0);";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fragment_shader += "}";
|
|
|
|
break;
|
|
|
|
|
2018-11-16 02:21:54 +00:00
|
|
|
case InputDataType::Luminance8:
|
|
|
|
break;
|
|
|
|
|
2018-11-16 02:02:46 +00:00
|
|
|
// SVideo,
|
|
|
|
// CompositeColour,
|
|
|
|
// CompositeMonochrome
|
|
|
|
|
|
|
|
case InputDataType::Phase8Luminance8:
|
|
|
|
return nullptr;
|
|
|
|
// fragment_shader +=
|
|
|
|
// "uniform sampler2D textureName;"
|
|
|
|
// "void main(void) {";
|
|
|
|
//
|
2018-11-22 19:36:46 +00:00
|
|
|
// switch(display_type) {
|
2018-11-16 02:02:46 +00:00
|
|
|
// default: return nullptr;
|
|
|
|
//
|
|
|
|
// case OutputType::SVideo:
|
|
|
|
// break;
|
|
|
|
//// CompositeColour,
|
|
|
|
//// CompositeMonochrome
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// fragment_shader += "}";
|
|
|
|
// break;
|
|
|
|
|
2018-11-16 02:32:22 +00:00
|
|
|
// TODO: write encoding functions for RGB -> composite/s-video for the RGB inputs.
|
|
|
|
|
2018-11-16 02:02:46 +00:00
|
|
|
case InputDataType::Red1Green1Blue1:
|
|
|
|
fragment_shader +=
|
|
|
|
"uniform usampler2D textureName;"
|
|
|
|
"void main(void) {"
|
|
|
|
"uint textureValue = texture(textureName, textureCoordinate).r;"
|
|
|
|
"fragColour = vec4(uvec3(textureValue) & uvec3(4u, 2u, 1u), 1.0);"
|
|
|
|
"}";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case InputDataType::Red2Green2Blue2:
|
2018-11-16 02:32:22 +00:00
|
|
|
fragment_shader +=
|
|
|
|
"uniform usampler2D textureName;"
|
|
|
|
"void main(void) {"
|
|
|
|
"uint textureValue = texture(textureName, textureCoordinate).r;"
|
|
|
|
"fragColour = vec4(vec3(float((textureValue >> 4) & 3u), float((textureValue >> 2) & 3u), float(textureValue & 3u)) / 3.0, 1.0);"
|
|
|
|
"}";
|
2018-11-16 02:02:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case InputDataType::Red4Green4Blue4:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case InputDataType::Red8Green8Blue8:
|
|
|
|
fragment_shader +=
|
2018-11-16 02:21:54 +00:00
|
|
|
"uniform usampler2D textureName;"
|
2018-11-16 02:02:46 +00:00
|
|
|
"void main(void) {"
|
2018-11-16 02:21:54 +00:00
|
|
|
"fragColour = vec4(texture(textureName, textureCoordinate).rgb / vec3(255.0), 1.0);"
|
2018-11-16 02:02:46 +00:00
|
|
|
"}";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::unique_ptr<Shader>(new Shader(
|
2018-11-16 02:21:54 +00:00
|
|
|
glsl_globals(ShaderType::Scan) + glsl_default_vertex_shader(ShaderType::Scan),
|
2018-11-16 02:02:46 +00:00
|
|
|
fragment_shader
|
|
|
|
));
|
|
|
|
}
|