[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-gl-abstraction.h
index 834ae6f..a70c21f 100644 (file)
@@ -2,7 +2,7 @@
 #define TEST_GL_ABSTRACTION_H
 
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -51,9 +51,10 @@ struct UniformData
 
 struct ActiveUniform
 {
-  std::string name;
-  GLenum      type;
-  GLint       size;
+  std::string name{};
+  GLenum      type{GL_FLOAT};
+  GLint       size{0};
+  GLint       offset{0};
 };
 
 class DALI_CORE_API TestGlAbstraction : public Dali::Integration::GlAbstraction
@@ -76,6 +77,8 @@ public:
 
   bool IsBlendEquationSupported(DevelBlendEquation::Type blendEquation) override;
 
+  uint32_t GetShaderLanguageVersion();
+
   std::string GetShaderVersionPrefix();
 
   std::string GetVertexShaderPrefix();
@@ -457,6 +460,10 @@ public:
 
   inline void DeleteBuffers(GLsizei n, const GLuint* buffers) override
   {
+    TraceCallStack::NamedParams namedParams;
+    namedParams["n"] << n;
+    namedParams["id"] << buffers[0];
+    mBufferTrace.PushCall("DeleteBuffers", namedParams.str(), namedParams);
   }
 
   inline void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers) override
@@ -697,13 +704,21 @@ public:
   inline void GenBuffers(GLsizei n, GLuint* buffers) override
   {
     // avoids an assert in GpuBuffers
-    *buffers = 1u;
+    static GLuint id = 1;
 
-    std::ostringstream o;
-    o << n;
     TraceCallStack::NamedParams namedParams;
-    namedParams["n"] << o.str();
-    mBufferTrace.PushCall("GenBuffers", o.str(), namedParams);
+    namedParams["n"] << n;
+
+    // Allocate some buffer names
+    bool first = true;
+    while(n)
+    {
+      namedParams["buffers"] << (first ? "" : ", ") << id;
+      first      = false;
+      *buffers++ = id++;
+      --n;
+    }
+    mBufferTrace.PushCall("GenBuffers", namedParams.str(), namedParams);
   }
 
   inline void GenerateMipmap(GLenum target) override
@@ -796,12 +811,11 @@ public:
 
   inline void GetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) override
   {
+    strncpy(name, mAttribLocs[index].c_str(), 99);
+    *type = mAttribTypes[index];
   }
 
-  inline void SetActiveUniforms(const std::vector<ActiveUniform>& uniforms)
-  {
-    mActiveUniforms = uniforms;
-  }
+  void SetActiveUniforms(const std::vector<ActiveUniform>& uniforms);
 
   inline void GetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) override
   {
@@ -863,6 +877,9 @@ public:
       case GL_PROGRAM_BINARY_FORMATS_OES:
         *params = mBinaryFormats;
         break;
+      case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
+        *params = mUniformBufferOffsetAlignment;
+        break;
     }
   }
 
@@ -1026,7 +1043,32 @@ public:
 
     for(const auto& uniform : mActiveUniforms)
     {
-      GetUniformLocation(program, uniform.name.c_str());
+      std::string name = uniform.name;
+      if(uniform.size <= 1)
+      {
+        GetUniformLocation(program, name.c_str());
+      }
+      else
+      {
+        // Convert single active uniform from "uBlah[0]" or "uStruct[0].element" to N versions of the same
+        std::string suffix;
+        auto        iter = name.find("["); // Search for index operator
+        if(iter != std::string::npos)
+        {
+          name = uniform.name.substr(0, iter); // Strip off index operator
+          iter = uniform.name.find("]");
+          if(iter != std::string::npos && iter + 1 != uniform.name.length())
+          {
+            suffix = uniform.name.substr(iter + 1);
+          }
+        }
+        for(int i = 0; i < uniform.size; ++i)
+        {
+          std::stringstream nss;
+          nss << name << "[" << i << "]" << suffix;
+          GetUniformLocation(program, nss.str().c_str()); // Generate N uniforms in the uniform map
+        }
+      }
     }
 
     for(const auto& uniform : mCustomUniformData)
@@ -1590,6 +1632,18 @@ public:
     mBufferTrace.PushCall("VertexAttribPointer", namedParams.str(), namedParams);
   }
 
+  inline void VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) override
+  {
+    TraceCallStack::NamedParams namedParams;
+    namedParams["index"] << index;
+    namedParams["size"] << size;
+    namedParams["type"] << std::hex << type;
+    namedParams["stride"] << stride;
+    namedParams["offset"] << std::to_string(reinterpret_cast<unsigned long>(pointer));
+
+    mBufferTrace.PushCall("VertexAttribIPointer", namedParams.str(), namedParams);
+  }
+
   inline void Viewport(GLint x, GLint y, GLsizei width, GLsizei height) override
   {
     std::string commaString(", ");
@@ -1772,10 +1826,6 @@ public:
   {
   }
 
-  inline void VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer) override
-  {
-  }
-
   inline void GetVertexAttribIiv(GLuint index, GLenum pname, GLint* params) override
   {
   }
@@ -1872,6 +1922,44 @@ public:
 
   inline void GetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params) override
   {
+    for(int i = 0; i < uniformCount; ++i)
+    {
+      if(i < int(mActiveUniforms.size()))
+      {
+        switch(pname)
+        {
+          case GL_UNIFORM_TYPE:
+          {
+            params[i] = mActiveUniforms[i].type;
+            break;
+          }
+          case GL_UNIFORM_SIZE:
+          {
+            params[i] = mActiveUniforms[i].size;
+            break;
+          }
+          case GL_UNIFORM_NAME_LENGTH:
+          {
+            params[i] = mActiveUniforms[i].name.length();
+            break;
+          }
+          case GL_UNIFORM_BLOCK_INDEX:
+          {
+            params[i] = -1;
+            break;
+          }
+          case GL_UNIFORM_OFFSET:
+          {
+            params[i] = mActiveUniforms[i].offset;
+            break;
+          }
+          case GL_UNIFORM_MATRIX_STRIDE:
+          {
+            break;
+          }
+        }
+      }
+    }
   }
 
   inline GLuint GetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName) override
@@ -2099,10 +2187,14 @@ public: // TEST FUNCTIONS
   {
     mLinkStatus = value;
   }
-  inline void SetAttribLocations(std::vector<std::string> locs)
+  inline void SetAttribLocations(std::vector<std::string>& locs)
   {
     mAttribLocs = locs;
   }
+  inline void SetAttribTypes(std::vector<GLenum>& types)
+  {
+    mAttribTypes = types;
+  }
   inline void SetGetErrorResult(GLenum result)
   {
     mGetErrorResult = result;
@@ -2155,7 +2247,10 @@ public: // TEST FUNCTIONS
   {
     mProgramBinaryLength = length;
   }
-
+  inline void SetUniformBufferOffsetAlignment(GLint align)
+  {
+    mUniformBufferOffsetAlignment = align;
+  }
   inline bool GetVertexAttribArrayState(GLuint index)
   {
     if(index >= MAX_ATTRIBUTE_CACHE_SIZE)
@@ -2568,12 +2663,14 @@ public:
   GLint                                 mNumBinaryFormats;
   GLint                                 mBinaryFormats;
   GLint                                 mProgramBinaryLength;
+  GLint                                 mUniformBufferOffsetAlignment{1};
   bool                                  mVertexAttribArrayState[MAX_ATTRIBUTE_CACHE_SIZE];
   bool                                  mVertexAttribArrayChanged; // whether the vertex attrib array has been changed
   bool                                  mGetProgramBinaryCalled;
   typedef std::map<GLuint, std::string> ShaderSourceMap;
   ShaderSourceMap                       mShaderSources;
-  std::vector<std::string>              mAttribLocs; // should be bound to shader
+  std::vector<std::string>              mAttribLocs;  // should be bound to shader
+  std::vector<GLenum>                   mAttribTypes; // should be bound to shader
   GLuint                                mLastShaderCompiled;
   GLbitfield                            mLastClearBitMask;
   Vector4                               mLastClearColor;
@@ -2617,6 +2714,8 @@ public:
   TraceCallStack mViewportTrace;
 
   // Shaders & Uniforms
+  uint32_t mShaderLanguageVersion{320u};
+
   GLuint                                 mLastShaderIdUsed;
   GLuint                                 mLastProgramIdUsed{0u};
   GLuint                                 mLastUniformIdUsed;