mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-03-28 14:56:22 +01:00
Bitmap: short-circuit shader/bilinear interpolation
Benchmark shows a speedup from 10.4s to 4.1s.
This commit is contained in:
parent
1114671567
commit
7e9937b80f
3 changed files with 69 additions and 16 deletions
|
@ -737,16 +737,16 @@ Bitmap::Bitmap(const Bitmap &other, int frame)
|
|||
throw e;
|
||||
}
|
||||
|
||||
GLMeta::blitBegin(p->gl);
|
||||
GLMeta::blitBegin(p->gl, false, SameScale);
|
||||
// Blit just the current frame of the other animated bitmap
|
||||
if (!other.isAnimated() || frame == -1) {
|
||||
GLMeta::blitSource(other.getGLTypes());
|
||||
GLMeta::blitSource(other.getGLTypes(), SameScale);
|
||||
}
|
||||
else {
|
||||
auto &frames = other.getFrames();
|
||||
GLMeta::blitSource(frames[clamp(frame, 0, (int)frames.size() - 1)]);
|
||||
GLMeta::blitSource(frames[clamp(frame, 0, (int)frames.size() - 1)], SameScale);
|
||||
}
|
||||
GLMeta::blitRectangle(rect(), rect(), true);
|
||||
GLMeta::blitRectangle(rect(), rect());
|
||||
GLMeta::blitEnd();
|
||||
}
|
||||
else {
|
||||
|
@ -768,9 +768,9 @@ Bitmap::Bitmap(const Bitmap &other, int frame)
|
|||
throw e;
|
||||
}
|
||||
|
||||
GLMeta::blitBegin(newframe);
|
||||
GLMeta::blitSource(sourceframe);
|
||||
GLMeta::blitRectangle(rect(), rect(), true);
|
||||
GLMeta::blitBegin(newframe, false, SameScale);
|
||||
GLMeta::blitSource(sourceframe, SameScale);
|
||||
GLMeta::blitRectangle(rect(), rect());
|
||||
GLMeta::blitEnd();
|
||||
|
||||
p->animation.frames.push_back(newframe);
|
||||
|
@ -806,9 +806,9 @@ Bitmap::Bitmap(TEXFBO &other)
|
|||
|
||||
// Skip blitting to lores texture, since only the hires one will be displayed.
|
||||
if (p->selfHires == nullptr) {
|
||||
GLMeta::blitBegin(p->gl);
|
||||
GLMeta::blitSource(other);
|
||||
GLMeta::blitRectangle(rect(), rect(), true);
|
||||
GLMeta::blitBegin(p->gl, false, SameScale);
|
||||
GLMeta::blitSource(other, SameScale);
|
||||
GLMeta::blitRectangle(rect(), rect());
|
||||
GLMeta::blitEnd();
|
||||
}
|
||||
|
||||
|
@ -1086,10 +1086,16 @@ void Bitmap::stretchBlt(IntRect destRect,
|
|||
SDL_Surface *blitTemp = 0;
|
||||
bool touchesTaintedArea = p->touchesTaintedArea(destRect);
|
||||
bool unpack_subimage = srcSurf && gl.unpack_subimage;
|
||||
|
||||
|
||||
const bool scaleIsOne = sourceRect.w == destRect.w && sourceRect.h == destRect.h;
|
||||
if (scaleIsOne) {
|
||||
smooth = false;
|
||||
}
|
||||
|
||||
if (!srcSurf && opacity == 255 && !touchesTaintedArea)
|
||||
{
|
||||
/* Fast blit */
|
||||
// TODO: Use bitmapSmoothScaling/bitmapSmoothScalingDown configs for this.
|
||||
GLMeta::blitBegin(getGLTypes());
|
||||
GLMeta::blitSource(source.getGLTypes());
|
||||
GLMeta::blitRectangle(sourceRect, destRect, smooth);
|
||||
|
@ -1227,8 +1233,8 @@ void Bitmap::stretchBlt(IntRect destRect,
|
|||
TEXFBO &gpTex = shState->gpTexFBO(abs(destRect.w), abs(destRect.h));
|
||||
Vec2i gpTexSize;
|
||||
|
||||
GLMeta::blitBegin(gpTex);
|
||||
GLMeta::blitSource(getGLTypes());
|
||||
GLMeta::blitBegin(gpTex, false, SameScale);
|
||||
GLMeta::blitSource(getGLTypes(), SameScale);
|
||||
GLMeta::blitRectangle(destRect, IntRect(0, 0, abs(destRect.w), abs(destRect.h)));
|
||||
GLMeta::blitEnd();
|
||||
|
||||
|
@ -2432,9 +2438,9 @@ int Bitmap::addFrame(Bitmap &source, int position)
|
|||
p->surface = 0;
|
||||
}
|
||||
else {
|
||||
GLMeta::blitBegin(newframe);
|
||||
GLMeta::blitSource(source.getGLTypes());
|
||||
GLMeta::blitRectangle(rect(), rect(), true);
|
||||
GLMeta::blitBegin(newframe, false, SameScale);
|
||||
GLMeta::blitSource(source.getGLTypes(), SameScale);
|
||||
GLMeta::blitRectangle(rect(), rect());
|
||||
GLMeta::blitEnd();
|
||||
}
|
||||
|
||||
|
|
BIN
tests/benchmark-bitmap-dup/Graphics/Pictures/lime.png
Normal file
BIN
tests/benchmark-bitmap-dup/Graphics/Pictures/lime.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5 KiB |
47
tests/benchmark-bitmap-dup/dup-speed-test.rb
Executable file
47
tests/benchmark-bitmap-dup/dup-speed-test.rb
Executable file
|
@ -0,0 +1,47 @@
|
|||
# Test suite for mkxp-z.
|
||||
# Copyright 2023-2024 Splendide Imaginarius.
|
||||
# License GPLv2+.
|
||||
#
|
||||
# Run the suite via the "customScript" field in mkxp.json.
|
||||
|
||||
def dump(bmp, spr, desc)
|
||||
spr.bitmap = bmp
|
||||
Graphics.wait(1)
|
||||
end
|
||||
|
||||
src = Bitmap.new("Graphics/Pictures/lime")
|
||||
|
||||
starttime = System.uptime
|
||||
|
||||
for i in 1..100 do
|
||||
dst1 = src.dup
|
||||
dst2 = src.dup
|
||||
dst3 = src.dup
|
||||
dst4 = src.dup
|
||||
dst5 = src.dup
|
||||
dst6 = src.dup
|
||||
dst7 = src.dup
|
||||
dst8 = src.dup
|
||||
dst9 = src.dup
|
||||
dst10 = src.dup
|
||||
|
||||
dst1.dispose
|
||||
dst2.dispose
|
||||
dst3.dispose
|
||||
dst4.dispose
|
||||
dst5.dispose
|
||||
dst6.dispose
|
||||
dst7.dispose
|
||||
dst8.dispose
|
||||
dst9.dispose
|
||||
dst10.dispose
|
||||
|
||||
GC.start
|
||||
Graphics.wait(1)
|
||||
end
|
||||
|
||||
endtime = System.uptime
|
||||
|
||||
System::puts("\n\nTotal dup time: %s\n\n" % [endtime - starttime])
|
||||
|
||||
exit
|
Loading…
Add table
Reference in a new issue