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

OpenGL #468

Draft
wants to merge 81 commits into
base: master
Choose a base branch
from
Draft

OpenGL #468

wants to merge 81 commits into from

Conversation

katajakasa
Copy link
Member

@katajakasa katajakasa commented Apr 22, 2023

WIP, do not merge.

Plan:

  1. Dump sprites to an RG8 texture atlas (R = color, G = alpha)
  2. Dump vertices and texture coords to a VBO
  3. Dump palettes and remappings to UBO(s) (or possibly consider 1D textures later for gotta go faster ?)
  4. Create an R8 texture and bind it to FBO, set FBO as target.
  5. Draw all objects. Shader should do any palette trickery now.
  6. Switch back to default FBO, and bind the previous render target texture.
  7. Ram the textuer through RGBA conversion with current palette.
  8. Run any upscaler shaders we want also (scalehqx, vhs, scanline, etc).
  9. Profit!

Notes:

  • Currently FBO size is 320x200, and we change the viewport to match that on fbo rendering phase. If/when we do sprite packs for larger sprites, we should bump the size. Perhaps some config option ?
  • When everything else works, consider using https://github.com/libretro/glsl-shaders for upscaling the result in rgba phase.

It might make sense to split the rendering into three, as the news caster guy wants images from arenas without the text and UI crap. So perhaps first render all game objects, then snatch any screenshots, and then draw the UI crap.

Cleanup TODO:

@katajakasa katajakasa force-pushed the ttv-use-opengl branch 5 times, most recently from 3667586 to fa3a964 Compare April 23, 2023 13:40
src/video/video.c Outdated Show resolved Hide resolved
@turol
Copy link

turol commented Apr 24, 2023

Prefer libepoxy over libglew. It supports GL ES too and starts up faster.

@katajakasa
Copy link
Member Author

Prefer libepoxy over libglew. It supports GL ES too and starts up faster.

Interesting, I will take a look. Glew is a total pain to maintain.

src/video/texture_atlas.c Outdated Show resolved Hide resolved
src/video/opengl/shaders.c Outdated Show resolved Hide resolved
@turol
Copy link

turol commented May 2, 2023

Reading from UBO with a varying offset might be a slow path. Use a texture instead. Either GL_TEXTURE_1D or a 2d texture with width or height of 1.

Using discard in shader is potentially a slow path. Prefer outputting fully transparent color instead.

@katajakasa katajakasa force-pushed the ttv-use-opengl branch 2 times, most recently from 02bb69f to 7ba8baf Compare May 2, 2023 15:13
@katajakasa
Copy link
Member Author

Reading from UBO with a varying offset might be a slow path. Use a texture instead. Either GL_TEXTURE_1D or a 2d texture with width or height of 1.

Using discard in shader is potentially a slow path. Prefer outputting fully transparent color instead.

Interesting. I added these on my future to-do list.

@turol
Copy link

turol commented May 3, 2023

@katajakasa
Copy link
Member Author

You probably want this: https://www.reddit.com/r/gamedev/comments/2j17wk/a_slightly_faster_bufferless_vertex_shader_trick/

Lol. On to the list it goes.

src/utils/io.c Show resolved Hide resolved
shaders/palette.frag Outdated Show resolved Hide resolved
src/engine.c Show resolved Hide resolved

for(int i = range_start; i <= range_end; i++) {
current = pal->data[i][0]; // Grayscale, r = g = b so pick any.
dist = current - ref;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to use squared distance.

Also, I don't feel like fixing it and we don't really need it anymore.
Different versions of clang-format handle these differently, so just silence it.
Screen captures for newsroom are still borked (for now).
We could precalc the conversion mapping etc. But hey, it works.
Not quite correct, more fixes needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants