mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-25 05:01:24 +00:00
[qfcc] Enable color/texture vector component names
Yet another step closer to glsl support. While it wasn't correct anyway (neither vectors nor quaternions are colors), the additional names broke q.s in the quaternion.r test, likely due to there being two s fields.
This commit is contained in:
parent
08bdc0794a
commit
663aeb16fd
2 changed files with 35 additions and 12 deletions
|
@ -172,17 +172,26 @@ build_struct (int su, symbol_t *tag, symtab_t *symtab, type_t *type,
|
|||
return sym;
|
||||
}
|
||||
int index = 0;
|
||||
int offset = 0;
|
||||
for (s = symtab->symbols; s; s = s->next) {
|
||||
if (s->sy_type != sy_offset)
|
||||
continue;
|
||||
if (!s->type) {
|
||||
if (su != 's' || strcmp (s->name, ".reset") != 0) {
|
||||
internal_error (0, "invalid struct field");
|
||||
}
|
||||
index = 0;
|
||||
offset = 0;
|
||||
continue;
|
||||
}
|
||||
if (is_class (s->type)) {
|
||||
error (0, "statically allocated instance of class %s",
|
||||
s->type->class->name);
|
||||
}
|
||||
if (su == 's') {
|
||||
symtab->size = RUP (symtab->size + base, s->type->alignment) - base;
|
||||
s->offset = symtab->size;
|
||||
symtab->size += type_size (s->type);
|
||||
offset = RUP (offset + base, s->type->alignment) - base;
|
||||
s->offset = offset;
|
||||
offset += type_size (s->type);
|
||||
} else {
|
||||
int size = type_size (s->type);
|
||||
if (size > symtab->size) {
|
||||
|
@ -224,6 +233,9 @@ build_struct (int su, symbol_t *tag, symtab_t *symtab, type_t *type,
|
|||
s->id = index++;
|
||||
}
|
||||
}
|
||||
if (su == 's') {
|
||||
symtab->size = offset;
|
||||
}
|
||||
symtab->count = index;
|
||||
if (!type)
|
||||
sym->type = find_type (sym->type); // checks the tag, not the symtab
|
||||
|
|
|
@ -1971,11 +1971,11 @@ chain_initial_types (void)
|
|||
}
|
||||
|
||||
static const char *vector_field_names[] = { "x", "y", "z", "w" };
|
||||
//static const char *color_field_names[] = { "r", "g", "b", "a" };
|
||||
//static const char *texture_field_names[] = { "s", "t", "p", "q" };
|
||||
static const char *color_field_names[] = { "r", "g", "b", "a" };
|
||||
static const char *texture_field_names[] = { "s", "t", "p", "q" };
|
||||
|
||||
static void
|
||||
build_vector_struct (type_t *type)
|
||||
build_vector_struct (type_t *type, bool extra_names)
|
||||
{
|
||||
ty_meta_e meta = type->meta;
|
||||
etype_t etype = type->type;
|
||||
|
@ -1986,11 +1986,21 @@ build_vector_struct (type_t *type)
|
|||
internal_error (0, "%s not a vector type: %p %d", type->name, ele_type, width);
|
||||
}
|
||||
|
||||
struct_def_t fields[width + 1];
|
||||
struct_def_t fields[3 * (width + 1)] = {};
|
||||
for (int i = 0; i < width; i++) {
|
||||
fields[i] = (struct_def_t) { vector_field_names[i], ele_type };
|
||||
auto v = &fields[i + 0 * (width + 1)];
|
||||
auto c = &fields[i + 1 * (width + 1)];
|
||||
auto t = &fields[i + 2 * (width + 1)];
|
||||
*v = (struct_def_t) { vector_field_names[i], ele_type };
|
||||
*c = (struct_def_t) { color_field_names[i], ele_type };
|
||||
*t = (struct_def_t) { texture_field_names[i], ele_type };
|
||||
}
|
||||
if (extra_names) {
|
||||
// these slots were zero-initialized so filling them in with a
|
||||
// reset field enables the additional component names
|
||||
fields[1 * (width + 1) - 1] = (struct_def_t) { ".reset" };
|
||||
fields[2 * (width + 1) - 1] = (struct_def_t) { ".reset" };
|
||||
}
|
||||
fields[width] = (struct_def_t) {};
|
||||
|
||||
make_structure (va (0, "@%s", type->name), 's', fields, type);
|
||||
type->type = etype;
|
||||
|
@ -2084,7 +2094,7 @@ init_types (void)
|
|||
|
||||
make_structure ("@zero", 'u', zero_struct, &type_zero);
|
||||
make_structure ("@param", 'u', param_struct, &type_param);
|
||||
build_vector_struct (&type_vector);
|
||||
build_vector_struct (&type_vector, false);
|
||||
|
||||
make_structure ("@type_encodings", 's', type_encoding_struct,
|
||||
&type_type_encodings);
|
||||
|
@ -2094,7 +2104,7 @@ init_types (void)
|
|||
va_list_struct[1].type = pointer_type (&type_param);
|
||||
make_structure ("@va_list", 's', va_list_struct, &type_va_list);
|
||||
|
||||
build_vector_struct (&type_quaternion);
|
||||
build_vector_struct (&type_quaternion, false);
|
||||
{
|
||||
symbol_t *sym;
|
||||
|
||||
|
@ -2106,7 +2116,8 @@ init_types (void)
|
|||
sym->offset = 3;
|
||||
symtab_addsymbol (type_quaternion.symtab, sym);
|
||||
}
|
||||
#define VEC_TYPE(type_name, base_type) build_vector_struct (&type_##type_name);
|
||||
#define VEC_TYPE(type_name, base_type) \
|
||||
build_vector_struct (&type_##type_name, true);
|
||||
#include "tools/qfcc/include/vec_types.h"
|
||||
|
||||
chain_structural_types ();
|
||||
|
|
Loading…
Reference in a new issue