this repo has no description
1# Introduction #
2
3This page contains notes that explain or argue the implementation details of the library. If you have anything to say about them, let us know!
4
5
6# Notes #
7
8Couldn't there be GPU\_BLEND\_NONE instead of GPU\_Image::use\_blending?
9> Yeah, that is what SDL2 does. However, I feel that the separation is a useful and intuitive convention. It separates "how" blending is done (blend mode) from "whether" it is done (use\_blending). To combine them would be to change the abstraction to "pixel transfer mode".
10
11Clearing new blank textures.
12> glClearTexImage() extension is very new, so not well supported.
13> Clearing via upload works but is a little slower.
14> > Allocate a zeroed array and grow it when more is needed.
15
16Rendering to intermediate buffer that has an odd dimension size will blur the result a little. I think the rule should be: If you want pixel-perfect, don't use odd sizes!
17
18GPU\_Init() sets an empty window caption. It's not a big deal to change after init by using target->context->window\_id, so adding stuff to SDL\_gpu to do it would just be unnecessary. Maybe GPU\_GetWindowID().
19
20Making every shape able to be textured would mean either a lot of assumptions about the texture coordinates or else a few extra function arguments to specify the texture coordinates and number of vertices to use (which would also lead to ambiguity). The current functions are only untextured and their number of vertices is not specified (which makes shader attributes not work reliably with them). The best way to texture shapes is to write your own textured shape functions using GPU\_TriangleBatch().
21
22Attributes
23
24> Don't try to use expanded (per-sprite) attributes for positions or texcoords... You would have 4 vertices on top of each other for each sprite.
25
26Shader blocks
27> Used to pass default shader variables (attributes and a uniform) to the shader.
28> Has 3 default attributes: position, color, texcoords. Has 1 default uniform: gpu\_ModelViewProjectionMatrix. These are handled by the blit buffer and flush.
29
30State contained in images:
31> Pixel descriptors
32> > width, height
33> > channels
34
35> Modulation color (GPU\_SetRGBA())
36> Blending on/off (GPU\_SetBlending())
37> Blend mode (GPU\_SetBlendMode())
38
39State contained in render targets:
40> Camera transform (via matrix stack for GL 3+)
41> Virtual width and height
42> Framebuffer width and height (duplicated from image or window)
43> Clipping rect
44> Modulation color (GPU\_SetTargetRGBA())
45
46State contained in context targets:
47> Current shader
48> Default shaders
49> Blit buffer
50> Window ID
51> Shape blending
52> Shape blend mode
53> Line thickness (GPU\_SetThickness())
54> GL Context (SDL\_GLContext is just a void`*`)
55> Matrix stack
56
57State contained in renderer:
58> Renderer ID
59> Renderer tier
60> Renderer features
61> Current context target
62
63Windowless OpenGL context would be useful for triggering renderer init failure, but it gets messy and platform-specific.
64
65FlushBlitBuffer() uses GL\_TRIANGLES instead of a fan or strip because a single glDrawArrays/glDrawElements call can't draw separate strips. Thankfully, I can use an index buffer to reduce the vertex count back to 4, instead of the 6 that two triangles would normally use.
66
67GLES does not support GL\_UNPACK\_ROW\_LENGTH, which is a shame. It means that if image data is not tightly-packed, it has to be re-copied into a tightly-packed array first. This makes the GL and GLES renderers do loading/updating images in slightly different ways. I think there's a GLES2 extension for it though, so that might be worth looking into.
68
69Multiple windows can be done in two ways:
70 1. GPU\_CreateTargetFromWindow() creates a separate context for rendering, shaders, and textures.
71> 2) GPU\_MakeCurrent() can be used to switch the window of a GPU\_Target in order to share a context between windows.
72> What about SDL\_GL\_SHARE\_WITH\_CURRENT\_CONTEXT?