Torque3D Documentation / _generateds / sdlPlatformGL.cpp

sdlPlatformGL.cpp

Engine/source/platformSDL/sdlPlatformGL.cpp

More...

Namespaces:

namespace

Detailed Description

 1
 2#include <SDL.h>
 3#include "windowManager/sdl/sdlWindow.h"
 4#include "console/console.h"
 5
 6#ifdef TORQUE_OS_WIN
 7#include "gfx/gl/tGL/tWGL.h"
 8#endif
 9
10#include "gfx/gl/gfxGLUtils.h"
11
12namespace PlatformGL
13{
14
15   void init()
16   {
17       const U32 majorOGL = 3;
18       const U32 minorOGL = 3;
19       U32 debugFlag = 0;
20#ifdef TORQUE_DEBUG
21       debugFlag |= SDL_GL_CONTEXT_DEBUG_FLAG;
22#endif
23
24       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorOGL);
25       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorOGL);
26       SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
27       SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, debugFlag);
28       SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);
29#ifdef TORQUE_GL_SOFTWARE
30       SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 0);
31#endif
32
33       SDL_ClearError();
34   }
35
36   void* CreateContextGL( PlatformWindow *window )
37   {
38       init();
39
40       PlatformWindowSDL* windowSdl = dynamic_cast<PlatformWindowSDL*>(window);
41       AssertFatal(windowSdl, "");
42
43       if( !windowSdl )
44           return NULL;
45
46       SDL_ClearError();
47       SDL_GLContext ctx = SDL_GL_CreateContext( windowSdl->getSDLWindow() );
48       if( !ctx )
49       {
50           const char *err = SDL_GetError();
51           Con::printf( err );
52           AssertFatal(0, err );
53       }
54
55       return ctx;
56   }
57
58   void MakeCurrentGL( PlatformWindow *window, void *glContext )
59   {
60       PlatformWindowSDL* windowSdl = dynamic_cast<PlatformWindowSDL*>(window);
61       AssertFatal( windowSdl && glContext, "" );
62
63       SDL_ClearError();
64       SDL_GL_MakeCurrent( windowSdl->getSDLWindow(), glContext );
65
66       const char *err = SDL_GetError();
67       if( err && err[0] )
68       {
69           Con::printf( err );
70           AssertFatal(0, err );
71       }
72   }
73
74   void setVSync(const int i)
75   {
76      PRESERVE_FRAMEBUFFER();
77      // Nvidia needs to have the default framebuffer bound or the vsync calls fail
78      glBindFramebuffer(GL_FRAMEBUFFER, 0);
79       if( i == 1 || i == -1 )
80       {
81           int ret = SDL_GL_SetSwapInterval(-1);
82
83           if( ret == -1)
84               SDL_GL_SetSwapInterval(1);
85       }
86       else
87           SDL_GL_SetSwapInterval(0);
88
89   }
90
91}
92