Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Rendering a GUI efficiently


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 ic0de   Members   -  Reputation: 895

Like
0Likes
Like

Posted 11 July 2013 - 10:07 AM

I did some profiling the other day and I found that drawing my gui over my 3d scene increased my frametime by up to 30%. I'm using GWEN for my gui but it allows you to write a custom renderer which I did. I used the same terrible techniques as the sample renderer but was able to squeeze out a little more performance by better integrating it into my engine which removed a few OpenGL calls. The problem with the renderer is that the way it works is that I basically get to derive a renderer class and rewrite a DrawTexturedRect function and that is the only way I can get geometry. In the sample implementation (and mine) It places two triangles to form a quad in a buffer on the cpu side when everything is finished drawing or the buffer is full it calls a flush function which uploads the buffer to the gpu and draws it, then the buffer is emptied. The problem is that this happens every frame and I have no way of knowing whether the geometry has actually changed between frames so I have no choice but to do everything all over again. So I was thinking of ways to change this awful setup while only being allowed to use DrawTexturedRect and I thought about instancing a single 1x1 quad (everthing is a quad with the same texcoords) and then scaling and translating it in the vertex shader. But unfortunately instanced rendering is only core in OpenGL 3.1+ and my minimum is GL 2.1 support where it is available as an extension (but probably not on intel cards). So my question boils down to is it faster to draw individual quads (one draw call per quad) that are already in the gpu memory or to use the terrible buffering solution? any other general GUI drawing advice would be appreciated as well. 


you know you program too much when you start ending sentences with semicolons;


Sponsor:

#2 froop   Members   -  Reputation: 636

Like
2Likes
Like

Posted 11 July 2013 - 10:59 AM

Gwen apparently supports caching (take a look at the ICacheToTexture interface in the base renderer). Unfortunately I haven't tried to implement it yet so I can't say anything about its usefulness.



#3 ic0de   Members   -  Reputation: 895

Like
2Likes
Like

Posted 11 July 2013 - 11:12 AM

Gwen apparently supports caching (take a look at the ICacheToTexture interface in the base renderer). Unfortunately I haven't tried to implement it yet so I can't say anything about its usefulness.

 

Hmm thats very interesting. Depending on how it works that may be ideal. Unfortunately none of the samples seem to use it.


Edited by ic0de, 11 July 2013 - 11:29 AM.

you know you program too much when you start ending sentences with semicolons;


#4 LorenzoGatti   Crossbones+   -  Reputation: 2737

Like
0Likes
Like

Posted 12 July 2013 - 02:04 AM

 

It places two triangles to form a quad in a buffer on the cpu side when everything is finished drawing or the buffer is full it calls a flush function which uploads the buffer to the gpu and draws it, then the buffer is emptied.

 
This waiting (draw other things, then draw GUI) might waste some parallelism.
Do you need normal 3D scene drawing while there is a dialog in front of it? A freeze frame (copy last frame to a texture, then draw it as a full-screen quad) should be cheaper.
Produci, consuma, crepa

#5 ic0de   Members   -  Reputation: 895

Like
0Likes
Like

Posted 12 July 2013 - 11:55 AM

This waiting (draw other things, then draw GUI) might waste some parallelism.

Do you need normal 3D scene drawing while there is a dialog in front of it? A freeze frame (copy last frame to a texture, then draw it as a full-screen quad) should be cheaper.

 

Unfortunately the 3D scene must remain dynamic while gui elements are being displayed.


you know you program too much when you start ending sentences with semicolons;


#6 clashie   Validating   -  Reputation: 479

Like
1Likes
Like

Posted 13 July 2013 - 03:06 AM

I dunno if it's optimal how I have my stuff set up, but I have a simple sprite batching class that I use to draw quads with. I don't really do anything special at all.

 

SpriteBatch manages the state, etc. It's really dead simple and really doesn't do that much work internally. Just tracking a few things, starting a new batch, finally issuing the draw call, etc. I pre-fill the index buffer and cap how large batches can get. Adding a sprite to the batch just needs a Rect for the position and another for the texture coordinates.

 

A batch is a simple struct like this

struct Batch
{
	Vertex2D*	verts;
	Texture*	texture;
	u32		numSprites;
	u32		numVerts;
	u32		numIndicies;
}; 

Then keep a vector of them. Batches hang around until you explicitly purge them, so once you add a bunch of quads, you don't need to re-add them and the only thing that needs to happen is the draw call (and prior memcpy() to push whatever batch verts to the underlying vertex buffer).

 

It's not fancy or super robust, but I don't see why I couldn't draw an entire UI with just one or two draw calls. Drawing thousands of textured quads costs practically nothing, and my framerate is still well into the thousands. What's GWEN doing that's taking so long?


Edited by clashie, 13 July 2013 - 03:07 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS