Panda3D

tinySDLGraphicsPipe.cxx

00001 // Filename: tinySDLGraphicsPipe.cxx
00002 // Created by:  drose (24Apr08)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "pandabase.h"
00016 
00017 #ifdef HAVE_SDL
00018 
00019 #include "tinySDLGraphicsPipe.h"
00020 #include "tinySDLGraphicsWindow.h"
00021 #include "tinyGraphicsStateGuardian.h"
00022 #include "config_tinydisplay.h"
00023 #include "frameBufferProperties.h"
00024 
00025 TypeHandle TinySDLGraphicsPipe::_type_handle;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: TinySDLGraphicsPipe::Constructor
00029 //       Access: Public
00030 //  Description: 
00031 ////////////////////////////////////////////////////////////////////
00032 TinySDLGraphicsPipe::
00033 TinySDLGraphicsPipe() {
00034   _is_valid = true;
00035 
00036   if (SDL_Init(SDL_INIT_VIDEO) < 0) {
00037     tinydisplay_cat.error()
00038       << "Cannot initialize SDL video.\n";
00039     _is_valid = false;
00040   }
00041 }
00042 
00043 ////////////////////////////////////////////////////////////////////
00044 //     Function: TinySDLGraphicsPipe::Destructor
00045 //       Access: Public, Virtual
00046 //  Description: 
00047 ////////////////////////////////////////////////////////////////////
00048 TinySDLGraphicsPipe::
00049 ~TinySDLGraphicsPipe() {
00050   if (SDL_WasInit(SDL_INIT_VIDEO)) {
00051     SDL_QuitSubSystem(SDL_INIT_VIDEO);
00052   }
00053 
00054   SDL_Quit();
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: TinySDLGraphicsPipe::get_interface_name
00059 //       Access: Published, Virtual
00060 //  Description: Returns the name of the rendering interface
00061 //               associated with this GraphicsPipe.  This is used to
00062 //               present to the user to allow him/her to choose
00063 //               between several possible GraphicsPipes available on a
00064 //               particular platform, so the name should be meaningful
00065 //               and unique for a given platform.
00066 ////////////////////////////////////////////////////////////////////
00067 string TinySDLGraphicsPipe::
00068 get_interface_name() const {
00069   return "TinyPanda";
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: TinySDLGraphicsPipe::pipe_constructor
00074 //       Access: Public, Static
00075 //  Description: This function is passed to the GraphicsPipeSelection
00076 //               object to allow the user to make a default
00077 //               TinySDLGraphicsPipe.
00078 ////////////////////////////////////////////////////////////////////
00079 PT(GraphicsPipe) TinySDLGraphicsPipe::
00080 pipe_constructor() {
00081   return new TinySDLGraphicsPipe;
00082 }
00083 
00084 ////////////////////////////////////////////////////////////////////
00085 //     Function: TinySDLGraphicsPipe::make_output
00086 //       Access: Protected, Virtual
00087 //  Description: Creates a new window on the pipe, if possible.
00088 ////////////////////////////////////////////////////////////////////
00089 PT(GraphicsOutput) TinySDLGraphicsPipe::
00090 make_output(const string &name,
00091             const FrameBufferProperties &fb_prop,
00092             const WindowProperties &win_prop,
00093             int flags,
00094             GraphicsEngine *engine,
00095             GraphicsStateGuardian *gsg,
00096             GraphicsOutput *host,
00097             int retry,
00098             bool &precertify) {
00099   if (!_is_valid) {
00100     return NULL;
00101   }
00102 
00103   TinyGraphicsStateGuardian *tinygsg = 0;
00104   if (gsg != 0) {
00105     DCAST_INTO_R(tinygsg, gsg, NULL);
00106   }
00107 
00108   // First thing to try: a TinySDLGraphicsWindow
00109 
00110   if (retry == 0) {
00111     if (((flags&BF_require_parasite)!=0)||
00112         ((flags&BF_refuse_window)!=0)||
00113         ((flags&BF_resizeable)!=0)||
00114         ((flags&BF_size_track_host)!=0)||
00115         ((flags&BF_rtt_cumulative)!=0)||
00116         ((flags&BF_can_bind_color)!=0)||
00117         ((flags&BF_can_bind_every)!=0)) {
00118       return NULL;
00119     }
00120     return new TinySDLGraphicsWindow(engine, this, name, fb_prop, win_prop,
00121                                      flags, gsg, host);
00122   }
00123   
00124   // Nothing else left to try.
00125   return NULL;
00126 }
00127 
00128 #endif  // HAVE_SDL
 All Classes Functions Variables Enumerations