diff options
-rw-r--r-- | gfx/README.md | 133 | ||||
-rw-r--r-- | gfx/include/gfx/README.md | 3 | ||||
-rw-r--r-- | gfx/include/gfx/scene/README.md | 75 | ||||
-rw-r--r-- | gfx/include/gfx/util/README.md | 3 |
4 files changed, 103 insertions, 111 deletions
diff --git a/gfx/README.md b/gfx/README.md index 97c6ce9..f0b103d 100644 --- a/gfx/README.md +++ b/gfx/README.md | |||
@@ -5,13 +5,13 @@ educational purposes. | |||
5 | 5 | ||
6 | ## Guiding Principles | 6 | ## Guiding Principles |
7 | 7 | ||
8 | - Provide a minimal set of functionality necessary for indie games and graphics | 8 | - Provide enough functionality for graphics applications and indie games. |
9 | applications. | 9 | - Provide a minimal interface, physically hide the implementation. Make bindings |
10 | - Provide a minimal interface; physically hide the implementation. | 10 | easy. |
11 | - Allow for additional future rendering backends (e.g. Vulkan). | 11 | - Establish a clean separation from the render backend and the rest of the |
12 | - Strive for a minimal set of dependencies. | 12 | library to allow for additional rendering backends (e.g. Vulkan). |
13 | - All dependencies but system libraries should be compiled with the graphics | 13 | - Strive for a minimal set of dependencies, all of which should ship and compile |
14 | library for portability and ease of use. | 14 | with the graphics library for ease of use. |
15 | - Rely on dynamic allocation as little as possible. Isolate dynamic allocation | 15 | - Rely on dynamic allocation as little as possible. Isolate dynamic allocation |
16 | to where it is strictly needed. | 16 | to where it is strictly needed. |
17 | 17 | ||
@@ -19,37 +19,105 @@ educational purposes. | |||
19 | 19 | ||
20 | ### Gfx | 20 | ### Gfx |
21 | 21 | ||
22 | The `Gfx` object represents the graphics subsystem and provides a high-level API | 22 | The `Gfx` object represents the graphics subsystem and is at the center of the |
23 | to render graphics. The `Gfx` object exposes a `Render` backend and a `Renderer` | 23 | library's high-level API. The `Gfx` object exposes a `Render` backend and a |
24 | , and allows the caller to create `Scene` objects. | 24 | `Renderer` and allows the caller to create `Scene`s. |
25 | 25 | ||
26 | ### Render Backend | 26 | ### Render Backend |
27 | 27 | ||
28 | The `Render Backend` is a thin abstraction layer over low-level graphics APIs | 28 | The `Render` backend is a thin abstraction layer over low-level graphics APIs |
29 | (OpenGL, etc). It presents an immediate mode style of rendering, whereby callers | 29 | like OpenGL or Vulkan. It holds GPU resources such as geometry, textures, |
30 | directly submit draw commands to the `Render Backend`. | 30 | shaders, etc, and exposes functions to manipulate them. |
31 | 31 | ||
32 | The `Render Backend` holds GPU resources such as geometry, textures, shaders, | 32 | Currently there is only one implementation of the `Render` backend based on |
33 | etc. | 33 | OpenGL. |
34 | |||
35 | Currently there is only one implementation of the `Render Backend` based on | ||
36 | OpenGL for simplicity and portability. | ||
37 | 34 | ||
38 | #### Ownership | 35 | #### Ownership |
39 | 36 | ||
40 | The `Render Backend` owns all rendering resources: buffers, geometries, | 37 | The `Render` backend owns all rendering resources: buffers, geometries, |
41 | textures, shaders, etc. Even resources that point to other resources do not own | 38 | textures, shaders, etc. Even resources that point to other resources do not own |
42 | those other resources (geometries and buffers). | 39 | those other resources (geometries pointing to buffers). |
43 | 40 | ||
44 | There is no sophisticated resource sharing on the renderer side, like reference | 41 | There is no ownership tracking in the render backend. It is up to the client to |
45 | counting or resource naming. Instead, it is up to the user to make appropriate | 42 | manage resource lifetime. |
46 | use of allocated resources and share them where appropriate. | ||
47 | 43 | ||
48 | ### Scene | 44 | ### Scene |
49 | 45 | ||
50 | A `Scene` is the top-level object of a scene graph. A scene graph is a | 46 | A `Scene` encapsulates a scene graph. A scene graph contains the elements that |
51 | description of the scene and holds all of the elements that make up a scene: | 47 | make up a scene: nodes, cameras, lights, objects, etc. The current scene graph |
52 | nodes, cameras, lights, objects, etc. | 48 | implementation includes: |
49 | |||
50 | - Camera | ||
51 | - Light | ||
52 | - Material | ||
53 | - Mesh | ||
54 | - Node | ||
55 | - Object | ||
56 | - Scene | ||
57 | |||
58 | #### Hierarchy and Parenting | ||
59 | |||
60 | Scene graphs typically expose functions on nodes to add/remove objects, cameras, | ||
61 | lights, etc. This implementation forces the hierarchy to be a strict tree and | ||
62 | not a more general DAG. Given this, and to avoid confusion, we instead expose | ||
63 | functions to set the parent node of an object/camera/light. If we exposed the | ||
64 | former, the API could create the illusion that the hierarchy can be a DAG. | ||
65 | |||
66 | The strict tree hierarchy should not be that restrictive in practice. Even the | ||
67 | glTF 2.0 spec [enforces this](https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#nodes-and-hierarchy): | ||
68 | |||
69 | > *For Version 2.0 conformance, the glTF node hierarchy is not a directed | ||
70 | > acyclic graph (DAG) or scene graph, but a disjoint union of strict trees. That | ||
71 | > is, no node may be a direct descendant of more than one node. This restriction | ||
72 | > is meant to simplify implementation and facilitate conformance.* | ||
73 | |||
74 | #### Instancing | ||
75 | |||
76 | Two use cases for instancing seem to be: | ||
77 | |||
78 | 1. Creating N identical clones, but each with a unique transform. (Ex: N | ||
79 | animated characters animated in unison but located in different locations.) | ||
80 | 2. Creating N copies of a sub-tree, each now being their own unique tree. (Ex: | ||
81 | The same N animated characters, but each of them now being animated separately.) | ||
82 | |||
83 | Some scene graphs | ||
84 | ([Panda3D](https://docs.panda3d.org/1.10/python/programming/scene-graph/instancing)) | ||
85 | allow two or more nodes to point to the same child, or, in other words, a node | ||
86 | to have multiple parents. This turns the scene graph into a DAG and adds a | ||
87 | number of complications for us: | ||
88 | |||
89 | 1. Shared ownership of children. We would now need some sort of ref counting or | ||
90 | deferred GC to delete nodes and their subtrees. | ||
91 | 2. Nodes no longer have a unique parent. | ||
92 | 3. Given a node, we can no longer determine its location (which parent link do | ||
93 | you follow?), or any attribute that is derived from its parent(s). | ||
94 | |||
95 | In our case, we stick to strict tree hierarchies. | ||
96 | |||
97 | Use case (1), N identical clones with unique transforms, is not a problem for | ||
98 | us. This is because the bulk of the data -- geometry buffers, etc. -- is stored | ||
99 | in the render backend anyway. So creating a full copy of the node does not | ||
100 | present a significant overhead since we need a unique transform for each of the | ||
101 | clones anyway. | ||
102 | |||
103 | Use case (2) does present a bit more overhead and we currently do not handle it. | ||
104 | This could be handled in the future by special-casing a node such as | ||
105 | `InstanceNode` that has one child subtree and N transforms (or other | ||
106 | attributes), one for each unique instance of that child subtree. | ||
107 | |||
108 | Therefore, to visit the use cases again: | ||
109 | |||
110 | 1. N character clones animated in unison in different locations -> future | ||
111 | `InstanceNode`. | ||
112 | 2. N unique character copies animated on their own -> copy the character subtree | ||
113 | (N unique skeletons; shared mesh data and textures stored in the render | ||
114 | backend.) | ||
115 | |||
116 | #### Reading | ||
117 | |||
118 | [Panda3D Scene Graph](https://docs.panda3d.org/1.10/python/programming/scene-graph/index) | ||
119 | |||
120 | [Pixar's USD](https://graphics.pixar.com/usd/release/intro.html) | ||
53 | 121 | ||
54 | ### Renderer | 122 | ### Renderer |
55 | 123 | ||
@@ -57,10 +125,15 @@ The `Renderer` takes a `Render` backend and a `Scene` and renders the scene. | |||
57 | Currently, only a forward renderer is provided, but additional renderers can be | 125 | Currently, only a forward renderer is provided, but additional renderers can be |
58 | implemented in the future. | 126 | implemented in the future. |
59 | 127 | ||
60 | ## Future Work | 128 | ### Util |
129 | |||
130 | Code under `util/` provides functionality that need not be in the core part | ||
131 | of the library (Gfx, render backend, scene or renderer). This includes functions | ||
132 | to compute irradiance maps, create procedural geometry, etc. | ||
133 | |||
134 | ## Ideas for Future Work | ||
61 | 135 | ||
62 | - Ideally, some way to customize the rendering pipeline to allow for custom | 136 | - Render graphs to allow for custom multi-pass rendering algorithms. |
63 | multi-pass rendering algorithms. | ||
64 | 137 | ||
65 | ## Build (Ubuntu) | 138 | ## Build (Ubuntu) |
66 | 139 | ||
@@ -68,4 +141,4 @@ implemented in the future. | |||
68 | sudo apt install libbsd-dev libgl-dev libglfw3-dev zlib1g-dev | 141 | sudo apt install libbsd-dev libgl-dev libglfw3-dev zlib1g-dev |
69 | ``` | 142 | ``` |
70 | 143 | ||
71 | TODO: Add GLFW and zlib to `contrib/`. | 144 | TODO: Add these libraries to `contrib/`. |
diff --git a/gfx/include/gfx/README.md b/gfx/include/gfx/README.md deleted file mode 100644 index 81f6759..0000000 --- a/gfx/include/gfx/README.md +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | # GFX / include | ||
2 | |||
3 | Public API of the graphics library. | ||
diff --git a/gfx/include/gfx/scene/README.md b/gfx/include/gfx/scene/README.md deleted file mode 100644 index c8cdadb..0000000 --- a/gfx/include/gfx/scene/README.md +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
1 | # Scene Graph | ||
2 | |||
3 | A scene graph implementation that includes: | ||
4 | |||
5 | - Camera | ||
6 | - Light | ||
7 | - Material | ||
8 | - Mesh | ||
9 | - Node | ||
10 | - Object | ||
11 | - Scene | ||
12 | |||
13 | ## Hierarchy and Parenting | ||
14 | |||
15 | Scene graphs typically expose functions on nodes to add/remove objects, cameras, | ||
16 | lights, etc. This implementation forces the hierarchy to be a strict tree and | ||
17 | not a more general DAG. Given this, and to avoid confusion, we instead expose | ||
18 | functions to set the parent node of an object/camera/light. If we exposed the | ||
19 | former, the API could create the illusion that the hierarchy can be a DAG. | ||
20 | |||
21 | The strict tree hierarchy should not be that restrictive in practice. Even the | ||
22 | glTF 2.0 spec [enforces this](https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#nodes-and-hierarchy): | ||
23 | |||
24 | > *For Version 2.0 conformance, the glTF node hierarchy is not a directed | ||
25 | > acyclic graph (DAG) or scene graph, but a disjoint union of strict trees. That | ||
26 | > is, no node may be a direct descendant of more than one node. This restriction | ||
27 | > is meant to simplify implementation and facilitate conformance.* | ||
28 | |||
29 | ## Instancing | ||
30 | |||
31 | Two use cases for instancing seem to be: | ||
32 | |||
33 | 1. Creating N identical clones, but each with a unique transform. (Ex: N | ||
34 | animated characters animated in unison but located in different locations.) | ||
35 | 2. Creating N copies of a sub-tree, each now being their own unique tree. (Ex: | ||
36 | The same N animated characters, but each of them now being animated separately.) | ||
37 | |||
38 | Some scene graphs | ||
39 | ([Panda3D](https://docs.panda3d.org/1.10/python/programming/scene-graph/instancing)) | ||
40 | allow two or more nodes to point to the same child, or, in other words, a node | ||
41 | to have multiple parents. This turns the scene graph into a DAG and adds a | ||
42 | number of complications for us: | ||
43 | |||
44 | 1. Shared ownership of children. We would now need some sort of ref counting or | ||
45 | deferred GC to delete nodes and their subtrees. | ||
46 | 2. Nodes no longer have a unique parent. | ||
47 | 3. Given a node, we can no longer determine its location (which parent link do | ||
48 | you follow?), or any attribute that is derived from its parent(s). | ||
49 | |||
50 | In our case, we stick to strict tree hierarchies. | ||
51 | |||
52 | Use case (1), N identical clones with unique transforms, is not a problem for | ||
53 | us. This is because the bulk of the data -- geometry buffers, etc. -- is stored | ||
54 | in the render backend anyway. So creating a full copy of the node does not | ||
55 | present a significant overhead since we need a unique transform for each of the | ||
56 | clones anyway. | ||
57 | |||
58 | Use case (2) does present a bit more overhead and we currently do not handle it. | ||
59 | This could be handled in the future by special-casing a node such as | ||
60 | `InstanceNode` that has one child subtree and N transforms (or other | ||
61 | attributes), one for each unique instance of that child subtree. | ||
62 | |||
63 | Therefore, to visit the use cases again: | ||
64 | |||
65 | 1. N character clones animated in unison in different locations -> future | ||
66 | `InstanceNode`. | ||
67 | 2. N unique character copies animated on their own -> copy the character subtree | ||
68 | (N unique skeletons; shared mesh data and textures stored in the render | ||
69 | backend.) | ||
70 | |||
71 | ## Reading | ||
72 | |||
73 | [Panda3D Scene Graph](https://docs.panda3d.org/1.10/python/programming/scene-graph/index) | ||
74 | |||
75 | [Pixar's USD](https://graphics.pixar.com/usd/release/intro.html) | ||
diff --git a/gfx/include/gfx/util/README.md b/gfx/include/gfx/util/README.md deleted file mode 100644 index 642cf24..0000000 --- a/gfx/include/gfx/util/README.md +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | # GFX / util | ||
2 | |||
3 | Various utilities on top of the core graphics library. | ||