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