mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-23 20:29:42 +00:00
Switched to integer textures, likely to simplify for most use cases.
This commit is contained in:
parent
a6ef78862c
commit
729fddea1c
@ -61,11 +61,10 @@ void Machine::setup_output()
|
||||
_crt->set_rgb_sampling_function(
|
||||
"vec4 rgb_sample(vec2 coordinate)"
|
||||
"{"
|
||||
"float texValue = texture(texID, coordinate).r;"
|
||||
"return vec4(step(4.0/256.0, mod(texValue, 8.0/256.0)), step(2.0/256.0, mod(texValue, 4.0/256.0)), step(1.0/256.0, mod(texValue, 2.0/256.0)), 1.0);"
|
||||
"uint texValue = texture(texID, coordinate).r;"
|
||||
"return vec4(texValue & 4u, texValue & 2u, texValue & 1u, 1.0);"
|
||||
"}");
|
||||
_crt->set_output_device(Outputs::CRT::Monitor);
|
||||
// _crt->set_visible_area(Outputs::Rect(0.23108f, 0.0f, 0.8125f, 0.98f)); //1875
|
||||
|
||||
_speaker.set_input_rate(125000);
|
||||
}
|
||||
|
@ -58,15 +58,27 @@ OpenGLOutputBuilder::~OpenGLOutputBuilder()
|
||||
free(_rgb_shader);
|
||||
}
|
||||
|
||||
static GLenum formatForDepth(size_t depth)
|
||||
static const GLint internalFormatForDepth(size_t depth)
|
||||
{
|
||||
switch(depth)
|
||||
{
|
||||
default: return GL_FALSE;
|
||||
case 1: return GL_RED;
|
||||
case 2: return GL_RG;
|
||||
case 3: return GL_RGB;
|
||||
case 4: return GL_RGBA;
|
||||
case 1: return GL_R8UI;
|
||||
case 2: return GL_RG8UI;
|
||||
case 3: return GL_RGB8UI;
|
||||
case 4: return GL_RGBA8UI;
|
||||
}
|
||||
}
|
||||
|
||||
static const GLenum formatForDepth(size_t depth)
|
||||
{
|
||||
switch(depth)
|
||||
{
|
||||
default: return GL_FALSE;
|
||||
case 1: return GL_RED_INTEGER;
|
||||
case 2: return GL_RG_INTEGER;
|
||||
case 3: return GL_RGB_INTEGER;
|
||||
case 4: return GL_RGBA_INTEGER;
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,13 +96,12 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
GLenum format = formatForDepth(_buffer_builder->bytes_per_pixel);
|
||||
glGenBuffers(1, &_input_texture_array);
|
||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, _input_texture_array);
|
||||
_input_texture_array_size = (GLsizeiptr)(InputBufferBuilderWidth * InputBufferBuilderHeight * _buffer_builder->bytes_per_pixel);
|
||||
glBufferData(GL_PIXEL_UNPACK_BUFFER, _input_texture_array_size, NULL, GL_STREAM_DRAW);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, (GLint)format, InputBufferBuilderWidth, InputBufferBuilderHeight, 0, format, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormatForDepth(_buffer_builder->bytes_per_pixel), InputBufferBuilderWidth, InputBufferBuilderHeight, 0, formatForDepth(_buffer_builder->bytes_per_pixel), GL_UNSIGNED_BYTE, nullptr);
|
||||
|
||||
prepare_composite_input_shader();
|
||||
prepare_rgb_output_shader();
|
||||
@ -137,13 +148,12 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
|
||||
// for(unsigned int buffer = 0; buffer < _buffer_builder->number_of_buffers; buffer++)
|
||||
// {
|
||||
// glActiveTexture(GL_TEXTURE0 + first_supplied_buffer_texture_unit + buffer);
|
||||
GLenum format = formatForDepth(_buffer_builder->bytes_per_pixel);
|
||||
if(_buffer_builder->_next_write_y_position < _buffer_builder->last_uploaded_line)
|
||||
{
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0,
|
||||
0, (GLint)_buffer_builder->last_uploaded_line,
|
||||
InputBufferBuilderWidth, (GLint)(InputBufferBuilderHeight - _buffer_builder->last_uploaded_line),
|
||||
format, GL_UNSIGNED_BYTE,
|
||||
formatForDepth(_buffer_builder->bytes_per_pixel), GL_UNSIGNED_BYTE,
|
||||
(void *)(_buffer_builder->last_uploaded_line * InputBufferBuilderWidth * _buffer_builder->bytes_per_pixel));
|
||||
_buffer_builder->last_uploaded_line = 0;
|
||||
}
|
||||
@ -153,7 +163,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0,
|
||||
0, (GLint)_buffer_builder->last_uploaded_line,
|
||||
InputBufferBuilderWidth, (GLint)(1 + _buffer_builder->_next_write_y_position - _buffer_builder->last_uploaded_line),
|
||||
format, GL_UNSIGNED_BYTE,
|
||||
formatForDepth(_buffer_builder->bytes_per_pixel), GL_UNSIGNED_BYTE,
|
||||
(void *)(_buffer_builder->last_uploaded_line * InputBufferBuilderWidth * _buffer_builder->bytes_per_pixel));
|
||||
_buffer_builder->last_uploaded_line = _buffer_builder->_next_write_y_position;
|
||||
}
|
||||
@ -303,7 +313,7 @@ char *OpenGLOutputBuilder::get_input_fragment_shader()
|
||||
|
||||
"out vec4 fragColour;"
|
||||
|
||||
"uniform sampler2D texID;"
|
||||
"uniform usampler2D texID;"
|
||||
|
||||
"\n%s\n"
|
||||
|
||||
@ -396,7 +406,7 @@ char *OpenGLOutputBuilder::get_output_fragment_shader(const char *sampling_funct
|
||||
|
||||
"out vec4 fragColour;"
|
||||
|
||||
"uniform sampler2D texID;"
|
||||
"uniform usampler2D texID;"
|
||||
"uniform sampler2D shadowMaskTexID;"
|
||||
|
||||
"\n%s\n"
|
||||
|
Loading…
Reference in New Issue
Block a user