gl_engine: revise target API for context managing

Issue: #3024
This commit is contained in:
Jinny You 2024-12-06 14:35:03 +09:00 committed by Hermet Park
parent 1cbc11cadd
commit 596de01b12
6 changed files with 9 additions and 7 deletions

View file

@ -349,7 +349,7 @@ struct GlWindow : Window
void resize() override void resize() override
{ {
//Set the canvas target and draw on it. //Set the canvas target and draw on it.
verify(static_cast<tvg::GlCanvas*>(canvas)->target(0, width, height, tvg::ColorSpace::ABGR8888S)); verify(static_cast<tvg::GlCanvas*>(canvas)->target(context, 0, width, height, tvg::ColorSpace::ABGR8888S));
} }
void refresh() override void refresh() override

View file

@ -218,7 +218,7 @@ void runGl()
auto canvas = unique_ptr<tvg::GlCanvas>(tvg::GlCanvas::gen()); auto canvas = unique_ptr<tvg::GlCanvas>(tvg::GlCanvas::gen());
// Pass the framebuffer id to the GlCanvas // Pass the framebuffer id to the GlCanvas
tvgexam::verify(canvas->target(glFbo.fbo, SIZE, SIZE, tvg::ColorSpace::ABGR8888S)); tvgexam::verify(canvas->target(context, glFbo.fbo, SIZE, SIZE, tvg::ColorSpace::ABGR8888S));
content(canvas.get()); content(canvas.get());
if (tvgexam::verify(canvas->draw())) { if (tvgexam::verify(canvas->draw())) {

View file

@ -1750,6 +1750,7 @@ public:
* This function specifies the drawing target where the rasterization will occur. It can target * This function specifies the drawing target where the rasterization will occur. It can target
* a specific framebuffer object (FBO) or the main surface. * a specific framebuffer object (FBO) or the main surface.
* *
* @param[in] context The GL context assigning to the current canvas rendering.
* @param[in] id The GL target ID, usually indicating the FBO ID. A value of @c 0 specifies the main surface. * @param[in] id The GL target ID, usually indicating the FBO ID. A value of @c 0 specifies the main surface.
* @param[in] w The width (in pixels) of the raster image. * @param[in] w The width (in pixels) of the raster image.
* @param[in] h The height (in pixels) of the raster image. * @param[in] h The height (in pixels) of the raster image.
@ -1763,7 +1764,7 @@ public:
* *
* @note Experimental API * @note Experimental API
*/ */
Result target(int32_t id, uint32_t w, uint32_t h, ColorSpace cs) noexcept; Result target(void* context, int32_t id, uint32_t w, uint32_t h, ColorSpace cs) noexcept;
/** /**
* @brief Creates a new GlCanvas object. * @brief Creates a new GlCanvas object.

View file

@ -519,6 +519,7 @@ TVG_API Tvg_Canvas* tvg_glcanvas_create(void);
* This function specifies the drawing target where the rasterization will occur. It can target * This function specifies the drawing target where the rasterization will occur. It can target
* a specific framebuffer object (FBO) or the main surface. * a specific framebuffer object (FBO) or the main surface.
* *
* @param[in] context The GL context assigning to the current canvas rendering.
* @param[in] id The GL target ID, usually indicating the FBO ID. A value of @c 0 specifies the main surface. * @param[in] id The GL target ID, usually indicating the FBO ID. A value of @c 0 specifies the main surface.
* @param[in] w The width (in pixels) of the raster image. * @param[in] w The width (in pixels) of the raster image.
* @param[in] h The height (in pixels) of the raster image. * @param[in] h The height (in pixels) of the raster image.
@ -530,7 +531,7 @@ TVG_API Tvg_Canvas* tvg_glcanvas_create(void);
* *
* @note Experimental API * @note Experimental API
*/ */
TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, int32_t id, uint32_t w, uint32_t h, Tvg_Colorspace cs); TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, void* context, int32_t id, uint32_t w, uint32_t h, Tvg_Colorspace cs);
/** \} */ // end defgroup ThorVGCapi_GlCanvas /** \} */ // end defgroup ThorVGCapi_GlCanvas

View file

@ -102,10 +102,10 @@ TVG_API Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer,
} }
TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, int32_t id, uint32_t w, uint32_t h, Tvg_Colorspace cs) TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, void* context, int32_t id, uint32_t w, uint32_t h, Tvg_Colorspace cs)
{ {
if (!canvas) return TVG_RESULT_INVALID_ARGUMENT; if (!canvas) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<GlCanvas*>(canvas)->target(id, w, h, static_cast<ColorSpace>(cs)); return (Tvg_Result) reinterpret_cast<GlCanvas*>(canvas)->target(context, id, w, h, static_cast<ColorSpace>(cs));
} }

View file

@ -41,7 +41,7 @@ GlCanvas::~GlCanvas()
} }
Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h, ColorSpace cs) noexcept Result GlCanvas::target(void* context, int32_t id, uint32_t w, uint32_t h, ColorSpace cs) noexcept
{ {
#ifdef THORVG_GL_RASTER_SUPPORT #ifdef THORVG_GL_RASTER_SUPPORT
if (cs != ColorSpace::ABGR8888S) return Result::NonSupport; if (cs != ColorSpace::ABGR8888S) return Result::NonSupport;