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 896a6e1 + 36d871f commit 0f83827
Showing 1 changed file with 15 additions and 77 deletions.
92 changes: 15 additions & 77 deletions video.c
Expand Up @@ -54,81 +54,7 @@ static WORD g_wShakeLevel = 0;
#ifdef __PSP2__
#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
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;

void enable_psp2_shader(SDL_Texture *sdl_texture_) {
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

#if SDL_VERSION_ATLEAST(2, 0, 0)
Expand Down Expand Up @@ -184,9 +110,7 @@ static SDL_Texture *VIDEO_CreateTexture(int width, int height)
// Create texture for screen.
//
#ifdef __PSP2__
SDL_Texture *my_texture = SDL_CreateTexture(gpRenderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, texture_width, texture_height);
enable_psp2_shader(my_texture);
return my_texture;
return SDL_CreateTexture(gpRenderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, texture_width, texture_height);
#else
return SDL_CreateTexture(gpRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, texture_width, texture_height);
#endif
Expand Down Expand Up @@ -235,6 +159,16 @@ VIDEO_Startup(
return -1;
}

#ifdef __PSP2__
// 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

#if defined (__IOS__)
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
Expand Down Expand Up @@ -402,6 +336,10 @@ VIDEO_Shutdown(
{
SDL_FreePalette(gpPalette);
}

#ifdef __PSP2__
clearPSP2Shader(shader);
#endif
#endif
gpPalette = NULL;

Expand Down

0 comments on commit 0f83827

Please sign in to comment.