More sophisticated detection whether qis is supported.

This commit is contained in:
Christian Speckner 2019-12-13 21:00:23 +01:00
parent 59b5a5cc88
commit 4e444f7383
3 changed files with 36 additions and 11 deletions

View File

@ -27,10 +27,6 @@ unique_ptr<Blitter> BlitterFactory::createBlitter(FrameBufferSDL2& fb)
throw runtime_error("BlitterFactory requires an initialized framebuffer!"); throw runtime_error("BlitterFactory requires an initialized framebuffer!");
} }
SDL_RendererInfo info; return HqBlitter::isSupported(fb) ?
SDL_GetRendererInfo(fb.renderer(), &info);
return (info.flags & SDL_RENDERER_TARGETTEXTURE) ?
unique_ptr<Blitter>(new HqBlitter(fb)) : unique_ptr<Blitter>(new BilinearBlitter(fb)); unique_ptr<Blitter>(new HqBlitter(fb)) : unique_ptr<Blitter>(new BilinearBlitter(fb));
} }

View File

@ -36,6 +36,31 @@ HqBlitter::~HqBlitter()
free(); free();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool HqBlitter::isSupported(FrameBufferSDL2 &fb)
{
ASSERT_MAIN_THREAD;
if (!fb.isInitialized()) throw runtime_error("frambuffer not initialized");
SDL_RendererInfo info;
SDL_GetRendererInfo(fb.renderer(), &info);
if (!(info.flags & SDL_RENDERER_TARGETTEXTURE)) return false;
SDL_Texture* tex = SDL_CreateTexture(fb.renderer(), fb.pixelFormat().format, SDL_TEXTUREACCESS_TARGET, 16, 16);
if (!tex) return false;
int sdlError = SDL_SetRenderTarget(fb.renderer(), tex);
SDL_SetRenderTarget(fb.renderer(), nullptr);
SDL_DestroyTexture(tex);
return sdlError == 0;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void HqBlitter::reinitialize( void HqBlitter::reinitialize(
SDL_Rect srcRect, SDL_Rect srcRect,
@ -103,15 +128,17 @@ void HqBlitter::blit(SDL_Surface& surface)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void HqBlitter::blitToIntermediate() void HqBlitter::blitToIntermediate()
{ {
SDL_Rect r = mySrcRect; ASSERT_MAIN_THREAD;
r.x = r.y = 0;
SDL_UpdateTexture(myIntermediateTexture, nullptr, myBlankBuffer.get(), 4 * myIntermediateRect.w); SDL_Rect r = mySrcRect;
r.x = r.y = 0;
SDL_SetRenderTarget(myFB.renderer(), myIntermediateTexture); SDL_UpdateTexture(myIntermediateTexture, nullptr, myBlankBuffer.get(), 4 * myIntermediateRect.w);
SDL_RenderCopy(myFB.renderer(), mySrcTexture, &r, &myIntermediateRect);
SDL_SetRenderTarget(myFB.renderer(), nullptr); SDL_SetRenderTarget(myFB.renderer(), myIntermediateTexture);
SDL_RenderCopy(myFB.renderer(), mySrcTexture, &r, &myIntermediateRect);
SDL_SetRenderTarget(myFB.renderer(), nullptr);
} }

View File

@ -28,6 +28,8 @@ class HqBlitter : public Blitter {
HqBlitter(FrameBufferSDL2& fb); HqBlitter(FrameBufferSDL2& fb);
static bool isSupported(FrameBufferSDL2 &fb);
virtual ~HqBlitter(); virtual ~HqBlitter();
virtual void reinitialize( virtual void reinitialize(