Implement smooth scaling

This commit is contained in:
Jonas Kulla 2013-09-23 11:00:50 +02:00
parent 7f604e25ad
commit da4e0fbed0
5 changed files with 25 additions and 6 deletions

View File

@ -3,6 +3,7 @@ debugMode=true
winResizable=true winResizable=true
fullscreen=false fullscreen=false
fixedAspectRatio=false fixedAspectRatio=false
smoothScaling=false
vsync=true vsync=true
defScreenW=640 defScreenW=640
defScreenH=480 defScreenH=480

View File

@ -33,6 +33,7 @@ Config::Config()
winResizable(false), winResizable(false),
fullscreen(false), fullscreen(false),
fixedAspectRatio(false), fixedAspectRatio(false),
smoothScaling(false),
vsync(false), vsync(false),
defScreenW(640), defScreenW(640),
defScreenH(480), defScreenH(480),
@ -50,6 +51,7 @@ void Config::read()
READ_VAL(winResizable, Bool); READ_VAL(winResizable, Bool);
READ_VAL(fullscreen, Bool); READ_VAL(fullscreen, Bool);
READ_VAL(fixedAspectRatio, Bool); READ_VAL(fixedAspectRatio, Bool);
READ_VAL(smoothScaling, Bool);
READ_VAL(vsync, Bool); READ_VAL(vsync, Bool);
READ_VAL(defScreenW, Int); READ_VAL(defScreenW, Int);
READ_VAL(defScreenH, Int); READ_VAL(defScreenH, Int);

View File

@ -34,6 +34,7 @@ struct Config
bool winResizable; bool winResizable;
bool fullscreen; bool fullscreen;
bool fixedAspectRatio; bool fixedAspectRatio;
bool smoothScaling;
bool vsync; bool vsync;
int defScreenW; int defScreenW;

View File

@ -147,6 +147,12 @@ namespace FBO
Read = 1 Read = 1
}; };
enum BlitMode
{
Nearest = 0,
Linear = 1
};
inline ID gen() inline ID gen()
{ {
ID id; ID id;
@ -189,18 +195,26 @@ namespace FBO
inline void blit(int srcX, int srcY, inline void blit(int srcX, int srcY,
int srcW, int srcH, int srcW, int srcH,
int dstX, int dstY, int dstX, int dstY,
int dstW, int dstH) int dstW, int dstH,
BlitMode mode = Nearest)
{ {
static const GLenum modes[] =
{
GL_NEAREST,
GL_LINEAR
};
glBlitFramebufferEXT(srcX, srcY, srcX+srcW, srcY+srcH, glBlitFramebufferEXT(srcX, srcY, srcX+srcW, srcY+srcH,
dstX, dstY, dstX+dstW, dstY+dstH, dstX, dstY, dstX+dstW, dstY+dstH,
GL_COLOR_BUFFER_BIT, GL_NEAREST); GL_COLOR_BUFFER_BIT, modes[mode]);
} }
inline void blit(int srcX, int srcY, inline void blit(int srcX, int srcY,
int dstX, int dstY, int dstX, int dstY,
int srcW, int srcH) int srcW, int srcH,
BlitMode mode = Nearest)
{ {
blit(srcX, srcY, srcW, srcH, dstX, dstY, srcW, srcH); blit(srcX, srcY, srcW, srcH, dstX, dstY, srcW, srcH, mode);
} }
inline Vec4 getPixel(int x, int y) inline Vec4 getPixel(int x, int y)

View File

@ -537,7 +537,7 @@ struct GraphicsPrivate
{ {
scSize = winSize; scSize = winSize;
if (!gState->config().fixedAspectRatio) if (!threadData->config.fixedAspectRatio)
{ {
scOffset = Vec2i(0, 0); scOffset = Vec2i(0, 0);
return; return;
@ -591,7 +591,8 @@ struct GraphicsPrivate
void blitBufferFlippedScaled() void blitBufferFlippedScaled()
{ {
FBO::blit(0, 0, scRes.x, scRes.y, FBO::blit(0, 0, scRes.x, scRes.y,
scOffset.x, scSize.y+scOffset.y, scSize.x, -scSize.y); scOffset.x, scSize.y+scOffset.y, scSize.x, -scSize.y,
threadData->config.smoothScaling ? FBO::Linear : FBO::Nearest);
} }
/* Blits currently bound read FBO to screen (upside-down) */ /* Blits currently bound read FBO to screen (upside-down) */