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