diff --git a/README.md b/README.md index 0301846..f9d6379 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,52 @@ + ooga booga ## TOC -- [Getting started](#getting-started) - [What is ooga booga?](#what-is-ooga-booga) + - [SIMPLICITY IS KING](#simplicity-is-king) + - [The "Build System"](#the-build-system) +- [Course: From Scratch to Steam](#course-from-scratch-to-steam) - [Quickstart](#quickstart) -- [The "Build System"](#the-build-system) - [Examples & Documentation](#examples--documentation) - [Known bugs](#known-bugs) - [Licensing](#licensing) -## Getting started -If you'd like to learn how to use the engine to build a game, there's a completely free course in the [Skool community](https://www.skool.com/game-dev) - -You can find all tutorials and resources for getting started within the community. - ## What is ooga booga? Ooga booga, often referred to as a *game engine* for simplicity, is more so designed to be a new C Standard, i.e. a new way to develop software from scratch in C. Other than `` we don't include a single C std header, but are instead writing a better standard library heavily optimized for developing games. Except for some image & audio file decoding, Ooga booga does not rely on any other third party code. +### SIMPLICITY IS KING + +Ooga booga is designed to keep things simple, and let you solve video game problems the simplest way possible. + +Performing SIMPLE and TRIVIAL tasks should be ... SIMPLE. +If you want to draw a rectangle, there should be a single procedure to draw a rectangle. +If you want to play an audio clip, there should be a single procedure to play an audio clip. +Etc. +This is something OS & Graphics API's tend to be fascinatingly terrible at even for the most trivial of tasks. +Thankfully, this is a main problem which oogabooga seeks to solve with a thin-as-possible layer of abstraction over the +If you need to do something more complicated, you should be able to focus on that problem alone. +We aim to give you tools at a low enough level where there are no constraints to how you can go about solving the problems which arise for your game. +If you wonder what any of the oogabooga procedures do, you can search for that symbol, go to the definition, and see & digest the exact implementation. +Almost all implementations are code written by us with this in mind (with the exception of 3 nothings stb headers). + + +### The "Build System" + +Our build system is a build.c and a build.bat which invokes the clang compiler on build.c. That's it. And we highly discourage anyone from introducing unnecessary complexity like a third party build system (cmake, premake) or to use header files at all whatsoever. + +This might sound like we are breaking some law, but we're not. We're using a compiler to compile a file which includes all the other files, it doesn't get simpler. We are NOT using third party software to run the same compiler to compile the same files over and over again and write it all to disk to then try and link it together. That's what we call silly business (and unreasonably slow compile times, without any real benefit). + +Oogabooga is made to be used in Unity builds. The idea is that you only include oogabooga.c somewhere in your project, specify the entry (see build.c) and now it's a Oogabooga project. Oogabooga is meant to replace the C standard, so it is not tested with projects which include standard C headers, so that will probably cause issues. + +## Course: From Scratch to Steam + +This project was started to be used in a course detailing the full ride from starting out making a game to publishing it to Steam. If you're keen on going all-in on getting a small game published to steam within 2-3 months, then check it out for free in our [Skool Community](https://www.skool.com/game-dev). + ## Quickstart -1. Install clang, add to path +Currently, we only support Windows x64 systems. +1. Make sure Windows SDK is installed +2. Install clang, add to path 2. Clone repo to 3. Make a file my_file.c in ``` @@ -35,11 +62,6 @@ int entry(int argc, char **argv) { 6. Run build/cgame.exe 7. profit -## The "Build System" - -Our build system is a build.c and a build.bat which invokes the clang compiler on build.c. That's it. And we highly discourage anyone from introducing unnecessary complexity like a third party build system (cmake, premake) or to use header files at all whatsoever. - -This might sound like we are breaking some law, but we're not. We're using a compiler to compile a file which includes all the other files, it doesn't get simpler. We are NOT using third party software to run the same compiler to compile the same files over and over again and write it all to disk to then try and link it together. That's what we call silly business (and unreasonably slow compile times, without any real benefit). ## Examples & Documentation Documentation will come in the form of a lot of examples because that's the best way to learn and understand how everything works. diff --git a/TODO b/TODO index 76e8210..2b60ac8 100644 --- a/TODO +++ b/TODO @@ -17,10 +17,14 @@ - End of clip also causes noise if audio clip does not end smoothly - Setting audio source to a format which differs from audio output format in both channels and bit_width at the same time will produce pure loud noise. - 24-Bit audio conversion doesn't really work - + - General bugs & issues - Release freeze in run_tests +- Renderer + - Custom shaders (just do hlsl for now, later we transpile) + - Still compile a default that's set by default and we can set with set_shader_for_basic_2d + - Needs testing: - Audio format channel conversions - sample rate downsampling diff --git a/build.c b/build.c index 8a4ec13..ad209ee 100644 --- a/build.c +++ b/build.c @@ -7,6 +7,13 @@ #define INITIAL_PROGRAM_MEMORY_SIZE MB(5) +// You might want to increase this if you get a log warning saying the temporary storage was overflown. +// In many cases, overflowing the temporary storage should be fine since it just wraps back around and +// allocations made way earlier in the frame are likely not used anymore. +// This might however not always be the case, so it's probably a good idea to make sure you always have +// enough temporary storage for your game. +#define TEMPORARY_STORAGE_SIZE MB(2) + typedef struct Context_Extra { int monkee; } Context_Extra; diff --git a/oogabooga/audio.c b/oogabooga/audio.c index 58f874a..9fb5dd8 100644 --- a/oogabooga/audio.c +++ b/oogabooga/audio.c @@ -1,5 +1,4 @@ - /* Loading audio: @@ -27,7 +26,6 @@ float64 audio_player_get_current_progression_factor(Audio_Player *p); void audio_player_set_source(Audio_Player *p, Audio_Source src, bool retain_progression_factor); void audio_player_clear_source(Audio_Player *p); - void audio_player_clear_source(Audio_Player *p); void audio_player_set_looping(Audio_Player *p, bool looping); */ diff --git a/oogabooga/gfx_impl_d3d11.c b/oogabooga/gfx_impl_d3d11.c index ab477f8..ffa302f 100644 --- a/oogabooga/gfx_impl_d3d11.c +++ b/oogabooga/gfx_impl_d3d11.c @@ -6,9 +6,7 @@ #endif -// #Cleanup apparently there are C macros for these (COBJMACROS) #define D3D11Release(x) x->lpVtbl->Release(x) -#define VTABLE(proc, ...) FIRST_ARG(__VA_ARGS__)->lpVtbl->proc(__VA_ARGS__) const Gfx_Handle GFX_INVALID_HANDLE = 0; @@ -184,14 +182,14 @@ void d3d11_update_swapchain() { win32_check_hr(hr); IDXGIAdapter *adapter; - hr = VTABLE(GetAdapter, dxgi_device, &adapter); + hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter); win32_check_hr(hr); IDXGIFactory2 *dxgi_factory; - hr = VTABLE(GetParent, adapter, &IID_IDXGIFactory2, cast(void**)&dxgi_factory); + hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory2, cast(void**)&dxgi_factory); win32_check_hr(hr); - hr = VTABLE(CreateSwapChainForHwnd, dxgi_factory, (IUnknown*)d3d11_device, window._os_handle, &scd, 0, 0, &d3d11_swap_chain); + hr = IDXGIFactory2_CreateSwapChainForHwnd(dxgi_factory, (IUnknown*)d3d11_device, window._os_handle, &scd, 0, 0, &d3d11_swap_chain); win32_check_hr(hr); RECT client_rect; @@ -202,15 +200,15 @@ void d3d11_update_swapchain() { d3d11_swap_chain_height = client_rect.bottom-client_rect.top; // store the swap chain description, as created by CreateSwapChainForHwnd - hr = VTABLE(GetDesc1, d3d11_swap_chain, &d3d11_swap_chain_desc); + hr = IDXGISwapChain1_GetDesc1(d3d11_swap_chain, &d3d11_swap_chain_desc); win32_check_hr(hr); // disable alt enter - VTABLE(MakeWindowAssociation, dxgi_factory, window._os_handle, cast (u32) DXGI_MWA_NO_ALT_ENTER); + IDXGIFactory_MakeWindowAssociation(dxgi_factory, window._os_handle, cast (u32) DXGI_MWA_NO_ALT_ENTER); - D3D11Release(dxgi_device); - D3D11Release(adapter); - D3D11Release(dxgi_factory); + IDXGIDevice_Release(dxgi_device); + IDXGIAdapter_Release(adapter); + IDXGIFactory_Release(dxgi_factory); log("Created swap chain of size %dx%d", d3d11_swap_chain_width, d3d11_swap_chain_height); } else { @@ -224,11 +222,11 @@ void d3d11_update_swapchain() { u32 window_width = client_rect.right-client_rect.left; u32 window_height = client_rect.bottom-client_rect.top; - hr = VTABLE(ResizeBuffers, d3d11_swap_chain, d3d11_swap_chain_desc.BufferCount, window_width, window_height, d3d11_swap_chain_desc.Format, d3d11_swap_chain_desc.Flags); + hr = IDXGISwapChain1_ResizeBuffers(d3d11_swap_chain, d3d11_swap_chain_desc.BufferCount, window_width, window_height, d3d11_swap_chain_desc.Format, d3d11_swap_chain_desc.Flags); win32_check_hr(hr); // update swap chain description - hr = VTABLE(GetDesc1, d3d11_swap_chain, &d3d11_swap_chain_desc); + hr = IDXGISwapChain1_GetDesc1(d3d11_swap_chain, &d3d11_swap_chain_desc); win32_check_hr(hr); log("Resized swap chain from %dx%d to %dx%d", d3d11_swap_chain_width, d3d11_swap_chain_height, window_width, window_height); @@ -240,9 +238,9 @@ void d3d11_update_swapchain() { - hr = VTABLE(GetBuffer, d3d11_swap_chain, 0, &IID_ID3D11Texture2D, (void**)&d3d11_back_buffer); + hr = IDXGISwapChain1_GetBuffer(d3d11_swap_chain, 0, &IID_ID3D11Texture2D, (void**)&d3d11_back_buffer); win32_check_hr(hr); - hr = VTABLE(CreateRenderTargetView, d3d11_device, (ID3D11Resource*)d3d11_back_buffer, 0, &d3d11_window_render_target_view); + hr = ID3D11Device_CreateRenderTargetView(d3d11_device, (ID3D11Resource*)d3d11_back_buffer, 0, &d3d11_window_render_target_view); win32_check_hr(hr); } @@ -310,7 +308,7 @@ void gfx_init() { assert(d3d11_device != 0, "D3D11CreateDevice failed"); #if CONFIGURATION == DEBUG - hr = VTABLE(QueryInterface, d3d11_device, &IID_ID3D11Debug, (void**)&d3d11_debug); + hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Debug, (void**)&d3d11_debug); if (SUCCEEDED(hr)) { log_verbose("D3D11 debug is active"); } @@ -320,13 +318,13 @@ void gfx_init() { IDXGIDevice *dxgi_device = 0; IDXGIAdapter *target_adapter = 0; - hr = VTABLE(QueryInterface, d3d11_device, &IID_IDXGIDevice, (void **)&dxgi_device); + hr = ID3D11Device_QueryInterface(d3d11_device, &IID_IDXGIDevice, (void **)&dxgi_device); - hr = VTABLE(GetAdapter, dxgi_device, &target_adapter); + hr = IDXGIDevice_GetAdapter(dxgi_device, &target_adapter); if (SUCCEEDED(hr)) { DXGI_ADAPTER_DESC adapter_desc = ZERO(DXGI_ADAPTER_DESC); - hr = VTABLE(GetDesc, target_adapter, &adapter_desc); + hr = IDXGIAdapter_GetDesc(target_adapter, &adapter_desc); if (SUCCEEDED(hr)) { string desc = temp_win32_null_terminated_wide_to_fixed_utf8(adapter_desc.Description); log("D3D11 adapter is: %s", desc); @@ -349,9 +347,9 @@ void gfx_init() { bd.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; bd.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; bd.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; - hr = VTABLE(CreateBlendState, d3d11_device, &bd, &d3d11_blend_state); + hr = ID3D11Device_CreateBlendState(d3d11_device, &bd, &d3d11_blend_state); win32_check_hr(hr); - VTABLE(OMSetBlendState, d3d11_context, d3d11_blend_state, NULL, 0xffffffff); + ID3D11DeviceContext_OMSetBlendState(d3d11_context, d3d11_blend_state, NULL, 0xffffffff); } { @@ -361,9 +359,9 @@ void gfx_init() { desc.FrontCounterClockwise = FALSE; desc.DepthClipEnable = FALSE; desc.CullMode = D3D11_CULL_NONE; - hr = VTABLE(CreateRasterizerState, d3d11_device, &desc, &d3d11_rasterizer); + hr = ID3D11Device_CreateRasterizerState(d3d11_device, &desc, &d3d11_rasterizer); win32_check_hr(hr); - VTABLE(RSSetState, d3d11_context, d3d11_rasterizer); + ID3D11DeviceContext_RSSetState(d3d11_context, d3d11_rasterizer); } // COnst buffer @@ -394,19 +392,19 @@ void gfx_init() { sd.ComparisonFunc = D3D11_COMPARISON_NEVER; sd.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - hr = VTABLE(CreateSamplerState, d3d11_device, &sd, &d3d11_image_sampler_np_fp); + hr = ID3D11Device_CreateSamplerState(d3d11_device, &sd, &d3d11_image_sampler_np_fp); win32_check_hr(hr); sd.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; - hr = VTABLE(CreateSamplerState, d3d11_device, &sd, &d3d11_image_sampler_nl_fl); + hr =ID3D11Device_CreateSamplerState(d3d11_device, &sd, &d3d11_image_sampler_nl_fl); win32_check_hr(hr); sd.Filter = D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; - hr = VTABLE(CreateSamplerState, d3d11_device, &sd, &d3d11_image_sampler_np_fl); + hr = ID3D11Device_CreateSamplerState(d3d11_device, &sd, &d3d11_image_sampler_np_fl); win32_check_hr(hr); sd.Filter = D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; - hr = VTABLE(CreateSamplerState, d3d11_device, &sd, &d3d11_image_sampler_nl_fp); + hr = ID3D11Device_CreateSamplerState(d3d11_device, &sd, &d3d11_image_sampler_nl_fp); win32_check_hr(hr); } @@ -421,17 +419,17 @@ void gfx_init() { ID3DBlob* vs_blob = NULL; ID3DBlob* err_blob = NULL; hr = D3DCompile((char*)source.data, source.count, 0, 0, 0, "vs_main", "vs_5_0", 0, 0, &vs_blob, &err_blob); - assert(SUCCEEDED(hr), "Vertex Shader Compilation Error: %cs\n", (char*)VTABLE(GetBufferPointer, err_blob)); + assert(SUCCEEDED(hr), "Vertex Shader Compilation Error: %cs\n", (char*)ID3D10Blob_GetBufferPointer(err_blob)); // Compile pixel shader ID3DBlob* ps_blob = NULL; hr = D3DCompile((char*)source.data, source.count, 0, 0, 0, "ps_main", "ps_5_0", 0, 0, &ps_blob, &err_blob); - assert(SUCCEEDED(hr), "Vertex Shader Compilation Error: %cs\n", (char*)VTABLE(GetBufferPointer, err_blob)); + assert(SUCCEEDED(hr), "Vertex Shader Compilation Error: %cs\n", (char*)ID3D10Blob_GetBufferPointer(err_blob)); - void *vs_buffer = VTABLE(GetBufferPointer, vs_blob); - u64 vs_size = VTABLE(GetBufferSize, vs_blob); - void *ps_buffer = VTABLE(GetBufferPointer, ps_blob); - u64 ps_size = VTABLE(GetBufferSize, ps_blob); + void *vs_buffer = ID3D10Blob_GetBufferPointer(vs_blob); + u64 vs_size = ID3D10Blob_GetBufferSize(vs_blob); + void *ps_buffer = ID3D10Blob_GetBufferPointer(ps_blob); + u64 ps_size = ID3D10Blob_GetBufferSize(ps_blob); log_verbose("Shaders compiled"); @@ -472,10 +470,10 @@ void gfx_init() { #endif // Create the shaders - hr = VTABLE(CreateVertexShader, d3d11_device, vs_buffer, vs_size, NULL, &d3d11_image_vertex_shader); + hr = ID3D11Device_CreateVertexShader(d3d11_device, vs_buffer, vs_size, NULL, &d3d11_image_vertex_shader); win32_check_hr(hr); - hr = VTABLE(CreatePixelShader, d3d11_device, ps_buffer, ps_size, NULL, &d3d11_image_pixel_shader); + hr = ID3D11Device_CreatePixelShader(d3d11_device, ps_buffer, ps_size, NULL, &d3d11_image_pixel_shader); win32_check_hr(hr); log_verbose("Shaders created"); @@ -517,7 +515,7 @@ void gfx_init() { layout[3].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; layout[3].InstanceDataStepRate = 0; - hr = VTABLE(CreateInputLayout, d3d11_device, layout, 4, vs_buffer, vs_size, &d3d11_image_vertex_layout); + hr = ID3D11Device_CreateInputLayout(d3d11_device, layout, 4, vs_buffer, vs_size, &d3d11_image_vertex_layout); win32_check_hr(hr); #if OOGABOOGA_DEV @@ -530,39 +528,39 @@ void gfx_init() { } void d3d11_draw_call(int number_of_rendered_quads, ID3D11ShaderResourceView **textures, u64 num_textures) { - VTABLE(OMSetBlendState, d3d11_context, d3d11_blend_state, 0, 0xffffffff); - VTABLE(OMSetRenderTargets, d3d11_context, 1, &d3d11_window_render_target_view, 0); - VTABLE(RSSetState, d3d11_context, d3d11_rasterizer); + ID3D11DeviceContext_OMSetBlendState(d3d11_context, d3d11_blend_state, 0, 0xffffffff); + ID3D11DeviceContext_OMSetRenderTargets(d3d11_context, 1, &d3d11_window_render_target_view, 0); + ID3D11DeviceContext_RSSetState(d3d11_context, d3d11_rasterizer); D3D11_VIEWPORT viewport = ZERO(D3D11_VIEWPORT); viewport.Width = d3d11_swap_chain_width; viewport.Height = d3d11_swap_chain_height; viewport.MaxDepth = 1.0; - VTABLE(RSSetViewports, d3d11_context, 1, &viewport); + ID3D11DeviceContext_RSSetViewports(d3d11_context, 1, &viewport); UINT stride = sizeof(D3D11_Vertex); UINT offset = 0; - VTABLE(IASetInputLayout, d3d11_context, d3d11_image_vertex_layout); - VTABLE(IASetVertexBuffers, d3d11_context, 0, 1, &d3d11_quad_vbo, &stride, &offset); - VTABLE(IASetPrimitiveTopology, d3d11_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D11DeviceContext_IASetInputLayout(d3d11_context, d3d11_image_vertex_layout); + ID3D11DeviceContext_IASetVertexBuffers(d3d11_context, 0, 1, &d3d11_quad_vbo, &stride, &offset); + ID3D11DeviceContext_IASetPrimitiveTopology(d3d11_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - VTABLE(VSSetShader, d3d11_context, d3d11_image_vertex_shader, NULL, 0); - VTABLE(PSSetShader, d3d11_context, d3d11_image_pixel_shader, NULL, 0); + ID3D11DeviceContext_VSSetShader(d3d11_context, d3d11_image_vertex_shader, NULL, 0); + ID3D11DeviceContext_PSSetShader(d3d11_context, d3d11_image_pixel_shader, NULL, 0); - VTABLE(PSSetSamplers, d3d11_context, 0, 1, &d3d11_image_sampler_np_fp); - VTABLE(PSSetSamplers, d3d11_context, 1, 1, &d3d11_image_sampler_nl_fl); - VTABLE(PSSetSamplers, d3d11_context, 2, 1, &d3d11_image_sampler_np_fl); - VTABLE(PSSetSamplers, d3d11_context, 3, 1, &d3d11_image_sampler_nl_fp); - VTABLE(PSSetShaderResources, d3d11_context, 0, num_textures, textures); + ID3D11DeviceContext_PSSetSamplers(d3d11_context, 0, 1, &d3d11_image_sampler_np_fp); + ID3D11DeviceContext_PSSetSamplers(d3d11_context, 1, 1, &d3d11_image_sampler_nl_fl); + ID3D11DeviceContext_PSSetSamplers(d3d11_context, 2, 1, &d3d11_image_sampler_np_fl); + ID3D11DeviceContext_PSSetSamplers(d3d11_context, 3, 1, &d3d11_image_sampler_nl_fp); + ID3D11DeviceContext_PSSetShaderResources(d3d11_context, 0, num_textures, textures); - VTABLE(Draw, d3d11_context, number_of_rendered_quads * 6, 0); + ID3D11DeviceContext_Draw(d3d11_context, number_of_rendered_quads * 6, 0); } void d3d11_process_draw_frame() { HRESULT hr; - VTABLE(ClearRenderTargetView, d3d11_context, d3d11_window_render_target_view, (float*)&window.clear_color); + ID3D11DeviceContext_ClearRenderTargetView(d3d11_context, d3d11_window_render_target_view, (float*)&window.clear_color); /// // Maybe grow quad vbo @@ -578,7 +576,7 @@ void d3d11_process_draw_frame() { desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; desc.ByteWidth = required_size; desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - HRESULT hr = VTABLE(CreateBuffer, d3d11_device, &desc, 0, &d3d11_quad_vbo); + HRESULT hr = ID3D11Device_CreateBuffer(d3d11_device, &desc, 0, &d3d11_quad_vbo); assert(SUCCEEDED(hr), "CreateBuffer failed"); d3d11_quad_vbo_size = required_size; @@ -639,9 +637,9 @@ void d3d11_process_draw_frame() { if (num_textures >= 32) { // If max textures reached, make a draw call and start over D3D11_MAPPED_SUBRESOURCE buffer_mapping; - VTABLE(Map, d3d11_context, (ID3D11Resource*)d3d11_quad_vbo, 0, D3D11_MAP_WRITE_DISCARD, 0, &buffer_mapping); + ID3D11DeviceContext_Map(d3d11_context, (ID3D11Resource*)d3d11_quad_vbo, 0, D3D11_MAP_WRITE_DISCARD, 0, &buffer_mapping); memcpy(buffer_mapping.pData, d3d11_staging_quad_buffer, number_of_rendered_quads*sizeof(D3D11_Vertex)*6); - VTABLE(Unmap, d3d11_context, (ID3D11Resource*)d3d11_quad_vbo, 0); + ID3D11DeviceContext_Unmap(d3d11_context, (ID3D11Resource*)d3d11_quad_vbo, 0); d3d11_draw_call(number_of_rendered_quads, textures, num_textures); head = (D3D11_Vertex*)d3d11_staging_quad_buffer; num_textures = 0; @@ -727,14 +725,14 @@ void d3d11_process_draw_frame() { tm_scope("Write to gpu") { D3D11_MAPPED_SUBRESOURCE buffer_mapping; tm_scope("The Map call") { - hr = VTABLE(Map, d3d11_context, (ID3D11Resource*)d3d11_quad_vbo, 0, D3D11_MAP_WRITE_DISCARD, 0, &buffer_mapping); + hr = ID3D11DeviceContext_Map(d3d11_context, (ID3D11Resource*)d3d11_quad_vbo, 0, D3D11_MAP_WRITE_DISCARD, 0, &buffer_mapping); win32_check_hr(hr); } tm_scope("The memcpy") { memcpy(buffer_mapping.pData, d3d11_staging_quad_buffer, number_of_rendered_quads*sizeof(D3D11_Vertex)*6); } tm_scope("The Unmap call") { - VTABLE(Unmap, d3d11_context, (ID3D11Resource*)d3d11_quad_vbo, 0); + ID3D11DeviceContext_Unmap(d3d11_context, (ID3D11Resource*)d3d11_quad_vbo, 0); } } @@ -766,7 +764,7 @@ void gfx_update() { d3d11_process_draw_frame(); tm_scope("Present") { - VTABLE(Present, d3d11_swap_chain, window.enable_vsync, window.enable_vsync ? 0 : DXGI_PRESENT_ALLOW_TEARING); + IDXGISwapChain1_Present(d3d11_swap_chain, window.enable_vsync, window.enable_vsync ? 0 : DXGI_PRESENT_ALLOW_TEARING); } @@ -774,16 +772,16 @@ void gfx_update() { /// // Check debug messages, output to stdout ID3D11InfoQueue* info_q = 0; - hr = VTABLE(QueryInterface, d3d11_device, &IID_ID3D11InfoQueue, (void**)&info_q); + hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11InfoQueue, (void**)&info_q); if (SUCCEEDED(hr)) { - u64 msg_count = VTABLE(GetNumStoredMessagesAllowedByRetrievalFilter, info_q); + u64 msg_count = ID3D11InfoQueue_GetNumStoredMessagesAllowedByRetrievalFilter(info_q); for (u64 i = 0; i < msg_count; i++) { SIZE_T msg_size = 0; - VTABLE(GetMessage, info_q, i, 0, &msg_size); + ID3D11InfoQueue_GetMessage(info_q, i, 0, &msg_size); D3D11_MESSAGE* msg = (D3D11_MESSAGE*)talloc(msg_size); if (msg) { - VTABLE(GetMessage, info_q, i, msg, &msg_size); // Get the actual message + ID3D11InfoQueue_GetMessage(info_q, i, msg, &msg_size); // Get the actual message d3d11_debug_callback(msg->Category, msg->Severity, msg->ID, msg->pDescription); } @@ -828,10 +826,10 @@ void gfx_init_image(Gfx_Image *image, void *initial_data) { data_desc.SysMemPitch = image->width * image->channels; ID3D11Texture2D* texture = 0; - HRESULT hr = VTABLE(CreateTexture2D, d3d11_device, &desc, &data_desc, &texture); + HRESULT hr = ID3D11Device_CreateTexture2D(d3d11_device, &desc, &data_desc, &texture); win32_check_hr(hr); - hr = VTABLE(CreateShaderResourceView, d3d11_device, (ID3D11Resource*)texture, 0, &image->gfx_handle); + hr = ID3D11Device_CreateShaderResourceView(d3d11_device, (ID3D11Resource*)texture, 0, &image->gfx_handle); win32_check_hr(hr); if (!initial_data) { @@ -845,14 +843,14 @@ void gfx_set_image_data(Gfx_Image *image, u32 x, u32 y, u32 w, u32 h, void *data ID3D11ShaderResourceView *view = image->gfx_handle; ID3D11Resource *resource = NULL; - VTABLE(GetResource, view, &resource); + ID3D11ShaderResourceView_GetResource(view, &resource); assert(resource, "Invalid image passed to gfx_set_image_data"); assert(x+w <= image->width && y+h <= image->height, "Specified subregion in image is out of bounds"); ID3D11Texture2D *texture = NULL; - HRESULT hr = VTABLE(QueryInterface, resource, &IID_ID3D11Texture2D, (void**)&texture); + HRESULT hr = ID3D11Resource_QueryInterface(resource, &IID_ID3D11Texture2D, (void**)&texture); assert(SUCCEEDED(hr), "Expected gfx resource to be a texture but it wasn't"); D3D11_BOX destBox; @@ -864,15 +862,15 @@ void gfx_set_image_data(Gfx_Image *image, u32 x, u32 y, u32 w, u32 h, void *data destBox.back = 1; // #Incomplete bit-width 8 assumed - VTABLE(UpdateSubresource, d3d11_context, (ID3D11Resource*)texture, 0, &destBox, data, w * image->channels, 0); + ID3D11DeviceContext_UpdateSubresource(d3d11_context, (ID3D11Resource*)texture, 0, &destBox, data, w * image->channels, 0); } void gfx_deinit_image(Gfx_Image *image) { ID3D11ShaderResourceView *view = image->gfx_handle; ID3D11Resource *resource = 0; - VTABLE(GetResource, view, &resource); + ID3D11ShaderResourceView_GetResource(view, &resource); ID3D11Texture2D *texture = 0; - HRESULT hr = VTABLE(QueryInterface, resource, &IID_ID3D11Texture2D, (void**)&texture); + HRESULT hr = ID3D11Resource_QueryInterface(resource, &IID_ID3D11Texture2D, (void**)&texture); if (SUCCEEDED(hr)) { D3D11Release(view); D3D11Release(texture);