Search code examples
pythonopengl-eseglpython-moderngl

ModernGL render returns GL_INVALID_ENUM error?


I have written this GPU code in C using GLES and EGL, and it ran fine. I am now trying to port this GPU code to python using ModernGL, except right after I call the render function, ctx returns a GL_INVALID_ENUM error. I am using a NanoPi M1 Plus with Mali400 GPU which supports only OpenGL version 120.

GPU CODE:

import moderngl
import numpy as np

ctx = moderngl.create_context(standalone=True,
    backend='egl'
    ) 
prog = ctx.program(
            vertex_shader='''
                        #version 120
                        attribute vec4 vPosition;
                        void main() {
                            gl_Position = vPosition;
                        }
                        ''',
            fragment_shader='''
                            #version 120
                            uniform float Aarr[1000];

                            void main() {
                                int my_index = int(gl_FragCoord[0]);
                                float ex = exp(-Aarr[my_index]);
                                float result = 1 / (1.0 + ex);
                                gl_FragColor = vec4(result, 0.0, 0.0, 1.0);
                            }
                            ''',
        )

vertices = np.array([
                    -1.0, -1.0, 1.0,
                    -1.0, 1.0, 1.0,
                    1.0, 1.0, 1.0,
                    -1.0, -1.0, 1.0,
                    1.0, 1.0, 1.0,
                    1.0, -1.0, 1.0
                    ],
                    dtype='f4',
                )

vbo = ctx.buffer(vertices)
vao = ctx.simple_vertex_array(prog, vbo, 'vPosition')

A_vec = prog['Aarr']
A_vec.write(np.random.uniform(-256,256,[1000]).astype('f4'))
fbo = ctx.simple_framebuffer((1000, 2), components=4)
fbo.use()
fbo.clear(0.0, 0.0, 0.0, 1.0)
vao.render()
print("Error after render: ",ctx.error)

Output:

libGL error: MESA-LOADER: malformed or no PCI ID
libGL error: unable to load driver: mali_drm_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: mali_drm
Error after render:  GL_INVALID_ENUM

Any help would be greatly appreciated as this is required for my final year project.


Solution

  • Mali400 GPU which supports only OpenGL version 120

    It doesn't support OpenGL at all; it supports OpenGL ES 1.1 and 2.0.