-
-
Save paulhoux/7c59968603a075f98e9ca8b6339dc74f to your computer and use it in GitHub Desktop.
Markers class for easy GPU debugging.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Markers.h" | |
namespace tools { | |
// Note: when using C++17, you can define this variable in the header file if you precede it with 'inline' | |
__declspec( thread ) int Marker::mId = 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Copyright (c) 2016-2021, Paul Houx | |
All rights reserved. | |
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. | |
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, | |
PO Box 1866, Mountain View, CA 94042, USA. | |
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS | |
OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, | |
WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, | |
ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED | |
WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU. | |
EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, | |
INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR | |
HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
*/ | |
#pragma once | |
#include <cinder/gl/gl.h> | |
#include <string> | |
namespace tools { | |
class Marker { | |
public: | |
static void push( const char *message ) noexcept { glPushDebugGroup( GL_DEBUG_SOURCE_APPLICATION, ++mId, -1, message ); } | |
static void pop() noexcept { glPopDebugGroup(); } | |
private: | |
Marker() = default; | |
__declspec( thread ) static int mId; | |
}; | |
class ScopedMarker { | |
public: | |
explicit ScopedMarker( const char *message ) { Marker::push( message ); } | |
explicit ScopedMarker( const std::string &message ) { Marker::push( message.c_str() ); } | |
~ScopedMarker() { Marker::pop(); } | |
ScopedMarker( const ScopedMarker & ) = delete; | |
ScopedMarker( ScopedMarker && ) = delete; | |
ScopedMarker &operator=( const ScopedMarker & ) = delete; | |
ScopedMarker &operator=( ScopedMarker && ) = delete; | |
}; | |
} // namespace render |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment