Blender V2.61 - r43446
Classes | Defines | Typedefs | Enumerations | Functions | Variables

gpu_buffers.c File Reference

#include <limits.h>
#include <stddef.h>
#include <string.h>
#include "GL/glew.h"
#include "MEM_guardedalloc.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_ghash.h"
#include "BLI_threads.h"
#include "DNA_meshdata_types.h"
#include "BKE_DerivedMesh.h"
#include "DNA_userdef_types.h"
#include "GPU_buffers.h"

Go to the source code of this file.

Classes

struct  GPUBufferPool
struct  GPUVertPointLink
struct  GPUBufferTypeSettings
struct  VertexBufferFormat
struct  GPU_Buffers

Defines

#define MAX_GPU_ATTRIB_DATA   32
#define MAX_MATERIALS   16384
#define MAX_FREE_GPU_BUFFERS   8

Typedefs

typedef struct GPUBufferPool GPUBufferPool
typedef struct GPUVertPointLink GPUVertPointLink
typedef void(* GPUBufferCopyFunc )(DerivedMesh *dm, float *varray, int *index, int *mat_orig_to_new, void *user_data)

Enumerations

enum  GPUBufferState {
  GPU_BUFFER_VERTEX_STATE = 1, GPU_BUFFER_NORMAL_STATE = 2, GPU_BUFFER_TEXCOORD_STATE = 4, GPU_BUFFER_COLOR_STATE = 8,
  GPU_BUFFER_ELEMENT_STATE = 16
}
enum  GPUBufferType {
  GPU_BUFFER_VERTEX = 0, GPU_BUFFER_NORMAL, GPU_BUFFER_COLOR, GPU_BUFFER_UV,
  GPU_BUFFER_EDGE, GPU_BUFFER_UVEDGE
}

Functions

static GPUBufferPoolgpu_buffer_pool_new (void)
static void gpu_buffer_pool_remove_index (GPUBufferPool *pool, int index)
static void gpu_buffer_pool_delete_last (GPUBufferPool *pool)
static void gpu_buffer_pool_free (GPUBufferPool *pool)
static GPUBufferPoolgpu_get_global_buffer_pool (void)
void GPU_global_buffer_pool_free (void)
GPUBufferGPU_buffer_alloc (int size)
void GPU_buffer_free (GPUBuffer *buffer)
static void gpu_drawobject_add_vert_point (GPUDrawObject *gdo, int vert_index, int point_index)
static void gpu_drawobject_add_triangle (GPUDrawObject *gdo, int base_point_index, int face_index, int v1, int v2, int v3)
static void gpu_drawobject_init_vert_points (GPUDrawObject *gdo, MFace *f, int totface)
GPUDrawObjectGPU_drawobject_new (DerivedMesh *dm)
void GPU_drawobject_free (DerivedMesh *dm)
static GPUBuffergpu_buffer_setup (DerivedMesh *dm, GPUDrawObject *object, int vector_size, int size, GLenum target, void *user, GPUBufferCopyFunc copy_f)
static void GPU_buffer_copy_vertex (DerivedMesh *dm, float *varray, int *index, int *mat_orig_to_new, void *UNUSED(user))
static void GPU_buffer_copy_normal (DerivedMesh *dm, float *varray, int *index, int *mat_orig_to_new, void *UNUSED(user))
static void GPU_buffer_copy_uv (DerivedMesh *dm, float *varray, int *index, int *mat_orig_to_new, void *UNUSED(user))
static void GPU_buffer_copy_color3 (DerivedMesh *dm, float *varray_, int *index, int *mat_orig_to_new, void *user)
static void copy_mcol_uc3 (unsigned char *v, unsigned char *col)
static void GPU_buffer_copy_mcol (DerivedMesh *dm, float *varray_, int *index, int *mat_orig_to_new, void *user)
static void GPU_buffer_copy_edge (DerivedMesh *dm, float *varray_, int *UNUSED(index), int *UNUSED(mat_orig_to_new), void *UNUSED(user))
static void GPU_buffer_copy_uvedge (DerivedMesh *dm, float *varray, int *UNUSED(index), int *UNUSED(mat_orig_to_new), void *UNUSED(user))
static MColgpu_buffer_color_type (DerivedMesh *dm)
static GPUBuffer ** gpu_drawobject_buffer_from_type (GPUDrawObject *gdo, GPUBufferType type)
static int gpu_buffer_size_from_type (DerivedMesh *dm, GPUBufferType type)
static GPUBuffergpu_buffer_setup_type (DerivedMesh *dm, GPUBufferType type)
static GPUBuffergpu_buffer_setup_common (DerivedMesh *dm, GPUBufferType type)
void GPU_vertex_setup (DerivedMesh *dm)
void GPU_normal_setup (DerivedMesh *dm)
void GPU_uv_setup (DerivedMesh *dm)
void GPU_color_setup (DerivedMesh *dm)
void GPU_edge_setup (DerivedMesh *dm)
void GPU_uvedge_setup (DerivedMesh *dm)
static int GPU_typesize (int type)
int GPU_attrib_element_size (GPUAttrib data[], int numdata)
void GPU_interleaved_attrib_setup (GPUBuffer *buffer, GPUAttrib data[], int numdata)
void GPU_buffer_unbind (void)
void GPU_color3_upload (DerivedMesh *dm, unsigned char *data)
void GPU_color4_upload (DerivedMesh *UNUSED(dm), unsigned char *UNUSED(data))
void GPU_color_switch (int mode)
int GPU_buffer_legacy (DerivedMesh *dm)
void * GPU_buffer_lock (GPUBuffer *buffer)
void * GPU_buffer_lock_stream (GPUBuffer *buffer)
void GPU_buffer_unlock (GPUBuffer *buffer)
void GPU_buffer_draw_elements (GPUBuffer *elements, unsigned int mode, int start, int count)
void GPU_update_mesh_buffers (GPU_Buffers *buffers, MVert *mvert, int *vert_indices, int totvert)
GPU_BuffersGPU_build_mesh_buffers (GHash *map, MVert *mvert, MFace *mface, int *face_indices, int totface, int *vert_indices, int tot_uniq_verts, int totvert)
void GPU_update_grid_buffers (GPU_Buffers *buffers, DMGridData **grids, int *grid_indices, int totgrid, int gridsize, int smooth)
GPU_BuffersGPU_build_grid_buffers (DMGridData **UNUSED(grids), int *UNUSED(grid_indices), int totgrid, int gridsize)
void GPU_draw_buffers (GPU_Buffers *buffers)
void GPU_free_buffers (GPU_Buffers *buffers)

Variables

static int useVBOs = -1
static GPUBufferState GLStates = 0
static GPUAttrib attribData [MAX_GPU_ATTRIB_DATA] = { { -1, 0, 0 } }
static GPUBufferPoolgpu_buffer_pool = NULL
const GPUBufferTypeSettings gpu_buffer_type_settings []

Detailed Description

Definition in file gpu_buffers.c.


Define Documentation

#define MAX_FREE_GPU_BUFFERS   8

Definition at line 90 of file gpu_buffers.c.

Referenced by GPU_buffer_free(), and gpu_buffer_pool_new().

#define MAX_GPU_ATTRIB_DATA   32

Definition at line 62 of file gpu_buffers.c.

Referenced by GPU_buffer_unbind(), and GPU_interleaved_attrib_setup().

#define MAX_MATERIALS   16384

Typedef Documentation

typedef void(* GPUBufferCopyFunc)(DerivedMesh *dm, float *varray, int *index, int *mat_orig_to_new, void *user_data)

Definition at line 467 of file gpu_buffers.c.

typedef struct GPUBufferPool GPUBufferPool

Enumeration Type Documentation

Enumerator:
GPU_BUFFER_VERTEX_STATE 
GPU_BUFFER_NORMAL_STATE 
GPU_BUFFER_TEXCOORD_STATE 
GPU_BUFFER_COLOR_STATE 
GPU_BUFFER_ELEMENT_STATE 

Definition at line 54 of file gpu_buffers.c.

Enumerator:
GPU_BUFFER_VERTEX 
GPU_BUFFER_NORMAL 
GPU_BUFFER_COLOR 
GPU_BUFFER_UV 
GPU_BUFFER_EDGE 
GPU_BUFFER_UVEDGE 

Definition at line 833 of file gpu_buffers.c.


Function Documentation

static void copy_mcol_uc3 ( unsigned char *  v,
unsigned char *  col 
) [static]

Definition at line 728 of file gpu_buffers.c.

Referenced by GPU_buffer_copy_mcol().

int GPU_attrib_element_size ( GPUAttrib  data[],
int  numdata 
)
GPUBuffer* GPU_buffer_alloc ( int  size)
static MCol* gpu_buffer_color_type ( DerivedMesh dm) [static]
static void GPU_buffer_copy_color3 ( DerivedMesh dm,
float *  varray_,
int *  index,
int *  mat_orig_to_new,
void *  user 
) [static]
static void GPU_buffer_copy_edge ( DerivedMesh dm,
float *  varray_,
int *  UNUSEDindex,
int *  UNUSEDmat_orig_to_new,
void *  UNUSEDuser 
) [static]
static void GPU_buffer_copy_mcol ( DerivedMesh dm,
float *  varray_,
int *  index,
int *  mat_orig_to_new,
void *  user 
) [static]
static void GPU_buffer_copy_normal ( DerivedMesh dm,
float *  varray,
int *  index,
int *  mat_orig_to_new,
void *  UNUSEDuser 
) [static]
static void GPU_buffer_copy_uv ( DerivedMesh dm,
float *  varray,
int *  index,
int *  mat_orig_to_new,
void *  UNUSEDuser 
) [static]
static void GPU_buffer_copy_uvedge ( DerivedMesh dm,
float *  varray,
int *  UNUSEDindex,
int *  UNUSEDmat_orig_to_new,
void *  UNUSEDuser 
) [static]
static void GPU_buffer_copy_vertex ( DerivedMesh dm,
float *  varray,
int *  index,
int *  mat_orig_to_new,
void *  UNUSEDuser 
) [static]
void GPU_buffer_draw_elements ( GPUBuffer elements,
unsigned int  mode,
int  start,
int  count 
)

Definition at line 1261 of file gpu_buffers.c.

References GPUBuffer::pointer, and useVBOs.

Referenced by cdDM_drawEdges(), and cdDM_drawLooseEdges().

void GPU_buffer_free ( GPUBuffer buffer)
int GPU_buffer_legacy ( DerivedMesh dm)
void* GPU_buffer_lock ( GPUBuffer buffer)

Definition at line 1212 of file gpu_buffers.c.

References GPUBuffer::id, GPUBuffer::pointer, and useVBOs.

void* GPU_buffer_lock_stream ( GPUBuffer buffer)

Definition at line 1229 of file gpu_buffers.c.

References GPUBuffer::id, GPUBuffer::pointer, GPUBuffer::size, and useVBOs.

Referenced by cdDM_drawMappedFacesGLSL().

static void gpu_buffer_pool_delete_last ( GPUBufferPool pool) [static]
static void gpu_buffer_pool_free ( GPUBufferPool pool) [static]
static GPUBufferPool* gpu_buffer_pool_new ( void  ) [static]
static void gpu_buffer_pool_remove_index ( GPUBufferPool pool,
int  index 
) [static]

Definition at line 111 of file gpu_buffers.c.

References GPUBufferPool::buffers, i, NULL, and GPUBufferPool::totbuf.

Referenced by GPU_buffer_alloc().

static GPUBuffer* gpu_buffer_setup ( DerivedMesh dm,
GPUDrawObject object,
int  vector_size,
int  size,
GLenum  target,
void *  user,
GPUBufferCopyFunc  copy_f 
) [static]
static GPUBuffer* gpu_buffer_setup_common ( DerivedMesh dm,
GPUBufferType  type 
) [static]
static GPUBuffer* gpu_buffer_setup_type ( DerivedMesh dm,
GPUBufferType  type 
) [static]
static int gpu_buffer_size_from_type ( DerivedMesh dm,
GPUBufferType  type 
) [static]
void GPU_buffer_unbind ( void  )
void GPU_buffer_unlock ( GPUBuffer buffer)

Definition at line 1248 of file gpu_buffers.c.

References useVBOs.

Referenced by cdDM_drawMappedFacesGLSL().

GPU_Buffers* GPU_build_grid_buffers ( DMGridData **  UNUSEDgrids,
int *  UNUSEDgrid_indices,
int  totgrid,
int  gridsize 
)
GPU_Buffers* GPU_build_mesh_buffers ( GHash map,
MVert mvert,
MFace mface,
int *  face_indices,
int  totface,
int *  vert_indices,
int  tot_uniq_verts,
int  totvert 
)
void GPU_color3_upload ( DerivedMesh dm,
unsigned char *  data 
)
void GPU_color4_upload ( DerivedMesh UNUSEDdm,
unsigned char *  UNUSEDdata 
)

Definition at line 1175 of file gpu_buffers.c.

void GPU_color_setup ( DerivedMesh dm)
void GPU_color_switch ( int  mode)

Definition at line 1185 of file gpu_buffers.c.

References GLStates, and GPU_BUFFER_COLOR_STATE.

Referenced by cdDM_drawFacesTex_common().

void GPU_draw_buffers ( GPU_Buffers buffers)
static void gpu_drawobject_add_triangle ( GPUDrawObject gdo,
int  base_point_index,
int  face_index,
int  v1,
int  v2,
int  v3 
) [static]
static void gpu_drawobject_add_vert_point ( GPUDrawObject gdo,
int  vert_index,
int  point_index 
) [static]
static GPUBuffer** gpu_drawobject_buffer_from_type ( GPUDrawObject gdo,
GPUBufferType  type 
) [static]
void GPU_drawobject_free ( DerivedMesh dm)
static void gpu_drawobject_init_vert_points ( GPUDrawObject gdo,
MFace f,
int  totface 
) [static]
GPUDrawObject* GPU_drawobject_new ( DerivedMesh dm)
void GPU_edge_setup ( DerivedMesh dm)
void GPU_free_buffers ( GPU_Buffers buffers)

Definition at line 1631 of file gpu_buffers.c.

References GPU_Buffers::index_buf, MEM_freeN(), and GPU_Buffers::vert_buf.

Referenced by BLI_pbvh_free().

static GPUBufferPool* gpu_get_global_buffer_pool ( void  ) [static]

Definition at line 168 of file gpu_buffers.c.

References gpu_buffer_pool, and gpu_buffer_pool_new().

Referenced by GPU_buffer_alloc(), GPU_buffer_free(), and gpu_buffer_setup().

void GPU_global_buffer_pool_free ( void  )

Definition at line 177 of file gpu_buffers.c.

References gpu_buffer_pool_free(), and NULL.

Referenced by WM_exit_ext().

void GPU_interleaved_attrib_setup ( GPUBuffer buffer,
GPUAttrib  data[],
int  numdata 
)
void GPU_normal_setup ( DerivedMesh dm)
static int GPU_typesize ( int  type) [static]

Definition at line 1056 of file gpu_buffers.c.

Referenced by GPU_attrib_element_size(), and GPU_interleaved_attrib_setup().

void GPU_update_grid_buffers ( GPU_Buffers buffers,
DMGridData **  grids,
int *  grid_indices,
int  totgrid,
int  gridsize,
int  smooth 
)
void GPU_update_mesh_buffers ( GPU_Buffers buffers,
MVert mvert,
int *  vert_indices,
int  totvert 
)
void GPU_uv_setup ( DerivedMesh dm)
void GPU_uvedge_setup ( DerivedMesh dm)
void GPU_vertex_setup ( DerivedMesh dm)

Variable Documentation

GPUAttrib attribData[MAX_GPU_ATTRIB_DATA] = { { -1, 0, 0 } } [static]

Definition at line 70 of file gpu_buffers.c.

GPUBufferState GLStates = 0 [static]
GPUBufferPool* gpu_buffer_pool = NULL [static]

Definition at line 167 of file gpu_buffers.c.

Referenced by gpu_get_global_buffer_pool().

Initial value:
 {
    {GPU_buffer_copy_vertex, GL_ARRAY_BUFFER_ARB, 3},
    {GPU_buffer_copy_normal, GL_ARRAY_BUFFER_ARB, 3},
    {GPU_buffer_copy_mcol, GL_ARRAY_BUFFER_ARB, 3},
    {GPU_buffer_copy_uv, GL_ARRAY_BUFFER_ARB, 2},
    {GPU_buffer_copy_edge, GL_ELEMENT_ARRAY_BUFFER_ARB, 2},
    {GPU_buffer_copy_uvedge, GL_ELEMENT_ARRAY_BUFFER_ARB, 4}
}

Definition at line 848 of file gpu_buffers.c.

int useVBOs = -1 [static]