Page MenuHome

PyGPU: Allow changing the attributes of a 'GPUVertFormat'
Needs ReviewPublic

Authored by Germano Cavalcante (mano-wii) on Aug 19 2022, 1:44 AM.

Details

Summary

Implement a new intern type for editing GPUVertFormat attributes:
GPUVertAttr


In python, it is not uncommon to automatically create a GPUVertFormat
through the GPUShader.format_calc() method.

This conveniently avoids the need to call
GPUVertFormat.attr_add(id, comp_type, len, fetch_mode) for every
attribute that Shader supports.

However, once a GPUVertFormat is created, it cannot be changed.

This is an inconvenient limitation as VBOs with a 2D format attribute
are correctly read by Shaders that support a 3D attribute.

This patch proposes the creation of a new internal type for editing
attributes: GPUVertAttr.

So we can edit an attribute as follows:

import gpu
shader = gpu.shader.from_builtin('3D_POLYLINE_UNIFORM_COLOR')
format = shader.format_calc()
format['pos'].len = 2

Diff Detail

Repository
rB Blender
Branch
pygpu_GPUVertAttr (branched from master)
Build Status
Buildable 23392
Build 23392: arc lint + arc unit