OpenGL examples: use NWindow instead of old gfx API

This commit is contained in:
fincs 2018-12-12 21:16:51 +01:00
parent 2a6e86f1ea
commit 6590041f87
7 changed files with 28 additions and 26 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ build
*.nacp *.nacp
*.nro *.nro
*.bz2 *.bz2
*~

View File

@ -77,7 +77,7 @@ static EGLDisplay s_display;
static EGLContext s_context; static EGLContext s_context;
static EGLSurface s_surface; static EGLSurface s_surface;
static bool initEgl() static bool initEgl(NWindow* win)
{ {
// Connect to the EGL default display // Connect to the EGL default display
s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
@ -119,7 +119,7 @@ static bool initEgl()
} }
// Create an EGL window surface // Create an EGL window surface
s_surface = eglCreateWindowSurface(s_display, config, (char*)"", nullptr); s_surface = eglCreateWindowSurface(s_display, config, win, nullptr);
if (!s_surface) if (!s_surface)
{ {
TRACE("Surface creation failed! error: %d", eglGetError()); TRACE("Surface creation failed! error: %d", eglGetError());
@ -450,7 +450,7 @@ static void sceneUpdate(u32 kHeld)
glUniformMatrix4fv(loc_mdlvMtx, 1, GL_FALSE, glm::value_ptr(mdlvMtx)); glUniformMatrix4fv(loc_mdlvMtx, 1, GL_FALSE, glm::value_ptr(mdlvMtx));
} }
static void configureResolution(bool halved) static void configureResolution(NWindow* win, bool halved)
{ {
int width, height; int width, height;
@ -484,7 +484,7 @@ static void configureResolution(bool halved)
// remain unused when rendering at a smaller resolution than the framebuffer). // remain unused when rendering at a smaller resolution than the framebuffer).
// Note that glViewport expects the coordinates of the bottom-left corner of // Note that glViewport expects the coordinates of the bottom-left corner of
// the viewport, so we have to calculate that too. // the viewport, so we have to calculate that too.
gfxConfigureResolution(width, height); nwindowSetCrop(win, 0, 0, width, height);
glViewport(0, 1080-height, width, height); glViewport(0, 1080-height, width, height);
} }
@ -511,11 +511,12 @@ int main(int argc, char* argv[])
// Set mesa configuration (useful for debugging) // Set mesa configuration (useful for debugging)
setMesaConfig(); setMesaConfig();
// Configure the framebuffer dimensions (1080p) // Retrieve the default window and configure its dimensions (1080p)
gfxInitResolution(1920, 1080); NWindow* win = nwindowGetDefault();
nwindowSetDimensions(win, 1920, 1080);
// Initialize EGL // Initialize EGL on the default window
if (!initEgl()) if (!initEgl(win))
return EXIT_FAILURE; return EXIT_FAILURE;
// Load OpenGL routines using glad // Load OpenGL routines using glad
@ -540,7 +541,7 @@ int main(int argc, char* argv[])
// will be different in handheld mode/docked mode. // will be different in handheld mode/docked mode.
// As an additional demonstration, when holding A we render the scene // As an additional demonstration, when holding A we render the scene
// at half the original resolution. // at half the original resolution.
configureResolution(shouldHalveResolution); configureResolution(win, shouldHalveResolution);
// Update our scene // Update our scene
sceneUpdate(kHeld); sceneUpdate(kHeld);

View File

