BaseSoftRenderSurface.h

Go to the documentation of this file.
00001 /*
00002 BaseSoftRenderSurface.h : Abstract BaseSoftRenderSurface header
00003 
00004 Copyright (C) 2003 The Pentagram Team
00005 
00006 This program is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU General Public License
00008 as published by the Free Software Foundation; either version 2
00009 of the License, or (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 */
00020 
00021 #ifndef BASESOFTRENDERSURFACE_H
00022 #define BASESOFTRENDERSURFACE_H
00023 
00024 #include "RenderSurface.h"
00025 #include "Rect.h"
00026 #include <SDL.h>
00027 
00028 //
00029 // Class BaseSoftRenderSurface
00030 //
00031 // Desc: The base abstact class for software rendering in Pentagram
00032 //
00033 class BaseSoftRenderSurface : public RenderSurface
00034 {
00035 protected:
00036         // Frame buffer
00037         uint8                   *pixels;                                // Pointer to logical pixel 0,0
00038         uint8                   *pixels00;                              // Pointer to physical pixel 0,0
00039 
00040         // Depth Buffer
00041         uint16                  *zbuffer;                               // Pointer to logical pixel 0,0
00042         uint8                   *zbuffer00;                             // Pointer to physical pixel 0,0
00043 
00044         // Pixel Format (also see 'Colour shifting values' later)
00045         int                             bytes_per_pixel;                // 2 or 4
00046         int                             bits_per_pixel;                 // 16 or 32
00047         int                             format_type;                    // 16, 555, 565, 32 or 888
00048 
00049         // Dimensions
00050         sint32                  ox, oy;                                 // Physical Pixel for Logical Origin
00051         sint32                  width, height;                  // Width and height
00052         sint32                  pitch;                                  // Frame buffer pitch (bytes) (could be negated)
00053         sint32                  zpitch;                                 // Z Buffer pitch (bytes) (could be negated)
00054         bool                    flipped;
00055 
00056         // Clipping Rectangle
00057         Pentagram::Rect clip_window;
00058 
00059         // Locking count
00060         uint32                  lock_count;                             // Number of locks on surface
00061 
00062         // SDL_Surface
00063         SDL_Surface             *sdl_surf;
00064 
00065         // Renderint to a texture
00066         Texture                 *rtt_tex;
00067 
00068         // Create from a SDL_Surface
00069         BaseSoftRenderSurface(SDL_Surface *);
00070 
00071         // Create with Texture
00072         BaseSoftRenderSurface(int w, int h);
00073 
00074         // Create Generic
00075         BaseSoftRenderSurface(int w, int h, int bpp, int rsft, int gsft, int bsft, int asft);
00076         BaseSoftRenderSurface(int w, int h, uint8 *buf);
00077         virtual ECode GenericLock()  { return P_NO_ERROR; }
00078         virtual ECode GenericUnlock()  { return P_NO_ERROR; }
00079 
00080         // Update the Pixels Pointer
00081         void    SetPixelsPointer()
00082         {
00083                 uint8 *pix00 = pixels00;
00084                 uint8 *zbuf00 = zbuffer00;
00085 
00086                 if (flipped)
00087                 {
00088                         pix00 += -pitch * (height-1);
00089                         zbuf00 += -zpitch * (height-1);
00090                 }
00091 
00092                 pixels = pix00 + ox*bytes_per_pixel + oy*pitch;
00093                 zbuffer = reinterpret_cast<uint16*>(zbuf00 + ox + oy * zpitch);
00094         }
00095 
00096 public:
00097 
00098         // Virtual Destructor
00099         virtual ~BaseSoftRenderSurface();
00100 
00101         //
00102         // Being/End Painting
00103         //
00104 
00105         // Begin painting to the buffer. MUST BE CALLED BEFORE DOING ANYTHING TO THE SURFACE!
00106         // Can be called multiple times
00107         // Returns Error Code on error. Check return code.....
00108         virtual ECode BeginPainting();
00109 
00110         // Finish paining to the buffer. MUST BE CALLED FOR EACH CALL TO BeginPainting()
00111         // Returns Error Code on error. Check return code.....
00112         virtual ECode EndPainting();
00113 
00114         // Get the surface as a Texture. Only valid for SecondaryRenderSurfaces
00115         virtual Texture *GetSurfaceAsTexture();
00116 
00117 
00118         //
00119         // Surface Properties
00120         //
00121 
00122         // Set the Origin of the Surface
00123         virtual void SetOrigin(sint32 x, sint32 y);
00124 
00125         // Set the Origin of the Surface
00126         virtual void GetOrigin(sint32 &x, sint32 &y) const;
00127 
00128         // Get the Surface Dimensions
00129         virtual void GetSurfaceDims(Pentagram::Rect &) const;
00130 
00131         // Get Clipping Rectangle
00132         virtual void GetClippingRect(Pentagram::Rect &) const;
00133 
00134         // Set Clipping Rectangle
00135         virtual void SetClippingRect(const Pentagram::Rect &);
00136 
00137         // Check Clipped. -1 if off screen, 0 if not clipped, 1 if clipped
00138         virtual sint16 CheckClipped(const Pentagram::Rect &) const;
00139 
00140         // Flip the surface
00141         virtual void SetFlipped(bool flipped);
00142 
00143         // Has the render surface been flipped?
00144         virtual bool IsFlipped() const;
00145 
00146         //
00147         // Surface Palettes
00148         //
00149         // TODO: Make a Palette class
00150         // TODO: Handle Ultima8 and Crusader Xforms
00151         //
00152 
00153         // Set The Surface Palette
00154         // virtual void SetPalette(uint8 palette[768]);
00155 
00156         // Set The Surface Palette to be the one used by another surface
00157         // TODO: virtual void SetPalette(RenderSurface &);
00158 
00159         // Get The Surface Palette
00160         // TODO: virtual void GetPalette(uint8 palette[768]);
00161 
00162         virtual void CreateNativePalette(Pentagram::Palette* palette);
00163 
00164 };
00165 
00166 #endif

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