                     # this means it's the probe cube texture
                     tex = mesh.probe?.cubemap or @blank_cube_texture
                     tex_input.value = tex
+                    tex.last_used_material = mat
                 else
                     tex = tex_input.value
                 if tex.bound_unit == -1

        @background_alpha = if ba? then ba else 1
        @compiled_shaders_this_frame = 0
        @use_frustum_culling = true
        # TODO: workaround until we properly manage reused textures
        @unbind_textures_on_draw_mesh = false
        @unbind_textures_on_draw_viewport = true
        @probes = []


        return

    # @nodoc
    debug_break_on_any_gl_error: ->
        gl = @gl
        for k,v of gl when typeof v == 'function' and k != 'getError'
            gl['_'+k] = gl[k]
            gl[k] = do (k, gl) => (args...)->
                r = gl["_"+k](args...)
                if error = gl.getError()
                    debugger
                return r
        return


    # @nodoc
    # This method allows to compare performance between few objects
    # and many object with similar total poly count.
    polycount_debug: (ratio=1)->
