Metal backend, part 10

This commit is contained in:
tildearrow 2024-04-14 19:39:43 -05:00
parent 53d71c798a
commit a4fe96954b
2 changed files with 25 additions and 1 deletions

View file

@ -24,6 +24,7 @@ struct FurnaceGUIRenderMetalPrivate;
class FurnaceGUIRenderMetal: public FurnaceGUIRender {
SDL_Renderer* sdlRend;
FurnaceGUIRenderMetalPrivate* priv;
bool swapIntervalSet;
public:
ImTextureID getTextureID(FurnaceGUITexture* which);
bool lockTexture(FurnaceGUITexture* which, void** data, int* pitch);
@ -35,6 +36,7 @@ class FurnaceGUIRenderMetal: public FurnaceGUIRender {
void setBlendMode(FurnaceGUIBlendMode mode);
void clear(ImVec4 color);
bool newFrame();
bool canVSync();
void createFontsTexture();
void destroyFontsTexture();
void renderGUI();
@ -42,6 +44,7 @@ class FurnaceGUIRenderMetal: public FurnaceGUIRender {
void present();
bool getOutputSize(int& w, int& h);
int getWindowFlags();
void setSwapInterval(int swapInterval);
void preInit();
bool init(SDL_Window* win, int swapInterval);
void initGUI(SDL_Window* win);
@ -49,5 +52,6 @@ class FurnaceGUIRenderMetal: public FurnaceGUIRender {
bool quit();
FurnaceGUIRenderMetal():
sdlRend(NULL),
priv(NULL) {}
priv(NULL),
swapIntervalSet(false) {}
};

View file

@ -130,6 +130,10 @@ bool FurnaceGUIRenderMetal::newFrame() {
return ImGui_ImplMetal_NewFrame(priv->renderPass);
}
bool FurnaceGUIRenderMetal::canVSync() {
return swapIntervalSet;
}
void FurnaceGUIRenderMetal::createFontsTexture() {
logI("Metal: createFontsTexture()");
ImGui_ImplMetal_CreateFontsTexture(priv->context.device);
@ -167,6 +171,15 @@ int FurnaceGUIRenderMetal::getWindowFlags() {
return 0;
}
void FurnaceGUIRenderMetal::setSwapInterval(int swapInterval) {
if (SDL_RenderSetVSync(sdlRend,(swapInterval>=0)?1:0)!=0) {
swapIntervalSet=false;
logW("tried to enable VSync but couldn't!");
} else {
swapIntervalSet=true;
}
}
void FurnaceGUIRenderMetal::preInit() {
SDL_SetHint(SDL_HINT_RENDER_DRIVER,"metal");
priv=new FurnaceGUIRenderMetalPrivate;
@ -180,6 +193,13 @@ bool FurnaceGUIRenderMetal::init(SDL_Window* win, int swapInterval) {
if (sdlRend==NULL) return false;
if (SDL_RenderSetVSync(sdlRend,(swapInterval>=0)?1:0)!=0) {
swapIntervalSet=false;
logW("tried to enable VSync but couldn't!");
} else {
swapIntervalSet=true;
}
logI("retrieving context...");
priv->context=(__bridge CAMetalLayer*)SDL_RenderGetMetalLayer(sdlRend);