Blender 2.8 new draw API


I am trying to start an addon, and test the new draw API. But when I try one of the examples presented in the link, I get an error saying that " ‘GPUShader’ object has no attribute ‘batch’ ".

Do you know if there is anything to replace it ? When I try to autocomplete I can’t find anything with “batch” in it :confused:

The new batch method is still under discussion.
But you can get a batch with this function:

import gpu

def batch_for_shader(shader, type, content, indices=None):
    length = max(len(data) for data in content.values())
    vbo_format = shader.format_calc()
    vbo = gpu.types.GPUVertBuf(vbo_format, length)

    for identifier, data in content.items():
        vbo.attr_fill(identifier, data)

    if indices is None:
        return gpu.types.GPUBatch(type=type, buf=vbo)
        ibo = gpu.types.GPUIndexBuf(type="POINTS", seq=indices)
        return gpu.types.GPUBatch(type=type, buf=vbo, elem=ibo)

Just use this function instead of shader.batch_new.
However It’s good to be aware the API can still change a lot.


Thanks a lot, yes I know that but it is just to play a bit with the new API :smiley: Thanks again !