rt: do not allow direct access to pached surfaces

This commit is contained in:
Ivan Avdeev 2023-03-02 20:25:25 -08:00
parent ed9a06cae1
commit 58c9a9920e
3 changed files with 59 additions and 41 deletions

View File

@ -388,7 +388,7 @@ void VK_BrushModelDraw( const cl_entity_t *ent, int render_mode, float blend, co
for (int i = 0; i < bmodel->render_model.num_geometries; ++i) {
vk_render_geometry_t *geom = bmodel->render_model.geometries + i;
const int surface_index = geom->surf - mod->surfaces;
const xvk_patch_surface_t *patch_surface = g_map_entities.patch.surfaces ? g_map_entities.patch.surfaces+surface_index : NULL;
const xvk_patch_surface_t *const patch_surface = R_VkPatchGetSurface(surface_index);
if (render_mode == kRenderTransColor) {
// TransColor mode means no texture color is used
@ -427,9 +427,12 @@ static qboolean renderableSurface( const msurface_t *surf, int i ) {
// PRINTFLAGS(PRINTFLAG)
// gEngine.Con_Reportf("\n");
// }
//
if (g_map_entities.patch.surfaces && g_map_entities.patch.surfaces[i].flags & Patch_Surface_Delete)
return false;
{
const xvk_patch_surface_t *patch_surface = R_VkPatchGetSurface(i);
if (patch_surface && patch_surface->flags & Patch_Surface_Delete)
return false;
}
//if( surf->flags & ( SURF_DRAWSKY | SURF_DRAWTURB | SURF_CONVEYOR | SURF_DRAWTURB_QUADS ) ) {
if( surf->flags & ( SURF_DRAWTURB | SURF_DRAWTURB_QUADS ) ) {
@ -481,7 +484,7 @@ static model_sizes_t computeSizes( const model_t *mod ) {
sizes.max_texture_id = tex_id;
{
const xvk_patch_surface_t *const psurf = g_map_entities.patch.surfaces ? g_map_entities.patch.surfaces + surface_index : NULL;
const xvk_patch_surface_t *const psurf = R_VkPatchGetSurface(i);
vec3_t emissive;
if ((psurf && (psurf->flags & Patch_Surface_Emissive)) || (RT_GetEmissiveForTexture(emissive, tex_id)))
++sizes.emissive_surfaces;
@ -545,7 +548,7 @@ static qboolean loadBrushSurfaces( model_sizes_t sizes, const model_t *mod ) {
int index_count = 0;
vec3_t tangent;
int tex_id = surf->texinfo->texture->gl_texturenum;
const xvk_patch_surface_t *const psurf = g_map_entities.patch.surfaces ? g_map_entities.patch.surfaces + surface_index : NULL;
const xvk_patch_surface_t *const psurf = R_VkPatchGetSurface(i);
if (!renderableSurface(surf, surface_index))
continue;

View File

@ -10,6 +10,11 @@
xvk_map_entities_t g_map_entities;
static struct {
xvk_patch_surface_t *surfaces;
int surfaces_count;
} g_patch;
static unsigned parseEntPropWadList(const char* value, string *out, unsigned bit) {
int dst_left = sizeof(string) - 2; // ; \0
char *dst = *out;
@ -321,16 +326,17 @@ static void addPatchSurface( const entity_props_t *props, uint32_t have_fields )
continue;
}
if (!g_map_entities.patch.surfaces) {
g_map_entities.patch.surfaces = Mem_Malloc(vk_core.pool, num_surfaces * sizeof(xvk_patch_surface_t));
if (!g_patch.surfaces) {
g_patch.surfaces = Mem_Malloc(vk_core.pool, num_surfaces * sizeof(xvk_patch_surface_t));
g_patch.surfaces_count = num_surfaces;
for (int i = 0; i < num_surfaces; ++i) {
g_map_entities.patch.surfaces[i].flags = Patch_Surface_NoPatch;
g_map_entities.patch.surfaces[i].tex_id = -1;
g_map_entities.patch.surfaces[i].tex = NULL;
g_patch.surfaces[i].flags = Patch_Surface_NoPatch;
g_patch.surfaces[i].tex_id = -1;
g_patch.surfaces[i].tex = NULL;
}
}
psurf = g_map_entities.patch.surfaces + index;
psurf = g_patch.surfaces + index;
if (should_remove) {
gEngine.Con_Reportf("Patch: surface %d removed\n", index);
@ -507,9 +513,10 @@ static void parsePatches( const model_t *const map ) {
char filename[256];
byte *data;
if (g_map_entities.patch.surfaces) {
Mem_Free(g_map_entities.patch.surfaces);
g_map_entities.patch.surfaces = NULL;
if (g_patch.surfaces) {
Mem_Free(g_patch.surfaces);
g_patch.surfaces = NULL;
g_patch.surfaces_count = 0;
}
Q_snprintf(filename, sizeof(filename), "luchiki/%s.patch", map->name);
@ -544,3 +551,14 @@ void XVK_ParseMapPatches( void ) {
parsePatches( map );
orientSpotlights();
}
const xvk_patch_surface_t* R_VkPatchGetSurface( int surface_index ) {
if (!g_patch.surfaces_count)
return NULL;
ASSERT(g_patch.surfaces);
ASSERT(surface_index >= 0);
ASSERT(surface_index < g_patch.surfaces_count);
return g_patch.surfaces + surface_index;
}

View File

@ -72,6 +72,28 @@ typedef struct {
vec3_t origin;
} xvk_mapent_target_t;
#define MAX_MAPENT_TARGETS 256
typedef struct {
int num_lights;
vk_light_entity_t lights[256];
int single_environment_index;
int entity_count;
string wadlist;
int num_targets;
xvk_mapent_target_t targets[MAX_MAPENT_TARGETS];
} xvk_map_entities_t;
extern xvk_map_entities_t g_map_entities;
enum { NoEnvironmentLights = -1, MoreThanOneEnvironmentLight = -2 };
void XVK_ParseMapEntities( void );
void XVK_ParseMapPatches( void );
enum {
Patch_Surface_NoPatch = 0,
Patch_Surface_Delete = 0x01,
@ -93,30 +115,5 @@ typedef struct {
vec3_t emissive;
} xvk_patch_surface_t;
typedef struct {
xvk_patch_surface_t *surfaces;
} xvk_patch_t;
const xvk_patch_surface_t* R_VkPatchGetSurface( int surface_index );
#define MAX_MAPENT_TARGETS 256
typedef struct {
int num_lights;
vk_light_entity_t lights[256];
int single_environment_index;
int entity_count;
string wadlist;
int num_targets;
xvk_mapent_target_t targets[MAX_MAPENT_TARGETS];
xvk_patch_t patch;
} xvk_map_entities_t;
extern xvk_map_entities_t g_map_entities;
enum { NoEnvironmentLights = -1, MoreThanOneEnvironmentLight = -2 };
void XVK_ParseMapEntities( void );
void XVK_ParseMapPatches( void );