SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Gpu: OpenGL 4 implementation

Open meyraud705 opened this issue 2 years ago • 0 comments

I wrote an OpenGL implementation and fixed some bugs in SDL_gpu.c and spinning cube test. It is working:

output

But:

  • No multithreading support
  • ~No command buffer, every command is sent immediately to OpenGL~
  • It uses GLSL shader for now
  • No fences yet
  • There are others TODO and FIXME, take a look at the source

It requires OpenGL 4.6 for polygon offset clamp and uses Direct State Access from 4.5.

Change I made to the API:

  • Added SDL_SetGpuMesh(): Mesh buffer is declared differently from other buffer in shader (@input vs @buffer(index)). It is the same in GLSL. We could also add a parameter to SDL_GpuDraw*(). @input should also take an index to allow more than 1 buffer as mesh buffer.

Remark about the API:

  • Do we really need CPU buffer. I see there are implemented the same in metal and it is also the case in OpenGL. I think an usage flag on GPU buffer could work (SDL_GPU_BUFFER_USAGE_LOCKABLE_READ, SDL_GPU_BUFFER_USAGE_LOCKABLE_WRITE, ...).

  • SDL_GPUSAMPADDR_CLAMPTOZERO does not exit in OpenGL (maybe there is an extention?)

  • SDL_GpuFillBuffer(), like memset(), is only good to fill 0. OpenGL can convert clear value to internal format if you pass the internal buffer format.

  • I am not conviced about GetBackbuffer and Present too. I would simplify it a lot: user create a render texture, then call Present() to tell: put that texture on that window.

  • ~Could we make RenderPass persistent? OpenGL currently create a framebuffer, to store render textures, in StartRenderPass(). Creating a framebuffer is not a fast operation.~ We execute only 1 render pass at a time, all render passes can share the same framebuffer.

  • I complained about the lack of glUniform() equivalent in the past. I see now how you don't need it, you can forget about it.

meyraud705 avatar Dec 29 '23 12:12 meyraud705