1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-06 01:28:57 +00:00

Dropped the size per output run back down to 8 bytes.

This commit is contained in:
Thomas Harte 2016-05-10 07:47:47 -04:00
parent b0f0315f12
commit 1d0bcb416d
4 changed files with 29 additions and 37 deletions

View File

@ -96,12 +96,10 @@ Flywheel::SyncEvent CRT::get_next_horizontal_sync_event(bool hsync_is_requested,
return _horizontal_flywheel->get_next_event_in_period(hsync_is_requested, cycles_to_run_for, cycles_advanced);
}
#define output_position_x1() (*(uint16_t *)&next_run[OutputVertexOffsetOfPosition + 0])
#define output_position_x2() (*(uint16_t *)&next_run[OutputVertexOffsetOfTerminators + 0])
#define output_position_y() (*(uint16_t *)&next_run[OutputVertexOffsetOfPosition + 2])
#define output_tex_x1() (*(uint16_t *)&next_run[OutputVertexOffsetOfTexCoord + 0])
#define output_tex_x2() (*(uint16_t *)&next_run[OutputVertexOffsetOfTerminators + 2])
#define output_tex_y() (*(uint16_t *)&next_run[OutputVertexOffsetOfTexCoord + 2])
#define output_x1() (*(uint16_t *)&next_run[OutputVertexOffsetOfHorizontal + 0])
#define output_x2() (*(uint16_t *)&next_run[OutputVertexOffsetOfHorizontal + 2])
#define output_position_y() (*(uint16_t *)&next_run[OutputVertexOffsetOfVertical + 0])
#define output_tex_y() (*(uint16_t *)&next_run[OutputVertexOffsetOfVertical + 2])
#define source_input_position_x(v) (*(uint16_t *)&next_run[SourceVertexSize*v + SourceVertexOffsetOfInputPosition + 0])
#define source_input_position_y(v) (*(uint16_t *)&next_run[SourceVertexSize*v + SourceVertexOffsetOfInputPosition + 2])
@ -198,15 +196,13 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi
{
if(_did_start_run)
{
output_position_x1() = (uint16_t)_horizontal_flywheel->get_current_output_position();
output_x1() = (uint16_t)_horizontal_flywheel->get_current_output_position();
output_position_y() = (uint16_t)(_vertical_flywheel->get_current_output_position() / _vertical_flywheel_output_divider);
output_tex_x1() = (uint16_t)_horizontal_flywheel->get_current_output_position();
output_tex_y() = _openGL_output_builder->get_composite_output_y();
}
else
{
output_position_x2() = (uint16_t)_horizontal_flywheel->get_current_output_position();
output_tex_x2() = (uint16_t)_horizontal_flywheel->get_current_output_position();
output_x2() = (uint16_t)_horizontal_flywheel->get_current_output_position();
_openGL_output_builder->complete_output_run();
}
@ -237,11 +233,10 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi
}
}
#undef output_position_x
#undef output_x1
#undef output_x2
#undef output_position_y
#undef output_tex_x
#undef output_tex_y
#undef output_lateral
#undef input_input_position_x
#undef input_input_position_y

View File

@ -17,11 +17,10 @@ namespace CRT {
// Output vertices are those used to copy from an input buffer — whether it describes data that maps directly to RGB
// or is one of the intermediate buffers that we've used to convert from composite towards RGB.
const GLsizei OutputVertexOffsetOfPosition = 0;
const GLsizei OutputVertexOffsetOfTexCoord = 4;
const GLsizei OutputVertexOffsetOfTerminators = 8;
const GLsizei OutputVertexOffsetOfHorizontal = 0;
const GLsizei OutputVertexOffsetOfVertical = 4;
const GLsizei OutputVertexSize = 12;
const GLsizei OutputVertexSize = 8;
// Input vertices, used only in composite mode, map from the input buffer to temporary buffer locations; such
// remapping occurs to ensure a continous stream of data for each scan, giving correct out-of-bounds behaviour

View File

@ -424,25 +424,23 @@ void OpenGLOutputBuilder::prepare_output_vertex_array()
{
if(output_shader_program)
{
GLint positionAttribute = output_shader_program->get_attrib_location("position");
GLint textureCoordinatesAttribute = output_shader_program->get_attrib_location("srcCoordinates");
GLint terminatorsAttribute = output_shader_program->get_attrib_location("terminators");
glBindVertexArray(output_vertex_array);
glEnableVertexAttribArray((GLuint)positionAttribute);
glEnableVertexAttribArray((GLuint)textureCoordinatesAttribute);
glEnableVertexAttribArray((GLuint)terminatorsAttribute);
glBindBuffer(GL_ARRAY_BUFFER, output_array_buffer);
const GLsizei vertexStride = OutputVertexSize;
glBindBuffer(GL_ARRAY_BUFFER, output_array_buffer);
glVertexAttribPointer((GLuint)positionAttribute, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)OutputVertexOffsetOfPosition);
glVertexAttribPointer((GLuint)textureCoordinatesAttribute, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)OutputVertexOffsetOfTexCoord);
glVertexAttribPointer((GLuint)terminatorsAttribute, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)OutputVertexOffsetOfTerminators);
size_t offset = 0;
glVertexAttribDivisor((GLuint)positionAttribute, 1);
glVertexAttribDivisor((GLuint)textureCoordinatesAttribute, 1);
glVertexAttribDivisor((GLuint)terminatorsAttribute, 1);
const char *attributes[] = {"horizontal", "vertical", nullptr};
const char **attribute = attributes;
while(*attribute)
{
GLint attributeLocation = output_shader_program->get_attrib_location(*attribute);
glEnableVertexAttribArray((GLuint)attributeLocation);
glVertexAttribPointer((GLuint)attributeLocation, 2, GL_UNSIGNED_SHORT, GL_FALSE, vertexStride, (void *)offset);
glVertexAttribDivisor((GLuint)attributeLocation, 1);
offset += 4;
attribute++;
}
}
}

View File

@ -30,9 +30,8 @@ std::unique_ptr<OutputShader> OutputShader::make_shader(const char *fragment_met
asprintf(&vertex_shader,
"#version 150\n"
"in vec2 position;"
"in vec2 srcCoordinates;"
"in vec2 terminators;"
"in vec2 horizontal;"
"in vec2 vertical;"
"uniform vec2 boundsOrigin;"
"uniform vec2 boundsSize;"
@ -48,15 +47,16 @@ std::unique_ptr<OutputShader> OutputShader::make_shader(const char *fragment_met
"{"
"float lateral = float(gl_VertexID & 1);"
"float longitudinal = float((gl_VertexID & 2) >> 1);"
"float x = mix(horizontal.x, horizontal.y, longitudinal);"
"lateralVarying = lateral - 0.5;"
"vec2 vSrcCoordinates = vec2(mix(srcCoordinates.x, terminators.y, longitudinal), srcCoordinates.y);"
"vec2 vSrcCoordinates = vec2(x, vertical.y);"
"ivec2 textureSize = textureSize(texID, 0);"
"iSrcCoordinatesVarying = vSrcCoordinates;"
"srcCoordinatesVarying = vec2(vSrcCoordinates.x / textureSize.x, (vSrcCoordinates.y + 0.5) / textureSize.y);"
"vec2 vPosition = vec2(mix(position.x, terminators.x, longitudinal), position.y);"
"vec2 vPosition = vec2(x, vertical.x);"
"vec2 floatingPosition = (vPosition / positionConversion) + lateral * scanNormal;"
"vec2 mappedPosition = (floatingPosition - boundsOrigin) / boundsSize;"
"gl_Position = vec4(mappedPosition.x * 2.0 - 1.0, 1.0 - mappedPosition.y * 2.0, 0.0, 1.0);"