Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-09-05 18:35:38 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-09-05 18:49:14 +0300
commit558e1158e7b07e2a1b2fd239cd662282828990f0 (patch)
tree2acfb127563476bc121c301ba23fad7a408ad4b8 /source
parent6560a1c35e2398fb3f3460c62e683062c3d08f06 (diff)
GLState: Add texture multibind and remove redundant binds
Diffstat (limited to 'source')
-rw-r--r--source/blender/gpu/opengl/gl_state.cc25
1 files changed, 19 insertions, 6 deletions
diff --git a/source/blender/gpu/opengl/gl_state.cc b/source/blender/gpu/opengl/gl_state.cc
index 4831185307f..20d6d608f78 100644
--- a/source/blender/gpu/opengl/gl_state.cc
+++ b/source/blender/gpu/opengl/gl_state.cc
@@ -20,7 +20,10 @@
* \ingroup gpu
*/
+#include "BKE_global.h"
+
#include "BLI_math_base.h"
+#include "BLI_math_bits.h"
#include "GPU_extensions.h"
@@ -431,6 +434,11 @@ void GLStateManager::texture_bind(Texture *tex_, eGPUSamplerState sampler_type,
{
BLI_assert(unit < GPU_max_textures());
GLTexture *tex = static_cast<GLTexture *>(tex_);
+ /* Eliminate redundant binds. */
+ if ((textures_[unit] == tex->tex_id_) &&
+ (samplers_[unit] == GLTexture::samplers_[sampler_type])) {
+ return;
+ }
targets_[unit] = tex->target_;
textures_[unit] = tex->tex_id_;
samplers_[unit] = GLTexture::samplers_[sampler_type];
@@ -486,20 +494,25 @@ void GLStateManager::texture_bind_apply(void)
if (dirty_texture_binds_ == 0) {
return;
}
+ uint64_t dirty_bind = dirty_texture_binds_;
+ dirty_texture_binds_ = 0;
+
+ int first = bitscan_forward_uint64(dirty_bind);
+ int last = 64 - bitscan_reverse_uint64(dirty_bind);
+ int count = last - first;
- if (false) {
- /* TODO multibind */
+ if (GLEW_ARB_multi_bind) {
+ glBindTextures(first, count, textures_ + first);
+ glBindSamplers(first, count, samplers_ + first);
}
else {
- uint64_t dirty_bind = dirty_texture_binds_;
- for (int unit = 0; dirty_bind != 0; dirty_bind >>= 1, unit++) {
- if (dirty_bind & 1) {
+ for (int unit = first; unit < last; unit++) {
+ if ((dirty_bind >> unit) & 1UL) {
glActiveTexture(GL_TEXTURE0 + unit);
glBindTexture(targets_[unit], textures_[unit]);
glBindSampler(unit, samplers_[unit]);
}
}
- dirty_texture_binds_ = 0;
}
}