mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-23 03:32:32 +00:00
Finished consolidation into OutputShader. With its documentation yet to update.
This commit is contained in:
parent
496d979aca
commit
8849dc3265
@ -580,58 +580,6 @@ char *OpenGLOutputBuilder::get_chrominance_filter_fragment_shader()
|
|||||||
|
|
||||||
#pragma mark - Intermediate vertex shaders (i.e. from intermediate line layout to intermediate line layout)
|
#pragma mark - Intermediate vertex shaders (i.e. from intermediate line layout to intermediate line layout)
|
||||||
|
|
||||||
#pragma mark - Output fragment shaders; RGB and from composite
|
|
||||||
|
|
||||||
char *OpenGLOutputBuilder::get_rgb_output_fragment_shader()
|
|
||||||
{
|
|
||||||
const char *rgb_shader = _rgb_shader;
|
|
||||||
if(!_rgb_shader)
|
|
||||||
{
|
|
||||||
rgb_shader =
|
|
||||||
"vec3 rgb_sample(usampler2D sampler, vec2 coordinate, vec2 icoordinate)"
|
|
||||||
"{"
|
|
||||||
"return texture(sampler, coordinate).rgb / vec3(255.0);"
|
|
||||||
"}";
|
|
||||||
}
|
|
||||||
|
|
||||||
char *result = get_output_fragment_shader(rgb_shader, "uniform usampler2D texID;",
|
|
||||||
"vec3 colour = rgb_sample(texID, srcCoordinatesVarying, iSrcCoordinatesVarying);");
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *OpenGLOutputBuilder::get_composite_output_fragment_shader()
|
|
||||||
{
|
|
||||||
return get_output_fragment_shader("",
|
|
||||||
"uniform sampler2D texID;",
|
|
||||||
"vec3 colour = texture(texID, srcCoordinatesVarying).rgb;"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *OpenGLOutputBuilder::get_output_fragment_shader(const char *sampling_function, const char *header, const char *fragColour_function)
|
|
||||||
{
|
|
||||||
char *result;
|
|
||||||
asprintf(&result,
|
|
||||||
"#version 150\n"
|
|
||||||
|
|
||||||
"in float lateralVarying;"
|
|
||||||
"in vec2 srcCoordinatesVarying;"
|
|
||||||
"in vec2 iSrcCoordinatesVarying;"
|
|
||||||
|
|
||||||
"out vec4 fragColour;"
|
|
||||||
|
|
||||||
"%s\n"
|
|
||||||
"%s\n"
|
|
||||||
"void main(void)"
|
|
||||||
"{"
|
|
||||||
"\n%s\n"
|
|
||||||
"fragColour = vec4(colour, 0.5*cos(lateralVarying));"
|
|
||||||
"}",
|
|
||||||
header, sampling_function, fragColour_function);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Program compilation
|
#pragma mark - Program compilation
|
||||||
|
|
||||||
std::unique_ptr<OpenGL::Shader> OpenGLOutputBuilder::prepare_intermediate_shader(const char *input_position, const char *header, char *fragment_shader, GLenum texture_unit, bool extends)
|
std::unique_ptr<OpenGL::Shader> OpenGLOutputBuilder::prepare_intermediate_shader(const char *input_position, const char *header, char *fragment_shader, GLenum texture_unit, bool extends)
|
||||||
@ -695,24 +643,26 @@ void OpenGLOutputBuilder::prepare_source_vertex_array()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<OpenGL::OutputShader> OpenGLOutputBuilder::prepare_output_shader(char *fragment_shader, bool use_usampler, GLenum source_texture_unit)
|
|
||||||
{
|
|
||||||
std::unique_ptr<OpenGL::OutputShader> shader_program;
|
|
||||||
|
|
||||||
shader_program = OpenGL::OutputShader::make_shader(fragment_shader, use_usampler);
|
|
||||||
shader_program->set_source_texture_unit(source_texture_unit);
|
|
||||||
|
|
||||||
return shader_program;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLOutputBuilder::prepare_rgb_output_shader()
|
void OpenGLOutputBuilder::prepare_rgb_output_shader()
|
||||||
{
|
{
|
||||||
rgb_shader_program = prepare_output_shader(get_rgb_output_fragment_shader(), true, source_data_texture_unit);
|
const char *rgb_shader = _rgb_shader;
|
||||||
|
if(!_rgb_shader)
|
||||||
|
{
|
||||||
|
rgb_shader =
|
||||||
|
"vec3 rgb_sample(usampler2D sampler, vec2 coordinate, vec2 icoordinate)"
|
||||||
|
"{"
|
||||||
|
"return texture(sampler, coordinate).rgb / vec3(255.0);"
|
||||||
|
"}";
|
||||||
|
}
|
||||||
|
|
||||||
|
rgb_shader_program = OpenGL::OutputShader::make_shader(rgb_shader, "rgb_sample(texID, srcCoordinatesVarying, iSrcCoordinatesVarying)", true);
|
||||||
|
rgb_shader_program->set_source_texture_unit(source_data_texture_unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLOutputBuilder::prepare_composite_output_shader()
|
void OpenGLOutputBuilder::prepare_composite_output_shader()
|
||||||
{
|
{
|
||||||
composite_output_shader_program = prepare_output_shader(get_composite_output_fragment_shader(), false, filtered_texture_unit);
|
composite_output_shader_program = OpenGL::OutputShader::make_shader("", "texture(texID, srcCoordinatesVarying).rgb", false);
|
||||||
|
composite_output_shader_program->set_source_texture_unit(filtered_texture_unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLOutputBuilder::prepare_output_vertex_array()
|
void OpenGLOutputBuilder::prepare_output_vertex_array()
|
||||||
|
@ -63,14 +63,6 @@ class OpenGLOutputBuilder {
|
|||||||
// transient buffers indicating composite data not yet decoded
|
// transient buffers indicating composite data not yet decoded
|
||||||
uint16_t _composite_src_output_y, _cleared_composite_output_y;
|
uint16_t _composite_src_output_y, _cleared_composite_output_y;
|
||||||
|
|
||||||
char *get_output_vertex_shader(const char *header);
|
|
||||||
char *get_rgb_output_vertex_shader();
|
|
||||||
char *get_composite_output_vertex_shader();
|
|
||||||
|
|
||||||
char *get_output_fragment_shader(const char *sampling_function, const char *header, const char *fragColour_function);
|
|
||||||
char *get_rgb_output_fragment_shader();
|
|
||||||
char *get_composite_output_fragment_shader();
|
|
||||||
|
|
||||||
char *get_input_vertex_shader(const char *input_position, const char *header);
|
char *get_input_vertex_shader(const char *input_position, const char *header);
|
||||||
char *get_input_fragment_shader();
|
char *get_input_fragment_shader();
|
||||||
|
|
||||||
|
@ -23,8 +23,10 @@ namespace {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<OutputShader> OutputShader::make_shader(const char *fragment_shader, bool use_usampler)
|
std::unique_ptr<OutputShader> OutputShader::make_shader(const char *fragment_methods, const char *output_colour, bool use_usampler)
|
||||||
{
|
{
|
||||||
|
const char *sampler_type = use_usampler ? "usampler2D" : "sampler2D";
|
||||||
|
|
||||||
char *vertex_shader;
|
char *vertex_shader;
|
||||||
asprintf(&vertex_shader,
|
asprintf(&vertex_shader,
|
||||||
"#version 150\n"
|
"#version 150\n"
|
||||||
@ -54,10 +56,31 @@ std::unique_ptr<OutputShader> OutputShader::make_shader(const char *fragment_sha
|
|||||||
"vec2 floatingPosition = (position / positionConversion) + lateral * scanNormal;"
|
"vec2 floatingPosition = (position / positionConversion) + lateral * scanNormal;"
|
||||||
"vec2 mappedPosition = (floatingPosition - boundsOrigin) / boundsSize;"
|
"vec2 mappedPosition = (floatingPosition - boundsOrigin) / boundsSize;"
|
||||||
"gl_Position = vec4(mappedPosition.x * 2.0 - 1.0, 1.0 - mappedPosition.y * 2.0, 0.0, 1.0);"
|
"gl_Position = vec4(mappedPosition.x * 2.0 - 1.0, 1.0 - mappedPosition.y * 2.0, 0.0, 1.0);"
|
||||||
"}", use_usampler ? "usampler2D" : "sampler2D");
|
"}", sampler_type);
|
||||||
|
|
||||||
|
char *fragment_shader;
|
||||||
|
asprintf(&fragment_shader,
|
||||||
|
"#version 150\n"
|
||||||
|
|
||||||
|
"in float lateralVarying;"
|
||||||
|
"in vec2 srcCoordinatesVarying;"
|
||||||
|
"in vec2 iSrcCoordinatesVarying;"
|
||||||
|
|
||||||
|
"out vec4 fragColour;"
|
||||||
|
|
||||||
|
"uniform %s texID;"
|
||||||
|
|
||||||
|
"\n%s\n"
|
||||||
|
|
||||||
|
"void main(void)"
|
||||||
|
"{"
|
||||||
|
"fragColour = vec4(%s, 0.6*cos(lateralVarying));"
|
||||||
|
"}",
|
||||||
|
sampler_type, fragment_methods, output_colour);
|
||||||
|
|
||||||
std::unique_ptr<OutputShader> result = std::unique_ptr<OutputShader>(new OutputShader(vertex_shader, fragment_shader, bindings));
|
std::unique_ptr<OutputShader> result = std::unique_ptr<OutputShader>(new OutputShader(vertex_shader, fragment_shader, bindings));
|
||||||
free(vertex_shader);
|
free(vertex_shader);
|
||||||
|
free(fragment_shader);
|
||||||
|
|
||||||
result->boundsSizeUniform = result->get_uniform_location("boundsSize");
|
result->boundsSizeUniform = result->get_uniform_location("boundsSize");
|
||||||
result->boundsOriginUniform = result->get_uniform_location("boundsOrigin");
|
result->boundsOriginUniform = result->get_uniform_location("boundsOrigin");
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
|
|
||||||
@returns an instance of OutputShader.
|
@returns an instance of OutputShader.
|
||||||
*/
|
*/
|
||||||
static std::unique_ptr<OutputShader> make_shader(const char *fragment_shader, bool use_usampler);
|
static std::unique_ptr<OutputShader> make_shader(const char *fragment_methods, const char *output_colour, bool use_usampler);
|
||||||
using Shader::Shader;
|
using Shader::Shader;
|
||||||
|
|
||||||
void set_output_size(unsigned int output_width, unsigned int output_height, Outputs::CRT::Rect visible_area);
|
void set_output_size(unsigned int output_width, unsigned int output_height, Outputs::CRT::Rect visible_area);
|
||||||
|
Loading…
Reference in New Issue
Block a user