Quake II RTX doxygen
1.0 dev
|
|
#include "material.h"
#include "common/files.h"
#include "refresh/images.h"
#include "vk_util.h"
#include "shader/constants.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
Go to the source code of this file.
|
static qerror_t | getStringValue (CSV_values_t const *csv, int index, char *dest) |
|
static qerror_t | getFloatValue (CSV_values_t const *csv, int index, float *dest) |
|
static qerror_t | getIntValue (CSV_values_t const *csv, int index, int *dest) |
|
static qerror_t | getFlagValue (CSV_values_t const *csv, int index, uint32_t *flags, uint32_t mask) |
|
static qerror_t | parse_CSV_line (char *linebuf, CSV_values_t *csv) |
|
static size_t | truncateExtension (char const *src, char *dest) |
|
const pbr_material_t * | MAT_GetPBRMaterialsTable () |
|
int | MAT_GetNumPBRMaterials () |
|
int | MAT_GetPBRMaterialIndex (pbr_material_t const *mat) |
|
static void | MAT_Reset (pbr_material_t *mat, int mat_index) |
|
static qerror_t | validateMaterialsTable (pbr_materials_table_t *table) |
|
static uint32_t | getMaterialKind (char const *kindname) |
|
static const char * | getMaterialKindName (uint32_t flag) |
|
static qerror_t | writeMaterialsTable (char const *filename, pbr_materials_table_t const *table) |
|
static qerror_t | parseMaterialsTable (char const *filename, pbr_materials_table_t *table) |
|
qerror_t | MAT_InitializePBRmaterials () |
|
qerror_t | MAT_ReloadPBRMaterials () |
|
qerror_t | MAT_SavePBRMaterials () |
|
qerror_t | MAT_RegisterPBRMaterial (pbr_material_t *mat, image_t *image_diffuse, image_t *image_normals, image_t *image_emissive) |
|
void | MAT_UpdateRegistration (pbr_material_t *mat) |
|
qerror_t | MAT_ResetUnused () |
|
pbr_material_t * | MAT_GetPBRMaterial (int index) |
|
pbr_material_t * | MAT_FindPBRMaterial (char const *name) |
|
const pbr_material_t * | MAT_UpdatePBRMaterialSkin (image_t *image_diffuse) |
|
void | MAT_PrintMaterialProperties (pbr_material_t const *mat) |
|
qerror_t | MAT_SetPBRMaterialAttribute (pbr_material_t *mat, char const *token, char const *value) |
|
uint32_t | MAT_SetKind (uint32_t material, uint32_t kind) |
|
qboolean | MAT_IsKind (uint32_t material, uint32_t kind) |
|
◆ MAX_CSV_VALUES
#define MAX_CSV_VALUES 32 |
◆ CSV_values_t
◆ pbr_materials_table_t
◆ getFlagValue()
static qerror_t getFlagValue |
( |
CSV_values_t const * |
csv, |
|
|
int |
index, |
|
|
uint32_t * |
flags, |
|
|
uint32_t |
mask |
|
) |
| |
|
static |
Definition at line 67 of file material.c.
69 if (index >= csv->num_values || csv->values[index][0] ==
'\0')
71 if (atoi(csv->values[index]))
72 *flags = *flags | mask;
Referenced by parseMaterialsTable().
◆ getFloatValue()
static qerror_t getFloatValue |
( |
CSV_values_t const * |
csv, |
|
|
int |
index, |
|
|
float * |
dest |
|
) |
| |
|
static |
Definition at line 50 of file material.c.
53 if (index >= csv->num_values || csv->values[index][0] ==
'\0')
55 *dest = atof(csv->values[index]);
Referenced by parseMaterialsTable().
◆ getIntValue()
Definition at line 59 of file material.c.
61 if (index >= csv->num_values || csv->values[index][0] ==
'\0')
63 *dest = atoi(csv->values[index]);
Referenced by parseMaterialsTable().
◆ getMaterialKind()
static uint32_t getMaterialKind |
( |
char const * |
kindname | ) |
|
|
static |
◆ getMaterialKindName()
static const char* getMaterialKindName |
( |
uint32_t |
flag | ) |
|
|
static |
◆ getStringValue()
static qerror_t getStringValue |
( |
CSV_values_t const * |
csv, |
|
|
int |
index, |
|
|
char * |
dest |
|
) |
| |
|
static |
◆ MAT_FindPBRMaterial()
◆ MAT_GetNumPBRMaterials()
int MAT_GetNumPBRMaterials |
( |
| ) |
|
◆ MAT_GetPBRMaterial()
◆ MAT_GetPBRMaterialIndex()
◆ MAT_GetPBRMaterialsTable()
◆ MAT_InitializePBRmaterials()
qerror_t MAT_InitializePBRmaterials |
( |
| ) |
|
◆ MAT_IsKind()
qboolean MAT_IsKind |
( |
uint32_t |
material, |
|
|
uint32_t |
kind |
|
) |
| |
◆ MAT_PrintMaterialProperties()
Definition at line 549 of file material.c.
551 Com_Printf(
"{ %s\n", mat->name);
552 Com_Printf(
" image_diffuse = '%s'\n", mat->image_diffuse ? mat->image_diffuse->name :
"");
553 Com_Printf(
" image_normals = '%s'\n", mat->image_normals ? mat->image_normals->name :
"");
554 Com_Printf(
" image_emissive = '%s'\n", mat->image_emissive ? mat->image_emissive->name :
"");
555 Com_Printf(
" bump_scale = %f,\n", mat->bump_scale);
556 Com_Printf(
" rough_override = %f,\n", mat->rough_override);
557 Com_Printf(
" specular_scale = %f,\n", mat->specular_scale);
558 Com_Printf(
" emissive_scale = %f,\n", mat->emissive_scale);
560 Com_Printf(
" kind = '%s',\n", kind ? kind :
"");
561 Com_Printf(
" light = %d,\n", (mat->flags &
MATERIAL_FLAG_LIGHT) ? (mat->enable_light_styles ? 1 : 2) : 0);
Referenced by vkpt_print_material().
◆ MAT_RegisterPBRMaterial()
◆ MAT_ReloadPBRMaterials()
qerror_t MAT_ReloadPBRMaterials |
( |
| ) |
|
Definition at line 347 of file material.c.
352 * new_table = &newtable;
358 Com_EPrintf(
"Cannot reload materials table : table has different material count, please restart the game\n");
359 return Q_ERR_FAILURE;
364 Com_EPrintf(
"Cannot reload materials table : table has different material keys, please check your edits\n");
365 return Q_ERR_FAILURE;
371 * new_mat = &new_table->materials[i];
373 if (strncmp(old_mat->
name, new_mat->name, MAX_QPATH) != 0)
375 Com_EPrintf(
"Cannot update material '%s' : incorrect name, please check your edits\n", new_mat->name);
384 old_mat->
flags = new_mat->flags;
388 return Q_ERR_FAILURE;
Referenced by vkpt_reload_materials().
◆ MAT_Reset()
◆ MAT_ResetUnused()
qerror_t MAT_ResetUnused |
( |
| ) |
|
◆ MAT_SavePBRMaterials()
qerror_t MAT_SavePBRMaterials |
( |
| ) |
|
◆ MAT_SetKind()
uint32_t MAT_SetKind |
( |
uint32_t |
material, |
|
|
uint32_t |
kind |
|
) |
| |
◆ MAT_SetPBRMaterialAttribute()
qerror_t MAT_SetPBRMaterialAttribute |
( |
pbr_material_t * |
mat, |
|
|
char const * |
token, |
|
|
char const * |
value |
|
) |
| |
Definition at line 570 of file material.c.
576 enum TokenType { TOKEN_BOOL, TOKEN_FLOAT, TOKEN_STRING };
578 static struct Token {
583 {0,
"bump_scale", TOKEN_FLOAT},
584 {1,
"roughness_override", TOKEN_FLOAT},
585 {2,
"specular_scale", TOKEN_FLOAT},
586 {3,
"emissive_scale", TOKEN_FLOAT},
587 {4,
"kind", TOKEN_STRING},
588 {5,
"light_flag", TOKEN_BOOL},
589 {6,
"correct_albedo_flag", TOKEN_BOOL} };
591 static int ntokens =
sizeof(tokens) /
sizeof(
struct Token);
593 if (token == NULL || value == NULL)
596 struct Token const * t = NULL;
597 for (
int i = 0; i < ntokens; ++i)
599 if (strcmp(token, tokens[i].name) == 0)
604 Com_EPrintf(
"Unknown material token '%s'\n",
Cmd_Argv(1));
608 float fvalue = 0.f; qboolean bvalue = qfalse;
char const * svalue = NULL;
611 case TOKEN_BOOL: bvalue = atoi(value) == 0 ? qfalse : qtrue;
break;
612 case TOKEN_FLOAT: fvalue = (float)atof(value);
break;
613 case TOKEN_STRING: svalue = value;
break;
615 assert(
"unknown PBR MAT attribute token type");
632 Com_EPrintf(
"Unknown material kind '%s'\n", svalue);
633 return Q_ERR_FAILURE;
640 return Q_ERR_SUCCESS;
643 Com_Printf(
"Usage : set_material <token> <value>\n");
644 for (
int i = 0; i < ntokens; ++i)
646 struct Token const * t = &tokens[i];
648 char const *
typename =
"(undefined)";
651 case TOKEN_BOOL:
typename =
"bool [0,1]";
break;
652 case TOKEN_FLOAT:
typename =
"float";
break;
653 case TOKEN_STRING:
typename =
"string";
break;
655 Com_Printf(
" %s (%s)\n", t->name,
typename);
657 return Q_ERR_FAILURE;
Referenced by vkpt_set_material().
◆ MAT_UpdatePBRMaterialSkin()
◆ MAT_UpdateRegistration()
◆ parse_CSV_line()
static qerror_t parse_CSV_line |
( |
char * |
linebuf, |
|
|
CSV_values_t * |
csv |
|
) |
| |
|
static |
Definition at line 76 of file material.c.
78 static char delim =
',';
80 char * cptr = linebuf,
c;
91 csv->
values[index] = cptr + 1;
96 else if (
c == delim && !inquote)
99 csv->
values[++index] = cptr + 1;
104 return Q_ERR_SUCCESS;
Referenced by parseMaterialsTable().
◆ parseMaterialsTable()
Definition at line 261 of file material.c.
267 byte * buffer = NULL; ssize_t buffer_size = 0;
268 buffer_size = FS_LoadFile(filename, (
void**)&buffer);
271 Com_EPrintf(
"cannot load materials table '%s'\n", filename);
272 return Q_ERR_FAILURE;
278 char const * ptr = (
char const *)buffer;
279 char linebuf[MAX_QPATH * 3];
280 while (
sgets(linebuf,
sizeof(linebuf), &ptr))
283 if (currentLine == 0 && strncmp(linebuf,
"Material", 8) == 0)
290 qerror_t status = Q_ERR_SUCCESS;
302 char kindname[MAX_QPATH];
314 status = Q_ERR_FAILURE;
316 if (status == Q_ERR_SUCCESS)
323 Com_EPrintf(
"CSV error in materials table : '%s':%d", table->
filename, currentLine);
330 Com_Printf(
"Loaded '%s' (fast search = %s)\n", filename, table->
alpha_sorted == qtrue ?
"true" :
"false");
Referenced by MAT_InitializePBRmaterials(), and MAT_ReloadPBRMaterials().
◆ truncateExtension()
static size_t truncateExtension |
( |
char const * |
src, |
|
|
char * |
dest |
|
) |
| |
|
static |
Definition at line 111 of file material.c.
114 size_t len = strlen(src);
115 assert(len < MAX_QPATH);
117 if (len > 4 && src[len - 4] ==
'.')
121 memcpy(dest, src, len);
Referenced by MAT_FindPBRMaterial().
◆ validateMaterialsTable()
Definition at line 166 of file material.c.
176 Com_EPrintf(
"duplicate material names in materials table '%s'\n", table->
filename);
177 return Q_ERR_FAILURE;
181 Com_WPrintf(
"materials table '%s' is not sorted - fast search disabled\n", table->
filename);
185 return Q_ERR_SUCCESS;
Referenced by parseMaterialsTable().
◆ writeMaterialsTable()
Definition at line 229 of file material.c.
231 char path[MAX_OSPATH];
232 qhandle_t f =
FS_EasyOpenFile(path,
sizeof(path), FS_MODE_WRITE | FS_FLAG_TEXT,
"", filename,
"");
234 Com_EPrintf(
"Error opening '%s'\n", path);
235 return Q_ERR_FAILURE;
238 FS_FPrintf(f,
"Material,Bump Scale,Roughness Override,Specular Scale,Emissive Scale,Kind,Invisible Flag,Light Flag,Correct Albedo Flag\n");
240 for (
int i = 0; i < table->num_materials; ++i)
257 Com_Printf(
"Saved '%s'\n", path);
258 return Q_ERR_SUCCESS;
Referenced by MAT_SavePBRMaterials().
◆ materialKinds
◆ materials_filename
const char* materials_filename = "materials.csv" |
|
static |
◆ nMaterialKinds
◆ pbr_materials_table
pbr_materials_table_t pbr_materials_table = { .num_materials = 0, .num_custom_materials = 0, .alpha_sorted = qtrue } |
|
static |
◆ registration_sequence
int registration_sequence |
Definition at line 34 of file main.c.
Referenced by enqueue_stretch_pic(), find_or_load_image(), GL_LoadWorld(), GL_PostInit(), IMG_FreeUnused(), MAT_RegisterPBRMaterial(), MAT_ResetUnused(), MAT_UpdatePBRMaterialSkin(), MAT_UpdateRegistration(), MOD_FreeUnused(), MOD_Reference(), MOD_Reference_GL(), MOD_Reference_RTX(), R_BeginRegistration(), R_BeginRegistration_GL(), R_BeginRegistration_RTX(), R_Init_RTX(), R_InitImages(), R_RegisterModel(), and R_RegisterRawImage().
static qerror_t parse_CSV_line(char *linebuf, CSV_values_t *csv)
static qerror_t getStringValue(CSV_values_t const *csv, int index, char *dest)
qhandle_t FS_EasyOpenFile(char *buf, size_t size, unsigned mode, const char *dir, const char *name, const char *ext)
#define MATERIAL_KIND_INVALID
#define MATERIAL_FLAG_CORRECT_ALBEDO
static qerror_t validateMaterialsTable(pbr_materials_table_t *table)
#define MATERIAL_KIND_LAVA
static struct MaterialKind materialKinds[]
static const char * materials_filename
int registration_sequence
ssize_t FS_FPrintf(qhandle_t f, const char *format,...)
#define MATERIAL_KIND_SKY
#define MATERIAL_FLAG_LIGHT
static qerror_t writeMaterialsTable(char const *filename, pbr_materials_table_t const *table)
static qerror_t getIntValue(CSV_values_t const *csv, int index, int *dest)
#define MATERIAL_KIND_REGULAR
static void MAT_Reset(pbr_material_t *mat, int mat_index)
#define MATERIAL_KIND_MASK
static int nMaterialKinds
#define MATERIAL_KIND_CHROME
char * values[MAX_CSV_VALUES]
pbr_material_t materials[MAX_PBR_MATERIALS]
int Q_strcasecmp(const char *s1, const char *s2)
#define MATERIAL_KIND_CAMERA
#define MATERIAL_KIND_SLIME
char * sgets(char *str, int num, char const **input)
int registration_sequence
#define MATERIAL_KIND_SCREEN
static pbr_materials_table_t pbr_materials_table
static const char * getMaterialKindName(uint32_t flag)
void FS_FCloseFile(qhandle_t f)
size_t Q_concat(char *dest, size_t size,...)
static qerror_t getFlagValue(CSV_values_t const *csv, int index, uint32_t *flags, uint32_t mask)
#define MATERIAL_KIND_INVISIBLE
static uint32_t getMaterialKind(char const *kindname)
#define MATERIAL_INDEX_MASK
static size_t truncateExtension(char const *src, char *dest)
#define MATERIAL_KIND_WATER
static qerror_t getFloatValue(CSV_values_t const *csv, int index, float *dest)
static qerror_t parseMaterialsTable(char const *filename, pbr_materials_table_t *table)
uint32_t MAT_SetKind(uint32_t material, uint32_t kind)
pbr_material_t * MAT_FindPBRMaterial(char const *name)
#define MATERIAL_KIND_GLASS