Changed GL video scaling so that special filter does not effect the size of the overall window.

This commit is contained in:
mjbudd77 2021-05-29 21:52:32 -04:00
parent b58d4f903c
commit 96c569a652
6 changed files with 80 additions and 44 deletions

View File

@ -879,13 +879,13 @@ QSize ConsoleVideoConfDialog_t::calcNewScreenSize(void)
if ( aspectCbx->isChecked() )
{
xscale = xScaleBox->value();
xscale = xScaleBox->value() / nes_shm->video.xscale;
yscale = xscale * (double)nes_shm->video.xyRatio;
}
else
{
xscale = xScaleBox->value();
yscale = yScaleBox->value();
xscale = xScaleBox->value() / nes_shm->video.xscale;
yscale = yScaleBox->value() / nes_shm->video.yscale;
}
rw=(int)((r-l)*xscale);
rh=(int)((b-t)*yscale);

View File

@ -163,7 +163,7 @@ void ConsoleViewGL_t::buildTextures(void)
if ( textureType == GL_TEXTURE_RECTANGLE )
{
printf("Using GL_TEXTURE_RECTANGLE\n");
//printf("Using GL_TEXTURE_RECTANGLE\n");
glEnable(GL_TEXTURE_RECTANGLE);
glGenTextures(1, &gltexture);
//printf("Linear Interpolation on GL Texture: %s \n", linearFilter ? "Enabled" : "Disabled");
@ -184,7 +184,7 @@ void ConsoleViewGL_t::buildTextures(void)
}
else
{
printf("Using GL_TEXTURE_2D\n");
//printf("Using GL_TEXTURE_2D\n");
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &gltexture);
//printf("Linear Interpolation on GL Texture: %s \n", linearFilter ? "Enabled" : "Disabled");
@ -224,7 +224,7 @@ void ConsoleViewGL_t::chkExtnsGL(void)
glGetIntegerv(GL_NUM_EXTENSIONS, &NumberOfExtensions);
printf("Number of GL Externsions: %i \n", NumberOfExtensions );
//printf("Number of GL Externsions: %i \n", NumberOfExtensions );
c = glGetString( GL_VERSION );
@ -264,12 +264,12 @@ void ConsoleViewGL_t::chkExtnsGL(void)
if ( strcmp( extName, "GL_ARB_texture_rectangle" ) == 0 )
{
printf("GL Has: %s\n", extName );
//printf("GL Has: %s\n", extName );
textureType = GL_TEXTURE_RECTANGLE;
}
else if ( strcmp( extName, "GL_ARB_texture_non_power_of_two" ) == 0 )
{
printf("GL Has: %s\n", extName );
//printf("GL Has: %s\n", extName );
reqPwr2 = false;
}
}
@ -343,20 +343,28 @@ void ConsoleViewGL_t::setLinearFilterEnable( bool ena )
void ConsoleViewGL_t::setScaleXY( double xs, double ys )
{
float xyRatio = (float)nes_shm->video.xyRatio;
//float xyRatio = (float)nes_shm->video.xyRatio;
xscale = xs;
yscale = ys;
if ( forceAspect )
{
if ( (xscale*xyRatio) < yscale )
//if ( (xscale*xyRatio) < yscale )
//{
// yscale = (xscale*xyRatio);
//}
//else
//{
// xscale = (yscale/xyRatio);
//}
if ( xscale < yscale )
{
yscale = (xscale*xyRatio);
yscale = xscale;
}
else
{
xscale = (yscale/xyRatio);
xscale = yscale;
}
}
}
@ -476,19 +484,32 @@ void ConsoleViewGL_t::paintGL(void)
int l=0, r=texture_width;
int t=0, b=texture_height;
float xyRatio = (float)nes_shm->video.xyRatio;
float ixScale = (float)nes_shm->video.xscale;
float iyScale = (float)nes_shm->video.yscale;
//float xyRatio = (float)nes_shm->video.xyRatio;
float xscaleTmp = (float)(view_width) / (float)(texture_width);
float yscaleTmp = (float)(view_height) / (float)(texture_height);
xscaleTmp *= ixScale;
yscaleTmp *= iyScale;
if ( forceAspect )
{
if ( (xscaleTmp*xyRatio) < yscaleTmp )
//if ( (xscaleTmp*xyRatio) < yscaleTmp )
//{
// yscaleTmp = xscaleTmp * xyRatio;
//}
//else
//{
// xscaleTmp = yscaleTmp / xyRatio;
//}
if ( xscaleTmp < yscaleTmp )
{
yscaleTmp = xscaleTmp * xyRatio;
yscaleTmp = xscaleTmp;
}
else
{
xscaleTmp = yscaleTmp / xyRatio;
xscaleTmp = yscaleTmp;
}
}
@ -509,8 +530,8 @@ void ConsoleViewGL_t::paintGL(void)
}
}
rw=(int)((r-l)*xscaleTmp);
rh=(int)((b-t)*yscaleTmp);
rw=(int)((r-l)*xscaleTmp/ixScale);
rh=(int)((b-t)*yscaleTmp/iyScale);
if ( forceAspect )
{

View File

@ -37,7 +37,8 @@ nes_shm_t *open_nes_shm(void)
vaddr->video.ncol = GL_NES_WIDTH;
vaddr->video.nrow = GL_NES_HEIGHT;
vaddr->video.pitch = GL_NES_WIDTH * 4;
vaddr->video.scale = 1;
vaddr->video.xscale = 1;
vaddr->video.yscale = 1;
vaddr->video.xyRatio = 1;
vaddr->video.preScaler = 0;

View File

@ -25,7 +25,8 @@ struct nes_shm_t
int ncol;
int nrow;
int pitch;
int scale;
int xscale;
int yscale;
int xyRatio;
int preScaler;
} video;

