Add extension to RSX interface - rsx_set_blend_mode - also

read this - http://forums.qhimm.com/index.php?topic=6229.5
This commit is contained in:
twinaphex 2016-04-10 04:26:12 +02:00
parent e90994d595
commit d6484915b3
7 changed files with 63 additions and 31 deletions

View File

@ -14,6 +14,8 @@
#include <glsm/glsmsym.h>
#endif
#include "../../rsx/rsx.h"
class PS_GPU;
#define INCMD_NONE 0
@ -26,11 +28,6 @@ class PS_GPU;
#define DISP_RGB24 0x10
#define DISP_INTERLACED 0x20
#define BLEND_MODE_AVERAGE 0
#define BLEND_MODE_ADD 1
#define BLEND_MODE_SUBTRACT 2
#define BLEND_MODE_ADD_FOURTH 3
enum dither_mode {
DITHER_NATIVE,
DITHER_UPSCALED,

View File

@ -1,9 +1,14 @@
template<int BlendMode>
INLINE void PS_GPU::PlotPixelBlend(uint16_t bg_pix, uint16_t *fore_pix)
{
uint32_t sum, carry, diff, borrow;
/*
* fore_pix - foreground - the screen
* bg_pix - background - the texture
*/
// Efficient 15bpp pixel math algorithms from blargg
uint32_t sum, carry;
/* Efficient 15bpp pixel math algorithms from blargg */
switch(BlendMode)
{
/* 0.5 x B + 0.5 x F */
@ -23,11 +28,16 @@ INLINE void PS_GPU::PlotPixelBlend(uint16_t bg_pix, uint16_t *fore_pix)
/* 1.0 x B - 1.0 x F */
case BLEND_MODE_SUBTRACT:
bg_pix |= 0x8000;
*fore_pix &= ~0x8000;
diff = bg_pix - *fore_pix + 0x108420;
borrow = (diff - ((bg_pix ^ *fore_pix) & 0x108420)) & 0x108420;
*fore_pix = (diff - borrow) & (borrow - (borrow >> 5));
{
uint32_t diff;
uint32_t borrow;
bg_pix |= 0x8000;
*fore_pix &= ~0x8000;
diff = bg_pix - *fore_pix + 0x108420;
borrow = (diff - ((bg_pix ^ *fore_pix) & 0x108420)) & 0x108420;
*fore_pix = (diff - borrow) & (borrow - (borrow >> 5));
}
break;
/* 1.0 x B + 0.25 * F */
@ -40,6 +50,7 @@ INLINE void PS_GPU::PlotPixelBlend(uint16_t bg_pix, uint16_t *fore_pix)
*fore_pix = (sum - carry) | (carry - (carry >> 5));
break;
}
}
template<int BlendMode, bool MaskEval_TA, bool textured>

View File

@ -175,6 +175,7 @@ INLINE void PS_GPU::DrawSpan(int y, uint32_t clut_offset, const int32_t x_start,
ig.b += (xs * idl.db_dx) + (y * idl.db_dy);
}
for(int32_t x = xs; MDFN_LIKELY(x < xb); x++)
{
uint32_t r, g, b;
@ -482,7 +483,7 @@ INLINE void PS_GPU::Command_DrawPolygon(const uint32_t *cb)
int32 x = sign_x_to_s32(11, ((int16_t)(*cb & 0xFFFF)));
int32 y = sign_x_to_s32(11, ((int16_t)(*cb >> 16)));
// Attempt to retreive subpixel coordinates if available
// Attempt to retrieve subpixel coordinates if available
const subpixel_vertex *pv = GetSubpixelVertex(x, y);
if (pv != NULL) {
@ -527,18 +528,18 @@ INLINE void PS_GPU::Command_DrawPolygon(const uint32_t *cb)
uint16_t clut_x = (clut & (0x3f << 4));
uint16_t clut_y = (clut >> 10) & 0x1ff;
uint8_t blend_mode;
enum blending_modes blend_mode = BLEND_MODE_AVERAGE;
if (textured) {
if (TexMult) {
blend_mode = 2;
} else {
blend_mode = 1;
}
} else {
blend_mode = 0;
if (textured)
{
if (TexMult)
blend_mode = BLEND_MODE_SUBTRACT;
else
blend_mode = BLEND_MODE_ADD;
}
rsx_intf_set_blend_mode(blend_mode);
rsx_intf_push_triangle(vertices[0].x, vertices[0].y,
vertices[1].x, vertices[1].y,
vertices[2].x, vertices[2].y,

View File

@ -172,18 +172,18 @@ INLINE void PS_GPU::Command_DrawSprite(const uint32_t *cb)
uint16_t clut_x = (clut & (0x3f << 4));
uint16_t clut_y = (clut >> 10) & 0x1ff;
uint8_t blend_mode;
enum blending_modes blend_mode = BLEND_MODE_AVERAGE;
if (textured) {
if (TexMult) {
blend_mode = 2;
} else {
blend_mode = 1;
}
} else {
blend_mode = 0;
if (textured)
{
if (TexMult)
blend_mode = BLEND_MODE_SUBTRACT;
else
blend_mode = BLEND_MODE_ADD;
}
rsx_intf_set_blend_mode(blend_mode);
rsx_intf_push_triangle(x, y,
x + w, y,
x, y + h,

View File

@ -7,6 +7,14 @@
extern "C" {
#endif
enum blending_modes
{
BLEND_MODE_AVERAGE = 0,
BLEND_MODE_ADD,
BLEND_MODE_SUBTRACT,
BLEND_MODE_ADD_FOURTH
};
void rsx_set_environment(retro_environment_t);
void rsx_set_video_refresh(retro_video_refresh_t);
void rsx_get_system_av_info(struct retro_system_av_info *);
@ -18,6 +26,8 @@ extern "C" {
void rsx_prepare_frame(void);
void rsx_finalize_frame(void);
void rsx_set_blend_mode(enum blending_modes mode);
void rsx_set_draw_offset(int16_t x, int16_t y);
void rsx_set_draw_area(uint16_t x, uint16_t y,
uint16_t w, uint16_t h);

View File

@ -19,6 +19,15 @@ RSX_SOFTWARE
#endif
;
void rsx_intf_set_blend_mode(enum blending_modes mode)
{
switch (rsx_type)
{
default:
break;
}
}
void rsx_intf_set_environment(retro_environment_t cb)
{
switch (rsx_type)

View File

@ -3,6 +3,8 @@
#include "libretro.h"
#include "rsx.h"
#define MEDNAFEN_CORE_NAME_MODULE "psx"
#define MEDNAFEN_CORE_NAME "Mednafen PSX"
#define MEDNAFEN_CORE_VERSION "v0.9.38.6"
@ -24,6 +26,8 @@ enum rsx_renderer_type
extern "C" {
#endif
void rsx_intf_set_blend_mode(enum blending_modes mode);
void rsx_intf_set_environment(retro_environment_t cb);
void rsx_intf_set_video_refresh(retro_video_refresh_t cb);
void rsx_intf_get_system_av_info(struct retro_system_av_info *info);