vn/code/vn_render.h

121 lines
2.5 KiB
C
Raw Permalink Normal View History

2023-06-17 17:00:55 +00:00
/* date = April 26th 2023 11:04 pm */
#ifndef VN_RENDER_H
#define VN_RENDER_H
#define MAX_BOUND_TEXTURES 16
2023-07-19 15:09:41 +00:00
#define MAX_QUAD_COUNT 128*1024
2023-06-17 17:00:55 +00:00
2024-01-20 11:18:57 +00:00
#define ColorFromHex(Value) V4R32((((Value) >> 24) & 0xFF) / 255.0, (((Value) >> 16) & 0xFF) / 255.0, (((Value) >> 8) & 0xFF) / 255.0, (((Value) >> 0) & 0xFF) / 255.0)
2023-06-17 17:00:55 +00:00
2023-06-27 14:14:28 +00:00
#define Brighten(Color, Amount) (Color*(Amount))
#define Darken(Color, Amount) (Color*(1.0/(Amount)))
2024-01-20 11:18:57 +00:00
read_only v4_r32 Color_Black = V4R32(0, 0, 0, 1);
read_only v4_r32 Color_White = V4R32(1, 1, 1, 1);
read_only v4_r32 Color_Grey = V4R32(0.5, 0.5, 0.5, 1);
read_only v4_r32 Color_Red = V4R32(1, 0, 0, 1);
read_only v4_r32 Color_Green = V4R32(0, 1, 0, 1);
read_only v4_r32 Color_Blue = V4R32(0, 0, 1, 1);
read_only v4_r32 Color_Yellow = V4R32(1, 1, 0, 1);
read_only v4_r32 Color_Magenta = V4R32(1, 0, 1, 1);
read_only v4_r32 Color_Cyan = V4R32(0, 1, 1, 1);
2023-06-17 17:00:55 +00:00
2024-01-20 11:18:57 +00:00
#define SetAlpha(Color, Value) V4R32(Color.x, Color.y, Color.z, Value)
2023-07-19 15:09:41 +00:00
2023-06-17 17:00:55 +00:00
enum render_texture_format
{
2023-07-19 15:09:41 +00:00
Render_TextureFormat_Invalid,
2023-06-17 17:00:55 +00:00
Render_TextureFormat_R8,
Render_TextureFormat_RGB8,
Render_TextureFormat_RGBA8,
};
struct render_handle
{
union
{
u64 U64[4];
u32 U32[8];
};
};
enum render_command_type
{
Render_Command_render_command_clear,
Render_Command_render_command_quads,
2023-08-22 03:19:51 +00:00
Render_Command_render_command_instanced_quads,
2023-06-17 17:00:55 +00:00
Render_Command_render_command_clip,
};
struct render_command_clear
{
2024-01-20 11:18:57 +00:00
v3_r32 Color;
2023-06-17 17:00:55 +00:00
};
2023-08-22 03:19:51 +00:00
struct render_texture_mapping
{
s32 TexturesUsed;
render_handle Textures[16];
};
2023-06-17 17:00:55 +00:00
struct render_command_quads
{
2023-08-22 03:19:51 +00:00
render_texture_mapping Mapping;
u64 QuadCount;
u64 QuadBufferIndex;
};
struct render_command_instanced_quads
{
render_texture_mapping Mapping;
2023-06-17 17:00:55 +00:00
u64 QuadCount;
u64 QuadBufferIndex;
};
struct render_command_clip
{
range2_r32 ClipRect;
};
struct render_command_header
{
render_command_type Type;
};
struct render_group
{
struct vn_render_commands *Commands;
render_command_header *CurrentCommand;
range2_r32 ClipStack[64];
s32 ClipStackUsed;
};
2023-07-19 15:09:41 +00:00
struct instanced_quad
{
range2_r32 Dest;
range2_r32 Source;
u32 TextureIndex;
2023-08-22 03:19:51 +00:00
u32 Color[4];
2024-01-20 11:18:57 +00:00
r32 CornerRadius[4];
2023-07-19 15:09:41 +00:00
r32 EdgeSoftness;
r32 BorderThickness;
};
2023-06-17 17:00:55 +00:00
struct quad_vertex
{
2024-01-20 11:18:57 +00:00
v2_r32 P;
v2_r32 SourceP;
2023-06-17 17:00:55 +00:00
u32 TextureIndex;
u32 Color;
2024-01-20 11:18:57 +00:00
v2_r32 ToCenter; // sixten: ToCenter = Center - P
v2_r32 HalfSize;
2023-06-17 17:00:55 +00:00
r32 CornerRadius;
r32 EdgeSoftness;
r32 BorderThickness;
};
#endif //VN_RENDER_H