summaryrefslogtreecommitdiff
path: root/dwm/grender.h
blob: bd65fba679cd4512be070dc4773985249462fb85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#pragma once

#include "../src/color.h"

#include <windows.h>
#include <d3d11.h>
#include <DirectXMath.h>

#include <freetype/freetype.h>
#include FT_FREETYPE_H

#ifdef _WIN64
#pragma comment(lib, "freetype64.lib")
#else
#pragma comment(lib, "freetype32.lib")
#endif

enum rounded_rect_corners {
  e_top_left = 0b0001,
  e_top_right = 0b0010,
  e_bottom_left = 0b0100,
  e_bottom_right = 0b1000,
};

struct DXVEC2 {
  F32 x, y;
};

using DXMAT4X4 = float[4][4];

struct D3D11_VERTEX {
  F32 x, y;
  DXVEC2 uv;
  FCLR col;
};

struct D3D11_TEXTURE {
  ID3D11Texture2D* tex2d;
  ID3D11ShaderResourceView* srv;
  I32 w, h;
  UINT8* rgba;
};

struct FONT_GLYPH {
  F32 offset_x;
  F32 offset_y;
  F32 width;
  F32 height;
  F32 advance_x;
  F32 advance_y;
  F32 bearing_x;
};

struct D3D11_FONT {
  struct D3D11_RENDERDATA* d3d11;
  U32 size;
  FT_Face face;

  const char* name;
  UINT8* font_data;
  U32 font_data_size;
  
  D3D11_TEXTURE* atlas;
  
  U32* bitmap;
  U32 bitmap_width;
  U32 bitmap_height;
  U32 char_width;
  U32 char_height;
  U32 blank_spacing;
  
  // YEAH BABY
  FONT_GLYPH* glyphs[0xFFFF];
};

struct D3D11_RENDERDATA {
  ID3D11Device* device;
  ID3D11DeviceContext* context;
  IDXGISwapChain* swapchain;
  
  ID3D11RenderTargetView* render_target_view;
  ID3D11InputLayout* input_layout;
  ID3D11BlendState* blend_state;
  ID3D11RasterizerState* rasterizer_state;
  ID3D11DepthStencilState* depth_stencil_state;
  
  ID3D11VertexShader* vertex_shader;
  ID3D11PixelShader* pixel_shader;
  ID3D11PixelShader* pixel_shader_textured;
  ID3DBlob* vs_blob;
  ID3DBlob* ps_blob;
  ID3DBlob* ps_blob_textured;
  
  ID3D11Texture2D* back_buffer;
  ID3D11Buffer* vertex_buffer;
  ID3D11Buffer* constant_buffer;

  F32 display[2];

  RECT clip;
  
  std::vector<D3D11_TEXTURE*> textures;
  std::vector<D3D11_FONT*> fonts;
};



extern D3D11_RENDERDATA* d3d11_init();
extern void d3d11_on_present( D3D11_RENDERDATA* data, void* swapchain );
extern void d3d11_on_swapchain_lost( D3D11_RENDERDATA* data );

extern bool d3d11_init_shaders( D3D11_RENDERDATA* data );
extern bool d3d11_init_resources( D3D11_RENDERDATA* data );
extern void d3d11_destroy_resources( D3D11_RENDERDATA* data );

extern D3D11_TEXTURE* d3d11_texture_create( D3D11_RENDERDATA* data, UINT8* rgba, I32 width, I32 height );
extern void d3d11_texture_init( D3D11_RENDERDATA* data, D3D11_TEXTURE* tex );
extern void d3d11_texture_destroy( D3D11_RENDERDATA* data, D3D11_TEXTURE* tex );

extern void d3d11_set_clip( D3D11_RENDERDATA* data, RECT* clip );
extern void d3d11_get_clip( D3D11_RENDERDATA* data, RECT* clip );

extern void d3d11_line( D3D11_RENDERDATA* data, DXVEC2 pos, DXVEC2 pos2, FCLR col );
extern void d3d11_rect( D3D11_RENDERDATA* data, DXVEC2 pos, DXVEC2 size, FCLR col );
extern void d3d11_frect( D3D11_RENDERDATA* data, DXVEC2 pos, DXVEC2 size, FCLR col );
extern void d3d11_textured_frect( D3D11_RENDERDATA* data, DXVEC2 pos, DXVEC2 size, D3D11_TEXTURE* texture, FCLR col );
extern void d3d11_gradient_frect( D3D11_RENDERDATA* data, DXVEC2 pos, DXVEC2 size, FCLR tl, FCLR tr, FCLR bl, FCLR br );
extern void d3d11_circle( D3D11_RENDERDATA* data, DXVEC2 pos, F32 radius, FCLR col, I32 res = 48 );
extern void d3d11_fcircle( D3D11_RENDERDATA* data, DXVEC2 pos, F32 radius, FCLR col, I32 res = 48 );
extern void d3d11_thick_circle( D3D11_RENDERDATA* data, DXVEC2 pos, F32 radius_in, F32 radius_out, FCLR col, I32 res = 48 );
extern void d3d11_arc( D3D11_RENDERDATA* data, DXVEC2 pos, F32 radius, F32 start_angle, F32 end_angle, FCLR col, I32 res = 48 );
extern void d3d11_farc( D3D11_RENDERDATA* data, DXVEC2 pos, F32 radius, F32 start_angle, F32 end_angle, FCLR col, I32 res = 48 );
extern void d3d11_farc_2clr( D3D11_RENDERDATA* data, DXVEC2 pos, F32 radius, F32 start_angle, F32 end_angle, FCLR col1, FCLR col2, I32 res = 24 );
extern void d3d11_rounded_rect( D3D11_RENDERDATA* data, DXVEC2 pos, DXVEC2 size, F32 radius, FCLR col, I32 flags );

extern D3D11_FONT* d3d11_font_create(
  D3D11_RENDERDATA* data,
  const char* font_name,
  U32 font_size,
  UINT8* font_data = 0,
  U32 font_data_size = 0
);
extern void d3d11_font_init( D3D11_FONT* font );
extern void d3d11_font_destroy( D3D11_FONT* font );
extern void d3d11_font_drawA( D3D11_FONT* font, DXVEC2 pos, const char* text, FCLR col );
extern void d3d11_font_drawW( D3D11_FONT* font, DXVEC2 pos, const wchar_t* text, FCLR col );
extern void d3d11_font_get_extentA( D3D11_FONT* font, const char* text, DXVEC2* extent );
extern void d3d11_font_get_extentW( D3D11_FONT* font, const wchar_t* text, DXVEC2* extent );

inline void d3d11_font_get_extent( D3D11_FONT* font, const char* text, DXVEC2* extent ) {
  return d3d11_font_get_extentA( font, text, extent );
}
inline void d3d11_font_draw( D3D11_FONT* font, DXVEC2 pos, const char* text, FCLR col ) {
  return d3d11_font_drawA( font, pos, text, col );
}