Mercurial > hg > orthanc-stone
comparison Applications/Sdl/SdlOpenGLContext.cpp @ 947:1091b2adeb5a toa2019081001
Fixed animation frame stopping when returning false + big work on the OpenGL
objects to make them lost context-safe + debug code to forcefully tag a
context as lost + debug macros
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Sat, 10 Aug 2019 13:07:31 +0200 |
parents | 0aff28f15ea2 |
children | a7351ad54960 |
comparison
equal
deleted
inserted
replaced
946:dbe3e1e47019 | 947:1091b2adeb5a |
---|---|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #include "SdlOpenGLContext.h" | 22 #include "SdlOpenGLContext.h" |
23 #include "../../Framework/StoneException.h" | |
23 | 24 |
24 #if ORTHANC_ENABLE_SDL == 1 | 25 #if ORTHANC_ENABLE_SDL == 1 |
25 | 26 |
26 #if !defined(ORTHANC_ENABLE_GLEW) | 27 #if !defined(ORTHANC_ENABLE_GLEW) |
27 # error Macro ORTHANC_ENABLE_GLEW must be defined | 28 # error Macro ORTHANC_ENABLE_GLEW must be defined |
36 namespace OrthancStone | 37 namespace OrthancStone |
37 { | 38 { |
38 SdlOpenGLContext::SdlOpenGLContext(const char* title, | 39 SdlOpenGLContext::SdlOpenGLContext(const char* title, |
39 unsigned int width, | 40 unsigned int width, |
40 unsigned int height, | 41 unsigned int height, |
41 bool allowDpiScaling) : | 42 bool allowDpiScaling) |
42 window_(title, width, height, true /* enable OpenGL */, allowDpiScaling) | 43 : window_(title, width, height, true /* enable OpenGL */, allowDpiScaling) |
44 , context_(NULL) | |
45 , contextLost_(false) | |
43 { | 46 { |
44 context_ = SDL_GL_CreateContext(window_.GetObject()); | 47 context_ = SDL_GL_CreateContext(window_.GetObject()); |
45 | 48 |
46 if (context_ == NULL) | 49 if (context_ == NULL) |
47 { | 50 { |
81 { | 84 { |
82 SDL_GL_DeleteContext(context_); | 85 SDL_GL_DeleteContext(context_); |
83 } | 86 } |
84 | 87 |
85 | 88 |
89 bool SdlOpenGLContext::IsContextLost() const | |
90 { | |
91 return contextLost_; | |
92 } | |
93 | |
94 | |
95 void SdlOpenGLContext::SetLostContext() | |
96 { | |
97 contextLost_ = true; | |
98 } | |
99 | |
100 void SdlOpenGLContext::RestoreLostContext() | |
101 { | |
102 contextLost_ = false; | |
103 } | |
104 | |
105 // extern bool Debug_MustContextBeKilled(std::string title); | |
106 // extern void Debug_Context_ClearKillFlag(std::string title); | |
107 | |
86 void SdlOpenGLContext::MakeCurrent() | 108 void SdlOpenGLContext::MakeCurrent() |
87 { | 109 { |
110 if (IsContextLost()) | |
111 throw OpenGLContextLostException(context_); | |
112 | |
113 // <DEBUG STUFF> | |
114 // This is used for context loss simulation | |
115 // SDL_Window* internalWindow = GetWindow().GetObject(); | |
116 // std::string title(SDL_GetWindowTitle(internalWindow)); | |
117 | |
118 // if (Debug_MustContextBeKilled(title)) | |
119 // { | |
120 // Debug_Context_ClearKillFlag(title); | |
121 // SetLostContext(); | |
122 // throw OpenGLContextLostException(context_); | |
123 // } | |
124 // </DEBUG STUFF> | |
125 | |
88 if (SDL_GL_MakeCurrent(window_.GetObject(), context_) != 0) | 126 if (SDL_GL_MakeCurrent(window_.GetObject(), context_) != 0) |
89 { | 127 { |
90 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, | 128 const char* errText = SDL_GetError(); |
91 "Cannot set current OpenGL context"); | 129 std::stringstream ss; |
130 ss << "Cannot set current OpenGL context. SDL error text: " << errText; | |
131 std::string errStr = ss.str(); | |
132 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, errStr.c_str()); | |
92 } | 133 } |
93 | 134 |
94 // This makes our buffer swap syncronized with the monitor's vertical refresh | 135 // This makes our buffer swap synchronized with the monitor's vertical refresh |
95 SDL_GL_SetSwapInterval(1); | 136 SDL_GL_SetSwapInterval(1); |
96 } | 137 } |
97 | 138 |
98 | 139 |
99 void SdlOpenGLContext::SwapBuffer() | 140 void SdlOpenGLContext::SwapBuffer() |