From e9d1afd5155c12dce5f765217cc741657a231dc1 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 12 Nov 2018 19:10:48 -0500 Subject: [PATCH] Appears to demonstrates that the line buffer is approximately working. --- Outputs/OpenGL/ScanTarget.cpp | 22 ++++++++++++---------- Outputs/OpenGL/ScanTarget.hpp | 2 +- Outputs/OpenGL/ScanTargetGLSLFragments.cpp | 12 ++++++------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Outputs/OpenGL/ScanTarget.cpp b/Outputs/OpenGL/ScanTarget.cpp index f7988d95e..6a1755fa4 100644 --- a/Outputs/OpenGL/ScanTarget.cpp +++ b/Outputs/OpenGL/ScanTarget.cpp @@ -66,38 +66,40 @@ const GLenum formatForDepth(std::size_t depth) { } -template void ScanTarget::allocate_buffer(const T &array, GLuint &buffer_name) { +template void ScanTarget::allocate_buffer(const T &array, GLuint &buffer_name, GLuint &vertex_array_name) { const auto buffer_size = array.size() * sizeof(array[0]); glGenBuffers(1, &buffer_name); glBindBuffer(GL_ARRAY_BUFFER, buffer_name); glBufferData(GL_ARRAY_BUFFER, GLsizeiptr(buffer_size), NULL, GL_STREAM_DRAW); + + glGenVertexArrays(1, &vertex_array_name); + glBindVertexArray(vertex_array_name); + glBindBuffer(GL_ARRAY_BUFFER, buffer_name); } ScanTarget::ScanTarget() : unprocessed_line_texture_(LineBufferWidth, LineBufferHeight, UnprocessedLineBufferTextureUnit, GL_LINEAR) { // Allocate space for the scans and lines. - allocate_buffer(scan_buffer_, scan_buffer_name_); - allocate_buffer(line_buffer_, line_buffer_name_); + allocate_buffer(scan_buffer_, scan_buffer_name_, scan_vertex_array_); + allocate_buffer(line_buffer_, line_buffer_name_, line_vertex_array_); // TODO: if this is OpenGL 4.4 or newer, use glBufferStorage rather than glBufferData // and specify GL_MAP_PERSISTENT_BIT. Then map the buffer now, and let the client // write straight into it. glGenTextures(1, &write_area_texture_name_); - glGenVertexArrays(1, &scan_vertex_array_); - glBindVertexArray(scan_vertex_array_); - glBindBuffer(GL_ARRAY_BUFFER, scan_buffer_name_); test_shader_.reset(new Shader( - glsl_globals(ShaderType::Scan) + glsl_default_vertex_shader(ShaderType::Scan), + glsl_globals(ShaderType::Line) + glsl_default_vertex_shader(ShaderType::Line), "#version 150\n" "out vec4 fragColour;" "void main(void) {" "fragColour = vec4(1.0);" "}" )); - enable_vertex_attributes(ShaderType::Scan, *test_shader_); + glBindVertexArray(line_vertex_array_); + enable_vertex_attributes(ShaderType::Line, *test_shader_); } ScanTarget::~ScanTarget() { @@ -354,10 +356,10 @@ void ScanTarget::draw() { // the submit pointer location. read_pointers_.store(submit_pointers); - // TEST: draw all scans. + // TEST: draw all lines. glBindFramebuffer(GL_FRAMEBUFFER, 0); - glBindVertexArray(scan_vertex_array_); + glBindVertexArray(line_vertex_array_); test_shader_->bind(); glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, GLsizei(scan_buffer_.size())); } diff --git a/Outputs/OpenGL/ScanTarget.hpp b/Outputs/OpenGL/ScanTarget.hpp index 812db7dbb..1e64fdea3 100644 --- a/Outputs/OpenGL/ScanTarget.hpp +++ b/Outputs/OpenGL/ScanTarget.hpp @@ -86,7 +86,7 @@ class ScanTarget: public Outputs::Display::ScanTarget { GLuint scan_buffer_name_ = 0, scan_vertex_array_ = 0; GLuint line_buffer_name_ = 0, line_vertex_array_ = 0; - template void allocate_buffer(const T &array, GLuint &buffer_name); + template void allocate_buffer(const T &array, GLuint &buffer_name, GLuint &vertex_array_name); template void submit_buffer(const T &array, GLuint target, uint16_t submit_pointer, uint16_t read_pointer); // Uses a texture to vend write areas. diff --git a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp index 5d3464089..d8fe3c505 100644 --- a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp +++ b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp @@ -45,8 +45,8 @@ std::string ScanTarget::glsl_globals(ShaderType type) { } std::string ScanTarget::glsl_default_vertex_shader(ShaderType type) { - switch(type) { - case ShaderType::Scan: +// switch(type) { +// case ShaderType::Scan: return "void main(void) {" "float lateral = float(gl_VertexID & 1);" @@ -54,13 +54,13 @@ std::string ScanTarget::glsl_default_vertex_shader(ShaderType type) { "vec2 centrePoint = mix(startPoint, endPoint, lateral) / scale;" "vec2 height = normalize(endPoint - startPoint).yx * (longitudinal - 0.5) * rowHeight;" - "vec2 eyePosition = vec2(1.0) - 2.0 * (centrePoint + height);" + "vec2 eyePosition = vec2(-0.9, 0.9) + vec2(1.8, -1.8) * (centrePoint + height);" "gl_Position = vec4(eyePosition, 0.0, 1.0);" "}"; - case ShaderType::Line: - return ""; - } +// case ShaderType::Line: +// return ""; +// } } void ScanTarget::enable_vertex_attributes(ShaderType type, Shader &target) {