diff --git a/tests/gal-regression/wasm/webgl/gpu_manager.cpp b/tests/gal-regression/wasm/webgl/gpu_manager.cpp index 13a0429..8096681 100644 --- a/tests/gal-regression/wasm/webgl/gpu_manager.cpp +++ b/tests/gal-regression/wasm/webgl/gpu_manager.cpp @@ -61,13 +61,20 @@ GPU_MANAGER::GPU_MANAGER( VERTEX_CONTAINER* aContainer ) : m_shaderAttrib( 0 ), m_vertexAttrib( 0 ), m_colorAttrib( 0 ), - m_enableDepthTest( true ) + m_enableDepthTest( true ), + m_vao( 0 ) { } GPU_MANAGER::~GPU_MANAGER() { + // Delete VAO if it was created + if( m_vao != 0 ) + { + glDeleteVertexArrays( 1, &m_vao ); + m_vao = 0; + } } @@ -82,6 +89,13 @@ void GPU_MANAGER::SetShader( SHADER& aShader ) { DisplayError( nullptr, wxT( "Could not get the shader attribute location" ) ); } + + // Create VAO for WebGL 2.0 / OpenGL ES 3.0 compatibility + // WebGL 2.0 requires a VAO to be bound before calling glVertexAttribPointer + if( m_vao == 0 ) + { + glGenVertexArrays( 1, &m_vao ); + } } @@ -163,6 +177,9 @@ void GPU_CACHED_MANAGER::EndDrawing() else glDisable( GL_DEPTH_TEST ); + // Bind VAO first (required for WebGL 2.0 / OpenGL ES 3.0) + glBindVertexArray( m_vao ); + // Bind vertices data buffers glBindBuffer( GL_ARRAY_BUFFER, cached->GetBufferHandle() ); @@ -250,6 +267,9 @@ void GPU_CACHED_MANAGER::EndDrawing() m_shader->Deactivate(); } + // Unbind VAO + glBindVertexArray( 0 ); + m_isDrawing = false; } @@ -301,6 +321,9 @@ void GPU_NONCACHED_MANAGER::EndDrawing() else glDisable( GL_DEPTH_TEST ); + // Bind VAO first (required for WebGL 2.0 / OpenGL ES 3.0) + glBindVertexArray( m_vao ); + // Modern vertex attributes (replacing legacy glEnableClientState/glVertexPointer/glColorPointer) // Vertex position (a_vertex) glEnableVertexAttribArray( m_vertexAttrib ); @@ -338,6 +361,9 @@ void GPU_NONCACHED_MANAGER::EndDrawing() m_shader->Deactivate(); } + // Unbind VAO + glBindVertexArray( 0 ); + m_container->Clear(); #ifdef KICAD_GAL_PROFILE diff --git a/tests/gal-regression/wasm/webgl/gpu_manager.h b/tests/gal-regression/wasm/webgl/gpu_manager.h index d6c81f1..fb79060 100644 --- a/tests/gal-regression/wasm/webgl/gpu_manager.h +++ b/tests/gal-regression/wasm/webgl/gpu_manager.h @@ -98,6 +98,10 @@ protected: ///< true: enable Z test when drawing bool m_enableDepthTest; + + ///< VAO for WebGL 2.0 / OpenGL ES 3.0 compatibility + ///< WebGL 2.0 requires a VAO to be bound before setting vertex attributes + unsigned int m_vao; };