Torque3D/Engine/source/platformSDL/sdlPlatformGL.cpp

90 lines
2.1 KiB
C++
Raw Normal View History

2015-01-16 19:37:16 +00:00
#include <SDL.h>
#include "windowManager/sdl/sdlWindow.h"
#include "console/console.h"
2016-03-26 01:11:42 +00:00
#ifdef TORQUE_OS_WIN
#include "gfx/gl/tGL/tWGL.h"
#endif
2016-12-23 03:59:55 +00:00
#include "gfx/gl/gfxGLUtils.h"
2015-01-16 19:37:16 +00:00
namespace PlatformGL
{
void init()
{
const U32 majorOGL = 3;
2015-01-16 19:37:16 +00:00
const U32 minorOGL = 2;
U32 debugFlag = 0;
#ifdef TORQUE_DEBUG
debugFlag |= SDL_GL_CONTEXT_DEBUG_FLAG;
#endif
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorOGL);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorOGL);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, debugFlag);
2016-09-28 01:09:48 +00:00
#ifdef TORQUE_GL_SOFTWARE
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 0);
#endif
2015-01-16 19:37:16 +00:00
SDL_ClearError();
}
void* CreateContextGL( PlatformWindow *window )
{
init();
PlatformWindowSDL* windowSdl = dynamic_cast<PlatformWindowSDL*>(window);
AssertFatal(windowSdl, "");
if( !windowSdl )
return NULL;
SDL_ClearError();
SDL_GLContext ctx = SDL_GL_CreateContext( windowSdl->getSDLWindow() );
if( !ctx )
{
const char *err = SDL_GetError();
Con::printf( err );
AssertFatal(0, err );
}
return ctx;
}
void MakeCurrentGL( PlatformWindow *window, void *glContext )
{
PlatformWindowSDL* windowSdl = dynamic_cast<PlatformWindowSDL*>(window);
AssertFatal( windowSdl && glContext, "" );
SDL_ClearError();
SDL_GL_MakeCurrent( windowSdl->getSDLWindow(), glContext );
const char *err = SDL_GetError();
if( err && err[0] )
{
Con::printf( err );
AssertFatal(0, err );
}
}
void setVSync(const int i)
{
2016-12-23 03:59:55 +00:00
PRESERVE_FRAMEBUFFER();
// Nvidia needs to have the default framebuffer bound or the vsync calls fail
glBindFramebuffer(GL_FRAMEBUFFER, 0);
2015-01-16 19:37:16 +00:00
if( i == 1 || i == -1 )
{
int ret = SDL_GL_SetSwapInterval(-1);
if( ret == -1)
SDL_GL_SetSwapInterval(1);
}
else
SDL_GL_SetSwapInterval(0);
2016-12-23 03:59:55 +00:00
2015-01-16 19:37:16 +00:00
}
}