impl sdl platform
This commit is contained in:
parent
88c24f8de7
commit
b9cfbebd40
|
|
@ -54,11 +54,13 @@
|
|||
#endif
|
||||
#include "SDL.h" // SDL base library (window/rendered, input, timing... functionality)
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
#if !defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// It seems it does not need to be included to work
|
||||
//#include "SDL_opengles2.h"
|
||||
#else
|
||||
#else
|
||||
#include "SDL_opengl.h" // SDL OpenGL functionality (if required, instead of internal renderer)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -1215,7 +1217,14 @@ void DisableCursor(void)
|
|||
// Swap back buffer with front buffer (screen drawing)
|
||||
void SwapScreenBuffer(void)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||
// NOTE: We use a preprocessor condition here because `rlCopyFramebuffer` is only declared for software rendering
|
||||
SDL_Surface* surface = SDL_GetWindowSurface(platform.window);
|
||||
rlCopyFramebuffer(0, 0, CORE.Window.render.width, CORE.Window.render.height, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, surface->pixels);
|
||||
SDL_UpdateWindowSurface(platform.window);
|
||||
#else
|
||||
SDL_GL_SwapWindow(platform.window);
|
||||
#endif
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -1895,7 +1904,6 @@ int InitPlatform(void)
|
|||
//----------------------------------------------------------------------------
|
||||
unsigned int flags = 0;
|
||||
flags |= SDL_WINDOW_SHOWN;
|
||||
flags |= SDL_WINDOW_OPENGL;
|
||||
flags |= SDL_WINDOW_INPUT_FOCUS;
|
||||
flags |= SDL_WINDOW_MOUSE_FOCUS;
|
||||
flags |= SDL_WINDOW_MOUSE_CAPTURE; // Window has mouse captured
|
||||
|
|
@ -1930,6 +1938,11 @@ int InitPlatform(void)
|
|||
|
||||
// NOTE: Some OpenGL context attributes must be set before window creation
|
||||
|
||||
if (rlGetVersion() != RL_OPENGL_11_SOFTWARE)
|
||||
{
|
||||
// Add the flag telling the window to use an OpenGL context
|
||||
flags |= SDL_WINDOW_OPENGL;
|
||||
|
||||
// Check selection OpenGL version
|
||||
if (rlGetVersion() == RL_OPENGL_21)
|
||||
{
|
||||
|
|
@ -1947,9 +1960,9 @@ int InitPlatform(void)
|
|||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
#if defined(RLGL_ENABLE_OPENGL_DEBUG_CONTEXT)
|
||||
#if defined(RLGL_ENABLE_OPENGL_DEBUG_CONTEXT)
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); // Enable OpenGL Debug Context
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
else if (rlGetVersion() == RL_OPENGL_ES_20) // Request OpenGL ES 2.0 context
|
||||
{
|
||||
|
|
@ -1969,6 +1982,7 @@ int InitPlatform(void)
|
|||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
|
||||
}
|
||||
}
|
||||
|
||||
// Init window
|
||||
#if defined(PLATFORM_DESKTOP_SDL3)
|
||||
|
|
@ -1978,10 +1992,12 @@ int InitPlatform(void)
|
|||
#endif
|
||||
|
||||
// Init OpenGL context
|
||||
if (rlGetVersion() != RL_OPENGL_11_SOFTWARE)
|
||||
{
|
||||
platform.glContext = SDL_GL_CreateContext(platform.window);
|
||||
}
|
||||
|
||||
// Check window and glContext have been initialized successfully
|
||||
if ((platform.window != NULL) && (platform.glContext != NULL))
|
||||
if ((platform.window != NULL) && ((rlGetVersion() == RL_OPENGL_11_SOFTWARE) || (platform.glContext != NULL)))
|
||||
{
|
||||
CORE.Window.ready = true;
|
||||
|
||||
|
|
@ -2002,8 +2018,14 @@ int InitPlatform(void)
|
|||
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);
|
||||
|
||||
if (CORE.Window.flags & FLAG_VSYNC_HINT) SDL_GL_SetSwapInterval(1);
|
||||
else SDL_GL_SetSwapInterval(0);
|
||||
if (platform.glContext != NULL)
|
||||
{
|
||||
SDL_GL_SetSwapInterval((CORE.Window.flags & FLAG_VSYNC_HINT)? 1 : 0);
|
||||
|
||||
// Load OpenGL extensions
|
||||
// NOTE: GL procedures address loader is required to load extensions
|
||||
rlLoadExtensions(SDL_GL_GetProcAddress);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -2011,9 +2033,6 @@ int InitPlatform(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
// Load OpenGL extensions
|
||||
// NOTE: GL procedures address loader is required to load extensions
|
||||
rlLoadExtensions(SDL_GL_GetProcAddress);
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// Initialize input events system
|
||||
|
|
@ -2078,7 +2097,7 @@ int InitPlatform(void)
|
|||
void ClosePlatform(void)
|
||||
{
|
||||
SDL_FreeCursor(platform.cursor); // Free cursor
|
||||
SDL_GL_DeleteContext(platform.glContext); // Deinitialize OpenGL context
|
||||
if (platform.glContext != NULL) SDL_GL_DeleteContext(platform.glContext); // Deinitialize OpenGL context
|
||||
SDL_DestroyWindow(platform.window);
|
||||
SDL_Quit(); // Deinitialize SDL internal global state
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user