View File

@ -150,28 +150,33 @@ void CalcVideoDimensions(void)
{
default:
case 0: // None
nes_shm->video.scale = 1;
nes_shm->video.xscale = 1;
nes_shm->video.yscale = 1;
break;
case 1: // hq2x
case 2: // Scale2x
case 3: // NTSC 2x
case 6: // Prescale2x
nes_shm->video.scale = 2;
nes_shm->video.xscale = 2;
nes_shm->video.yscale = 2;
break;
case 4: // hq3x
case 5: // Scale3x
case 7: // Prescale3x
nes_shm->video.scale = 3;
nes_shm->video.xscale = 3;
nes_shm->video.yscale = 3;
break;
case 8: // Prescale4x
nes_shm->video.scale = 4;
nes_shm->video.xscale = 4;
nes_shm->video.yscale = 4;
break;
case 9: // PAL
nes_shm->video.scale = 3;
nes_shm->video.xscale = 3;
nes_shm->video.yscale = 1;
break;
}
int iScale = nes_shm->video.scale;
int iScale = nes_shm->video.xscale;
if ( s_sponge == 3 )
{
nes_shm->video.ncol = iScale*301;
@ -236,24 +241,29 @@ int InitVideo(FCEUGI *gi)
{
default:
case 0: // None
nes_shm->video.scale = 1;
nes_shm->video.xscale = 1;
nes_shm->video.yscale = 1;
break;
case 1: // hq2x
case 2: // Scale2x
case 3: // NTSC 2x
case 6: // Prescale2x
nes_shm->video.scale = 2;
nes_shm->video.xscale = 2;
nes_shm->video.yscale = 2;
break;
case 4: // hq3x
case 5: // Scale3x
case 7: // Prescale3x
nes_shm->video.scale = 3;
nes_shm->video.xscale = 3;
nes_shm->video.yscale = 3;
break;
case 8: // Prescale4x
nes_shm->video.scale = 4;
nes_shm->video.xscale = 4;
nes_shm->video.yscale = 4;
break;
case 9: // PAL
nes_shm->video.scale = 3;
nes_shm->video.xscale = 3;
nes_shm->video.yscale = 1;
break;
}
@ -262,7 +272,7 @@ int InitVideo(FCEUGI *gi)
// check to see if we are showing FPS
FCEUI_SetShowFPS(show_fps);
int iScale = nes_shm->video.scale;
int iScale = nes_shm->video.xscale;
if ( s_sponge == 3 )
{
nes_shm->video.ncol = iScale*301;
@ -427,7 +437,7 @@ void
BlitScreen(uint8 *XBuf)
{
uint8 *dest;
int w, h, pitch, iScale;
int w, h, pitch, ixScale, iyScale;
// refresh the palette if required
if (s_paletterefresh)
@ -439,16 +449,17 @@ BlitScreen(uint8 *XBuf)
// XXX soules - not entirely sure why this is being done yet
XBuf += s_srendline * 256;
dest = (uint8*)nes_shm->pixbuf;
iScale = nes_shm->video.scale;
dest = (uint8*)nes_shm->pixbuf;
ixScale = nes_shm->video.xscale;
iyScale = nes_shm->video.yscale;
if ( s_sponge == 3 )
{
w = iScale*301;
w = ixScale*301;
}
else
{
w = iScale*NWIDTH;
w = ixScale*NWIDTH;
}
if ( s_sponge == 9 )
{
@ -456,7 +467,7 @@ BlitScreen(uint8 *XBuf)
}
else
{
h = iScale*s_tlines;
h = ixScale*s_tlines;
}
pitch = w*4;
@ -473,7 +484,7 @@ BlitScreen(uint8 *XBuf)
}
else
{
Blit8ToHigh(XBuf + NOFFSET, dest, NWIDTH, s_tlines, pitch, iScale, iScale);
Blit8ToHigh(XBuf + NOFFSET, dest, NWIDTH, s_tlines, pitch, ixScale, iyScale);
}
nes_shm->blitUpdated = 1;
@ -493,12 +504,13 @@ uint32 PtoV(double nx, double ny)
//printf("Scaled (%i,%i) \n", x, y);
x = x / nes_shm->video.scale;
x = x / nes_shm->video.xscale;
y = y / nes_shm->video.yscale;
if ( nes_shm->video.xyRatio == 1 )
{
y = y / nes_shm->video.scale;
}
//if ( nes_shm->video.xyRatio == 1 )
//{
// y = y / nes_shm->video.scale;
//}
//printf("UnScaled (%i,%i) \n", x, y);
if (s_clipSides)

View File

@ -208,6 +208,7 @@ int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int
palrgb = (uint32 *)FCEU_dmalloc((256+512)*PAL_PHASES*sizeof(uint32));
palrgb2 = (uint32 *)FCEU_dmalloc((256+512)*PAL_PHASES*sizeof(uint32));
moire = (float *)FCEU_dmalloc( PAL_PHASES*sizeof(float));
palupdate = 1;
}
silt = specfilt;