mirror of https://github.com/stella-emu/stella.git
Detect render target support when renderer is created, log if it is absent.
This commit is contained in:
parent
796cf27202
commit
d0e18d7e91
|
@ -32,7 +32,8 @@ FrameBufferSDL2::FrameBufferSDL2(OSystem& osystem)
|
|||
: FrameBuffer(osystem),
|
||||
myWindow(nullptr),
|
||||
myRenderer(nullptr),
|
||||
myCenter(false)
|
||||
myCenter(false),
|
||||
myRenderTargetSupport(false)
|
||||
{
|
||||
ASSERT_MAIN_THREAD;
|
||||
|
||||
|
@ -318,7 +319,10 @@ bool FrameBufferSDL2::setVideoMode(const string& title, const VideoMode& mode)
|
|||
const string& video = myOSystem.settings().getString("video"); // Render hint
|
||||
if(video != "")
|
||||
SDL_SetHint(SDL_HINT_RENDER_DRIVER, video.c_str());
|
||||
|
||||
myRenderer = SDL_CreateRenderer(myWindow, -1, renderFlags);
|
||||
detectFeatures();
|
||||
|
||||
if(myRenderer == nullptr)
|
||||
{
|
||||
string msg = "ERROR: Unable to create SDL renderer: " + string(SDL_GetError());
|
||||
|
@ -468,3 +472,44 @@ const SDL_PixelFormat& FrameBufferSDL2::pixelFormat() const
|
|||
{
|
||||
return *myPixelFormat;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void FrameBufferSDL2::detectFeatures()
|
||||
{
|
||||
myRenderTargetSupport = detectRenderTargetSupport();
|
||||
|
||||
if (myRenderer) {
|
||||
if (!myRenderTargetSupport) {
|
||||
Logger::info("Render targets are not supported --- QIS not available");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool FrameBufferSDL2::detectRenderTargetSupport()
|
||||
{
|
||||
if (myRenderer == nullptr) return false;
|
||||
|
||||
SDL_RendererInfo info;
|
||||
|
||||
SDL_GetRendererInfo(myRenderer, &info);
|
||||
|
||||
if (!(info.flags & SDL_RENDERER_TARGETTEXTURE)) return false;
|
||||
|
||||
SDL_Texture* tex = SDL_CreateTexture(myRenderer, myPixelFormat->format, SDL_TEXTUREACCESS_TARGET, 16, 16);
|
||||
|
||||
if (!tex) return false;
|
||||
|
||||
int sdlError = SDL_SetRenderTarget(myRenderer, tex);
|
||||
SDL_SetRenderTarget(myRenderer, nullptr);
|
||||
|
||||
SDL_DestroyTexture(tex);
|
||||
|
||||
return sdlError == 0;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool FrameBufferSDL2::hasRenderTargetSupport() const
|
||||
{
|
||||
return myRenderTargetSupport;
|
||||
}
|
||||
|
|
|
@ -129,6 +129,11 @@ class FrameBufferSDL2 : public FrameBuffer
|
|||
*/
|
||||
bool isInitialized() const;
|
||||
|
||||
/**
|
||||
Does the renderer support render targets?
|
||||
*/
|
||||
bool hasRenderTargetSupport() const;
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// The following are derived from protected methods in FrameBuffer.hxx
|
||||
|
@ -193,6 +198,16 @@ class FrameBufferSDL2 : public FrameBuffer
|
|||
*/
|
||||
void renderToScreen() override;
|
||||
|
||||
/**
|
||||
After the renderer has been created, detect the features it supports.
|
||||
*/
|
||||
void detectFeatures();
|
||||
|
||||
/**
|
||||
Detect render target support;
|
||||
*/
|
||||
bool detectRenderTargetSupport();
|
||||
|
||||
private:
|
||||
// The SDL video buffer
|
||||
SDL_Window* myWindow;
|
||||
|
@ -207,6 +222,8 @@ class FrameBufferSDL2 : public FrameBuffer
|
|||
// last position of windowed window
|
||||
Common::Point myWindowedPos;
|
||||
|
||||
bool myRenderTargetSupport;
|
||||
|
||||
private:
|
||||
// Following constructors and assignment operators not supported
|
||||
FrameBufferSDL2() = delete;
|
||||
|
|
|
@ -39,26 +39,9 @@ HqBlitter::~HqBlitter()
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool HqBlitter::isSupported(FrameBufferSDL2 &fb)
|
||||
{
|
||||
ASSERT_MAIN_THREAD;
|
||||
|
||||
if (!fb.isInitialized()) throw runtime_error("framebuffer 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;
|
||||
return fb.hasRenderTargetSupport();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
Loading…
Reference in New Issue