Revert "move towards blitting on the GPU"

This reverts commit a7d6de00e1.
This commit is contained in:
Tim Felgentreff 2020-04-18 13:35:38 +02:00
parent a7d6de00e1
commit 2770b3c524
5 changed files with 44 additions and 74 deletions

View file

@ -51,7 +51,7 @@ class CGraphic : public gcn::Image
};
protected:
CGraphic() : Surface(NULL), SurfaceFlip(NULL), Texture(NULL), TextureFlip(NULL), frame_map(NULL),
CGraphic() : Surface(NULL), SurfaceFlip(NULL), frame_map(NULL),
Width(0), Height(0), NumFrames(1), GraphicWidth(0), GraphicHeight(0),
Refs(1), Resized(false)
{
@ -106,8 +106,6 @@ public:
std::string HashFile; /// Filename used in hash
SDL_Surface *Surface; /// Surface
SDL_Surface *SurfaceFlip; /// Flipped surface
SDL_Texture *Texture;
SDL_Texture *TextureFlip;
frame_pos_t *frame_map;
frame_pos_t *frameFlip_map;
void GenFramesMap();
@ -401,7 +399,6 @@ extern void ToggleGrabMouse(int mode);
extern EventCallback GameCallbacks; /// Game callbacks
extern EventCallback EditorCallbacks; /// Editor callbacks
extern Uint32 ColorTransparent;
extern Uint32 ColorBlack;
extern Uint32 ColorDarkGreen;
extern Uint32 ColorLightBlue;

View file

@ -431,7 +431,7 @@ static void DrawEvents()
*/
void CMinimap::Draw() const
{
SDL_Rect drect = {Sint16(X), Sint16(Y), MinimapSurface->w, MinimapSurface->h};
SDL_Rect drect = {Sint16(X), Sint16(Y), 0, 0};
SDL_BlitSurface(MinimapSurface, NULL, TheScreen, &drect);
DrawEvents();

View file

@ -90,9 +90,10 @@ void CGraphic::DrawClip(int x, int y) const
void CGraphic::DrawSub(int gx, int gy, int w, int h, int x, int y) const
{
SDL_Rect srect = {Sint16(gx), Sint16(gy), Uint16(w), Uint16(h)};
SDL_Rect drect = {Sint16(x), Sint16(y), srect.w, srect.h};
SDL_RenderCopy(TheRenderer, Texture, &srect, &drect);
// SDL_BlitSurface(Surface, &srect, TheScreen, &drect);
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
//SDL_LockSurface(TheScreen);
SDL_BlitSurface(Surface, &srect, TheScreen, &drect);
//SDL_UnlockSurface(TheScreen);
}
/**
@ -112,7 +113,10 @@ void CGraphic::DrawSubClip(int gx, int gy, int w, int h, int x, int y) const
CLIP_RECTANGLE(x, y, w, h);
gx += x - oldx;
gy += y - oldy;
DrawSub(gx, gy, w, h, x, y);
SDL_Rect srect = {Sint16(gx), Sint16(gy), Uint16(w), Uint16(h)};
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
SDL_BlitSurface(Surface, &srect, TheScreen, &drect);
}
/**
@ -130,13 +134,10 @@ void CGraphic::DrawSubTrans(int gx, int gy, int w, int h, int x, int y,
unsigned char alpha) const
{
Uint8 oldalpha = 0xff;
// SDL_GetSurfaceAlphaMod(Surface, &oldalpha);
// SDL_SetSurfaceAlphaMod(Surface, alpha);
SDL_GetTextureAlphaMod(Texture, &oldalpha);
SDL_SetTextureAlphaMod(Texture, alpha);
SDL_GetSurfaceAlphaMod(Surface, &oldalpha);
SDL_SetSurfaceAlphaMod(Surface, alpha);
DrawSub(gx, gy, w, h, x, y);
SDL_SetTextureAlphaMod(Texture, oldalpha);
// SDL_SetSurfaceAlphaMod(Surface, oldalpha);
SDL_SetSurfaceAlphaMod(Surface, oldalpha);
}
/**
@ -222,10 +223,9 @@ void CPlayerColorGraphic::DrawPlayerColorFrameClip(int player, unsigned frame,
void CGraphic::DrawFrameX(unsigned frame, int x, int y) const
{
SDL_Rect srect = {frameFlip_map[frame].x, frameFlip_map[frame].y, Uint16(Width), Uint16(Height)};
SDL_Rect drect = {Sint16(x), Sint16(y), srect.w, srect.h};
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
SDL_RenderCopy(TheRenderer, TextureFlip, &srect, &drect);
// SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
}
/**
@ -245,25 +245,23 @@ void CGraphic::DrawFrameClipX(unsigned frame, int x, int y) const
srect.x += x - oldx;
srect.y += y - oldy;
SDL_Rect drect = {Sint16(x), Sint16(y), srect.w, srect.h};
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
SDL_RenderCopy(TheRenderer, TextureFlip, &srect, &drect);
// SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
int ret;
//SDL_SetSurfaceAlphaMod(SurfaceFlip, 0xFF);
ret = SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
}
void CGraphic::DrawFrameTransX(unsigned frame, int x, int y, int alpha) const
{
SDL_Rect srect = {frameFlip_map[frame].x, frameFlip_map[frame].y, Uint16(Width), Uint16(Height)};
SDL_Rect drect = {Sint16(x), Sint16(y), srect.w, srect.h};
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
Uint8 oldalpha = 0xff;
SDL_GetTextureAlphaMod(TextureFlip, &oldalpha);
// SDL_GetSurfaceAlphaMod(SurfaceFlip, &oldalpha);
SDL_SetTextureAlphaMod(TextureFlip, alpha);
// SDL_SetSurfaceAlphaMod(SurfaceFlip, alpha);
SDL_RenderCopy(TheRenderer, TextureFlip, &srect, &drect);
// SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
SDL_SetTextureAlphaMod(TextureFlip, oldalpha);
// SDL_SetSurfaceAlphaMod(SurfaceFlip, oldalpha);
SDL_GetSurfaceAlphaMod(SurfaceFlip, &oldalpha);
SDL_SetSurfaceAlphaMod(SurfaceFlip, alpha);
SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
SDL_SetSurfaceAlphaMod(SurfaceFlip, oldalpha);
}
void CGraphic::DrawFrameClipTransX(unsigned frame, int x, int y, int alpha) const
@ -276,16 +274,13 @@ void CGraphic::DrawFrameClipTransX(unsigned frame, int x, int y, int alpha) cons
srect.x += x - oldx;
srect.y += y - oldy;
SDL_Rect drect = {Sint16(x), Sint16(y), srect.w, srect.h};
SDL_Rect drect = {Sint16(x), Sint16(y), 0, 0};
Uint8 oldalpha = 0xff;
SDL_GetTextureAlphaMod(TextureFlip, &oldalpha);
// SDL_GetSurfaceAlphaMod(SurfaceFlip, &oldalpha);
SDL_SetTextureAlphaMod(TextureFlip, alpha);
// SDL_SetSurfaceAlphaMod(SurfaceFlip, alpha);
SDL_RenderCopy(TheRenderer, TextureFlip, &srect, &drect);
// SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
SDL_SetTextureAlphaMod(TextureFlip, oldalpha);
// SDL_SetSurfaceAlphaMod(SurfaceFlip, oldalpha);
SDL_GetSurfaceAlphaMod(SurfaceFlip, &oldalpha);
SDL_SetSurfaceAlphaMod(SurfaceFlip, alpha);
SDL_BlitSurface(SurfaceFlip, &srect, TheScreen, &drect);
SDL_SetSurfaceAlphaMod(SurfaceFlip, oldalpha);
}
/**
@ -608,9 +603,6 @@ void CGraphic::Load(bool grayscale)
}
GenFramesMap();
Texture = SDL_CreateTextureFromSurface(TheRenderer, Surface);
SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_BLEND);
return;
error:
@ -659,12 +651,10 @@ void CGraphic::Free(CGraphic *g)
FreeSurface(&g->Surface);
delete[] g->frame_map;
g->frame_map = NULL;
SDL_DestroyTexture(g->Texture);
FreeSurface(&g->SurfaceFlip);
delete[] g->frameFlip_map;
g->frameFlip_map = NULL;
SDL_DestroyTexture(g->TextureFlip);
if (!g->HashFile.empty()) {
GraphicHash.erase(g->HashFile);
@ -731,9 +721,6 @@ void CGraphic::Flip()
frameFlip_map[frame].x = ((NumFrames - frame - 1) % (SurfaceFlip->w / Width)) * Width;
frameFlip_map[frame].y = (frame / (SurfaceFlip->w / Width)) * Height;
}
TextureFlip = SDL_CreateTextureFromSurface(TheRenderer, SurfaceFlip);
SDL_SetTextureBlendMode(TextureFlip, SDL_BLENDMODE_BLEND);
}
/**
@ -860,9 +847,6 @@ void CGraphic::Resize(int w, int h)
Height = GraphicHeight = h;
GenFramesMap();
SDL_DestroyTexture(Texture);
Texture = SDL_CreateTextureFromSurface(TheRenderer, Surface);
SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_BLEND);
}
/**
@ -877,14 +861,15 @@ void CGraphic::SetOriginalSize()
return;
}
FreeSurface(&Surface);
SDL_DestroyTexture(Texture);
Surface = NULL;
if (Surface) {
FreeSurface(&Surface);
Surface = NULL;
}
delete[] frame_map;
frame_map = NULL;
if (SurfaceFlip) {
FreeSurface(&SurfaceFlip);
SDL_DestroyTexture(TextureFlip);
SurfaceFlip = NULL;
}
delete[] frameFlip_map;
@ -948,18 +933,10 @@ void CGraphic::MakeShadow()
SDL_SetPaletteColors(Surface->format->palette, colors, 0, 256);
SDL_SetSurfaceAlphaMod(Surface, 128);
SDL_DestroyTexture(Texture);
Texture = SDL_CreateTextureFromSurface(TheRenderer, Surface);
SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(Texture, 128);
if (SurfaceFlip) {
SDL_SetPaletteColors(SurfaceFlip->format->palette, colors, 0, 256);
SDL_SetSurfaceAlphaMod(SurfaceFlip, 128);
SDL_DestroyTexture(TextureFlip);
TextureFlip = SDL_CreateTextureFromSurface(TheRenderer, Surface);
SDL_SetTextureBlendMode(TextureFlip, SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(TextureFlip, 128);
}
}

View file

@ -339,21 +339,19 @@ void InitVideoSdl()
exit(1);
}
if (!TheRenderer) TheRenderer = SDL_CreateRenderer(TheWindow, -1, 0);
SDL_SetRenderDrawBlendMode(TheRenderer, SDL_BLENDMODE_BLEND);
SDL_RenderSetLogicalSize(TheRenderer, Video.Width, Video.Height);
SDL_SetRenderDrawColor(TheRenderer, 0, 0, 0, 0);
SDL_SetRenderDrawColor(TheRenderer, 0, 0, 0, 255);
TheScreen = SDL_CreateRGBSurface(0, Video.Width, Video.Height, 32,
0x00FF0000,
0x0000FF00,
0x000000FF,
0xFF000000); //0xFF000000);
0); //0xFF000000);
Assert(SDL_MUSTLOCK(TheScreen) == 0);
TheTexture = SDL_CreateTexture(TheRenderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
Video.Width, Video.Height);
SDL_SetTextureBlendMode(TheTexture, SDL_BLENDMODE_BLEND);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
#if ! defined(USE_WIN32) && ! defined(USE_MAEMO)
@ -417,7 +415,6 @@ void InitVideoSdl()
InitKey2Str();
ColorTransparent = Video.MapRGBA(TheScreen->format, 0, 0, 0, 0);
ColorBlack = Video.MapRGB(TheScreen->format, 0, 0, 0);
ColorDarkGreen = Video.MapRGB(TheScreen->format, 48, 100, 4);
ColorLightBlue = Video.MapRGB(TheScreen->format, 52, 113, 166);
@ -664,10 +661,13 @@ void WaitEventsOneFrame()
void RealizeVideoMemory()
{
if (NumRects) {
//SDL_UpdateWindowSurfaceRects(TheWindow, Rects, NumRects);
SDL_UpdateTexture(TheTexture, NULL, TheScreen->pixels, TheScreen->pitch);
SDL_RenderClear(TheRenderer);
//for (int i = 0; i < NumRects; i++)
// SDL_UpdateTexture(TheTexture, &Rects[i], TheScreen->pixels, TheScreen->pitch);
SDL_RenderCopy(TheRenderer, TheTexture, NULL, NULL);
SDL_RenderPresent(TheRenderer);
SDL_RenderClear(TheRenderer);
NumRects = 0;
}
HideCursor();

View file

@ -171,7 +171,6 @@ static std::vector<Clip> Clips;
int VideoSyncSpeed = 100; /// 0 disable interrupts
int SkipFrames; /// Skip this frames
Uint32 ColorTransparent;
Uint32 ColorBlack;
Uint32 ColorDarkGreen;
Uint32 ColorLightBlue;
@ -257,7 +256,7 @@ void CVideo::UnlockScreen()
*/
void CVideo::ClearScreen()
{
FillRectangle(ColorTransparent, 0, 0, Video.Width, Video.Height);
FillRectangle(ColorBlack, 0, 0, Video.Width, Video.Height);
}
/**
@ -290,12 +289,9 @@ bool CVideo::ResizeScreen(int w, int h)
// new texture
Uint32 format;
int access, oldW, oldH;
SDL_BlendMode blend;
SDL_QueryTexture(TheTexture, &format, &access, &oldW, &oldH);
SDL_GetTextureBlendMode(TheTexture, &blend);
SDL_DestroyTexture(TheTexture);
TheTexture = SDL_CreateTexture(TheRenderer, format, access, w, h);
SDL_SetTextureBlendMode(TheTexture, blend);
SetClipping(0, 0, w - 1, h - 1);