diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-02-24 21:12:18 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-03-30 08:20:21 +0200 |
| commit | b925e5e156db07494b338e7c130b72f8e3a7725e (patch) | |
| tree | 771e581beaadb5e1ece158ee40e4251a61b7873b /src | |
| parent | 669045df00302d7c4df861c4c21cac1efdb54048 (diff) | |
| download | jancity-b925e5e156db07494b338e7c130b72f8e3a7725e.tar.gz | |
gfx: separate port-specific interfaces
Diffstat (limited to 'src')
| -rw-r--r-- | src/gfx/inc/gfx.h | 5 | ||||
| -rw-r--r-- | src/gfx/privinc/gfx_private.h | 2 | ||||
| -rw-r--r-- | src/gfx/ps1/inc/gfx/port.h | 9 | ||||
| -rw-r--r-- | src/gfx/ps1/privinc/ps1/gfx_private.h | 2 | ||||
| -rw-r--r-- | src/gfx/ps1/src/4line.c | 1 | ||||
| -rw-r--r-- | src/gfx/ps1/src/env.c | 6 | ||||
| -rw-r--r-- | src/gfx/ps1/src/quad.c | 1 | ||||
| -rw-r--r-- | src/gfx/ps1/src/rect.c | 2 | ||||
| -rw-r--r-- | src/gfx/ps1/src/sort.c | 32 | ||||
| -rw-r--r-- | src/gfx/ps1/src/sprite.c | 1 | ||||
| -rw-r--r-- | src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h | 7 | ||||
| -rw-r--r-- | src/gfx/sdl-1.2/src/env.c | 45 | ||||
| -rw-r--r-- | src/gfx/sdl-1.2/src/line.c | 1 | ||||
| -rw-r--r-- | src/gfx/sdl-1.2/src/quad.c | 17 | ||||
| -rw-r--r-- | src/gfx/sdl-1.2/src/rect.c | 3 | ||||
| -rw-r--r-- | src/gfx/sdl-1.2/src/sprite.c | 3 |
16 files changed, 105 insertions, 32 deletions
diff --git a/src/gfx/inc/gfx.h b/src/gfx/inc/gfx.h index 7ea6df6..32c65a6 100644 --- a/src/gfx/inc/gfx.h +++ b/src/gfx/inc/gfx.h @@ -12,9 +12,12 @@ extern "C" int gfx_init(void); void gfx_draw(void); -void gfx_sync(void); +int gfx_toggle_fullscreen(void); void sprite_sort(struct sprite *s); int sprite_clone(const struct sprite *src, struct sprite *dst); +void rect_init(struct rect *r); +void semitrans_rect_init(struct rect *r); +void stp_4line_init(struct stp_4line *l); void quad_sort(struct quad *q); void rect_sort(struct rect *r); void stp_4line_sort(struct stp_4line *l); diff --git a/src/gfx/privinc/gfx_private.h b/src/gfx/privinc/gfx_private.h index 972efd0..b5cb96b 100644 --- a/src/gfx/privinc/gfx_private.h +++ b/src/gfx/privinc/gfx_private.h @@ -9,8 +9,6 @@ extern "C" { #endif -void rect_init(struct rect *r); -void semitrans_rect_init(struct rect *r); #ifdef __cplusplus } #endif diff --git a/src/gfx/ps1/inc/gfx/port.h b/src/gfx/ps1/inc/gfx/port.h index dec00c3..9aed9fd 100644 --- a/src/gfx/ps1/inc/gfx/port.h +++ b/src/gfx/ps1/inc/gfx/port.h @@ -129,7 +129,14 @@ struct stp_4line uint32_t end; }; -enum {DRAW_MODE = 0xE1}; +#define common_get_or_ret(t, x, ret) \ + struct t *x = t##_get(); \ + if (!x) return ret + +struct sprite *sprite_get(void); +struct quad *quad_get(void); +struct rect *rect_get(void); +struct stp_4line *stp_4line_get(void); int sprite_from_file_ex(const char *path, struct sprite *s); diff --git a/src/gfx/ps1/privinc/ps1/gfx_private.h b/src/gfx/ps1/privinc/ps1/gfx_private.h index fd5a790..651ee40 100644 --- a/src/gfx/ps1/privinc/ps1/gfx_private.h +++ b/src/gfx/ps1/privinc/ps1/gfx_private.h @@ -8,6 +8,8 @@ extern "C" { #endif +enum {DRAW_MODE = 0xE1}; + enum { SCREEN_W = 368, diff --git a/src/gfx/ps1/src/4line.c b/src/gfx/ps1/src/4line.c index 955277e..ead1ad6 100644 --- a/src/gfx/ps1/src/4line.c +++ b/src/gfx/ps1/src/4line.c @@ -1,4 +1,5 @@ #include <gfx.h> +#include <ps1/gfx_private.h> #include <psxgpu.h> #include <stdint.h> #include <string.h> diff --git a/src/gfx/ps1/src/env.c b/src/gfx/ps1/src/env.c index c12002b..e18eda8 100644 --- a/src/gfx/ps1/src/env.c +++ b/src/gfx/ps1/src/env.c @@ -32,6 +32,12 @@ void gfx_initenvs(void) GsSetDispEnv(&dispenv); } +int gfx_toggle_fullscreen(void) +{ + /* Not supported. */ + return -1; +} + bool gfx_inside_drawenv(const short x, const short y, const short w, const short h) { diff --git a/src/gfx/ps1/src/quad.c b/src/gfx/ps1/src/quad.c index 649426f..4b65b90 100644 --- a/src/gfx/ps1/src/quad.c +++ b/src/gfx/ps1/src/quad.c @@ -1,4 +1,5 @@ #include <gfx.h> +#include <ps1/gfx_private.h> #include <gfx/port.h> #include <stdint.h> #include <string.h> diff --git a/src/gfx/ps1/src/rect.c b/src/gfx/ps1/src/rect.c index 7e593b7..ff70b95 100644 --- a/src/gfx/ps1/src/rect.c +++ b/src/gfx/ps1/src/rect.c @@ -1,5 +1,7 @@ #include <gfx.h> +#include <ps1/gfx_private.h> #include <psxgpu.h> +#include <stdbool.h> #include <stdint.h> #include <string.h> diff --git a/src/gfx/ps1/src/sort.c b/src/gfx/ps1/src/sort.c index 03449fc..1c61d12 100644 --- a/src/gfx/ps1/src/sort.c +++ b/src/gfx/ps1/src/sort.c @@ -39,6 +39,22 @@ void stp_4line_sort(struct stp_4line *const l) add_to_list(&l->sznext); } +static void gfx_sync(void) +{ + /* Wait for the GPU to finish drawing primitives. */ + while (!(GPU_CONTROL_PORT & (1 << 0x1a))) + ; + + /* Wait for the GPU to be free. */ + while (!(GPU_CONTROL_PORT & (1 << 0x1c))) + ; + + while (!vblank_set) + ; + + vblank_set = false; +} + void gfx_draw(void) { static union gfx_sznext term = {.cmd_next = 0xffffff}; @@ -56,19 +72,3 @@ void gfx_draw(void) D2_CHCR = (1 << 0xa) | 1 | (1 << 0x18); first = NULL; } - -void gfx_sync(void) -{ - /* Wait for the GPU to finish drawing primitives. */ - while (!(GPU_CONTROL_PORT & (1 << 0x1a))) - ; - - /* Wait for the GPU to be free. */ - while (!(GPU_CONTROL_PORT & (1 << 0x1c))) - ; - - while (!vblank_set) - ; - - vblank_set = false; -} diff --git a/src/gfx/ps1/src/sprite.c b/src/gfx/ps1/src/sprite.c index 3e35a70..b94bf65 100644 --- a/src/gfx/ps1/src/sprite.c +++ b/src/gfx/ps1/src/sprite.c @@ -1,4 +1,5 @@ #include <gfx.h> +#include <ps1/gfx_private.h> #include <psxgpu.h> #include <errno.h> #include <inttypes.h> diff --git a/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h b/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h index c067af7..d095cc0 100644 --- a/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h +++ b/src/gfx/sdl-1.2/privinc/sdl-1.2/gfx_private.h @@ -1,6 +1,9 @@ #ifndef GFX_SDL_12_PRIVATE_H #define GFX_SDL_12_PRIVATE_H +#include <gfx.h> +#include <SDL/SDL.h> + #ifdef __cplusplus extern "C" { @@ -12,6 +15,10 @@ enum SCREEN_H = 240 }; +int sprite_screen_resize_ev(struct sprite *s); +void gfx_register_sprite(struct sprite *s); +SDL_Surface *gfx_screen(void); + #ifdef __cplusplus } #endif diff --git a/src/gfx/sdl-1.2/src/env.c b/src/gfx/sdl-1.2/src/env.c index 6589d84..d6d1f33 100644 --- a/src/gfx/sdl-1.2/src/env.c +++ b/src/gfx/sdl-1.2/src/env.c @@ -1,4 +1,5 @@ #include <gfx.h> +#include <gfx_private.h> #include <sdl-1.2/gfx_private.h> #include <SDL/SDL.h> #include <stdbool.h> @@ -27,34 +28,58 @@ static int resize_screen(const int w, const int h, const bool full_screen) return -1; } + static bool init; + + if (!init) + { + display.w = info->current_w; + display.h = info->current_h; + init = true; + } + if (fullscreen) + { flags |= SDL_FULLSCREEN; + w = display.w; + h = display.h; + } -#if 0 - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); -#endif - - const int bpp = info->vfmt->BitsPerPixel; + int bpp = info->vfmt->BitsPerPixel; if (screen) SDL_FreeSurface(screen); - if (!(screen = SDL_SetVideoMode(screen_w, screen_h, bpp, flags))) + const int max_bpp = SDL_VideoModeOK(w, h, 0, flags); + + if (max_bpp < 0) + { + fprintf(stderr, "SDL_VideoModeOK: %s\n", SDL_GetError()); + return -1; + } + else if (bpp > max_bpp) + bpp = max_bpp; + + if (!(screen = SDL_SetVideoMode(w, h, 0, flags))) { fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError()); return -1; } + for (size_t i = 0; i < list_len; i++) + if (sprite_screen_resize_ev(list[i])) + return -1; + screen_w = w; screen_h = h; fullscreen = full_screen; return 0; } +SDL_Surface *gfx_screen(void) +{ + return screen; +} + int gfx_init(void) { if (SDL_InitSubSystem(SDL_INIT_VIDEO)) diff --git a/src/gfx/sdl-1.2/src/line.c b/src/gfx/sdl-1.2/src/line.c index aeeda7b..3886204 100644 --- a/src/gfx/sdl-1.2/src/line.c +++ b/src/gfx/sdl-1.2/src/line.c @@ -1,5 +1,6 @@ #include <gfx.h> #include <gfx/port.h> +#include <sdl-1.2/gfx_private.h> #include <stddef.h> void stp_4line_init(struct stp_4line *const l) diff --git a/src/gfx/sdl-1.2/src/quad.c b/src/gfx/sdl-1.2/src/quad.c index fe1b39f..b680e0c 100644 --- a/src/gfx/sdl-1.2/src/quad.c +++ b/src/gfx/sdl-1.2/src/quad.c @@ -1,5 +1,6 @@ #include <gfx.h> #include <gfx/port.h> +#include <sdl-1.2/gfx_private.h> #include <stddef.h> #include <stdlib.h> @@ -15,4 +16,20 @@ int quad_from_sprite(const struct sprite *const s, struct quad *const q) void quad_sort(struct quad *const q) { + SDL_Rect r = + { + .x = q->x0, + .y = q->y0 + }; + + SDL_Rect clip = + { + .x = q->u0, + .y = q->v0, + .w = q->u1 - q->u0 + 1, + .h= q->v2 - q->v0 + 1 + }; + + if (SDL_BlitSurface(q->s, &clip, gfx_screen(), &r)) + fprintf(stderr, "SDL_BlitSurface: %s\n", SDL_GetError()); } diff --git a/src/gfx/sdl-1.2/src/rect.c b/src/gfx/sdl-1.2/src/rect.c index ee50378..38d9b62 100644 --- a/src/gfx/sdl-1.2/src/rect.c +++ b/src/gfx/sdl-1.2/src/rect.c @@ -1,5 +1,6 @@ #include <gfx.h> #include <gfx/port.h> +#include <sdl-1.2/gfx_private.h> #include <SDL/SDL.h> #include <stddef.h> #include <stdlib.h> @@ -14,7 +15,7 @@ void rect_sort(struct rect *const r) .h = r->h }; - SDL_Surface *const screen = gfx_port_screen(); + SDL_Surface *const screen = gfx_screen(); const Uint32 map = SDL_MapRGB(screen->format, r->r, r->g, r->b); if (SDL_FillRect(screen, &rct, map)) diff --git a/src/gfx/sdl-1.2/src/sprite.c b/src/gfx/sdl-1.2/src/sprite.c index e20f1c8..f3a2d94 100644 --- a/src/gfx/sdl-1.2/src/sprite.c +++ b/src/gfx/sdl-1.2/src/sprite.c @@ -1,6 +1,7 @@ #include <gfx.h> #include <gfx/port.h> #include <header.h> +#include <sdl-1.2/gfx_private.h> #include <SDL/SDL.h> #include <errno.h> #include <stddef.h> @@ -120,6 +121,6 @@ void sprite_sort(struct sprite *const s) .h = s->h }; - if (SDL_BlitSurface(s->s, &clip, gfx_port_screen(), &r)) + if (SDL_BlitSurface(s->s, &clip, gfx_screen(), &r)) fprintf(stderr, "SDL_BlitSurface: %s\n", SDL_GetError()); } |
