[Tizen] Fix typo error at ArrayBuffer bind + minor backport
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles-impl / gles-context.cpp
index 32f490d..c6f0728 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -74,6 +74,9 @@ struct Context::Impl
         {
           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;
       }
@@ -82,6 +85,10 @@ struct Context::Impl
     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)
     {
@@ -950,13 +957,31 @@ void Context::GenerateMipmap(GLenum target)
 
 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)