[gtk/wip/chergert/glproto: 114/526] handle initial state for uniform info




commit 2731c877c4ff67ebcf27dc886d6c8cddc87f83c2
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 26 11:12:35 2020 -0800

    handle initial state for uniform info
    
    if we set size past the info position, the type will be zero and that
    needs special setup.

 gsk/next/gskgluniformstate.c | 57 +++++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 27 deletions(-)
---
diff --git a/gsk/next/gskgluniformstate.c b/gsk/next/gskgluniformstate.c
index c079b2ac1e..66abe53c92 100644
--- a/gsk/next/gskgluniformstate.c
+++ b/gsk/next/gskgluniformstate.c
@@ -159,6 +159,7 @@ get_uniform (GskGLUniformState  *state,
 {
   ProgramInfo *program_info;
   GskGLUniformInfo *info;
+  guint offset;
 
   g_assert (state != NULL);
   g_assert (program > 0);
@@ -174,6 +175,9 @@ get_uniform (GskGLUniformState  *state,
     {
       info = &g_array_index (program_info->uniform_info, GskGLUniformInfo, location);
 
+      if (info->format == 0)
+        goto setup_info;
+
       if G_LIKELY (format == info->format && array_count <= info->array_count)
         {
           *infoptr = info;
@@ -182,45 +186,44 @@ get_uniform (GskGLUniformState  *state,
       else
         {
           g_critical ("Attempt to access uniform with different type of value "
-                      "than it was initialized with. Program %u Location %u.",
-                      program, location);
+                      "than it was initialized with. Program %u Location %u. "
+                      "Was %d now %d.",
+                      program, location, info->format, format);
           *infoptr = NULL;
           return NULL;
         }
     }
-  else
-    {
-      guint offset;
 
-      if (program >= state->program_info->len ||
-          g_array_index (state->program_info, ProgramInfo, program).uniform_info == NULL)
-        {
-          if (program >= state->program_info->len)
-            g_array_set_size (state->program_info, program + 1);
+setup_info:
 
-          program_info = &g_array_index (state->program_info, ProgramInfo, program);
-          program_info->uniform_info = g_array_new (FALSE, TRUE, sizeof (GskGLUniformInfo));
-          program_info->n_changed = 0;
-        }
+  if (program >= state->program_info->len ||
+      g_array_index (state->program_info, ProgramInfo, program).uniform_info == NULL)
+    {
+      if (program >= state->program_info->len)
+        g_array_set_size (state->program_info, program + 1);
 
-      g_assert (program_info != NULL);
-      g_assert (program_info->uniform_info != NULL);
+      program_info = &g_array_index (state->program_info, ProgramInfo, program);
+      program_info->uniform_info = g_array_new (FALSE, TRUE, sizeof (GskGLUniformInfo));
+      program_info->n_changed = 0;
+    }
 
-      if (location >= program_info->uniform_info->len)
-        g_array_set_size (program_info->uniform_info, location + 1);
+  g_assert (program_info != NULL);
+  g_assert (program_info->uniform_info != NULL);
 
-      alloc_uniform_data (state->uniform_data, uniform_sizes[format] * array_count, &offset);
+  if (location >= program_info->uniform_info->len)
+    g_array_set_size (program_info->uniform_info, location + 1);
 
-      info = &g_array_index (program_info->uniform_info, GskGLUniformInfo, location);
-      info->changed = TRUE;
-      info->format = format;
-      info->offset = offset;
-      info->array_count = 0;
+  alloc_uniform_data (state->uniform_data, uniform_sizes[format] * array_count, &offset);
 
-      *infoptr = info;
+  info = &g_array_index (program_info->uniform_info, GskGLUniformInfo, location);
+  info->changed = TRUE;
+  info->format = format;
+  info->offset = offset;
+  info->array_count = 0;
 
-      return state->uniform_data->data + offset;
-    }
+  *infoptr = info;
+
+  return state->uniform_data->data + offset;
 }
 
 void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]