forked from Mirrors/openclonk
Move shader logging into separate file and log only in editor mode (#1209)
parent
1e77de1044
commit
49f991c819
|
@ -133,6 +133,7 @@
|
|||
|
||||
#define C4CFN_Log "OpenClonk.log"
|
||||
#define C4CFN_LogEx "OpenClonk%d.log" // created if regular logfile is in use
|
||||
#define C4CFN_LogShader "OpenClonkShaders.log" // created in editor mode to dump shader code
|
||||
#define C4CFN_Intro "Clonk4.avi"
|
||||
#define C4CFN_Names "Names.txt"
|
||||
#define C4CFN_Titles "Title*.txt|Title.txt"
|
||||
|
|
|
@ -133,6 +133,9 @@ bool C4Application::DoInit(int argc, char * argv[])
|
|||
// Parse command line
|
||||
ParseCommandLine(argc, argv);
|
||||
|
||||
// Open additional logs that depend on command line
|
||||
OpenExtraLogs();
|
||||
|
||||
// Init external language packs
|
||||
Languages.Init();
|
||||
// Load language string table
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include "C4Include.h"
|
||||
#include "C4Shader.h"
|
||||
#include "C4Application.h"
|
||||
|
||||
struct C4ShaderPosName {
|
||||
int Position; const char *Name;
|
||||
|
@ -147,7 +148,7 @@ void C4Shader::AddSlices(ShaderSliceList& slices, const char *szWhat, const char
|
|||
pStart = pPos+1;
|
||||
fGotContent = false;
|
||||
} else {
|
||||
LogF(" gl: Missing opening brace in %s!", szWhat);
|
||||
ShaderLogF(" gl: Missing opening brace in %s!", szWhat);
|
||||
}
|
||||
pPos++;
|
||||
continue;
|
||||
|
@ -188,7 +189,7 @@ int C4Shader::ParsePosition(const char *szWhat, const char **ppPos)
|
|||
}
|
||||
}
|
||||
if (iPosition == -1) {
|
||||
LogF(" gl: Unknown slice position in %s: %s", szWhat, Name.getData());
|
||||
ShaderLogF(" gl: Unknown slice position in %s: %s", szWhat, Name.getData());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -197,7 +198,7 @@ int C4Shader::ParsePosition(const char *szWhat, const char **ppPos)
|
|||
if (*pPos == '+') {
|
||||
int iMod, iModLen;
|
||||
if (!sscanf(pPos+1, "%d%n", &iMod, &iModLen)) {
|
||||
LogF(" gl: Invalid slice modifier in %s", szWhat);
|
||||
ShaderLogF(" gl: Invalid slice modifier in %s", szWhat);
|
||||
return -1;
|
||||
}
|
||||
iPosition += iMod;
|
||||
|
@ -206,7 +207,7 @@ int C4Shader::ParsePosition(const char *szWhat, const char **ppPos)
|
|||
if (*pPos == '-') {
|
||||
int iMod, iModLen;
|
||||
if (!sscanf(pPos+1, "%d%n", &iMod, &iModLen)) {
|
||||
LogF(" gl: Invalid slice modifier in %s", szWhat);
|
||||
ShaderLogF(" gl: Invalid slice modifier in %s", szWhat);
|
||||
return -1;
|
||||
}
|
||||
iPosition -= iMod;
|
||||
|
@ -296,8 +297,13 @@ bool C4Shader::Init(const char *szWhat, const char **szUniforms)
|
|||
if (hProg) Clear();
|
||||
|
||||
// Dump
|
||||
LogSilent(Build(VertexSlices, true).getData());
|
||||
LogSilent(Build(FragmentSlices, true).getData());
|
||||
if (C4Shader::IsLogging())
|
||||
{
|
||||
ShaderLogF("******** Vertex shader for %s:", szWhat);
|
||||
ShaderLog(Build(VertexSlices, true).getData());
|
||||
ShaderLogF("******** Fragment shader for %s:", szWhat);
|
||||
ShaderLog(Build(FragmentSlices, true).getData());
|
||||
}
|
||||
|
||||
// Attempt to create shaders
|
||||
StdStrBuf VertexShader = Build(VertexSlices),
|
||||
|
@ -321,10 +327,10 @@ bool C4Shader::Init(const char *szWhat, const char **szUniforms)
|
|||
DumpInfoLog(FormatString("%s shader program", szWhat).getData(), hProg);
|
||||
if(GetObjectStatus(hProg, GL_OBJECT_LINK_STATUS_ARB) != 1) {
|
||||
Clear();
|
||||
LogF(" gl: Failed to link %s shader!", szWhat);
|
||||
ShaderLogF(" gl: Failed to link %s shader!", szWhat);
|
||||
return false;
|
||||
}
|
||||
LogF(" gl: %s shader linked successfully", szWhat);
|
||||
ShaderLogF(" gl: %s shader linked successfully", szWhat);
|
||||
|
||||
// Okay, allocate uniform array
|
||||
iUniformCount = 0;
|
||||
|
@ -370,7 +376,7 @@ bool C4Shader::Refresh(const char *szWhat, const char **szUniforms)
|
|||
!Group.LoadEntryString(GetFilename(Source.getData()),&Shader) ||
|
||||
!Group.Close())
|
||||
{
|
||||
LogF(" gl: Failed to refresh %s shader from %s!", szWhat, Source.getData());
|
||||
ShaderLogF(" gl: Failed to refresh %s shader from %s!", szWhat, Source.getData());
|
||||
return Refresh(szWhat, szUniforms);
|
||||
}
|
||||
|
||||
|
@ -477,8 +483,8 @@ void C4Shader::DumpInfoLog(const char *szWhat, GLhandleARB hShader)
|
|||
|
||||
// Terminate, log
|
||||
pBuf[iActualLength] = '\0';
|
||||
LogSilentF(" gl: Compiling %s:", szWhat);
|
||||
LogSilent(pBuf);
|
||||
ShaderLogF(" gl: Compiling %s:", szWhat);
|
||||
ShaderLogF(pBuf);
|
||||
delete[] pBuf;
|
||||
}
|
||||
|
||||
|
@ -489,6 +495,8 @@ int C4Shader::GetObjectStatus(GLhandleARB hObj, GLenum type)
|
|||
return iStatus;
|
||||
}
|
||||
|
||||
bool C4Shader::IsLogging() { return !!Application.isEditor; }
|
||||
|
||||
GLint C4ShaderCall::AllocTexUnit(int iUniform, GLenum iType)
|
||||
{
|
||||
// Want to bind uniform automatically? If not, the caller will take
|
||||
|
|
|
@ -103,6 +103,9 @@ private:
|
|||
GLhandleARB Create(GLenum iShaderType, const char *szWhat, const char *szShader);
|
||||
void DumpInfoLog(const char *szWhat, GLhandleARB hShader);
|
||||
int GetObjectStatus(GLhandleARB hObj, GLenum type);
|
||||
|
||||
public:
|
||||
static bool IsLogging();
|
||||
};
|
||||
|
||||
class C4ShaderCall
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <C4Config.h>
|
||||
#include <C4Components.h>
|
||||
#include <C4Window.h>
|
||||
#include <C4Shader.h>
|
||||
|
||||
#ifdef HAVE_SYS_FILE_H
|
||||
#include <sys/file.h>
|
||||
|
@ -41,6 +42,7 @@
|
|||
#endif
|
||||
|
||||
FILE *C4LogFile=NULL;
|
||||
FILE *C4ShaderLogFile = NULL;
|
||||
time_t C4LogStartTime;
|
||||
StdStrBuf sLogFileName;
|
||||
|
||||
|
@ -71,9 +73,18 @@ bool OpenLog()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool OpenExtraLogs()
|
||||
{
|
||||
// shader log in editor mode (only one file)
|
||||
bool success = true;
|
||||
if (C4Shader::IsLogging()) if (!(C4ShaderLogFile = _fsopen(Config.AtUserDataPath(C4CFN_LogShader), "wt", _SH_DENYWR))) success = false;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool CloseLog()
|
||||
{
|
||||
// close
|
||||
if (C4ShaderLogFile) fclose(C4ShaderLogFile); C4ShaderLogFile = NULL;
|
||||
if (C4LogFile) fclose(C4LogFile); C4LogFile = NULL;
|
||||
// ok
|
||||
return true;
|
||||
|
@ -304,3 +315,29 @@ bool GetLogSection(size_t iStart, size_t iLength, StdStrBuf &rsOut)
|
|||
// done, success
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ShaderLog(const char *szMessage)
|
||||
{
|
||||
// security
|
||||
if (!C4ShaderLogFile) return false;
|
||||
if (!Application.AssertMainThread()) return false;
|
||||
if (!szMessage) return false;
|
||||
// output into shader log file
|
||||
#ifdef HAVE_ICONV
|
||||
StdStrBuf Line = Languages.IconvSystem(TimeMessage.getData());
|
||||
#else
|
||||
StdStrBuf Line; Line.Ref(szMessage);
|
||||
#endif
|
||||
fputs(Line.getData(), C4ShaderLogFile);
|
||||
fputs("\n", C4ShaderLogFile);
|
||||
fflush(C4ShaderLogFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ShaderLogF(const char *strMessage ...)
|
||||
{
|
||||
va_list args; va_start(args, strMessage);
|
||||
StdStrBuf Buf;
|
||||
Buf.FormatV(strMessage, args);
|
||||
return ShaderLog(Buf.getData());
|
||||
}
|
|
@ -22,6 +22,7 @@
|
|||
#include <StdBuf.h>
|
||||
|
||||
bool OpenLog();
|
||||
bool OpenExtraLogs();
|
||||
bool CloseLog();
|
||||
|
||||
bool Log(const char *szMessage);
|
||||
|
@ -30,6 +31,8 @@ bool LogF(const char *strMessage, ...) GNUC_FORMAT_ATTRIBUTE;
|
|||
bool LogSilentF(const char *strMessage, ...) GNUC_FORMAT_ATTRIBUTE;
|
||||
bool DebugLog(const char *strMessage);
|
||||
bool DebugLogF(const char *strMessage ...) GNUC_FORMAT_ATTRIBUTE;
|
||||
bool ShaderLog(const char *strMessage);
|
||||
bool ShaderLogF(const char *strMessage ...) GNUC_FORMAT_ATTRIBUTE;
|
||||
|
||||
bool LogFatal(const char *szMessage); // log message and store it as a fatal error
|
||||
void ResetFatalError(); // clear any fatal error message
|
||||
|
|
Loading…
Reference in New Issue