improved glez performance

This commit is contained in:
Jenny White 2018-04-29 16:52:34 +03:00
parent 43cf73ef2b
commit 7d51035d98
6 changed files with 52 additions and 30 deletions

View File

@ -1,4 +1,4 @@
/*
/*
* prediction.h
*
* Created on: Dec 5, 2016

View File

@ -26,7 +26,7 @@ namespace api
struct font_handle_t
{
glez_font_t handle;
glez_font_t handle{ GLEZ_FONT_INVALID };
std::string filename;
float size;
};

View File

@ -104,8 +104,6 @@ DEFINE_HOOKED_METHOD(PaintTraverse, void, vgui::IPanel *this_,
original::PaintTraverse(this_, panel, force, allow_force);
// To avoid threading problems.
PROF_SECTION(PT_total);
if (panel == panel_top)
draw_flag = true;
if (!cathook)
@ -161,7 +159,6 @@ DEFINE_HOOKED_METHOD(PaintTraverse, void, vgui::IPanel *this_,
#if ENABLE_GUI
g_pGUI->Update();
#endif
PROF_SECTION(PT_active);
draw::UpdateWTS();
}
}

View File

@ -8,31 +8,34 @@
#include <visual/SDLHooks.hpp>
#include "HookedMethods.hpp"
static bool init{ false };
static bool init_wminfo{ false };
static SDL_SysWMinfo wminfo{};
int static_init_wminfo = (wminfo.version.major = 2, wminfo.version.minor = 0, 1);
typedef SDL_bool (*SDL_GetWindowWMInfo_t)(SDL_Window * window,
SDL_SysWMinfo * info);
static SDL_GetWindowWMInfo_t GetWindowWMInfo = nullptr;
static SDL_GLContext tf2_sdl = nullptr;
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(SDL_GL_SwapWindow, void, SDL_Window *window)
{
static SDL_SysWMinfo wminfo;
wminfo.version.major = 2;
wminfo.version.minor = 0;
typedef SDL_bool (*SDL_GetWindowWMInfo_t)(SDL_Window * window,
SDL_SysWMinfo * info);
static SDL_GetWindowWMInfo_t GetWindowWMInfo =
*reinterpret_cast<SDL_GetWindowWMInfo_t *>(
sharedobj::libsdl().Pointer(0xFD4D8));
static bool init_wminfo{ false };
if (!init_wminfo)
{
GetWindowWMInfo = *reinterpret_cast<SDL_GetWindowWMInfo_t *>(
sharedobj::libsdl().Pointer(0xFD4D8));
GetWindowWMInfo(window, &wminfo);
init_wminfo = true;
}
if (!sdl_hooks::window)
sdl_hooks::window = window;
static bool init{ false };
static SDL_GLContext tf2_sdl = SDL_GL_GetCurrentContext();
if (!tf2_sdl)
tf2_sdl = SDL_GL_GetCurrentContext();
if (cathook && !disable_visuals)
{
@ -46,7 +49,7 @@ DEFINE_HOOKED_METHOD(SDL_GL_SwapWindow, void, SDL_Window *window)
}
{
PROF_SECTION(SWAPWINDOW_tf2);
SDL_GL_MakeCurrent(window, tf2_sdl);
//SDL_GL_MakeCurrent(window, tf2_sdl);
original::SDL_GL_SwapWindow(window);
// glXMakeContextCurrent(wminfo.info.x11.display,
// wminfo.info.x11.window,

View File

@ -37,7 +37,7 @@ font_handle_t create_font(const char *path, float size)
font_handle_t result;
result.filename = std::string(path);
result.size = size;
result.handle = 0;
result.handle = GLEZ_FONT_INVALID;
return result;
}
@ -78,7 +78,7 @@ void initialize()
}
xoverlay_show();
#else
context = SDL_GL_CreateContext(sdl_hooks::window);
//context = SDL_GL_CreateContext(sdl_hooks::window);
glClearColor(1.0, 0.0, 0.0, 0.5);
glewExperimental = GL_TRUE;
glewInit();
@ -124,7 +124,7 @@ void draw_circle(float x, float y, float radius, const rgba_t &rgba,
void draw_string(float x, float y, const char *string, font_handle_t &font,
const rgba_t &rgba)
{
if (!font.handle)
if (font.handle == GLEZ_FONT_INVALID)
font.handle = glez_font_load(font.filename.c_str(), font.size);
glez_string(x, y, string, font.handle,
*reinterpret_cast<const glez_rgba_t *>(&rgba), nullptr,
@ -135,7 +135,7 @@ void draw_string_with_outline(float x, float y, const char *string,
font_handle_t &font, const rgba_t &rgba,
const rgba_t &rgba_outline, float thickness)
{
if (!font.handle)
if (font.handle == GLEZ_FONT_INVALID)
font.handle = glez_font_load(font.filename.c_str(), font.size);
glez_string_with_outline(
x, y, string, font.handle,
@ -149,7 +149,7 @@ void draw_string_with_outline(float x, float y, const char *string,
void get_string_size(const char *string, font_handle_t &font, float *x,
float *y)
{
if (!font.handle)
if (font.handle == GLEZ_FONT_INVALID)
font.handle = glez_font_load(font.filename.c_str(), font.size);
glez_font_string_size(font.handle, string, x, y);
}
@ -160,16 +160,29 @@ void draw_begin()
#if EXTERNAL_DRAWING
xoverlay_draw_begin();
#else
SDL_GL_MakeCurrent(sdl_hooks::window, context);
{
PROF_SECTION(draw_begin__SDL_GL_MakeCurrent);
//SDL_GL_MakeCurrent(sdl_hooks::window, context);
}
#endif
glez_begin();
{
glActiveTexture(GL_TEXTURE0);
PROF_SECTION(draw_begin__glez_end)
glez_begin();
}
}
void draw_end()
{
PROF_SECTION(DRAWEX_draw_end);
glez_end();
SDL_GL_MakeCurrent(sdl_hooks::window, nullptr);
{
PROF_SECTION(draw_end__glez_end);
glez_end();
}
{
PROF_SECTION(draw_end__SDL_GL_MakeCurrent);
//SDL_GL_MakeCurrent(sdl_hooks::window, nullptr);
}
#if EXTERNAL_DRAWING
xoverlay_draw_end();
#endif

View File

@ -15,7 +15,10 @@
void render_cheat_visuals()
{
BeginCheatVisuals();
{
PROF_SECTION(BeginCheatVisuals);
BeginCheatVisuals();
}
// xoverlay_draw_rect(300, 300, 100, 100, xoverlay_rgba(200, 100, 100,
// 255));
// draw_api::draw_string(100, 100, "Testing", fonts::main_font,
@ -25,8 +28,14 @@ void render_cheat_visuals()
// "TestingSTR", fh.handle, *reinterpret_cast<const xoverlay_rgba_t
// *>(&colors::white), 0, 0);
// xoverlay_draw_string_with_outline(100, 20, "Testing2", )
DrawCheatVisuals();
EndCheatVisuals();
{
PROF_SECTION(DrawCheatVisuals);
DrawCheatVisuals();
}
{
PROF_SECTION(EndCheatVisuals);
EndCheatVisuals();
}
}
void BeginCheatVisuals()