now we're doing a bunch of them
[carveJwlIkooP6JGAAIwe30JlM.git] / world_gen.h
index 2b2ba57d91b2eaa4ece165ec559d0f4765d9ff8b..59bed34a282cfdd8ae05687b4c94d261168c76ef 100644 (file)
@@ -596,6 +596,48 @@ VG_STATIC void world_post_process( world_instance *world )
 
    vg_acquire_thread_sync();
    {
+      /* create scene lighting buffer */
+      glGenBuffers( 1, &world->tbo_light_entities );
+      glBindBuffer( GL_TEXTURE_BUFFER, world->tbo_light_entities );
+      glBufferData( GL_TEXTURE_BUFFER, world->light_count*sizeof(float)*8,
+                    NULL, GL_DYNAMIC_DRAW );
+
+      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];
+
+         v3_muls( light->colour, light->colour[3] * 2.0f, light_dst[i*2+0] );
+         v3_copy( light->co, light_dst[i*2+1] );
+      }
+
+      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 );
+
+
       /* 
        * Rendering the depth map
        */
@@ -634,39 +676,11 @@ VG_STATIC void world_post_process( world_instance *world )
       glBlendFunc(GL_ONE, GL_ONE);
       glBlendEquation(GL_MAX);
 
-      render_world_depth( world, &ortho );
+      render_world_position( world, &ortho );
       glDisable(GL_BLEND);
       glEnable(GL_DEPTH_TEST);
       glBindFramebuffer( GL_FRAMEBUFFER, 0 );
 
-      /* 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 );
-
-      /* add scene lights */
-      for( int i=0; i<world->light_count; i++ )
-      {
-         struct world_light *light = &world->lights[i];
-
-         v3_muls( light->colour, light->colour[3] * 2.0f,
-                  world->ub_lighting.g_point_light_colours[i] );
-         v3_copy( light->co, 
-                  world->ub_lighting.g_point_light_positions[i] );
-      }
-
-      /* upload full buffer */
-      glBindBuffer( GL_UNIFORM_BUFFER, world->ubo_lighting );
-      glBufferSubData( GL_UNIFORM_BUFFER, 0, 
-                       sizeof(struct ub_world_lighting), &world->ub_lighting );
    }
 
    vg_release_thread_sync();