/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
mProgramVAOCurrentState = attributeIter->second;
gl.BindVertexArray(attributeIter->second);
+
+ // Binding VAO seems to reset the index buffer binding so the cache must be reset
+ mGlStateCache.mBoundElementArrayBufferId = 0;
}
return;
}
uint32_t vao;
gl.GenVertexArrays(1, &vao);
gl.BindVertexArray(vao);
+
+ // Binding VAO seems to reset the index buffer binding so the cache must be reset
+ mGlStateCache.mBoundElementArrayBufferId = 0;
+
mProgramVAOMap[program][hash] = vao;
for(const auto& attr : vertexInputState.attributes)
{
void Context::BindBuffer(GLenum target, uint32_t bufferId)
{
- if(mImpl->mGlStateCache.mBoundArrayBufferId != bufferId)
+ switch(target)
{
- mImpl->mGlStateCache.mBoundArrayBufferId = bufferId;
-
- auto& gl = *mImpl->mController.GetGL();
- gl.BindBuffer(target, bufferId);
+ case GL_ARRAY_BUFFER:
+ {
+ if(mImpl->mGlStateCache.mBoundArrayBufferId == bufferId)
+ {
+ return;
+ }
+ mImpl->mGlStateCache.mBoundArrayBufferId = bufferId;
+ break;
+ }
+ case GL_ELEMENT_ARRAY_BUFFER:
+ {
+ if(mImpl->mGlStateCache.mBoundElementArrayBufferId == bufferId)
+ {
+ return;
+ }
+ mImpl->mGlStateCache.mBoundElementArrayBufferId = bufferId;
+ break;
+ }
}
+
+ // Cache miss. Bind buffer.
+ auto& gl = *mImpl->mController.GetGL();
+ gl.BindBuffer(target, bufferId);
}
void Context::DrawBuffers(uint32_t count, const GLenum* buffers)
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// TODO: could use vector?
static thread_local UniformBufferBindingDescriptor sTempBindings[MAX_UNIFORM_BUFFER_BINDINGS];
- // reset temp bindings
- memset(sTempBindings, 0, sizeof(UniformBufferBindingDescriptor) * MAX_UNIFORM_BUFFER_BINDINGS);
-
- auto maxBinding = 0u;
+ auto maxBindingCount = 0u;
// find max binding and standalone UBO
for(const auto& binding : bindings)
}
else // Bind regular UBO
{
+ if(DALI_UNLIKELY(maxBindingCount == 0u))
+ {
+ // We can assume here comes first time. Reset temp bindings
+ std::fill_n(sTempBindings, MAX_UNIFORM_BUFFER_BINDINGS, UniformBufferBindingDescriptor());
+ }
auto& slot = sTempBindings[binding.binding];
slot.buffer = glesBuffer;
slot.offset = binding.offset;
slot.binding = binding.binding;
slot.emulated = false;
- maxBinding = std::max(maxBinding, binding.binding);
+
+ maxBindingCount = std::max(maxBindingCount, binding.binding + 1u);
}
}
}
bindCmd.uniformBufferBindingsCount = 0u;
// copy data
- if(maxBinding)
+ if(maxBindingCount)
{
- auto destBindings = mCommandPool->Allocate<UniformBufferBindingDescriptor>(maxBinding + 1);
+ auto destBindings = mCommandPool->Allocate<UniformBufferBindingDescriptor>(maxBindingCount);
// copy
- memcpy(destBindings.Ptr(), sTempBindings, sizeof(UniformBufferBindingDescriptor) * (maxBinding + 1));
+ memcpy(destBindings.Ptr(), sTempBindings, sizeof(UniformBufferBindingDescriptor) * (maxBindingCount));
bindCmd.uniformBufferBindings = destBindings;
- bindCmd.uniformBufferBindingsCount = maxBinding + 1;
+ bindCmd.uniformBufferBindingsCount = maxBindingCount;
}
}