summaryrefslogtreecommitdiff
path: root/src/graphics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics.cpp')
-rw-r--r--src/graphics.cpp49
1 files changed, 35 insertions, 14 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp
index b4c65b0a..d5c1e1a0 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -64,14 +64,13 @@ bool Graphics::setVideoMode(int w, int h, bool fs)
if (!window)
return false;
- SDL_SetWindowMinimumSize(window, 640, 480);
+ SDL_SetWindowMinimumSize(window, 640, 360);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
setTarget(window);
mRenderer = renderer;
- mWidth = w;
- mHeight = h;
+ videoResized(w, h);
mFullscreen = fs;
if (const char *driver = SDL_GetCurrentVideoDriver())
@@ -127,18 +126,26 @@ bool Graphics::changeVideoMode(int w, int h, bool fs)
void Graphics::videoResized(int w, int h)
{
- mWidth = w;
- mHeight = h;
-}
+ const int prevWidth = mWidth;
+ const int prevHeight = mHeight;
-int Graphics::getWidth() const
-{
- return mWidth;
-}
+ mScale = getScale(w, h);
+ mWidth = w / mScale;
+ mHeight = h / mScale;
-int Graphics::getHeight() const
-{
- return mHeight;
+ if (mWidth != prevWidth || mHeight != prevHeight) {
+ if (mScreenTexture) {
+ SDL_DestroyTexture(mScreenTexture);
+ mScreenTexture = nullptr;
+ }
+
+ if (mScale > 1) {
+ auto pixelFormat = SDL_GetWindowPixelFormat(mTarget);
+ mScreenTexture = SDL_CreateTexture(mRenderer, pixelFormat, SDL_TEXTUREACCESS_TARGET, mWidth, mHeight);
+ }
+
+ SDL_SetRenderTarget(mRenderer, mScreenTexture);
+ }
}
bool Graphics::drawImage(Image *image, int x, int y)
@@ -292,7 +299,16 @@ void Graphics::drawImageRect(int x, int y, int w, int h,
void Graphics::updateScreen()
{
- SDL_RenderPresent(mRenderer);
+ if (!mScreenTexture) {
+ // Simple case when we're rendering directly to the window
+ SDL_RenderPresent(mRenderer);
+ } else {
+ // Otherwise, we now render the screen surface to the window
+ SDL_SetRenderTarget(mRenderer, NULL);
+ SDL_RenderCopy(mRenderer, mScreenTexture, NULL, NULL);
+ SDL_RenderPresent(mRenderer);
+ SDL_SetRenderTarget(mRenderer, mScreenTexture);
+ }
}
SDL_Surface *Graphics::getScreenshot()
@@ -346,6 +362,11 @@ void Graphics::updateSDLClipRect()
SDL_RenderSetClipRect(mRenderer, &rect);
}
+int Graphics::getScale(int w, int h)
+{
+ return std::max(w / 640, h / 360);
+}
+
void Graphics::drawPoint(int x, int y)
{
if (mClipStack.empty())