mkxp/src/gl-debug.cpp

92 lines
2.0 KiB
C++
Raw Normal View History

2013-09-01 14:27:21 +00:00
/*
2014-11-29 16:47:40 +00:00
** gl-debug.cpp
2013-09-01 14:27:21 +00:00
**
** This file is part of mkxp.
**
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
**
** mkxp is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 2 of the License, or
** (at your option) any later version.
**
** mkxp is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/
2014-11-29 16:47:40 +00:00
#include "gl-debug.h"
#include "debugwriter.h"
2013-09-01 14:27:21 +00:00
#include <iostream>
2013-09-01 14:27:21 +00:00
#include "gl-fun.h"
2014-11-29 16:47:40 +00:00
struct GLDebugLoggerPrivate
2013-09-01 14:27:21 +00:00
{
std::ostream *stream;
2013-09-01 14:27:21 +00:00
2014-11-29 16:47:40 +00:00
GLDebugLoggerPrivate(const char *logFilename)
2013-09-01 14:27:21 +00:00
{
(void) logFilename;
stream = &std::clog;
2013-09-01 14:27:21 +00:00
}
2014-11-29 16:47:40 +00:00
~GLDebugLoggerPrivate()
2013-09-01 14:27:21 +00:00
{
}
void writeTimestamp()
{
// FIXME reintroduce proper time stamps (is this even necessary??)
*stream << "[GLDEBUG] ";
2013-09-01 14:27:21 +00:00
}
void writeLine(const char *line)
{
*stream << line << "\n";
stream->flush();
}
};
static void APIENTRY arbDebugFunc(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar* message,
const void* userParam)
2013-09-01 14:27:21 +00:00
{
2014-11-29 16:47:40 +00:00
GLDebugLoggerPrivate *p =
static_cast<GLDebugLoggerPrivate*>(const_cast<void*>(userParam));
2013-09-01 14:27:21 +00:00
(void) source;
(void) type;
(void) id;
(void) severity;
(void) length;
p->writeTimestamp();
p->writeLine(message);
}
2014-11-29 16:47:40 +00:00
GLDebugLogger::GLDebugLogger(const char *filename)
2013-09-01 14:27:21 +00:00
{
2014-11-29 16:47:40 +00:00
p = new GLDebugLoggerPrivate(filename);
2013-09-01 14:27:21 +00:00
if (gl.DebugMessageCallback)
gl.DebugMessageCallback(arbDebugFunc, p);
2013-09-01 14:27:21 +00:00
else
Debug() << "DebugLogger: no debug extensions found";
2013-09-01 14:27:21 +00:00
}
2014-11-29 16:47:40 +00:00
GLDebugLogger::~GLDebugLogger()
2013-09-01 14:27:21 +00:00
{
delete p;
}