OpenGL, glDraw* random GL_INVALID_OPERATION error.

OpenGL, glDraw* random GL_INVALID_OPERATION error.

Hi,

I have a bug in my program I have "resolved" but I can't figure out why it is happening :/ I am using the latest sdk and glfw. I have one vbo that is shared with openCL, when I render I get random GL_INVALID_OPERATION after a draw operation, so sometimes things are draw and sometimes the screen is black. (Even if I use an empty kernel I get this problem and if I run the program using nvidia implementation I don't have this problem.)

My loop is like that: 1) draw

                              2) execute kernel.

Here is the render code when it bugs (note that a vao is already bound):

glClear(GL_COLOR_BUFFER_BIT);        
GLenum glError = glGetError();    
glDrawElements(GL_TRIANGLES, NUM_INDICES * num_bacterias, GL_UNSIGNED_INT, NULL);    

glError = glGetError();    
assert (GL_NO_ERROR == glError);    
glfwSwapBuffers();     
return viewer_no_error;

Here is the render code when it works:

glClear(GL_COLOR_BUFFER_BIT);
    glBindVertexArray(bacteria_vao);
    
    // Render code here.
    GLenum glError = glGetError();
    glDrawElements(GL_TRIANGLES,
                   NUM_INDICES * num_bacterias,
                   GL_UNSIGNED_INT,
                   NULL);
    glError = glGetError();
    assert (GL_NO_ERROR == glError);
    glfwSwapBuffers();
    glBindVertexArray(0);
 
    return viewer_no_error;

Here is where I execute the kernel:

cl_engine_status_t cl_engine_step_1D (const cl_engine_t* engine,
                                      const char* kernel,
                                      cl_buffer_t** buffers_to_acquire,
                                      int num_buffers,
                                      size_t work_size,
                                      size_t local_work_size)
{
    cl_int err;
 
    size_t g_work_size[1] = {work_size};
    size_t l_work_size[1] = {local_work_size};
 
    cl_mem* buffers = alloca(sizeof(cl_mem) * num_buffers);
   
    if (0 != num_buffers && NULL != buffers_to_acquire)
    {
        for (int i = 0; i < num_buffers; i++)
        {
            buffers[i] = buffers_to_acquire[i]->buffer;               
        }
       
        glFinish();
        err = clEnqueueAcquireGLObjects(engine->queue,
                                        num_buffers,
                                        buffers,
                                        0,
                                        NULL,
                                        NULL);
        if (CL_SUCCESS != err)
        {
            return cl_engine_failed_sync_buffers;
        }
    }
   
    err = clEnqueueNDRangeKernel(engine->queue,
                                 get_kernel(&engine->program, kernel),
                                 1,
                                 NULL,
                                 g_work_size,
                                 0 == local_work_size ? NULL : l_work_size,
                                 0,
                                 NULL,
                                 NULL);
    if (CL_SUCCESS != err)
    {
        return cl_engine_failed_to_enqueue_kernel;
    }
   
 
    if (0 != num_buffers && NULL != buffers_to_acquire)
    {
        err = clEnqueueReleaseGLObjects(engine->queue,
                                        num_buffers,
                                        buffers,
                                        0,
                                        NULL,
                                        NULL);  
        if (CL_SUCCESS != err)
        {
            return cl_engine_failed_sync_buffers;
        }
       
    }
    clFinish(engine->queue);    
 
    return cl_engine_no_error;
}
 

So the only thing that change is that I rebind everytimes before rendering. I thought opencl was unbinding the vao but glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &current_vao) always report that my vao is bound. I have tested with opengl 4.3 and 3.3.

Thanks in advance for any possible help ! :)

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.