Skip to content

Commit

Permalink
global renderer and keep render code together
Browse files Browse the repository at this point in the history
  • Loading branch information
BttrDrgn committed May 14, 2022
1 parent c3734bf commit f51d42e
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 73 deletions.
1 change: 1 addition & 0 deletions src/app/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ std::uint32_t global::start;
#else
bool global::hide = false;
HWND global::hwnd;
kiero::RenderType::Enum global::renderer;
#endif
1 change: 1 addition & 0 deletions src/app/global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ class global
#else
static bool hide;
static HWND hwnd;
static kiero::RenderType::Enum renderer;
#endif
};
12 changes: 4 additions & 8 deletions src/app/hook/impl/d3d10_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ long __stdcall hkPresent10(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT F

if (!init)
{
global::renderer = kiero::RenderType::Enum::D3D10;

DXGI_SWAP_CHAIN_DESC desc;
pSwapChain->GetDesc(&desc);

Expand All @@ -32,15 +34,9 @@ long __stdcall hkPresent10(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT F
init = true;
}

ImGui_ImplDX10_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();

menus::prepare();
menus::update();

ImGui::EndFrame();
ImGui::Render();
ImGui_ImplDX10_RenderDrawData(ImGui::GetDrawData());
menus::present();

return oPresent(pSwapChain, SyncInterval, Flags);
}
Expand Down
12 changes: 4 additions & 8 deletions src/app/hook/impl/d3d11_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ long __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT F

if (!init)
{
global::renderer = kiero::RenderType::Enum::D3D11;

DXGI_SWAP_CHAIN_DESC desc;
pSwapChain->GetDesc(&desc);

Expand All @@ -35,15 +37,9 @@ long __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT F
init = true;
}

ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();

menus::prepare();
menus::update();

ImGui::EndFrame();
ImGui::Render();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
menus::present();

return oPresent(pSwapChain, SyncInterval, Flags);
}
Expand Down
12 changes: 4 additions & 8 deletions src/app/hook/impl/d3d9_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ long __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice)

if (!init)
{
global::renderer = kiero::RenderType::Enum::D3D9;

D3DDEVICE_CREATION_PARAMETERS params;
pDevice->GetCreationParameters(&params);

Expand All @@ -41,15 +43,9 @@ long __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice)
init = true;
}

ImGui_ImplDX9_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();

menus::prepare();
menus::update();

ImGui::EndFrame();
ImGui::Render();
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
menus::present();

return oEndScene(pDevice);
}
Expand Down
12 changes: 4 additions & 8 deletions src/app/hook/impl/opengl3_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ BOOL __stdcall hkWglSwapBuffers(_In_ HDC hDc)

if (!init)
{
global::renderer = kiero::RenderType::Enum::OpenGL;

HWND hwnd = WindowFromDC(hDc);

global::hwnd = hwnd;
Expand All @@ -26,15 +28,9 @@ BOOL __stdcall hkWglSwapBuffers(_In_ HDC hDc)
init = true;
}

ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();

menus::prepare();
menus::update();

ImGui::EndFrame();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
menus::present();

return owglSwapBuffers(hDc);
}
Expand Down
127 changes: 88 additions & 39 deletions src/app/menus/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <shellapi.h>
#endif


void menus::init()
{
IMGUI_CHECKVERSION();
Expand All @@ -32,6 +31,94 @@ void menus::init()
#endif
}

void menus::prepare()
{
#ifndef OVERLAY
ImGui_ImplSDLRenderer_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
SDL_SetRenderDrawColor(global::renderer, 68, 43, 134, 255);
SDL_RenderClear(global::renderer);
#else
switch (global::renderer)
{
case kiero::RenderType::D3D9:
ImGui_ImplDX9_NewFrame();
break;

case kiero::RenderType::D3D10:
ImGui_ImplDX10_NewFrame();
break;

case kiero::RenderType::D3D11:
ImGui_ImplDX11_NewFrame();
break;

case kiero::RenderType::OpenGL:
ImGui_ImplOpenGL3_NewFrame();
break;
}

ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
#endif
}

void menus::present()
{
#ifndef OVERLAY
ImGui::Render();
ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData());

if (!global::use_hardware)
{
SDL_UpdateWindowSurface(global::window);

}
else if (global::use_hardware)
{
SDL_RenderPresent(global::renderer);
}
#else
ImGui::EndFrame();
ImGui::Render();

switch (global::renderer)
{
case kiero::RenderType::D3D9:
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
break;

case kiero::RenderType::D3D10:
ImGui_ImplDX10_RenderDrawData(ImGui::GetDrawData());
break;

case kiero::RenderType::D3D11:
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
break;

case kiero::RenderType::OpenGL:
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
break;
}
#endif
}

void menus::cleanup()
{
#ifndef OVERLAY
ImGui_ImplSDLRenderer_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();

SDL_DestroyRenderer(global::renderer);
SDL_DestroyWindow(global::window);
SDL_Quit();
#else

#endif
}

void menus::update()
{

Expand Down Expand Up @@ -86,44 +173,6 @@ void menus::update()
#endif
}

#ifndef OVERLAY
void menus::prepare()
{
ImGui_ImplSDLRenderer_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
SDL_SetRenderDrawColor(global::renderer, 68, 43, 134, 255);
SDL_RenderClear(global::renderer);
}

void menus::present()
{
ImGui::Render();
ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData());

if (!global::use_hardware)
{
SDL_UpdateWindowSurface(global::window);

}
else if(global::use_hardware)
{
SDL_RenderPresent(global::renderer);
}
}

void menus::cleanup()
{
ImGui_ImplSDLRenderer_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();

SDL_DestroyRenderer(global::renderer);
SDL_DestroyWindow(global::window);
SDL_Quit();
}
#endif

void menus::main_menu_bar()
{
if (ImGui::BeginMainMenuBar())
Expand Down
5 changes: 3 additions & 2 deletions src/app/menus/menus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
class menus
{
public:
static void init();
static void update();

#ifndef OVERLAY
static void init();
static void prepare();
static void present();
static void cleanup();

#ifndef OVERLAY
static std::vector<vec2> snow;
static std::int32_t max_points;
static bool show_snow;
Expand Down
4 changes: 4 additions & 0 deletions src/app/stdafx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <backends/imgui_impl_sdl.h>
#include <backends/imgui_impl_sdlrenderer.h>
#else
#include <d3d9.h>
#include <d3d10.h>
#include <d3d11.h>

#include <MinHook.h>
#include <kiero.h>

Expand Down

0 comments on commit f51d42e

Please sign in to comment.