mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
example: synchronize the canvas before the window pops up.
This ensures that the window pops up with the appropriate content, since windows can be popped up asynchronously with mainloop.
This commit is contained in:
parent
7145c66b00
commit
4c57a64a82
1 changed files with 28 additions and 33 deletions
|
@ -188,6 +188,17 @@ struct Window
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ready()
|
||||||
|
{
|
||||||
|
if (!example->content(Window::canvas, width, height)) return false;
|
||||||
|
|
||||||
|
//initiate the first rendering before window pop-up.
|
||||||
|
if (!verify(canvas->draw())) return false;
|
||||||
|
if (!verify(canvas->sync())) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void show()
|
void show()
|
||||||
{
|
{
|
||||||
SDL_ShowWindow(window);
|
SDL_ShowWindow(window);
|
||||||
|
@ -250,7 +261,6 @@ struct Window
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool ready() { return false; }
|
|
||||||
virtual void resize() {}
|
virtual void resize() {}
|
||||||
virtual void refresh() {}
|
virtual void refresh() {}
|
||||||
};
|
};
|
||||||
|
@ -269,22 +279,17 @@ struct SwWindow : Window
|
||||||
SwWindow(Example* example, uint32_t width, uint32_t height) : Window(tvg::CanvasEngine::Sw, example, width, height)
|
SwWindow(Example* example, uint32_t width, uint32_t height) : Window(tvg::CanvasEngine::Sw, example, width, height)
|
||||||
{
|
{
|
||||||
window = SDL_CreateWindow("ThorVG Example (Software)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE);
|
window = SDL_CreateWindow("ThorVG Example (Software)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE);
|
||||||
}
|
|
||||||
|
|
||||||
bool ready() override
|
|
||||||
{
|
|
||||||
//Create a Canvas
|
//Create a Canvas
|
||||||
canvas = tvg::SwCanvas::gen();
|
canvas = tvg::SwCanvas::gen();
|
||||||
if (!canvas) {
|
if (!canvas) {
|
||||||
cout << "SwCanvas is not supported. Did you enable the SwEngine?" << endl;
|
cout << "SwCanvas is not supported. Did you enable the SwEngine?" << endl;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::canvas = canvas.get();
|
Window::canvas = canvas.get();
|
||||||
|
|
||||||
resize();
|
resize();
|
||||||
|
|
||||||
return example->content(Window::canvas, width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize() override
|
void resize() override
|
||||||
|
@ -325,27 +330,22 @@ struct GlWindow : Window
|
||||||
#endif
|
#endif
|
||||||
window = SDL_CreateWindow("ThorVG Example (OpenGL/ES)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE);
|
window = SDL_CreateWindow("ThorVG Example (OpenGL/ES)", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE);
|
||||||
context = SDL_GL_CreateContext(window);
|
context = SDL_GL_CreateContext(window);
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~GlWindow()
|
|
||||||
{
|
|
||||||
SDL_GL_DeleteContext(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ready() override
|
|
||||||
{
|
|
||||||
//Create a Canvas
|
//Create a Canvas
|
||||||
canvas = tvg::GlCanvas::gen();
|
canvas = tvg::GlCanvas::gen();
|
||||||
if (!canvas) {
|
if (!canvas) {
|
||||||
cout << "GlCanvas is not supported. Did you enable the GlEngine?" << endl;
|
cout << "GlCanvas is not supported. Did you enable the GlEngine?" << endl;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::canvas = canvas.get();
|
Window::canvas = canvas.get();
|
||||||
|
|
||||||
resize();
|
resize();
|
||||||
|
}
|
||||||
|
|
||||||
return example->content(Window::canvas, width, height);
|
virtual ~GlWindow()
|
||||||
|
{
|
||||||
|
SDL_GL_DeleteContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize() override
|
void resize() override
|
||||||
|
@ -419,6 +419,17 @@ struct WgWindow : Window
|
||||||
surfaceDesc.nextInChain = (const WGPUChainedStruct*)&surfaceNativeDesc;
|
surfaceDesc.nextInChain = (const WGPUChainedStruct*)&surfaceNativeDesc;
|
||||||
surfaceDesc.label = "The surface";
|
surfaceDesc.label = "The surface";
|
||||||
surface = wgpuInstanceCreateSurface(instance, &surfaceDesc);
|
surface = wgpuInstanceCreateSurface(instance, &surfaceDesc);
|
||||||
|
|
||||||
|
//Create a Canvas
|
||||||
|
canvas = tvg::WgCanvas::gen();
|
||||||
|
if (!canvas) {
|
||||||
|
cout << "WgCanvas is not supported. Did you enable the WgEngine?" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Window::canvas = canvas.get();
|
||||||
|
|
||||||
|
resize();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~WgWindow()
|
virtual ~WgWindow()
|
||||||
|
@ -427,22 +438,6 @@ struct WgWindow : Window
|
||||||
wgpuInstanceRelease(instance);
|
wgpuInstanceRelease(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ready() override
|
|
||||||
{
|
|
||||||
//Create a Canvas
|
|
||||||
canvas = tvg::WgCanvas::gen();
|
|
||||||
if (!canvas) {
|
|
||||||
cout << "WgCanvas is not supported. Did you enable the WgEngine?" << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Window::canvas = canvas.get();
|
|
||||||
|
|
||||||
resize();
|
|
||||||
|
|
||||||
return example->content(Window::canvas, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void resize() override
|
void resize() override
|
||||||
{
|
{
|
||||||
//Set the canvas target and draw on it.
|
//Set the canvas target and draw on it.
|
||||||
|
|
Loading…
Add table
Reference in a new issue