impl sdl platform
This commit is contained in:
parent
88c24f8de7
commit
b9cfbebd40
|
|
@ -54,11 +54,13 @@
|
||||||
#endif
|
#endif
|
||||||
#include "SDL.h" // SDL base library (window/rendered, input, timing... functionality)
|
#include "SDL.h" // SDL base library (window/rendered, input, timing... functionality)
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
#if !defined(GRAPHICS_API_OPENGL_11_SOFTWARE)
|
||||||
// It seems it does not need to be included to work
|
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
//#include "SDL_opengles2.h"
|
// It seems it does not need to be included to work
|
||||||
#else
|
//#include "SDL_opengles2.h"
|
||||||
#include "SDL_opengl.h" // SDL OpenGL functionality (if required, instead of internal renderer)
|
#else
|
||||||
|
#include "SDL_opengl.h" // SDL OpenGL functionality (if required, instead of internal renderer)
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -1215,7 +1217,14 @@ void DisableCursor(void)
|
||||||
// Swap back buffer with front buffer (screen drawing)
|
// Swap back buffer with front buffer (screen drawing)
|
||||||
void SwapScreenBuffer(void)
|
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);
|
SDL_GL_SwapWindow(platform.window);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -1895,7 +1904,6 @@ int InitPlatform(void)
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
flags |= SDL_WINDOW_SHOWN;
|
flags |= SDL_WINDOW_SHOWN;
|
||||||
flags |= SDL_WINDOW_OPENGL;
|
|
||||||
flags |= SDL_WINDOW_INPUT_FOCUS;
|
flags |= SDL_WINDOW_INPUT_FOCUS;
|
||||||
flags |= SDL_WINDOW_MOUSE_FOCUS;
|
flags |= SDL_WINDOW_MOUSE_FOCUS;
|
||||||
flags |= SDL_WINDOW_MOUSE_CAPTURE; // Window has mouse captured
|
flags |= SDL_WINDOW_MOUSE_CAPTURE; // Window has mouse captured
|
||||||
|
|
@ -1930,44 +1938,50 @@ int InitPlatform(void)
|
||||||
|
|
||||||
// NOTE: Some OpenGL context attributes must be set before window creation
|
// NOTE: Some OpenGL context attributes must be set before window creation
|
||||||
|
|
||||||
// Check selection OpenGL version
|
if (rlGetVersion() != RL_OPENGL_11_SOFTWARE)
|
||||||
if (rlGetVersion() == RL_OPENGL_21)
|
|
||||||
{
|
{
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
// Add the flag telling the window to use an OpenGL context
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
flags |= SDL_WINDOW_OPENGL;
|
||||||
}
|
|
||||||
else if (rlGetVersion() == RL_OPENGL_33)
|
|
||||||
{
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
|
||||||
}
|
|
||||||
else if (rlGetVersion() == RL_OPENGL_43)
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); // Enable OpenGL Debug Context
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else if (rlGetVersion() == RL_OPENGL_ES_20) // Request OpenGL ES 2.0 context
|
|
||||||
{
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
||||||
}
|
|
||||||
else if (rlGetVersion() == RL_OPENGL_ES_30) // Request OpenGL ES 3.0 context
|
|
||||||
{
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CORE.Window.flags & FLAG_MSAA_4X_HINT)
|
// Check selection OpenGL version
|
||||||
{
|
if (rlGetVersion() == RL_OPENGL_21)
|
||||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
{
|
||||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
||||||
|
}
|
||||||
|
else if (rlGetVersion() == RL_OPENGL_33)
|
||||||
|
{
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
}
|
||||||
|
else if (rlGetVersion() == RL_OPENGL_43)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); // Enable OpenGL Debug Context
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (rlGetVersion() == RL_OPENGL_ES_20) // Request OpenGL ES 2.0 context
|
||||||
|
{
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||||
|
}
|
||||||
|
else if (rlGetVersion() == RL_OPENGL_ES_30) // Request OpenGL ES 3.0 context
|
||||||
|
{
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CORE.Window.flags & FLAG_MSAA_4X_HINT)
|
||||||
|
{
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init window
|
// Init window
|
||||||
|
|
@ -1978,10 +1992,12 @@ int InitPlatform(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Init OpenGL context
|
// Init OpenGL context
|
||||||
platform.glContext = SDL_GL_CreateContext(platform.window);
|
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) && ((rlGetVersion() == RL_OPENGL_11_SOFTWARE) || (platform.glContext != NULL)))
|
||||||
if ((platform.window != NULL) && (platform.glContext != NULL))
|
|
||||||
{
|
{
|
||||||
CORE.Window.ready = true;
|
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, " > 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);
|
||||||
|
|
||||||
if (CORE.Window.flags & FLAG_VSYNC_HINT) SDL_GL_SetSwapInterval(1);
|
if (platform.glContext != NULL)
|
||||||
else SDL_GL_SetSwapInterval(0);
|
{
|
||||||
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -2011,9 +2033,6 @@ int InitPlatform(void)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load OpenGL extensions
|
|
||||||
// NOTE: GL procedures address loader is required to load extensions
|
|
||||||
rlLoadExtensions(SDL_GL_GetProcAddress);
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Initialize input events system
|
// Initialize input events system
|
||||||
|
|
@ -2078,7 +2097,7 @@ int InitPlatform(void)
|
||||||
void ClosePlatform(void)
|
void ClosePlatform(void)
|
||||||
{
|
{
|
||||||
SDL_FreeCursor(platform.cursor); // Free cursor
|
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_DestroyWindow(platform.window);
|
||||||
SDL_Quit(); // Deinitialize SDL internal global state
|
SDL_Quit(); // Deinitialize SDL internal global state
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user