Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_instance_data.c
| Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | if (handle->format != format) { | ||||
| GPU_vertbuf_data_alloc(vert, DRW_BUFFER_VERTS_CHUNK); | GPU_vertbuf_data_alloc(vert, DRW_BUFFER_VERTS_CHUNK); | ||||
| } | } | ||||
| return vert; | return vert; | ||||
| } | } | ||||
| /* NOTE: Does not return a valid drawable batch until DRW_instance_buffer_finish has run. */ | /* NOTE: Does not return a valid drawable batch until DRW_instance_buffer_finish has run. */ | ||||
| GPUBatch *DRW_temp_batch_instance_request(DRWInstanceDataList *idatalist, | GPUBatch *DRW_temp_batch_instance_request(DRWInstanceDataList *idatalist, | ||||
| GPUVertBuf *buf, | GPUVertBuf *buf, | ||||
| GPUBatch *instancer, | |||||
| GPUBatch *geom) | GPUBatch *geom) | ||||
| { | { | ||||
| /* Do not call this with a batch that is already an instancing batch. */ | /* Do not call this with a batch that is already an instancing batch. */ | ||||
| BLI_assert(geom->inst == NULL); | BLI_assert(geom->inst[0] == NULL); | ||||
| /* Only call with one of them. */ | |||||
| BLI_assert((instancer != NULL) != (buf != NULL)); | |||||
| GPUBatch *batch = BLI_memblock_alloc(idatalist->pool_instancing); | GPUBatch *batch = BLI_memblock_alloc(idatalist->pool_instancing); | ||||
| bool is_compatible = (batch->gl_prim_type == geom->gl_prim_type) && (batch->inst == buf) && | bool instancer_compat = buf ? ((batch->inst[0] == buf) && (buf->vbo_id != 0)) : | ||||
| (buf->vbo_id != 0) && (batch->phase == GPU_BATCH_READY_TO_DRAW) && | ((batch->inst[0] == instancer->inst[0]) && | ||||
| (batch->elem == geom->elem); | (batch->inst[1] == instancer->inst[1])); | ||||
| bool is_compatible = (batch->gl_prim_type == geom->gl_prim_type) && instancer_compat && | |||||
| (batch->phase == GPU_BATCH_READY_TO_DRAW) && (batch->elem == geom->elem); | |||||
| for (int i = 0; i < GPU_BATCH_VBO_MAX_LEN && is_compatible; i++) { | for (int i = 0; i < GPU_BATCH_VBO_MAX_LEN && is_compatible; i++) { | ||||
| if (batch->verts[i] != geom->verts[i]) { | if (batch->verts[i] != geom->verts[i]) { | ||||
| is_compatible = false; | is_compatible = false; | ||||
| } | } | ||||
| } | } | ||||
| if (!is_compatible) { | if (!is_compatible) { | ||||
| GPU_batch_clear(batch); | GPU_batch_clear(batch); | ||||
| /* Save args and init later */ | /* Save args and init later */ | ||||
| batch->inst = buf; | batch->inst[0] = buf; | ||||
| batch->inst[1] = (void *)instancer; /* HACK to save the pointer without other alloc. */ | |||||
| batch->phase = GPU_BATCH_READY_TO_BUILD; | batch->phase = GPU_BATCH_READY_TO_BUILD; | ||||
| batch->verts[0] = (void *)geom; /* HACK to save the pointer without other alloc. */ | batch->verts[0] = (void *)geom; /* HACK to save the pointer without other alloc. */ | ||||
| /* Make sure to free this batch if the instance geom gets free. */ | /* Make sure to free this batch if the instance geom gets free. */ | ||||
| GPU_batch_callback_free_set(geom, &instance_batch_free, NULL); | GPU_batch_callback_free_set(geom, &instance_batch_free, NULL); | ||||
| } | } | ||||
| return batch; | return batch; | ||||
| } | } | ||||
| Show All 36 Lines | if (handle->vert_len != NULL) { | ||||
| GPU_vertbuf_use(&handle->buf); /* Send data. */ | GPU_vertbuf_use(&handle->buf); /* Send data. */ | ||||
| } | } | ||||
| } | } | ||||
| /* Finish pending instancing batches. */ | /* Finish pending instancing batches. */ | ||||
| GPUBatch *batch; | GPUBatch *batch; | ||||
| BLI_memblock_iternew(idatalist->pool_instancing, &iter); | BLI_memblock_iternew(idatalist->pool_instancing, &iter); | ||||
| while ((batch = BLI_memblock_iterstep(&iter))) { | while ((batch = BLI_memblock_iterstep(&iter))) { | ||||
| if (batch->phase == GPU_BATCH_READY_TO_BUILD) { | if (batch->phase == GPU_BATCH_READY_TO_BUILD) { | ||||
| GPUVertBuf *inst = batch->inst; | GPUVertBuf *inst_buf = batch->inst[0]; | ||||
| GPUBatch *geom = (void *)batch->verts[0]; /* HACK see DRW_temp_batch_instance_request. */ | /* HACK see DRW_temp_batch_instance_request. */ | ||||
| GPUBatch *inst_batch = (void *)batch->inst[1]; | |||||
| GPUBatch *geom = (void *)batch->verts[0]; | |||||
| GPU_batch_copy(batch, geom); | GPU_batch_copy(batch, geom); | ||||
| GPU_batch_instbuf_set(batch, inst, false); | if (inst_batch != NULL) { | ||||
| for (int i = 0; i < GPU_BATCH_INST_VBO_MAX_LEN && inst_batch->verts[i]; i++) { | |||||
| GPU_batch_instbuf_add_ex(batch, inst_batch->verts[i], false); | |||||
| } | |||||
| } | |||||
| else { | |||||
| GPU_batch_instbuf_add_ex(batch, inst_buf, false); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| /* Resize pools and free unused. */ | /* Resize pools and free unused. */ | ||||
| BLI_memblock_clear(idatalist->pool_buffers, (MemblockValFreeFP)temp_buffer_handle_free); | BLI_memblock_clear(idatalist->pool_buffers, (MemblockValFreeFP)temp_buffer_handle_free); | ||||
| BLI_memblock_clear(idatalist->pool_instancing, (MemblockValFreeFP)GPU_batch_clear); | BLI_memblock_clear(idatalist->pool_instancing, (MemblockValFreeFP)GPU_batch_clear); | ||||
| BLI_memblock_clear(idatalist->pool_batching, (MemblockValFreeFP)GPU_batch_clear); | BLI_memblock_clear(idatalist->pool_batching, (MemblockValFreeFP)GPU_batch_clear); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines | |||||