They are on a mountain. Jesus has come to pray. He has brought Peter and John and James with him.
[I had intended to, but didn't get around to, doing a search on mountain experiences in the Old Testament and Jesus' praying in the New, and which events in Jesus' life included the presence of those three particular disciples.]
While he is praying, his appearance changes and his clothes become dazzling white. Moses and Elijah become present.
The disciples although they were weighed down by sleep have stayed awake and witness this.
Ronald Allen & Williamson write in their Preaching the Gospels without Blaming the Jews:
Jewish apocalyptic writers anticipated that in the final manifestation of the reign of God, persons would have transformed bodies in the luminescent white of the heavenly world (e.g., Daniel 10:6; 1 Enoch 62:15-16; 2Enoch 22:8; Luke 24:4; Acts 1:10; 1 Corinthians 15:35-49; Revelation 4:4; 7:9).
Moses and Elijah are talking to Jesus about his departure. Allen & Williamson point out that the Greek word for departure is exodos emphasizing that what is going to happen at Jerusalem will also be a way of liberating God's people.