Skip to content

Commit

Permalink
Merge pull request #2 from rsn8887/vita
Browse files Browse the repository at this point in the history
Vita: use SDL2 to set linear filtering (needs current SDL2 for Vita)
  • Loading branch information
usineur committed Jan 11, 2018
2 parents 13a2b61 + 89df763 commit 766b6f0
Showing 1 changed file with 10 additions and 77 deletions.
87 changes: 10 additions & 77 deletions src/seg009.c
Expand Up @@ -27,74 +27,6 @@ The authors of this program may be contacted at http://forum.princed.org
#include "psp2_shader.h"
#include <vita2d.h>
vita2d_shader *shader = NULL;

// these three internal structures from SDL2 are needed to gain access to the raw
// vita2d_texture pointer and be able to set the hw-filter to "linear" to make the
// sharp-bilinear-simple shader work correctly
#ifndef VITA_TEXTUREDATA
#define VITA_TEXTUREDATA

typedef struct SDL_SW_YUVTexture
{
Uint32 format;
Uint32 target_format;
int w, h;
Uint8 *pixels;
int *colortab;
Uint32 *rgb_2_pix;
void (*Display1X) (int *colortab, Uint32 * rgb_2_pix,
unsigned char *lum, unsigned char *cr,
unsigned char *cb, unsigned char *out,
int rows, int cols, int mod);
void (*Display2X) (int *colortab, Uint32 * rgb_2_pix,
unsigned char *lum, unsigned char *cr,
unsigned char *cb, unsigned char *out,
int rows, int cols, int mod);

/* These are just so we don't have to allocate them separately */
Uint16 pitches[3];
Uint8 *planes[3];

/* This is a temporary surface in case we have to stretch copy */
SDL_Surface *stretch;
SDL_Surface *display;
} SDL_SW_YUVTexture;

/* Define the SDL texture structure */
typedef struct SDL_Texture
{
const void *magic;
Uint32 format; /**< The pixel format of the texture */
int access; /**< SDL_TextureAccess */
int w; /**< The width of the texture */
int h; /**< The height of the texture */
int modMode; /**< The texture modulation mode */
SDL_BlendMode blendMode; /**< The texture blend mode */
Uint8 r, g, b, a; /**< Texture modulation values */

SDL_Renderer *renderer;

/* Support for formats not supported directly by the renderer */
SDL_Texture *native;
SDL_SW_YUVTexture *yuv;
void *pixels;
int pitch;
SDL_Rect locked_rect;

void *driverdata; /**< Driver specific texture representation */

SDL_Texture *prev;
SDL_Texture *next;
} SDL_Texture;

typedef struct VITA_TextureData
{
vita2d_texture *tex;
unsigned int pitch;
unsigned int w;
unsigned int h;
} VITA_TextureData;
#endif
#endif

// Most functions in this file are different from those in the original game.
Expand Down Expand Up @@ -2215,6 +2147,16 @@ void __pascal far set_gr_mode(byte grmode) {

window_resized();

#ifdef VITA
// For the sharp_bilinear_simple shader to work, linear filtering has to be enabled.
// This is done by a simple command here, supported by SDL2 for Vita since 2017/12/24.
// This affects all textures created after this command.
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
//Enable sharp-bilinear-simple shader for sharp pixels without distortion.
//This has to be done after the SDL renderer is created because that inits vita2d.
shader = setPSP2Shader(SHARP_BILINEAR_SIMPLE);
#endif

/* Migration to SDL2: everything is still blitted to onscreen_surface_, however:
* SDL2 renders textures to the screen instead of surfaces; so for now, every screen
* update causes the onscreen_surface_ to be copied into sdl_texture_, which is
Expand Down Expand Up @@ -2243,15 +2185,6 @@ void __pascal far set_gr_mode(byte grmode) {
#ifdef USE_TEXT
load_font();
#endif

#ifdef VITA
if (sdl_texture_!=NULL) {
VITA_TextureData *sdl_hwtex=(VITA_TextureData *) sdl_texture_->native->driverdata;
vita2d_texture_set_filters(sdl_hwtex->tex, SCE_GXM_TEXTURE_FILTER_POINT, SCE_GXM_TEXTURE_FILTER_LINEAR);
//set shader on Vita to sharp-bilinear-simple for sharp pixels without pixelwobble
shader = setPSP2Shader(SHARP_BILINEAR_SIMPLE);
}
#endif
}

void request_screen_update() {
Expand Down

0 comments on commit 766b6f0

Please sign in to comment.