Tramway SDK
render.h
Go to the documentation of this file.
1// Tramway Drifting and Dungeon Exploration Simulator SDK Runtime
2
3#ifndef TRAM_SDK_RENDER_H
4#define TRAM_SDK_RENDER_H
5
6#include <vector>
7
8#include <render/animation.h>
9
10struct IDirect3DVertexBuffer9;
11struct IDirect3DIndexBuffer9;
12struct IDirect3DTexture9;
13
14namespace tram::Render {
15
16typedef vec3 color_t;
17typedef uint32_t layer_t;
18
19typedef uint32_t vertexformat_t;
20typedef uint32_t materialtype_t;
21
22void Init();
23void Render();
24
25void Project(const vec3& point, vec3& result, layer_t layer = 0);
26vec3 ProjectInverse(vec3 point, layer_t layer = 0);
27
28void SetSunDirection(vec3 direction, layer_t layer = 0);
29void SetSunColor(color_t color, layer_t layer = 0);
30void SetAmbientColor(color_t color, layer_t layer = 0);
31
32void SetScreenSize(float width, float height);
33
34void SetOrthoRatio(float ratio, layer_t layer = 0);
35
36void SetViewFov(float fov, layer_t layer = 0);
37float GetViewFov(layer_t layer = 0);
38
39void SetViewDistance(float dist, layer_t layer = 0);
40float GetViewDistance(layer_t layer = 0);
41
42void SetViewPosition(vec3 position, layer_t layer = 0);
43void SetViewRotation(quat rotation, layer_t layer = 0);
44
47
48const color_t COLOR_WHITE (1.0f, 1.0f, 1.0f);
49const color_t COLOR_RED (1.0f, 0.0f, 0.0f);
50const color_t COLOR_GREEN (0.0f, 1.0f, 0.0f);
51const color_t COLOR_BLUE (0.0f, 0.0f, 1.0f);
52const color_t COLOR_YELLOW (1.0f, 1.0f, 0.0f);
53const color_t COLOR_PINK (1.0f, 0.0f, 1.0f);
54const color_t COLOR_CYAN (0.0f, 1.0f, 1.0f);
55const color_t COLOR_BLACK (0.0f, 0.0f, 0.0f);
56const color_t COLOR_GRAY (0.3f, 0.3f, 0.3f);
57
58void AddLine(vec3 from, vec3 to, color_t color);
59void AddLineMarker(vec3 location, color_t color);
60void AddLineAABB(vec3 min, vec3 max, vec3 center, quat rotation, vec3 color);
61void AddSphere(vec3 pos, float radius, color_t color);
62void AddCylinder(vec3 pos, float height, float radius, color_t color);
63void AddCube(vec3 pos, float height, float radius, color_t color);
64void AddText(vec3 pos, const char* text, color_t color = COLOR_WHITE);
65void AddText(float x, float y, const char* text, color_t color = COLOR_WHITE);
66
73};
74
84};
85
89};
90
91vertexformat_t RegisterVertexFormat(const char* name);
92materialtype_t RegisterMaterialType(const char* name);
93
94vertexformat_t FindVertexFormat(const char* name);
95materialtype_t FindMaterialType(const char* name);
96
97const char* GetVertexFormatName(vertexformat_t type);
98const char* GetMaterialTypeName(materialtype_t type);
99
100namespace API { struct SWVertexArray; }
101
103 union {
104 struct {
107 };
108 struct {
109 IDirect3DVertexBuffer9* d3d_vertex_buffer;
110 uint32_t d3d_metadata;
111 };
113 void* generic;
114 };
115};
116
117namespace API { struct SWIndexArray; }
118
120 union {
122 IDirect3DIndexBuffer9* d3d_index_buffer;
124 void* generic;
125 };
126};
127
129 union {
131 void* generic;
132 };
133
134 // TODO: add whatever you need for the D3D renderer
135 // TODO: also add everything for the SW renderer
136};
137
138namespace API { struct GLDrawListEntry; }
139namespace API { struct D3DDrawListEntry; }
140namespace API { struct SWDrawListEntry; }
141
143 union {
147 void* generic;
148 };
149};
150
151namespace API { struct SWTexture; }
152
154 union {
156 IDirect3DTexture9* d3d_texture_handle;
158 void* generic;
159 };
160};
161
162namespace API { struct GLLight; }
163namespace API { struct D3DLight; }
164namespace API { struct SWLight; }
165
166struct light_t {
167 union {
171 void* generic;
172 };
173};
174
175}
176
177#endif // TRAM_SDK_RENDER_H
High-level Render system API.
Definition: gui.h:8
const char * GetMaterialTypeName(materialtype_t type)
Finds an allocated material type's name.
Definition: render.cpp:515
float GetViewDistance(layer_t layer)
Definition: render.cpp:228
const color_t COLOR_BLACK(0.0f, 0.0f, 0.0f)
void SetViewFov(float fov, layer_t layer)
Definition: render.cpp:210
MaterialTypes
Definition: render.h:75
@ MATERIAL_LIGHTMAP
Definition: render.h:78
@ MATERIAL_TEXTURE_ALPHA
Definition: render.h:77
@ MATERIAL_LAST
Definition: render.h:83
@ MATERIAL_GLYPH
Definition: render.h:80
@ MATERIAL_FLAT_COLOR
Definition: render.h:82
@ MATERIAL_WATER
Definition: render.h:81
@ MATERIAL_MSDF
Definition: render.h:79
@ MATERIAL_TEXTURE
Definition: render.h:76
vec3 color_t
Definition: render.h:16
vertexformat_t FindVertexFormat(const char *name)
Finds an already allocated vertex format by its name.
Definition: render.cpp:490
const color_t COLOR_GRAY(0.3f, 0.3f, 0.3f)
const color_t COLOR_RED(1.0f, 0.0f, 0.0f)
void Init()
Initializes the rendering system.
Definition: render.cpp:105
const color_t COLOR_GREEN(0.0f, 1.0f, 0.0f)
uint32_t vertexformat_t
Definition: render.h:19
vertexformat_t RegisterVertexFormat(const char *name)
Allocates a new vertex format.
Definition: render.cpp:472
void AddCylinder(vec3 pos, float height, float radius, color_t color)
Draws a cylinder for a single frame.
Definition: render.cpp:325
const color_t COLOR_YELLOW(1.0f, 1.0f, 0.0f)
void SetSunDirection(color_t direction, layer_t layer)
Sets the sun direction.
Definition: render.cpp:178
VertexFormats
Definition: render.h:67
@ VERTEX_SPRITE
Definition: render.h:70
@ VERTEX_DYNAMIC
Definition: render.h:69
@ VERTEX_STATIC
Definition: render.h:68
@ VERTEX_LAST
Definition: render.h:72
@ VERTEX_LINE
Definition: render.h:71
void Render()
Renders a single frame.
Definition: render.cpp:152
quat GetViewRotation(layer_t layer)
Returns the view rotation for a given layer.
Definition: render.cpp:256
void Project(const vec3 &point, vec3 &result, layer_t layer)
Projects a point into screen coordinates.
Definition: render.cpp:433
void SetViewDistance(float dist, layer_t layer)
Definition: render.cpp:224
void AddCube(vec3 pos, float height, float radius, color_t color)
Draws a cube for a single frame.
Definition: render.cpp:331
void SetViewRotation(quat rotation, layer_t layer)
Sets the view rotation.
Definition: render.cpp:245
void SetViewPosition(vec3 position, layer_t layer)
Sets the view position.
Definition: render.cpp:237
materialtype_t RegisterMaterialType(const char *name)
Allocates a new material type.
Definition: render.cpp:481
void SetSunColor(color_t color, layer_t layer)
Sets the sun color.
Definition: render.cpp:186
float GetViewFov(layer_t layer)
Definition: render.cpp:215
uint32_t layer_t
Definition: render.h:17
materialtype_t FindMaterialType(const char *name)
Finds an already material type format by its name.
Definition: render.cpp:499
uint32_t materialtype_t
Definition: render.h:20
const color_t COLOR_CYAN(0.0f, 1.0f, 1.0f)
const color_t COLOR_PINK(1.0f, 0.0f, 1.0f)
void AddLineAABB(vec3 min, vec3 max, vec3 center, quat rotation, vec3 color)
Draws an AABB box for a single frame.
Definition: render.cpp:274
void SetOrthoRatio(float ratio, layer_t layer)
Definition: render.cpp:219
MaterialFilter
Definition: render.h:86
@ FILTER_NEAREST
Definition: render.h:87
@ FILTER_LINEAR
Definition: render.h:88
void AddLine(vec3 from, vec3 to, vec3 color)
Draws a line for a single frame.
Definition: render.cpp:261
void SetScreenSize(float width, float height)
Definition: render.cpp:199
const color_t COLOR_BLUE(0.0f, 0.0f, 1.0f)
const char * GetVertexFormatName(vertexformat_t type)
Finds an allocated vertex format's name.
Definition: render.cpp:508
const color_t COLOR_WHITE(1.0f, 1.0f, 1.0f)
void AddSphere(vec3 pos, float radius, color_t color)
Draws a sphere for a single frame.
Definition: render.cpp:315
void SetAmbientColor(color_t color, layer_t layer)
Sets the ambient color.
Definition: render.cpp:194
void AddText(vec3 pos, const char *text, color_t color)
Draws text, in 3D space, for a single frame.
Definition: render.cpp:336
vec3 GetViewPosition(layer_t layer)
Returns the view position for a given layer.
Definition: render.cpp:251
void AddLineMarker(vec3 location, vec3 color)
Draws a cross marker for a single frame.
Definition: render.cpp:267
vec3 ProjectInverse(vec3 point, layer_t layer)
Reverses screen coordinates into world coordinates.
Definition: render.cpp:442
glm::vec3 vec3
Definition: math.h:11
glm::quat quat
Definition: math.h:12
Definition: direct3d.h:10
Definition: direct3d.h:39
Definition: renderer.h:30
Definition: renderer.h:20
Definition: software.h:65
Definition: software.h:57
Definition: software.h:11
Definition: software.h:24
Definition: software.h:49
Definition: render.h:142
API::GLDrawListEntry * gl
Definition: render.h:144
API::SWDrawListEntry * sw
Definition: render.h:146
API::D3DDrawListEntry * d3d
Definition: render.h:145
Definition: render.h:119
IDirect3DIndexBuffer9 * d3d_index_buffer
Definition: render.h:122
API::SWIndexArray * sw_index_array
Definition: render.h:123
uint32_t gl_index_buffer
Definition: render.h:121
Definition: render.h:166
API::GLLight * gl
Definition: render.h:168
API::D3DLight * d3d
Definition: render.h:169
API::SWLight * sw
Definition: render.h:170
Definition: render.h:128
vertexarray_t vertex_array
Definition: render.h:130
Definition: render.h:153
uint32_t gl_texture_handle
Definition: render.h:155
IDirect3DTexture9 * d3d_texture_handle
Definition: render.h:156
API::SWTexture * sw_texture
Definition: render.h:157
Definition: render.h:102
API::SWVertexArray * sw_vertex_array
Definition: render.h:112
IDirect3DVertexBuffer9 * d3d_vertex_buffer
Definition: render.h:109
uint32_t gl_vertex_array
Definition: render.h:105
uint32_t gl_vertex_buffer
Definition: render.h:106
uint32_t d3d_metadata
Definition: render.h:110