RLQCP6HZ5VXDNVJCYA3EXDWFFPUGYZRKGAKY7TZS4QGA5ZL4OPBAC
#define THIN_GL_SHADER_FLAGS_require(NAME)
#define THIN_GL_SHADER_FLAGS_flag(NAME) | THIN_GL_SHADER_FLAG_ ## NAME
#define THIN_GL_SHADER_FLAGS_code(CODE)
#define THIN_GL_SHADER_FLAGS_string(CODE)
#define THIN_GL_SHADER_FLAGS_main(CODE)
#define THIN_GL_SHADER_FLAGS_(ITEM) ALIAS_CPP_CAT(THIN_GL_SHADER_FLAGS_, ITEM)
}
}
static uint32_t script_builder_collect_flags(const struct GL_ShaderSnippet *shader) {
uint32_t flags = shader->flags;
for(uint32_t i = 0; i < 8; i++) {
if(shader->requires[i] == NULL)
break;
flags |= script_builder_collect_flags(shader->requires[i]);
}
return flags;
}
static void script_builder_add_prelude(const struct GL_ShaderSnippet *shader) {
uint32_t flags = script_builder_collect_flags(shader);
script_builder_add("#version 460 core\n");
if(flags & THIN_GL_SHADER_FLAG_SUBGROUP_ARITHMETIC) {
script_builder_add("#extension GL_KHR_shader_subgroup_arithmetic : enable\n");
}
if(flags & THIN_GL_SHADER_FLAG_ARITHMETIC_INT64) {
script_builder_add("#extension GL_EXT_shader_explicit_arithmetic_types_int64 : enable\n");
extern void R_SetCacheState(msurface_t *surf);
extern void R_BuildLightMap(msurface_t *surf, byte *dest_rgb0, byte *dest_r1, byte *dest_g1, byte *dest_b1, int stride);
extern void R_SetCacheState(model_t *model, msurface_t *surf);
extern void R_BuildLightMap(model_t *model, msurface_t *surf, byte *dest_rgb0, byte *dest_r1, byte *dest_g1, byte *dest_b1, int stride);
for(i = 0; i < r_worldmodel[cmodel_index]->numleafs; i++)
r_worldmodel[cmodel_index]->leafs[i].visframe = r_visframecount;
for(i = 0; i < r_worldmodel[cmodel_index]->numnodes; i++)
r_worldmodel[cmodel_index]->nodes[i].visframe = r_visframecount;
for(i = 0; i < model->numleafs; i++)
model->leafs[i].visframe = r_visframecount;
for(i = 0; i < model->numnodes; i++)
model->nodes[i].visframe = r_visframecount;
memcpy(fatvis, vis, (r_worldmodel[cmodel_index]->numleafs + 7) / 8);
vis = Mod_ClusterPVS(r_viewcluster2, r_worldmodel[cmodel_index]);
c = (r_worldmodel[cmodel_index]->numleafs + 31) / 32;
memcpy(fatvis, vis, (model->numleafs + 7) / 8);
vis = Mod_ClusterPVS(r_viewcluster2, model);
c = (model->numleafs + 31) / 32;
THIN_GL_SHADER(post_simulate,
THIN_GL_SHADER(postsimulate,
main(
uint count = u_particle_counter.alive;
u_particle_indirect.draw.count = count;
for(uint i = 0; i < count; i++) {
u_particle_alive.item[i] = u_particle_emitted.item[i];
}
)
)
// clang-format on
struct GL_ComputeState postsimulate_compute_state = {.shader = &postsimulate_shader,
.global[0] = {0, &indirect_resource},
.global[1] = {0, &counter_resource},
.global[2] = {0, &alive_resource},
.global[3] = {0, &emitted_resource}};
// clang-format off
THIN_GL_SHADER(postsimulate_sort,
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
GL_compute_indirect(&sort_particles_fill_pass_state, NULL, &sort_parameters_buffer,
offsetof(struct GL_sort_parameters, fill));
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_COMMAND_BARRIER_BIT);
GL_compute_indirect(&sort_particles_fill_pass_state, NULL, &sort_parameters_buffer,
offsetof(struct GL_sort_parameters, fill));
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
GL_compute_indirect(&sort_particles_radix_pass_1_state, NULL, &sort_parameters_buffer,
offsetof(struct GL_sort_parameters, radix_1));
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
GL_compute_indirect(&sort_particles_radix_pass_1_state, NULL, &sort_parameters_buffer,
offsetof(struct GL_sort_parameters, radix_1));
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
GL_compute_indirect(&sort_particles_rotate_pass_state, NULL, &sort_parameters_buffer,
offsetof(struct GL_sort_parameters, rotate));
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
GL_compute_indirect(&sort_particles_rotate_pass_state, NULL, &sort_parameters_buffer,
offsetof(struct GL_sort_parameters, rotate));
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
GL_compute_indirect(&sort_particles_radix_pass_2_state, NULL, &sort_parameters_buffer,
offsetof(struct GL_sort_parameters, radix_2));
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
GL_compute_indirect(&sort_particles_radix_pass_2_state, NULL, &sort_parameters_buffer,
offsetof(struct GL_sort_parameters, radix_2));
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
GL_compute_indirect(&sort_particles_sortedmatrix_pass_state, NULL, &sort_parameters_buffer,
offsetof(struct GL_sort_parameters, sortedmatrix));
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
GL_compute_indirect(&sort_particles_sortedmatrix_pass_state, NULL, &sort_parameters_buffer,
offsetof(struct GL_sort_parameters, sortedmatrix));
} else {
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
GL_compute(&postsimulate_compute_state, NULL, 1, 1, 1);
}
loadmodel->extradata = HunkAllocator_Begin(&hunk, 0x1000000);
Mod_LoadBrushModel(mod, &hunk, (void *)buffer);
model->extradata = HunkAllocator_Begin(&hunk, 0x1000000);
model->old_lightmap = false;
Mod_LoadBrushModel(model, &hunk, (void *)buffer);
loadmodel->lightdata = HunkAllocator_Alloc(hunk, l->filelen);
memcpy(loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
model->lightdatasize = l->filelen;
model->lightdata = HunkAllocator_Alloc(hunk, l->filelen);
memcpy(model->lightdata, mod_base + l->fileofs, l->filelen);
loadmodel->vis->numclusters = LittleLong(loadmodel->vis->numclusters);
for(i = 0; i < loadmodel->vis->numclusters; i++) {
loadmodel->vis->bitofs[i][0] = LittleLong(loadmodel->vis->bitofs[i][0]);
loadmodel->vis->bitofs[i][1] = LittleLong(loadmodel->vis->bitofs[i][1]);
model->vis->numclusters = LittleLong(model->vis->numclusters);
for(i = 0; i < model->vis->numclusters; i++) {
model->vis->bitofs[i][0] = LittleLong(model->vis->bitofs[i][0]);
model->vis->bitofs[i][1] = LittleLong(model->vis->bitofs[i][1]);
GL_CreateSurfaceLightmap(out);
int smax = (out->extents[0] >> 4) + 1;
int tmax = (out->extents[1] >> 4) + 1;
int size = smax * tmax;
if(i + (size * 3) * 4 > model->lightdatasize) {
model->old_lightmap = true;
}
}
}
in = (void *)(mod_base + l->fileofs);
out = model->surfaces;
for(surfnum = 0; surfnum < count; surfnum++, in++, out++) {
GL_CreateSurfaceLightmap(model, out);
Mod_LoadVertexes(&header->lumps[LUMP_VERTEXES], hunk);
Mod_LoadEdges(&header->lumps[LUMP_EDGES], hunk);
Mod_LoadSurfedges(&header->lumps[LUMP_SURFEDGES], hunk);
Mod_LoadLighting(&header->lumps[LUMP_LIGHTING], hunk);
Mod_LoadPlanes(&header->lumps[LUMP_PLANES], hunk);
Mod_LoadTexinfo(&header->lumps[LUMP_TEXINFO], hunk);
Mod_LoadFaces(&header->lumps[LUMP_FACES], hunk);
Mod_LoadMarksurfaces(&header->lumps[LUMP_LEAFFACES], hunk);
Mod_LoadVisibility(&header->lumps[LUMP_VISIBILITY], hunk);
Mod_LoadLeafs(&header->lumps[LUMP_LEAFS], hunk);
Mod_LoadNodes(&header->lumps[LUMP_NODES], hunk);
Mod_LoadSubmodels(&header->lumps[LUMP_MODELS], hunk);
mod->numframes = 2; // regular and alternate animation
Mod_LoadVertexes(model, &header->lumps[LUMP_VERTEXES], hunk);
Mod_LoadEdges(model, &header->lumps[LUMP_EDGES], hunk);
Mod_LoadSurfedges(model, &header->lumps[LUMP_SURFEDGES], hunk);
Mod_LoadLighting(model, &header->lumps[LUMP_LIGHTING], hunk);
Mod_LoadPlanes(model, &header->lumps[LUMP_PLANES], hunk);
Mod_LoadTexinfo(model, &header->lumps[LUMP_TEXINFO], hunk);
Mod_LoadFaces(model, &header->lumps[LUMP_FACES], hunk);
Mod_LoadMarksurfaces(model, &header->lumps[LUMP_LEAFFACES], hunk);
Mod_LoadVisibility(model, &header->lumps[LUMP_VISIBILITY], hunk);
Mod_LoadLeafs(model, &header->lumps[LUMP_LEAFS], hunk);
Mod_LoadNodes(model, &header->lumps[LUMP_NODES], hunk);
Mod_LoadSubmodels(model, &header->lumps[LUMP_MODELS], hunk);
void R_DrawAliasModel(entity_t *e);
void R_DrawBrushModel(entity_t *e);
void R_DrawSpriteModel(entity_t *e);
void R_DrawBeam(entity_t *e);
void R_DrawWorld(int cmodel_index);
void R_DrawAliasModel(entity_t *e, model_t *model);
void R_DrawBrushModel(entity_t *e, model_t *model);
void R_DrawSpriteModel(entity_t *e, model_t *model);
void R_DrawBeam(entity_t *e, model_t *model);
void R_DrawWorld(model_t *model);
pointcolor.f[1] += lightmap[0] * scale[0] * (1.0 / 255) * 2.0f - 1.0f;
pointcolor.f[2] += lightmap[1] * scale[1] * (1.0 / 255) * 2.0f - 1.0f;
pointcolor.f[3] += lightmap[2] * scale[2] * (1.0 / 255) * 2.0f - 1.0f;
lightmap += 3 * ((surf->extents[0] >> 4) + 1) * ((surf->extents[1] >> 4) + 1);
if(!model->old_lightmap) {
pointcolor.f[1] += lightmap[0] * scale[0] * (1.0 / 255) * 2.0f - 1.0f;
pointcolor.f[2] += lightmap[1] * scale[1] * (1.0 / 255) * 2.0f - 1.0f;
pointcolor.f[3] += lightmap[2] * scale[2] * (1.0 / 255) * 2.0f - 1.0f;
lightmap += 3 * ((surf->extents[0] >> 4) + 1) * ((surf->extents[1] >> 4) + 1);
pointcolor.f[5] += lightmap[0] * scale[0] * (1.0 / 255) * 2.0f - 1.0f;
pointcolor.f[6] += lightmap[1] * scale[1] * (1.0 / 255) * 2.0f - 1.0f;
pointcolor.f[7] += lightmap[2] * scale[2] * (1.0 / 255) * 2.0f - 1.0f;
lightmap += 3 * ((surf->extents[0] >> 4) + 1) * ((surf->extents[1] >> 4) + 1);
pointcolor.f[5] += lightmap[0] * scale[0] * (1.0 / 255) * 2.0f - 1.0f;
pointcolor.f[6] += lightmap[1] * scale[1] * (1.0 / 255) * 2.0f - 1.0f;
pointcolor.f[7] += lightmap[2] * scale[2] * (1.0 / 255) * 2.0f - 1.0f;
lightmap += 3 * ((surf->extents[0] >> 4) + 1) * ((surf->extents[1] >> 4) + 1);
pointcolor.f[9] += (lightmap[0] * scale[0] * (1.0 / 255)) * 2.0f - 1.0f;
pointcolor.f[10] += (lightmap[1] * scale[1] * (1.0 / 255)) * 2.0f - 1.0f;
pointcolor.f[11] += (lightmap[2] * scale[2] * (1.0 / 255)) * 2.0f - 1.0f;
lightmap += 3 * ((surf->extents[0] >> 4) + 1) * ((surf->extents[1] >> 4) + 1);
pointcolor.f[9] += (lightmap[0] * scale[0] * (1.0 / 255)) * 2.0f - 1.0f;
pointcolor.f[10] += (lightmap[1] * scale[1] * (1.0 / 255)) * 2.0f - 1.0f;
pointcolor.f[11] += (lightmap[2] * scale[2] * (1.0 / 255)) * 2.0f - 1.0f;
lightmap += 3 * ((surf->extents[0] >> 4) + 1) * ((surf->extents[1] >> 4) + 1);
}
void R_BuildLightMap(msurface_t *surf, byte *dest_rgb0, byte *dest_r1, byte *dest_g1, byte *dest_b1, int stride) {
void R_BuildLightMap(model_t *model, msurface_t *surf, byte *dest_rgb0, byte *dest_r1, byte *dest_g1, byte *dest_b1, int stride) {
lightmap_rgb0 = surf->samples + (size * 3) * 0;
lightmap_r1 = surf->samples + (size * 3) * 1;
lightmap_g1 = surf->samples + (size * 3) * 2;
lightmap_b1 = surf->samples + (size * 3) * 3;
int newsize = model->old_lightmap ? 0 : size * 3;
int newstride = model->old_lightmap ? 1 : 4;
float newscale = model->old_lightmap ? 0.0f : 1.0f;
lightmap_rgb0 += size * 3 * 4;
lightmap_r1 += size * 3 * 4;
lightmap_g1 += size * 3 * 4;
lightmap_b1 += size * 3 * 4;
lightmap_rgb0 += size * 3 * newstride;
lightmap_r1 += size * 3 * newstride;
lightmap_g1 += size * 3 * newstride;
lightmap_b1 += size * 3 * newstride;
lightmap_rgb0 += size * 3 * 4;
lightmap_r1 += size * 3 * 4;
lightmap_g1 += size * 3 * 4;
lightmap_b1 += size * 3 * 4;
lightmap_rgb0 += size * 3 * newstride;
lightmap_r1 += size * 3 * newstride;
lightmap_g1 += size * 3 * newstride;
lightmap_b1 += size * 3 * newstride;