2013-04-18 03:29:41 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/IniFile.h"
|
2014-03-12 19:33:41 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/OGL/GLUtil.h"
|
|
|
|
#include "VideoBackends/OGL/Render.h"
|
|
|
|
#include "VideoBackends/OGL/VideoBackend.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2010-07-16 21:56:40 +00:00
|
|
|
|
|
|
|
GLWindow GLWin;
|
2012-12-17 20:54:20 +00:00
|
|
|
cInterfaceBase *GLInterface;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
namespace OGL
|
|
|
|
{
|
|
|
|
|
2009-02-19 06:52:01 +00:00
|
|
|
// Draw messages on top of the screen
|
2011-01-31 01:28:32 +00:00
|
|
|
unsigned int VideoBackend::PeekMessages()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-06-19 07:17:33 +00:00
|
|
|
return GLInterface->PeekMessages();
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-02-28 16:33:59 +00:00
|
|
|
|
2009-02-19 06:52:01 +00:00
|
|
|
// Show the current FPS
|
2014-03-12 19:33:41 +00:00
|
|
|
void VideoBackend::UpdateFPSDisplay(const std::string& text)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2014-03-12 19:33:41 +00:00
|
|
|
return GLInterface->UpdateFPSDisplay(StringFromFormat("%s | %s | %s", scm_rev_str, GetDisplayName().c_str(), text.c_str()));
|
2011-01-31 01:28:32 +00:00
|
|
|
}
|
|
|
|
|
2010-02-16 04:59:45 +00:00
|
|
|
}
|
2012-12-17 20:54:20 +00:00
|
|
|
void InitInterface()
|
2010-02-16 04:59:45 +00:00
|
|
|
{
|
2013-03-25 02:06:34 +00:00
|
|
|
#if defined(USE_EGL) && USE_EGL
|
2012-12-17 20:54:20 +00:00
|
|
|
GLInterface = new cInterfaceEGL;
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
GLInterface = new cInterfaceAGL;
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
GLInterface = new cInterfaceWGL;
|
|
|
|
#elif defined(HAVE_X11) && HAVE_X11
|
|
|
|
GLInterface = new cInterfaceGLX;
|
|
|
|
#endif
|
2010-02-16 04:59:45 +00:00
|
|
|
}
|
2009-01-04 21:53:41 +00:00
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
GLuint OpenGL_CompileProgram(const char* vertexShader, const char* fragmentShader)
|
2012-12-12 09:40:03 +00:00
|
|
|
{
|
|
|
|
// generate objects
|
|
|
|
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
|
|
|
|
GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
|
|
|
|
GLuint programID = glCreateProgram();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2012-12-12 09:40:03 +00:00
|
|
|
// compile vertex shader
|
2014-03-09 20:14:26 +00:00
|
|
|
glShaderSource(vertexShaderID, 1, &vertexShader, nullptr);
|
2012-12-12 09:40:03 +00:00
|
|
|
glCompileShader(vertexShaderID);
|
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
2013-01-11 20:24:59 +00:00
|
|
|
GLint Result = GL_FALSE;
|
|
|
|
char stringBuffer[1024];
|
|
|
|
GLsizei stringBufferUsage = 0;
|
2012-12-12 09:40:03 +00:00
|
|
|
glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &Result);
|
|
|
|
glGetShaderInfoLog(vertexShaderID, 1024, &stringBufferUsage, stringBuffer);
|
2014-03-10 11:30:55 +00:00
|
|
|
if (Result && stringBufferUsage) {
|
2012-12-12 09:40:03 +00:00
|
|
|
ERROR_LOG(VIDEO, "GLSL vertex shader warnings:\n%s%s", stringBuffer, vertexShader);
|
2014-03-10 11:30:55 +00:00
|
|
|
} else if (!Result) {
|
2012-12-12 09:40:03 +00:00
|
|
|
ERROR_LOG(VIDEO, "GLSL vertex shader error:\n%s%s", stringBuffer, vertexShader);
|
|
|
|
} else {
|
|
|
|
DEBUG_LOG(VIDEO, "GLSL vertex shader compiled:\n%s", vertexShader);
|
|
|
|
}
|
|
|
|
bool shader_errors = !Result;
|
|
|
|
#endif
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2012-12-12 09:40:03 +00:00
|
|
|
// compile fragment shader
|
2014-03-09 20:14:26 +00:00
|
|
|
glShaderSource(fragmentShaderID, 1, &fragmentShader, nullptr);
|
2012-12-12 09:40:03 +00:00
|
|
|
glCompileShader(fragmentShaderID);
|
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
|
|
|
glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &Result);
|
|
|
|
glGetShaderInfoLog(fragmentShaderID, 1024, &stringBufferUsage, stringBuffer);
|
2014-03-10 11:30:55 +00:00
|
|
|
if (Result && stringBufferUsage) {
|
2012-12-12 09:40:03 +00:00
|
|
|
ERROR_LOG(VIDEO, "GLSL fragment shader warnings:\n%s%s", stringBuffer, fragmentShader);
|
2014-03-10 11:30:55 +00:00
|
|
|
} else if (!Result) {
|
2012-12-12 09:40:03 +00:00
|
|
|
ERROR_LOG(VIDEO, "GLSL fragment shader error:\n%s%s", stringBuffer, fragmentShader);
|
|
|
|
} else {
|
|
|
|
DEBUG_LOG(VIDEO, "GLSL fragment shader compiled:\n%s", fragmentShader);
|
|
|
|
}
|
|
|
|
shader_errors |= !Result;
|
|
|
|
#endif
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2012-12-12 09:40:03 +00:00
|
|
|
// link them
|
|
|
|
glAttachShader(programID, vertexShaderID);
|
|
|
|
glAttachShader(programID, fragmentShaderID);
|
|
|
|
glLinkProgram(programID);
|
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
|
|
|
glGetProgramiv(programID, GL_LINK_STATUS, &Result);
|
|
|
|
glGetProgramInfoLog(programID, 1024, &stringBufferUsage, stringBuffer);
|
2014-03-10 11:30:55 +00:00
|
|
|
if (Result && stringBufferUsage) {
|
2012-12-12 09:40:03 +00:00
|
|
|
ERROR_LOG(VIDEO, "GLSL linker warnings:\n%s%s%s", stringBuffer, vertexShader, fragmentShader);
|
2014-03-10 11:30:55 +00:00
|
|
|
} else if (!Result && !shader_errors) {
|
2012-12-12 09:40:03 +00:00
|
|
|
ERROR_LOG(VIDEO, "GLSL linker error:\n%s%s%s", stringBuffer, vertexShader, fragmentShader);
|
|
|
|
}
|
|
|
|
#endif
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2012-12-12 09:40:03 +00:00
|
|
|
// cleanup
|
|
|
|
glDeleteShader(vertexShaderID);
|
|
|
|
glDeleteShader(fragmentShaderID);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2012-12-12 09:40:03 +00:00
|
|
|
return programID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-22 11:21:44 +00:00
|
|
|
GLuint OpenGL_ReportGLError(const char *function, const char *file, int line)
|
|
|
|
{
|
|
|
|
GLint err = glGetError();
|
|
|
|
if (err != GL_NO_ERROR)
|
|
|
|
{
|
2012-12-17 20:54:20 +00:00
|
|
|
ERROR_LOG(VIDEO, "%s:%d: (%s) OpenGL error 0x%x\n",
|
|
|
|
file, line, function, err);
|
2009-03-22 11:21:44 +00:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenGL_ReportFBOError(const char *function, const char *file, int line)
|
|
|
|
{
|
2013-01-03 11:06:47 +00:00
|
|
|
unsigned int fbo_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
|
|
if (fbo_status != GL_FRAMEBUFFER_COMPLETE)
|
2009-02-21 13:11:49 +00:00
|
|
|
{
|
2013-01-03 11:06:47 +00:00
|
|
|
const char *error = "unknown error";
|
2009-03-22 11:21:44 +00:00
|
|
|
switch (fbo_status)
|
|
|
|
{
|
2013-01-03 11:06:47 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
|
|
|
error = "INCOMPLETE_ATTACHMENT";
|
2011-03-02 05:16:49 +00:00
|
|
|
break;
|
2013-01-03 11:06:47 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
|
|
|
error = "INCOMPLETE_MISSING_ATTACHMENT";
|
2011-03-02 05:16:49 +00:00
|
|
|
break;
|
2013-01-03 11:06:47 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
|
|
|
|
error = "INCOMPLETE_DRAW_BUFFER";
|
2011-03-02 05:16:49 +00:00
|
|
|
break;
|
2013-01-03 11:06:47 +00:00
|
|
|
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
|
|
|
|
error = "INCOMPLETE_READ_BUFFER";
|
2011-03-02 05:16:49 +00:00
|
|
|
break;
|
2013-01-03 11:06:47 +00:00
|
|
|
case GL_FRAMEBUFFER_UNSUPPORTED:
|
|
|
|
error = "UNSUPPORTED";
|
2011-03-02 05:16:49 +00:00
|
|
|
break;
|
2009-03-22 11:21:44 +00:00
|
|
|
}
|
2011-03-02 05:16:49 +00:00
|
|
|
ERROR_LOG(VIDEO, "%s:%d: (%s) OpenGL FBO error - %s\n",
|
|
|
|
file, line, function, error);
|
2009-03-22 11:21:44 +00:00
|
|
|
return false;
|
2009-02-21 13:11:49 +00:00
|
|
|
}
|
2009-03-22 11:21:44 +00:00
|
|
|
return true;
|
2009-02-21 13:11:49 +00:00
|
|
|
}
|
2009-09-09 19:52:45 +00:00
|
|
|
|