From d5bac2f04f156ab763db8182deb7b99ddb9a5781 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 18 Apr 2016 21:32:48 -0400 Subject: [PATCH] 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. --- .../Base.lproj/ElectronDocument.xib | 2 +- Outputs/CRT/CRT.cpp | 4 ++- Outputs/CRT/Internals/CRTOpenGL.cpp | 30 ++++++++++++------- Outputs/CRT/Internals/Shader.cpp | 16 ++++++++++ Outputs/CRT/Internals/TextureTarget.cpp | 7 ++--- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Base.lproj/ElectronDocument.xib b/OSBindings/Mac/Clock Signal/Base.lproj/ElectronDocument.xib index 24ef1b95c..f5c6a8e5a 100644 --- a/OSBindings/Mac/Clock Signal/Base.lproj/ElectronDocument.xib +++ b/OSBindings/Mac/Clock Signal/Base.lproj/ElectronDocument.xib @@ -31,7 +31,7 @@ - + diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index c78b4b3b6..7ff10bce0 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -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(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; } diff --git a/Outputs/CRT/Internals/CRTOpenGL.cpp b/Outputs/CRT/Internals/CRTOpenGL.cpp index 8816e72bb..81ee128ac 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.cpp +++ b/Outputs/CRT/Internals/CRTOpenGL.cpp @@ -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); } diff --git a/Outputs/CRT/Internals/Shader.cpp b/Outputs/CRT/Internals/Shader.cpp index c89a41c3b..4bf63c8c6 100644 --- a/Outputs/CRT/Internals/Shader.cpp +++ b/Outputs/CRT/Internals/Shader.cpp @@ -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() diff --git a/Outputs/CRT/Internals/TextureTarget.cpp b/Outputs/CRT/Internals/TextureTarget.cpp index 5a622e09b..a57eaa26c 100644 --- a/Outputs/CRT/Internals/TextureTarget.cpp +++ b/Outputs/CRT/Internals/TextureTarget.cpp @@ -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);