瀏覽代碼

Made glfwGetVideoMode consistent with getters.

Camilla Berglund 12 年之前
父節點
當前提交
ce1e84def6
共有 7 個文件被更改,包括 18 次插入19 次删除
  1. 2 3
      include/GL/glfw3.h
  2. 1 0
      src/internal.h
  3. 4 5
      src/monitor.c
  4. 2 2
      tests/events.c
  5. 3 3
      tests/gamma.c
  6. 3 3
      tests/iconify.c
  7. 3 3
      tests/modes.c

+ 2 - 3
include/GL/glfw3.h

@@ -1060,14 +1060,13 @@ GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count);
  *  on whether it is focused.
  *  on whether it is focused.
  *
  *
  *  @param[in] monitor The monitor to query.
  *  @param[in] monitor The monitor to query.
- *  @return The current mode of the monitor, or a struct cleared to all zeroes
- *  if an error occurred.
+ *  @return The current mode of the monitor, or `NULL` if an error occurred.
  *
  *
  *  @sa glfwGetVideoModes
  *  @sa glfwGetVideoModes
  *
  *
  *  @ingroup monitor
  *  @ingroup monitor
  */
  */
-GLFWAPI GLFWvidmode glfwGetVideoMode(GLFWmonitor* monitor);
+GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor);
 
 
 /*! @brief Generates a gamma ramp and sets it for the specified monitor.
 /*! @brief Generates a gamma ramp and sets it for the specified monitor.
  *
  *

+ 1 - 0
src/internal.h

@@ -248,6 +248,7 @@ struct _GLFWmonitor
 
 
     GLFWvidmode*    modes;
     GLFWvidmode*    modes;
     int             modeCount;
     int             modeCount;
+    GLFWvidmode     currentMode;
 
 
     GLFWgammaramp   originalRamp;
     GLFWgammaramp   originalRamp;
     GLFWgammaramp   currentRamp;
     GLFWgammaramp   currentRamp;

+ 4 - 5
src/monitor.c

@@ -322,14 +322,13 @@ GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count)
     return monitor->modes;
     return monitor->modes;
 }
 }
 
 
-GLFWAPI GLFWvidmode glfwGetVideoMode(GLFWmonitor* handle)
+GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* handle)
 {
 {
     _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
     _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
-    GLFWvidmode mode = { 0, 0, 0, 0, 0 };
 
 
-    _GLFW_REQUIRE_INIT_OR_RETURN(mode);
+    _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
 
 
-    _glfwPlatformGetVideoMode(monitor, &mode);
-    return mode;
+    _glfwPlatformGetVideoMode(monitor, &monitor->currentMode);
+    return &monitor->currentMode;
 }
 }
 
 

+ 2 - 2
tests/events.c

@@ -371,7 +371,7 @@ void monitor_callback(GLFWmonitor* monitor, int event)
     if (event == GLFW_CONNECTED)
     if (event == GLFW_CONNECTED)
     {
     {
         int x, y, widthMM, heightMM;
         int x, y, widthMM, heightMM;
-        GLFWvidmode mode = glfwGetVideoMode(monitor);
+        const GLFWvidmode* mode = glfwGetVideoMode(monitor);
 
 
         glfwGetMonitorPos(monitor, &x, &y);
         glfwGetMonitorPos(monitor, &x, &y);
         glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM);
         glfwGetMonitorPhysicalSize(monitor, &widthMM, &heightMM);
@@ -380,7 +380,7 @@ void monitor_callback(GLFWmonitor* monitor, int event)
                counter++,
                counter++,
                glfwGetTime(),
                glfwGetTime(),
                glfwGetMonitorName(monitor),
                glfwGetMonitorName(monitor),
-               mode.width, mode.height,
+               mode->width, mode->height,
                x, y,
                x, y,
                widthMM, heightMM);
                widthMM, heightMM);
     }
     }

+ 3 - 3
tests/gamma.c

@@ -127,9 +127,9 @@ int main(int argc, char** argv)
 
 
     if (monitor)
     if (monitor)
     {
     {
-        GLFWvidmode mode = glfwGetVideoMode(monitor);
-        width = mode.width;
-        height = mode.height;
+        const GLFWvidmode* mode = glfwGetVideoMode(monitor);
+        width = mode->width;
+        height = mode->height;
     }
     }
     else
     else
     {
     {

+ 3 - 3
tests/iconify.c

@@ -117,9 +117,9 @@ int main(int argc, char** argv)
 
 
     if (monitor)
     if (monitor)
     {
     {
-        GLFWvidmode mode = glfwGetVideoMode(monitor);
-        width = mode.width;
-        height = mode.height;
+        const GLFWvidmode* mode = glfwGetVideoMode(monitor);
+        width = mode->width;
+        height = mode->height;
     }
     }
     else
     else
     {
     {

+ 3 - 3
tests/modes.c

@@ -82,7 +82,7 @@ static void key_callback(GLFWwindow* window, int key, int action, int mods)
 static void list_modes(GLFWmonitor* monitor)
 static void list_modes(GLFWmonitor* monitor)
 {
 {
     int count, x, y, widthMM, heightMM, dpi, i;
     int count, x, y, widthMM, heightMM, dpi, i;
-    GLFWvidmode mode = glfwGetVideoMode(monitor);
+    const GLFWvidmode* mode = glfwGetVideoMode(monitor);
     const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
     const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
 
 
     glfwGetMonitorPos(monitor, &x, &y);
     glfwGetMonitorPos(monitor, &x, &y);
@@ -91,10 +91,10 @@ static void list_modes(GLFWmonitor* monitor)
     printf("Name: %s (%s)\n",
     printf("Name: %s (%s)\n",
            glfwGetMonitorName(monitor),
            glfwGetMonitorName(monitor),
            glfwGetPrimaryMonitor() == monitor ? "primary" : "secondary");
            glfwGetPrimaryMonitor() == monitor ? "primary" : "secondary");
-    printf("Current mode: %s\n", format_mode(&mode));
+    printf("Current mode: %s\n", format_mode(mode));
     printf("Virtual position: %i %i\n", x, y);
     printf("Virtual position: %i %i\n", x, y);
 
 
-    dpi = (int) ((float) mode.width * 25.4f / (float) widthMM);
+    dpi = (int) ((float) mode->width * 25.4f / (float) widthMM);
     printf("Physical size: %i x %i mm (%i dpi)\n", widthMM, heightMM, dpi);
     printf("Physical size: %i x %i mm (%i dpi)\n", widthMM, heightMM, dpi);
 
 
     printf("Modes:\n");
     printf("Modes:\n");