Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_batch_presets.c
| Show All 25 Lines | |||||
| */ | */ | ||||
| /** \file blender/gpu/intern/gpu_batch_presets.c | /** \file blender/gpu/intern/gpu_batch_presets.c | ||||
| * \ingroup gpu | * \ingroup gpu | ||||
| */ | */ | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_threads.h" | |||||
| #include "GPU_batch.h" | #include "GPU_batch.h" | ||||
| #include "gpu_shader_private.h" | #include "gpu_shader_private.h" | ||||
| /* Struct to store 3D Batches and their format */ | /* Struct to store 3D Batches and their format */ | ||||
| static struct { | static struct { | ||||
| struct { | struct { | ||||
| Gwn_Batch *sphere_high; | Gwn_Batch *sphere_high; | ||||
| Show All 24 Lines | static void batch_sphere_lat_lon_vert( | ||||
| pos[0] = sinf(lat) * cosf(lon); | pos[0] = sinf(lat) * cosf(lon); | ||||
| pos[1] = cosf(lat); | pos[1] = cosf(lat); | ||||
| pos[2] = sinf(lat) * sinf(lon); | pos[2] = sinf(lat) * sinf(lon); | ||||
| copy_v3_v3(GWN_vertbuf_raw_step(pos_step), pos); | copy_v3_v3(GWN_vertbuf_raw_step(pos_step), pos); | ||||
| copy_v3_v3(GWN_vertbuf_raw_step(nor_step), pos); | copy_v3_v3(GWN_vertbuf_raw_step(nor_step), pos); | ||||
| } | } | ||||
| /* Replacement for gluSphere */ | /* Replacement for gluSphere */ | ||||
| static Gwn_Batch *batch_sphere(int lat_res, int lon_res) | Gwn_Batch *gpu_batch_sphere(int lat_res, int lon_res) | ||||
| { | { | ||||
| const float lon_inc = 2 * M_PI / lon_res; | const float lon_inc = 2 * M_PI / lon_res; | ||||
| const float lat_inc = M_PI / lat_res; | const float lat_inc = M_PI / lat_res; | ||||
| float lon, lat; | float lon, lat; | ||||
| Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&g_presets_3d.format); | Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&g_presets_3d.format); | ||||
| const uint vbo_len = (lat_res - 1) * lon_res * 6; | const uint vbo_len = (lat_res - 1) * lon_res * 6; | ||||
| GWN_vertbuf_data_alloc(vbo, vbo_len); | GWN_vertbuf_data_alloc(vbo, vbo_len); | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | static Gwn_Batch *batch_sphere_wire(int lat_res, int lon_res) | ||||
| BLI_assert(vbo_len == GWN_vertbuf_raw_used(&nor_step)); | BLI_assert(vbo_len == GWN_vertbuf_raw_used(&nor_step)); | ||||
| return GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO); | return GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO); | ||||
| } | } | ||||
| Gwn_Batch *GPU_batch_preset_sphere(int lod) | Gwn_Batch *GPU_batch_preset_sphere(int lod) | ||||
| { | { | ||||
| BLI_assert(lod >= 0 && lod <= 2); | BLI_assert(lod >= 0 && lod <= 2); | ||||
| BLI_assert(BLI_thread_is_main()); | |||||
| if (lod == 0) { | if (lod == 0) { | ||||
| return g_presets_3d.batch.sphere_low; | return g_presets_3d.batch.sphere_low; | ||||
| } | } | ||||
| else if (lod == 1) { | else if (lod == 1) { | ||||
| return g_presets_3d.batch.sphere_med; | return g_presets_3d.batch.sphere_med; | ||||
| } | } | ||||
| else { | else { | ||||
| return g_presets_3d.batch.sphere_high; | return g_presets_3d.batch.sphere_high; | ||||
| } | } | ||||
| } | } | ||||
| Gwn_Batch *GPU_batch_preset_sphere_wire(int lod) | Gwn_Batch *GPU_batch_preset_sphere_wire(int lod) | ||||
| { | { | ||||
| BLI_assert(lod >= 0 && lod <= 1); | BLI_assert(lod >= 0 && lod <= 1); | ||||
| BLI_assert(BLI_thread_is_main()); | |||||
| if (lod == 0) { | if (lod == 0) { | ||||
| return g_presets_3d.batch.sphere_wire_low; | return g_presets_3d.batch.sphere_wire_low; | ||||
| } | } | ||||
| else { | else { | ||||
| return g_presets_3d.batch.sphere_wire_med; | return g_presets_3d.batch.sphere_wire_med; | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| void gpu_batch_presets_init(void) | void gpu_batch_presets_init(void) | ||||
| { | { | ||||
| if (g_presets_3d.format.attrib_ct == 0) { | if (g_presets_3d.format.attrib_ct == 0) { | ||||
| Gwn_VertFormat *format = &g_presets_3d.format; | 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.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); | g_presets_3d.attr_id.nor = GWN_vertformat_attr_add(format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT); | ||||
| } | } | ||||
| /* Hard coded resolution */ | /* Hard coded resolution */ | ||||
| g_presets_3d.batch.sphere_low = batch_sphere(8, 16); | g_presets_3d.batch.sphere_low = gpu_batch_sphere(8, 16); | ||||
| g_presets_3d.batch.sphere_med = batch_sphere(16, 10); | g_presets_3d.batch.sphere_med = gpu_batch_sphere(16, 10); | ||||
| g_presets_3d.batch.sphere_high = batch_sphere(32, 24); | g_presets_3d.batch.sphere_high = gpu_batch_sphere(32, 24); | ||||
| g_presets_3d.batch.sphere_wire_low = batch_sphere_wire(6, 8); | g_presets_3d.batch.sphere_wire_low = batch_sphere_wire(6, 8); | ||||
| g_presets_3d.batch.sphere_wire_med = batch_sphere_wire(8, 16); | g_presets_3d.batch.sphere_wire_med = batch_sphere_wire(8, 16); | ||||
| } | } | ||||
| void gpu_batch_presets_exit(void) | void gpu_batch_presets_exit(void) | ||||
| { | { | ||||
| GWN_batch_discard(g_presets_3d.batch.sphere_low); | 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_med); | ||||
| GWN_batch_discard(g_presets_3d.batch.sphere_high); | 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_low); | ||||
| GWN_batch_discard(g_presets_3d.batch.sphere_wire_med); | GWN_batch_discard(g_presets_3d.batch.sphere_wire_med); | ||||
| } | } | ||||