Panda3D
tinySDLGraphicsPipe.cxx
1 // Filename: tinySDLGraphicsPipe.cxx
2 // Created by: drose (24Apr08)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "pandabase.h"
16 
17 #ifdef HAVE_SDL
18 
19 #include "tinySDLGraphicsPipe.h"
20 #include "tinySDLGraphicsWindow.h"
21 #include "tinyGraphicsStateGuardian.h"
22 #include "config_tinydisplay.h"
23 #include "frameBufferProperties.h"
24 
25 TypeHandle TinySDLGraphicsPipe::_type_handle;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: TinySDLGraphicsPipe::Constructor
29 // Access: Public
30 // Description:
31 ////////////////////////////////////////////////////////////////////
32 TinySDLGraphicsPipe::
33 TinySDLGraphicsPipe() {
34  _is_valid = true;
35 
36  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
37  tinydisplay_cat.error()
38  << "Cannot initialize SDL video.\n";
39  _is_valid = false;
40  }
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: TinySDLGraphicsPipe::Destructor
45 // Access: Public, Virtual
46 // Description:
47 ////////////////////////////////////////////////////////////////////
48 TinySDLGraphicsPipe::
49 ~TinySDLGraphicsPipe() {
50  if (SDL_WasInit(SDL_INIT_VIDEO)) {
51  SDL_QuitSubSystem(SDL_INIT_VIDEO);
52  }
53 
54  SDL_Quit();
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: TinySDLGraphicsPipe::get_interface_name
59 // Access: Published, Virtual
60 // Description: Returns the name of the rendering interface
61 // associated with this GraphicsPipe. This is used to
62 // present to the user to allow him/her to choose
63 // between several possible GraphicsPipes available on a
64 // particular platform, so the name should be meaningful
65 // and unique for a given platform.
66 ////////////////////////////////////////////////////////////////////
67 string TinySDLGraphicsPipe::
68 get_interface_name() const {
69  return "TinyPanda";
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: TinySDLGraphicsPipe::pipe_constructor
74 // Access: Public, Static
75 // Description: This function is passed to the GraphicsPipeSelection
76 // object to allow the user to make a default
77 // TinySDLGraphicsPipe.
78 ////////////////////////////////////////////////////////////////////
79 PT(GraphicsPipe) TinySDLGraphicsPipe::
80 pipe_constructor() {
81  return new TinySDLGraphicsPipe;
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: TinySDLGraphicsPipe::make_output
86 // Access: Protected, Virtual
87 // Description: Creates a new window on the pipe, if possible.
88 ////////////////////////////////////////////////////////////////////
89 PT(GraphicsOutput) TinySDLGraphicsPipe::
90 make_output(const string &name,
91  const FrameBufferProperties &fb_prop,
92  const WindowProperties &win_prop,
93  int flags,
94  GraphicsEngine *engine,
96  GraphicsOutput *host,
97  int retry,
98  bool &precertify) {
99  if (!_is_valid) {
100  return NULL;
101  }
102 
103  TinyGraphicsStateGuardian *tinygsg = 0;
104  if (gsg != 0) {
105  DCAST_INTO_R(tinygsg, gsg, NULL);
106  }
107 
108  // First thing to try: a TinySDLGraphicsWindow
109 
110  if (retry == 0) {
111  if (((flags&BF_require_parasite)!=0)||
112  ((flags&BF_refuse_window)!=0)||
113  ((flags&BF_resizeable)!=0)||
114  ((flags&BF_size_track_host)!=0)||
115  ((flags&BF_rtt_cumulative)!=0)||
116  ((flags&BF_can_bind_color)!=0)||
117  ((flags&BF_can_bind_every)!=0)) {
118  return NULL;
119  }
120  return new TinySDLGraphicsWindow(engine, this, name, fb_prop, win_prop,
121  flags, gsg, host);
122  }
123 
124  // Nothing else left to try.
125  return NULL;
126 }
127 
128 #endif // HAVE_SDL
A container for the various kinds of properties we might ask to have on a graphics window before we o...
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
This is a base class for the various different classes that represent the result of a frame of render...
Encapsulates all the communication with a particular instance of a given rendering backend...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
An interface to the TinyPanda software rendering code within this module.