[Marble-commits] KDE/kdeedu/marble/src/lib
Bernhard Beschow
bbeschow at cs.tu-berlin.de
Wed Jan 19 18:11:32 CET 2011
SVN commit 1215788 by beschow:
forward-port r1211240: turn GpFifo into a class and rename it to EmbossFifo
This patch resolves a small bug in the bumpmapping code where the gradient for the relief wasn't calculated properly.
It also turns the hidden union "GpFifo" in TextureColorizer.cpp into a proper FIFO class in order to make the code less fragile. The patch relies on very basic compiler
optimizations, relinguishing usage of a union.
I get ~3.5 fps on my machine before and after this patch is applied.
REVIEW: 6205
M +30 -18 TextureColorizer.cpp
--- trunk/KDE/kdeedu/marble/src/lib/TextureColorizer.cpp #1215787:1215788
@@ -33,22 +33,36 @@
namespace Marble
{
-typedef struct
+class EmbossFifo
{
+public:
+ EmbossFifo()
+ : x1( 0 )
+ , x2( 0 )
+ , x3( 0 )
+ , x4( 0 )
+ {}
+
+ inline uchar head() const { return x1; }
+
+ inline EmbossFifo &operator<<( uchar value )
+ {
+ x1 = x2;
+ x2 = x3;
+ x3 = x4;
+ x4 = value;
+
+ return *this;
+ }
+
+private:
uchar x1;
uchar x2;
uchar x3;
uchar x4;
-} GpUint;
+};
-typedef union
-{
- uint buffer;
- GpUint gpuint;
-} GpFifo;
-
-
TextureColorizer::TextureColorizer( QObject *parent )
: QObject( parent )
, m_veccomposer( this )
@@ -95,8 +109,6 @@
// const uint glaciercolor = qRgb(200,200,200);
int bump = 8;
- GpFifo emboss;
- emboss.buffer = 0;
bool showRelief;
viewParams->mapTheme()->settings()->propertyValue( "relief", showRelief );
@@ -139,7 +151,7 @@
uchar *readDataStart = origimg->scanLine( y );
const uchar *readDataEnd = readDataStart + imgwidth*4;
- emboss.buffer = 0;
+ EmbossFifo emboss;
for ( uchar* readData = readDataStart;
readData < readDataEnd;
@@ -150,9 +162,8 @@
uchar& grey = *readData; // qBlue(*data);
if ( showRelief ) {
- emboss.gpuint.x4 = grey;
- emboss.buffer = emboss.buffer >> 8;
- bump = ( emboss.gpuint.x1 + 8 - grey );
+ emboss << grey;
+ bump = ( emboss.head() + 8 - grey );
if ( bump < 0 ) bump = 0;
if ( bump > 15 ) bump = 15;
}
@@ -211,6 +222,8 @@
int yTop = ( imgry-radius < 0 ) ? 0 : imgry-radius;
const int yBottom = ( yTop == 0 ) ? imgheight : imgry + radius;
+ EmbossFifo emboss;
+
for ( int y = yTop; y < yBottom; ++y ) {
const int dy = imgry - y;
int rx = (int)sqrt( (qreal)( radius * radius - dy * dy ) );
@@ -238,9 +251,8 @@
uchar& grey = *readData; // qBlue(*data);
if ( showRelief ) {
- emboss.buffer = emboss.buffer >> 8;
- emboss.gpuint.x4 = grey;
- bump = ( emboss.gpuint.x1 + 16 - grey ) >> 1;
+ emboss << grey;
+ bump = ( emboss.head() + 16 - grey ) >> 1;
if ( bump > 15 ) bump = 15;
if ( bump < 0 ) bump = 0;
}
More information about the Marble-commits
mailing list