1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-26 09:29:45 +00:00

Spotted error was in texture target all along. This now gets as far as showing something a lot like the correct display, but precision is way off. Way off.

This commit is contained in:
Thomas Harte 2016-04-18 21:32:48 -04:00
parent 86626bbd72
commit d5bac2f04f
5 changed files with 43 additions and 16 deletions

View File

@ -31,7 +31,7 @@
</connections>
</window>
<window title="Options" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hidesOnDeactivate="YES" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="ZW7-Bw-4RP" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES" utility="YES" nonactivatingPanel="YES" HUD="YES"/>
<windowStyleMask key="styleMask" titled="YES" closable="YES" utility="YES" HUD="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="83" y="102" width="200" height="83"/>
<rect key="screenRect" x="0.0" y="0.0" width="1366" height="768"/>

View File

@ -77,7 +77,6 @@ CRT::CRT(unsigned int cycles_per_line, unsigned int common_output_divisor, unsig
CRT::CRT(unsigned int cycles_per_line, unsigned int common_output_divisor, DisplayType displayType, unsigned int buffer_depth) : CRT(common_output_divisor)
{
_openGL_output_builder = std::unique_ptr<OpenGLOutputBuilder>(new OpenGLOutputBuilder(buffer_depth));
set_new_display_type(cycles_per_line, displayType);
}
@ -238,6 +237,9 @@ void CRT::advance_cycles(unsigned int number_of_cycles, unsigned int source_divi
output_lateral(2) = 1;
output_frame_id(0) = output_frame_id(1) = output_frame_id(2) = (uint8_t)_openGL_output_builder->get_current_field();
// printf("%d", _horizontal_flywheel->get_current_output_position());
// if(_is_writing_composite_run) printf("\n"); else printf(" -> ");
_openGL_output_builder->complete_output_run(3);
_is_writing_composite_run ^= true;
}

View File

@ -176,6 +176,8 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
// upload more source pixel data if any; we'll always resubmit the last line submitted last
// time as it may have had extra data appended to it
glActiveTexture(GL_TEXTURE0 + first_supplied_buffer_texture_unit);
glBindTexture(GL_TEXTURE_2D, textureName);
if(_buffer_builder->_next_write_y_position < _buffer_builder->last_uploaded_line)
{
glTexSubImage2D( GL_TEXTURE_2D, 0,
@ -201,8 +203,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
{
composite_input_shader_program->bind();
// compositeTexture->bind_framebuffer();
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
compositeTexture->bind_framebuffer();
glBindVertexArray(source_vertex_array);
glDisable(GL_BLEND);
@ -230,7 +231,9 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
}
// transfer to screen
// perform_output_stage(output_width, output_height, rgb_shader_program.get());
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
compositeTexture->bind_texture();
perform_output_stage(output_width, output_height, rgb_shader_program.get());
}
else
perform_output_stage(output_width, output_height, rgb_shader_program.get());
@ -244,6 +247,7 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
_input_texture_data = (uint8_t *)glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, _input_texture_array_size, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
// printf("%04x\n", glGetError());
_output_mutex->unlock();
}
@ -251,16 +255,18 @@ void OpenGLOutputBuilder::perform_output_stage(unsigned int output_width, unsign
{
if(shader)
{
shader->bind();
// update uniforms
push_size_uniforms(output_width, output_height);
// definitively establish the viewport
glViewport(0, 0, (GLsizei)output_width, (GLsizei)output_height);
// Ensure we're back on the output framebuffer, drawing from the output array buffer
glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer);
glBindVertexArray(output_vertex_array);
shader->bind();
// update uniforms
push_size_uniforms(output_width, output_height);
// clear the buffer
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
@ -426,7 +432,7 @@ char *OpenGLOutputBuilder::get_output_vertex_shader()
"uniform vec2 positionConversion;"
"uniform vec2 scanNormal;"
"uniform usampler2D texID;"
"uniform sampler2D texID;"
// "uniform sampler2D shadowMaskTexID;"
// "const float shadowMaskMultiple = 600;"
@ -492,14 +498,18 @@ char *OpenGLOutputBuilder::get_output_fragment_shader(const char *sampling_funct
"out vec4 fragColour;"
"uniform usampler2D texID;"
// "uniform usampler2D texID;"
"uniform sampler2D texID;"
// "uniform sampler2D shadowMaskTexID;"
"\n%s\n"
"void main(void)"
"{"
"fragColour = vec4(rgb_sample(texID, srcCoordinatesVarying, iSrcCoordinatesVarying), clamp(alpha, 0.0, 1.0)*sin(lateralVarying));" //
// "fragColour = vec4(srcCoordinatesVarying.rg, 0.0, 1.0);" //
"fragColour = texture(texID, srcCoordinatesVarying).rgba;" //
// "fragColour = vec4(srcCoordinatesVarying.y / 4.0, 0.0, 0.0, 1.0);"//texture(texID, srcCoordinatesVarying).rgba;" //
// "fragColour = vec4(rgb_sample(texID, srcCoordinatesVarying, iSrcCoordinatesVarying), clamp(alpha, 0.0, 1.0)*sin(lateralVarying));" //
"}"
, sampling_function);
}

View File

@ -47,6 +47,22 @@ Shader::Shader(const char *vertex_shader, const char *fragment_shader)
glAttachShader(_shader_program, vertex);
glAttachShader(_shader_program, fragment);
glLinkProgram(_shader_program);
#if defined(DEBUG)
GLint didLink = 0;
glGetProgramiv(_shader_program, GL_LINK_STATUS, &didLink);
if(didLink == GL_FALSE)
{
GLint logLength;
glGetProgramiv(_shader_program, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 0) {
GLchar *log = (GLchar *)malloc((size_t)logLength);
glGetProgramInfoLog(_shader_program, logLength, &logLength, log);
printf("Link log:\n%s\n", log);
free(log);
}
}
#endif
}
Shader::~Shader()

View File

@ -17,10 +17,9 @@ TextureTarget::TextureTarget(GLsizei width, GLsizei height) : _width(width), _he
glGenTextures(1, &_texture);
glBindTexture(GL_TEXTURE_2D, _texture);
uint8_t *emptySpace = new uint8_t[width*height*3];
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, (GLsizei)width, (GLsizei)height, 0, GL_RGB, GL_UNSIGNED_BYTE, emptySpace);
delete[] emptySpace;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)width, (GLsizei)height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0);