Blender V4.3
gpu_py_batch.cc File Reference
#include <Python.h>
#include "BLI_utildefines.h"
#include "GPU_batch.hh"
#include "../generic/py_capi_utils.hh"
#include "../generic/python_compat.hh"
#include "gpu_py.hh"
#include "gpu_py_element.hh"
#include "gpu_py_shader.hh"
#include "gpu_py_vertex_buffer.hh"
#include "gpu_py_batch.hh"

Go to the source code of this file.

Functions

Utility Functions
static bool pygpu_batch_is_program_or_error (BPyGPUBatch *self)
 
Public API
PyObject * BPyGPUBatch_CreatePyObject (blender::gpu::Batch *batch)
 

GPUBatch Type

static PyMethodDef pygpu_batch__tp_methods []
 
PyTypeObject BPyGPUBatch_Type
 
static PyObject * pygpu_batch__tp_new (PyTypeObject *, PyObject *args, PyObject *kwds)
 
 PyDoc_STRVAR (pygpu_batch_vertbuf_add_doc, ".. method:: vertbuf_add(buf)\n" "\n" " Add another vertex buffer to the Batch.\n" " It is not possible to add more vertices to the batch using this method.\n" " Instead it can be used to add more attributes to the existing vertices.\n" " A good use case would be when you have a separate\n" " vertex buffer for vertex positions and vertex normals.\n" " Current a batch can have at most " STRINGIFY(GPU_BATCH_VBO_MAX_LEN) " vertex buffers.\n" "\n" " :arg buf: The vertex buffer that will be added to the batch.\n" " :type buf: :class:`gpu.types.GPUVertBuf`\n")
 
static PyObject * pygpu_batch_vertbuf_add (BPyGPUBatch *self, BPyGPUVertBuf *py_buf)
 
 PyDoc_STRVAR (pygpu_batch_program_set_doc, ".. method:: program_set(program)\n" "\n" " Assign a shader to this batch that will be used for drawing when not overwritten later.\n" " Note: This method has to be called in the draw context that the batch will be drawn in.\n" " This function does not need to be called when you always\n" " set the shader when calling :meth:`gpu.types.GPUBatch.draw`.\n" "\n" " :arg program: The program/shader the batch will use in future draw calls.\n" " :type program: :class:`gpu.types.GPUShader`\n")
 
static PyObject * pygpu_batch_program_set (BPyGPUBatch *self, BPyGPUShader *py_shader)
 
 PyDoc_STRVAR (pygpu_batch_draw_doc, ".. method:: draw(program=None)\n" "\n" " Run the drawing program with the parameters assigned to the batch.\n" "\n" " :arg program: Program that performs the drawing operations.\n" " If ``None`` is passed, the last program set to this batch will run.\n" " :type program: :class:`gpu.types.GPUShader`\n")
 
static PyObject * pygpu_batch_draw (BPyGPUBatch *self, PyObject *args)
 
 PyDoc_STRVAR (pygpu_batch_draw_instanced_doc, ".. method:: draw_instanced(program, *, instance_start=0, instance_count=0)\n" "\n" " Draw multiple instances of the drawing program with the parameters assigned\n" " to the batch. In the vertex shader, `gl_InstanceID` will contain the instance\n" " number being drawn.\n" "\n" " :arg program: Program that performs the drawing operations.\n" " :type program: :class:`gpu.types.GPUShader`\n" " :arg instance_start: Number of the first instance to draw.\n" " :type instance_start: int\n" " :arg instance_count: Number of instances to draw. When not provided or set to 0\n" " the number of instances will be determined by the number of rows in the first\n" " vertex buffer.\n" " :type instance_count: int\n")
 
static PyObject * pygpu_batch_draw_instanced (BPyGPUBatch *self, PyObject *args, PyObject *kw)
 
 PyDoc_STRVAR (pygpu_batch_draw_range_doc, ".. method:: draw_range(program, *, elem_start=0, elem_count=0)\n" "\n" " Run the drawing program with the parameters assigned to the batch. " "Only draw the ``elem_count`` elements of the index buffer starting at ``elem_start``.\n" "\n" " :arg program: Program that performs the drawing operations.\n" " :type program: :class:`gpu.types.GPUShader`\n" " :arg elem_start: First index to draw. When not provided or set to 0 drawing\n" " will start from the first element of the index buffer.\n" " :type elem_start: int\n" " :arg elem_count: Number of elements of the index buffer to draw. When not\n" " provided or set to 0 all elements from ``elem_start`` to the end of the\n" " index buffer will be drawn.\n" " :type elem_count: int\n")
 
static PyObject * pygpu_batch_draw_range (BPyGPUBatch *self, PyObject *args, PyObject *kw)
 
static PyObject * pygpu_batch_program_use_begin (BPyGPUBatch *self)
 
static PyObject * pygpu_batch_program_use_end (BPyGPUBatch *self)
 
static int pygpu_batch__tp_traverse (BPyGPUBatch *self, visitproc visit, void *arg)
 
static int pygpu_batch__tp_clear (BPyGPUBatch *self)
 
static int pygpu_batch__tp_is_gc (BPyGPUBatch *self)
 
static void pygpu_batch__tp_dealloc (BPyGPUBatch *self)
 
 PyDoc_STRVAR (pygpu_batch__tp_doc, ".. class:: GPUBatch(type, buf, elem=None)\n" "\n" " Reusable container for drawable geometry.\n" "\n" " :arg type: The primitive type of geometry to be drawn.\n" " Possible values are `POINTS`, `LINES`, `TRIS`, `LINE_STRIP`, `LINE_LOOP`, `TRI_STRIP`, " "`TRI_FAN`, `LINES_ADJ`, `TRIS_ADJ` and `LINE_STRIP_ADJ`.\n" " :type type: str\n" " :arg buf: Vertex buffer containing all or some of the attributes required for drawing.\n" " :type buf: :class:`gpu.types.GPUVertBuf`\n" " :arg elem: An optional index buffer.\n" " :type elem: :class:`gpu.types.GPUIndexBuf`\n")
 

Detailed Description

This file defines the off-screen functionalities of the 'gpu' module used for off-screen OpenGL rendering.

  • Use bpygpu_ for local API.
  • Use BPyGPU for public API.

Definition in file gpu_py_batch.cc.

Function Documentation

◆ BPyGPUBatch_CreatePyObject()

PyObject * BPyGPUBatch_CreatePyObject ( blender::gpu::Batch * batch)

Definition at line 529 of file gpu_py_batch.cc.

References batch, BPyGPUBatch_Type, BPyGPUBatch::references, and self.

Referenced by pygpu_batch__tp_new().

◆ PyDoc_STRVAR() [1/6]

PyDoc_STRVAR ( pygpu_batch__tp_doc ,
".. class:: GPUBatch(type, buf, elem=None)\n" "\n" " Reusable container for drawable geometry.\n" "\n" " :arg type: The primitive type of geometry to be drawn.\n" " Possible values are `POINTS` ,
`LINES` ,
`TRIS` ,
`LINE_STRIP` ,
`LINE_LOOP` ,
`TRI_STRIP` ,
" "`TRI_FAN` ,
`LINES_ADJ` ,
`TRIS_ADJ` and `LINE_STRIP_ADJ`.\n" " :type type:str\n" " :arg buf:Vertex buffer containing all or some of the attributes required for drawing.\n" " :type buf::class:`gpu.types.GPUVertBuf`\n" " :arg elem:An optional index buffer.\n" " :type elem::class:`gpu.types.GPUIndexBuf`\n"  )

◆ PyDoc_STRVAR() [2/6]

PyDoc_STRVAR ( pygpu_batch_draw_doc ,
".. method:: draw(program=None)\n" "\n" " Run the drawing program with the parameters assigned to the batch.\n" "\n" " :arg program: Program that performs the drawing operations.\n" " If ``None`` is passed,
the last program set to this batch will run.\n" " :type program::class:`gpu.types.GPUShader`\n"  )

◆ PyDoc_STRVAR() [3/6]

PyDoc_STRVAR ( pygpu_batch_draw_instanced_doc ,
".. method:: draw_instanced(program, *, instance_start=0, instance_count=0)\n" "\n" " Draw multiple instances of the drawing program with the parameters assigned\n" " to the batch. In the vertex shader,
`gl_InstanceID` will contain the instance\n" " number being drawn.\n" "\n" " :arg program:Program that performs the drawing operations.\n" " :type program::class:`gpu.types.GPUShader`\n" " :arg instance_start:Number of the first instance to draw.\n" " :type instance_start:int\n" " :arg instance_count:Number of instances to draw. When not provided or set to 0\n" " the number of instances will be determined by the number of rows in the first\n" " vertex buffer.\n" " :type instance_count:int\n"  )

◆ PyDoc_STRVAR() [4/6]

PyDoc_STRVAR ( pygpu_batch_draw_range_doc ,
".. method:: draw_range(program, *, elem_start=0, elem_count=0)\n" "\n" " Run the drawing program with the parameters assigned to the batch. " "Only draw the ``elem_count`` elements of the index buffer starting at ``elem_start``.\n" "\n" " :arg program: Program that performs the drawing operations.\n" " :type program: :class:`gpu.types.GPUShader`\n" " :arg elem_start: First index to draw. When not provided or set to 0 drawing\n" " will start from the first element of the index buffer.\n" " :type elem_start: int\n" " :arg elem_count: Number of elements of the index buffer to draw. When not\n" " provided or set to 0 all elements from ``elem_start`` to the end of the\n" " index buffer will be drawn.\n" " :type elem_count: int\n"  )

◆ PyDoc_STRVAR() [5/6]

PyDoc_STRVAR ( pygpu_batch_program_set_doc ,
".. method:: program_set(program)\n" "\n" " Assign a shader to this batch that will be used for drawing when not overwritten later.\n" " Note: This method has to be called in the draw context that the batch will be drawn in.\n" " This function does not need to be called when you always\n" " set the shader when calling :meth:`gpu.types.GPUBatch.draw`.\n" "\n" " :arg program: The program/shader the batch will use in future draw calls.\n" " :type program: :class:`gpu.types.GPUShader`\n"  )

◆ PyDoc_STRVAR() [6/6]

PyDoc_STRVAR ( pygpu_batch_vertbuf_add_doc ,
".. method:: vertbuf_add(buf)\n" "\n" " Add another vertex buffer to the Batch.\n" " It is not possible to add more vertices to the batch using this method.\n" " Instead it can be used to add more attributes to the existing vertices.\n" " A good use case would be when you have a separate\n" " vertex buffer for vertex positions and vertex normals.\n" " Current a batch can have at most " STRINGIFY(GPU_BATCH_VBO_MAX_LEN) " vertex buffers.\n" "\n" " :arg buf: The vertex buffer that will be added to the batch.\n" " :type buf: :class:`gpu.types.GPUVertBuf`\n"  )

◆ pygpu_batch__tp_clear()

static int pygpu_batch__tp_clear ( BPyGPUBatch * self)
static

Definition at line 412 of file gpu_py_batch.cc.

References self.

Referenced by pygpu_batch__tp_dealloc().

◆ pygpu_batch__tp_dealloc()

static void pygpu_batch__tp_dealloc ( BPyGPUBatch * self)
static

Definition at line 425 of file gpu_py_batch.cc.

References GPU_batch_discard(), pygpu_batch__tp_clear(), and self.

◆ pygpu_batch__tp_is_gc()

static int pygpu_batch__tp_is_gc ( BPyGPUBatch * self)
static

Definition at line 418 of file gpu_py_batch.cc.

References self.

◆ pygpu_batch__tp_new()

◆ pygpu_batch__tp_traverse()

static int pygpu_batch__tp_traverse ( BPyGPUBatch * self,
visitproc visit,
void * arg )
static

Definition at line 406 of file gpu_py_batch.cc.

References self.

◆ pygpu_batch_draw()

static PyObject * pygpu_batch_draw ( BPyGPUBatch * self,
PyObject * args )
static

◆ pygpu_batch_draw_instanced()

static PyObject * pygpu_batch_draw_instanced ( BPyGPUBatch * self,
PyObject * args,
PyObject * kw )
static

◆ pygpu_batch_draw_range()

static PyObject * pygpu_batch_draw_range ( BPyGPUBatch * self,
PyObject * args,
PyObject * kw )
static

◆ pygpu_batch_is_program_or_error()

static bool pygpu_batch_is_program_or_error ( BPyGPUBatch * self)
static

Definition at line 35 of file gpu_py_batch.cc.

References self.

Referenced by pygpu_batch_draw(), pygpu_batch_program_use_begin(), and pygpu_batch_program_use_end().

◆ pygpu_batch_program_set()

static PyObject * pygpu_batch_program_set ( BPyGPUBatch * self,
BPyGPUShader * py_shader )
static

◆ pygpu_batch_program_use_begin()

static PyObject * pygpu_batch_program_use_begin ( BPyGPUBatch * self)
static

Definition at line 360 of file gpu_py_batch.cc.

References GPU_shader_bind(), pygpu_batch_is_program_or_error(), and self.

◆ pygpu_batch_program_use_end()

static PyObject * pygpu_batch_program_use_end ( BPyGPUBatch * self)
static

Definition at line 369 of file gpu_py_batch.cc.

References GPU_shader_unbind(), pygpu_batch_is_program_or_error(), and self.

◆ pygpu_batch_vertbuf_add()

static PyObject * pygpu_batch_vertbuf_add ( BPyGPUBatch * self,
BPyGPUVertBuf * py_buf )
static

Variable Documentation

◆ BPyGPUBatch_Type

PyTypeObject BPyGPUBatch_Type

Definition at line 455 of file gpu_py_batch.cc.

Referenced by bpygpu_types_init(), and BPyGPUBatch_CreatePyObject().

◆ pygpu_batch__tp_methods

PyMethodDef pygpu_batch__tp_methods[]
static
Initial value:
= {
{"vertbuf_add", (PyCFunction)pygpu_batch_vertbuf_add, METH_O, pygpu_batch_vertbuf_add_doc},
{"program_set", (PyCFunction)pygpu_batch_program_set, METH_O, pygpu_batch_program_set_doc},
{"draw", (PyCFunction)pygpu_batch_draw, METH_VARARGS, pygpu_batch_draw_doc},
{"draw_instanced",
METH_VARARGS | METH_KEYWORDS,
pygpu_batch_draw_instanced_doc},
{"draw_range",
(PyCFunction)pygpu_batch_draw_range,
METH_VARARGS | METH_KEYWORDS,
pygpu_batch_draw_range_doc},
{"_program_use_begin", (PyCFunction)pygpu_batch_program_use_begin, METH_NOARGS, ""},
{"_program_use_end", (PyCFunction)pygpu_batch_program_use_end, METH_NOARGS, ""},
{nullptr, nullptr, 0, nullptr},
}
static PyObject * pygpu_batch_draw(BPyGPUBatch *self, PyObject *args)
static PyObject * pygpu_batch_program_use_begin(BPyGPUBatch *self)
static PyObject * pygpu_batch_program_set(BPyGPUBatch *self, BPyGPUShader *py_shader)
static PyObject * pygpu_batch_program_use_end(BPyGPUBatch *self)
static PyObject * pygpu_batch_draw_instanced(BPyGPUBatch *self, PyObject *args, PyObject *kw)
static PyObject * pygpu_batch_draw_range(BPyGPUBatch *self, PyObject *args, PyObject *kw)
static PyObject * pygpu_batch_vertbuf_add(BPyGPUBatch *self, BPyGPUVertBuf *py_buf)

Definition at line 383 of file gpu_py_batch.cc.