OO architecture for rendering in shader based games

前端 未结 2 562
难免孤独
难免孤独 2021-02-05 18:57

I keep hitting this problem when building game engines where my classes want to look like this:

interface Entity {
  draw();
}

class World {
  draw() {
    for          


        
2条回答
  •  情深已故
    2021-02-05 19:21

    Use a two stages approach: First loop through all entities, but instead of drawing let them insert references to themself into a (the) drawing batch list. Then sort the list by OpenGL state and shader use; after sorting insert state changer objects at every state transistion.

    Finally iterate through the list executing the drawing routine of each object referenced in the list.

提交回复
热议问题