Tramway SDK
renderer.h
Go to the documentation of this file.
1// Tramway Drifting and Dungeon Exploration Simulator SDK Runtime
2
3#ifndef TRAM_SDK_RENDER_OPENGL_RENDERER_H
4#define TRAM_SDK_RENDER_OPENGL_RENDERER_H
5
6#include <render/render.h>
7#include <render/renderer.h>
8
9namespace tram::Render::API {
10
11void CompileShaders();
12
13uint32_t FindShader(vertexformat_t format, materialtype_t type);
14void RegisterShader(vertexformat_t format, materialtype_t type, const char* vertex_shader, const char* fragment_shader);
15
16void BindUniformBlock (const char* name, uint32_t binding);
17
18
19
20struct GLLight {
21 vec3 location = {0.0f, 0.0f, 0.0f};
22 float padding;
23 vec3 color = {0.0f, 0.0f, 0.0f};
24 float distance = 0.0f;
25 vec3 direction = {0.0f, 0.0f, -1.0f};
26 float exponent = 0.0f;
27 float padding2[4];
28};
29
31 uint32_t flags = 0;
32
33 Pose* pose = nullptr;
34
35 mat4 matrix = mat4(1.0f);
36
37 uint32_t lights[4] = {0};
38
39 uint32_t layer = 0;
40 uint32_t lightmap = 0;
41 uint32_t vao = 0;
42 uint32_t eboLen = 0; // in primitive count
43 uint32_t eboOff = 0; // in primitive count
44 uint32_t shader = 0;
45 uint32_t texCount = 0;
46 uint32_t textures[15] = {0};
52
53 vec3 aabb_min = {0.0f, 0.0f, 0.0f};
54 vec3 aabb_max = {0.0f, 0.0f, 0.0f};
55
56 float fade_near = 0.0f;
57 float fade_far = INFINITY;
58
60 for (int i = 0; i < 15; i++) {
61 textures[i] = 0;
62 colors[i] = {1.0f, 1.0f, 1.0f, 1.0f};
63 specular_weights[i] = 0.0f;
64 specular_exponents[i] = 1.0f;
66 texture_transforms[i] = {0.0f, 0.0f, 0.0f, 0.0f};
67 }
68 }
69
71 uint64_t CalcSortKey (const vec3& cameraPosition) {
72 vec3 location = matrix * vec4(0.0f, 0.0f, 0.0f, 1.0f);
73 uint64_t sortkey = 0;
74 sortkey = flags & FLAG_TRANSPARENT ? 1 : 0;
75 sortkey = sortkey << 60;
76 sortkey = sortkey | (((uint64_t)layer) << 61); // 3 bits for the layer number
77 sortkey = sortkey | (((uint64_t)shader) << 48); // 12 bits for the shader
78 sortkey = sortkey | (((uint64_t)vao) << 32); // 16 bits or the vertex array number
79 // TODO: reverse the distance if FLAG_REVERSE_SORT is set
80 // also i think that the bitmask for the distance thing is incorrect
81 sortkey = sortkey | (((uint64_t)(glm::distance(cameraPosition, location) * 3000000.0f)) & 0x00000000FFFFFFFF); // 32 bits for the distance
82 return sortkey;
83 }
84};
85
86}
87
88#endif // TRAM_SDK_RENDER_OPENGL_RENDERER_H
Rendering backend API.
void CompileShaders()
Definition: shader.cpp:263
void BindUniformBlock(const char *name, uint32_t binding)
Definition: shader.cpp:205
void RegisterShader(vertexformat_t format, materialtype_t type, const char *vertex_shader, const char *fragment_shader)
Definition: shader.cpp:221
uint32_t FindShader(vertexformat_t format, materialtype_t type)
Definition: shader.cpp:249
uint32_t vertexformat_t
Definition: render.h:19
uint32_t materialtype_t
Definition: render.h:20
@ FLAG_TRANSPARENT
Definition: renderer.h:17
glm::vec4 vec4
Definition: math.h:15
glm::vec3 vec3
Definition: math.h:11
glm::mat4 mat4
Definition: math.h:14
Definition: renderer.h:30
uint32_t texCount
Definition: renderer.h:45
vec3 aabb_min
Definition: renderer.h:53
uint32_t eboLen
Definition: renderer.h:42
uint64_t CalcSortKey(const vec3 &cameraPosition)
Assembles a key for sorting.
Definition: renderer.h:71
uint32_t lights[4]
Definition: renderer.h:37
uint32_t flags
Definition: renderer.h:31
vec3 aabb_max
Definition: renderer.h:54
mat4 matrix
Definition: renderer.h:35
uint32_t lightmap
Definition: renderer.h:40
vec4 texture_transforms[15]
Definition: renderer.h:51
float specular_exponents[15]
Definition: renderer.h:49
float fade_near
Definition: renderer.h:56
uint32_t eboOff
Definition: renderer.h:43
uint32_t layer
Definition: renderer.h:39
uint32_t textures[15]
Definition: renderer.h:46
vec4 colors[15]
Definition: renderer.h:47
uint32_t vao
Definition: renderer.h:41
Pose * pose
Definition: renderer.h:33
float specular_transparencies[15]
Definition: renderer.h:50
uint32_t shader
Definition: renderer.h:44
float fade_far
Definition: renderer.h:57
float specular_weights[15]
Definition: renderer.h:48
GLDrawListEntry()
Definition: renderer.h:59
Definition: renderer.h:20
float exponent
Definition: renderer.h:26
vec3 direction
Definition: renderer.h:25
float padding
Definition: renderer.h:22
vec3 color
Definition: renderer.h:23
float distance
Definition: renderer.h:24
vec3 location
Definition: renderer.h:21
float padding2[4]
Definition: renderer.h:27
Definition: animation.h:35