From a74f081aa97ad7a2e68338fd0d55d8dd5d555386 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 5 May 2016 21:21:27 -0400 Subject: [PATCH] Put lateral lookup table directly into the shader. --- Outputs/CRT/Internals/CRTOpenGL.cpp | 21 ++----------------- Outputs/CRT/Internals/CRTOpenGL.hpp | 2 +- .../CRT/Internals/Shaders/OutputShader.cpp | 4 +++- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/Outputs/CRT/Internals/CRTOpenGL.cpp b/Outputs/CRT/Internals/CRTOpenGL.cpp index 3c3154d8c..06362794d 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.cpp +++ b/Outputs/CRT/Internals/CRTOpenGL.cpp @@ -124,17 +124,6 @@ OpenGLOutputBuilder::OpenGLOutputBuilder(unsigned int buffer_depth) : glBindBuffer(GL_ARRAY_BUFFER, output_array_buffer); glBufferData(GL_ARRAY_BUFFER, OutputVertexBufferDataSize, NULL, GL_STREAM_DRAW); - // create and populate a buffer for the lateral attributes - glGenBuffers(1, &lateral_array_buffer); - glBindBuffer(GL_ARRAY_BUFFER, lateral_array_buffer); - size_t number_of_vertices = OutputVertexBufferDataSize/OutputVertexSize; - uint8_t lateral_pattern[] = {0, 0, 1, 0, 1, 1}; - uint8_t *laterals = new uint8_t[number_of_vertices]; - for(size_t c = 0; c < number_of_vertices; c++) - laterals[c] = lateral_pattern[c%6]; - glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)number_of_vertices, laterals, GL_STATIC_DRAW); - delete[] laterals; - // map that buffer too, for any CRT activity that may occur before the first draw _output_buffer_data = (uint8_t *)glMapBufferRange(GL_ARRAY_BUFFER, 0, OutputVertexBufferDataSize, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT); @@ -157,7 +146,6 @@ OpenGLOutputBuilder::~OpenGLOutputBuilder() glDeleteTextures(1, &textureName); glDeleteBuffers(1, &output_array_buffer); glDeleteBuffers(1, &source_array_buffer); - glDeleteBuffers(1, &lateral_array_buffer); glDeleteVertexArrays(1, &output_vertex_array); free(_composite_shader); @@ -374,8 +362,8 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, (GLsizei)output_width, (GLsizei)output_height); glClear(GL_COLOR_BUFFER_BIT); -// framebuffer->draw((float)output_width / (float)output_height); - compositeTexture->draw((float)output_width / (float)output_height); + framebuffer->draw((float)output_width / (float)output_height); +// compositeTexture->draw((float)output_width / (float)output_height); // drawing commands having been issued, reclaim the array buffer pointer glBindBuffer(GL_ARRAY_BUFFER, output_array_buffer); @@ -483,11 +471,6 @@ void OpenGLOutputBuilder::prepare_output_vertex_array() 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); - - GLint lateralAttribute = output_shader_program->get_attrib_location("lateral"); - glEnableVertexAttribArray((GLuint)lateralAttribute); - glBindBuffer(GL_ARRAY_BUFFER, lateral_array_buffer); - glVertexAttribPointer((GLuint)lateralAttribute, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, (void *)0); } } diff --git a/Outputs/CRT/Internals/CRTOpenGL.hpp b/Outputs/CRT/Internals/CRTOpenGL.hpp index 8812abcc0..c41550f8c 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.hpp +++ b/Outputs/CRT/Internals/CRTOpenGL.hpp @@ -73,7 +73,7 @@ class OpenGLOutputBuilder { std::unique_ptr framebuffer; // the current pixel output - GLuint output_array_buffer, lateral_array_buffer, output_vertex_array; + GLuint output_array_buffer, output_vertex_array; GLuint source_array_buffer, source_vertex_array; unsigned int _last_output_width, _last_output_height; diff --git a/Outputs/CRT/Internals/Shaders/OutputShader.cpp b/Outputs/CRT/Internals/Shaders/OutputShader.cpp index 7deb4c508..00be80a6e 100644 --- a/Outputs/CRT/Internals/Shaders/OutputShader.cpp +++ b/Outputs/CRT/Internals/Shaders/OutputShader.cpp @@ -33,7 +33,7 @@ std::unique_ptr OutputShader::make_shader(const char *fragment_met "in vec2 position;" "in vec2 srcCoordinates;" - "in float lateral;" +// "in float lateral;" "uniform vec2 boundsOrigin;" "uniform vec2 boundsSize;" @@ -47,6 +47,8 @@ std::unique_ptr OutputShader::make_shader(const char *fragment_met "void main(void)" "{" + "float laterals[] = float[](0, 0, 1, 0, 1, 1);" + "float lateral = laterals[gl_VertexID %% 6];" "lateralVarying = lateral - 0.5;" "ivec2 textureSize = textureSize(texID, 0);"