David Rose 17 éve
szülő
commit
0f1aeb640a

+ 55 - 17
panda/src/tinydisplay/tinyGraphicsWindow.cxx

@@ -177,6 +177,14 @@ process_events() {
     case SDL_MOUSEMOTION:
     case SDL_MOUSEMOTION:
       _input_devices[0].set_pointer_in_window(evt.motion.x, evt.motion.y);
       _input_devices[0].set_pointer_in_window(evt.motion.x, evt.motion.y);
       break;
       break;
+     
+    case SDL_VIDEORESIZE:
+      properties.set_size(evt.resize.w, evt.resize.h);
+      system_changed_properties(properties);
+      _screen = SDL_SetVideoMode(_properties.get_x_size(), _properties.get_y_size(), 32, _flags);
+      ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size());
+      _pitch = _screen->pitch * TGL_FEATURE_RENDER_BITS / _screen->format->BitsPerPixel;
+      break;
       
       
     case SDL_QUIT:
     case SDL_QUIT:
       // The window was closed by the user.
       // The window was closed by the user.
@@ -222,6 +230,7 @@ set_properties_now(WindowProperties &properties) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void TinyGraphicsWindow::
 void TinyGraphicsWindow::
 close_window() {
 close_window() {
+  glClose();
   GraphicsWindow::close_window();
   GraphicsWindow::close_window();
 }
 }
 
 
@@ -245,8 +254,18 @@ open_window() {
   } else {
   } else {
     DCAST_INTO_R(tinygsg, _gsg, false);
     DCAST_INTO_R(tinygsg, _gsg, false);
   }
   }
-  
-  _screen = SDL_SetVideoMode(_properties.get_x_size(), _properties.get_y_size(), 32, SDL_SWSURFACE);
+
+  _flags = SDL_SWSURFACE;
+  if (_properties.get_fullscreen()) {
+    _flags |= SDL_FULLSCREEN;
+  }
+  if (!_properties.get_fixed_size()) {
+    _flags |= SDL_RESIZABLE;
+  }
+  if (_properties.get_undecorated()) {
+    _flags |= SDL_NOFRAME;
+  }
+  _screen = SDL_SetVideoMode(_properties.get_x_size(), _properties.get_y_size(), 32, _flags);
 
 
   if (_screen == NULL) {
   if (_screen == NULL) {
     tinydisplay_cat.error()
     tinydisplay_cat.error()
@@ -254,42 +273,61 @@ open_window() {
     return false;
     return false;
   }
   }
 
 
-  // initialize TinyGL:
+  create_frame_buffer();
+  if (_frame_buffer == NULL) {
+    tinydisplay_cat.error()
+      << "Could not create frame buffer.\n";
+    return false;
+  }
+
+  glInit(_frame_buffer);
+
+  // Now that we have made the context current to a window, we can
+  // reset the GSG state if this is the first time it has been used.
+  // (We can't just call reset() when we construct the GSG, because
+  // reset() requires having a current context.)
+  tinygsg->reset_if_new();
+
+  return true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: TinyGraphicsWindow::create_frame_buffer
+//       Access: Private
+//  Description: Creates a suitable frame buffer for the current
+//               window size.
+////////////////////////////////////////////////////////////////////
+void TinyGraphicsWindow::
+create_frame_buffer() {
+  if (_frame_buffer != NULL) {
+    ZB_close(_frame_buffer);
+    _frame_buffer = NULL;
+  }
+
   int mode;
   int mode;
   switch (_screen->format->BitsPerPixel) {
   switch (_screen->format->BitsPerPixel) {
   case  8:
   case  8:
     tinydisplay_cat.error()
     tinydisplay_cat.error()
       << "SDL Palettes are currently not supported.\n";
       << "SDL Palettes are currently not supported.\n";
-    return false;
+    return;
 
 
   case 16:
   case 16:
-    _pitch = _screen->pitch;
     mode = ZB_MODE_5R6G5B;
     mode = ZB_MODE_5R6G5B;
     break;
     break;
   case 24:
   case 24:
-    _pitch = (_screen->pitch * 2) / 3;
     mode = ZB_MODE_RGB24;
     mode = ZB_MODE_RGB24;
     break;
     break;
   case 32:
   case 32:
-    _pitch = _screen->pitch / 2;
     mode = ZB_MODE_RGBA;
     mode = ZB_MODE_RGBA;
     break;
     break;
 
 
   default:
   default:
-    return false;
-    break;
+    return;
   }
   }
 
 
   _frame_buffer = ZB_open(_properties.get_x_size(), _properties.get_y_size(), mode, 0, 0, 0, 0);
   _frame_buffer = ZB_open(_properties.get_x_size(), _properties.get_y_size(), mode, 0, 0, 0, 0);
-  glInit(_frame_buffer);
 
 
-  // Now that we have made the context current to a window, we can
-  // reset the GSG state if this is the first time it has been used.
-  // (We can't just call reset() when we construct the GSG, because
-  // reset() requires having a current context.)
-  tinygsg->reset_if_new();
-
-  return true;
+  _pitch = _screen->pitch * TGL_FEATURE_RENDER_BITS / _screen->format->BitsPerPixel;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 2 - 0
panda/src/tinydisplay/tinyGraphicsWindow.h

@@ -58,12 +58,14 @@ protected:
   virtual bool open_window();
   virtual bool open_window();
 
 
 private:
 private:
+  void create_frame_buffer();
   static ButtonHandle get_keyboard_button(SDLKey sym);
   static ButtonHandle get_keyboard_button(SDLKey sym);
   static ButtonHandle get_mouse_button(Uint8 button);
   static ButtonHandle get_mouse_button(Uint8 button);
 
 
 private:
 private:
   SDL_Surface *_screen;
   SDL_Surface *_screen;
   ZBuffer *_frame_buffer;
   ZBuffer *_frame_buffer;
+  unsigned int _flags;
   unsigned int _pitch;
   unsigned int _pitch;
 
 
 public:
 public: