diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-04-05 16:36:38 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-04-05 17:08:46 +0300 |
commit | cadef79a52cbe3d70488ef5fd70c805a872b17f9 (patch) | |
tree | c934d71c425a3e9c669841f38253ce221b8f92c8 /source | |
parent | d48597eb5422b33d5edc80f3b6d8d927f2f40444 (diff) |
GPUBatch: Change preset managment system.
Now use a list of preset batches with a function to add new ones to this
list.
This removes the need of new functions all over the place to reset/exit.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 17 | ||||
-rw-r--r-- | source/blender/gpu/GPU_batch.h | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_batch_presets.c | 62 |
4 files changed, 41 insertions, 43 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index eba3be327dd..6e09318314d 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -1168,8 +1168,4 @@ void UI_tooltip_free(struct bContext *C, struct bScreen *sc, struct ARegion *ar) int UI_calc_float_precision(int prec, double value); -/* UI Batches managment */ -void UI_widget_batch_preset_reset(void); -void UI_widget_batch_preset_exit(void); - #endif /* __UI_INTERFACE_H__ */ diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 886449b7eda..1ef39a1d52a 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -378,6 +378,7 @@ static Gwn_Batch *ui_batch_roundbox_get(int tria) roundbox_batch_add_tria(&vflag_step, tria, last_data); } g_ui_batch_cache.roundbox[tria] = GWN_batch_create_ex(GWN_PRIM_TRI_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO); + gpu_batch_presets_register(g_ui_batch_cache.roundbox[tria]); } return g_ui_batch_cache.roundbox[tria]; } @@ -387,22 +388,6 @@ static Gwn_Batch *ui_batch_roundbox_get(int tria) #undef EMBOSS #undef NO_AA -void UI_widget_batch_preset_reset(void) -{ - for (int i = 0; i < ROUNDBOX_TRIA_MAX; ++i) { - if (g_ui_batch_cache.roundbox[i]) { - gwn_batch_vao_cache_clear(g_ui_batch_cache.roundbox[i]); - } - } -} - -void UI_widget_batch_preset_exit(void) -{ - for (int i = 0; i < ROUNDBOX_TRIA_MAX; ++i) { - GWN_BATCH_DISCARD_SAFE(g_ui_batch_cache.roundbox[i]); - } -} - /* ************************************************* */ void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3, diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h index 52cf37a7457..760faeff7b1 100644 --- a/source/blender/gpu/GPU_batch.h +++ b/source/blender/gpu/GPU_batch.h @@ -67,6 +67,7 @@ Gwn_Batch *GPU_batch_preset_sphere(int lod) ATTR_WARN_UNUSED_RESULT; Gwn_Batch *GPU_batch_preset_sphere_wire(int lod) ATTR_WARN_UNUSED_RESULT; void gpu_batch_presets_init(void); +void gpu_batch_presets_register(Gwn_Batch *preset_batch); void gpu_batch_presets_reset(void); void gpu_batch_presets_exit(void); diff --git a/source/blender/gpu/intern/gpu_batch_presets.c b/source/blender/gpu/intern/gpu_batch_presets.c index 144c4a33787..10cbd16490b 100644 --- a/source/blender/gpu/intern/gpu_batch_presets.c +++ b/source/blender/gpu/intern/gpu_batch_presets.c @@ -32,6 +32,8 @@ #include "BLI_utildefines.h" #include "BLI_math.h" #include "BLI_threads.h" +#include "BLI_listbase.h" +#include "MEM_guardedalloc.h" #include "UI_interface.h" @@ -55,12 +57,22 @@ static struct { } attr_id; } g_presets_3d = {{0}}; -/* We may want 2D presets later. */ +static ListBase presets_list = {NULL, NULL}; /* -------------------------------------------------------------------- */ /** \name 3D Primitives * \{ */ +static Gwn_VertFormat *preset_3D_format(void) +{ + if (g_presets_3d.format.attrib_ct == 0) { + Gwn_VertFormat *format = &g_presets_3d.format; + g_presets_3d.attr_id.pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); + g_presets_3d.attr_id.nor = GWN_vertformat_attr_add(format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); + } + return &g_presets_3d.format; +} + static void batch_sphere_lat_lon_vert( Gwn_VertBufRaw *pos_step, Gwn_VertBufRaw *nor_step, float lat, float lon) @@ -80,7 +92,7 @@ Gwn_Batch *gpu_batch_sphere(int lat_res, int lon_res) const float lat_inc = M_PI / lat_res; float lon, lat; - Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&g_presets_3d.format); + Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(preset_3D_format()); const uint vbo_len = (lat_res - 1) * lon_res * 6; GWN_vertbuf_data_alloc(vbo, vbo_len); @@ -118,7 +130,7 @@ static Gwn_Batch *batch_sphere_wire(int lat_res, int lon_res) const float lat_inc = M_PI / lat_res; float lon, lat; - Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&g_presets_3d.format); + Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(preset_3D_format()); const uint vbo_len = (lat_res * lon_res * 2) + ((lat_res - 1) * lon_res * 2); GWN_vertbuf_data_alloc(vbo, vbo_len); @@ -180,41 +192,45 @@ Gwn_Batch *GPU_batch_preset_sphere_wire(int lod) void gpu_batch_presets_init(void) { - if (g_presets_3d.format.attrib_ct == 0) { - Gwn_VertFormat *format = &g_presets_3d.format; - g_presets_3d.attr_id.pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); - g_presets_3d.attr_id.nor = GWN_vertformat_attr_add(format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); - } - /* Hard coded resolution */ g_presets_3d.batch.sphere_low = gpu_batch_sphere(8, 16); + gpu_batch_presets_register(g_presets_3d.batch.sphere_low); + g_presets_3d.batch.sphere_med = gpu_batch_sphere(16, 10); + gpu_batch_presets_register(g_presets_3d.batch.sphere_med); + g_presets_3d.batch.sphere_high = gpu_batch_sphere(32, 24); + gpu_batch_presets_register(g_presets_3d.batch.sphere_high); g_presets_3d.batch.sphere_wire_low = batch_sphere_wire(6, 8); + gpu_batch_presets_register(g_presets_3d.batch.sphere_wire_low); + g_presets_3d.batch.sphere_wire_med = batch_sphere_wire(8, 16); + gpu_batch_presets_register(g_presets_3d.batch.sphere_wire_med); +} + +void gpu_batch_presets_register(Gwn_Batch *preset_batch) +{ + BLI_addtail(&presets_list, BLI_genericNodeN(preset_batch)); } void gpu_batch_presets_reset(void) { /* Reset vao caches for these every time we switch opengl context. * This way they will draw correctly for each window. */ - gwn_batch_vao_cache_clear(g_presets_3d.batch.sphere_low); - gwn_batch_vao_cache_clear(g_presets_3d.batch.sphere_med); - gwn_batch_vao_cache_clear(g_presets_3d.batch.sphere_high); - gwn_batch_vao_cache_clear(g_presets_3d.batch.sphere_wire_low); - gwn_batch_vao_cache_clear(g_presets_3d.batch.sphere_wire_med); - - UI_widget_batch_preset_reset(); + LinkData *link = presets_list.first; + for (link = presets_list.first; link; link = link->next) { + Gwn_Batch *preset = link->data; + gwn_batch_vao_cache_clear(preset); + } } void gpu_batch_presets_exit(void) { - GWN_batch_discard(g_presets_3d.batch.sphere_low); - GWN_batch_discard(g_presets_3d.batch.sphere_med); - GWN_batch_discard(g_presets_3d.batch.sphere_high); - GWN_batch_discard(g_presets_3d.batch.sphere_wire_low); - GWN_batch_discard(g_presets_3d.batch.sphere_wire_med); - - UI_widget_batch_preset_exit(); + LinkData *link; + while ((link = BLI_pophead(&presets_list))) { + Gwn_Batch *preset = link->data; + GWN_batch_discard(preset); + MEM_freeN(link); + } } |