[AD] Runtime Gfx Mode Info - Submission for A4.3.11+

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I've written some functions for Allegro that can be used to determine the graphics mode type of arbitrary graphics drivers at runtime. These could help a programmer determine which of a set of drivers that they would like to allow their users to pick from for choosing a graphics mode to run the program in.

I posted a thread giving more details about it on allegro.cc, along with a static Windows program demonstrating their usefulness :
http://www.allegro.cc/forums/thread/599169

The functions are useful when used in conjunction with the gfx_mode_select_filter function, and could be helpful for limiting config settings if so desired.

I made a patch against the latest SVN version of Allegro 4.3.11+ and attached it to this message.

Let me know if this is acceptable, if there are any things you would like to see changed, etc... Are the naming conventions acceptable? I think they might be better named as "is_*_mode" functions instead of "is_a_*_mode" functions, but that would require renaming the current "is_windowed_mode" function to "in_windowed_mode" instead, which makes more sense to me since it refers to the currently set mode instead of an arbitrary one. I will update the patch to include the changes if that is more favorable.

Let me know what you think.

Thanks,
Edgar


Index: docs/src/allegro._tx
===================================================================
--- docs/src/allegro._tx	(revision 11605)
+++ docs/src/allegro._tx	(working copy)
@@ -4389,6 +4389,69 @@
    it is a fullscreen mode. You should not call this function if you are not
    in graphics mode.
 
+@@int @is_a_windowed_mode(const int graphics_card);
+@xref is_a_fullscreen_mode, is_a_definite_mode, is_a_magic_mode
+@shortdesc Determines whether graphics_card is windowed or unknown.
+   Allows run time determination of whether the specified graphics driver
+   operates in windowed mode. If the function returns zero, that does not
+   mean that it is a fullscreen driver however, just that it is unknown
+   whether it is a windowed mode. For example, passing GFX_AUTODETECT
+   to the function would return 0 (false), but that doesn't mean that
+   GFX_AUTODETECT can't set a windowed mode.
+   
+   Allegro needs to be initialized before this function is called.
+   
+@retval
+   Returns non-zero if graphics_card is windowed, or zero if unknown.
+
+@@int @is_a_fullscreen_mode(const int graphics_card);
+@xref is_a_windowed_mode, is_a_definite_mode, is_a_magic_mode
+@shortdesc Determines whether graphics_card is fullscreen or unknown.
+   Allows run time determination of whether the specified graphics driver
+   operates in fullscreen mode. If the function returns zero, that does not
+   mean that it is a windowed driver however, just that it is unknown
+   whether it is a fullscreen mode. For example, passing GFX_AUTODETECT
+   to the function would return 0 (false), but that doesn't mean that
+   GFX_AUTODETECT can't set a fullscreen mode.
+   
+   Allegro needs to be initialized before this function is called.
+   
+@retval
+   Returns non-zero if graphics_card is fullscreen, or zero if unknown.
+
+@@int @is_a_definite_mode(const int graphics_card);
+@xref is_a_windowed_mode, is_a_fullscreen_mode, is_a_magic_mode
+@shortdesc Determines whether graphics_card is a definite mode or unknown.
+   Allows run time determination of whether the specified graphics driver
+   operates definitively in a fullscreen or windowed mode. If the function
+   returns zero, this is unknown, but most likely means it is one of the
+   indefinite mode drivers like GFX_AUTODETECT or GFX_SAFE.
+   
+   Allegro needs to be initialized before this function is called.
+   
+@retval
+   Returns non-zero if graphics_card is definitely windowed or fullscreen,
+   or zero if unknown.
+
+@@int @is_a_magic_mode(const int graphics_card);
+@xref is_a_windowed_mode, is_a_fullscreen_mode, is_a_magic_mode
+@shortdesc Determines whether graphics_card is a magic mode or not.
+   A simple helper function to check if a given mode is one of the magic
+   drivers.
+   
+@retval
+   Non-zero if true, and zero if false.
+
+@@int @current_gfx_mode();
+@xref set_gfx_mode
+@shortdesc Returns the id of the current graphics driver.
+   This function will let you determine which graphics driver is currently
+   set by allegro. If no graphics driver is set, it will return GFX_NONE.
+   
+@retval
+   The id of the current graphics driver if there is one, or
+   GFX_NONE if none is set.
+
 @@extern int @gfx_capabilities;
 @xref screen, create_video_bitmap, scroll_screen, request_scroll, show_mouse
 @xref enable_triple_buffer
@@ -11969,7 +12032,7 @@
       0, 0, 0,  /* Viewer position, in this case, 0/0/0. */
       0, 0, -1, /* Viewer direction, in this case along negative z. */
       0, 1, 0,  /* Up vector, in this case positive y. */
