Ejemplo n.º 1
0
static GLboolean slang_uniform_bindings_add (slang_uniform_bindings *self, slang_export_data_quant *q,
	const char *name, GLuint index, GLuint address)
{
	const GLuint n = self->count;
	GLuint i;

	for (i = 0; i < n; i++)
		if (slang_string_compare (self->table[i].name, name) == 0)
		{
			self->table[i].address[index] = address;
			return GL_TRUE;
		}

	self->table = (slang_uniform_binding *) slang_alloc_realloc (self->table,
		n * sizeof (slang_uniform_binding), (n + 1) * sizeof (slang_uniform_binding));
	if (self->table == NULL)
		return GL_FALSE;
	self->table[n].quant = q;
	self->table[n].name = slang_string_duplicate (name);
	for (i = 0; i < SLANG_SHADER_MAX; i++)
		self->table[n].address[i] = ~0;
	self->table[n].address[index] = address;
	if (self->table[n].name == NULL)
		return GL_FALSE;
	self->count++;
	return GL_TRUE;
}
Ejemplo n.º 2
0
static GLboolean call_asm_instruction (slang_assemble_ctx *A, slang_atom a_name)
{
	const char *id;
	GLuint i;

	id = slang_atom_pool_id (A->atoms, a_name);

	for (i = 0; inst[i].name != NULL; i++)
		if (slang_string_compare (id, inst[i].name) == 0)
			break;
	if (inst[i].name == NULL)
		return GL_FALSE;

	if (!PLAB2 (A->file, inst[i].code1, 4, 0))
		return GL_FALSE;
	if (inst[i].code2 != slang_asm_none)
		if (!PLAB2 (A->file, inst[i].code2, 4, 0))
			return GL_FALSE;

	/* clean-up the stack from the remaining dst address */
	if (!PLAB (A->file, slang_asm_local_free, 4))
		return GL_FALSE;

	return GL_TRUE;
}
slang_type_specifier_type slang_type_specifier_type_from_string (const char *name)
{
	type_specifier_type_name *p = type_specifier_type_names;
	while (p->name != NULL)
	{
		if (slang_string_compare (p->name, name) == 0)
			break;
		p++;
	}
	return p->type;
}
Ejemplo n.º 4
0
/*
 * Search the atom pool for an atom with a given name.
 * If atom is not found, create and add it to the pool.
 * Returns ATOM_NULL if the atom was not found and the function failed
 * to create a new atom.
 */
slang_atom
slang_atom_pool_atom(slang_atom_pool * pool, const char * id)
{
   GLuint hash;
   const char * p = id;
   slang_atom_entry ** entry;

   /* Hash a given string to a number in the range [0, ATOM_POOL_SIZE). */
   hash = 0;
   while (*p != '\0') {
      GLuint g;

      hash = (hash << 4) + (GLuint) (*p++);
      g = hash & 0xf0000000;
      if (g != 0)
         hash ^= g >> 24;
      hash &= ~g;
   }
   hash %= SLANG_ATOM_POOL_SIZE;

   /* Now the hash points to a linked list of atoms with names that
    * have the same hash value.  Search the linked list for a given
    * name.
    */
   entry = &pool->entries[hash];
   while (*entry != NULL) {
      /* If the same, return the associated atom. */
      if (slang_string_compare((**entry).id, id) == 0)
         return (slang_atom) (**entry).id;
      /* Grab the next atom in the linked list. */
      entry = &(**entry).next;
   }

   /* Okay, we have not found an atom. Create a new entry for it.
    * Note that the <entry> points to the last entry's <next> field.
    */
   *entry = (slang_atom_entry *) _slang_alloc(sizeof(slang_atom_entry));
   if (*entry == NULL)
      return SLANG_ATOM_NULL;

   /* Initialize a new entry. Because we'll need the actual name of
    * the atom, we use the pointer to this string as an actual atom's
    * value.
    */
   (**entry).next = NULL;
   (**entry).id = _slang_strdup(id);
   if ((**entry).id == NULL)
      return SLANG_ATOM_NULL;
   return (slang_atom) (**entry).id;
}
Ejemplo n.º 5
0
slang_atom slang_atom_pool_atom (slang_atom_pool *pool, const char *id)
{
    GLuint hash;
    const char *p = id;
    slang_atom_entry **entry;

    hash = 0;
    while (*p != '\0')
    {
        GLuint g;

        hash = (hash << 4) + (GLuint) *p++;
        g = hash & 0xf0000000;
        if (g != 0)
            hash ^= g >> 24;
        hash &= ~g;
    }
    hash %= SLANG_ATOM_POOL_SIZE;

    entry = &pool->entries[hash];
    while (*entry != NULL)
    {
        if (slang_string_compare ((**entry).id, id) == 0)
            return (slang_atom) (**entry).id;
        entry = &(**entry).next;
    }

    *entry = (slang_atom_entry *) slang_alloc_malloc (sizeof (slang_atom_entry));
    if (*entry == NULL)
        return SLANG_ATOM_NULL;

    (**entry).next = NULL;
    (**entry).id = slang_string_duplicate (id);
    if ((**entry).id == NULL)
        return SLANG_ATOM_NULL;
    return (slang_atom) (**entry).id;
}