mirror of https://github.com/stella-emu/stella.git
Use and alternate between two textures for TIA image.
* Avoids blocking if the texture is still locked in the rendering pipeline and fixes framerates on the R77.
This commit is contained in:
parent
2d0221ae1f
commit
f511f9fbe7
|
@ -25,6 +25,7 @@ FBSurfaceSDL2::FBSurfaceSDL2(FrameBufferSDL2& buffer,
|
||||||
: myFB(buffer),
|
: myFB(buffer),
|
||||||
mySurface(nullptr),
|
mySurface(nullptr),
|
||||||
myTexture(nullptr),
|
myTexture(nullptr),
|
||||||
|
mySecondaryTexture(nullptr),
|
||||||
mySurfaceIsDirty(true),
|
mySurfaceIsDirty(true),
|
||||||
myIsVisible(true),
|
myIsVisible(true),
|
||||||
myTexAccess(SDL_TEXTUREACCESS_STREAMING),
|
myTexAccess(SDL_TEXTUREACCESS_STREAMING),
|
||||||
|
@ -135,9 +136,15 @@ bool FBSurfaceSDL2::render()
|
||||||
|
|
||||||
if(myIsVisible)
|
if(myIsVisible)
|
||||||
{
|
{
|
||||||
if(myTexAccess == SDL_TEXTUREACCESS_STREAMING)
|
SDL_Texture* texture = myTexture;
|
||||||
|
|
||||||
|
if(myTexAccess == SDL_TEXTUREACCESS_STREAMING) {
|
||||||
SDL_UpdateTexture(myTexture, &mySrcR, mySurface->pixels, mySurface->pitch);
|
SDL_UpdateTexture(myTexture, &mySrcR, mySurface->pixels, mySurface->pitch);
|
||||||
SDL_RenderCopy(myFB.myRenderer, myTexture, &mySrcR, &myDstR);
|
myTexture = mySecondaryTexture;
|
||||||
|
mySecondaryTexture = texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_RenderCopy(myFB.myRenderer, texture, &mySrcR, &myDstR);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -157,8 +164,10 @@ void FBSurfaceSDL2::free()
|
||||||
{
|
{
|
||||||
ASSERT_MAIN_THREAD;
|
ASSERT_MAIN_THREAD;
|
||||||
|
|
||||||
if(myTexture)
|
SDL_Texture* textures[] = {myTexture, mySecondaryTexture};
|
||||||
{
|
for (SDL_Texture* texture: textures) {
|
||||||
|
if (!texture) continue;
|
||||||
|
|
||||||
SDL_DestroyTexture(myTexture);
|
SDL_DestroyTexture(myTexture);
|
||||||
myTexture = nullptr;
|
myTexture = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -174,15 +183,24 @@ void FBSurfaceSDL2::reload()
|
||||||
myTexture = SDL_CreateTexture(myFB.myRenderer, myFB.myPixelFormat->format,
|
myTexture = SDL_CreateTexture(myFB.myRenderer, myFB.myPixelFormat->format,
|
||||||
myTexAccess, mySurface->w, mySurface->h);
|
myTexAccess, mySurface->w, mySurface->h);
|
||||||
|
|
||||||
|
if (myTexAccess == SDL_TEXTUREACCESS_STREAMING)
|
||||||
|
mySecondaryTexture = SDL_CreateTexture(myFB.myRenderer, myFB.myPixelFormat->format,
|
||||||
|
myTexAccess, mySurface->w, mySurface->h);
|
||||||
|
|
||||||
// If the data is static, we only upload it once
|
// If the data is static, we only upload it once
|
||||||
if(myTexAccess == SDL_TEXTUREACCESS_STATIC)
|
if(myTexAccess == SDL_TEXTUREACCESS_STATIC)
|
||||||
SDL_UpdateTexture(myTexture, nullptr, myStaticData.get(), myStaticPitch);
|
SDL_UpdateTexture(myTexture, nullptr, myStaticData.get(), myStaticPitch);
|
||||||
|
|
||||||
// Blending enabled?
|
SDL_Texture* textures[] = {myTexture, mySecondaryTexture};
|
||||||
if(myBlendEnabled)
|
for (SDL_Texture* texture: textures) {
|
||||||
{
|
if (!texture) continue;
|
||||||
SDL_SetTextureBlendMode(myTexture, SDL_BLENDMODE_BLEND);
|
|
||||||
SDL_SetTextureAlphaMod(myTexture, myBlendAlpha);
|
// Blending enabled?
|
||||||
|
if(myBlendEnabled)
|
||||||
|
{
|
||||||
|
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||||
|
SDL_SetTextureAlphaMod(texture, myBlendAlpha);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ class FBSurfaceSDL2 : public FBSurface
|
||||||
|
|
||||||
SDL_Surface* mySurface;
|
SDL_Surface* mySurface;
|
||||||
SDL_Texture* myTexture;
|
SDL_Texture* myTexture;
|
||||||
|
SDL_Texture* mySecondaryTexture;
|
||||||
SDL_Rect mySrcR, myDstR;
|
SDL_Rect mySrcR, myDstR;
|
||||||
|
|
||||||
bool mySurfaceIsDirty;
|
bool mySurfaceIsDirty;
|
||||||
|
|
Loading…
Reference in New Issue