Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/opengl/gl_batch.cc
| Show All 23 Lines | |||||
| * The only specificity of GL here is that it caches a list of | * The only specificity of GL here is that it caches a list of | ||||
| * Vertex Array Objects based on the bound shader interface. | * Vertex Array Objects based on the bound shader interface. | ||||
| */ | */ | ||||
| #include "BLI_assert.h" | #include "BLI_assert.h" | ||||
| #include "glew-mx.h" | #include "glew-mx.h" | ||||
| #include "GPU_extensions.h" | |||||
| #include "gpu_batch_private.hh" | #include "gpu_batch_private.hh" | ||||
| #include "gpu_shader_private.hh" | #include "gpu_shader_private.hh" | ||||
| #include "gl_backend.hh" | |||||
| #include "gl_context.hh" | #include "gl_context.hh" | ||||
| #include "gl_debug.hh" | #include "gl_debug.hh" | ||||
| #include "gl_index_buffer.hh" | #include "gl_index_buffer.hh" | ||||
| #include "gl_primitive.hh" | #include "gl_primitive.hh" | ||||
| #include "gl_vertex_array.hh" | #include "gl_vertex_array.hh" | ||||
| #include "gl_batch.hh" | #include "gl_batch.hh" | ||||
| ▲ Show 20 Lines • Show All 259 Lines • ▼ Show 20 Lines | void GLBatch::bind(int i_first) | ||||
| if (flag & GPU_BATCH_DIRTY) { | if (flag & GPU_BATCH_DIRTY) { | ||||
| flag &= ~GPU_BATCH_DIRTY; | flag &= ~GPU_BATCH_DIRTY; | ||||
| vao_cache_.clear(); | vao_cache_.clear(); | ||||
| } | } | ||||
| #if GPU_TRACK_INDEX_RANGE | #if GPU_TRACK_INDEX_RANGE | ||||
| /* Can be removed if GL 4.3 is required. */ | /* Can be removed if GL 4.3 is required. */ | ||||
| if (!GLEW_ARB_ES3_compatibility && (elem != NULL)) { | if (!GLEW_ARB_ES3_compatibility && (elem != NULL)) { | ||||
| glPrimitiveRestartIndex(this->gl_elem()->restart_index()); | glPrimitiveRestartIndex(this->elem_()->restart_index()); | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Can be removed if GL 4.2 is required. */ | /* Can be removed if GL 4.2 is required. */ | ||||
| if (!GPU_arb_base_instance_is_supported() && (i_first > 0)) { | if (!GLContext::base_instance_support && (i_first > 0)) { | ||||
| glBindVertexArray(vao_cache_.base_instance_vao_get(this, i_first)); | glBindVertexArray(vao_cache_.base_instance_vao_get(this, i_first)); | ||||
| } | } | ||||
| else { | else { | ||||
| glBindVertexArray(vao_cache_.vao_get(this)); | glBindVertexArray(vao_cache_.vao_get(this)); | ||||
| } | } | ||||
| } | } | ||||
| void GLBatch::draw(int v_first, int v_count, int i_first, int i_count) | void GLBatch::draw(int v_first, int v_count, int i_first, int i_count) | ||||
| { | { | ||||
| GL_CHECK_RESOURCES("Batch"); | GL_CHECK_RESOURCES("Batch"); | ||||
| GL_CHECK_ERROR("Batch Pre drawing"); | GL_CHECK_ERROR("Batch Pre drawing"); | ||||
| this->bind(i_first); | this->bind(i_first); | ||||
| BLI_assert(v_count > 0 && i_count > 0); | BLI_assert(v_count > 0 && i_count > 0); | ||||
| GLenum gl_type = to_gl(prim_type); | GLenum gl_type = to_gl(prim_type); | ||||
| if (elem) { | if (elem) { | ||||
| const GLIndexBuf *el = this->gl_elem(); | const GLIndexBuf *el = this->elem_(); | ||||
| GLenum index_type = to_gl(el->index_type_); | GLenum index_type = to_gl(el->index_type_); | ||||
| GLint base_index = el->index_base_; | GLint base_index = el->index_base_; | ||||
| void *v_first_ofs = el->offset_ptr(v_first); | void *v_first_ofs = el->offset_ptr(v_first); | ||||
| if (GPU_arb_base_instance_is_supported()) { | if (GLContext::base_instance_support) { | ||||
| glDrawElementsInstancedBaseVertexBaseInstance( | glDrawElementsInstancedBaseVertexBaseInstance( | ||||
| gl_type, v_count, index_type, v_first_ofs, i_count, base_index, i_first); | gl_type, v_count, index_type, v_first_ofs, i_count, base_index, i_first); | ||||
| } | } | ||||
| else { | else { | ||||
| glDrawElementsInstancedBaseVertex( | glDrawElementsInstancedBaseVertex( | ||||
| gl_type, v_count, index_type, v_first_ofs, i_count, base_index); | gl_type, v_count, index_type, v_first_ofs, i_count, base_index); | ||||
| } | } | ||||
| GL_CHECK_ERROR("Batch Post-drawing Indexed"); | GL_CHECK_ERROR("Batch Post-drawing Indexed"); | ||||
| } | } | ||||
| else { | else { | ||||
| #ifdef __APPLE__ | #ifdef __APPLE__ | ||||
| glDisable(GL_PRIMITIVE_RESTART); | glDisable(GL_PRIMITIVE_RESTART); | ||||
| #endif | #endif | ||||
| if (GPU_arb_base_instance_is_supported()) { | if (GLContext::base_instance_support) { | ||||
| glDrawArraysInstancedBaseInstance(gl_type, v_first, v_count, i_count, i_first); | glDrawArraysInstancedBaseInstance(gl_type, v_first, v_count, i_count, i_first); | ||||
| } | } | ||||
| else { | else { | ||||
| glDrawArraysInstanced(gl_type, v_first, v_count, i_count); | glDrawArraysInstanced(gl_type, v_first, v_count, i_count); | ||||
| } | } | ||||
| #ifdef __APPLE__ | #ifdef __APPLE__ | ||||
| glEnable(GL_PRIMITIVE_RESTART); | glEnable(GL_PRIMITIVE_RESTART); | ||||
| #endif | #endif | ||||
| GL_CHECK_ERROR("Batch Post-drawing Non-indexed"); | GL_CHECK_ERROR("Batch Post-drawing Non-indexed"); | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||