Text using Cg

I’m working on an alternative way to display and edit text, which would allow adding and removing (very) large chunks of text fast without having to sacrifice framerate.

I would like to ask you guys to test it and, assuming it runs, provide feedback on the performance. Please also provide information about your OS and graphics card, especially if you experience any problems.

I’m especially interested in whether you experience any lag when adding large amounts of text (press F1 to do that). That’s what the animation in the background is for.

Requires Panda 1.8 (devel)

What works:
    Letters (ascii, upper and lower case),
    Digits,
    Punctuation,
    Space,
    Enter,
    Backspace,
    Delete,
    Arrow keys,
    Line wrap,
    Home & End,
    Multi line editing,

What doesn't work:
    Tab,
    Text wrap without breaking words,

Limitations:
    Mono font only and only supports a premade font texture

Grab the newest version here:
dl.dropbox.com/u/196274/experime … Text4a.zip

Update 3:
Fixed some issues with multi line editing, the cursor behaved incorrectly in certain places in the text. Now it should be fine.

Update 2:
I’ve managed to remove the need for lots of shader inputs by moving the texture coordinate calculation into the shader. I’m not sure if it made it any slower or any faster, but it definitely made it easier to maintain and develop (it’s a lot shorter now) and I hope it’ll allow it to work where it refused to work before.

Theoretically, it could also allow support for more characters than just ascii, but I’m not gonna get into that just yet.

Additionally, this update brings better support for multiline editing (although it’s still slow for key repeat) and support for punctuation and home/end keys.

Update:
Nemesis#13’s bug report pointed me at a large performance bottleneck in the first shader implementation, which (I think) also caused it not to work in some cases. Now the framerate is around twice that of testText and testText2 and comes close to that of flattened TextNode, at least on my system. Thanks :).

The framerate drops on key repeat persist in this version.

Older versions:
dl.dropbox.com/u/196274/experime … tText4.zip
dl.dropbox.com/u/196274/experime … tText3.zip
dl.dropbox.com/u/196274/experiments/testText.zip
dl.dropbox.com/u/196274/experime … tText2.zip

Thanks in advance

Coppertop

I was getting ~200 FPS on a GTX 260, Win-7, i2500k. It ran well, I was able to type quite a bit, but eventually it crashed with an assertion error to PNMImage. (Forgot to save the error. sorry!)

Thanks zhao. The performance seems good, given how many character slots there are.

No problem about that particular error – I don’t check the length of the text yet, so it probably just tried to add more text than the texture could hold (that could happen easily if you repeatedly tapped F1).

All I can see is a rotating smiley. No text at all.
My laptop:
Graphics: Intel GMA 4500
CPU: Intel Pentium Dual Core 2 * 2,200 Ghz

Here’s the output:

DirectStart: Starting the game.
Known pipe types:
  glxGraphicsPipe
(all display modules loaded.)
:display:glxdisplay(warning): No suitable FBConfig contexts available; using XVisual only.
depth_bits=24 color_bits=24 alpha_bits=8 stencil_bits=8 back_buffers=1 force_hardware=1 
  index 0.0 2.0 texcoords 0.0 0.0078125 0.0 1.0
0 index 2.0 4.0 texcoords 0.0078125 0.015625 0.0 1.0
1 index 4.0 6.0 texcoords 0.015625 0.0234375 0.0 1.0
2 index 6.0 8.0 texcoords 0.0234375 0.03125 0.0 1.0
3 index 8.0 10.0 texcoords 0.03125 0.0390625 0.0 1.0
4 index 10.0 12.0 texcoords 0.0390625 0.046875 0.0 1.0
5 index 12.0 14.0 texcoords 0.046875 0.0546875 0.0 1.0
6 index 14.0 16.0 texcoords 0.0546875 0.0625 0.0 1.0
7 index 16.0 18.0 texcoords 0.0625 0.0703125 0.0 1.0
8 index 18.0 20.0 texcoords 0.0703125 0.078125 0.0 1.0
9 index 20.0 22.0 texcoords 0.078125 0.0859375 0.0 1.0
a index 22.0 24.0 texcoords 0.0859375 0.09375 0.0 1.0
b index 24.0 26.0 texcoords 0.09375 0.1015625 0.0 1.0
c index 26.0 28.0 texcoords 0.1015625 0.109375 0.0 1.0
d index 28.0 30.0 texcoords 0.109375 0.1171875 0.0 1.0
e index 30.0 32.0 texcoords 0.1171875 0.125 0.0 1.0
f index 32.0 34.0 texcoords 0.125 0.1328125 0.0 1.0
g index 34.0 36.0 texcoords 0.1328125 0.140625 0.0 1.0
h index 36.0 38.0 texcoords 0.140625 0.1484375 0.0 1.0
i index 38.0 40.0 texcoords 0.1484375 0.15625 0.0 1.0
j index 40.0 42.0 texcoords 0.15625 0.1640625 0.0 1.0
k index 42.0 44.0 texcoords 0.1640625 0.171875 0.0 1.0
l index 44.0 46.0 texcoords 0.171875 0.1796875 0.0 1.0
m index 46.0 48.0 texcoords 0.1796875 0.1875 0.0 1.0
n index 48.0 50.0 texcoords 0.1875 0.1953125 0.0 1.0
o index 50.0 52.0 texcoords 0.1953125 0.203125 0.0 1.0
p index 52.0 54.0 texcoords 0.203125 0.2109375 0.0 1.0
q index 54.0 56.0 texcoords 0.2109375 0.21875 0.0 1.0
r index 56.0 58.0 texcoords 0.21875 0.2265625 0.0 1.0
s index 58.0 60.0 texcoords 0.2265625 0.234375 0.0 1.0
t index 60.0 62.0 texcoords 0.234375 0.2421875 0.0 1.0
u index 62.0 64.0 texcoords 0.2421875 0.25 0.0 1.0
v index 64.0 66.0 texcoords 0.25 0.2578125 0.0 1.0
w index 66.0 68.0 texcoords 0.2578125 0.265625 0.0 1.0
x index 68.0 70.0 texcoords 0.265625 0.2734375 0.0 1.0
y index 70.0 72.0 texcoords 0.2734375 0.28125 0.0 1.0
z index 72.0 74.0 texcoords 0.28125 0.2890625 0.0 1.0
A index 74.0 76.0 texcoords 0.2890625 0.296875 0.0 1.0
B index 76.0 78.0 texcoords 0.296875 0.3046875 0.0 1.0
C index 78.0 80.0 texcoords 0.3046875 0.3125 0.0 1.0
D index 80.0 82.0 texcoords 0.3125 0.3203125 0.0 1.0
E index 82.0 84.0 texcoords 0.3203125 0.328125 0.0 1.0
F index 84.0 86.0 texcoords 0.328125 0.3359375 0.0 1.0
G index 86.0 88.0 texcoords 0.3359375 0.34375 0.0 1.0
H index 88.0 90.0 texcoords 0.34375 0.3515625 0.0 1.0
I index 90.0 92.0 texcoords 0.3515625 0.359375 0.0 1.0
J index 92.0 94.0 texcoords 0.359375 0.3671875 0.0 1.0
K index 94.0 96.0 texcoords 0.3671875 0.375 0.0 1.0
L index 96.0 98.0 texcoords 0.375 0.3828125 0.0 1.0
M index 98.0 100.0 texcoords 0.3828125 0.390625 0.0 1.0
N index 100.0 102.0 texcoords 0.390625 0.3984375 0.0 1.0
O index 102.0 104.0 texcoords 0.3984375 0.40625 0.0 1.0
P index 104.0 106.0 texcoords 0.40625 0.4140625 0.0 1.0
Q index 106.0 108.0 texcoords 0.4140625 0.421875 0.0 1.0
R index 108.0 110.0 texcoords 0.421875 0.4296875 0.0 1.0
S index 110.0 112.0 texcoords 0.4296875 0.4375 0.0 1.0
T index 112.0 114.0 texcoords 0.4375 0.4453125 0.0 1.0
U index 114.0 116.0 texcoords 0.4453125 0.453125 0.0 1.0
V index 116.0 118.0 texcoords 0.453125 0.4609375 0.0 1.0
W index 118.0 120.0 texcoords 0.4609375 0.46875 0.0 1.0
X index 120.0 122.0 texcoords 0.46875 0.4765625 0.0 1.0
Y index 122.0 124.0 texcoords 0.4765625 0.484375 0.0 1.0
Z index 124.0 126.0 texcoords 0.484375 0.4921875 0.0 1.0
Text len 14011
:gobj(error): text.sha: (171) : error C6016: Profile requires arrays with non-constant indexes to be uniform

Do you want me to set gobj notifier to debug?

No, thanks, there’s no such need. The error is in the shader. I used a very suboptimal way of doing things, which apparently also caused it to not work at all in your case.

I’ve uploaded a new version, which should work for you, and if it does, I’m very interested in the performance on your GPU. It should also be way faster for everybody else. At least that’s what my tests suggest (the framerate doubled for me).

Enter Captain Low End!
Athlon XP 2000+ (1.67 GHz), 1GB RAM, GeForce 6200

version 3 runs at 0.7 FPS :smiley:

Wezu, I’m afraid that’s below my target hardware… :frowning: The good information for me is that it runs at all on that card, even below 1 FPS.

In case anyone’s interested, I’ve also been informed that it runs at ~65 FPS with a screen full of text on a GF 102M. Which is acceptable for that card, I think.

Still no visible text.

:gobj(error): Cg program too complex for driver: text.sha. Try choosing a different profile

You probably need to put “basic-shaders-only #f” in your Config.prc file.

Basic shaders only is disabled in the code.

Nemesis#13, what OS are you on?

I’m afraid it might actually be too complex. The GMA is not exactly the most shader friendly environment and that shader is not very subtle. It has a whole lot of inputs, so maybe the driver has a problem with that? There’s not much other stuff in there that could cause this kind of issues.

Can you run other, more standard shaders on that GPU? Like normal mapping or shadows from Panda’s Autoshader?

EDIT
I’m now in the process of removing the need for so many shader inputs, which was kinda of ugly brute force (good for proof of concept, not so much for the real thing). Stay tuned :wink:.

New version has just been published. Nemesis#13, if I was right about the cause of the shader not working for you, now it should work.

Nice work.

1500 fps here.

Edit: I lose 100 fps for one key stroke. Goes down to 4 fps if I let key pushed (aaaaaaa). Gtx 260, Ubuntu 10.10.

Thanks for testing Manou!

The difference between 1500 FPS and 1400 FPS is just 0.00004 SPF, so that’s very good imho. But I really have to work on that key repeat stuff ;D. I’ll get to that.