26
26
#include " DebugOutput.h"
27
27
28
28
#ifndef MAGNUM_TARGET_WEBGL
29
+ #include < Corrade/Containers/StringView.h>
29
30
#include < Corrade/Utility/Assert.h>
30
31
#include < Corrade/Utility/Debug.h>
31
- #include < Corrade/Utility/DebugStl.h>
32
32
33
33
#include " Magnum/GL/Context.h"
34
34
#include " Magnum/GL/Extensions.h"
35
35
#include " Magnum/GL/Implementation/State.h"
36
36
#include " Magnum/GL/Implementation/DebugState.h"
37
+ #include " Magnum/GL/Implementation/defaultDebugCallback.h"
38
+
39
+ #ifdef MAGNUM_BUILD_DEPRECATED
40
+ #include < string>
41
+ #endif
37
42
38
43
namespace Magnum { namespace GL {
39
44
40
45
namespace Implementation {
41
46
42
- void defaultDebugCallback (const DebugOutput::Source source, const DebugOutput::Type type, const UnsignedInt id, const DebugOutput::Severity severity, const std::string& string, std::ostream* out) {
47
+ void defaultDebugCallback (const DebugOutput::Source source, const DebugOutput::Type type, const UnsignedInt id, const DebugOutput::Severity severity, const Containers::StringView string, std::ostream* out) {
43
48
Debug output{out};
44
49
output << " Debug output:" ;
45
50
@@ -105,7 +110,7 @@ APIENTRY
105
110
#endif
106
111
callbackWrapper (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void * userParam) {
107
112
const auto & callback = *static_cast <const Implementation::DebugState::MessageCallback*>(userParam);
108
- callback.callback (DebugOutput::Source (source), DebugOutput::Type (type), id, DebugOutput::Severity (severity), std::string {message, std::size_t (length)}, callback.userParam );
113
+ callback.callback (DebugOutput::Source (source), DebugOutput::Type (type), id, DebugOutput::Severity (severity), {message, std::size_t (length)}, callback.userParam );
109
114
}
110
115
111
116
}
@@ -149,8 +154,25 @@ void DebugOutput::setCallback(const Callback callback, const void* userParam) {
149
154
Context::current ().state ().debug .callbackImplementation (callback);
150
155
}
151
156
157
+ #ifdef MAGNUM_BUILD_DEPRECATED
158
+ void DebugOutput::setCallback (void (*const callback)(Source, Type, UnsignedInt, Severity, const std::string&, const void *), const void* userParam) {
159
+ /* This is a second delegation step after the callbackWrapper() which
160
+ converts from raw GL types. Alternatively there could be a deprecated
161
+ version of all callbackImplementation*() variants, but this is less
162
+ code in total -- just two extra members in the MessageCallback
163
+ struct. */
164
+ Context::current ().state ().debug .messageCallback .userParam = &Context::current ().state ().debug .messageCallback ;
165
+ Context::current ().state ().debug .messageCallback .callbackStlString = callback;
166
+ Context::current ().state ().debug .messageCallback .userParamStlString = userParam;
167
+ Context::current ().state ().debug .callbackImplementation ([](DebugOutput::Source source, DebugOutput::Type type, UnsignedInt id, DebugOutput::Severity severity, const Containers::StringView string, const void * userParam) {
168
+ const auto & messageCallback = *static_cast <const Implementation::DebugState::MessageCallback*>(userParam);
169
+ messageCallback.callbackStlString (source, type, id, severity, string, messageCallback.userParamStlString );
170
+ });
171
+ }
172
+ #endif
173
+
152
174
void DebugOutput::setDefaultCallback () {
153
- setCallback ([](DebugOutput::Source source, DebugOutput::Type type, UnsignedInt id, DebugOutput::Severity severity, const std::string& string, const void *) {
175
+ setCallback ([](DebugOutput::Source source, DebugOutput::Type type, UnsignedInt id, DebugOutput::Severity severity, const Containers::StringView string, const void *) {
154
176
Implementation::defaultDebugCallback (source, type, id, severity, string, Debug::output ());
155
177
});
156
178
}
@@ -267,30 +289,30 @@ Debug& operator<<(Debug& debug, const DebugOutput::Severity value) {
267
289
}
268
290
#endif
269
291
270
- void DebugMessage::insertInternal (const Source source, const Type type, const UnsignedInt id, const DebugOutput::Severity severity, const Containers::ArrayView< const char > string) {
292
+ void DebugMessage::insert (const Source source, const Type type, const UnsignedInt id, const DebugOutput::Severity severity, const Containers::StringView string) {
271
293
Context::current ().state ().debug .messageInsertImplementation (source, type, id, severity, string);
272
294
}
273
295
274
- void DebugMessage::insertImplementationNoOp (Source, Type, UnsignedInt, DebugOutput::Severity, const Containers::ArrayView< const char > ) {}
296
+ void DebugMessage::insertImplementationNoOp (Source, Type, UnsignedInt, DebugOutput::Severity, const Containers::StringView ) {}
275
297
276
298
#ifndef MAGNUM_TARGET_GLES2
277
- void DebugMessage::insertImplementationKhrDesktopES32 (const Source source, const Type type, const UnsignedInt id, const DebugOutput::Severity severity, const Containers::ArrayView< const char > string) {
299
+ void DebugMessage::insertImplementationKhrDesktopES32 (const Source source, const Type type, const UnsignedInt id, const DebugOutput::Severity severity, const Containers::StringView string) {
278
300
glDebugMessageInsert (GLenum (source), GLenum (type), id, GLenum (severity), string.size (), string.data ());
279
301
}
280
302
#endif
281
303
282
304
#ifdef MAGNUM_TARGET_GLES
283
- void DebugMessage::insertImplementationKhrES (const Source source, const Type type, const UnsignedInt id, const DebugOutput::Severity severity, const Containers::ArrayView< const char > string) {
305
+ void DebugMessage::insertImplementationKhrES (const Source source, const Type type, const UnsignedInt id, const DebugOutput::Severity severity, const Containers::StringView string) {
284
306
glDebugMessageInsertKHR (GLenum (source), GLenum (type), id, GLenum (severity), string.size (), string.data ());
285
307
}
286
308
#endif
287
309
288
- void DebugMessage::insertImplementationExt (Source, Type, UnsignedInt, DebugOutput::Severity, const Containers::ArrayView< const char > string) {
310
+ void DebugMessage::insertImplementationExt (Source, Type, UnsignedInt, DebugOutput::Severity, const Containers::StringView string) {
289
311
glInsertEventMarkerEXT (string.size (), string.data ());
290
312
}
291
313
292
314
#ifndef MAGNUM_TARGET_GLES
293
- void DebugMessage::insertImplementationGremedy (Source, Type, UnsignedInt, DebugOutput::Severity, const Containers::ArrayView< const char > string) {
315
+ void DebugMessage::insertImplementationGremedy (Source, Type, UnsignedInt, DebugOutput::Severity, const Containers::StringView string) {
294
316
glStringMarkerGREMEDY (string.size (), string.data ());
295
317
}
296
318
#endif
@@ -347,7 +369,11 @@ Int DebugGroup::maxStackDepth() {
347
369
return value;
348
370
}
349
371
350
- void DebugGroup::pushInternal (const Source source, const UnsignedInt id, const Containers::ArrayView<const char > message) {
372
+ DebugGroup::DebugGroup (const Source source, const UnsignedInt id, const Containers::StringView message): DebugGroup{} {
373
+ push (source, id, message);
374
+ }
375
+
376
+ void DebugGroup::push (const Source source, const UnsignedInt id, const Containers::StringView message) {
351
377
CORRADE_ASSERT (!_active, " GL::DebugGroup::push(): group is already active" , );
352
378
Context::current ().state ().debug .pushGroupImplementation (source, id, message);
353
379
_active = true ;
@@ -359,21 +385,21 @@ void DebugGroup::pop() {
359
385
_active = false ;
360
386
}
361
387
362
- void DebugGroup::pushImplementationNoOp (Source, UnsignedInt, Containers::ArrayView< const char > ) {}
388
+ void DebugGroup::pushImplementationNoOp (Source, UnsignedInt, Containers::StringView ) {}
363
389
364
390
#ifndef MAGNUM_TARGET_GLES2
365
- void DebugGroup::pushImplementationKhrDesktopES32 (const Source source, const UnsignedInt id, const Containers::ArrayView< const char > message) {
391
+ void DebugGroup::pushImplementationKhrDesktopES32 (const Source source, const UnsignedInt id, const Containers::StringView message) {
366
392
glPushDebugGroup (GLenum (source), id, message.size (), message.data ());
367
393
}
368
394
#endif
369
395
370
396
#ifdef MAGNUM_TARGET_GLES
371
- void DebugGroup::pushImplementationKhrES (const Source source, const UnsignedInt id, const Containers::ArrayView< const char > message) {
397
+ void DebugGroup::pushImplementationKhrES (const Source source, const UnsignedInt id, const Containers::StringView message) {
372
398
glPushDebugGroupKHR (GLenum (source), id, message.size (), message.data ());
373
399
}
374
400
#endif
375
401
376
- void DebugGroup::pushImplementationExt (Source, UnsignedInt, const Containers::ArrayView< const char > message) {
402
+ void DebugGroup::pushImplementationExt (Source, UnsignedInt, const Containers::StringView message) {
377
403
glPushGroupMarkerEXT (message.size (), message.data ());
378
404
}
379
405
0 commit comments