@ -105,7 +105,7 @@ static EGLDisplay s_display;
static EGLContext s_context; static EGLContext s_context;
static EGLSurface s_surface; static EGLSurface s_surface;
static bool initEgl() static bool initEgl(NWindow* win)
{ {
// Connect to the EGL default display // Connect to the EGL default display
s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
@ -139,7 +139,7 @@ static bool initEgl()
} }
// Create an EGL window surface // Create an EGL window surface
s_surface = eglCreateWindowSurface(s_display, config, (char*)"", NULL); s_surface = eglCreateWindowSurface(s_display, config, win, NULL);
if (!s_surface) if (!s_surface)
{ {
TRACE("Surface creation failed! error: %d", eglGetError()); TRACE("Surface creation failed! error: %d", eglGetError());
@ -847,8 +847,8 @@ int main(int argc, char* argv[])
// Set mesa configuration (useful for debugging) // Set mesa configuration (useful for debugging)
setMesaConfig(); setMesaConfig();
// Initialize EGL // Initialize EGL on the default window
if (!initEgl()) if (!initEgl(nwindowGetDefault()))
return EXIT_FAILURE; return EXIT_FAILURE;
// Initialize gears demo // Initialize gears demo

View File

@ -404,7 +404,7 @@ bool GpuConsole::initEgl()
} }
// Create an EGL window surface // Create an EGL window surface
s_surface = eglCreateWindowSurface(s_display, config, (char*)"", nullptr); s_surface = eglCreateWindowSurface(s_display, config, nwindowGetDefault(), nullptr);
if (!s_surface) if (!s_surface)
{ {
TRACE("Surface creation failed! error: %d", eglGetError()); TRACE("Surface creation failed! error: %d", eglGetError());

View File

@ -74,7 +74,7 @@ static EGLDisplay s_display;
static EGLContext s_context; static EGLContext s_context;
static EGLSurface s_surface; static EGLSurface s_surface;
static bool initEgl() static bool initEgl(NWindow* win)
{ {
// Connect to the EGL default display // Connect to the EGL default display
s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
@ -116,7 +116,7 @@ static bool initEgl()
} }
// Create an EGL window surface // Create an EGL window surface
s_surface = eglCreateWindowSurface(s_display, config, (char*)"", nullptr); s_surface = eglCreateWindowSurface(s_display, config, win, nullptr);
if (!s_surface) if (!s_surface)
{ {
TRACE("Surface creation failed! error: %d", eglGetError()); TRACE("Surface creation failed! error: %d", eglGetError());
@ -404,8 +404,8 @@ int main(int argc, char* argv[])
// Set mesa configuration (useful for debugging) // Set mesa configuration (useful for debugging)
setMesaConfig(); setMesaConfig();
// Initialize EGL // Initialize EGL on the default window
if (!initEgl()) if (!initEgl(nwindowGetDefault()))
return EXIT_FAILURE; return EXIT_FAILURE;
// Load OpenGL routines using glad // Load OpenGL routines using glad

View File

@ -61,7 +61,7 @@ static EGLDisplay s_display;
static EGLContext s_context; static EGLContext s_context;
static EGLSurface s_surface; static EGLSurface s_surface;
static bool initEgl() static bool initEgl(NWindow* win)
{ {
// Connect to the EGL default display // Connect to the EGL default display
s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
@ -103,7 +103,7 @@ static bool initEgl()
} }
// Create an EGL window surface // Create an EGL window surface
s_surface = eglCreateWindowSurface(s_display, config, (char*)"", nullptr); s_surface = eglCreateWindowSurface(s_display, config, win, nullptr);
if (!s_surface) if (!s_surface)
{ {
TRACE("Surface creation failed! error: %d", eglGetError()); TRACE("Surface creation failed! error: %d", eglGetError());
@ -315,8 +315,8 @@ int main(int argc, char* argv[])
// Set mesa configuration (useful for debugging) // Set mesa configuration (useful for debugging)
setMesaConfig(); setMesaConfig();
// Initialize EGL // Initialize EGL on the default window
if (!initEgl()) if (!initEgl(nwindowGetDefault()))
return EXIT_FAILURE; return EXIT_FAILURE;
// Load OpenGL routines using glad // Load OpenGL routines using glad

View File

@ -74,7 +74,7 @@ static EGLDisplay s_display;
static EGLContext s_context; static EGLContext s_context;
static EGLSurface s_surface; static EGLSurface s_surface;
static bool initEgl() static bool initEgl(NWindow* win)
{ {
// Connect to the EGL default display // Connect to the EGL default display
s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); s_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
@ -116,7 +116,7 @@ static bool initEgl()
} }
// Create an EGL window surface // Create an EGL window surface
s_surface = eglCreateWindowSurface(s_display, config, (char*)"", nullptr); s_surface = eglCreateWindowSurface(s_display, config, win, nullptr);
if (!s_surface) if (!s_surface)
{ {
TRACE("Surface creation failed! error: %d", eglGetError()); TRACE("Surface creation failed! error: %d", eglGetError());
@ -504,8 +504,8 @@ int main(int argc, char* argv[])
// Set mesa configuration (useful for debugging) // Set mesa configuration (useful for debugging)
setMesaConfig(); setMesaConfig();
// Initialize EGL // Initialize EGL on the default window
if (!initEgl()) if (!initEgl(nwindowGetDefault()))
return EXIT_FAILURE; return EXIT_FAILURE;
// Load OpenGL routines using glad // Load OpenGL routines using glad