Skip to content

Commit

Permalink
wii-sdl2: 2.28.5-12
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterMute committed Apr 22, 2024
1 parent cf501f0 commit 1533eae
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 24 deletions.
5 changes: 3 additions & 2 deletions wii/SDL2/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pkgname=wii-sdl2
pkgver=2.28.5
pkgrel=11
pkgrel=12
pkgdesc="A library for portable low-level access to a video framebuffer, audio output, mouse, and keyboard"
arch=('any')
url="https://libsdl.org"
Expand Down Expand Up @@ -35,5 +35,6 @@ package() {
# remove useless stuff
rm -r "$pkgdir"${PORTLIBS_PREFIX}/share
}

sha256sums=('332cb37d0be20cb9541739c61f79bae5a477427d79ae85e352089afdaf6666e4'
'7626633751d479206582ff5cf7d85a89936e8284ead26dce49d7fbfd7e1313b6')
'29ca5c9f7490c6b2e466e75f19c7d18715798b9a76123f48cc032252e9078a6b')
132 changes: 110 additions & 22 deletions wii/SDL2/SDL2-2.28.5.patch
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ index 6d8ece6ac..ea0b7dd8d 100644
endif()
diff --git a/docs/README-ogc.md b/docs/README-ogc.md
new file mode 100644
index 000000000..a2a1fefb5
index 000000000..619c87a0d
--- /dev/null
+++ b/docs/README-ogc.md
@@ -0,0 +1,22 @@
+# Nintendo 3DS
+# Nintendo GameCube/Nintendo Wii
+
+SDL port for the Nintendo GameCube and Nintendo Wii [Homebrew toolchain](https://devkitpro.org/).
+
Expand All @@ -265,7 +265,7 @@ index 000000000..a2a1fefb5
+
+## Building
+
+To build for the Nintendo GameCure or Wii, make sure you have devkitARM and cmake installed and run:
+To build for the Nintendo GameCube or Wii, make sure you have devkitPPC and cmake installed and run:
+
+```bash
+cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/Wii.cmake" -DCMAKE_BUILD_TYPE=Release
Expand Down Expand Up @@ -2394,10 +2394,10 @@ index 36e9555bb..d3db2b387 100644
extern SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode);
diff --git a/src/render/ogc/SDL_render_ogc.c b/src/render/ogc/SDL_render_ogc.c
new file mode 100644
index 000000000..3aa86c1c0
index 000000000..ece76c7fc
--- /dev/null
+++ b/src/render/ogc/SDL_render_ogc.c
@@ -0,0 +1,659 @@
@@ -0,0 +1,747 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Expand Down Expand Up @@ -2444,6 +2444,8 @@ index 000000000..3aa86c1c0
+ int ops_after_present;
+ bool vsync;
+ u8 efb_pixel_format;
+ SDL_Texture *render_target;
+ SDL_Texture *saved_efb_texture;
+} OGC_RenderData;
+
+typedef struct
Expand All @@ -2457,6 +2459,8 @@ index 000000000..3aa86c1c0
+ u8 needed_stages; // Normally 1, set to 2 for palettized formats
+} OGC_TextureData;
+
+static void OGC_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture);
+
+static void OGC_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
+{
+}
Expand Down Expand Up @@ -2501,14 +2505,51 @@ index 000000000..3aa86c1c0
+ set_blend_mode_real(renderer, blend_mode);
+}
+
+static void save_efb_to_texture(SDL_Renderer *renderer)
+static void load_efb_from_texture(SDL_Renderer *renderer, SDL_Texture *texture)
+{
+ OGC_TextureData *ogc_tex = texture->driverdata;
+
+ OGC_load_texture(ogc_tex->texels, texture->w, texture->h,
+ ogc_tex->format, SDL_ScaleModeNearest);
+
+ GX_ClearVtxDesc();
+ GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
+ GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_S16, 0);
+
+ GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
+ GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_U8, 0);
+ GX_SetNumTexGens(1);
+
+ GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
+ GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
+ GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
+ GX_SetNumTevStages(1);
+
+ GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
+ GX_Position2s16(0, 0);
+ GX_TexCoord2u8(0, 0);
+ GX_Position2s16(texture->w, 0);
+ GX_TexCoord2u8(1, 0);
+ GX_Position2s16(texture->w, texture->h);
+ GX_TexCoord2u8(1, 1);
+ GX_Position2s16(0, texture->h);
+ GX_TexCoord2u8(0, 1);
+ GX_End();
+}
+
+static void save_efb_to_texture(SDL_Texture *texture)
+{
+ SDL_Texture *texture = renderer->target;
+ OGC_TextureData *ogc_tex = texture->driverdata;
+ u32 texture_size;
+
+ texture_size = GX_GetTexBufferSize(texture->w, texture->h, ogc_tex->format,
+ GX_FALSE, 0);
+ DCInvalidateRange(ogc_tex->texels, texture_size);
+
+ GX_SetTexCopySrc(0, 0, texture->w, texture->h);
+ GX_SetTexCopyDst(texture->w, texture->h, ogc_tex->format, GX_FALSE);
+ GX_CopyTex(ogc_tex->texels, GX_TRUE);
+ GX_PixModeSync();
+}
+
+static void update_texture(SDL_Texture *texture, const SDL_Rect *rect,
Expand Down Expand Up @@ -2592,6 +2633,42 @@ index 000000000..3aa86c1c0
+ * loading it in OGC_load_texture(). */
+}
+
+static SDL_Texture *create_efb_texture(OGC_RenderData *data, SDL_Texture *target)
+{
+ /* Note: we do return a SDL_Texture, but not via SDL's API, since that does
+ * a bunch of other stuffs we don't care about. We create this texture for
+ * our internal use, so we initialize only those fields we care about. */
+ SDL_Texture *texture;
+ OGC_TextureData *ogc_tex;
+ u32 texture_size;
+
+ texture = SDL_calloc(1, sizeof(*texture));
+ if (!texture) goto fail_texture_alloc;
+
+ ogc_tex = SDL_calloc(1, sizeof(OGC_TextureData));
+ if (!ogc_tex) goto fail_ogc_tex_alloc;
+
+ ogc_tex->format = data->efb_pixel_format == GX_PF_RGB565_Z16 ?
+ GX_TF_RGB565 : GX_TF_RGBA8;
+ texture->w = target->w;
+ texture->h = target->h;
+ texture_size = GX_GetTexBufferSize(texture->w, texture->h, ogc_tex->format,
+ GX_FALSE, 0);
+ ogc_tex->texels = memalign(32, texture_size);
+ if (!ogc_tex->texels) goto fail_texels_alloc;
+
+ texture->driverdata = ogc_tex;
+ return texture;
+
+fail_texels_alloc:
+ SDL_free(ogc_tex->texels);
+fail_ogc_tex_alloc:
+ SDL_free(texture);
+fail_texture_alloc:
+ SDL_OutOfMemory();
+ return NULL;
+}
+
+static int OGC_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
+{
+ OGC_RenderData *data = renderer->driverdata;
Expand All @@ -2603,28 +2680,38 @@ index 000000000..3aa86c1c0
+ }
+
+ if (data->ops_after_present > 0) {
+ /* We should save the current EFB contents into the window data.
+ * However, it's unclear whether this is a possible scenario, since
+ * all actual drawing happens in RunCommandQueue() and this method
+ * will not be called in between of the drawing operations; but
+ * just to be on the safe side, log a warning. We can come back to
+ * this later and implement the EFB saving if we see that this
+ * happens in real life.
+ */
+ SDL_LogWarn(SDL_LOG_CATEGORY_RENDER,
+ "Render target set after drawing!");
+ /* Save the current EFB contents if we already drew something onto
+ * it. We'll restore it later, when the rendering target is reset
+ * to NULL (the screen). */
+ data->saved_efb_texture = create_efb_texture(data, texture);
+ save_efb_to_texture(data->saved_efb_texture);
+ }
+
+ if (SDL_ISPIXELFORMAT_ALPHA(texture->format)) {
+ desired_efb_pixel_format = GX_PF_RGBA6_Z24;
+ }
+ } else if (data->render_target) {
+ save_efb_to_texture(data->render_target);
+ }
+
+ data->render_target = texture;
+
+ if (desired_efb_pixel_format != data->efb_pixel_format) {
+ data->efb_pixel_format = desired_efb_pixel_format;
+ GX_SetPixelFmt(data->efb_pixel_format, GX_ZC_LINEAR);
+ }
+
+ /* Restore the EFB to how it was before the we started to render to a
+ * texture. */
+ if (!texture && data->saved_efb_texture) {
+ load_efb_from_texture(renderer, data->saved_efb_texture);
+ /* Flush the draw operation before destroying the texture */
+ GX_DrawDone();
+ OGC_DestroyTexture(renderer, data->saved_efb_texture);
+ SDL_free(data->saved_efb_texture);
+ data->saved_efb_texture = NULL;
+ }
+
+ return 0;
+}
+
Expand Down Expand Up @@ -2780,7 +2867,11 @@ index 000000000..3aa86c1c0
+
+ data->clear_color = c;
+ GX_SetCopyClear(c, GX_MAX_Z24);
+ GX_CopyDisp(OGC_video_get_xfb(SDL_GetVideoDevice()), GX_TRUE);
+ if (renderer->target) {
+ save_efb_to_texture(renderer->target);
+ } else {
+ GX_CopyDisp(OGC_video_get_xfb(SDL_GetVideoDevice()), GX_TRUE);
+ }
+
+ return 0;
+}
Expand Down Expand Up @@ -2925,10 +3016,7 @@ index 000000000..3aa86c1c0
+ cmd = cmd->next;
+ }
+
+ if (renderer->target) {
+ save_efb_to_texture(renderer);
+ }
+
+ GX_DrawDone();
+ return 0;
+}
+
Expand Down

0 comments on commit 1533eae

Please sign in to comment.