The Code Kingdom

viva la programmers!

Skip to content

Some questions about canvas

Everything but the kitchen sink! [Off-Topic]

Some questions about canvas

Postby entelin » Thu Jun 18, 2009 7:29 am

Firstly I'd like to link this question:
http://www.ogre3d.org/forums/viewtopic.php?f=2&t=50711&p=344775#p344775

Next, is there any way of arbitrarily setting the depth on quads within a canvas? or is it by render order only? I am working on taking canvas apart and reassembling it to understand better how to create my own renderables.

Thanks for the great code, its useful not to have something hugely featured to work with / learn from. I made my own gui using overlays, only to realize once I got way into it that the overlay system sucks and really cant be used for anything remotely complicated, the performance just dies.

Basically my intention is to have 3 textures, the first containing bitmap fonts or possibly something similar to how atlas does it, the second containing the skin that makes up the gui, and the third would be for arbitrary graphics, icons and such which could be drawn to, and wouldn't invalidate texture coords that are in use. I'd like to be able to keep track of the quads that make up each window, so that I could then adjust their Z order to keep them infront or behind each other. So any words of wisdom on that subject would be much appreciated.

heres a screenshot of my old gui http://logicaldreams.net/images/stories/rpge5/beach22.png, yes thats all overlays, sad isn't it?

Thanks

entelin
 
Posts: 2
Joined: Thu Jun 18, 2009 6:56 am


Re: Some questions about canvas

Postby adam » Sun Jun 21, 2009 8:11 am

I've responded to your first question at the Ogre3D forum.

As for your second question, it doesn't support it natively but you could add it yourself. Canvas maintains an internal list of quads ("quadList" member variable) whose order determines the z-order (or depth) of a quad. If you really wanted to, you could modify some of the draw_____ API calls so you can specify a z-order and then sort those quads by z-order in Canvas::updateGeometry.

You're welcome, I'm glad my little rendering library has been useful for you.

If you wish to accommodate multiple atlases/textures, you should first be aware that every time you switch textures in a list of quads it will require another batch call.

For example: say you had a bunch of quads layered one on top of each other with textures "A" and "B", with an order of: AAABAABBBBAAABBAABAAAABA

Even though you only have two unique texture-atlases, you've suddenly increased your batch count to 11! This is why I pack all of the assets (glyphs and images) as tightly as I can into a single atlas so I can avoid crazy batching calls.

However, I do concede that this is not realistic for every scenario-- especially for applications that tend to have a large number of image assets (for example, RPGs and icons for items), it's just not feasible to pack all of them into a single texture.

For these cases, you might be able to build a system on top of Canvas that allows you to reference multiple atlases. I would recommend putting your most commonly used assets into a single Atlas (common fonts and user-interface elements) and then arbitrarily creating other Atlases for other groups of assets. You can then maintain a pool of Canvas elements to use for each batch of draw calls with a different Atlas.

Here's some pseudo-code for "MultiCanvas", a special class that allows you to draw from multiple atlases by maintaining a pool of Canvases and switching between them for each batch:

Code: Select all
void MultiCanvas::drawRectangle(int x, int y, int width, int height, const Fill& fill, const Border& border, Atlas* atlas)
{
   // If the texture-atlas changed since the last draw call,
   // switch to a new canvas, effectively creating a new batch
   if(atlas != currentAtlas)
   {
      currentCanvas = getOrCreateCanvasFromPool(atlas, canvasZOrder++);
      currentAtlas = atlas;
   }
   
   currentCanvas->drawRectangle(x, y, width, height, fill, border);
}

Canvas* MultiCanvas::getOrCreateCanvasFromPool(Atlas* atlas, int canvasZOrder)
{
   std::vector<Canvas*>::iterator i = canvasPool.findEmptyCanvas();
   
   // If there is an empty Canvas in the pool
   // change its z-order and atlas and return the canvas
   if(i != canvasPool.end())
   {
      (*i)->setZOrder(canvasZOrder);
      (*i)->setAtlas(atlas);
      
      return *i;
   }
   else
   {
      Canvas* canvas = new Canvas(atlas, canvasZOrder);
      canvasPool.push_back(canvas);
      
      return canvas;
   }
}


You will need to modify Canvas.h/Canvas.cpp so that you can set each Canvas's global z-order (set renderQueueID to Ogre::RENDER_QUEUE_OVERLAY + zOrder) and change its Atlas at runtime.
User avatar
adam
Site Admin
 
Posts: 191
Joined: Tue Feb 03, 2009 11:05 pm

Re: Some questions about canvas

Postby entelin » Sun Jun 21, 2009 6:44 pm

Thanks for the great reply, I will chew on this for awhile.

entelin
 
Posts: 2
Joined: Thu Jun 18, 2009 6:56 am

Re: Some questions about canvas

Postby toglia » Mon Nov 23, 2009 4:17 pm

Hi ajs15822, I have been using your Canvas lib since I saw it in "the Player Demo", I find it to be sweet for replacing my overlays sometimes... But right now I'm finding it difficult to display the canvas when a compositor effect is applied to the screen, do you know why is this?

The compositor I'm using is the blurred glow:
http://www.ogre3d.org/forums/viewtopic.php?t=52316

Thanks for you help! :D

toglia
 
Posts: 2
Joined: Sat Aug 08, 2009 2:47 am


Return to The Kitchen Sink

Who is online

Users browsing this forum: No registered users and 1 guest