Separated window and framebuffer sizes.

This commit is contained in:
Camilla Berglund 2013-06-03 12:51:57 +02:00
parent 89588a4508
commit 3498163da1
26 changed files with 197 additions and 58 deletions

View File

@ -280,6 +280,8 @@ GLFW.
compile time
* Added `glfwGetWindowMonitor` for querying the monitor, if any, of the
specified window
* Added `glfwGetFramebufferSize` and `glfwSetFramebufferSizeCallback` for
receiving the current size, in pixels, of the framebuffer
* Added `glfwSetWindowPosCallback` and `GLFWwindowposfun` for receiving window
position events
* Added `glfwSetWindowFocusCallback` and `GLFWwindowfocusfun` for receiving
@ -377,6 +379,7 @@ GLFW.
* Bugfix: Cursor centering upon leaving captured cursor mode was reported
before the mode was changed to non-captured
* [Cocoa] Added support for OpenGL 3.2 core profile in 10.7 Lion and above
* [Cocoa] Added support for high-DPI (Retina) monitors
* [Cocoa] Added support for joysticks
* [Cocoa] Postponed menu creation to first window creation
* [Cocoa] Replaced `NSDate` time source with `mach_absolute_time`
@ -413,6 +416,7 @@ GLFW.
mode was incorrectly removed
* [X11] Bugfix: The window size hints were not updated when calling
`glfwSetWindowSize` on a non-resizable window
* [Win32] Added support for high-DPI monitors
* [Win32] Changed port to use Unicode mode only
* [Win32] Removed explicit support for versions of Windows older than Windows
XP

View File

@ -589,13 +589,13 @@ int main( void )
exit( EXIT_FAILURE );
}
glfwSetWindowSizeCallback(window, reshape);
glfwSetFramebufferSizeCallback(window, reshape);
glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
glfwSwapInterval( 1 );
glfwGetWindowSize(window, &width, &height);
glfwGetFramebufferSize(window, &width, &height);
reshape(window, width, height);
glfwSetTime( 0.0 );

View File

@ -337,13 +337,13 @@ int main(int argc, char *argv[])
}
// Set callback functions
glfwSetWindowSizeCallback(window, reshape);
glfwSetFramebufferSizeCallback(window, reshape);
glfwSetKeyCallback(window, key);
glfwMakeContextCurrent(window);
glfwSwapInterval( 1 );
glfwGetWindowSize(window, &width, &height);
glfwGetFramebufferSize(window, &width, &height);
reshape(window, width, height);
// Parse command-line options

View File

@ -57,7 +57,7 @@ int main(void)
float ratio;
int width, height;
glfwGetWindowSize(window, &width, &height);
glfwGetFramebufferSize(window, &width, &height);
ratio = width / (float) height;
glViewport(0, 0, width, height);

View File

@ -354,10 +354,10 @@ static void drawAllViews(void)
//========================================================================
// Window size callback function
// Framebuffer size callback function
//========================================================================
static void windowSizeFun(GLFWwindow* window, int w, int h)
static void framebufferSizeFun(GLFWwindow* window, int w, int h)
{
width = w;
height = h > 0 ? h : 1;
@ -467,7 +467,7 @@ int main(void)
}
// Set callback functions
glfwSetWindowSizeCallback(window, windowSizeFun);
glfwSetFramebufferSizeCallback(window, framebufferSizeFun);
glfwSetWindowRefreshCallback(window, windowRefreshFun);
glfwSetCursorPosCallback(window, cursorPosFun);
glfwSetMouseButtonCallback(window, mouseButtonFun);
@ -477,8 +477,8 @@ int main(void)
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwGetWindowSize(window, &width, &height);
windowSizeFun(window, width, height);
glfwGetFramebufferSize(window, &width, &height);
framebufferSizeFun(window, width, height);
// Main loop
for (;;)

View File

