Celestia icon indicating copy to clipboard operation
Celestia copied to clipboard

Use array buffer for all drawing calls

Open levinli303 opened this issue 3 years ago • 14 comments

There are places where GL functions like glVertexAttribPointer are called with pointer address rather than offset. Might it be a good idea to replace all of them with array buffer when/if we are going to revamp the render engine some time?

I found out about this in WebGL that you have to always bind an array buffer, or they will just not render and log warning in the browser console.

As Emscripten supports WebGL and SDL, it is actually not hard to port to make a web version of Celestia. Screen Shot 2020-11-05 at 7 36 41 PM

levinli303 avatar Nov 05 '20 12:11 levinli303

Screen Shot 2020-11-05 at 8 28 00 PM

levinli303 avatar Nov 05 '20 12:11 levinli303

agree. this is a good idea, but straightforward replacement will kill performance. and actually emscripten supports this old mode, there is an option to enable it:

If your application renders geometry from client side memory, it will need to build with the linker flag -s FULL_ES2=1. This mode is convenient to ease porting of new codebases, however WebGL itself does not support rendering from client side memory, so this feature is emulated. For best performance, use VBOs instead and build without the -s FULL_ES2=1 linker flag.

375gnu avatar Nov 05 '20 15:11 375gnu

Screen Shot 2020-11-05 at 11 42 24 PM

@375gnu Great! now it actually works just like the other ES builds.

These are generating warning, I believe it is also happening at least on iOS build when validation is enabled. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texAddress); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texAddress); glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR_OES, bc);

And the other warnings are GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 0 which does not have call stack, and this warning is not showing in Safari.

levinli303 avatar Nov 05 '20 15:11 levinli303

GL_TEXTURE_BORDER_COLOR_OES

is not supported in pure GLES v2 (and hence WebGL 1.0). we need to check if it's mandatory, maybe we can live without it

375gnu avatar Nov 05 '20 16:11 375gnu

yeah and also GL_CLAMP_TO_BORDER_OES. I added defines with values from other platforms for the two to make it pass compile. Well just like the iOS build I don't see any problem so far.

levinli303 avatar Nov 05 '20 16:11 levinli303

With the recent changes, the WebGL port is much better now, still missing rectangles Screenshot 2023-01-28 at 22 50 54

levinli303 avatar Jan 28 '23 14:01 levinli303

so now we have 2 remaining pieces of code to update: rectangles and model drawing (index buffers) and then fix performance regressions caused by migration.

375gnu avatar Jan 30 '23 15:01 375gnu

Core is done in #1582. The only remaining piece is Celx::GL module.

375gnu avatar Feb 26 '23 11:02 375gnu

@levinli303 @ajtribick what do you think about hosting webgl port at celestia.space as an online demo?

375gnu avatar Feb 26 '23 11:02 375gnu

@levinli303 @ajtribick what do you think about hosting webgl port at celestia.space as an online demo?

sounds good. a key thing would be to get a tiny data ready for the use in web, as it wouldn't be good for it to be 300m. i have some small changes for it to be used in emscripten, which also need to be upstreamed.

levinli303 avatar Feb 27 '23 04:02 levinli303

i have updated the https://celestia.mobi/web to use the latest code and disabled FULL_ES2

levinli303 avatar Feb 28 '23 14:02 levinli303

nice. i have > 60 fps. there are some artifacts on saturn, perhaps due to missing CLAMP_TO_BORDER texture mode, but else seems to be good.

375gnu avatar Feb 28 '23 17:02 375gnu

nice. i have > 60 fps. there are some artifacts on saturn, perhaps due to missing CLAMP_TO_BORDER texture mode, but else seems to be good.

yeah error is logged into the browser console. Another thing is that I did not use libepoxy as i think it depends on dlopen (i suppose gl calls are compiled into the wasm file by default), and dlsym (symbols are not glXXX, but rather emscripten_glXXX). maybe we should support the use of direct GLES calls without libepoxy?

levinli303 avatar Mar 01 '23 02:03 levinli303

It should be possible, but we may need some extensions, but none of them is mandatory

375gnu avatar Mar 01 '23 08:03 375gnu