Blender  V3.3
Classes | Macros | Typedefs | Functions
gpu_buffers.c File Reference
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_bitmap.h"
#include "BLI_ghash.h"
#include "BLI_math_color.h"
#include "BLI_utildefines.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "BKE_DerivedMesh.h"
#include "BKE_attribute.h"
#include "BKE_ccg.h"
#include "BKE_customdata.h"
#include "BKE_mesh.h"
#include "BKE_paint.h"
#include "BKE_pbvh.h"
#include "BKE_subdiv_ccg.h"
#include "GPU_batch.h"
#include "GPU_buffers.h"
#include "DRW_engine.h"
#include "gpu_private.h"
#include "bmesh.h"

Go to the source code of this file.

Classes

struct  GPU_PBVH_Buffers
 
struct  GPUAttrRef
 
struct  PBVHGPUFormat
 

Macros

#define MAX_GPU_ATTR   256
 

Typedefs

typedef struct GPUAttrRef GPUAttrRef
 
typedef struct PBVHGPUFormat PBVHGPUFormat
 

Functions

PBVHGPUFormatGPU_pbvh_make_format (void)
 
void GPU_pbvh_free_format (PBVHGPUFormat *vbo_id)
 
Generic
static int gpu_pbvh_make_attr_offs (eAttrDomainMask domain_mask, eCustomDataMask type_mask, const CustomData *vdata, const CustomData *edata, const CustomData *ldata, const CustomData *pdata, GPUAttrRef r_cd_attrs[MAX_GPU_ATTR], bool active_only, int active_type, int active_domain, const CustomDataLayer *active_layer, const CustomDataLayer *render_layer)
 
GPU_PBVH_BuffersGPU_pbvh_bmesh_buffers_build (bool smooth_shading)
 
static bool gpu_pbvh_format_equals (PBVHGPUFormat *a, PBVHGPUFormat *b)
 
bool GPU_pbvh_attribute_names_update (PBVHType pbvh_type, PBVHGPUFormat *vbo_id, const CustomData *vdata, const CustomData *ldata, bool active_attrs_only)
 
GPUBatchGPU_pbvh_buffers_batch_get (GPU_PBVH_Buffers *buffers, bool fast, bool wires)
 
bool GPU_pbvh_buffers_has_overlays (GPU_PBVH_Buffers *buffers)
 
short GPU_pbvh_buffers_material_index_get (GPU_PBVH_Buffers *buffers)
 
static void gpu_pbvh_buffers_clear (GPU_PBVH_Buffers *buffers)
 
void GPU_pbvh_buffers_update_flush (GPU_PBVH_Buffers *buffers)
 
void GPU_pbvh_buffers_free (GPU_PBVH_Buffers *buffers)
 
PBVH Utils
void gpu_pbvh_init ()
 
void gpu_pbvh_exit ()
 
static CustomDataLayerget_active_layer (const CustomData *cdata, int type)
 
static CustomDataLayerget_render_layer (const CustomData *cdata, int type)
 
static bool gpu_pbvh_vert_buf_data_set (PBVHGPUFormat *vbo_id, GPU_PBVH_Buffers *buffers, uint vert_len)
 
static void gpu_pbvh_batch_init (GPU_PBVH_Buffers *buffers, GPUPrimType prim)
 
Mesh PBVH
static bool gpu_pbvh_is_looptri_visible (const MLoopTri *lt, const MVert *mvert, const MLoop *mloop, const int *sculpt_face_sets)
 
void GPU_pbvh_mesh_buffers_update (PBVHGPUFormat *vbo_id, GPU_PBVH_Buffers *buffers, const MVert *mvert, const CustomData *vdata, const CustomData *ldata, const float *vmask, const int *sculpt_face_sets, int face_sets_color_seed, int face_sets_color_default, int update_flags, const float(*vert_normals)[3])
 
GPU_PBVH_BuffersGPU_pbvh_mesh_buffers_build (const MPoly *mpoly, const MLoop *mloop, const MLoopTri *looptri, const MVert *mvert, const int *face_indices, const int *sculpt_face_sets, const int face_indices_len, const struct Mesh *mesh)
 
Grid PBVH
static void gpu_pbvh_grid_fill_index_buffers (GPU_PBVH_Buffers *buffers, SubdivCCG *UNUSED(subdiv_ccg), const int *UNUSED(face_sets), const int *grid_indices, uint visible_quad_len, int totgrid, int gridsize)
 
void GPU_pbvh_grid_buffers_update_free (GPU_PBVH_Buffers *buffers, const struct DMFlagMat *grid_flag_mats, const int *grid_indices)
 
void GPU_pbvh_grid_buffers_update (PBVHGPUFormat *vbo_id, GPU_PBVH_Buffers *buffers, SubdivCCG *subdiv_ccg, CCGElem **grids, const struct DMFlagMat *grid_flag_mats, int *grid_indices, int totgrid, const int *sculpt_face_sets, const int face_sets_color_seed, const int face_sets_color_default, const struct CCGKey *key, const int update_flags)
 
GPU_PBVH_BuffersGPU_pbvh_grid_buffers_build (int totgrid, BLI_bitmap **grid_hidden, bool smooth)
 
BMesh PBVH
static void gpu_bmesh_vert_to_buffer_copy (PBVHGPUFormat *vbo_id, BMVert *v, GPUVertBuf *vert_buf, int v_index, const float fno[3], const float *fmask, const int cd_vert_mask_offset, const bool show_mask, const bool show_vcol, bool *empty_mask)
 
static int gpu_bmesh_vert_visible_count (GSet *bm_unique_verts, GSet *bm_other_verts)
 
static int gpu_bmesh_face_visible_count (GSet *bm_faces)
 
void GPU_pbvh_bmesh_buffers_update_free (GPU_PBVH_Buffers *buffers)
 
void GPU_pbvh_bmesh_buffers_update (PBVHGPUFormat *vbo_id, GPU_PBVH_Buffers *buffers, BMesh *bm, GSet *bm_faces, GSet *bm_unique_verts, GSet *bm_other_verts, const int update_flags)
 

Detailed Description

Mesh drawing using OpenGL VBO (Vertex Buffer Objects)

Definition in file gpu_buffers.c.

Macro Definition Documentation

◆ MAX_GPU_ATTR

#define MAX_GPU_ATTR   256

Definition at line 90 of file gpu_buffers.c.

Typedef Documentation

◆ GPUAttrRef

typedef struct GPUAttrRef GPUAttrRef

◆ PBVHGPUFormat

typedef struct PBVHGPUFormat PBVHGPUFormat

Function Documentation

◆ get_active_layer()

static CustomDataLayer* get_active_layer ( const CustomData cdata,
int  type 
)
static

◆ get_render_layer()

static CustomDataLayer* get_render_layer ( const CustomData cdata,
int  type 
)
static

◆ gpu_bmesh_face_visible_count()

static int gpu_bmesh_face_visible_count ( GSet bm_faces)
static

◆ gpu_bmesh_vert_to_buffer_copy()

static void gpu_bmesh_vert_to_buffer_copy ( PBVHGPUFormat vbo_id,
BMVert v,
GPUVertBuf vert_buf,
int  v_index,
const float  fno[3],
const float fmask,
const int  cd_vert_mask_offset,
const bool  show_mask,
const bool  show_vcol,
bool empty_mask 
)
static

◆ gpu_bmesh_vert_visible_count()

static int gpu_bmesh_vert_visible_count ( GSet bm_unique_verts,
GSet bm_other_verts 
)
static

◆ GPU_pbvh_attribute_names_update()

bool GPU_pbvh_attribute_names_update ( PBVHType  pbvh_type,
PBVHGPUFormat vbo_id,
const CustomData vdata,
const CustomData ldata,
bool  active_attrs_only 
)

◆ gpu_pbvh_batch_init()

static void gpu_pbvh_batch_init ( GPU_PBVH_Buffers buffers,
GPUPrimType  prim 
)
static

◆ GPU_pbvh_bmesh_buffers_build()

GPU_PBVH_Buffers* GPU_pbvh_bmesh_buffers_build ( bool  smooth_shading)

Threaded: do not call any functions that use OpenGL calls!

Definition at line 1169 of file gpu_buffers.c.

References MEM_callocN, GPU_PBVH_Buffers::show_overlay, GPU_PBVH_Buffers::smooth, and GPU_PBVH_Buffers::use_bmesh.

Referenced by pbvh_update_draw_buffer_cb().

◆ GPU_pbvh_bmesh_buffers_update()

void GPU_pbvh_bmesh_buffers_update ( PBVHGPUFormat vbo_id,
struct GPU_PBVH_Buffers buffers,
struct BMesh bm,
struct GSet bm_faces,
struct GSet bm_unique_verts,
struct GSet bm_other_verts,
const int  update_flags 
)

◆ GPU_pbvh_bmesh_buffers_update_free()

void GPU_pbvh_bmesh_buffers_update_free ( GPU_PBVH_Buffers buffers)

Free part of data for update. Not thread safe, must run in OpenGL main thread.

Definition at line 984 of file gpu_buffers.c.

References GPU_BATCH_DISCARD_SAFE, GPU_INDEXBUF_DISCARD_SAFE, GPU_PBVH_Buffers::index_buf, GPU_PBVH_Buffers::index_lines_buf, GPU_PBVH_Buffers::lines, GPU_PBVH_Buffers::smooth, and GPU_PBVH_Buffers::triangles.

Referenced by pbvh_update_draw_buffers().

◆ GPU_pbvh_buffers_batch_get()

GPUBatch* GPU_pbvh_buffers_batch_get ( GPU_PBVH_Buffers buffers,
bool  fast,
bool  wires 
)

◆ gpu_pbvh_buffers_clear()

static void gpu_pbvh_buffers_clear ( GPU_PBVH_Buffers buffers)
static

◆ GPU_pbvh_buffers_free()

void GPU_pbvh_buffers_free ( GPU_PBVH_Buffers buffers)

Free buffers. Not thread safe, must run in OpenGL main thread.

Definition at line 1471 of file gpu_buffers.c.

References gpu_pbvh_buffers_clear(), and MEM_freeN.

Referenced by BKE_pbvh_free(), and pbvh_free_draw_buffers().

◆ GPU_pbvh_buffers_has_overlays()

bool GPU_pbvh_buffers_has_overlays ( GPU_PBVH_Buffers buffers)

Definition at line 1434 of file gpu_buffers.c.

References GPU_PBVH_Buffers::show_overlay.

Referenced by sculpt_draw_cb().

◆ GPU_pbvh_buffers_material_index_get()

short GPU_pbvh_buffers_material_index_get ( GPU_PBVH_Buffers buffers)

Definition at line 1439 of file gpu_buffers.c.

References GPU_PBVH_Buffers::material_index.

Referenced by sculpt_draw_cb().

◆ GPU_pbvh_buffers_update_flush()

void GPU_pbvh_buffers_update_flush ( GPU_PBVH_Buffers buffers)

Finish update. Not thread safe, must run in OpenGL main thread.

Definition at line 1457 of file gpu_buffers.c.

References GPU_PBVH_Buffers::clear_bmesh_on_flush, gpu_pbvh_buffers_clear(), GPU_vertbuf_get_data(), GPU_vertbuf_use(), and GPU_PBVH_Buffers::vert_buf.

Referenced by pbvh_update_draw_buffers().

◆ gpu_pbvh_exit()

void gpu_pbvh_exit ( void  )

Definition at line 141 of file gpu_buffers.c.

Referenced by GPU_exit().

◆ gpu_pbvh_format_equals()

static bool gpu_pbvh_format_equals ( PBVHGPUFormat a,
PBVHGPUFormat b 
)
static

Definition at line 1266 of file gpu_buffers.c.

References Freestyle::a, usdtokens::b(), and MIN2.

Referenced by GPU_pbvh_attribute_names_update().

◆ GPU_pbvh_free_format()

void GPU_pbvh_free_format ( PBVHGPUFormat vbo_id)

Definition at line 113 of file gpu_buffers.c.

References MEM_SAFE_FREE.

Referenced by BKE_pbvh_free().

◆ GPU_pbvh_grid_buffers_build()

GPU_PBVH_Buffers* GPU_pbvh_grid_buffers_build ( int  totgrid,
unsigned int **  grid_hidden,
bool  smooth 
)

Threaded: do not call any functions that use OpenGL calls!

Definition at line 884 of file gpu_buffers.c.

References GPU_PBVH_Buffers::grid_hidden, MEM_callocN, GPU_PBVH_Buffers::show_overlay, smooth(), GPU_PBVH_Buffers::smooth, and GPU_PBVH_Buffers::totgrid.

Referenced by pbvh_update_draw_buffer_cb().

◆ GPU_pbvh_grid_buffers_update()

void GPU_pbvh_grid_buffers_update ( PBVHGPUFormat vbo_id,
GPU_PBVH_Buffers buffers,
struct SubdivCCG subdiv_ccg,
struct CCGElem **  grids,
const struct DMFlagMat grid_flag_mats,
int *  grid_indices,
int  totgrid,
const int *  sculpt_face_sets,
int  face_sets_color_seed,
int  face_sets_color_default,
const struct CCGKey key,
int  update_flags 
)

◆ GPU_pbvh_grid_buffers_update_free()

void GPU_pbvh_grid_buffers_update_free ( GPU_PBVH_Buffers buffers,
const struct DMFlagMat grid_flag_mats,
const int *  grid_indices 
)

◆ gpu_pbvh_grid_fill_index_buffers()

static void gpu_pbvh_grid_fill_index_buffers ( GPU_PBVH_Buffers buffers,
SubdivCCG UNUSEDsubdiv_ccg,
const int *  UNUSEDface_sets,
const int *  grid_indices,
uint  visible_quad_len,
int  totgrid,
int  gridsize 
)
static

◆ gpu_pbvh_init()

void gpu_pbvh_init ( void  )

Definition at line 137 of file gpu_buffers.c.

Referenced by GPU_init().

◆ gpu_pbvh_is_looptri_visible()

static bool gpu_pbvh_is_looptri_visible ( const MLoopTri lt,
const MVert mvert,
const MLoop mloop,
const int *  sculpt_face_sets 
)
static

◆ gpu_pbvh_make_attr_offs()

static int gpu_pbvh_make_attr_offs ( eAttrDomainMask  domain_mask,
eCustomDataMask  type_mask,
const CustomData vdata,
const CustomData edata,
const CustomData ldata,
const CustomData pdata,
GPUAttrRef  r_cd_attrs[MAX_GPU_ATTR],
bool  active_only,
int  active_type,
int  active_domain,
const CustomDataLayer active_layer,
const CustomDataLayer render_layer 
)
static

Builds a list of attributes from a set of domains and a set of customdata types.

Parameters
active_onlyReturns only one item, a GPUAttrRef to active_layer.
active_layerCustomDataLayer to use for the active layer.
active_layerCustomDataLayer to use for the render layer.

Definition at line 1189 of file gpu_buffers.c.

References ATTR_DOMAIN_POINT, CD_FLAG_TEMPORARY, GPUAttrRef::cd_offset, CD_TYPE_AS_MASK, count, GPUAttrRef::domain, CustomDataLayer::flag, GPUAttrRef::layer_idx, CustomData::layers, MAX_GPU_ATTR, CustomDataLayer::offset, SWAP, CustomData::totlayer, GPUAttrRef::type, and CustomDataLayer::type.

Referenced by GPU_pbvh_attribute_names_update(), and GPU_pbvh_mesh_buffers_update().

◆ GPU_pbvh_make_format()

PBVHGPUFormat* GPU_pbvh_make_format ( void  )

◆ GPU_pbvh_mesh_buffers_build()

GPU_PBVH_Buffers* GPU_pbvh_mesh_buffers_build ( const MPoly mpoly,
const MLoop mloop,
const MLoopTri looptri,
const MVert mvert,
const int *  face_indices,
const int *  sculpt_face_sets,
const int  face_indices_len,
const struct Mesh mesh 
)

◆ GPU_pbvh_mesh_buffers_update()

void GPU_pbvh_mesh_buffers_update ( PBVHGPUFormat vbo_id,
GPU_PBVH_Buffers buffers,
const MVert mvert,
const CustomData vdata,
const CustomData ldata,
const float vmask,
const int *  sculpt_face_sets,
int  face_sets_color_seed,
int  face_sets_color_default,
int  update_flags,
const float(*)  vert_normals[3] 
)

Definition at line 222 of file gpu_buffers.c.

References MLoopCol::a, blender::math::abs(), PBVHGPUFormat::active_attrs_only, ATTR_DOMAIN_AUTO, ATTR_DOMAIN_CORNER, ATTR_DOMAIN_MASK_COLOR, ATTR_DOMAIN_MASK_CORNER, ATTR_DOMAIN_POINT, MLoopCol::b, BKE_id_attribute_copy_domains_temp(), BKE_id_attribute_domain(), BKE_id_attributes_active_color_get(), BKE_id_attributes_render_color_get(), BKE_mesh_calc_poly_normal(), BKE_paint_face_set_overlay_color_get(), BLI_color_from_srgb_table, CD_MASK_COLOR_ALL, CD_MASK_MLOOPUV, CD_MLOOPUV, CD_PROP_COLOR, BMVert::co, PBVHGPUFormat::col, MPropCol::color, copy_v3_v3(), copy_v3_v3_short(), CustomDataLayer::data, GPUAttrRef::domain, GPU_PBVH_Buffers::face_indices, GPU_PBVH_Buffers::face_indices_len, PBVHGPUFormat::fset, MLoopCol::g, get_active_layer(), get_render_layer(), gpu_pbvh_batch_init(), GPU_PBVH_BUFFERS_SHOW_MASK, GPU_PBVH_BUFFERS_SHOW_SCULPT_FACE_SETS, GPU_PBVH_BUFFERS_SHOW_VCOL, gpu_pbvh_is_looptri_visible(), gpu_pbvh_make_attr_offs(), gpu_pbvh_vert_buf_data_set(), GPU_PRIM_TRIS, GPU_vertbuf_attr_get_raw_data(), GPU_vertbuf_raw_step(), Mesh::id, ID_ME, GPUAttrRef::layer_idx, CustomData::layers, MPoly::loopstart, GPU_PBVH_Buffers::looptri, MPoly::mat_nr, GPU_PBVH_Buffers::material_index, MAX_GPU_ATTR, GPU_PBVH_Buffers::mloop, GPU_PBVH_Buffers::mpoly, PBVHGPUFormat::msk, GPU_PBVH_Buffers::mvert, PBVHGPUFormat::nor, normal_float_to_short_v3(), NULL, MLoopTri::poly, PBVHGPUFormat::pos, MLoopCol::r, GPU_PBVH_Buffers::show_overlay, GPU_PBVH_Buffers::smooth, GPU_PBVH_Buffers::tot_tri, MLoopTri::tri, CustomDataLayer::type, UINT_MAX, unit_float_to_ushort_clamp(), MLoopUV::uv, PBVHGPUFormat::uv, v, MLoop::v, and GPU_PBVH_Buffers::vert_buf.

◆ gpu_pbvh_vert_buf_data_set()

static bool gpu_pbvh_vert_buf_data_set ( PBVHGPUFormat vbo_id,
GPU_PBVH_Buffers buffers,
uint  vert_len 
)
static