fix(webgl): Add VAO support for WebGL 2.0 rendering
WebGL 2.0 / OpenGL ES 3.0 requires a Vertex Array Object (VAO) to be bound before setting vertex attributes. Desktop OpenGL has a default VAO (VAO 0), but WebGL 2.0 does not. Changes to GPU_MANAGER: - Add m_vao member variable to store VAO handle - Create VAO in SetShader() when GL context is available - Bind VAO before glVertexAttribPointer calls in EndDrawing() - Unbind VAO after rendering completes - Delete VAO in destructor This fix enables actual rendering output in WebGL. Without a VAO, glVertexAttribPointer silently fails and no geometry is drawn. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d0e2500048
commit
7617acf8b5
2 changed files with 31 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue