gfx: separate port-specific interfaces
This commit is contained in:
parent
6c5eb81b3c
commit
8347125b19
|
@ -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);
|
||||
|
|
|
@ -9,8 +9,6 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
void rect_init(struct rect *r);
|
||||
void semitrans_rect_init(struct rect *r);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
enum {DRAW_MODE = 0xE1};
|
||||
|
||||
enum
|
||||
{
|
||||
SCREEN_W = 368,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <gfx.h>
|
||||
#include <ps1/gfx_private.h>
|
||||
#include <psxgpu.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <gfx.h>
|
||||
#include <ps1/gfx_private.h>
|
||||
#include <gfx/port.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <gfx.h>
|
||||
#include <ps1/gfx_private.h>
|
||||
#include <psxgpu.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <gfx.h>
|
||||
#include <ps1/gfx_private.h>
|
||||
#include <psxgpu.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue