Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_batch.c
| Show All 22 Lines | |||||
| * GPU geometry batch | * GPU geometry batch | ||||
| * Contains VAOs + VBOs + Shader representing a drawable entity. | * Contains VAOs + VBOs + Shader representing a drawable entity. | ||||
| */ | */ | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "GPU_batch.h" | #include "GPU_batch.h" | ||||
| #include "GPU_batch_presets.h" | #include "GPU_batch_presets.h" | ||||
| #include "GPU_extensions.h" | |||||
| #include "GPU_matrix.h" | #include "GPU_matrix.h" | ||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "gpu_batch_private.h" | #include "gpu_batch_private.h" | ||||
| #include "gpu_context_private.h" | #include "gpu_context_private.h" | ||||
| #include "gpu_primitive_private.h" | #include "gpu_primitive_private.h" | ||||
| #include "gpu_shader_private.h" | #include "gpu_shader_private.h" | ||||
| ▲ Show 20 Lines • Show All 555 Lines • ▼ Show 20 Lines | #endif | ||||
| 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) ? batch->inst->vertex_len : 1; | ||||
| } | } | ||||
| if (!GLEW_ARB_base_instance) { | if (!GPU_arb_base_instance_is_supported()) { | ||||
| if (i_first > 0 && i_count > 0) { | if (i_first > 0 && i_count > 0) { | ||||
| /* If using offset drawing with instancing, we must | /* If using offset drawing with instancing, we must | ||||
| * use the default VAO and redo bindings. */ | * use the default VAO and redo bindings. */ | ||||
| glBindVertexArray(GPU_vao_default()); | glBindVertexArray(GPU_vao_default()); | ||||
| batch_update_program_bindings(batch, i_first); | batch_update_program_bindings(batch, i_first); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Previous call could have bind the default vao | /* Previous call could have bind the default vao | ||||
| * see above. */ | * see above. */ | ||||
| glBindVertexArray(batch->vao_id); | glBindVertexArray(batch->vao_id); | ||||
| } | } | ||||
| } | } | ||||
| if (batch->elem) { | if (batch->elem) { | ||||
| const GPUIndexBuf *el = batch->elem; | const GPUIndexBuf *el = batch->elem; | ||||
| #if GPU_TRACK_INDEX_RANGE | #if GPU_TRACK_INDEX_RANGE | ||||
| GLenum index_type = el->gl_index_type; | GLenum index_type = el->gl_index_type; | ||||
| GLint base_index = el->base_index; | GLint base_index = el->base_index; | ||||
| #else | #else | ||||
| GLenum index_type = GL_UNSIGNED_INT; | GLenum index_type = GL_UNSIGNED_INT; | ||||
| GLint base_index = 0; | GLint base_index = 0; | ||||
| #endif | #endif | ||||
| void *v_first_ofs = elem_offset(el, v_first); | void *v_first_ofs = elem_offset(el, v_first); | ||||
| if (GLEW_ARB_base_instance) { | if (GPU_arb_base_instance_is_supported()) { | ||||
| glDrawElementsInstancedBaseVertexBaseInstance( | glDrawElementsInstancedBaseVertexBaseInstance( | ||||
| batch->gl_prim_type, v_count, index_type, v_first_ofs, i_count, base_index, i_first); | batch->gl_prim_type, v_count, index_type, v_first_ofs, i_count, base_index, i_first); | ||||
| } | } | ||||
| else { | else { | ||||
| glDrawElementsInstancedBaseVertex( | glDrawElementsInstancedBaseVertex( | ||||
| batch->gl_prim_type, v_count, index_type, v_first_ofs, i_count, base_index); | batch->gl_prim_type, v_count, index_type, v_first_ofs, i_count, base_index); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| #ifdef __APPLE__ | #ifdef __APPLE__ | ||||
| glDisable(GL_PRIMITIVE_RESTART); | glDisable(GL_PRIMITIVE_RESTART); | ||||
| #endif | #endif | ||||
| if (GLEW_ARB_base_instance) { | if (GPU_arb_base_instance_is_supported()) { | ||||
| glDrawArraysInstancedBaseInstance(batch->gl_prim_type, v_first, v_count, i_count, i_first); | glDrawArraysInstancedBaseInstance(batch->gl_prim_type, v_first, v_count, i_count, i_first); | ||||
| } | } | ||||
| else { | else { | ||||
| glDrawArraysInstanced(batch->gl_prim_type, v_first, v_count, i_count); | glDrawArraysInstanced(batch->gl_prim_type, v_first, v_count, i_count); | ||||
| } | } | ||||
| #ifdef __APPLE__ | #ifdef __APPLE__ | ||||
| glEnable(GL_PRIMITIVE_RESTART); | glEnable(GL_PRIMITIVE_RESTART); | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines | |||||