Best way to draw special kind of image

Started by Cornix, August 09, 2013, 17:48:25

Previous topic - Next topic

Cornix

Hello again,
I am currently working on a way to display my own "windows" and fill them with buttons, labels, etc.
For the windowskin I need a very flexible design.
The entire windowskin is split into 9 areas and a window of any given size is drawn by putting these areas from the windowskin together; like a mosaic.
This is how a windowskin could for example look like:
A -> Corner
B -> Edge


And when the window is constructed from the given skin it should look like this:


Now the problem is, how would I do this the most efficient way.
I could just store each area of the windowskin in a VBO and draw them with brute force to fill the window. But this could become very heavy on the performance with some skins.
I could also create a separate VBO for every window which is created with the skin. Only problem is, the windows can get resized by the user in real time, so in the worst case I would have to upload new VBO's to the graphics card every single frame.

Maybe there is a way I havent thought about yet?

I would really appreciate any thoughts and suggestions, thank you alot.

quew8

You could try setting the viewport to the specific window you want to draw. For example with 9 "windows" in a 3 x 3 grid in a display 900 x 900 (realistic), for the bottom left window call glViewport(0, 0, 300, 300); before drawing the middle window call glViewport(300, 300, 300, 300); etc.

The viewport transform is actually more efficient than even the hugely optimized matrix transforms (since it doesn't use matrices) however I'm not sure about changing it 17 times every frame. Probably more efficient than updating 17 * 4 vertices each of 3 floats (assuming you use a single block texture) potentially per frame. But ultimately the only way to know for sure is to try it out.

Cornix

What about re-uploading vertex data? The windows shouldnt get resized too often, in a normal use case. (In the worst case however the user might go crazy with the windows and resize them every frame...)
I was thinking about using glBufferSubData(...) whenever possible and only make the VBO bigger when needed, but never smaller in case it gets resized again.

But thanks for the information about the glViewport, I didnt know that.