From 5d95c7132c9285f57b48b4deb3808e9cce291660 Mon Sep 17 00:00:00 2001 From: Lukas Rusak Date: Fri, 21 Apr 2023 10:41:10 -0700 Subject: [PATCH] CVisualizationShadertoy: use vao Signed-off-by: Lukas Rusak --- src/main.cpp | 11 +++++++++++ src/main.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index ec9e1fe..2db9bdb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -154,6 +154,8 @@ void CVisualizationShadertoy::Render() { if (m_initialized) { + glBindVertexArray(m_state.vao); + if (m_state.fbwidth && m_state.fbheight) { RenderTo(m_shadertoyShader.ProgramHandle(), m_state.effect_fb); @@ -163,6 +165,8 @@ void CVisualizationShadertoy::Render() { RenderTo(m_shadertoyShader.ProgramHandle(), 0); } + + glBindVertexArray(0); } } @@ -180,11 +184,16 @@ bool CVisualizationShadertoy::Start(int iChannels, int iSamplesPerSec, int iBits -1.0,-1.0, 1.0, 1.0, }; + glGenVertexArrays(1, &m_state.vao); + glBindVertexArray(m_state.vao); + // Upload vertex data to a buffer glGenBuffers(1, &m_state.vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, m_state.vertex_buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); + glBindVertexArray(0); + m_samplesPerSec = iSamplesPerSec; Launch(m_currentPreset); m_initialized = true; @@ -203,6 +212,8 @@ void CVisualizationShadertoy::Stop() UnloadTextures(); glDeleteBuffers(1, &m_state.vertex_buffer); + + glDeleteVertexArrays(1, &m_state.vao); } diff --git a/src/main.h b/src/main.h index 61a0db9..195ac5b 100644 --- a/src/main.h +++ b/src/main.h @@ -81,6 +81,7 @@ class ATTR_DLL_LOCAL CVisualizationShadertoy struct { + GLuint vao; GLuint vertex_buffer; GLuint attr_vertex_e; GLuint attr_vertex_r, uTexture;