Bladeren bron

REVIEWED: New platform backend template comments

pull/3452/head
Ray 1 jaar geleden
bovenliggende
commit
1aad6a2fc0
1 gewijzigde bestanden met toevoegingen van 46 en 35 verwijderingen
  1. +46
    -35
      src/platforms/rcore_template.c

+ 46
- 35
src/platforms/rcore_template.c Bestand weergeven

@ -431,6 +431,12 @@ void PollInputEvents(void)
// Initialize platform: graphics, inputs and more
int InitPlatform(void)
{
// TODO: Initialize graphic device: display/window
// It usually requires setting up the platform display system configuration
// and connexion with the GPU through some system graphic API
// raylib uses OpenGL so, platform should create that kind of connection
// Below example illustrates that process using EGL library
//----------------------------------------------------------------------------
CORE.Window.fullscreen = true;
CORE.Window.flags |= FLAG_FULLSCREEN_MODE;
@ -496,61 +502,66 @@ int InitPlatform(void)
}
// Create an EGL window surface
//---------------------------------------------------------------------------------
EGLint displayFormat = 0;
// EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is guaranteed to be accepted by ANativeWindow_setBuffersGeometry()
// As soon as we picked a EGLConfig, we can safely reconfigure the ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID
eglGetConfigAttrib(platform.device, platform.config, EGL_NATIVE_VISUAL_ID, &displayFormat);
// At this point we need to manage render size vs screen size
// NOTE: This function use and modify global module variables:
// -> CORE.Window.screen.width/CORE.Window.screen.height
// -> CORE.Window.render.width/CORE.Window.render.height
// -> CORE.Window.screenScale
SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height);
ANativeWindow_setBuffersGeometry(platform.app->window, CORE.Window.render.width, CORE.Window.render.height, displayFormat);
//ANativeWindow_setBuffersGeometry(platform.app->window, 0, 0, displayFormat); // Force use of native display size
// Android specific call
ANativeWindow_setBuffersGeometry(platform.app->window, 0, 0, displayFormat); // Force use of native display size
platform.surface = eglCreateWindowSurface(platform.device, platform.config, platform.app->window, NULL);
// 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)
// Enabling current display surface and context failed
if (result == EGL_FALSE)
{
TRACELOG(LOG_WARNING, "DISPLAY: Failed to attach EGL rendering context to EGL surface");
return -1;
}
else
{
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);
}
// Load OpenGL extensions
else CORE.Window.ready = true;
//----------------------------------------------------------------------------
// If everything work as expected, we can continue
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);
// TODO: Load OpenGL extensions
// NOTE: GL procedures address loader is required to load extensions
//----------------------------------------------------------------------------
rlLoadExtensions(eglGetProcAddress);
CORE.Window.ready = true;
// 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; }
// Initialize hi-res timer
//----------------------------------------------------------------------------
// TODO: Initialize input system
// It could imply keyboard, mouse, gamepad, touch...
// 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()
//----------------------------------------------------------------------------
// ...
//----------------------------------------------------------------------------
// TODO: Initialize hi-res timer
//----------------------------------------------------------------------------
InitTimer();
//----------------------------------------------------------------------------
// Initialize base path for storage
// TODO: Initialize base path for storage
//----------------------------------------------------------------------------
CORE.Storage.basePath = GetWorkingDirectory();
//----------------------------------------------------------------------------
return 0;
}

Laden…
Annuleren
Opslaan