Gpu: OpenGL 4 implementation
I wrote an OpenGL implementation and fixed some bugs in SDL_gpu.c and spinning cube test. It is working:
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 (@inputvs@buffer(index)). It is the same in GLSL. We could also add a parameter toSDL_GpuDraw*().@inputshould 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_CLAMPTOZEROdoes not exit in OpenGL (maybe there is an extention?) -
SDL_GpuFillBuffer(), likememset(), 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
GetBackbufferandPresenttoo. I would simplify it a lot: user create a render texture, then callPresent()to tell: put that texture on that window. -
~Could we make
RenderPasspersistent? OpenGL currently create a framebuffer, to store render textures, inStartRenderPass(). 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.