I’ve done a bit of refactoring of my UI code and brought it down a few hundred lines of code.
I’ve also started noting the performance. Right now, a window with a table and a bit of text and another window with just text gets me around 500-550 fps. This is from a base of about 2500 (if nothing is being drawn to the screen).
I have no idea if this is acceptable or not. In contrast, my scene with a sun and an earth runs at about 200-250 fps. The thing is; I’m doing things in the most inefficient way.
So; I put some work into speeding up the code. Everything in the UI uses a single shader for one. Next is to get everything to use a single VBO; it’s not doing that now because my text quads are drawn with position info in the vertices, whereas everything else uses a translation and scale matrix to define the position.
If they both use the translation matrix, I can remove any need to bind different buffers between calls. This should make things faster.
Also, everything at the moment binds it’s texture. However everything uses the same texture (except text); so I may be able to remove the
glBindTexture calls for a lot of the time. Probably via a texture manager or something.
If it’s still not fast enough; I’ve been reading about instance drawing and also about using textures to hold position info (R,G is x,y and B,A is w,h). I think I can combine these so that my
gl_InstanceID in the vertex shader is my lookup into the texture of position info. I’d probably also need a second texture to hold UV coords seeing as these don’t change much either (textures rather than providing a lookup array to the shader, only because that would need to be updated and passed each frame anyway).
I’m pretty sure I’m now 99% complete with the scrolling boxes. There were a couple of bugs; one which was interesting.
Because the box essentially draws its contents onto a render texture, the render texture created is the size of the screen. Then, as the box is scrolled, basically the region of this texture that’s then drawn to the boxes quad is updated.
What I found was that I was drawing the contents at normal window position on this texture. So a box close to the edge of the screen would result in the contents being partially drawn offscreen. Which is fine. Until you scroll and then the “region” of the texture you’re drawing is actually not on the texture. Graphical glitch.
Easy fix was to just draw to 0,0 on the texture and accommodate this in the region calculation. It also means that I can use a much smaller texture; probably the size of the widget contents. However, there would be a problem if that widget changed it’s size, I would then need to regenerate the texture, or resize it; and I’m concerned about the overhead needed. For now the screen dimensions cover all possible cases, so I’m using it until there’s performance problems.
I’ve also enabled mouse wheel and touch-pad scrolling via SDL2. So that’s pretty handy, makes it much more usable. I’m basically trying to recreate everything that people are used to.
The UI is coming along nicely (I need to work out how to do animated gifs to show stuff off). It’s widget based with a good input handling system, I just need to work on using several textured quads so that the windows can be styled nicely.
I’ve also done a bit of work with post-processing effect shaders to produce a glow on the more luminous areas. Here’s a couple of screenshots showing the sun from the perspective of an Earth and the result of the reflection of sunlight over the desert (it’s not quite right over the ocean yet, so still need to work on that).
I’ve spent the last couple days trying to work out view-space vs world-space and how to incorporate lights into my shaders. It’s been difficult. The concept of a View space vs World space and when to use which is not a simple one.
Anyway, I now have materials with specular maps and diffuse maps (and a fallback to color when diffuse isn’t provided). My shaders are all working correctly and producing the lighting effects. I’ve also added a arcball type of camera only because I needed to see the lighting move around in real time.