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
|
|
|
|
|
|
|
#include "Globals.h"
|
2009-09-13 09:23:30 +00:00
|
|
|
#include "VideoConfig.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
#include "IniFile.h"
|
2011-01-31 01:28:32 +00:00
|
|
|
#include "Core.h"
|
|
|
|
#include "Host.h"
|
|
|
|
#include "VideoBackend.h"
|
|
|
|
#include "ConfigManager.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
#include "Render.h"
|
2010-12-21 23:58:25 +00:00
|
|
|
#include "VertexShaderManager.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-07-16 21:56:40 +00:00
|
|
|
#include "GLUtil.h"
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-12-17 20:54:20 +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
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackend::UpdateFPSDisplay(const char *text)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2011-01-10 23:48:59 +00:00
|
|
|
char temp[100];
|
2011-08-21 21:30:19 +00:00
|
|
|
snprintf(temp, sizeof temp, "%s | OpenGL | %s", scm_rev_str, text);
|
2012-12-17 20:54:20 +00:00
|
|
|
return GLInterface->UpdateFPSDisplay(temp);
|
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
|
|
|
|
2012-12-17 20:54:20 +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();
|
|
|
|
|
|
|
|
// compile vertex shader
|
|
|
|
glShaderSource(vertexShaderID, 1, &vertexShader, NULL);
|
|
|
|
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);
|
|
|
|
if(Result && stringBufferUsage) {
|
|
|
|
ERROR_LOG(VIDEO, "GLSL vertex shader warnings:\n%s%s", stringBuffer, vertexShader);
|
|
|
|
} else if(!Result) {
|
|
|
|
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
|
|
|
|
|
|
|
|
// compile fragment shader
|
|
|
|
glShaderSource(fragmentShaderID, 1, &fragmentShader, NULL);
|
|
|
|
glCompileShader(fragmentShaderID);
|
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
|
|
|
glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &Result);
|
|
|
|
glGetShaderInfoLog(fragmentShaderID, 1024, &stringBufferUsage, stringBuffer);
|
|
|
|
if(Result && stringBufferUsage) {
|
|
|
|
ERROR_LOG(VIDEO, "GLSL fragment shader warnings:\n%s%s", stringBuffer, fragmentShader);
|
|
|
|
} else if(!Result) {
|
|
|
|
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
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
if(Result && stringBufferUsage) {
|
|
|
|
ERROR_LOG(VIDEO, "GLSL linker warnings:\n%s%s%s", stringBuffer, vertexShader, fragmentShader);
|
|
|
|
} else if(!Result && !shader_errors) {
|
|
|
|
ERROR_LOG(VIDEO, "GLSL linker error:\n%s%s%s", stringBuffer, vertexShader, fragmentShader);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
glDeleteShader(vertexShaderID);
|
|
|
|
glDeleteShader(fragmentShaderID);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGL_ReportARBProgramError()
|
2009-02-21 13:11:49 +00:00
|
|
|
{
|
2012-12-17 20:54:20 +00:00
|
|
|
#ifndef USE_GLES
|
2009-02-21 13:11:49 +00:00
|
|
|
const GLubyte* pstr = glGetString(GL_PROGRAM_ERROR_STRING_ARB);
|
|
|
|
if (pstr != NULL && pstr[0] != 0)
|
|
|
|
{
|
|
|
|
GLint loc = 0;
|
|
|
|
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &loc);
|
2013-03-31 23:10:21 +00:00
|
|
|
ERROR_LOG(VIDEO, "Program error at %d: ", loc);
|
2010-12-05 09:04:34 +00:00
|
|
|
ERROR_LOG(VIDEO, "%s", (char*)pstr);
|
|
|
|
ERROR_LOG(VIDEO, "\n");
|
2009-02-21 13:11:49 +00:00
|
|
|
}
|
2012-12-17 20:54:20 +00:00
|
|
|
#endif
|
2009-03-22 11:21:44 +00:00
|
|
|
}
|
2009-02-21 13:11:49 +00:00
|
|
|
|
2009-03-22 11:21:44 +00:00
|
|
|
bool OpenGL_ReportFBOError(const char *function, const char *file, int line)
|
|
|
|
{
|
2012-12-17 20:54:20 +00:00
|
|
|
#ifndef USE_GLES
|
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
|
|
|
}
|
2012-12-17 20:54:20 +00:00
|
|
|
#endif
|
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
|
|
|
|