+ scene_upload( world->scene_no_collide, &world->mesh_no_collide );
+ }
+ vg_release_thread_sync();
+
+ vg_linear_del( world_global.generic_heap, world->scene_no_collide );
+ world->scene_no_collide = NULL;
+}
+
+VG_STATIC int reset_player( int argc, char const *argv[] );
+VG_STATIC void world_post_process( world_instance *world )
+{
+ /* initialize audio if need be */
+ audio_lock();
+ for( int i=0; i<world->audio_things_count; i++ )
+ {
+ struct world_audio_thing *thingy = &world->audio_things[ i ];
+
+ audio_player_init( &thingy->player );
+ audio_player_set_flags( &thingy->player, thingy->flags );
+ audio_player_set_vol( &thingy->player, thingy->volume );
+ audio_player_set_pan( &thingy->player, 0.0f );
+
+ if( thingy->flags & AUDIO_FLAG_SPACIAL_3D )
+ audio_player_set_position( &thingy->player, thingy->pos );
+
+ if( thingy->flags & AUDIO_FLAG_AUTO_START )
+ audio_player_playclip( &thingy->player, &thingy->temp_embedded_clip );
+ }
+ audio_unlock();
+
+ vg_acquire_thread_sync();
+ {
+ /* create scene lighting buffer */
+
+ u32 size = VG_MAX(world->light_count,1) * sizeof(float)*12;
+
+ vg_info( "Upload %ubytes (lighting)\n", size );
+
+ glGenBuffers( 1, &world->tbo_light_entities );
+ glBindBuffer( GL_TEXTURE_BUFFER, world->tbo_light_entities );
+ glBufferData( GL_TEXTURE_BUFFER, size, NULL, GL_DYNAMIC_DRAW );
+
+ /* buffer layout
+ *
+ * colour position direction (spots)
+ * | . . . . | . . . . | . . . . |
+ * | Re Ge Be Night | Xco Yco Zco | Dx Dy Dz Da |
+ *
+ */
+
+ v4f *light_dst = glMapBuffer( GL_TEXTURE_BUFFER, GL_WRITE_ONLY );
+
+ for( int i=0; i<world->light_count; i++ )
+ {
+ struct world_light *light = &world->lights[i];
+ struct classtype_world_light *inf = light->inf;
+
+ /* colour + night */
+ v3_muls( inf->colour, inf->colour[3] * 2.0f, light_dst[i*3+0] );
+ light_dst[i*3+0][3] = 0.0f;
+
+ if( (inf->type == k_light_type_spot_nighttime_only) ||
+ (inf->type == k_light_type_point_nighttime_only ) )
+ {
+ u32 hash = (i * 29986577) & 0xff;
+ float switch_on = hash;
+ switch_on *= (1.0f/255.0f);
+
+ light_dst[i*3+0][3] = 0.44f + switch_on * 0.015f;
+ }
+
+ /* position + nothing */
+ v3_copy( light->node->co, light_dst[i*3+1] );
+
+ /* direction + angle */
+ q_mulv( light->node->q, (v3f){0.0f,-1.0f,0.0f}, light_dst[i*3+2]);
+ light_dst[i*3+2][3] = inf->angle;
+ }
+
+ glUnmapBuffer( GL_TEXTURE_BUFFER );
+
+ glGenTextures( 1, &world->tex_light_entities );
+ glBindTexture( GL_TEXTURE_BUFFER, world->tex_light_entities );
+ glTexBuffer( GL_TEXTURE_BUFFER, GL_RGBA32F, world->tbo_light_entities );
+
+
+ /* Upload lighting uniform buffer */
+ if( world->water.enabled )
+ v4_copy( world->water.plane, world->ub_lighting.g_water_plane );
+
+ v4f info_vec;
+ v3f *bounds = world->scene_geo->bbx;
+
+ info_vec[0] = bounds[0][0];
+ info_vec[1] = bounds[0][2];
+ info_vec[2] = 1.0f/ (bounds[1][0]-bounds[0][0]);
+ info_vec[3] = 1.0f/ (bounds[1][2]-bounds[0][2]);
+ v4_copy( info_vec, world->ub_lighting.g_depth_bounds );
+
+ /* upload full buffer */
+ glBindBuffer( GL_UNIFORM_BUFFER, world->ubo_lighting );
+ glBufferSubData( GL_UNIFORM_BUFFER, 0,
+ sizeof(struct ub_world_lighting), &world->ub_lighting );
+