Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

displaycard_svgalib.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: displaycard_svgalib.cpp,v 1.1 2001/03/06 15:09:17 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00015 #include "Core/precomp.h"
00016 
00017 #ifdef USE_SVGALIB
00018 
00019 #include <vga.h>
00020 #include <Display/Display/Generic/displaycard_generic.h>
00021 #include <Display/Display/Svgalib/displaycard_svgalib.h>
00022 #include <API/Core/System/error.h>
00023 #include <API/Display/Display/palette.h>
00024 #include <Display/Display/Generic/target_system.h>
00025 #include <API/Display/Display/vidmode.h>
00026 #include "API/Core/System/cl_assert.h"
00027 
00028 CL_DisplayCard_Svgalib::CL_DisplayCard_Svgalib(int _card_no) :
00029         CL_DisplayCard_Generic(_card_no)
00030 {
00031         m_initialized = true;
00032         m_target = NULL;
00033 }
00034 
00035 CL_DisplayCard_Svgalib::~CL_DisplayCard_Svgalib()
00036 {
00037         if (m_initialized) vga_setmode(TEXT);
00038         delete m_target;
00039 }
00040 
00041 void CL_DisplayCard_Svgalib::put_display(const class CL_Rect &rect)
00042 {
00043         cl_assert(false); // not implemented.
00044 }
00045 
00046 void CL_DisplayCard_Svgalib::flip_display(bool)
00047 {
00048         m_target->lock();
00049 
00050         unsigned char *backbuffer = (unsigned char *) m_target->get_data();
00051         unsigned int pitch = m_target->get_pitch();
00052         int height = m_target->get_height();
00053 
00054         for (int line=0; line<height; line++)
00055                 vga_drawscanline(
00056                         line,
00057                         backbuffer+line*pitch);
00058 
00059         m_target->unlock();
00060 }
00061 
00062 void CL_DisplayCard_Svgalib::set_palette(CL_Palette *palette)
00063 {
00064         m_palette = new CL_Palette(palette->palette, palette->num_colors);
00065 
00066         for (int i=0; i<256; i++)
00067         {
00068                 vga_setpalette(
00069                         i,
00070                         palette->palette[i*3+0]/4,
00071                         palette->palette[i*3+1]/4,
00072                         palette->palette[i*3+2]/4);
00073         }
00074 }
00075 
00076 CL_Palette *CL_DisplayCard_Svgalib::get_palette()
00077 {
00078 /*      for (int i=0; i<256; i++)
00079         {
00080                 int r,g,b;
00081                 vga_getpalette(i, &r, &g, &b);
00082 
00083                 system_palette.palette[i*3+0] = r;
00084                 system_palette.palette[i*3+1] = g;
00085                 system_palette.palette[i*3+2] = b;
00086         }
00087 */
00088         return m_palette;
00089 }
00090 
00091 void CL_DisplayCard_Svgalib::set_videomode(int width, int height, int bpp, bool fullscreen, bool allow_resize, bool video_memory)
00092 {
00093         int num_modes = vga_lastmodenumber();
00094 
00095         for (int i=0; i<num_modes; i++)
00096         {
00097                 vga_modeinfo *cur_mode = vga_getmodeinfo(i);
00098 
00099                 if (cur_mode->width == width &&
00100                         cur_mode->height == height &&
00101                         cur_mode->bytesperpixel == (bpp+7)/8)
00102                 {
00103                         delete m_target;
00104                         m_target = NULL;
00105 
00106                         set_gfxmode(width, height, bpp, fullscreen, allow_resize);
00107 
00108                         vga_setmode(i);
00109                         m_initialized = true;
00110                         
00111                         // this may look like the strangest way to find the correct masks,
00112                         // but this is how the vgatest application does!
00113                         int red_mask=0, green_mask=0, blue_mask=0;
00114                         switch (cur_mode->colors)
00115                         {
00116                         case 256:
00117                                 // 8 bpp not supported in this version of ClanLib.
00118                                 cl_assert(false);
00119                                 break;
00120                         
00121                         case 1 << 15: // 555 RGB, blue at LSB
00122                                 red_mask = 31 << (5+5);
00123                                 green_mask = 31 << 5;
00124                                 blue_mask = 31;
00125                                 break;
00126                         
00127                         case 1 << 16: // 565 RGB, blue at LSB
00128                                 red_mask =  31 << (6+5);
00129                                 green_mask = 63 << 5;
00130                                 blue_mask = 31;
00131                                 break;
00132                         
00133                         case 1 << 24: // 888 RGB or BGR
00134                                 if (cur_mode->bytesperpixel == 3)
00135                                 {
00136                                         if (cur_mode->flags & RGB_MISORDERED) // BGR
00137                                         {
00138                                                 blue_mask = 255 << (8+8);
00139                                                 green_mask = 255 << 8;
00140                                                 red_mask = 255;
00141                                         }
00142                                         else
00143                                         {
00144                                                 red_mask = 255 << (8+8);
00145                                                 green_mask = 255 << 8;
00146                                                 blue_mask = 255;
00147                                         }
00148                                 }
00149                                 else
00150                                 {
00151                                         if (cur_mode->flags & RGB_MISORDERED) // RGBX
00152                                         {
00153                                                 red_mask = 255 << (8+8+8);
00154                                                 green_mask = 255 << (8+8);
00155                                                 blue_mask = 255 << 8;
00156                                         }
00157                                         else // XRGB
00158                                         {
00159                                                 red_mask = 255 << (8+8);
00160                                                 green_mask = 255 << 8;
00161                                                 blue_mask = 255;
00162                                         }
00163                                 }
00164                                 break;
00165                         
00166                         default:
00167                                 // unknown bit depth!
00168                                 cl_assert(false);
00169                         }
00170 
00171                         m_target = new CL_Target_System(
00172                                 width,
00173                                 height,
00174                                 (bpp+7)/8,
00175                                 red_mask,
00176                                 green_mask,
00177                                 blue_mask,
00178                                 0); // alpha mask
00179 
00180                         return;
00181                 }
00182         }
00183 
00184         throw CL_Error("Video mode not available");
00185 }
00186 
00187 bool CL_DisplayCard_Svgalib::is_initialized()
00188 {
00189         return m_initialized;
00190 }
00191 
00192 const std::list<CL_VidMode*> &CL_DisplayCard_Svgalib::get_videomodes()
00193 {
00194 //      std::cout << "TODO: Make CL_DisplayCard_Svgalib::get_videmodes()" << std::endl;
00195         static std::list<CL_VidMode*> dummy;
00196         return dummy;
00197 }
00198 
00199 #endif

Generated at Wed Apr 4 19:54:00 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001