Skip to content

Commit 00affed

Browse files
committed
Prepare model rendering.
1 parent b66fd0c commit 00affed

36 files changed

Lines changed: 2234 additions & 1813 deletions

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ Supported platforms: Windows (x64), Linux (x64 and ARM64).
66

77
# Roadmap
88

9-
- [X] Simple ECS
10-
- [ ] Config management (progress, settings, etc.)
11-
- [ ] Type reflection
129
- [ ] Forward renderer using OpenGL ES 2.0
10+
- [ ] Config management (settings, input, progress)
11+
- [ ] Type reflection
1312
- [ ] GLTF/GLB import
1413
- [ ] GUI
1514
- [ ] Audio

docs/Manual.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,51 @@
1+
# Manual
2+
3+
This is a manual - a step-by-step guide to introduce you to various aspects of the engine. This manual will not explain every piece of code, only some high-level entities and their usage, more specific documentation can be always found in the struct/function/variable documentation in the source code, every code entity is documented so you should not get lost.
4+
5+
# Project manager
6+
17
TODO
8+
9+
# Thread safety
10+
11+
The engine is single threaded and expects all functions to be executed in a single (main) thread. Only game resource loading (deserialization) is asynchronous (so you can show a loading screen while loading game resources).
12+
13+
# Memory leak checks
14+
15+
In debug builds the engine has memory leak checks enabled (thanks to CRT library on Windows and ASAN on Linux). Look for the output/debugger output tab of your IDE after running your project. If any leaks occurred it should print about them. You can test whether the memory leak checks are enabled or not by doing something like this:
16+
```C
17+
malloc(1);
18+
// not using `free`
19+
```
20+
run your program that has this code and after your program is finished you should see a message about the memory leak in the output/debugger output tab of your IDE.
21+
22+
# Naming
23+
24+
Engine types have the `te_` prefix (tiny engine). Functions have filename prefix so for example if you include `renderer.h` all of its functions will start with the `renderer_` prefix.
25+
26+
# Core objects
27+
28+
When the game is running the object ownership structure looks like this:
29+
30+
- `te_window` (i.e. game window) owns:
31+
- `te_game_manager` which manages core engine systems like:
32+
- `te_renderer`
33+
- `te_world` owns game entities, you can think of this as a game level
34+
- your game objects are here
35+
- etc.
36+
37+
This means that for example when you query `te_window` pointer in some of your game objects you should not free/destroy received pointer, that pointer will be valid during the whole lifetime of your game object.
38+
39+
# Managing pointers
40+
41+
When working with the engine you would often see the following approach: in order to create some engine object use `..._create()` function and later `..._destroy()` to destroy it. For example in order to create a camera (game object):
42+
43+
```C
44+
#include "game/camera.h"
45+
46+
te_camera* camera = camera_create();
47+
// later ...
48+
camera_destroy(camera);
49+
```
50+
51+
When the engine returns a pointer to you (like in the example above) often you need to make sure to free/destroy the pointer but in some cases you should not do that for example when the engine returns pointer to the game's window, in these cases the documentation for the function will specifically state that you should not free/destroy returned pointer so make sure to read the docs on the functions you are using.

res/engine/shader/model.frag.glsl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
varying vec3 frag_pos;
2+
varying vec3 frag_normal;
3+
varying vec2 frag_uv;
4+
5+
uniform vec4 color;
6+
7+
void main(void) {
8+
// Normals may be unnormalized after the rasterization (when they are interpolated).
9+
vec3 frag_normal_unit = normalize(frag_normal);
10+
11+
gl_FragColor = color;
12+
}

res/engine/shader/model.vert.glsl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
attribute vec3 pos;
2+
attribute vec3 normal;
3+
attribute vec2 uv;
4+
5+
varying vec3 frag_pos;
6+
varying vec3 frag_normal;
7+
varying vec2 frag_uv;
8+
9+
uniform mat4 view_proj_mat;
10+
uniform mat4 world_mat;
11+
uniform mat3 normal_mat;
12+
13+
void main(void) {
14+
vec4 world_pos = world_mat * vec4(pos, 1.0F);
15+
gl_Position = view_proj_mat * world_pos;
16+
17+
frag_pos = world_pos.xyz;
18+
frag_normal = normal_mat * normal;
19+
frag_uv = uv;
20+
}

src/engine_lib/CMakeLists.txt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,26 @@ set(PROJECT_SOURCES
1313
src/misc/globals.c
1414
src/misc/error.c
1515
src/game_manager.c
16-
src/renderer.c
1716
src/world.c
18-
src/ecs/ecs.c
19-
src/ecs/transform_component.c
20-
src/ecs/camera_component.c
21-
src/ecs/camera_system.c
17+
src/render/renderer.c
18+
src/render/model_renderer.h
19+
src/render/model_renderer.c
20+
src/render/shader_manager.c
21+
src/game/camera.c
22+
src/game/model.c
23+
include/math_funcs.h
2224
include/window.h
2325
include/io/log.h
2426
include/io/paths.h
2527
include/io/filesystem.h
2628
include/misc/globals.h
2729
include/misc/error.h
2830
include/game_manager.h
29-
include/renderer.h
31+
include/render/renderer.h
32+
include/render/shader_manager.h
3033
include/world.h
31-
include/ecs/ecs.h
32-
include/ecs/transform_component.h
33-
include/ecs/camera_component.h
34-
include/ecs/camera_system.h
34+
include/game/camera.h
35+
include/game/model.h
3536
)
3637

3738
# Define targets (one without any specific macros and another for compilation with editor).
@@ -47,6 +48,9 @@ add_library(${ENGINE_LIB_TARGET_FOR_EDITOR} STATIC ${PROJECT_SOURCES})
4748
tiny_engine_configure_target(${ENGINE_LIB_TARGET})
4849
tiny_engine_configure_target(${ENGINE_LIB_TARGET_FOR_EDITOR})
4950

51+
target_include_directories(${ENGINE_LIB_TARGET} PRIVATE src)
52+
target_include_directories(${ENGINE_LIB_TARGET_FOR_EDITOR} PRIVATE src)
53+
5054
# Define editor macros for editor's version of the engine_lib.
5155
target_compile_definitions(${ENGINE_LIB_TARGET_FOR_EDITOR} PUBLIC ENGINE_EDITOR)
5256

src/engine_lib/include/ecs/camera_component.h

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/engine_lib/include/ecs/camera_system.h

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)