Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_batch.c
| Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | |||||
| #if TRUST_NO_ONE | #if TRUST_NO_ONE | ||||
| assert(verts != NULL); | assert(verts != NULL); | ||||
| #endif | #endif | ||||
| batch->verts[0] = verts; | batch->verts[0] = verts; | ||||
| for (int v = 1; v < GPU_BATCH_VBO_MAX_LEN; v++) { | for (int v = 1; v < GPU_BATCH_VBO_MAX_LEN; v++) { | ||||
| batch->verts[v] = NULL; | batch->verts[v] = NULL; | ||||
| } | } | ||||
| batch->inst = NULL; | for (int v = 0; v < GPU_BATCH_INST_VBO_MAX_LEN; v++) { | ||||
| batch->inst[v] = NULL; | |||||
| } | |||||
| batch->elem = elem; | batch->elem = elem; | ||||
| batch->gl_prim_type = convert_prim_type_to_gl(prim_type); | batch->gl_prim_type = convert_prim_type_to_gl(prim_type); | ||||
| batch->phase = GPU_BATCH_READY_TO_DRAW; | batch->phase = GPU_BATCH_READY_TO_DRAW; | ||||
| batch->is_dynamic_vao_count = false; | batch->is_dynamic_vao_count = false; | ||||
| batch->owns_flag = owns_flag; | batch->owns_flag = owns_flag; | ||||
| batch->free_callback = NULL; | batch->free_callback = NULL; | ||||
| } | } | ||||
| Show All 9 Lines | |||||
| } | } | ||||
| void GPU_batch_clear(GPUBatch *batch) | void GPU_batch_clear(GPUBatch *batch) | ||||
| { | { | ||||
| if (batch->owns_flag & GPU_BATCH_OWNS_INDEX) { | if (batch->owns_flag & GPU_BATCH_OWNS_INDEX) { | ||||
| GPU_indexbuf_discard(batch->elem); | GPU_indexbuf_discard(batch->elem); | ||||
| } | } | ||||
| if (batch->owns_flag & GPU_BATCH_OWNS_INSTANCES) { | if (batch->owns_flag & GPU_BATCH_OWNS_INSTANCES) { | ||||
| GPU_vertbuf_discard(batch->inst); | GPU_vertbuf_discard(batch->inst[0]); | ||||
| GPU_VERTBUF_DISCARD_SAFE(batch->inst[1]); | |||||
| } | } | ||||
| if ((batch->owns_flag & ~GPU_BATCH_OWNS_INDEX) != 0) { | if ((batch->owns_flag & ~GPU_BATCH_OWNS_INDEX) != 0) { | ||||
| for (int v = 0; v < GPU_BATCH_VBO_MAX_LEN; v++) { | for (int v = 0; v < GPU_BATCH_VBO_MAX_LEN; v++) { | ||||
| if (batch->verts[v] == NULL) { | if (batch->verts[v] == NULL) { | ||||
| break; | break; | ||||
| } | } | ||||
| if (batch->owns_flag & (1 << v)) { | if (batch->owns_flag & (1 << v)) { | ||||
| GPU_vertbuf_discard(batch->verts[v]); | GPU_vertbuf_discard(batch->verts[v]); | ||||
| Show All 25 Lines | |||||
| void GPU_batch_instbuf_set(GPUBatch *batch, GPUVertBuf *inst, bool own_vbo) | void GPU_batch_instbuf_set(GPUBatch *batch, GPUVertBuf *inst, bool own_vbo) | ||||
| { | { | ||||
| #if TRUST_NO_ONE | #if TRUST_NO_ONE | ||||
| assert(inst != NULL); | assert(inst != NULL); | ||||
| #endif | #endif | ||||
| /* redo the bindings */ | /* redo the bindings */ | ||||
| GPU_batch_vao_cache_clear(batch); | GPU_batch_vao_cache_clear(batch); | ||||
| if (batch->inst != NULL && (batch->owns_flag & GPU_BATCH_OWNS_INSTANCES)) { | if (batch->inst[0] != NULL && (batch->owns_flag & GPU_BATCH_OWNS_INSTANCES)) { | ||||
| GPU_vertbuf_discard(batch->inst); | GPU_vertbuf_discard(batch->inst[0]); | ||||
| GPU_VERTBUF_DISCARD_SAFE(batch->inst[1]); | |||||
| } | } | ||||
| batch->inst = inst; | batch->inst[0] = inst; | ||||
| if (own_vbo) { | if (own_vbo) { | ||||
| batch->owns_flag |= GPU_BATCH_OWNS_INSTANCES; | batch->owns_flag |= GPU_BATCH_OWNS_INSTANCES; | ||||
| } | } | ||||
| else { | else { | ||||
| batch->owns_flag &= ~GPU_BATCH_OWNS_INSTANCES; | batch->owns_flag &= ~GPU_BATCH_OWNS_INSTANCES; | ||||
| } | } | ||||
| } | } | ||||
| Show All 12 Lines | void GPU_batch_elembuf_set(GPUBatch *batch, GPUIndexBuf *elem, bool own_ibo) | ||||
| if (own_ibo) { | if (own_ibo) { | ||||
| batch->owns_flag |= GPU_BATCH_OWNS_INDEX; | batch->owns_flag |= GPU_BATCH_OWNS_INDEX; | ||||
| } | } | ||||
| else { | else { | ||||
| batch->owns_flag &= ~GPU_BATCH_OWNS_INDEX; | batch->owns_flag &= ~GPU_BATCH_OWNS_INDEX; | ||||
| } | } | ||||
| } | } | ||||
| /* A bit of a quick hack. Should be streamlined as the vbos handling */ | |||||
| int GPU_batch_instbuf_add_ex(GPUBatch *batch, GPUVertBuf *insts, bool own_vbo) | |||||
| { | |||||
| /* redo the bindings */ | |||||
| GPU_batch_vao_cache_clear(batch); | |||||
| for (uint v = 0; v < GPU_BATCH_INST_VBO_MAX_LEN; v++) { | |||||
| if (batch->inst[v] == NULL) { | |||||
| #if TRUST_NO_ONE | |||||
| /* for now all VertexBuffers must have same vertex_len */ | |||||
| if (batch->inst[0] != NULL) { | |||||
| /* Allow for different size of vertex buf (will choose the smallest number of verts). */ | |||||
| // assert(insts->vertex_len == batch->inst[0]->vertex_len); | |||||
| assert(own_vbo == ((batch->owns_flag & GPU_BATCH_OWNS_INSTANCES) != 0)); | |||||
| } | |||||
| #endif | |||||
| batch->inst[v] = insts; | |||||
| if (own_vbo) { | |||||
| batch->owns_flag |= GPU_BATCH_OWNS_INSTANCES; | |||||
| } | |||||
| return v; | |||||
| } | |||||
| } | |||||
| /* we only make it this far if there is no room for another GPUVertBuf */ | |||||
| #if TRUST_NO_ONE | |||||
| assert(false); | |||||
| #endif | |||||
| return -1; | |||||
| } | |||||
| /* Returns the index of verts in the batch. */ | /* Returns the index of verts in the batch. */ | ||||
| int GPU_batch_vertbuf_add_ex(GPUBatch *batch, GPUVertBuf *verts, bool own_vbo) | int GPU_batch_vertbuf_add_ex(GPUBatch *batch, GPUVertBuf *verts, bool own_vbo) | ||||
| { | { | ||||
| /* redo the bindings */ | /* redo the bindings */ | ||||
| GPU_batch_vao_cache_clear(batch); | GPU_batch_vao_cache_clear(batch); | ||||
| for (uint v = 0; v < GPU_BATCH_VBO_MAX_LEN; v++) { | for (uint v = 0; v < GPU_BATCH_VBO_MAX_LEN; v++) { | ||||
| if (batch->verts[v] == NULL) { | if (batch->verts[v] == NULL) { | ||||
| ▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | |||||
| static void batch_update_program_bindings(GPUBatch *batch, uint i_first) | static void batch_update_program_bindings(GPUBatch *batch, uint i_first) | ||||
| { | { | ||||
| /* Reverse order so first vbos have more prevalence (in term of attrib override). */ | /* Reverse order so first vbos have more prevalence (in term of attrib override). */ | ||||
| for (int v = GPU_BATCH_VBO_MAX_LEN - 1; v > -1; v--) { | for (int v = GPU_BATCH_VBO_MAX_LEN - 1; v > -1; v--) { | ||||
| if (batch->verts[v] != NULL) { | if (batch->verts[v] != NULL) { | ||||
| create_bindings(batch->verts[v], batch->interface, 0, false); | create_bindings(batch->verts[v], batch->interface, 0, false); | ||||
| } | } | ||||
| } | } | ||||
| if (batch->inst) { | for (int v = GPU_BATCH_INST_VBO_MAX_LEN - 1; v > -1; v--) { | ||||
| create_bindings(batch->inst, batch->interface, i_first, true); | if (batch->inst[v]) { | ||||
| create_bindings(batch->inst[v], batch->interface, i_first, true); | |||||
| } | |||||
| } | } | ||||
| if (batch->elem) { | if (batch->elem) { | ||||
| GPU_indexbuf_use(batch->elem); | GPU_indexbuf_use(batch->elem); | ||||
| } | } | ||||
| } | } | ||||
| void GPU_batch_program_use_begin(GPUBatch *batch) | void GPU_batch_program_use_begin(GPUBatch *batch) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| BLI_assert(batch->program_in_use); | BLI_assert(batch->program_in_use); | ||||
| /* TODO could assert that VAO is bound. */ | /* TODO could assert that VAO is bound. */ | ||||
| if (v_count == 0) { | if (v_count == 0) { | ||||
| v_count = (batch->elem) ? batch->elem->index_len : batch->verts[0]->vertex_len; | v_count = (batch->elem) ? batch->elem->index_len : batch->verts[0]->vertex_len; | ||||
| } | } | ||||
| if (i_count == 0) { | if (i_count == 0) { | ||||
| i_count = (batch->inst) ? batch->inst->vertex_len : 1; | i_count = (batch->inst[0]) ? batch->inst[0]->vertex_len : 1; | ||||
| /* Meh. This is to be able to use different numbers of verts in instance vbos. */ | |||||
| if (batch->inst[1] && i_count > batch->inst[1]->vertex_len) { | |||||
| i_count = batch->inst[1]->vertex_len; | |||||
| } | |||||
| } | } | ||||
| if (v_count == 0 || i_count == 0) { | if (v_count == 0 || i_count == 0) { | ||||
| /* Nothing to draw. */ | /* Nothing to draw. */ | ||||
| return; | return; | ||||
| } | } | ||||
| /* Verify there is enough data do draw. */ | /* Verify there is enough data do draw. */ | ||||
| ▲ Show 20 Lines • Show All 310 Lines • Show Last 20 Lines | |||||