Skip to content

Commit

Permalink
ogc: implement texture scale mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mardy authored and WinterMute committed Jan 14, 2024
1 parent 67aaabf commit 310a84e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/render/ogc/SDL_render_ogc.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,12 @@ static int OGC_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
return 0;
}

static void OGC_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode)
static void OGC_SetTextureScaleMode(SDL_Renderer *renderer,
SDL_Texture *texture,
SDL_ScaleMode scaleMode)
{
// TODO
/* Nothing to do here: the scale mode is applied to the texture when
* loading it in OGC_load_texture(). */
}

static int OGC_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
Expand Down Expand Up @@ -386,7 +389,7 @@ static int OGC_RenderGeometry(SDL_Renderer *renderer, void *vertices,

size_per_element += sizeof(SDL_FPoint);
OGC_load_texture(ogc_tex->texels, texture->w, texture->h,
ogc_tex->format);
ogc_tex->format, texture->scaleMode);
stage = GX_TEVSTAGE0 + ogc_tex->needed_stages - 1;

GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
Expand Down
3 changes: 2 additions & 1 deletion src/video/ogc/SDL_ogcframebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ int SDL_OGC_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *r
GX_FALSE, 0);
DCStoreRange(windowdata->texels, texture_size);
GX_InvalidateTexAll();
OGC_load_texture(windowdata->texels, window->w, window->h, gx_format);
OGC_load_texture(windowdata->texels, window->w, window->h, gx_format,
SDL_ScaleModeNearest);
draw_screen_rect(window);
GX_DrawDone();

Expand Down
17 changes: 15 additions & 2 deletions src/video/ogc/SDL_ogcgxcommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ void OGC_draw_init(int w, int h, int h_aspect, int v_aspect)
GX_InvVtxCache(); // update vertex cache
}

void OGC_load_texture(void *texels, int w, int h, u8 format)
void OGC_load_texture(void *texels, int w, int h, u8 format,
SDL_ScaleMode scale_mode)
{
GXTexObj texobj_a, texobj_b;

Expand Down Expand Up @@ -127,7 +128,19 @@ void OGC_load_texture(void *texels, int w, int h, u8 format)
GX_InitTexObj(&texobj_a, texels, w, h, format, GX_CLAMP, GX_CLAMP, GX_FALSE);
}

GX_InitTexObjLOD(&texobj_a, GX_NEAR, GX_NEAR, 0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1);
switch (scale_mode) {
case SDL_ScaleModeLinear:
GX_InitTexObjLOD(&texobj_a, GX_LINEAR, GX_LINEAR,
0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1);
break;
case SDL_ScaleModeBest:
GX_InitTexObjLOD(&texobj_a, GX_LIN_MIP_LIN, GX_LINEAR,
0.0f, 10.0f, 0.0f, 0, GX_ENABLE, GX_ANISO_4);
break;
default:
GX_InitTexObjLOD(&texobj_a, GX_NEAR, GX_NEAR,
0.0f, 0.0f, 0.0f, 0, 0, GX_ANISO_1);
}
GX_LoadTexObj(&texobj_a, GX_TEXMAP0); // load texture object so its ready to use
}

Expand Down
5 changes: 4 additions & 1 deletion src/video/ogc/SDL_ogcgxcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
#ifndef SDL_ogcgxcommon_h_
#define SDL_ogcgxcommon_h_

#include "SDL_render.h"

#include <gctypes.h>

#define GX_COLOR_AS_U32(c) *((u32*)&c)

void OGC_draw_init(int w, int h, int h_aspect, int v_aspect);
void OGC_set_viewport(int x, int y, int w, int h, float h_aspect, float v_aspect);
void OGC_load_texture(void *texels, int w, int h, u8 gx_format);
void OGC_load_texture(void *texels, int w, int h, u8 gx_format,
SDL_ScaleMode scale_mode);

#endif /* SDL_ogcgxcommon_h_ */

Expand Down

0 comments on commit 310a84e

Please sign in to comment.