-      32,       /* The FOV, here 45°. */
+      32,       /* The FOV, here 45°. */
       (float)SCREEN_W / (float)SCREEN_H)); /* Aspect ratio. */
   
    /* Applying the matrix transforms the point 100/200/-300
@@ -12156,7 +12219,7 @@
    The fov parameter specifies the field of view (ie. width of the camera
    focus) in binary, 256 degrees to the circle format. For typical
    projections, a field of view in the region 32-48 will work well. 64
-   (90°) applies no extra scaling - so something which is one unit away
+   (90°) applies no extra scaling - so something which is one unit away
    from the viewer will be directly scaled to the viewport. A bigger FOV
    moves you closer to the viewing plane, so more objects will appear. A
    smaller FOV moves you away from the viewing plane, which means you see a
Index: include/allegro/gfx.h
===================================================================
--- include/allegro/gfx.h	(revision 11605)
+++ include/allegro/gfx.h	(working copy)
@@ -427,6 +427,11 @@
 AL_FUNC(void, clear_bitmap, (BITMAP *bitmap));
 AL_FUNC(void, vsync, (void));
 
+AL_FUNC(int , is_a_windowed_mode   , (const int graphics_card));
+AL_FUNC(int , is_a_fullscreen_mode , (const int graphics_card));
+AL_FUNC(int , is_a_definite_mode   , (const int graphics_card));
+AL_FUNC(int , is_a_magic_mode      , (const int graphics_card));
+AL_FUNC(int , current_gfx_mode     , ());
 
 
 #define SWITCH_NONE           0
Index: src/graphics.c
===================================================================
--- src/graphics.c	(revision 11605)
+++ src/graphics.c	(working copy)
@@ -1750,3 +1750,123 @@
 }
 
 
+
+/* is_a_windowed_mode :
+ * Determines if graphics_card is a windowed driver.
+ * A return value of 0 does NOT indicate that it is
+ * a fullscreen driver, just that it is unknown whether
+ * it is a windowed driver. GFX_SAFE is not definitively
+ * a windowed mode, as with system drivers that don't
+ * provide a recommended safe mode, GFX_AUTODETECT is
+ * used, and that can set windowed or fullscreen modes.
+ */
+int is_a_windowed_mode(const int graphics_card) {
+   
+   _DRIVER_INFO* gfx_driver_info  = NULL;
+   GFX_DRIVER*   gfx_driver_entry = NULL;
+   
+   ASSERT(system_driver);
+   
+   if (graphics_card == GFX_AUTODETECT_WINDOWED) {return 1;}
+   
+   /* ask the system driver for a list of graphics hardware drivers */
+   if (system_driver->gfx_drivers) {
+      gfx_driver_info = system_driver->gfx_drivers();
+   } else {
+      gfx_driver_info = _gfx_driver_list;
+   }
+   
+   ASSERT(gfx_driver_info);
+   
+   while(gfx_driver_info->driver) {
+      if (gfx_driver_info->id == graphics_card) {
+         gfx_driver_entry = (GFX_DRIVER*)gfx_driver_info->driver;
+         return gfx_driver_entry->windowed;
+      }
+      ++gfx_driver_info;
+   }
+   return 0;// windowed status is unknown for graphics_card value
+}
+
+
+
+/* is_a_fullscreen_mode :
+ * Determines if graphics_card is a fullscreen driver.
+ * A return value of 0 does NOT indicate that it is
+ * a windowed driver, just that it is unknown whether
+ * it is a fullscreen driver. GFX_AUTODETECT_FULLSCREEN
+ * will return non-zero, but GFX_AUTODETECT will not, as
+ * it can set either windowed or fullscreen modes.
+ */
+int is_a_fullscreen_mode(const int graphics_card) {
+   
+   _DRIVER_INFO* gfx_driver_info  = NULL;
+   GFX_DRIVER*   gfx_driver_entry = NULL;
+   
+   ASSERT(system_driver);
+   
+   if (graphics_card == GFX_AUTODETECT_FULLSCREEN) {return 1;}
+   
+   /* ask the system driver for a list of graphics hardware drivers */
+   if (system_driver->gfx_drivers) {
+      gfx_driver_info = system_driver->gfx_drivers();
+   } else {
+      gfx_driver_info = _gfx_driver_list;
+   }
+   
+   ASSERT(gfx_driver_info);
+   while(gfx_driver_info->driver) {
+      if (gfx_driver_info->id == graphics_card) {
+         gfx_driver_entry = (GFX_DRIVER*)gfx_driver_info->driver;
+         return !gfx_driver_entry->windowed;
+      }
+      ++gfx_driver_info;
+   }
+   return 0;// fullscreen status is unknown for graphics_card value
+}
+
+
+
+/* is_a_definite_mode :
+ * Determines if graphics_card is definitively
+ * a windowed or fullscreen driver. This means
+ * GFX_AUTODETECT and GFX_TEXT return false.
+ * See is_a_windowed_mode for details about GFX_SAFE.
+ */
+int is_a_definite_mode(const int graphics_card) {
+   if (is_a_windowed_mode(graphics_card)) {return 1;}
+   if (is_a_fullscreen_mode(graphics_card)) {return 1;}
+   return 0;// graphics_card is not a definitive mode
+}
+
+
+
+/* is_a_magic_mode :
+ * Determines whether graphics_card is one
+ * of the magic drivers, or is unknown.
+ */
+int is_a_magic_mode(const int graphics_card) {
+   switch (graphics_card) {
+      case GFX_AUTODETECT            : return 1;
+      case GFX_AUTODETECT_FULLSCREEN : return 1;
+      case GFX_AUTODETECT_WINDOWED   : return 1;
+      case GFX_SAFE                  : return 1;
+      case GFX_TEXT                  : return 1;
+   }
+   return 0;
+}
+
+
+
+/* current_gfx_mode :
+ * Tells you which graphics mode is currently
+ * set. Useful for determining which driver that
+ * GFX_AUTODETECT* or GFX_SAFE set successfully.
+ */
+int current_gfx_mode() {
+   if (!gfx_driver) {return GFX_NONE;}
+   return gfx_driver->id;
+}
+
+
+


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/