mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-25 05:55:12 +00:00
patch ImGui so it supports square textures
in the font atlas
This commit is contained in:
parent
c9b2172c4f
commit
72cd745824
11 changed files with 80 additions and 7 deletions
1
extern/imgui_patched/imgui.h
vendored
1
extern/imgui_patched/imgui.h
vendored
|
@ -2989,6 +2989,7 @@ enum ImFontAtlasFlags_
|
|||
ImFontAtlasFlags_NoPowerOfTwoHeight = 1 << 0, // Don't round the height to next power of two
|
||||
ImFontAtlasFlags_NoMouseCursors = 1 << 1, // Don't build software mouse cursors into the atlas (save a little texture memory)
|
||||
ImFontAtlasFlags_NoBakedLines = 1 << 2, // Don't build thick line textures into the atlas (save a little texture memory, allow support for point/nearest filtering). The AntiAliasedLinesUseTex features uses them, otherwise they will be rendered using polygons (more expensive for CPU/GPU).
|
||||
ImFontAtlasFlags_Square = 1 << 3, // Make sure the texture is a square
|
||||
};
|
||||
|
||||
// Load and rasterize multiple TTF/OTF fonts into a same texture. The font atlas will build a single texture holding:
|
||||
|
|
9
extern/imgui_patched/imgui_draw.cpp
vendored
9
extern/imgui_patched/imgui_draw.cpp
vendored
|
@ -2678,6 +2678,15 @@ static bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
|||
// 7. Allocate texture
|
||||
atlas->TexHeight = (atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) ? (atlas->TexHeight + 1) : ImUpperPowerOfTwo(atlas->TexHeight);
|
||||
atlas->TexUvScale = ImVec2(1.0f / atlas->TexWidth, 1.0f / atlas->TexHeight);
|
||||
|
||||
if (atlas->Flags & ImFontAtlasFlags_Square) {
|
||||
if (atlas->TexWidth>atlas->TexHeight) {
|
||||
atlas->TexHeight=atlas->TexWidth;
|
||||
} else {
|
||||
atlas->TexWidth=atlas->TexHeight;
|
||||
}
|
||||
}
|
||||
|
||||
atlas->TexPixelsAlpha8 = (unsigned char*)IM_ALLOC(atlas->TexWidth * atlas->TexHeight);
|
||||
memset(atlas->TexPixelsAlpha8, 0, atlas->TexWidth * atlas->TexHeight);
|
||||
spc.pixels = atlas->TexPixelsAlpha8;
|
||||
|
|
|
@ -643,6 +643,15 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u
|
|||
|
||||
// 7. Allocate texture
|
||||
atlas->TexHeight = (atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) ? (atlas->TexHeight + 1) : ImUpperPowerOfTwo(atlas->TexHeight);
|
||||
|
||||
if (atlas->Flags & ImFontAtlasFlags_Square) {
|
||||
if (atlas->TexWidth>atlas->TexHeight) {
|
||||
atlas->TexHeight=atlas->TexWidth;
|
||||
} else {
|
||||
atlas->TexWidth=atlas->TexHeight;
|
||||
}
|
||||
}
|
||||
|
||||
atlas->TexUvScale = ImVec2(1.0f / atlas->TexWidth, 1.0f / atlas->TexHeight);
|
||||
if (src_load_color)
|
||||
{
|
||||
|
|
|
@ -4074,6 +4074,9 @@ bool FurnaceGUI::loop() {
|
|||
rend->initGUI(sdlWin);
|
||||
|
||||
logD("building font...");
|
||||
if (rend->areTexturesSquare()) {
|
||||
ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square;
|
||||
}
|
||||
if (!ImGui::GetIO().Fonts->Build()) {
|
||||
logE("error while building font atlas!");
|
||||
showError(_("error while loading fonts! please check your settings."));
|
||||
|
@ -4082,7 +4085,12 @@ bool FurnaceGUI::loop() {
|
|||
patFont=mainFont;
|
||||
bigFont=mainFont;
|
||||
headFont=mainFont;
|
||||
if (rend) rend->destroyFontsTexture();
|
||||
if (rend) {
|
||||
rend->destroyFontsTexture();
|
||||
if (rend->areTexturesSquare()) {
|
||||
ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square;
|
||||
}
|
||||
}
|
||||
if (!ImGui::GetIO().Fonts->Build()) {
|
||||
logE("error again while building font atlas!");
|
||||
}
|
||||
|
@ -6692,7 +6700,12 @@ bool FurnaceGUI::loop() {
|
|||
|
||||
applyUISettings();
|
||||
|
||||
if (rend) rend->destroyFontsTexture();
|
||||
if (rend) {
|
||||
rend->destroyFontsTexture();
|
||||
if (rend->areTexturesSquare()) {
|
||||
ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square;
|
||||
}
|
||||
}
|
||||
if (!ImGui::GetIO().Fonts->Build()) {
|
||||
logE("error while building font atlas!");
|
||||
showError(_("error while loading fonts! please check your settings."));
|
||||
|
@ -6701,7 +6714,12 @@ bool FurnaceGUI::loop() {
|
|||
patFont=mainFont;
|
||||
bigFont=mainFont;
|
||||
headFont=mainFont;
|
||||
if (rend) rend->destroyFontsTexture();
|
||||
if (rend) {
|
||||
rend->destroyFontsTexture();
|
||||
if (rend->areTexturesSquare()) {
|
||||
ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square;
|
||||
}
|
||||
}
|
||||
if (!ImGui::GetIO().Fonts->Build()) {
|
||||
logE("error again while building font atlas!");
|
||||
} else {
|
||||
|
@ -6723,7 +6741,12 @@ bool FurnaceGUI::loop() {
|
|||
patFont=mainFont;
|
||||
bigFont=mainFont;
|
||||
headFont=mainFont;
|
||||
if (rend) rend->destroyFontsTexture();
|
||||
if (rend) {
|
||||
rend->destroyFontsTexture();
|
||||
if (rend->areTexturesSquare()) {
|
||||
ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square;
|
||||
}
|
||||
}
|
||||
if (!ImGui::GetIO().Fonts->Build()) {
|
||||
logE("error again while building font atlas!");
|
||||
} else {
|
||||
|
@ -7131,6 +7154,9 @@ bool FurnaceGUI::init() {
|
|||
applyUISettings();
|
||||
|
||||
logD("building font...");
|
||||
if (rend->areTexturesSquare()) {
|
||||
ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square;
|
||||
}
|
||||
if (!ImGui::GetIO().Fonts->Build()) {
|
||||
logE("error while building font atlas!");
|
||||
showError(_("error while loading fonts! please check your settings."));
|
||||
|
@ -7139,7 +7165,9 @@ bool FurnaceGUI::init() {
|
|||
patFont=mainFont;
|
||||
bigFont=mainFont;
|
||||
headFont=mainFont;
|
||||
if (rend) rend->destroyFontsTexture();
|
||||
if (rend) {
|
||||
rend->destroyFontsTexture();
|
||||
}
|
||||
if (!ImGui::GetIO().Fonts->Build()) {
|
||||
logE("error again while building font atlas!");
|
||||
}
|
||||
|
|
|
@ -1529,6 +1529,7 @@ class FurnaceGUIRender {
|
|||
virtual void drawOsc(float* data, size_t len, ImVec2 pos0, ImVec2 pos1, ImVec4 color, ImVec2 canvasSize, float lineWidth);
|
||||
virtual void present();
|
||||
virtual bool supportsDrawOsc();
|
||||
virtual bool areTexturesSquare();
|
||||
virtual bool getOutputSize(int& w, int& h);
|
||||
virtual int getWindowFlags();
|
||||
virtual int getMaxTextureWidth();
|
||||
|
|
|
@ -105,6 +105,10 @@ bool FurnaceGUIRender::supportsDrawOsc() {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool FurnaceGUIRender::areTexturesSquare() {
|
||||
return false;
|
||||
}
|
||||
|
||||
int FurnaceGUIRender::getWindowFlags() {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -469,6 +469,11 @@ void FurnaceGUIRenderDX9::setSwapInterval(int swapInt) {
|
|||
swapInterval=swapInt;
|
||||
}
|
||||
|
||||
// I would use caps but...
|
||||
bool FurnaceGUIRenderDX9::areTexturesSquare() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void FurnaceGUIRenderDX9::preInit(const DivConfig& conf) {
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ class FurnaceGUIRenderDX9: public FurnaceGUIRender {
|
|||
void clear(ImVec4 color);
|
||||
bool newFrame();
|
||||
bool canVSync();
|
||||
bool areTexturesSquare();
|
||||
void createFontsTexture();
|
||||
void destroyFontsTexture();
|
||||
void renderGUI();
|
||||
|
|
|
@ -225,6 +225,10 @@ int FurnaceGUIRenderGL1::getWindowFlags() {
|
|||
return SDL_WINDOW_OPENGL;
|
||||
}
|
||||
|
||||
bool FurnaceGUIRenderGL1::areTexturesSquare() {
|
||||
return true;
|
||||
}
|
||||
|
||||
int FurnaceGUIRenderGL1::getMaxTextureWidth() {
|
||||
return maxWidth;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ class FurnaceGUIRenderGL1: public FurnaceGUIRender {
|
|||
void clear(ImVec4 color);
|
||||
bool newFrame();
|
||||
bool canVSync();
|
||||
bool areTexturesSquare();
|
||||
void createFontsTexture();
|
||||
void destroyFontsTexture();
|
||||
void renderGUI();
|
||||
|
|
|
@ -5679,7 +5679,12 @@ void FurnaceGUI::commitSettings() {
|
|||
|
||||
applyUISettings();
|
||||
|
||||
if (rend) rend->destroyFontsTexture();
|
||||
if (rend) {
|
||||
rend->destroyFontsTexture();
|
||||
if (rend->areTexturesSquare()) {
|
||||
ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square;
|
||||
}
|
||||
}
|
||||
if (!ImGui::GetIO().Fonts->Build()) {
|
||||
logE("error while building font atlas!");
|
||||
showError(_("error while loading fonts! please check your settings."));
|
||||
|
@ -5688,7 +5693,12 @@ void FurnaceGUI::commitSettings() {
|
|||
patFont=mainFont;
|
||||
bigFont=mainFont;
|
||||
headFont=mainFont;
|
||||
if (rend) rend->destroyFontsTexture();
|
||||
if (rend) {
|
||||
rend->destroyFontsTexture();
|
||||
if (rend->areTexturesSquare()) {
|
||||
ImGui::GetIO().Fonts->Flags|=ImFontAtlasFlags_Square;
|
||||
}
|
||||
}
|
||||
if (!ImGui::GetIO().Fonts->Build()) {
|
||||
logE("error again while building font atlas!");
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue