hash_table *glsl_type::array_types = NULL;
hash_table *glsl_type::record_types = NULL;
+void *glsl_type::ctx = NULL;
glsl_type::glsl_type(GLenum gl_type,
unsigned base_type, unsigned vector_elements,
const glsl_type *t = (glsl_type *) hash_table_find(array_types, & key);
if (t == NULL) {
- t = new(ctx) glsl_type(ctx, base, array_size);
+ t = new glsl_type(ctx, base, array_size);
hash_table_insert(array_types, (void *) t, t);
}
const glsl_type *t = (glsl_type *) hash_table_find(record_types, & key);
if (t == NULL) {
- t = new(NULL) glsl_type(fields, num_fields, name);
+ t = new glsl_type(fields, num_fields, name);
hash_table_insert(record_types, (void *) t, t);
}
/* Callers of this talloc-based new need not call delete. It's
* easier to just talloc_free 'ctx' (or any of its ancestors). */
- static void* operator new(size_t size, void *ctx)
+ static void* operator new(size_t size)
{
+ if (glsl_type::ctx == NULL) {
+ glsl_type::ctx = talloc_init("glsl_type");
+ assert(glsl_type::ctx != NULL);
+ }
+
void *type;
- type = talloc_size(ctx, size);
+ type = talloc_size(glsl_type::ctx, size);
assert(type != NULL);
return type;
}
private:
+ /**
+ * talloc context for all glsl_type allocations
+ *
+ * Set on the first call to \c glsl_type::new.
+ */
+ static TALLOC_CTX *ctx;
+
/** Constructor for vector and matrix types */
glsl_type(GLenum gl_type,
unsigned base_type, unsigned vector_elements,