diff --git a/examples/Example.h b/examples/Example.h index d61c7e35..02f22075 100644 --- a/examples/Example.h +++ b/examples/Example.h @@ -344,7 +344,7 @@ struct GlWindow : Window void resize() override { //Set the canvas target and draw on it. - verify(static_cast(canvas)->target(0, width, height)); + verify(static_cast(canvas)->target(0, width, height, tvg::ColorSpace::ABGR8888S)); } void refresh() override diff --git a/examples/MultiCanvas.cpp b/examples/MultiCanvas.cpp index 7b4c2745..255e0f37 100644 --- a/examples/MultiCanvas.cpp +++ b/examples/MultiCanvas.cpp @@ -218,7 +218,7 @@ void runGl() auto canvas = unique_ptr(tvg::GlCanvas::gen()); // Pass the framebuffer id to the GlCanvas - tvgexam::verify(canvas->target(glFbo.fbo, SIZE, SIZE)); + tvgexam::verify(canvas->target(glFbo.fbo, SIZE, SIZE, tvg::ColorSpace::ABGR8888S)); content(canvas.get()); if (tvgexam::verify(canvas->draw())) { diff --git a/inc/thorvg.h b/inc/thorvg.h index 2e8848c9..1a12b4c5 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -1732,6 +1732,7 @@ public: * @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] h The height (in pixels) of the raster image. + * @param[in] cs Specifies how the pixel values should be interpreted. Currently, it only allows @c ColorSpace::ABGR8888S as @c GL_RGBA8. * * @retval Result::InsufficientCondition if the canvas is performing rendering. Please ensure the canvas is synced. * @retval Result::NonSupport In case the gl engine is not supported. @@ -1739,10 +1740,9 @@ public: * @see Canvas::viewport() * @see Canvas::sync() * - * @note Currently, this only allows the GL_RGBA8 color space format. * @note Experimental API */ - Result target(int32_t id, uint32_t w, uint32_t h) noexcept; + Result target(int32_t id, uint32_t w, uint32_t h, ColorSpace cs) noexcept; /** * @brief Creates a new GlCanvas object. diff --git a/src/bindings/capi/thorvg_capi.h b/src/bindings/capi/thorvg_capi.h index e0914319..0d3b31a0 100644 --- a/src/bindings/capi/thorvg_capi.h +++ b/src/bindings/capi/thorvg_capi.h @@ -522,15 +522,15 @@ TVG_API Tvg_Canvas* tvg_glcanvas_create(void); * \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] h The height (in pixels) of the raster image. +* \param[in] cs Specifies how the pixel values should be interpreted. Currently, it only allows @c TVG_COLORSPACE_ABGR8888S as @c GL_RGBA8. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_INSUFFICIENT_CONDITION if the canvas is performing rendering. Please ensure the canvas is synced. * \retval TVG_RESULT_NOT_SUPPORTED In case the gl engine is not supported. * -* \note Currently, this only allows the GL_RGBA8 color space format. * \note Experimental API */ -TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, int32_t id, uint32_t w, uint32_t h); +TVG_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, int32_t id, uint32_t w, uint32_t h, Tvg_Colorspace cs); /** \} */ // end defgroup ThorVGCapi_GlCanvas diff --git a/src/bindings/capi/tvgCapi.cpp b/src/bindings/capi/tvgCapi.cpp index 1481f04d..c9457114 100644 --- a/src/bindings/capi/tvgCapi.cpp +++ b/src/bindings/capi/tvgCapi.cpp @@ -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_API Tvg_Result tvg_glcanvas_set_target(Tvg_Canvas* canvas, int32_t id, uint32_t w, uint32_t h, Tvg_Colorspace cs) { if (!canvas) return TVG_RESULT_INVALID_ARGUMENT; - return (Tvg_Result) reinterpret_cast(canvas)->target(id, w, h); + return (Tvg_Result) reinterpret_cast(canvas)->target(id, w, h, static_cast(cs)); } diff --git a/src/renderer/tvgGlCanvas.cpp b/src/renderer/tvgGlCanvas.cpp index 847a6ba6..08f41f6b 100644 --- a/src/renderer/tvgGlCanvas.cpp +++ b/src/renderer/tvgGlCanvas.cpp @@ -59,9 +59,11 @@ GlCanvas::~GlCanvas() } -Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h) noexcept +Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h, ColorSpace cs) noexcept { #ifdef THORVG_GL_RASTER_SUPPORT + if (cs != ColorSpace::ABGR8888S) return Result::NonSupport; + if (Canvas::pImpl->status != Status::Damaged && Canvas::pImpl->status != Status::Synced) { return Result::InsufficientCondition; }