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

Implemented font atlas support for the renderer text engine #386

Merged
merged 4 commits into from
Oct 1, 2024

Conversation

slouken
Copy link
Collaborator

@slouken slouken commented Sep 30, 2024

This turns most text drawing into a single draw call.

@sezero
Copy link
Contributor

sezero commented Sep 30, 2024

src/SDL_renderer_textengine.c: In function 'ResolveMissingGlyphs':
src/SDL_renderer_textengine.c:386: warning: passing argument 4 of 'SDL_qsort_r' from incompatible pointer type
/tmp/SDL3/include/SDL3/SDL_stdinc.h:1382: note: expected 'SDL_CompareCallback_r' but argument is of type 'int (*)(const void *, const void *, const void *)'
src/SDL_renderer_textengine.c: In function 'CreateMissingGlyphs':
src/SDL_renderer_textengine.c:459: warning: passing argument 4 of 'SDL_qsort_r' from incompatible pointer type
/tmp/SDL3/include/SDL3/SDL_stdinc.h:1382: note: expected 'SDL_CompareCallback_r' but argument is of type 'int (*)(const void *, const void *, const void *)'
src/SDL_renderer_textengine.c: At top level:
src/stb_rect_pack.h:229: warning: ‘stbrp_setup_heuristic’ defined but not used

@sezero
Copy link
Contributor

sezero commented Sep 30, 2024

Trivial build fix for sort callback:

diff --git a/src/SDL_renderer_textengine.c b/src/SDL_renderer_textengine.c
--- a/src/SDL_renderer_textengine.c
+++ b/src/SDL_renderer_textengine.c
@@ -86,5 +86,5 @@ typedef struct TTF_RendererTextEngineData
 
 
-static int SDLCALL SortMissing(const void *userdata, const void *a, const void *b)
+static int SDLCALL SortMissing(void *userdata, const void *a, const void *b)
 {
     const TTF_DrawOperation *ops = (const TTF_DrawOperation *)userdata;

Didn't touch stb header. (Its permissions need changing to 0644, btw...)

@slouken
Copy link
Collaborator Author

slouken commented Sep 30, 2024

Fixed!

@sezero
Copy link
Contributor

sezero commented Sep 30, 2024

About stb_rect_pack.h: There is this open PR at mainstream you might want to include.

@sezero
Copy link
Contributor

sezero commented Oct 1, 2024

You may also want to do this:

diff --git a/src/SDL_renderer_textengine.c b/src/SDL_renderer_textengine.c
index 9b707e4..4aa1093 100644
--- a/src/SDL_renderer_textengine.c
+++ b/src/SDL_renderer_textengine.c
@@ -29,4 +29,5 @@
 #define STBRP_SORT SDL_qsort
 #define STBRP_ASSERT SDL_assert
+#define STBRP__CDECL SDLCALL
 #include "stb_rect_pack.h"
 
diff --git a/src/stb_rect_pack.h b/src/stb_rect_pack.h
index 6a633ce..099b132 100644
--- a/src/stb_rect_pack.h
+++ b/src/stb_rect_pack.h
@@ -216,9 +216,14 @@ struct stbrp_context
 #ifdef _MSC_VER
 #define STBRP__NOTUSED(v)  (void)(v)
-#define STBRP__CDECL       __cdecl
 #else
 #define STBRP__NOTUSED(v)  (void)sizeof(v)
+#endif
+#ifndef STBRP__CDECL
+#ifdef _MSC_VER
+#define STBRP__CDECL       __cdecl
+#else
 #define STBRP__CDECL
 #endif
+#endif /* STBRP__CDECL */
 
 enum

@slouken
Copy link
Collaborator Author

slouken commented Oct 1, 2024

Good call, I'll pull them in shortly.

This turns most text drawing into a single draw call.
This will also potentially allow us to change the triangle winding order if it becomes important.
@slouken slouken merged commit 7719fcb into libsdl-org:main Oct 1, 2024
5 checks passed
@slouken slouken deleted the font-atlas branch October 1, 2024 01:03
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.

2 participants