2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:29:41 -06:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/IniFile.h"
|
2014-03-12 13:33:41 -06:00
|
|
|
#include "Common/StringUtil.h"
|
2015-09-18 10:40:00 -06:00
|
|
|
#include "Common/GL/GLInterfaceBase.h"
|
|
|
|
#include "Common/GL/GLUtil.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoBackends/OGL/Render.h"
|
|
|
|
#include "VideoBackends/OGL/VideoBackend.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2010-07-16 15:56:40 -06:00
|
|
|
|
2012-12-17 13:54:20 -07:00
|
|
|
cInterfaceBase *GLInterface;
|
2014-12-04 00:24:58 -07:00
|
|
|
static GLuint attributelessVAO = 0;
|
|
|
|
static GLuint attributelessVBO = 0;
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
namespace OGL
|
|
|
|
{
|
|
|
|
|
2009-02-18 23:52:01 -07:00
|
|
|
// Draw messages on top of the screen
|
2011-01-30 18:28:32 -07:00
|
|
|
unsigned int VideoBackend::PeekMessages()
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2013-06-19 01:17:33 -06:00
|
|
|
return GLInterface->PeekMessages();
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
2009-02-28 09:33:59 -07:00
|
|
|
|
2010-02-15 21:59:45 -07:00
|
|
|
}
|
2012-12-17 13:54:20 -07:00
|
|
|
void InitInterface()
|
2010-02-15 21:59:45 -07:00
|
|
|
{
|
2014-08-02 00:21:03 -06:00
|
|
|
GLInterface = HostGL_CreateGLInterface();
|
2010-02-15 21:59:45 -07:00
|
|
|
}
|
2009-01-04 14:53:41 -07:00
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
GLuint OpenGL_CompileProgram(const char* vertexShader, const char* fragmentShader)
|
2012-12-12 02:40:03 -07:00
|
|
|
{
|
|
|
|
// generate objects
|
|
|
|
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
|
|
|
|
GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
|
|
|
|
GLuint programID = glCreateProgram();
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2012-12-12 02:40:03 -07:00
|
|
|
// compile vertex shader
|
2014-03-09 14:14:26 -06:00
|
|
|
glShaderSource(vertexShaderID, 1, &vertexShader, nullptr);
|
2012-12-12 02:40:03 -07:00
|
|
|
glCompileShader(vertexShaderID);
|
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
2013-01-11 13:24:59 -07:00
|
|
|
GLint Result = GL_FALSE;
|
|
|
|
char stringBuffer[1024];
|
|
|
|
GLsizei stringBufferUsage = 0;
|
2012-12-12 02:40:03 -07:00
|
|
|
glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &Result);
|
|
|
|
glGetShaderInfoLog(vertexShaderID, 1024, &stringBufferUsage, stringBuffer);
|
2014-08-15 12:09:53 -06:00
|
|
|
|
|
|
|
if (Result && stringBufferUsage)
|
|
|
|
{
|
2012-12-12 02:40:03 -07:00
|
|
|
ERROR_LOG(VIDEO, "GLSL vertex shader warnings:\n%s%s", stringBuffer, vertexShader);
|
2014-08-15 12:09:53 -06:00
|
|
|
}
|
|
|
|
else if (!Result)
|
|
|
|
{
|
2012-12-12 02:40:03 -07:00
|
|
|
ERROR_LOG(VIDEO, "GLSL vertex shader error:\n%s%s", stringBuffer, vertexShader);
|
2014-08-15 12:09:53 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-12 02:40:03 -07:00
|
|
|
DEBUG_LOG(VIDEO, "GLSL vertex shader compiled:\n%s", vertexShader);
|
|
|
|
}
|
2014-08-15 12:09:53 -06:00
|
|
|
|
2012-12-12 02:40:03 -07:00
|
|
|
bool shader_errors = !Result;
|
|
|
|
#endif
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2012-12-12 02:40:03 -07:00
|
|
|
// compile fragment shader
|
2014-03-09 14:14:26 -06:00
|
|
|
glShaderSource(fragmentShaderID, 1, &fragmentShader, nullptr);
|
2012-12-12 02:40:03 -07:00
|
|
|
glCompileShader(fragmentShaderID);
|
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST) || defined(DEBUG_GLSL)
|
|
|
|
glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &Result);
|
|
|
|
glGetShaderInfoLog(fragmentShaderID, 1024, &stringBufferUsage, stringBuffer);
|
2014-08-15 12:09:53 -06:00
|
|
|
|
|
|
|
if (Result && stringBufferUsage)
|
|
|
|
{
|
2012-12-12 02:40:03 -07:00
|
|
|
ERROR_LOG(VIDEO, "GLSL fragment shader warnings:\n%s%s", stringBuffer, fragmentShader);
|
2014-08-15 12:09:53 -06:00
|
|
|
}
|
|
|
|
else if (!Result)
|
|
|
|
{
|
2012-12-12 02:40:03 -07:00
|
|
|
ERROR_LOG(VIDEO, "GLSL fragment shader error:\n%s%s", stringBuffer, fragmentShader);
|
2014-08-15 12:09:53 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-12 02:40:03 -07:00
|
|
|
DEBUG_LOG(VIDEO, "GLSL fragment shader compiled:\n%s", fragmentShader);
|
|
|
|
}
|
2014-08-15 12:09:53 -06:00
|
|
|
|
2012-12-12 02:40:03 -07:00
|
|
|
shader_errors |= !Result;
|
|
|
|
#endif
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2012-12-12 02:40:03 -07: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-08-15 12:09:53 -06:00
|
|
|
|
|
|
|
if (Result && stringBufferUsage)
|
|
|
|
{
|
2012-12-12 02:40:03 -07:00
|
|
|
ERROR_LOG(VIDEO, "GLSL linker warnings:\n%s%s%s", stringBuffer, vertexShader, fragmentShader);
|
2014-08-15 12:09:53 -06:00
|
|
|
}
|
|
|
|
else if (!Result && !shader_errors)
|
|
|
|
{
|
2012-12-12 02:40:03 -07:00
|
|
|
ERROR_LOG(VIDEO, "GLSL linker error:\n%s%s%s", stringBuffer, vertexShader, fragmentShader);
|
|
|
|
}
|
|
|
|
#endif
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2012-12-12 02:40:03 -07:00
|
|
|
// cleanup
|
|
|
|
glDeleteShader(vertexShaderID);
|
|
|
|
glDeleteShader(fragmentShaderID);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2012-12-12 02:40:03 -07:00
|
|
|
return programID;
|
|
|
|
}
|
|
|
|
|
2014-12-11 02:00:37 -07:00
|
|
|
void OpenGL_CreateAttributelessVAO()
|
2014-12-04 00:24:58 -07:00
|
|
|
{
|
|
|
|
glGenVertexArrays(1, &attributelessVAO);
|
2014-12-11 02:00:37 -07:00
|
|
|
_dbg_assert_msg_(VIDEO, attributelessVAO != 0, "Attributeless VAO should have been created successfully.")
|
2014-12-04 00:24:58 -07:00
|
|
|
|
|
|
|
// In a compatibility context, we require a valid, bound array buffer.
|
|
|
|
glGenBuffers(1, &attributelessVBO);
|
2014-12-11 02:00:37 -07:00
|
|
|
_dbg_assert_msg_(VIDEO, attributelessVBO != 0, "Attributeless VBO should have been created successfully.")
|
2014-12-04 00:24:58 -07:00
|
|
|
|
2014-12-16 23:20:45 -07:00
|
|
|
// Initialize the buffer with nothing. 16 floats is an arbitrary size that may work around driver issues.
|
2014-12-04 00:24:58 -07:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, attributelessVBO);
|
2014-12-16 23:20:45 -07:00
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 16, nullptr, GL_STATIC_DRAW);
|
2014-12-04 00:24:58 -07:00
|
|
|
|
|
|
|
// We must also define vertex attribute 0.
|
2014-12-13 22:01:29 -07:00
|
|
|
glBindVertexArray(attributelessVAO);
|
2014-12-04 00:24:58 -07:00
|
|
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
|
2014-12-16 23:20:45 -07:00
|
|
|
glEnableVertexAttribArray(0);
|
2014-12-04 00:24:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGL_BindAttributelessVAO()
|
|
|
|
{
|
2014-12-11 02:00:37 -07:00
|
|
|
_dbg_assert_msg_(VIDEO, attributelessVAO != 0, "Attributeless VAO should have already been created.")
|
2014-12-04 00:24:58 -07:00
|
|
|
glBindVertexArray(attributelessVAO);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGL_DeleteAttributelessVAO()
|
|
|
|
{
|
2014-12-11 02:00:37 -07:00
|
|
|
_dbg_assert_msg_(VIDEO, attributelessVAO != 0, "Attributeless VAO should have already been created.")
|
|
|
|
if (attributelessVAO != 0)
|
2014-12-11 00:19:18 -07:00
|
|
|
{
|
|
|
|
glDeleteVertexArrays(1, &attributelessVAO);
|
|
|
|
glDeleteBuffers(1, &attributelessVBO);
|
2014-12-10 21:11:48 -07:00
|
|
|
|
2014-12-11 00:19:18 -07:00
|
|
|
attributelessVAO = 0;
|
|
|
|
attributelessVBO = 0;
|
|
|
|
}
|
2014-12-04 00:24:58 -07:00
|
|
|
}
|