{"id":40,"date":"2014-07-08T18:17:04","date_gmt":"2014-07-08T18:17:04","guid":{"rendered":"https:\/\/blogs.scummvm.org\/subr3v\/?p=40"},"modified":"2022-05-23T18:18:30","modified_gmt":"2022-05-23T18:18:30","slug":"tinygl-2d-blitting-api","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/subr3v\/2014\/07\/08\/tinygl-2d-blitting-api\/","title":{"rendered":"TinyGL 2D blitting API"},"content":{"rendered":"<p>In the past week I&#8217;ve been working on the design and implementation of the 2D rendering API that will be used as an extension to TinyGL.<br \/>\nI already listed all the features that I wanted to expose in the API and here&#8217;s the result:<\/p>\n<p>Blitting api header:<\/p>\n<pre>struct BlitTransform {\r\n\tBlitTransform(int dstX, int dstY);\r\n\tvoid sourceRectangle(int srcX, int srcY, int srcWidth, int srcHeight);\r\n\tvoid tint(float aTint, float rTint = 1.0f, float gTint = 1.0f, float bTint = 1.0f);\r\n\tvoid scale(int width, int height);\r\n\tvoid rotate(float rotation, float originX, float originY);\r\n\tvoid flip(bool verticalFlip, bool horizontalFlip);\r\n \r\n\tCommon::Rect _sourceRectangle;\r\n\tCommon::Rect _destinationRectangle;\r\n\tfloat _rotation;\r\n\tfloat _originX, _originY;\r\n\tfloat _aTint, _rTint, _gTint, _bTint;\r\n\tbool _flipHorizontally, _flipVertically;\r\n};\r\n \r\nstruct BlitImage;\r\n \r\nBlitImage *tglGenBlitImage();\r\nvoid tglUploadBlitImage(BlitImage *blitImage, const Graphics::Surface &amp;surface, uint32 colorKey, bool applyColorKey);\r\nvoid tglDeleteBlitImage(BlitImage *blitImage);\r\n \r\nvoid tglBlit(BlitImage *blitImage, const BlitTransform &amp;transform);\r\n \r\n\/\/ Disables blending explicitly.\r\nvoid tglBlitNoBlend(BlitImage *blitImage, const BlitTransform &amp;transform);\r\n \r\n\/\/ Disables blending, transforms and tinting.\r\nvoid tglBlitFast(BlitImage *blitImage, int x, int y);<\/pre>\n<p>The API is pretty simple but effective: it allows you to create and delete textures and to blit them. Its implementation under the hood is somewhat more involved: I only have a generic templated function that takes care of blitting, this function has a few parameters that allow me to skip some computation if they&#8217;re not needed (skipping pixel blending, sprite transformation or tinting etc).<\/p>\n<p>Since everything else is hidden the implementation can always be expanded and this can allow some aggressive optimizations like RLE encoding or just memcpy-ing the whole sprite if I know it&#8217;s totally opaque and blending is not enabled and so on.<\/p>\n<p>For the next week I will keep on refining the implementation to add all those optimized cases and I will also work into integrating this new API on the existing engines: some work has already been done on myst3 engine but there&#8217;s still a lot to do for the grim engine as it is way more complex compared to myst3.<\/p>\n<p>I will keep you updated in the next posts as I will probably post more updates this week, stay tuned!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the past week I&#8217;ve been working on the design and implementation of the 2D rendering API that will be used as an extension to TinyGL. I already listed all the features that I wanted to expose in the API and here&#8217;s the result: Blitting api header: struct BlitTransform { BlitTransform(int dstX, int dstY); void [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":3,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":43,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/posts\/40\/revisions\/43"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/subr3v\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}