REVIEWED: InitPlatform()
organization and code-gardening
This commit is contained in:
parent
3ff6026917
commit
a0f0034352
7 changed files with 221 additions and 134 deletions
|
@ -518,6 +518,8 @@ void PollInputEvents(void)
|
||||||
// Initialize platform: graphics, inputs and more
|
// Initialize platform: graphics, inputs and more
|
||||||
int InitPlatform(void)
|
int InitPlatform(void)
|
||||||
{
|
{
|
||||||
|
// Initialize display basic configuration
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
CORE.Window.currentFbo.width = CORE.Window.screen.width;
|
CORE.Window.currentFbo.width = CORE.Window.screen.width;
|
||||||
CORE.Window.currentFbo.height = CORE.Window.screen.height;
|
CORE.Window.currentFbo.height = CORE.Window.screen.height;
|
||||||
|
|
||||||
|
@ -545,27 +547,33 @@ int InitPlatform(void)
|
||||||
//AConfiguration_getKeyboard(platform.app->config);
|
//AConfiguration_getKeyboard(platform.app->config);
|
||||||
//AConfiguration_getScreenSize(platform.app->config);
|
//AConfiguration_getScreenSize(platform.app->config);
|
||||||
//AConfiguration_getScreenLong(platform.app->config);
|
//AConfiguration_getScreenLong(platform.app->config);
|
||||||
|
|
||||||
// Initialize App command system
|
|
||||||
// NOTE: On APP_CMD_INIT_WINDOW -> InitGraphicsDevice(), InitTimer(), LoadFontDefault()...
|
|
||||||
platform.app->onAppCmd = AndroidCommandCallback;
|
|
||||||
|
|
||||||
// Initialize input events system
|
|
||||||
platform.app->onInputEvent = AndroidInputCallback;
|
|
||||||
|
|
||||||
// Initialize assets manager
|
|
||||||
InitAssetManager(platform.app->activity->assetManager, platform.app->activity->internalDataPath);
|
|
||||||
|
|
||||||
// Initialize base path for storage
|
|
||||||
CORE.Storage.basePath = platform.app->activity->internalDataPath;
|
|
||||||
|
|
||||||
// Set some default window flags
|
// Set some default window flags
|
||||||
CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; // false
|
CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; // false
|
||||||
CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; // false
|
CORE.Window.flags &= ~FLAG_WINDOW_MINIMIZED; // false
|
||||||
CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; // true
|
CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; // true
|
||||||
CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; // false
|
CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; // false
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "PLATFORM: ANDROID: Application initialized successfully");
|
// Initialize App command system
|
||||||
|
// NOTE: On APP_CMD_INIT_WINDOW -> InitGraphicsDevice(), InitTimer(), LoadFontDefault()...
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
platform.app->onAppCmd = AndroidCommandCallback;
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Initialize input events system
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
platform.app->onInputEvent = AndroidInputCallback;
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Initialize storage system
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
InitAssetManager(platform.app->activity->assetManager, platform.app->activity->internalDataPath); // Initialize assets manager
|
||||||
|
|
||||||
|
CORE.Storage.basePath = platform.app->activity->internalDataPath; // Define base path for storage
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "PLATFORM: ANDROID: Initialized successfully");
|
||||||
|
|
||||||
// Android ALooper_pollAll() variables
|
// Android ALooper_pollAll() variables
|
||||||
int pollResult = 0;
|
int pollResult = 0;
|
||||||
|
@ -613,7 +621,6 @@ void ClosePlatform(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialize display device and framebuffer
|
// Initialize display device and framebuffer
|
||||||
// NOTE: width and height represent the screen (framebuffer) desired size, not actual display size
|
// NOTE: width and height represent the screen (framebuffer) desired size, not actual display size
|
||||||
// If width or height are 0, default display size will be used for framebuffer size
|
// If width or height are 0, default display size will be used for framebuffer size
|
||||||
|
|
|
@ -1236,6 +1236,8 @@ int InitPlatform(void)
|
||||||
int result = glfwInit();
|
int result = glfwInit();
|
||||||
if (result == GLFW_FALSE) { TRACELOG(LOG_WARNING, "GLFW: Failed to initialize GLFW"); return -1; }
|
if (result == GLFW_FALSE) { TRACELOG(LOG_WARNING, "GLFW: Failed to initialize GLFW"); return -1; }
|
||||||
|
|
||||||
|
// Initialize graphic device: display/window and graphic context
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
glfwDefaultWindowHints(); // Set default windows hints
|
glfwDefaultWindowHints(); // Set default windows hints
|
||||||
//glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits
|
//glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits
|
||||||
//glfwWindowHint(GLFW_GREEN_BITS, 8); // Framebuffer green color component bits
|
//glfwWindowHint(GLFW_GREEN_BITS, 8); // Framebuffer green color component bits
|
||||||
|
@ -1450,60 +1452,73 @@ int InitPlatform(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwMakeContextCurrent(platform.handle);
|
glfwMakeContextCurrent(platform.handle);
|
||||||
glfwSwapInterval(0); // No V-Sync by default
|
result = glfwGetError(NULL);
|
||||||
|
|
||||||
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
// Check context activation
|
||||||
// NOTE: V-Sync can be enabled by graphic driver configuration, it doesn't need
|
if ((result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR))
|
||||||
// to be activated on web platforms since VSync is enforced there.
|
|
||||||
if (CORE.Window.flags & FLAG_VSYNC_HINT)
|
|
||||||
{
|
{
|
||||||
// WARNING: It seems to hit a critical render path in Intel HD Graphics
|
CORE.Window.ready = true;
|
||||||
glfwSwapInterval(1);
|
|
||||||
TRACELOG(LOG_INFO, "DISPLAY: Trying to enable VSYNC");
|
glfwSwapInterval(0); // No V-Sync by default
|
||||||
|
|
||||||
|
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
||||||
|
// NOTE: V-Sync can be enabled by graphic driver configuration, it doesn't need
|
||||||
|
// to be activated on web platforms since VSync is enforced there.
|
||||||
|
if (CORE.Window.flags & FLAG_VSYNC_HINT)
|
||||||
|
{
|
||||||
|
// WARNING: It seems to hit a critical render path in Intel HD Graphics
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
TRACELOG(LOG_INFO, "DISPLAY: Trying to enable VSYNC");
|
||||||
|
}
|
||||||
|
|
||||||
|
int fbWidth = CORE.Window.screen.width;
|
||||||
|
int fbHeight = CORE.Window.screen.height;
|
||||||
|
|
||||||
|
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
|
||||||
|
{
|
||||||
|
// NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling.
|
||||||
|
// Framebuffer scaling should be activated with: glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE);
|
||||||
|
#if !defined(__APPLE__)
|
||||||
|
glfwGetFramebufferSize(platform.handle, &fbWidth, &fbHeight);
|
||||||
|
|
||||||
|
// Screen scaling matrix is required in case desired screen area is different from display area
|
||||||
|
CORE.Window.screenScale = MatrixScale((float)fbWidth/CORE.Window.screen.width, (float)fbHeight/CORE.Window.screen.height, 1.0f);
|
||||||
|
|
||||||
|
// Mouse input scaling for the new screen size
|
||||||
|
SetMouseScale((float)CORE.Window.screen.width/fbWidth, (float)CORE.Window.screen.height/fbHeight);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
CORE.Window.render.width = fbWidth;
|
||||||
|
CORE.Window.render.height = fbHeight;
|
||||||
|
CORE.Window.currentFbo.width = fbWidth;
|
||||||
|
CORE.Window.currentFbo.height = fbHeight;
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
|
||||||
|
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
|
||||||
|
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
|
||||||
|
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
||||||
|
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
int fbWidth = CORE.Window.screen.width;
|
{
|
||||||
int fbHeight = CORE.Window.screen.height;
|
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device");
|
||||||
|
return -1;
|
||||||
if ((CORE.Window.flags & FLAG_WINDOW_HIGHDPI) > 0)
|
|
||||||
{
|
|
||||||
// NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling.
|
|
||||||
// Framebuffer scaling should be activated with: glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_TRUE);
|
|
||||||
#if !defined(__APPLE__)
|
|
||||||
glfwGetFramebufferSize(platform.handle, &fbWidth, &fbHeight);
|
|
||||||
|
|
||||||
// Screen scaling matrix is required in case desired screen area is different from display area
|
|
||||||
CORE.Window.screenScale = MatrixScale((float)fbWidth/CORE.Window.screen.width, (float)fbHeight/CORE.Window.screen.height, 1.0f);
|
|
||||||
|
|
||||||
// Mouse input scaling for the new screen size
|
|
||||||
SetMouseScale((float)CORE.Window.screen.width/fbWidth, (float)CORE.Window.screen.height/fbHeight);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CORE.Window.render.width = fbWidth;
|
|
||||||
CORE.Window.render.height = fbHeight;
|
|
||||||
CORE.Window.currentFbo.width = fbWidth;
|
|
||||||
CORE.Window.currentFbo.height = fbHeight;
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
|
|
||||||
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
|
|
||||||
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
|
|
||||||
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
|
||||||
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
|
||||||
|
|
||||||
// Load OpenGL extensions
|
|
||||||
// NOTE: GL procedures address loader is required to load extensions
|
|
||||||
rlLoadExtensions(glfwGetProcAddress);
|
|
||||||
|
|
||||||
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow();
|
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow();
|
||||||
|
|
||||||
CORE.Window.ready = true; // TODO: Proper validation on windows/context creation
|
|
||||||
|
|
||||||
// If graphic device is no properly initialized, we end program
|
// If graphic device is no properly initialized, we end program
|
||||||
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
|
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
|
||||||
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor())/2 - CORE.Window.screen.width/2, GetMonitorHeight(GetCurrentMonitor())/2 - CORE.Window.screen.height/2);
|
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor())/2 - CORE.Window.screen.width/2, GetMonitorHeight(GetCurrentMonitor())/2 - CORE.Window.screen.height/2);
|
||||||
|
|
||||||
|
// Load OpenGL extensions
|
||||||
|
// NOTE: GL procedures address loader is required to load extensions
|
||||||
|
rlLoadExtensions(glfwGetProcAddress);
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Initialize input events callbacks
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
// Set window callback events
|
// Set window callback events
|
||||||
glfwSetWindowSizeCallback(platform.handle, WindowSizeCallback); // NOTE: Resizing not allowed by default!
|
glfwSetWindowSizeCallback(platform.handle, WindowSizeCallback); // NOTE: Resizing not allowed by default!
|
||||||
glfwSetWindowMaximizeCallback(platform.handle, WindowMaximizeCallback);
|
glfwSetWindowMaximizeCallback(platform.handle, WindowMaximizeCallback);
|
||||||
|
@ -1521,12 +1536,19 @@ int InitPlatform(void)
|
||||||
glfwSetJoystickCallback(JoystickCallback);
|
glfwSetJoystickCallback(JoystickCallback);
|
||||||
|
|
||||||
glfwSetInputMode(platform.handle, GLFW_LOCK_KEY_MODS, GLFW_TRUE); // Enable lock keys modifiers (CAPS, NUM)
|
glfwSetInputMode(platform.handle, GLFW_LOCK_KEY_MODS, GLFW_TRUE); // Enable lock keys modifiers (CAPS, NUM)
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize hi-res timer
|
// Initialize timming system
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
InitTimer();
|
InitTimer();
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
// Initialize base path for storage
|
|
||||||
|
// Initialize storage system
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
CORE.Storage.basePath = GetWorkingDirectory();
|
CORE.Storage.basePath = GetWorkingDirectory();
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (GLFW): Initialized successfully");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1542,7 +1564,6 @@ void ClosePlatform(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GLFW3 Error Callback, runs on GLFW3 error
|
// GLFW3 Error Callback, runs on GLFW3 error
|
||||||
static void ErrorCallback(int error, const char *description)
|
static void ErrorCallback(int error, const char *description)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1107,6 +1107,8 @@ int InitPlatform(void)
|
||||||
int result = SDL_Init(SDL_INIT_EVERYTHING);
|
int result = SDL_Init(SDL_INIT_EVERYTHING);
|
||||||
if (result < 0) { TRACELOG(LOG_WARNING, "SDL: Failed to initialize SDL"); return -1; }
|
if (result < 0) { TRACELOG(LOG_WARNING, "SDL: Failed to initialize SDL"); return -1; }
|
||||||
|
|
||||||
|
// Initialize graphic device: display/window and graphic context
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
flags |= SDL_WINDOW_SHOWN;
|
flags |= SDL_WINDOW_SHOWN;
|
||||||
flags |= SDL_WINDOW_OPENGL;
|
flags |= SDL_WINDOW_OPENGL;
|
||||||
|
@ -1143,6 +1145,7 @@ int InitPlatform(void)
|
||||||
//if ((CORE.Window.flags & FLAG_FULLSCREEN_DESKTOP) > 0) flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
//if ((CORE.Window.flags & FLAG_FULLSCREEN_DESKTOP) > 0) flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
|
|
||||||
// NOTE: Some OpenGL context attributes must be set before window creation
|
// NOTE: Some OpenGL context attributes must be set before window creation
|
||||||
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
@ -1170,7 +1173,7 @@ int InitPlatform(void)
|
||||||
{
|
{
|
||||||
CORE.Window.ready = true;
|
CORE.Window.ready = true;
|
||||||
|
|
||||||
SDL_DisplayMode displayMode;
|
SDL_DisplayMode displayMode = { 0 };
|
||||||
SDL_GetCurrentDisplayMode(GetCurrentMonitor(), &displayMode);
|
SDL_GetCurrentDisplayMode(GetCurrentMonitor(), &displayMode);
|
||||||
|
|
||||||
CORE.Window.display.width = displayMode.w;
|
CORE.Window.display.width = displayMode.w;
|
||||||
|
@ -1187,30 +1190,43 @@ int InitPlatform(void)
|
||||||
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
||||||
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
||||||
}
|
}
|
||||||
else { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
|
else
|
||||||
|
{
|
||||||
|
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Load OpenGL extensions
|
// Load OpenGL extensions
|
||||||
// NOTE: GL procedures address loader is required to load extensions
|
// NOTE: GL procedures address loader is required to load extensions
|
||||||
rlLoadExtensions(SDL_GL_GetProcAddress);
|
rlLoadExtensions(SDL_GL_GetProcAddress);
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Initialize input events system
|
||||||
// Init input gamepad
|
//----------------------------------------------------------------------------
|
||||||
if (SDL_NumJoysticks() >= 1)
|
if (SDL_NumJoysticks() >= 1)
|
||||||
{
|
{
|
||||||
SDL_Joystick *gamepad = SDL_JoystickOpen(0);
|
SDL_Joystick *gamepad = SDL_JoystickOpen(0);
|
||||||
//if (SDL_Joystick *gamepad == NULL) SDL_Log("WARNING: Unable to open game controller! SDL Error: %s\n", SDL_GetError());
|
//if (SDL_Joystick *gamepad == NULL) SDL_Log("WARNING: Unable to open game controller! SDL Error: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize hi-res timer
|
// Initialize timming system
|
||||||
//InitTimer();
|
//----------------------------------------------------------------------------
|
||||||
|
// NOTE: No need to call InitTimer(), let SDL manage it internally
|
||||||
CORE.Time.previous = GetTime(); // Get time as double
|
CORE.Time.previous = GetTime(); // Get time as double
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize base path for storage
|
// Initialize storage system
|
||||||
CORE.Storage.basePath = GetWorkingDirectory();
|
//----------------------------------------------------------------------------
|
||||||
|
CORE.Storage.basePath = GetWorkingDirectory(); // Define base path for storage
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "PLATFORM: DESKTOP (SDL): Initialized successfully");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close platform
|
||||||
void ClosePlatform(void)
|
void ClosePlatform(void)
|
||||||
{
|
{
|
||||||
SDL_FreeCursor(platform.cursor); // Free cursor
|
SDL_FreeCursor(platform.cursor); // Free cursor
|
||||||
|
@ -1219,7 +1235,7 @@ void ClosePlatform(void)
|
||||||
SDL_Quit(); // Deinitialize SDL internal global state
|
SDL_Quit(); // Deinitialize SDL internal global state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scancode to keycode mapping
|
||||||
static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode)
|
static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode)
|
||||||
{
|
{
|
||||||
if (sdlScancode >= 0 && sdlScancode < SCANCODE_MAPPED_NUM)
|
if (sdlScancode >= 0 && sdlScancode < SCANCODE_MAPPED_NUM)
|
||||||
|
|
|
@ -576,6 +576,8 @@ int InitPlatform(void)
|
||||||
platform.prevBO = NULL;
|
platform.prevBO = NULL;
|
||||||
platform.prevFB = 0;
|
platform.prevFB = 0;
|
||||||
|
|
||||||
|
// Initialize graphic device: display/window and graphic context
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
CORE.Window.fullscreen = true;
|
CORE.Window.fullscreen = true;
|
||||||
CORE.Window.flags |= FLAG_FULLSCREEN_MODE;
|
CORE.Window.flags |= FLAG_FULLSCREEN_MODE;
|
||||||
|
|
||||||
|
@ -846,7 +848,6 @@ int InitPlatform(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an EGL window surface
|
// Create an EGL window surface
|
||||||
//---------------------------------------------------------------------------------
|
|
||||||
platform.surface = eglCreateWindowSurface(platform.device, platform.config, (EGLNativeWindowType)platform.gbmSurface, NULL);
|
platform.surface = eglCreateWindowSurface(platform.device, platform.config, (EGLNativeWindowType)platform.gbmSurface, NULL);
|
||||||
if (EGL_NO_SURFACE == platform.surface)
|
if (EGL_NO_SURFACE == platform.surface)
|
||||||
{
|
{
|
||||||
|
@ -863,14 +864,14 @@ int InitPlatform(void)
|
||||||
|
|
||||||
// There must be at least one frame displayed before the buffers are swapped
|
// There must be at least one frame displayed before the buffers are swapped
|
||||||
//eglSwapInterval(platform.device, 1);
|
//eglSwapInterval(platform.device, 1);
|
||||||
|
|
||||||
|
EGLBoolean result = eglMakeCurrent(platform.device, platform.surface, platform.surface, platform.context);
|
||||||
|
|
||||||
if (eglMakeCurrent(platform.device, platform.surface, platform.surface, platform.context) == EGL_FALSE)
|
// Check surface and context activation
|
||||||
{
|
if (result != EGL_FALSE)
|
||||||
TRACELOG(LOG_WARNING, "DISPLAY: Failed to attach EGL rendering context to EGL surface");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
CORE.Window.ready = true;
|
||||||
|
|
||||||
CORE.Window.render.width = CORE.Window.screen.width;
|
CORE.Window.render.width = CORE.Window.screen.width;
|
||||||
CORE.Window.render.height = CORE.Window.screen.height;
|
CORE.Window.render.height = CORE.Window.screen.height;
|
||||||
CORE.Window.currentFbo.width = CORE.Window.render.width;
|
CORE.Window.currentFbo.width = CORE.Window.render.width;
|
||||||
|
@ -882,16 +883,15 @@ int InitPlatform(void)
|
||||||
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
||||||
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// Load OpenGL extensions
|
{
|
||||||
// NOTE: GL procedures address loader is required to load extensions
|
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device");
|
||||||
rlLoadExtensions(eglGetProcAddress);
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow();
|
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow();
|
||||||
|
|
||||||
CORE.Window.ready = true; // TODO: Proper validation on windows/context creation
|
// If graphic device is no properly initialized, we end program
|
||||||
|
|
||||||
// If graphic device is no properly initialized, we end program
|
|
||||||
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
|
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
|
||||||
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor()) / 2 - CORE.Window.screen.width / 2, GetMonitorHeight(GetCurrentMonitor()) / 2 - CORE.Window.screen.height / 2);
|
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor()) / 2 - CORE.Window.screen.width / 2, GetMonitorHeight(GetCurrentMonitor()) / 2 - CORE.Window.screen.height / 2);
|
||||||
|
|
||||||
|
@ -901,16 +901,29 @@ int InitPlatform(void)
|
||||||
CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; // true
|
CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; // true
|
||||||
CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; // false
|
CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED; // false
|
||||||
|
|
||||||
// Initialize hi-res timer
|
// Load OpenGL extensions
|
||||||
|
// NOTE: GL procedures address loader is required to load extensions
|
||||||
|
rlLoadExtensions(eglGetProcAddress);
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Initialize input events system
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
InitEvdevInput(); // Evdev inputs initialization
|
||||||
|
InitGamepad(); // Gamepad init
|
||||||
|
InitKeyboard(); // Keyboard init (stdin)
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Initialize timming system
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
InitTimer();
|
InitTimer();
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize base path for storage
|
// Initialize storage system
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
CORE.Storage.basePath = GetWorkingDirectory();
|
CORE.Storage.basePath = GetWorkingDirectory();
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
// Initialize raw input system
|
|
||||||
InitEvdevInput(); // Evdev inputs initialization
|
TRACELOG(LOG_INFO, "PLATFORM: DRM: Initialized successfully");
|
||||||
InitGamepad(); // Gamepad init
|
|
||||||
InitKeyboard(); // Keyboard init (stdin)
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1005,7 +1018,6 @@ void ClosePlatform(void)
|
||||||
if (platform.gamepadThreadId) pthread_join(platform.gamepadThreadId, NULL);
|
if (platform.gamepadThreadId) pthread_join(platform.gamepadThreadId, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialize Keyboard system (using standard input)
|
// Initialize Keyboard system (using standard input)
|
||||||
static void InitKeyboard(void)
|
static void InitKeyboard(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -518,13 +518,27 @@ int InitPlatform(void)
|
||||||
|
|
||||||
EGLBoolean result = eglMakeCurrent(platform.device, platform.surface, platform.surface, platform.context);
|
EGLBoolean result = eglMakeCurrent(platform.device, platform.surface, platform.surface, platform.context);
|
||||||
|
|
||||||
// Enabling current display surface and context failed
|
// Check surface and context activation
|
||||||
if (result == EGL_FALSE)
|
if (result != EGL_FALSE)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "DISPLAY: Failed to attach EGL rendering context to EGL surface");
|
CORE.Window.ready = true;
|
||||||
|
|
||||||
|
CORE.Window.render.width = CORE.Window.screen.width;
|
||||||
|
CORE.Window.render.height = CORE.Window.screen.height;
|
||||||
|
CORE.Window.currentFbo.width = CORE.Window.render.width;
|
||||||
|
CORE.Window.currentFbo.height = CORE.Window.render.height;
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
|
||||||
|
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
|
||||||
|
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
|
||||||
|
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
||||||
|
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else CORE.Window.ready = true;
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// If everything work as expected, we can continue
|
// If everything work as expected, we can continue
|
||||||
|
@ -545,7 +559,7 @@ int InitPlatform(void)
|
||||||
rlLoadExtensions(eglGetProcAddress);
|
rlLoadExtensions(eglGetProcAddress);
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// TODO: Initialize input system
|
// TODO: Initialize input events system
|
||||||
// It could imply keyboard, mouse, gamepad, touch...
|
// It could imply keyboard, mouse, gamepad, touch...
|
||||||
// Depending on the platform libraries/SDK it could use a callbacks mechanims
|
// Depending on the platform libraries/SDK it could use a callbacks mechanims
|
||||||
// For system events and inputs evens polling on a per-frame basis, use PollInputEvents()
|
// For system events and inputs evens polling on a per-frame basis, use PollInputEvents()
|
||||||
|
@ -553,15 +567,17 @@ int InitPlatform(void)
|
||||||
// ...
|
// ...
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// TODO: Initialize hi-res timer
|
// TODO: Initialize timming system
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
InitTimer();
|
InitTimer();
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// TODO: Initialize base path for storage
|
// TODO: Initialize storage system
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
CORE.Storage.basePath = GetWorkingDirectory();
|
CORE.Storage.basePath = GetWorkingDirectory();
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "PLATFORM: CUSTOM: Initialized successfully");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -677,6 +677,8 @@ int InitPlatform(void)
|
||||||
int result = glfwInit();
|
int result = glfwInit();
|
||||||
if (result == GLFW_FALSE) { TRACELOG(LOG_WARNING, "GLFW: Failed to initialize GLFW"); return -1; }
|
if (result == GLFW_FALSE) { TRACELOG(LOG_WARNING, "GLFW: Failed to initialize GLFW"); return -1; }
|
||||||
|
|
||||||
|
// Initialize graphic device: display/window and graphic context
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
glfwDefaultWindowHints(); // Set default windows hints
|
glfwDefaultWindowHints(); // Set default windows hints
|
||||||
// glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits
|
// glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits
|
||||||
// glfwWindowHint(GLFW_GREEN_BITS, 8); // Framebuffer green color component bits
|
// glfwWindowHint(GLFW_GREEN_BITS, 8); // Framebuffer green color component bits
|
||||||
|
@ -862,43 +864,46 @@ int InitPlatform(void)
|
||||||
glfwSetCursorEnterCallback(platform.handle, CursorEnterCallback);
|
glfwSetCursorEnterCallback(platform.handle, CursorEnterCallback);
|
||||||
|
|
||||||
glfwMakeContextCurrent(platform.handle);
|
glfwMakeContextCurrent(platform.handle);
|
||||||
|
result = glfwGetError(NULL);
|
||||||
|
|
||||||
|
// Check context activation
|
||||||
|
if ((result != GLFW_NO_WINDOW_CONTEXT) && (result != GLFW_PLATFORM_ERROR))
|
||||||
|
{
|
||||||
|
CORE.Window.ready = true; // TODO: Proper validation on windows/context creation
|
||||||
|
|
||||||
// Load OpenGL extensions
|
int fbWidth = CORE.Window.screen.width;
|
||||||
// NOTE: GL procedures address loader is required to load extensions
|
int fbHeight = CORE.Window.screen.height;
|
||||||
rlLoadExtensions(glfwGetProcAddress);
|
|
||||||
|
CORE.Window.render.width = fbWidth;
|
||||||
|
CORE.Window.render.height = fbHeight;
|
||||||
|
CORE.Window.currentFbo.width = fbWidth;
|
||||||
|
CORE.Window.currentFbo.height = fbHeight;
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
|
||||||
|
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
|
||||||
|
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
|
||||||
|
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
||||||
|
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphics device");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow();
|
if ((CORE.Window.flags & FLAG_WINDOW_MINIMIZED) > 0) MinimizeWindow();
|
||||||
|
|
||||||
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
|
||||||
// NOTE: V-Sync can be enabled by graphic driver configuration, it doesn't need
|
|
||||||
// to be activated on web platforms since VSync is enforced there.
|
|
||||||
|
|
||||||
int fbWidth = CORE.Window.screen.width;
|
|
||||||
int fbHeight = CORE.Window.screen.height;
|
|
||||||
|
|
||||||
CORE.Window.render.width = fbWidth;
|
|
||||||
CORE.Window.render.height = fbHeight;
|
|
||||||
CORE.Window.currentFbo.width = fbWidth;
|
|
||||||
CORE.Window.currentFbo.height = fbHeight;
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
|
|
||||||
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
|
|
||||||
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
|
|
||||||
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
|
||||||
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
|
||||||
|
|
||||||
CORE.Window.ready = true; // TODO: Proper validation on windows/context creation
|
|
||||||
|
|
||||||
// If graphic device is no properly initialized, we end program
|
// If graphic device is no properly initialized, we end program
|
||||||
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
|
if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; }
|
||||||
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor())/2 - CORE.Window.screen.width/2, GetMonitorHeight(GetCurrentMonitor())/2 - CORE.Window.screen.height/2);
|
else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor())/2 - CORE.Window.screen.width/2, GetMonitorHeight(GetCurrentMonitor())/2 - CORE.Window.screen.height/2);
|
||||||
|
|
||||||
// Initialize hi-res timer
|
// Load OpenGL extensions
|
||||||
InitTimer();
|
// NOTE: GL procedures address loader is required to load extensions
|
||||||
|
rlLoadExtensions(glfwGetProcAddress);
|
||||||
// Initialize base path for storage
|
//----------------------------------------------------------------------------
|
||||||
CORE.Storage.basePath = GetWorkingDirectory();
|
|
||||||
|
// Initialize input events callbacks
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
// Setup callback functions for the DOM events
|
// Setup callback functions for the DOM events
|
||||||
emscripten_set_fullscreenchange_callback("#canvas", NULL, 1, EmscriptenFullscreenChangeCallback);
|
emscripten_set_fullscreenchange_callback("#canvas", NULL, 1, EmscriptenFullscreenChangeCallback);
|
||||||
|
|
||||||
|
@ -927,6 +932,19 @@ int InitPlatform(void)
|
||||||
// Support gamepad events (not provided by GLFW3 on emscripten)
|
// Support gamepad events (not provided by GLFW3 on emscripten)
|
||||||
emscripten_set_gamepadconnected_callback(NULL, 1, EmscriptenGamepadCallback);
|
emscripten_set_gamepadconnected_callback(NULL, 1, EmscriptenGamepadCallback);
|
||||||
emscripten_set_gamepaddisconnected_callback(NULL, 1, EmscriptenGamepadCallback);
|
emscripten_set_gamepaddisconnected_callback(NULL, 1, EmscriptenGamepadCallback);
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Initialize timming system
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
InitTimer();
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Initialize storage system
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
CORE.Storage.basePath = GetWorkingDirectory();
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TRACELOG(LOG_INFO, "PLATFORM: WEB: Initialized successfully");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -938,7 +956,6 @@ void ClosePlatform(void)
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GLFW3 Error Callback, runs on GLFW3 error
|
// GLFW3 Error Callback, runs on GLFW3 error
|
||||||
static void ErrorCallback(int error, const char *description)
|
static void ErrorCallback(int error, const char *description)
|
||||||
{
|
{
|
||||||
|
|
|
@ -491,8 +491,6 @@ void InitWindow(int width, int height, const char *title)
|
||||||
|
|
||||||
// Initialize random seed
|
// Initialize random seed
|
||||||
SetRandomSeed((unsigned int)time(NULL));
|
SetRandomSeed((unsigned int)time(NULL));
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "PLATFORM: DESKTOP: Application initialized successfully");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close window and unload OpenGL context
|
// Close window and unload OpenGL context
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue