Files
dolphin/Source/Core/VideoBackends/OGL/GLUtil.cpp
T

155 lines
4.4 KiB
C++
Raw Normal View History

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