2010-07-10 08:20:50 +00:00
|
|
|
/* ZZ Open GL graphics plugin
|
|
|
|
* Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
|
|
|
|
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
|
2010-07-02 09:32:04 +00:00
|
|
|
*
|
2010-07-10 08:20:50 +00:00
|
|
|
* This program 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.
|
2010-07-02 09:32:04 +00:00
|
|
|
*
|
2010-07-10 08:20:50 +00:00
|
|
|
* This program 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.
|
2010-07-02 09:32:04 +00:00
|
|
|
*
|
2010-07-10 08:20:50 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2010-07-02 09:32:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "ZZLog.h"
|
2011-03-25 01:09:18 +00:00
|
|
|
#include <list>
|
2010-10-17 08:47:31 +00:00
|
|
|
#include <cstring>
|
2010-07-02 09:32:04 +00:00
|
|
|
|
|
|
|
extern GSconf conf;
|
|
|
|
|
2010-10-17 08:47:31 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
static list<MESSAGE> listMsgs;
|
2012-04-19 21:22:08 +00:00
|
|
|
const char* logging_prefix = "ZZOgl-PG";
|
2010-10-17 08:47:31 +00:00
|
|
|
void ProcessMessages()
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
if (listMsgs.size() > 0)
|
|
|
|
{
|
|
|
|
int left = 25, top = 15;
|
|
|
|
list<MESSAGE>::iterator it = listMsgs.begin();
|
|
|
|
|
|
|
|
while (it != listMsgs.end())
|
|
|
|
{
|
|
|
|
DrawText(it->str, left + 1, top + 1, 0xff000000);
|
|
|
|
DrawText(it->str, left, top, 0xffffff30);
|
|
|
|
top += 15;
|
|
|
|
|
|
|
|
if ((int)(it->dwTimeStamp - timeGetTime()) < 0)
|
|
|
|
it = listMsgs.erase(it);
|
|
|
|
else ++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZZAddMessage(const char* pstr, u32 ms)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
listMsgs.push_back(MESSAGE(pstr, timeGetTime() + ms));
|
|
|
|
ZZLog::Log("%s\n", pstr);
|
|
|
|
}
|
|
|
|
|
2010-07-02 09:32:04 +00:00
|
|
|
namespace ZZLog
|
|
|
|
{
|
2011-03-25 01:09:18 +00:00
|
|
|
std::string s_strLogPath("logs");
|
2010-07-02 12:10:40 +00:00
|
|
|
FILE *gsLog;
|
2012-04-29 18:50:07 +00:00
|
|
|
FILE *gsLogGL; // I create a separate file because it could be very verbose
|
2010-07-02 12:10:40 +00:00
|
|
|
|
2010-07-02 09:32:04 +00:00
|
|
|
bool IsLogging()
|
|
|
|
{
|
|
|
|
// gsLog can be null if the config dialog is used prior to Pcsx2 starting an emulation session.
|
|
|
|
// (GSinit won't have been called then)
|
|
|
|
return (gsLog != NULL && conf.log);
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
void Open()
|
2010-07-02 09:32:04 +00:00
|
|
|
{
|
2011-03-25 01:09:18 +00:00
|
|
|
const std::string LogFile(s_strLogPath + "/GSzzogl.log");
|
2012-04-29 18:50:07 +00:00
|
|
|
const std::string LogFileGL(s_strLogPath + "/GSzzogl_GL.log");
|
2010-07-02 09:32:04 +00:00
|
|
|
|
|
|
|
gsLog = fopen(LogFile.c_str(), "w");
|
|
|
|
if (gsLog != NULL)
|
|
|
|
setvbuf(gsLog, NULL, _IONBF, 0);
|
|
|
|
else
|
|
|
|
SysMessage("Can't create log file %s\n", LogFile.c_str());
|
|
|
|
|
2012-04-29 18:50:07 +00:00
|
|
|
gsLogGL = fopen(LogFileGL.c_str(), "w");
|
|
|
|
if (gsLogGL != NULL)
|
|
|
|
setvbuf(gsLogGL, NULL, _IONBF, 0);
|
|
|
|
else
|
|
|
|
SysMessage("Can't create log file %s\n", LogFileGL.c_str());
|
|
|
|
|
|
|
|
|
2010-07-02 09:32:04 +00:00
|
|
|
}
|
|
|
|
|
2010-07-02 12:10:40 +00:00
|
|
|
void Close()
|
|
|
|
{
|
2010-08-20 11:13:40 +00:00
|
|
|
if (gsLog != NULL) {
|
|
|
|
fclose(gsLog);
|
|
|
|
gsLog = NULL;
|
|
|
|
}
|
2012-04-29 18:50:07 +00:00
|
|
|
if (gsLogGL != NULL) {
|
|
|
|
fclose(gsLogGL);
|
|
|
|
gsLogGL = NULL;
|
|
|
|
}
|
2010-07-02 12:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetDir(const char* dir)
|
|
|
|
{
|
|
|
|
// Get the path to the log directory.
|
2011-03-25 01:09:18 +00:00
|
|
|
s_strLogPath = (dir==NULL) ? "logs" : dir;
|
2010-07-02 12:10:40 +00:00
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
// Reload previously open log file
|
|
|
|
if (gsLog) {
|
|
|
|
Close();
|
|
|
|
Open();
|
|
|
|
}
|
2010-07-02 12:10:40 +00:00
|
|
|
}
|
|
|
|
|
2010-07-02 09:32:04 +00:00
|
|
|
void WriteToScreen(const char* pstr, u32 ms)
|
|
|
|
{
|
2010-10-16 11:54:46 +00:00
|
|
|
ZZAddMessage(pstr, ms);
|
2010-07-02 09:32:04 +00:00
|
|
|
}
|
|
|
|
|
2010-11-07 04:45:10 +00:00
|
|
|
void WriteToScreen2(const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
char tmp[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
vsprintf(tmp, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
ZZAddMessage(tmp, 5000);
|
|
|
|
}
|
|
|
|
|
2010-07-02 09:32:04 +00:00
|
|
|
void _Message(const char *str)
|
|
|
|
{
|
|
|
|
SysMessage(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _Log(const char *str)
|
|
|
|
{
|
|
|
|
if (IsLogging()) fprintf(gsLog, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _WriteToConsole(const char *str)
|
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
fprintf(stderr,"%s: ", logging_prefix);
|
|
|
|
fprintf(stderr,"%s", str);
|
2010-07-02 09:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _Print(const char *str)
|
|
|
|
{
|
2012-04-19 21:22:08 +00:00
|
|
|
fprintf(stderr,"%s: ", logging_prefix);
|
|
|
|
fprintf(stderr,"%s", str);
|
2010-07-02 09:32:04 +00:00
|
|
|
|
|
|
|
if (IsLogging()) fprintf(gsLog, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
char tmp[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
vsprintf(tmp, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
SysMessage(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging()) vfprintf(gsLog, fmt, list);
|
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteToConsole(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
fprintf(stderr, "%s: ", logging_prefix);
|
2010-07-02 09:32:04 +00:00
|
|
|
vfprintf(stderr, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Print(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging()) vfprintf(gsLog, fmt, list);
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
fprintf(stderr, "%s: ", logging_prefix);
|
2010-07-02 09:32:04 +00:00
|
|
|
vfprintf(stderr, fmt, list);
|
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WriteLn(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging()) vfprintf(gsLog, fmt, list);
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
fprintf(stderr, "%s: ", logging_prefix);
|
2010-07-02 09:32:04 +00:00
|
|
|
vfprintf(stderr, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
fprintf(stderr,"\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Greg_Log(const char *fmt, ...)
|
|
|
|
{
|
2010-07-10 10:25:48 +00:00
|
|
|
#if defined(WRITE_GREG_LOGS)
|
2010-07-02 09:32:04 +00:00
|
|
|
va_list list;
|
|
|
|
char tmp[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
if (IsLogging()) {
|
|
|
|
fprintf(gsLog, "GRegs: ");
|
|
|
|
vfprintf(gsLog, fmt, list);
|
|
|
|
}
|
2010-07-10 10:25:48 +00:00
|
|
|
//fprintf(stderr,"GRegs: ");
|
|
|
|
//vfprintf(stderr, fmt, list);
|
2010-07-02 09:32:04 +00:00
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
|
2010-07-10 10:25:48 +00:00
|
|
|
if (IsLogging()) fprintf(gsLog, "\n");
|
|
|
|
//fprintf(stderr,"\n");
|
2010-07-02 09:32:04 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Prim_Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
#if defined(ZEROGS_DEVBUILD) && defined(WRITE_PRIM_LOGS)
|
|
|
|
va_list list;
|
|
|
|
char tmp[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (conf.log /*& 0x00000010*/)
|
|
|
|
{
|
|
|
|
if (IsLogging()) vfprintf(gsLog, fmt, list);
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
fprintf(stderr, "%s(PRIM): ", logging_prefix);
|
2010-07-02 09:32:04 +00:00
|
|
|
vfprintf(stderr, fmt, list);
|
|
|
|
|
|
|
|
vprintf(fmt, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
fprintf(stderr,"\n");
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GS_Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
#ifdef ZEROGS_DEVBUILD
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging())
|
|
|
|
{
|
|
|
|
vfprintf(gsLog, fmt, list);
|
|
|
|
fprintf(gsLog, "\n");
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
fprintf(stderr, "%s: ", logging_prefix);
|
2010-07-02 09:32:04 +00:00
|
|
|
vfprintf(stderr, fmt, list);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Warn_Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
#ifdef ZEROGS_DEVBUILD
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging())
|
|
|
|
{
|
|
|
|
vfprintf(gsLog, fmt, list);
|
|
|
|
fprintf(gsLog, "\n");
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
fprintf(stderr, "%s(Warning): ", logging_prefix);
|
2010-07-02 09:32:04 +00:00
|
|
|
vfprintf(stderr, fmt, list);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-09-25 08:57:44 +00:00
|
|
|
void Dev_Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
#ifdef ZEROGS_DEVBUILD
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging())
|
|
|
|
{
|
|
|
|
vfprintf(gsLog, fmt, list);
|
|
|
|
fprintf(gsLog, "\n");
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
fprintf(stderr, "%s: ", logging_prefix);
|
2010-09-25 08:57:44 +00:00
|
|
|
vfprintf(stderr, fmt, list);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-07-02 09:32:04 +00:00
|
|
|
void Debug_Log(const char *fmt, ...)
|
|
|
|
{
|
2010-11-10 11:15:48 +00:00
|
|
|
#ifdef _DEBUG
|
2010-07-02 09:32:04 +00:00
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging())
|
|
|
|
{
|
|
|
|
vfprintf(gsLog, fmt, list);
|
|
|
|
fprintf(gsLog, "\n");
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
fprintf(stderr, "%s: ", logging_prefix);
|
2010-07-02 09:32:04 +00:00
|
|
|
vfprintf(stderr, fmt, list);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Error_Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging())
|
|
|
|
{
|
|
|
|
vfprintf(gsLog, fmt, list);
|
|
|
|
fprintf(gsLog, "\n");
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
fprintf(stderr, "%s: ", logging_prefix);
|
2010-07-02 09:32:04 +00:00
|
|
|
vfprintf(stderr, fmt, list);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
}
|
2012-04-29 18:50:07 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
#ifdef _DEBUG
|
2012-04-29 18:50:07 +00:00
|
|
|
#define LOUD_DEBUGGING
|
2012-10-21 18:10:13 +00:00
|
|
|
#endif
|
2012-04-29 18:50:07 +00:00
|
|
|
|
|
|
|
#ifdef OGL4_LOG
|
|
|
|
void Check_GL_Error()
|
|
|
|
{
|
2012-10-21 18:10:13 +00:00
|
|
|
#if defined(ZEROGS_DEVBUILD) || defined(_DEBUG)
|
2012-04-29 18:50:07 +00:00
|
|
|
unsigned int count = 64; // max. num. of messages that will be read from the log
|
|
|
|
int bufsize = 2048;
|
|
|
|
unsigned int* sources = new unsigned int[count];
|
|
|
|
unsigned int* types = new unsigned int[count];
|
|
|
|
unsigned int* ids = new unsigned int[count];
|
|
|
|
unsigned int* severities = new unsigned int[count];
|
|
|
|
int* lengths = new int[count];
|
|
|
|
char* messageLog = new char[bufsize];
|
|
|
|
unsigned int retVal = glGetDebugMessageLogARB(count, bufsize, sources, types, ids, severities, lengths, messageLog);
|
|
|
|
|
|
|
|
if(retVal > 0)
|
|
|
|
{
|
|
|
|
unsigned int pos = 0;
|
|
|
|
for(unsigned int i=0; i<retVal; i++)
|
|
|
|
{
|
|
|
|
GL_Error_Log(sources[i], types[i], ids[i], severities[i],
|
|
|
|
&messageLog[pos]);
|
|
|
|
pos += lengths[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] sources;
|
|
|
|
delete [] types;
|
|
|
|
delete [] ids;
|
|
|
|
delete [] severities;
|
|
|
|
delete [] lengths;
|
|
|
|
delete [] messageLog;
|
2012-10-21 18:10:13 +00:00
|
|
|
#endif
|
2012-04-29 18:50:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GL_Error_Log(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, const char* message)
|
|
|
|
{
|
|
|
|
char debType[20], debSev[5];
|
|
|
|
static int sev_counter = 0;
|
|
|
|
|
|
|
|
if(type == GL_DEBUG_TYPE_ERROR_ARB)
|
|
|
|
strcpy(debType, "Error");
|
|
|
|
else if(type == GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB)
|
|
|
|
strcpy(debType, "Deprecated behavior");
|
|
|
|
else if(type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB)
|
|
|
|
strcpy(debType, "Undefined behavior");
|
|
|
|
else if(type == GL_DEBUG_TYPE_PORTABILITY_ARB)
|
|
|
|
strcpy(debType, "Portability");
|
|
|
|
else if(type == GL_DEBUG_TYPE_PERFORMANCE_ARB)
|
|
|
|
strcpy(debType, "Performance");
|
|
|
|
else if(type == GL_DEBUG_TYPE_OTHER_ARB)
|
|
|
|
strcpy(debType, "Other");
|
|
|
|
else
|
|
|
|
strcpy(debType, "UNKNOWN");
|
|
|
|
|
|
|
|
if(severity == GL_DEBUG_SEVERITY_HIGH_ARB) {
|
|
|
|
strcpy(debSev, "High");
|
|
|
|
sev_counter++;
|
|
|
|
}
|
|
|
|
else if(severity == GL_DEBUG_SEVERITY_MEDIUM_ARB)
|
|
|
|
strcpy(debSev, "Med");
|
|
|
|
else if(severity == GL_DEBUG_SEVERITY_LOW_ARB)
|
|
|
|
strcpy(debSev, "Low");
|
|
|
|
|
|
|
|
#ifdef LOUD_DEBUGGING
|
|
|
|
fprintf(stderr,"Type:%s\tSeverity:%s\tMessage:%s\n", debType, debSev,message);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(gsLogGL)
|
|
|
|
{
|
|
|
|
fprintf(gsLogGL,"Type:%s\tSeverity:%s\tMessage:%s\n", debType, debSev,message);
|
|
|
|
}
|
|
|
|
//if (sev_counter > 2) assert(0);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void Check_GL_Error() {}
|
|
|
|
void GL_Error_Log(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, const char* message) {}
|
|
|
|
#endif
|
|
|
|
|
2010-07-02 09:32:04 +00:00
|
|
|
};
|