summaryrefslogtreecommitdiff
path: root/src/graphics.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-05 01:36:21 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-05 02:13:21 +0300
commit237cbc536ce74a0d4f1540b299e29f81e903b3ae (patch)
treeed852cd138313be403b9845a8798f3871b7f908e /src/graphics.cpp
parent4ee3cee44c73802059506787e74adeacd39e5230 (diff)
downloadmanaverse-237cbc536ce74a0d4f1540b299e29f81e903b3ae.tar.gz
manaverse-237cbc536ce74a0d4f1540b299e29f81e903b3ae.tar.bz2
manaverse-237cbc536ce74a0d4f1540b299e29f81e903b3ae.tar.xz
manaverse-237cbc536ce74a0d4f1540b299e29f81e903b3ae.zip
Improve fillrectangle speed.
Diffstat (limited to 'src/graphics.cpp')
-rw-r--r--src/graphics.cpp54
1 files changed, 53 insertions, 1 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp
index e6841fa5c..3a6aef3bc 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -37,6 +37,10 @@
#include "debug.h"
+static unsigned int *cR = nullptr;
+static unsigned int *cG = nullptr;
+static unsigned int *cB = nullptr;
+
Graphics::Graphics():
mWidth(0),
mHeight(0),
@@ -49,7 +53,9 @@ Graphics::Graphics():
mSecure(false),
mOpenGL(0),
mEnableResize(false),
- mNoFrame(false)
+ mNoFrame(false),
+ mOldPixel(0),
+ mOldAlpha(0)
{
mRect.x = 0;
mRect.y = 0;
@@ -894,10 +900,12 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle)
}
case 4:
{
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const unsigned pb = (pixel & 0xff) * mColor.a;
const unsigned pg = (pixel & 0xff00) * mColor.a;
const unsigned pr = (pixel & 0xff0000) * mColor.a;
const unsigned a1 = (255 - mColor.a);
+
for (y = y1; y < y2; y++)
{
Uint8 *p0 = static_cast<Uint8 *>(mTarget->pixels)
@@ -915,6 +923,50 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle)
| (g & 0xff00) | (r & 0xff0000));
}
}
+#else
+ if (!cR)
+ {
+ cR = new unsigned int[0xff];
+ cG = new unsigned int[0xff];
+ cB = new unsigned int[0xff];
+ mOldPixel = 0;
+ mOldAlpha = mColor.a;
+ }
+
+ if (pixel != mOldPixel || mColor.a != mOldAlpha)
+ {
+ const unsigned pb = (pixel & 0xff) * mColor.a;
+ const unsigned pg = (pixel & 0xff00) * mColor.a;
+ const unsigned pr = (pixel & 0xff0000) * mColor.a;
+ const unsigned a1 = (255 - mColor.a);
+
+ const unsigned int a2 = a1 * 0xff;
+ const unsigned int a3 = a1 * 0xff00;
+
+ for (int f = 0; f < 0xff; f ++)
+ {
+ cB[f] = ((pb + f * a1) >> 8) & 0xff;
+ cG[f] = ((pg + f * a2) >> 8) & 0xff00;
+ cR[f] = ((pr + f * a3) >> 8) & 0xff0000;
+ }
+
+ mOldPixel = pixel;
+ mOldAlpha = mColor.a;
+ }
+
+ for (y = y1; y < y2; y++)
+ {
+ Uint32 *p0 = reinterpret_cast<Uint32*>(static_cast<Uint8*>(
+ mTarget->pixels) + y * mTarget->pitch);
+ for (x = x1; x < x2; x++)
+ {
+ Uint32 *p = p0 + x;
+ Uint32 dst = *reinterpret_cast<Uint32*>(p);
+ *p = cB[dst & 0xff] | cG[(dst & 0xff00) >> 8]
+ | cR[(dst & 0xff0000) >> 16];
+ }
+ }
+#endif
break;
}
default: