2015-06-21 23:33:46 +08:00
|
|
|
/*
|
2024-01-02 05:15:26 +08:00
|
|
|
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely.
|
|
|
|
*/
|
2022-11-27 12:43:38 +08:00
|
|
|
#include <SDL3/SDL_test_common.h>
|
2022-12-15 12:58:20 +08:00
|
|
|
#include <SDL3/SDL_main.h>
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_OPENGL
|
|
|
|
|
2022-11-26 17:41:46 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2022-11-27 12:43:38 +08:00
|
|
|
#include <SDL3/SDL_opengl.h>
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
typedef struct GL_Context
|
|
|
|
{
|
2023-05-19 19:10:02 +08:00
|
|
|
#define SDL_PROC(ret, func, params) ret (APIENTRY *func) params;
|
2015-06-21 23:33:46 +08:00
|
|
|
#include "../src/render/opengl/SDL_glfuncs.h"
|
|
|
|
#undef SDL_PROC
|
|
|
|
} GL_Context;
|
|
|
|
|
|
|
|
/* Undefine this if you want a flat cube instead of a rainbow cube */
|
|
|
|
#define SHADED_CUBE
|
|
|
|
|
|
|
|
static SDLTest_CommonState *state;
|
|
|
|
static SDL_GLContext context;
|
|
|
|
static GL_Context ctx;
|
2023-06-25 22:18:58 +08:00
|
|
|
static SDL_bool suspend_when_occluded;
|
2015-06-21 23:33:46 +08:00
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
static int LoadContext(GL_Context *data)
|
2015-06-21 23:33:46 +08:00
|
|
|
{
|
2023-03-30 05:49:01 +08:00
|
|
|
#ifdef SDL_VIDEO_DRIVER_UIKIT
|
2015-06-21 23:33:46 +08:00
|
|
|
#define __SDL_NOGETPROCADDR__
|
2023-03-30 05:49:01 +08:00
|
|
|
#elif defined(SDL_VIDEO_DRIVER_ANDROID)
|
2015-06-21 23:33:46 +08:00
|
|
|
#define __SDL_NOGETPROCADDR__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined __SDL_NOGETPROCADDR__
|
2022-12-01 04:51:59 +08:00
|
|
|
#define SDL_PROC(ret, func, params) data->func = func;
|
2015-06-21 23:33:46 +08:00
|
|
|
#else
|
2022-12-01 04:51:59 +08:00
|
|
|
#define SDL_PROC(ret, func, params) \
|
|
|
|
do { \
|
2023-03-17 07:25:39 +08:00
|
|
|
data->func = (ret (APIENTRY *) params)SDL_GL_GetProcAddress(#func); \
|
2022-12-01 04:51:59 +08:00
|
|
|
if (!data->func) { \
|
2017-03-27 03:00:19 +08:00
|
|
|
return SDL_SetError("Couldn't load GL function %s: %s", #func, SDL_GetError()); \
|
2022-12-01 04:51:59 +08:00
|
|
|
} \
|
|
|
|
} while (0);
|
2015-12-25 20:41:23 +08:00
|
|
|
#endif /* __SDL_NOGETPROCADDR__ */
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
#include "../src/render/opengl/SDL_glfuncs.h"
|
|
|
|
#undef SDL_PROC
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
2023-03-08 23:12:45 +08:00
|
|
|
static void quit(int rc)
|
2015-06-21 23:33:46 +08:00
|
|
|
{
|
|
|
|
if (context) {
|
2022-12-01 04:51:59 +08:00
|
|
|
/* SDL_GL_MakeCurrent(0, NULL); */ /* doesn't do anything */
|
2024-07-11 02:50:57 +08:00
|
|
|
SDL_GL_DestroyContext(context);
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
SDLTest_CommonQuit(state);
|
2023-04-12 17:07:28 +08:00
|
|
|
/* Let 'main()' return normally */
|
|
|
|
if (rc != 0) {
|
|
|
|
exit(rc);
|
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
|
2023-03-08 23:12:45 +08:00
|
|
|
static void Render(void)
|
2015-06-21 23:33:46 +08:00
|
|
|
{
|
|
|
|
static float color[8][3] = {
|
2022-12-01 04:51:59 +08:00
|
|
|
{ 1.0, 1.0, 0.0 },
|
|
|
|
{ 1.0, 0.0, 0.0 },
|
|
|
|
{ 0.0, 0.0, 0.0 },
|
|
|
|
{ 0.0, 1.0, 0.0 },
|
|
|
|
{ 0.0, 1.0, 1.0 },
|
|
|
|
{ 1.0, 1.0, 1.0 },
|
|
|
|
{ 1.0, 0.0, 1.0 },
|
|
|
|
{ 0.0, 0.0, 1.0 }
|
2015-06-21 23:33:46 +08:00
|
|
|
};
|
|
|
|
static float cube[8][3] = {
|
2022-12-01 04:51:59 +08:00
|
|
|
{ 0.5, 0.5, -0.5 },
|
|
|
|
{ 0.5, -0.5, -0.5 },
|
|
|
|
{ -0.5, -0.5, -0.5 },
|
|
|
|
{ -0.5, 0.5, -0.5 },
|
|
|
|
{ -0.5, 0.5, 0.5 },
|
|
|
|
{ 0.5, 0.5, 0.5 },
|
|
|
|
{ 0.5, -0.5, 0.5 },
|
|
|
|
{ -0.5, -0.5, 0.5 }
|
2015-06-21 23:33:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Do our drawing, too. */
|
2023-03-11 20:53:14 +08:00
|
|
|
ctx.glClearColor(0.0, 0.0, 0.0, 0.0 /* used with --transparent */);
|
2015-06-21 23:33:46 +08:00
|
|
|
ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
ctx.glBegin(GL_QUADS);
|
|
|
|
|
|
|
|
#ifdef SHADED_CUBE
|
|
|
|
ctx.glColor3fv(color[0]);
|
|
|
|
ctx.glVertex3fv(cube[0]);
|
|
|
|
ctx.glColor3fv(color[1]);
|
|
|
|
ctx.glVertex3fv(cube[1]);
|
|
|
|
ctx.glColor3fv(color[2]);
|
|
|
|
ctx.glVertex3fv(cube[2]);
|
|
|
|
ctx.glColor3fv(color[3]);
|
|
|
|
ctx.glVertex3fv(cube[3]);
|
|
|
|
|
|
|
|
ctx.glColor3fv(color[3]);
|
|
|
|
ctx.glVertex3fv(cube[3]);
|
|
|
|
ctx.glColor3fv(color[4]);
|
|
|
|
ctx.glVertex3fv(cube[4]);
|
|
|
|
ctx.glColor3fv(color[7]);
|
|
|
|
ctx.glVertex3fv(cube[7]);
|
|
|
|
ctx.glColor3fv(color[2]);
|
|
|
|
ctx.glVertex3fv(cube[2]);
|
|
|
|
|
|
|
|
ctx.glColor3fv(color[0]);
|
|
|
|
ctx.glVertex3fv(cube[0]);
|
|
|
|
ctx.glColor3fv(color[5]);
|
|
|
|
ctx.glVertex3fv(cube[5]);
|
|
|
|
ctx.glColor3fv(color[6]);
|
|
|
|
ctx.glVertex3fv(cube[6]);
|
|
|
|
ctx.glColor3fv(color[1]);
|
|
|
|
ctx.glVertex3fv(cube[1]);
|
|
|
|
|
|
|
|
ctx.glColor3fv(color[5]);
|
|
|
|
ctx.glVertex3fv(cube[5]);
|
|
|
|
ctx.glColor3fv(color[4]);
|
|
|
|
ctx.glVertex3fv(cube[4]);
|
|
|
|
ctx.glColor3fv(color[7]);
|
|
|
|
ctx.glVertex3fv(cube[7]);
|
|
|
|
ctx.glColor3fv(color[6]);
|
|
|
|
ctx.glVertex3fv(cube[6]);
|
|
|
|
|
|
|
|
ctx.glColor3fv(color[5]);
|
|
|
|
ctx.glVertex3fv(cube[5]);
|
|
|
|
ctx.glColor3fv(color[0]);
|
|
|
|
ctx.glVertex3fv(cube[0]);
|
|
|
|
ctx.glColor3fv(color[3]);
|
|
|
|
ctx.glVertex3fv(cube[3]);
|
|
|
|
ctx.glColor3fv(color[4]);
|
|
|
|
ctx.glVertex3fv(cube[4]);
|
|
|
|
|
|
|
|
ctx.glColor3fv(color[6]);
|
|
|
|
ctx.glVertex3fv(cube[6]);
|
|
|
|
ctx.glColor3fv(color[1]);
|
|
|
|
ctx.glVertex3fv(cube[1]);
|
|
|
|
ctx.glColor3fv(color[2]);
|
|
|
|
ctx.glVertex3fv(cube[2]);
|
|
|
|
ctx.glColor3fv(color[7]);
|
|
|
|
ctx.glVertex3fv(cube[7]);
|
2022-12-01 04:51:59 +08:00
|
|
|
#else /* flat cube */
|
2015-06-21 23:33:46 +08:00
|
|
|
ctx.glColor3f(1.0, 0.0, 0.0);
|
|
|
|
ctx.glVertex3fv(cube[0]);
|
|
|
|
ctx.glVertex3fv(cube[1]);
|
|
|
|
ctx.glVertex3fv(cube[2]);
|
|
|
|
ctx.glVertex3fv(cube[3]);
|
|
|
|
|
|
|
|
ctx.glColor3f(0.0, 1.0, 0.0);
|
|
|
|
ctx.glVertex3fv(cube[3]);
|
|
|
|
ctx.glVertex3fv(cube[4]);
|
|
|
|
ctx.glVertex3fv(cube[7]);
|
|
|
|
ctx.glVertex3fv(cube[2]);
|
|
|
|
|
|
|
|
ctx.glColor3f(0.0, 0.0, 1.0);
|
|
|
|
ctx.glVertex3fv(cube[0]);
|
|
|
|
ctx.glVertex3fv(cube[5]);
|
|
|
|
ctx.glVertex3fv(cube[6]);
|
|
|
|
ctx.glVertex3fv(cube[1]);
|
|
|
|
|
|
|
|
ctx.glColor3f(0.0, 1.0, 1.0);
|
|
|
|
ctx.glVertex3fv(cube[5]);
|
|
|
|
ctx.glVertex3fv(cube[4]);
|
|
|
|
ctx.glVertex3fv(cube[7]);
|
|
|
|
ctx.glVertex3fv(cube[6]);
|
|
|
|
|
|
|
|
ctx.glColor3f(1.0, 1.0, 0.0);
|
|
|
|
ctx.glVertex3fv(cube[5]);
|
|
|
|
ctx.glVertex3fv(cube[0]);
|
|
|
|
ctx.glVertex3fv(cube[3]);
|
|
|
|
ctx.glVertex3fv(cube[4]);
|
|
|
|
|
|
|
|
ctx.glColor3f(1.0, 0.0, 1.0);
|
|
|
|
ctx.glVertex3fv(cube[6]);
|
|
|
|
ctx.glVertex3fv(cube[1]);
|
|
|
|
ctx.glVertex3fv(cube[2]);
|
|
|
|
ctx.glVertex3fv(cube[7]);
|
|
|
|
#endif /* SHADED_CUBE */
|
|
|
|
|
|
|
|
ctx.glEnd();
|
|
|
|
|
|
|
|
ctx.glMatrixMode(GL_MODELVIEW);
|
|
|
|
ctx.glRotatef(5.0, 1.0, 1.0, 1.0);
|
|
|
|
}
|
|
|
|
|
2023-11-24 02:47:13 +08:00
|
|
|
static void LogSwapInterval(void)
|
|
|
|
{
|
|
|
|
int interval = 0;
|
|
|
|
const int ret_interval = SDL_GL_GetSwapInterval(&interval);
|
|
|
|
if (ret_interval < 0) {
|
|
|
|
SDL_Log("Swap Interval : %d error: %s\n", interval, SDL_GetError());
|
|
|
|
} else {
|
|
|
|
SDL_Log("Swap Interval : %d\n", interval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
int main(int argc, char *argv[])
|
2015-06-21 23:33:46 +08:00
|
|
|
{
|
|
|
|
int fsaa, accel;
|
|
|
|
int value;
|
|
|
|
int i, done;
|
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
if (modes) {
for (i = 0; i < num_modes; ++i) {
SDL_DisplayMode *mode = modes[i];
SDL_Log("Display %" SDL_PRIu32 " mode %d: %dx%d@%gHz, %d%% scale\n",
display, i, mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f));
}
SDL_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
|
|
|
const SDL_DisplayMode *mode;
|
2015-06-21 23:33:46 +08:00
|
|
|
SDL_Event event;
|
2022-12-02 17:17:17 +08:00
|
|
|
Uint64 then, now;
|
|
|
|
Uint32 frames;
|
2015-06-21 23:33:46 +08:00
|
|
|
int status;
|
|
|
|
int dw, dh;
|
2018-12-16 14:04:07 +08:00
|
|
|
int swap_interval = 0;
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
/* Initialize parameters */
|
|
|
|
fsaa = 0;
|
|
|
|
accel = -1;
|
|
|
|
|
|
|
|
/* Initialize test framework */
|
|
|
|
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
2023-11-10 05:29:15 +08:00
|
|
|
if (!state) {
|
2015-06-21 23:33:46 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2023-03-17 07:25:39 +08:00
|
|
|
|
|
|
|
/* Enable standard application logging */
|
2024-05-17 01:00:50 +08:00
|
|
|
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
2023-03-17 07:25:39 +08:00
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
for (i = 1; i < argc;) {
|
|
|
|
int consumed;
|
|
|
|
|
|
|
|
consumed = SDLTest_CommonArg(state, i);
|
|
|
|
if (consumed == 0) {
|
2022-12-01 04:51:59 +08:00
|
|
|
if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i + 1 < argc) {
|
|
|
|
fsaa = SDL_atoi(argv[i + 1]);
|
2015-06-21 23:33:46 +08:00
|
|
|
consumed = 2;
|
2022-12-01 04:51:59 +08:00
|
|
|
} else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i + 1 < argc) {
|
|
|
|
accel = SDL_atoi(argv[i + 1]);
|
2015-06-21 23:33:46 +08:00
|
|
|
consumed = 2;
|
2023-06-25 22:18:58 +08:00
|
|
|
} else if(SDL_strcasecmp(argv[i], "--suspend-when-occluded") == 0) {
|
|
|
|
suspend_when_occluded = SDL_TRUE;
|
|
|
|
consumed = 1;
|
2015-06-21 23:33:46 +08:00
|
|
|
} else {
|
|
|
|
consumed = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (consumed < 0) {
|
2023-06-25 22:18:58 +08:00
|
|
|
static const char *options[] = { "[--fsaa n]", "[--accel n]", "[--suspend-when-occluded]", NULL };
|
2019-05-29 05:39:13 +08:00
|
|
|
SDLTest_CommonLogUsage(state, argv[0], options);
|
2015-06-21 23:33:46 +08:00
|
|
|
quit(1);
|
|
|
|
}
|
|
|
|
i += consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set OpenGL parameters */
|
|
|
|
state->window_flags |= SDL_WINDOW_OPENGL;
|
|
|
|
state->gl_red_size = 5;
|
|
|
|
state->gl_green_size = 5;
|
|
|
|
state->gl_blue_size = 5;
|
|
|
|
state->gl_depth_size = 16;
|
|
|
|
state->gl_double_buffer = 1;
|
|
|
|
if (fsaa) {
|
|
|
|
state->gl_multisamplebuffers = 1;
|
|
|
|
state->gl_multisamplesamples = fsaa;
|
|
|
|
}
|
|
|
|
if (accel >= 0) {
|
|
|
|
state->gl_accelerated = accel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SDLTest_CommonInit(state)) {
|
|
|
|
quit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create OpenGL context */
|
|
|
|
context = SDL_GL_CreateContext(state->windows[0]);
|
|
|
|
if (!context) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
|
|
|
quit(2);
|
|
|
|
}
|
2022-12-01 04:51:59 +08:00
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
/* Important: call this *after* creating the context */
|
|
|
|
if (LoadContext(&ctx) < 0) {
|
|
|
|
SDL_Log("Could not load GL functions\n");
|
|
|
|
quit(2);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-14 01:31:55 +08:00
|
|
|
SDL_GL_SetSwapInterval(state->render_vsync);
|
|
|
|
swap_interval = state->render_vsync;
|
2015-06-21 23:33:46 +08:00
|
|
|
|
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
if (modes) {
for (i = 0; i < num_modes; ++i) {
SDL_DisplayMode *mode = modes[i];
SDL_Log("Display %" SDL_PRIu32 " mode %d: %dx%d@%gHz, %d%% scale\n",
display, i, mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f));
}
SDL_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
|
|
|
mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
|
|
|
|
if (mode) {
|
2024-03-07 21:20:20 +08:00
|
|
|
SDL_Log("Screen BPP : %d\n", SDL_BITSPERPIXEL(mode->format));
|
Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
if (modes) {
for (i = 0; i < num_modes; ++i) {
SDL_DisplayMode *mode = modes[i];
SDL_Log("Display %" SDL_PRIu32 " mode %d: %dx%d@%gHz, %d%% scale\n",
display, i, mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f));
}
SDL_free(modes);
}
}
SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.
Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 13:23:14 +08:00
|
|
|
}
|
2023-01-02 00:20:41 +08:00
|
|
|
|
2023-11-24 02:47:13 +08:00
|
|
|
LogSwapInterval();
|
2023-01-02 00:20:41 +08:00
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
SDL_GetWindowSize(state->windows[0], &dw, &dh);
|
|
|
|
SDL_Log("Window Size : %d,%d\n", dw, dh);
|
2023-01-29 10:43:03 +08:00
|
|
|
SDL_GetWindowSizeInPixels(state->windows[0], &dw, &dh);
|
2015-06-21 23:33:46 +08:00
|
|
|
SDL_Log("Draw Size : %d,%d\n", dw, dh);
|
|
|
|
SDL_Log("\n");
|
|
|
|
SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR));
|
|
|
|
SDL_Log("Renderer : %s\n", ctx.glGetString(GL_RENDERER));
|
|
|
|
SDL_Log("Version : %s\n", ctx.glGetString(GL_VERSION));
|
|
|
|
SDL_Log("Extensions : %s\n", ctx.glGetString(GL_EXTENSIONS));
|
|
|
|
SDL_Log("\n");
|
|
|
|
|
|
|
|
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
|
|
|
|
if (!status) {
|
|
|
|
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
|
|
|
|
} else {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
|
|
|
|
}
|
|
|
|
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
|
|
|
|
if (!status) {
|
|
|
|
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
|
|
|
|
} else {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
|
|
|
|
}
|
|
|
|
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
|
|
|
|
if (!status) {
|
|
|
|
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
|
|
|
|
} else {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
|
|
|
|
}
|
|
|
|
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
|
|
|
|
if (!status) {
|
|
|
|
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
|
|
|
|
} else {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
|
|
|
|
}
|
|
|
|
if (fsaa) {
|
|
|
|
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
|
|
|
|
if (!status) {
|
|
|
|
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
|
|
|
|
} else {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
|
2022-12-01 04:51:59 +08:00
|
|
|
SDL_GetError());
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
|
|
|
|
if (!status) {
|
|
|
|
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
|
2022-12-01 04:51:59 +08:00
|
|
|
value);
|
2015-06-21 23:33:46 +08:00
|
|
|
} else {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
2022-12-01 04:51:59 +08:00
|
|
|
SDL_GetError());
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (accel >= 0) {
|
|
|
|
status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
|
|
|
|
if (!status) {
|
|
|
|
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
|
2022-12-01 04:51:59 +08:00
|
|
|
value);
|
2015-06-21 23:33:46 +08:00
|
|
|
} else {
|
2015-11-26 04:39:28 +08:00
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
2022-12-01 04:51:59 +08:00
|
|
|
SDL_GetError());
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set rendering settings */
|
|
|
|
ctx.glMatrixMode(GL_PROJECTION);
|
|
|
|
ctx.glLoadIdentity();
|
|
|
|
ctx.glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
|
|
|
|
ctx.glMatrixMode(GL_MODELVIEW);
|
|
|
|
ctx.glLoadIdentity();
|
|
|
|
ctx.glEnable(GL_DEPTH_TEST);
|
|
|
|
ctx.glDepthFunc(GL_LESS);
|
|
|
|
ctx.glShadeModel(GL_SMOOTH);
|
2022-12-01 04:51:59 +08:00
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
/* Main render loop */
|
|
|
|
frames = 0;
|
|
|
|
then = SDL_GetTicks();
|
|
|
|
done = 0;
|
|
|
|
while (!done) {
|
2018-12-16 14:04:07 +08:00
|
|
|
SDL_bool update_swap_interval = SDL_FALSE;
|
2023-06-25 22:18:58 +08:00
|
|
|
int active_windows = 0;
|
2018-12-16 14:04:07 +08:00
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
/* Check for events */
|
|
|
|
++frames;
|
|
|
|
while (SDL_PollEvent(&event)) {
|
|
|
|
SDLTest_CommonEvent(state, &event, &done);
|
2023-01-24 09:54:09 +08:00
|
|
|
if (event.type == SDL_EVENT_KEY_DOWN) {
|
2024-07-01 11:05:22 +08:00
|
|
|
if (event.key.key == SDLK_O) {
|
2018-12-16 14:04:07 +08:00
|
|
|
swap_interval--;
|
|
|
|
update_swap_interval = SDL_TRUE;
|
2024-07-01 11:05:22 +08:00
|
|
|
} else if (event.key.key == SDLK_P) {
|
2018-12-16 14:04:07 +08:00
|
|
|
swap_interval++;
|
|
|
|
update_swap_interval = SDL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
2018-12-16 14:04:07 +08:00
|
|
|
|
|
|
|
if (update_swap_interval) {
|
|
|
|
SDL_Log("Swap interval to be set to %d\n", swap_interval);
|
|
|
|
}
|
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
for (i = 0; i < state->num_windows; ++i) {
|
|
|
|
int w, h;
|
2023-06-25 22:18:58 +08:00
|
|
|
if (state->windows[i] == NULL ||
|
|
|
|
(suspend_when_occluded && (SDL_GetWindowFlags(state->windows[i]) & SDL_WINDOW_OCCLUDED))) {
|
2015-06-21 23:33:46 +08:00
|
|
|
continue;
|
2022-11-28 00:38:43 +08:00
|
|
|
}
|
2023-06-25 22:18:58 +08:00
|
|
|
++active_windows;
|
2015-06-21 23:33:46 +08:00
|
|
|
SDL_GL_MakeCurrent(state->windows[i], context);
|
2018-12-16 14:04:07 +08:00
|
|
|
if (update_swap_interval) {
|
|
|
|
SDL_GL_SetSwapInterval(swap_interval);
|
2023-11-24 02:47:13 +08:00
|
|
|
LogSwapInterval();
|
2018-12-16 14:04:07 +08:00
|
|
|
}
|
2023-01-29 10:43:03 +08:00
|
|
|
SDL_GetWindowSizeInPixels(state->windows[i], &w, &h);
|
2015-06-21 23:33:46 +08:00
|
|
|
ctx.glViewport(0, 0, w, h);
|
|
|
|
Render();
|
|
|
|
SDL_GL_SwapWindow(state->windows[i]);
|
|
|
|
}
|
2023-06-25 22:18:58 +08:00
|
|
|
|
|
|
|
/* If all windows are occluded, throttle event polling to 15hz. */
|
|
|
|
if (!active_windows) {
|
|
|
|
SDL_DelayNS(SDL_NS_PER_SECOND / 15);
|
|
|
|
}
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Print out some timing information */
|
|
|
|
now = SDL_GetTicks();
|
|
|
|
if (now > then) {
|
|
|
|
SDL_Log("%2.2f frames per second\n",
|
2022-12-01 04:51:59 +08:00
|
|
|
((double)frames * 1000) / (now - then));
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
quit(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* HAVE_OPENGL */
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
int main(int argc, char *argv[])
|
2015-06-21 23:33:46 +08:00
|
|
|
{
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_OPENGL */
|