SoftRenderSurface.inl

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2004  The Pentagram Team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 //
00020 // Render Surface Shape Display include file
00021 //
00022 
00023 //
00024 // Macros to define before including this:
00025 //
00026 // #define NO_CLIPPING to disable shape clipping
00027 //
00028 // #define FLIP_SHAPES to flip rendering
00029 //
00030 // #define FLIP_CONDITIONAL to an argument of the function so FLIPPING can be 
00031 // enabled/disabled with a bool
00032 //
00033 // #define XFORM_SHAPES to enable XFORMing
00034 //
00035 // #define XFORM_CONDITIONAL to an argument of the function so XFORM can be 
00036 // enabled/disabled with a bool
00037 //
00038 // #define BLEND_SHAPES(src,dst) to an a specified blend function.
00039 //
00040 // #define BLEND_CONDITIONAL to an argument of the function so BLEND
00041 // painting can be enabled/disabled with a bool
00042 //
00043 
00044 //
00045 // Macros defined by this file:
00046 //
00047 // NOT_CLIPPED_Y - Does Y Clipping check per line
00048 // 
00049 // NOT_CLIPPED_X - Does X Clipping check per Pixel
00050 // 
00051 // LINE_END_ASSIGN - Calcuates the line_end pointer required for X clipping
00052 //
00053 // XNEG - Negates X values if doing shape flipping
00054 // 
00055 // USE_XFORM_FUNC - Checks to see if we want to use XForm Blending for this pixel
00056 // 
00057 // CUSTOM_BLEND - Final Blend for invisiblity
00058 //
00059 
00060 //
00061 // XForm = TRUE
00062 //
00063 #ifdef XFORM_SHAPES
00064 
00065 #ifdef XFORM_CONDITIONAL
00066 #define USE_XFORM_FUNC ((XFORM_CONDITIONAL) && xform_pal[*linedata])
00067 #else
00068 #define USE_XFORM_FUNC (xform_pal[*linedata])
00069 #endif
00070 
00071 //
00072 // XForm = FALSE
00073 //
00074 #else
00075 #define USE_XFORM_FUNC 0
00076 #endif
00077 
00078 
00079 //
00080 // Flipping = TRUE
00081 //
00082 #ifdef FLIP_SHAPES
00083 
00084 #ifdef FLIP_CONDITIONAL
00085 const sint32 neg = (FLIP_CONDITIONAL)?-1:0;
00086 #define XNEG(x) (((x)+neg)^neg)
00087 #else
00088 #define XNEG(x) (-(x))
00089 #endif
00090 
00091 // Flipping = FALSE
00092 #else
00093 #define XNEG(x)(+(x))
00094 #endif
00095 
00096 
00097 //
00098 // No Clipping = TRUE
00099 //      
00100 #ifdef NO_CLIPPING
00101 
00102 #define LINE_END_ASSIGN()
00103 #define NOT_CLIPPED_X (1)
00104 #define NOT_CLIPPED_Y (1)
00105 #define OFFSET_PIXELS (pixels)
00106 
00107 //
00108 // No Clipping = FALSE
00109 //      
00110 #else
00111 
00112 #define LINE_END_ASSIGN() do { line_end = line_start+scrn_width; } while (0)
00113 #define NOT_CLIPPED_Y (line >= 0 && line < scrn_height)
00114 #define NOT_CLIPPED_X (pixptr >= line_start && pixptr < line_end)
00115 
00116         int                                     scrn_width = clip_window.w;
00117         int                                     scrn_height = clip_window.h;
00118         uintX                           *line_end;
00119 
00120 #define OFFSET_PIXELS (off_pixels)
00121 
00122         uint8                           *off_pixels  = static_cast<uint8*>(pixels) + static_cast<sintptr>(clip_window.x)*sizeof(uintX) + static_cast<sintptr>(clip_window.y)*pitch;
00123         x -= clip_window.x;
00124         y -= clip_window.y;
00125 
00126 #endif
00127 
00128 
00129 //
00130 // Invisilibity = TRUE
00131 //
00132 #ifdef BLEND_SHAPES
00133 
00134 #ifdef BLEND_CONDITIONAL
00135 #define CUSTOM_BLEND(src) static_cast<uintX>((BLEND_CONDITIONAL)?BLEND_SHAPES(src,*pixptr):src)
00136 #else
00137 #define CUSTOM_BLEND(src) static_cast<uintX>(BLEND_SHAPES(src,*pixptr))
00138 #endif
00139 
00140 //
00141 // Invisilibity = FALSE
00142 //
00143 #else
00144 
00145 #define CUSTOM_BLEND(src) static_cast<uintX>(src)
00146 
00147 #endif
00148 
00149 //
00150 // Destination Alpha Masking
00151 //
00152 #ifdef DESTALPHA_MASK
00153 
00154 #define NOT_DESTINATION_MASKED  (*pixptr & RenderSurface::format.a_mask)
00155 
00156 #else
00157 
00158 #define NOT_DESTINATION_MASKED  (1)
00159 
00160 #endif
00161 
00162 //
00163 // The Function
00164 //
00165 
00166 // All the variables we want
00167 
00168         const uint8                     *linedata;
00169         sint32                          xpos;
00170         sintptr                         line; // sintptr for pointer arithmetic
00171         sint32                          dlen;
00172 
00173         uintX                           *pixptr;
00174         uintX                           *endrun;
00175         uintX                           *line_start;
00176         uint32                          pix;
00177 
00178         // Sanity check
00179         if (framenum >= s->frameCount()) return;
00180         if (s->getPalette() == 0) return;
00181 
00182         ShapeFrame              *frame                  = s->getFrame(framenum);
00183         const uint8             *rle_data               = frame->rle_data;
00184         const uint32    *line_offsets   = frame->line_offsets;
00185         const uint32    *pal                    = untformed_pal?
00186                                                                                 &(s->getPalette()->native_untransformed[0]):
00187                                                                                 &(s->getPalette()->native[0]);
00188 
00189         
00190 #ifdef XFORM_SHAPES
00191         const uint32    *xform_pal              = untformed_pal?
00192                                                                                 &(s->getPalette()->xform_untransformed[0]):
00193                                                                                 &(s->getPalette()->xform[0]);
00194 #endif
00195 
00196         sint32 width = frame->width;
00197         sint32 height = frame->height;
00198         x -= XNEG(frame->xoff);
00199         y -= frame->yoff;
00200 
00201         // Do it this way if compressed
00202         if (frame->compressed) for (int i=0; i<height; i++) 
00203         {
00204                 xpos = 0;
00205                 line = y+i;
00206 
00207                 if (NOT_CLIPPED_Y)
00208                 {
00209 
00210                         linedata = rle_data + line_offsets[i];
00211                         line_start = reinterpret_cast<uintX *>(static_cast<uint8*>(OFFSET_PIXELS) + pitch*line);
00212 
00213                         LINE_END_ASSIGN();
00214 
00215                         do 
00216                         {
00217                                 xpos += *linedata++;
00218                           
00219                                 if (xpos == width) break;
00220 
00221                                 dlen = *linedata++;
00222                                 int type = dlen & 1;
00223                                 dlen >>= 1;
00224 
00225                                 pixptr= line_start+x+XNEG(xpos);
00226                                 endrun = pixptr + XNEG(dlen);
00227                                 
00228                                 if (!type) 
00229                                 {
00230                                         while (pixptr != endrun) 
00231                                         {
00232                                                 if (NOT_CLIPPED_X && NOT_DESTINATION_MASKED) 
00233                                                 {
00234                                                         #ifdef XFORM_SHAPES
00235                                                         if (USE_XFORM_FUNC) 
00236                                                         {
00237                                                                 *pixptr = CUSTOM_BLEND(BlendPreModulated(xform_pal[*linedata],*pixptr));
00238                                                         }
00239                                                         else 
00240                                                         #endif
00241                                                         {
00242                                                                 *pixptr = CUSTOM_BLEND(pal[*linedata]);
00243                                                         }
00244                                                 }
00245                                                 pixptr += XNEG(1);
00246                                                 linedata++;
00247                                         }
00248                                 } 
00249                                 else 
00250                                 {
00251                                         #ifdef XFORM_SHAPES
00252                                         pix = xform_pal[*linedata];
00253                                         if (USE_XFORM_FUNC) 
00254                                         {
00255                                                 while (pixptr != endrun) 
00256                                                 {
00257                                                         if (NOT_CLIPPED_X && NOT_DESTINATION_MASKED) *pixptr = CUSTOM_BLEND(BlendPreModulated(xform_pal[*linedata],*pixptr));
00258                                                         pixptr += XNEG(1);
00259                                                 }
00260                                         } 
00261                                         else 
00262                                         #endif
00263                                         {
00264                                                 pix = pal[*linedata];
00265                                                 while (pixptr != endrun) 
00266                                                 {
00267                                                         if (NOT_CLIPPED_X && NOT_DESTINATION_MASKED) 
00268                                                         {
00269                                                                 *pixptr = CUSTOM_BLEND(pix);
00270                                                         }
00271                                                         pixptr += XNEG(1);
00272                                                 }
00273                                         }       
00274                                         linedata++;
00275                                 }
00276 
00277                                 xpos += dlen;
00278 
00279                         } while (xpos < width);
00280                 }
00281         }
00282         // Uncompressed
00283         else for (int i=0; i<height; i++) 
00284         {
00285                 linedata = rle_data + line_offsets[i];
00286                 xpos = 0;
00287                 line = y+i;
00288 
00289                 if (NOT_CLIPPED_Y)
00290                 {
00291                         line_start = reinterpret_cast<uintX *>(static_cast<uint8*>(OFFSET_PIXELS) + pitch*line);
00292                         LINE_END_ASSIGN();
00293 
00294                         do 
00295                         {
00296                                 xpos += *linedata++;
00297                           
00298                                 if (xpos == width) break;
00299 
00300                                 dlen = *linedata++;
00301 
00302                                 pixptr= line_start+x+XNEG(xpos);
00303                                 endrun = pixptr + XNEG(dlen);
00304 
00305                                 while (pixptr != endrun) 
00306                                 {
00307                                         if (NOT_CLIPPED_X && NOT_DESTINATION_MASKED) 
00308                                         {
00309                                                 #ifdef XFORM_SHAPES
00310                                                 if (USE_XFORM_FUNC) 
00311                                                 {
00312                                                         *pixptr = CUSTOM_BLEND(BlendPreModulated(xform_pal[*linedata],*pixptr));
00313                                                 }
00314                                                 else 
00315                                                 #endif
00316                                                 {
00317                                                         *pixptr = CUSTOM_BLEND(pal[*linedata]);
00318                                                 }
00319                                         }
00320                                         pixptr += XNEG(1);
00321                                         linedata++;
00322                                 }
00323 
00324                                 xpos += dlen;
00325 
00326                         } while (xpos < width);
00327                 }
00328         }
00329 
00330 #undef NOT_DESTINATION_MASKED
00331 #undef OFFSET_PIXELS
00332 #undef CUSTOM_BLEND
00333 #undef LINE_END_ASSIGN
00334 #undef NOT_CLIPPED_X
00335 #undef NOT_CLIPPED_Y
00336 #undef XNEG
00337 #undef USE_XFORM_FUNC

Generated on Fri Jul 27 22:27:39 2007 for pentagram by  doxygen 1.4.7