From 819cf3e4e8abb5ad41d8830155fc20bd833b21e8 Mon Sep 17 00:00:00 2001 From: navewindre Date: Wed, 17 Jul 2024 08:36:51 +0200 Subject: render wip --- dwm/grender.h | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 dwm/grender.h (limited to 'dwm/grender.h') diff --git a/dwm/grender.h b/dwm/grender.h new file mode 100644 index 0000000..bd65fba --- /dev/null +++ b/dwm/grender.h @@ -0,0 +1,155 @@ +#pragma once + +#include "../src/color.h" + +#include +#include +#include + +#include +#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 textures; + std::vector 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 ); +} \ No newline at end of file -- cgit v1.2.3