Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch the OpenGL code to use VBOs instead of direct mode #17

Merged
merged 1 commit into from
Jul 10, 2020

Conversation

nikp123
Copy link
Owner

@nikp123 nikp123 commented Jun 4, 2020

This would not only improve performance, but will actually allow me to use GLSL shaders among other things.

@nikp123 nikp123 linked an issue Jun 4, 2020 that may be closed by this pull request
@nikp123
Copy link
Owner Author

nikp123 commented Jun 4, 2020

This obviously isn't ready yet, it will need some work (and extreme amounts of testing - you can't EVER be sure that it works)

My goal for now:

  • Is to make a functional renderer that works cross-platform - Windows and Linux (macOS if I manage to get my hands on it)
  • That my build system doesn't puke upon adding a new dependency (GLEW)
  • To add configuration options, which include specifying a shader file (fragment and vertex for "cool effects")
  • Add default shader files from which the user can poke around, preferably placed in in the config directory and included with the install environment (cmake + NSIS)

Also doesn't my project become GLava basically after these mods (except it has windows support)?

@nikp123 nikp123 self-assigned this Jun 4, 2020
@nikp123 nikp123 added the feature label Jun 4, 2020
@nikp123 nikp123 added this to the switch to VBO milestone Jun 4, 2020
@make-42
Copy link
Contributor

make-42 commented Jun 5, 2020

Yes, defining the shader files in the config would be pretty good. In the GLSL code, we need to access X.A.V.A. variables, it would be good if you could pass:

  • A function called data that we call with a float from 0 to 1 as an argument, it returns the bar height.
  • A float variable called time that is seconds since X.A.V.A. start.
  • A vec2 variable called resolution that is the screen resolution.
  • A float variable called bar_width that is the bar width.
  • A float variable called bar_spacing that is the bar spacing.
  • A float variable called bar_count that is the bar count.

If you have another idea of variables to pass, go ahead.
PS: This isn't GLava as it is cross-platform.

@make-42
Copy link
Contributor

make-42 commented Jun 5, 2020

Also while the code works it is less efficient in terms of video card usage

@make-42
Copy link
Contributor

make-42 commented Jun 5, 2020

Didn't build it properly, I'm good now, no shadows though...

@nikp123
Copy link
Owner Author

nikp123 commented Jun 23, 2020

Did some work on it, I figured out (somewhat) what to do. But there are so many annoying bugs to fix. (fxp. shader compilation failures, as OGL is asyncronous AF). And also the way that I deal with variables is backstabing me. I'm thinking of just making all major variables global, since having 3 different variables with the same name is driving me insane (messy code, i know).....

Will update as I go through on this.

@nikp123
Copy link
Owner Author

nikp123 commented Jun 23, 2020

But I think the first order of duty is to update the branch to mainline, since the removal of bar limits is causing seg. faults all over the place. Thank GDB for giving me insight about my variable issue.

@nikp123
Copy link
Owner Author

nikp123 commented Jun 23, 2020

Also your assumption is correct, shaders are expesive (in cycles) as it gets when it comes to code. Any slight change to the shader code can change the temps of the GPU from 40 to 80*C.

But I'm thinking of doing geometry inside of a shader, that'll give more flexibility to the developer/end-user (and possibly reduce the load). Only catch though: it's not EGL friendly.

@nikp123
Copy link
Owner Author

nikp123 commented Jun 23, 2020

Also those shaders (that you demonstrated) draw every single pixel, unlike real fragment shaders which are ran on every pixel that is occupied by a 2d raster of the final polygon.

@nikp123
Copy link
Owner Author

nikp123 commented Jun 23, 2020

Can I work around this by using two polygons that just cover the entire screen and use fragment shaders for the final image? (kinda hacky, but may work)

@make-42
Copy link
Contributor

make-42 commented Jun 23, 2020

Yeah, I think having 2 polygons that cover the screen is an idea worth exploring but the frag makers need to have an easy way to map the fragment shader to the screen.

@nikp123
Copy link
Owner Author

nikp123 commented Jun 30, 2020

update: the two polygon thing is working, I've managed to cram the entire renderer into a fragment shader that runs about 30 lines of code per pixel (not sure if it's bad or not)

comparing with the legacy OGL code it uses 20% more GPU, but it's not so bad as you get the complete flexibility of GLSL

However, uno problemo: GLSL had no way to put a dynamic array as an "uniform" variable up until OGL 4.0
So my workaround was to limit the bars to something absurdly high, such as 10000 bars. I did this because like 70% of all computers I ever used barely go above OGL 3.0, so I've did it like this in order to preserve compatibility.

@nikp123
Copy link
Owner Author

nikp123 commented Jun 30, 2020

Also the current shader I wrote is about 100 LoC and implements most features (80%) and works with the minimum version tag of 110 = OGL 2.0 minimum, which is ok compatibility IMO.

@make-42
Copy link
Contributor

make-42 commented Jun 30, 2020

Yup, sounds great, +20% GPU should be fine for most people.

@nikp123
Copy link
Owner Author

nikp123 commented Jun 30, 2020

Review this, and try to find bugs and other things (if you're willing to do so).
Anyway I think this is the polishing phase.

Just need to update the windows code as well, and do a bit of testing there before merging.

@nikp123
Copy link
Owner Author

nikp123 commented Jun 30, 2020

Anyway it wasn't 20% more it was more like triple, my benchmarking was flawed.
However I believe I can optimize the shader as the GPU isn't that good at doing logic (for which I rely heavily on)
So I believe more reliance on floats should help in any case.
Would writing inline code help as well?

Besides it's only 10% of my GPU (when I disable compositing ofc)

Also the conversion between ints and floats is expensive, so maybe it's that.

@make-42
Copy link
Contributor

make-42 commented Jun 30, 2020

Ok, I will test it ASAP, thanks!

@make-42
Copy link
Contributor

make-42 commented Jun 30, 2020

"xava" terminated by signal SIGSEGV (Adress boundary error), basically a segmentation fault...

@make-42
Copy link
Contributor

make-42 commented Jun 30, 2020

Also, shaders do not get copied over by install and it has to regenerate them in Ubuntu 20.04...
xava installs to /usr/local/bin/xava

@make-42
Copy link
Contributor

make-42 commented Jun 30, 2020

"xava" terminated by signal SIGSEGV (Adress boundary error), basically a segmentation fault...

Error is in src/config.c line 226, it does: assert(!(fragmentShader&&vertexShader));
So if you check the memory addresses instead it goes a bit further(assert(!(*fragmentShader&&*vertexShader));), so basically one of those vars is null...

@nikp123
Copy link
Owner Author

nikp123 commented Jun 30, 2020

Both should be non-NULL at that point... I have no idea what might be going on.

@nikp123
Copy link
Owner Author

nikp123 commented Jun 30, 2020

I mean look at the lines behind... it's just two mallocs!?!

@nikp123
Copy link
Owner Author

nikp123 commented Jun 30, 2020

Also it doesn't matter if the package is installed in /usror /usr/local as all hardcoded directory paths are generated on compile time, so if CMake built it for a PREFIX=/usr/local, all the functions would be using that.

@make-42
Copy link
Contributor

make-42 commented Jul 1, 2020

Gonna have to rebuild it on another PC to find out what is going on, in the meantime do you have a Windows build?

@nikp123
Copy link
Owner Author

nikp123 commented Jul 1, 2020

I have to work on it since I've changed the renderer code

@make-42
Copy link
Contributor

make-42 commented Jul 3, 2020

image
New system, different error...

@nikp123 nikp123 merged commit 5f720df into master Jul 10, 2020
@make-42
Copy link
Contributor

make-42 commented Jul 19, 2020

It works but there is no way to make another shader, in the config changing the shader variable does nothing.

@nikp123 nikp123 deleted the opengl-vbo branch July 17, 2021 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Glow bars...
2 participants