@ -361,10 +361,10 @@ void scroll_callback(GLFWwindow* window, double x, double y)
//========================================================================
// Callback function for window resize events
// Callback function for framebuffer resize events
//========================================================================
void window_size_callback(GLFWwindow* window, int width, int height)
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
float ratio = 1.f;
@ -404,7 +404,7 @@ int main(int argc, char* argv[])
}
glfwSetKeyCallback(window, key_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
glfwSetCursorPosCallback(window, cursor_position_callback);
glfwSetScrollCallback(window, scroll_callback);
@ -412,8 +412,8 @@ int main(int argc, char* argv[])
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwGetWindowSize(window, &width, &height);
window_size_callback(window, width, height);
glfwGetFramebufferSize(window, &width, &height);
framebuffer_size_callback(window, width, height);
// Initialize OpenGL
init_opengl();

View File

@ -679,6 +679,21 @@ typedef void (* GLFWwindowfocusfun)(GLFWwindow*,int);
*/
typedef void (* GLFWwindowiconifyfun)(GLFWwindow*,int);
/*! @brief The function signature for framebuffer resize callbacks.
*
* This is the function signature for framebuffer resize callback
* functions.
*
* @param[in] window The window whose framebuffer was resized.
* @param[in] width The new width, in pixels, of the framebuffer.
* @param[in] height The new height, in pixels, of the framebuffer.
*
* @sa glfwSetFramebufferSizeCallback
*
* @ingroup window
*/
typedef void (* GLFWframebuffersizefun)(GLFWwindow*,int,int);
/*! @brief The function signature for mouse button callbacks.
*
* This is the function signature for mouse button callback functions.
@ -1369,6 +1384,21 @@ GLFWAPI void glfwGetWindowSize(GLFWwindow* window, int* width, int* height);
*/
GLFWAPI void glfwSetWindowSize(GLFWwindow* window, int width, int height);
/*! @brief Retrieves the size of the framebuffer of the specified window.
*
* This function retrieves the size, in pixels, of the framebuffer of the
* specified window.
*
* @param[in] window The window whose framebuffer to query.
* @param[out] width The width of the framebuffer.
* @param[out] height The height of the framebuffer.
*
* @sa glfwSetFramebufferSizeCallback
*
* @ingroup window
*/
GLFWAPI void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height);
/*! @brief Iconifies the specified window.
*
* This function iconifies/minimizes the specified window, if it was previously
@ -1604,6 +1634,21 @@ GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwi
*/
GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun cbfun);
/*! @brief Sets the framebuffer resize callback for the specified window.
*
* This function sets the framebuffer resize callback of the specified window,
* which is called when the framebuffer of the specified window is resized.
*
* @param[in] window The window whose callback to set.
* @param[in] cbfun The new callback, or `NULL` to remove the currently set
* callback.
*
* @return The previously set callback, or `NULL` if an error occurred.
*
* @ingroup window
*/
GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun cbfun);
/*! @brief Processes all pending events.
*
* This function processes only those events that have already been received

View File

@ -111,9 +111,11 @@ static void centerCursor(_GLFWwindow *window)
{
[window->nsgl.context update];
int width, height;
_glfwPlatformGetWindowSize(window, &width, &height);
_glfwInputWindowSize(window, width, height);
const NSRect contentRect = [window->ns.view frame];
const NSRect fbRect = [window->ns.view convertRectToBacking:contentRect];
_glfwInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
_glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height);
_glfwInputWindowDamage(window);
if (window->cursorMode == GLFW_CURSOR_DISABLED)
@ -515,6 +517,14 @@ static int convertMacKeyCode(unsigned int macKeyCode)
_glfwInputCursorEnter(window, GL_TRUE);
}
- (void)viewDidChangeBackingProperties
{
const NSRect contentRect = [window->ns.view frame];
const NSRect fbRect = [window->ns.view convertRectToBacking:contentRect];
_glfwInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
}
- (void)updateTrackingAreas
{
if (trackingArea != nil)
@ -804,6 +814,8 @@ static GLboolean createWindow(_GLFWwindow* window,
window->ns.view = [[GLFWContentView alloc] initWithGlfwWindow:window];
[window->ns.view setWantsBestResolutionOpenGLSurface:YES];
[window->ns.object setTitle:[NSString stringWithUTF8String:wndconfig->title]];
[window->ns.object setContentView:window->ns.view];
[window->ns.object setDelegate:window->ns.delegate];
@ -927,6 +939,11 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
[window->ns.object setContentSize:NSMakeSize(width, height)];
}
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height)
{
_glfwPlatformGetWindowSize(window, width, height);
}
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
{
if (window->monitor)

View File

@ -222,6 +222,7 @@ struct _GLFWwindow
GLFWwindowrefreshfun refresh;
GLFWwindowfocusfun focus;
GLFWwindowiconifyfun iconify;
GLFWframebuffersizefun fbsize;
GLFWmousebuttonfun mouseButton;
GLFWcursorposfun cursorPos;
GLFWcursorenterfun cursorEnter;
@ -474,6 +475,11 @@ void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height);
*/
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
/*! @copydoc glfwGetFramebufferSize
* @ingroup platform
*/
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height);
/*! @copydoc glfwIconifyWindow
* @ingroup platform
*/
@ -562,6 +568,14 @@ void _glfwInputWindowPos(_GLFWwindow* window, int xpos, int ypos);
*/
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
/*! @brief Notifies shared code of a framebuffer resize event.
* @param[in] window The window that received the event.
* @param[in] width The new width, in pixels, of the framebuffer.
* @param[in] height The new height, in pixels, of the framebuffer.
* @ingroup event
*/
void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height);
/*! @brief Notifies shared code of a window iconification event.
* @param[in] window The window that received the event.
* @param[in] iconified `GL_TRUE` if the window was iconified, or `GL_FALSE`

View File

@ -645,6 +645,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (window->cursorMode == GLFW_CURSOR_DISABLED)
updateClipRect(window);
_glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam));
_glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
return 0;
}
@ -991,6 +992,11 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
}
}
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height)
{
_glfwPlatformGetWindowSize(window, width, height);
}
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
{
ShowWindow(window->win32.handle, SW_MINIMIZE);

View File

@ -113,6 +113,12 @@ void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
window->callbacks.iconify((GLFWwindow*) window, iconified);
}
void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height)
{
if (window->callbacks.fbsize)
window->callbacks.fbsize((GLFWwindow*) window, width, height);
}
void _glfwInputWindowVisibility(_GLFWwindow* window, int visible)
{
window->visible = visible;
@ -478,6 +484,15 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height)
_glfwPlatformSetWindowSize(window, width, height);
}
GLFWAPI void glfwGetFramebufferSize(GLFWwindow* handle, int* width, int* height)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
_GLFW_REQUIRE_INIT();
_glfwPlatformGetFramebufferSize(window, width, height);
}
GLFWAPI void glfwIconifyWindow(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
@ -665,6 +680,19 @@ GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle,
return previous;
}
GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle,
GLFWframebuffersizefun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
GLFWframebuffersizefun previous;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
previous = window->callbacks.fbsize;
window->callbacks.fbsize = cbfun;
return previous;
}
GLFWAPI void glfwPollEvents(void)
{
_GLFW_REQUIRE_INIT();

View File

@ -635,6 +635,10 @@ static void processEvent(XEvent *event)
case ConfigureNotify:
{
_glfwInputFramebufferSize(window,
event->xconfigure.width,
event->xconfigure.height);
_glfwInputWindowSize(window,
event->xconfigure.width,
event->xconfigure.height);
@ -1021,6 +1025,11 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
XFlush(_glfw.x11.display);
}
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height)
{
_glfwPlatformGetWindowSize(window, width, height);
}
void _glfwPlatformIconifyWindow(_GLFWwindow* window)
{
if (window->x11.overrideRedirect)

View File

@ -56,7 +56,7 @@ static void error_callback(int error, const char* description)
fprintf(stderr, "Error: %s\n", description);
}
static void window_size_callback(GLFWwindow* window, int width, int height)
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
window_width = width;
window_height = height;
@ -98,13 +98,13 @@ int main(void)
}
glfwSetCursorPosCallback(window, cursor_position_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
glfwGetWindowSize(window, &width, &height);
window_size_callback(window, width, height);
glfwGetFramebufferSize(window, &width, &height);
framebuffer_size_callback(window, width, height);
set_swap_interval(window, swap_interval);

View File

@ -79,7 +79,7 @@ static void key_callback(GLFWwindow* window, int key, int action, int mods)
}
}
static void window_size_callback(GLFWwindow* window, int width, int height)
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
@ -124,7 +124,7 @@ int main(int argc, char** argv)
glfwSwapInterval(1);
glfwSetKeyCallback(window, key_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f);

View File

@ -96,9 +96,9 @@ int main(void)
}
glfwMakeContextCurrent(window);
glfwGetWindowSize(window, &width, &height);
glfwGetFramebufferSize(window, &width, &height);
printf("window size: %ix%i\n", width, height);
printf("framebuffer size: %ix%i\n", width, height);
for (i = 0; glfw_attribs[i].name; i++)
{

View File

@ -259,6 +259,15 @@ static void window_size_callback(GLFWwindow* window, int width, int height)
glfwGetTime(),
width,
height);
}
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
printf("%08x at %0.3f: Framebuffer size: %i %i\n",
counter++,
glfwGetTime(),
width,
height);
glViewport(0, 0, width, height);
}
@ -422,6 +431,7 @@ int main(void)
glfwSetWindowPosCallback(window, window_pos_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetWindowRefreshCallback(window, window_refresh_callback);
glfwSetWindowFocusCallback(window, window_focus_callback);

View File

@ -43,7 +43,7 @@ static void error_callback(int error, const char* description)
fprintf(stderr, "Error: %s\n", description);
}
static void window_size_callback(GLFWwindow* window, int width, int height)
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
@ -107,7 +107,7 @@ int main(int argc, char** argv)
}
glfwSetKeyCallback(window, key_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);

View File

@ -91,7 +91,7 @@ static void key_callback(GLFWwindow* window, int key, int action, int mods)
}
}
static void size_callback(GLFWwindow* window, int width, int height)
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
@ -150,7 +150,7 @@ int main(int argc, char** argv)
glfwSwapInterval(1);
glfwSetKeyCallback(window, key_callback);
glfwSetWindowSizeCallback(window, size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f);

View File

@ -68,6 +68,11 @@ static void key_callback(GLFWwindow* window, int key, int action, int mods)
static void window_size_callback(GLFWwindow* window, int width, int height)
{
printf("%0.2f Window resized to %ix%i\n", glfwGetTime(), width, height);
}
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
printf("%0.2f Framebuffer resized to %ix%i\n", glfwGetTime(), width, height);
glViewport(0, 0, width, height);
}
@ -138,6 +143,7 @@ int main(int argc, char** argv)
glfwSwapInterval(1);
glfwSetKeyCallback(window, key_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetWindowFocusCallback(window, window_focus_callback);
glfwSetWindowIconifyCallback(window, window_iconify_callback);
@ -150,7 +156,7 @@ int main(int argc, char** argv)
while (!glfwWindowShouldClose(window))
{
glfwGetWindowSize(window, &width, &height);
glfwGetFramebufferSize(window, &width, &height);
glScissor(0, 0, width, height);
glClearColor(0, 0, 0, 0);

View File

@ -56,7 +56,7 @@ static void error_callback(int error, const char* description)
fprintf(stderr, "Error: %s\n", description);
}
static void window_size_callback(GLFWwindow* window, int width, int height)
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
@ -108,7 +108,7 @@ static void draw_joysticks(GLFWwindow* window)
{
int i, width, height;
glfwGetWindowSize(window, &width, &height);
glfwGetFramebufferSize(window, &width, &height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@ -208,7 +208,7 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);

View File

@ -67,9 +67,9 @@ static void error_callback(int error, const char* description)
fprintf(stderr, "Error: %s\n", description);
}
static void window_size_callback(GLFWwindow* window, int width, int height)
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
printf("Window resized to %ix%i\n", width, height);
printf("Framebuffer resized to %ix%i\n", width, height);
glViewport(0, 0, width, height);
}
@ -143,7 +143,7 @@ static void test_modes(GLFWmonitor* monitor)
continue;
}
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);

View File

@ -87,7 +87,7 @@ static void key_callback(GLFWwindow* window, int key, int action, int mods)
}
}
static void window_size_callback(GLFWwindow* window, int width, int height)
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
@ -104,7 +104,7 @@ static GLFWwindow* open_window(void)
glfwGetCursorPos(window, &cursor_x, &cursor_y);
printf("Cursor position: %f %f\n", cursor_x, cursor_y);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetCursorPosCallback(window, cursor_position_callback);
glfwSetKeyCallback(window, key_callback);

View File

@ -44,7 +44,7 @@ static void error_callback(int error, const char* description)
fprintf(stderr, "Error: %s\n", description);
}
static void window_size_callback(GLFWwindow* window, int width, int height)
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
@ -82,7 +82,7 @@ static GLFWwindow* open_window(int width, int height, GLFWmonitor* monitor)
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetKeyCallback(window, key_callback);

View File

@ -94,7 +94,7 @@ static GLuint create_texture(void)
static void draw_quad(GLuint texture)
{
int width, height;
glfwGetWindowSize(glfwGetCurrentContext(), &width, &height);
glfwGetFramebufferSize(glfwGetCurrentContext(), &width, &height);
glViewport(0, 0, width, height);

View File

@ -59,7 +59,7 @@ static void error_callback(int error, const char* description)
fprintf(stderr, "Error: %s\n", description);
}
static void window_size_callback(GLFWwindow* window, int width, int height)
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
@ -95,7 +95,7 @@ int main(void)
last_time = glfwGetTime();
frame_rate = 0.0;
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetKeyCallback(window, key_callback);
glMatrixMode(GL_PROJECTION);

View File

@ -37,7 +37,7 @@ static void error_callback(int error, const char* description)
fprintf(stderr, "Error: %s\n", description);
}
static void window_size_callback(GLFWwindow* window, int width, int height)
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
@ -61,7 +61,7 @@ int main(void)
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
while (!glfwWindowShouldClose(window))
{