Merge: gamnit: new services and a lot of bug fixes and performance improvements
[nit.git] / lib / gamnit / depth / depth.nit
index 1fe507a..a7864f9 100644 (file)
@@ -21,22 +21,28 @@ import more_models
 import model_dimensions
 import particles
 import selection
+import shadow
 
 redef class App
 
-       redef fun on_create
+       redef fun create_scene
        do
-               super
-
                # Move the camera back a bit
                world_camera.reset_height(10.0)
                world_camera.near = 0.1
 
+               super
+       end
+
+       redef fun create_gamnit
+       do
+               super
+
                # Cull the invisible triangles in the back of the geometries
                glCullFace gl_BACK
 
                # Prepare programs
-               var programs = [versatile_program, normals_program, explosion_program, smoke_program, static_program, selection_program: GamnitProgram]
+               var programs = [blinn_phong_program, normals_program, explosion_program, smoke_program, static_program, selection_program: GamnitProgram]
                for program in programs do
                        program.compile_and_link
                        var gamnit_error = program.error
@@ -49,13 +55,22 @@ redef class App
        # Draw all elements of `actors` and then call `frame_core_flat`
        protected fun frame_core_depth(display: GamnitDisplay)
        do
+               frame_core_depth_clock.lapse
+
+               # Compute shadows
+               if light isa LightCastingShadows then
+                       frame_core_shadow_prep display
+                       perfs["gamnit depth shadows"].add frame_core_depth_clock.lapse
+               end
+
                glViewport(0, 0, display.width, display.height)
                frame_core_dynamic_resolution_before display
+               perfs["gamnit depth dynres"].add frame_core_depth_clock.lapse
 
-               frame_core_depth_clock.lapse
                for actor in actors do
                        for leaf in actor.model.leaves do
                                leaf.material.draw(actor, leaf, app.world_camera)
+                               assert glGetError == gl_NO_ERROR else print_error "Gamnit error on material {leaf.material.class_name}"
                        end
                end
                perfs["gamnit depth actors"].add frame_core_depth_clock.lapse
@@ -65,14 +80,21 @@ redef class App
 
                # Toggle writing to the depth buffer for particles effects
                glDepthMask false
-               for system in particle_systems do system.draw
+               for system in particle_systems do
+                       system.draw
+                       assert glGetError == gl_NO_ERROR else print_error "OpenGL error in {system}"
+               end
                glDepthMask true
                perfs["gamnit depth particles"].add frame_core_depth_clock.lapse
 
+               # Stop using the dynamic resolution before drawing UI sprites
+               frame_core_dynamic_resolution_after display
+
                frame_core_ui_sprites display
                perfs["gamnit depth ui_sprites"].add frame_core_depth_clock.lapse
 
-               frame_core_dynamic_resolution_after display
+               # Debug, show the light point of view
+               #frame_core_shadow_debug display
        end
 
        private var frame_core_depth_clock = new Clock