2014-09-07 15:27:49 +00:00
|
|
|
/* * Copyright (C) 2011-2014 Gregory hainaut
|
2013-01-14 09:15:39 +00:00
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
*
|
|
|
|
* This Program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This Program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "GLLoader.h"
|
2013-05-27 16:53:38 +00:00
|
|
|
#include "GSdx.h"
|
2013-01-14 09:15:39 +00:00
|
|
|
|
2014-09-07 15:27:49 +00:00
|
|
|
PFNGLACTIVETEXTUREPROC gl_ActiveTexture = NULL;
|
|
|
|
PFNGLBLENDCOLORPROC gl_BlendColor = NULL;
|
|
|
|
PFNGLATTACHSHADERPROC gl_AttachShader = NULL;
|
|
|
|
PFNGLBINDBUFFERPROC gl_BindBuffer = NULL;
|
|
|
|
PFNGLBINDBUFFERBASEPROC gl_BindBufferBase = NULL;
|
2015-08-15 07:57:32 +00:00
|
|
|
PFNGLBINDBUFFERRANGEPROC gl_BindBufferRange = NULL;
|
2014-09-07 15:27:49 +00:00
|
|
|
PFNGLBINDFRAMEBUFFERPROC gl_BindFramebuffer = NULL;
|
|
|
|
PFNGLBINDSAMPLERPROC gl_BindSampler = NULL;
|
|
|
|
PFNGLBINDVERTEXARRAYPROC gl_BindVertexArray = NULL;
|
|
|
|
PFNGLBLENDEQUATIONSEPARATEIARBPROC gl_BlendEquationSeparateiARB = NULL;
|
|
|
|
PFNGLBLENDFUNCSEPARATEIARBPROC gl_BlendFuncSeparateiARB = NULL;
|
|
|
|
PFNGLBLITFRAMEBUFFERPROC gl_BlitFramebuffer = NULL;
|
|
|
|
PFNGLBUFFERDATAPROC gl_BufferData = NULL;
|
|
|
|
PFNGLCHECKFRAMEBUFFERSTATUSPROC gl_CheckFramebufferStatus = NULL;
|
|
|
|
PFNGLCLEARBUFFERFVPROC gl_ClearBufferfv = NULL;
|
|
|
|
PFNGLCLEARBUFFERIVPROC gl_ClearBufferiv = NULL;
|
|
|
|
PFNGLCLEARBUFFERUIVPROC gl_ClearBufferuiv = NULL;
|
|
|
|
PFNGLCOLORMASKIPROC gl_ColorMaski = NULL;
|
|
|
|
PFNGLCOMPILESHADERPROC gl_CompileShader = NULL;
|
|
|
|
PFNGLCREATEPROGRAMPROC gl_CreateProgram = NULL;
|
|
|
|
PFNGLCREATESHADERPROC gl_CreateShader = NULL;
|
|
|
|
PFNGLCREATESHADERPROGRAMVPROC gl_CreateShaderProgramv = NULL;
|
|
|
|
PFNGLDELETEBUFFERSPROC gl_DeleteBuffers = NULL;
|
|
|
|
PFNGLDELETEFRAMEBUFFERSPROC gl_DeleteFramebuffers = NULL;
|
|
|
|
PFNGLDELETEPROGRAMPROC gl_DeleteProgram = NULL;
|
|
|
|
PFNGLDELETESAMPLERSPROC gl_DeleteSamplers = NULL;
|
|
|
|
PFNGLDELETESHADERPROC gl_DeleteShader = NULL;
|
|
|
|
PFNGLDELETEVERTEXARRAYSPROC gl_DeleteVertexArrays = NULL;
|
|
|
|
PFNGLDETACHSHADERPROC gl_DetachShader = NULL;
|
|
|
|
PFNGLDRAWBUFFERSPROC gl_DrawBuffers = NULL;
|
|
|
|
PFNGLDRAWELEMENTSBASEVERTEXPROC gl_DrawElementsBaseVertex = NULL;
|
|
|
|
PFNGLENABLEVERTEXATTRIBARRAYPROC gl_EnableVertexAttribArray = NULL;
|
|
|
|
PFNGLFRAMEBUFFERRENDERBUFFERPROC gl_FramebufferRenderbuffer = NULL;
|
|
|
|
PFNGLFRAMEBUFFERTEXTURE2DPROC gl_FramebufferTexture2D = NULL;
|
|
|
|
PFNGLGENBUFFERSPROC gl_GenBuffers = NULL;
|
|
|
|
PFNGLGENFRAMEBUFFERSPROC gl_GenFramebuffers = NULL;
|
|
|
|
PFNGLGENSAMPLERSPROC gl_GenSamplers = NULL;
|
|
|
|
PFNGLGENVERTEXARRAYSPROC gl_GenVertexArrays = NULL;
|
|
|
|
PFNGLGETBUFFERPARAMETERIVPROC gl_GetBufferParameteriv = NULL;
|
|
|
|
PFNGLGETDEBUGMESSAGELOGARBPROC gl_GetDebugMessageLogARB = NULL;
|
2014-09-27 16:57:17 +00:00
|
|
|
PFNGLDEBUGMESSAGECALLBACKPROC gl_DebugMessageCallback = NULL;
|
2014-09-07 15:27:49 +00:00
|
|
|
PFNGLGETPROGRAMINFOLOGPROC gl_GetProgramInfoLog = NULL;
|
|
|
|
PFNGLGETPROGRAMIVPROC gl_GetProgramiv = NULL;
|
|
|
|
PFNGLGETSHADERIVPROC gl_GetShaderiv = NULL;
|
|
|
|
PFNGLGETSTRINGIPROC gl_GetStringi = NULL;
|
|
|
|
PFNGLISFRAMEBUFFERPROC gl_IsFramebuffer = NULL;
|
|
|
|
PFNGLLINKPROGRAMPROC gl_LinkProgram = NULL;
|
|
|
|
PFNGLMAPBUFFERPROC gl_MapBuffer = NULL;
|
|
|
|
PFNGLMAPBUFFERRANGEPROC gl_MapBufferRange = NULL;
|
|
|
|
PFNGLPROGRAMPARAMETERIPROC gl_ProgramParameteri = NULL;
|
|
|
|
PFNGLSAMPLERPARAMETERFPROC gl_SamplerParameterf = NULL;
|
|
|
|
PFNGLSAMPLERPARAMETERIPROC gl_SamplerParameteri = NULL;
|
|
|
|
PFNGLSHADERSOURCEPROC gl_ShaderSource = NULL;
|
|
|
|
PFNGLUNIFORM1IPROC gl_Uniform1i = NULL;
|
|
|
|
PFNGLUNMAPBUFFERPROC gl_UnmapBuffer = NULL;
|
|
|
|
PFNGLUSEPROGRAMSTAGESPROC gl_UseProgramStages = NULL;
|
|
|
|
PFNGLVERTEXATTRIBIPOINTERPROC gl_VertexAttribIPointer = NULL;
|
|
|
|
PFNGLVERTEXATTRIBPOINTERPROC gl_VertexAttribPointer = NULL;
|
|
|
|
PFNGLBUFFERSUBDATAPROC gl_BufferSubData = NULL;
|
|
|
|
PFNGLFENCESYNCPROC gl_FenceSync = NULL;
|
|
|
|
PFNGLDELETESYNCPROC gl_DeleteSync = NULL;
|
|
|
|
PFNGLCLIENTWAITSYNCPROC gl_ClientWaitSync = NULL;
|
|
|
|
PFNGLFLUSHMAPPEDBUFFERRANGEPROC gl_FlushMappedBufferRange = NULL;
|
2015-06-10 20:55:27 +00:00
|
|
|
PFNGLBLENDEQUATIONSEPARATEPROC gl_BlendEquationSeparate = NULL;
|
|
|
|
PFNGLBLENDFUNCSEPARATEPROC gl_BlendFuncSeparate = NULL;
|
2013-08-10 19:43:59 +00:00
|
|
|
// GL4.0
|
|
|
|
// GL4.1
|
2014-09-07 15:27:49 +00:00
|
|
|
PFNGLBINDPROGRAMPIPELINEPROC gl_BindProgramPipeline = NULL;
|
|
|
|
PFNGLGENPROGRAMPIPELINESPROC gl_GenProgramPipelines = NULL;
|
|
|
|
PFNGLDELETEPROGRAMPIPELINESPROC gl_DeleteProgramPipelines = NULL;
|
|
|
|
PFNGLGETPROGRAMPIPELINEIVPROC gl_GetProgramPipelineiv = NULL;
|
|
|
|
PFNGLVALIDATEPROGRAMPIPELINEPROC gl_ValidateProgramPipeline = NULL;
|
|
|
|
PFNGLGETPROGRAMPIPELINEINFOLOGPROC gl_GetProgramPipelineInfoLog = NULL;
|
2015-07-15 06:59:16 +00:00
|
|
|
PFNGLGETPROGRAMBINARYPROC gl_GetProgramBinary = NULL;
|
2013-05-19 12:42:55 +00:00
|
|
|
// NO GL4.1
|
2014-09-07 15:27:49 +00:00
|
|
|
PFNGLUSEPROGRAMPROC gl_UseProgram = NULL;
|
|
|
|
PFNGLGETSHADERINFOLOGPROC gl_GetShaderInfoLog = NULL;
|
|
|
|
PFNGLPROGRAMUNIFORM1IPROC gl_ProgramUniform1i = NULL;
|
2013-08-03 08:29:01 +00:00
|
|
|
// GL4.3
|
2014-09-07 15:27:49 +00:00
|
|
|
PFNGLCOPYIMAGESUBDATAPROC gl_CopyImageSubData = NULL;
|
2015-04-25 10:44:59 +00:00
|
|
|
PFNGLINVALIDATETEXIMAGEPROC gl_InvalidateTexImage = NULL;
|
2015-05-06 16:52:51 +00:00
|
|
|
PFNGLPUSHDEBUGGROUPPROC gl_PushDebugGroup = NULL;
|
|
|
|
PFNGLPOPDEBUGGROUPPROC gl_PopDebugGroup = NULL;
|
2015-05-07 22:16:31 +00:00
|
|
|
PFNGLDEBUGMESSAGEINSERTPROC gl_DebugMessageInsert = NULL;
|
2013-07-28 14:40:43 +00:00
|
|
|
// GL4.2
|
2014-09-07 15:27:49 +00:00
|
|
|
PFNGLBINDIMAGETEXTUREPROC gl_BindImageTexture = NULL;
|
|
|
|
PFNGLMEMORYBARRIERPROC gl_MemoryBarrier = NULL;
|
|
|
|
PFNGLTEXSTORAGE2DPROC gl_TexStorage2D = NULL;
|
2013-08-02 16:38:12 +00:00
|
|
|
// GL4.4
|
2015-05-15 18:58:14 +00:00
|
|
|
PFNGLCLEARTEXIMAGEPROC gl_ClearTexImage = NULL;
|
2014-09-07 15:27:49 +00:00
|
|
|
PFNGLBUFFERSTORAGEPROC gl_BufferStorage = NULL;
|
|
|
|
|
|
|
|
// GL4.5
|
|
|
|
PFNGLCREATETEXTURESPROC gl_CreateTextures = NULL;
|
|
|
|
PFNGLTEXTURESTORAGE2DPROC gl_TextureStorage2D = NULL;
|
|
|
|
PFNGLTEXTURESUBIMAGE2DPROC gl_TextureSubImage2D = NULL;
|
|
|
|
PFNGLCOPYTEXTURESUBIMAGE2DPROC gl_CopyTextureSubImage2D = NULL;
|
|
|
|
PFNGLBINDTEXTUREUNITPROC gl_BindTextureUnit = NULL;
|
|
|
|
PFNGLGETTEXTUREIMAGEPROC gl_GetTextureImage = NULL;
|
2015-06-14 08:02:30 +00:00
|
|
|
PFNGLTEXTUREPARAMETERIPROC gl_TextureParameteri = NULL;
|
2014-09-07 15:27:49 +00:00
|
|
|
|
|
|
|
PFNGLCREATEFRAMEBUFFERSPROC gl_CreateFramebuffers = NULL;
|
|
|
|
PFNGLCLEARNAMEDFRAMEBUFFERFVPROC gl_ClearNamedFramebufferfv = NULL;
|
|
|
|
PFNGLCLEARNAMEDFRAMEBUFFERIVPROC gl_ClearNamedFramebufferiv = NULL;
|
|
|
|
PFNGLCLEARNAMEDFRAMEBUFFERUIVPROC gl_ClearNamedFramebufferuiv = NULL;
|
|
|
|
PFNGLNAMEDFRAMEBUFFERTEXTUREPROC gl_NamedFramebufferTexture = NULL;
|
|
|
|
PFNGLNAMEDFRAMEBUFFERDRAWBUFFERSPROC gl_NamedFramebufferDrawBuffers = NULL;
|
|
|
|
PFNGLNAMEDFRAMEBUFFERREADBUFFERPROC gl_NamedFramebufferReadBuffer = NULL;
|
|
|
|
PFNGLCHECKNAMEDFRAMEBUFFERSTATUSPROC gl_CheckNamedFramebufferStatus = NULL;
|
|
|
|
|
|
|
|
PFNGLCREATEBUFFERSPROC gl_CreateBuffers = NULL;
|
|
|
|
PFNGLNAMEDBUFFERSTORAGEPROC gl_NamedBufferStorage = NULL;
|
|
|
|
PFNGLNAMEDBUFFERDATAPROC gl_NamedBufferData = NULL;
|
|
|
|
PFNGLNAMEDBUFFERSUBDATAPROC gl_NamedBufferSubData = NULL;
|
|
|
|
PFNGLMAPNAMEDBUFFERPROC gl_MapNamedBuffer = NULL;
|
|
|
|
PFNGLMAPNAMEDBUFFERRANGEPROC gl_MapNamedBufferRange = NULL;
|
|
|
|
PFNGLUNMAPNAMEDBUFFERPROC gl_UnmapNamedBuffer = NULL;
|
2015-04-25 09:41:46 +00:00
|
|
|
PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEPROC gl_FlushMappedNamedBufferRange = NULL;
|
2014-09-07 15:27:49 +00:00
|
|
|
|
|
|
|
PFNGLCREATESAMPLERSPROC gl_CreateSamplers = NULL;
|
|
|
|
PFNGLCREATEPROGRAMPIPELINESPROC gl_CreateProgramPipelines = NULL;
|
|
|
|
|
|
|
|
PFNGLCLIPCONTROLPROC gl_ClipControl = NULL;
|
2015-04-22 18:38:22 +00:00
|
|
|
PFNGLTEXTUREBARRIERPROC gl_TextureBarrier = NULL;
|
2014-01-31 21:30:54 +00:00
|
|
|
|
2015-04-24 17:32:00 +00:00
|
|
|
namespace Emulate_DSA {
|
2015-04-25 09:41:46 +00:00
|
|
|
// Texture entry point
|
2015-04-24 23:32:09 +00:00
|
|
|
void APIENTRY BindTextureUnit(GLuint unit, GLuint texture) {
|
2015-04-24 17:32:00 +00:00
|
|
|
gl_ActiveTexture(GL_TEXTURE0 + unit);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
}
|
|
|
|
|
2015-04-24 23:32:09 +00:00
|
|
|
void APIENTRY CreateTexture(GLenum target, GLsizei n, GLuint *textures) {
|
2015-04-24 17:32:00 +00:00
|
|
|
glGenTextures(1, textures);
|
|
|
|
}
|
|
|
|
|
2015-04-24 23:32:09 +00:00
|
|
|
void APIENTRY TextureStorage(GLuint texture, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height) {
|
2015-04-24 17:32:00 +00:00
|
|
|
BindTextureUnit(7, texture);
|
|
|
|
gl_TexStorage2D(GL_TEXTURE_2D, levels, internalformat, width, height);
|
|
|
|
}
|
|
|
|
|
2015-04-24 23:32:09 +00:00
|
|
|
void APIENTRY TextureSubImage(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels) {
|
2015-04-24 17:32:00 +00:00
|
|
|
BindTextureUnit(7, texture);
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, level, xoffset, yoffset, width, height, format, type, pixels);
|
|
|
|
}
|
|
|
|
|
2015-04-24 23:32:09 +00:00
|
|
|
void APIENTRY CopyTextureSubImage(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {
|
2015-04-24 17:32:00 +00:00
|
|
|
BindTextureUnit(7, texture);
|
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, level, xoffset, yoffset, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2015-04-24 23:32:09 +00:00
|
|
|
void APIENTRY GetTexureImage(GLuint texture, GLint level, GLenum format, GLenum type, GLsizei bufSize, void *pixels) {
|
2015-04-24 17:32:00 +00:00
|
|
|
BindTextureUnit(7, texture);
|
|
|
|
glGetTexImage(GL_TEXTURE_2D, level, format, type, pixels);
|
|
|
|
}
|
|
|
|
|
2015-06-14 08:02:30 +00:00
|
|
|
void APIENTRY TextureParameteri (GLuint texture, GLenum pname, GLint param) {
|
|
|
|
BindTextureUnit(7, texture);
|
2015-06-25 08:25:24 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, pname, param);
|
2015-06-14 08:02:30 +00:00
|
|
|
}
|
|
|
|
|
2015-04-25 09:41:46 +00:00
|
|
|
// Framebuffer entry point
|
2015-04-25 10:06:30 +00:00
|
|
|
GLenum fb_target = 0;
|
|
|
|
void SetFramebufferTarget(GLenum target) {
|
|
|
|
fb_target = target;
|
|
|
|
}
|
|
|
|
|
2015-04-25 09:41:46 +00:00
|
|
|
void APIENTRY CreateFramebuffers(GLsizei n, GLuint *framebuffers) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_GenFramebuffers(n, framebuffers);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY ClearNamedFramebufferfv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat *value) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindFramebuffer(fb_target, framebuffer);
|
|
|
|
gl_ClearBufferfv(buffer, drawbuffer, value);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY ClearNamedFramebufferiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint *value) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindFramebuffer(fb_target, framebuffer);
|
|
|
|
gl_ClearBufferiv(buffer, drawbuffer, value);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY ClearNamedFramebufferuiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint *value) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindFramebuffer(fb_target, framebuffer);
|
|
|
|
gl_ClearBufferuiv(buffer, drawbuffer, value);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY NamedFramebufferTexture(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindFramebuffer(fb_target, framebuffer);
|
|
|
|
gl_FramebufferTexture2D(fb_target, attachment, GL_TEXTURE_2D, texture, level);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY NamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n, const GLenum *bufs) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindFramebuffer(fb_target, framebuffer);
|
|
|
|
gl_DrawBuffers(n, bufs);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY NamedFramebufferReadBuffer(GLuint framebuffer, GLenum src) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindFramebuffer(fb_target, framebuffer);
|
|
|
|
glReadBuffer(src);
|
2015-05-11 13:46:31 +00:00
|
|
|
gl_BindFramebuffer(fb_target, 0);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLenum APIENTRY CheckNamedFramebufferStatus(GLuint framebuffer, GLenum target) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindFramebuffer(fb_target, framebuffer);
|
|
|
|
return gl_CheckFramebufferStatus(fb_target);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Buffer entry point
|
2015-04-25 10:06:30 +00:00
|
|
|
GLenum buffer_target = 0;
|
|
|
|
void SetBufferTarget(GLenum target) {
|
|
|
|
buffer_target = target;
|
|
|
|
}
|
|
|
|
|
2015-04-25 09:41:46 +00:00
|
|
|
void APIENTRY CreateBuffers(GLsizei n, GLuint *buffers) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_GenBuffers(1, buffers);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY NamedBufferStorage(GLuint buffer, GLsizei size, const void *data, GLbitfield flags) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindBuffer(buffer_target, buffer);
|
|
|
|
gl_BufferStorage(buffer_target, size, data, flags);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY NamedBufferData(GLuint buffer, GLsizei size, const void *data, GLenum usage) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindBuffer(buffer_target, buffer);
|
|
|
|
gl_BufferData(buffer_target, size, data, usage);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY NamedBufferSubData(GLuint buffer, GLintptr offset, GLsizei size, const void *data) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindBuffer(buffer_target, buffer);
|
|
|
|
gl_BufferSubData(buffer_target, offset, size, data);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *APIENTRY MapNamedBuffer(GLuint buffer, GLenum access) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindBuffer(buffer_target, buffer);
|
|
|
|
return gl_MapBuffer(buffer_target, access);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *APIENTRY MapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizei length, GLbitfield access) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindBuffer(buffer_target, buffer);
|
|
|
|
return gl_MapBufferRange(buffer_target, offset, length, access);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLboolean APIENTRY UnmapNamedBuffer(GLuint buffer) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindBuffer(buffer_target, buffer);
|
|
|
|
return gl_UnmapBuffer(buffer_target);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY FlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizei length) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindBuffer(buffer_target, buffer);
|
|
|
|
gl_FlushMappedBufferRange(buffer_target, offset, length);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Misc entry point
|
|
|
|
// (only purpose is to have a consistent API otherwise it is useless)
|
|
|
|
void APIENTRY CreateProgramPipelines(GLsizei n, GLuint *pipelines) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_GenProgramPipelines(n, pipelines);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY CreateSamplers(GLsizei n, GLuint *samplers) {
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_GenSamplers(n, samplers);
|
2015-04-25 09:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Replace function pointer to emulate DSA behavior
|
2015-04-24 17:32:00 +00:00
|
|
|
void Init() {
|
2015-06-06 19:28:59 +00:00
|
|
|
fprintf(stderr, "DSA is not supported. Replacing the GL function pointer to emulate it\n");
|
2015-04-25 10:06:30 +00:00
|
|
|
gl_BindTextureUnit = BindTextureUnit;
|
|
|
|
gl_CreateTextures = CreateTexture;
|
|
|
|
gl_TextureStorage2D = TextureStorage;
|
|
|
|
gl_TextureSubImage2D = TextureSubImage;
|
|
|
|
gl_CopyTextureSubImage2D = CopyTextureSubImage;
|
|
|
|
gl_GetTextureImage = GetTexureImage;
|
2015-06-14 08:02:30 +00:00
|
|
|
gl_TextureParameteri = TextureParameteri;
|
2015-04-25 10:06:30 +00:00
|
|
|
|
|
|
|
gl_CreateFramebuffers = CreateFramebuffers;
|
|
|
|
gl_ClearNamedFramebufferfv = ClearNamedFramebufferfv;
|
|
|
|
gl_ClearNamedFramebufferiv = ClearNamedFramebufferiv;
|
|
|
|
gl_ClearNamedFramebufferuiv = ClearNamedFramebufferuiv;
|
|
|
|
gl_NamedFramebufferDrawBuffers = NamedFramebufferDrawBuffers;
|
|
|
|
gl_NamedFramebufferReadBuffer = NamedFramebufferReadBuffer;
|
|
|
|
gl_CheckNamedFramebufferStatus = CheckNamedFramebufferStatus;
|
|
|
|
|
|
|
|
gl_CreateBuffers = CreateBuffers;
|
|
|
|
gl_NamedBufferStorage = NamedBufferStorage;
|
|
|
|
gl_NamedBufferData = NamedBufferData;
|
|
|
|
gl_NamedBufferSubData = NamedBufferSubData;
|
|
|
|
gl_MapNamedBuffer = MapNamedBuffer;
|
|
|
|
gl_MapNamedBufferRange = MapNamedBufferRange;
|
|
|
|
gl_UnmapNamedBuffer = UnmapNamedBuffer;
|
|
|
|
gl_FlushMappedNamedBufferRange = FlushMappedNamedBufferRange;
|
|
|
|
|
|
|
|
gl_CreateProgramPipelines = CreateProgramPipelines;
|
|
|
|
gl_CreateSamplers = CreateSamplers;
|
2015-04-24 17:32:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-14 09:15:39 +00:00
|
|
|
namespace GLLoader {
|
|
|
|
|
2014-03-29 09:47:53 +00:00
|
|
|
bool fglrx_buggy_driver = false;
|
|
|
|
bool mesa_amd_buggy_driver = false;
|
|
|
|
bool nvidia_buggy_driver = false;
|
|
|
|
bool intel_buggy_driver = false;
|
|
|
|
bool in_replayer = false;
|
2013-07-11 17:08:42 +00:00
|
|
|
|
2015-08-07 12:46:57 +00:00
|
|
|
|
|
|
|
// GL4 hardware (due to proprietary driver limitation)
|
2014-10-01 07:50:59 +00:00
|
|
|
bool found_GL_ARB_separate_shader_objects = false; // Issue with Mesa and Catalyst...
|
2014-09-30 20:04:42 +00:00
|
|
|
bool found_geometry_shader = true; // we require GL3.3 so geometry must be supported by default
|
2015-05-02 08:53:19 +00:00
|
|
|
bool found_GL_EXT_texture_filter_anisotropic = false;
|
2015-05-15 18:58:14 +00:00
|
|
|
bool found_GL_ARB_clear_texture = false; // Don't know if GL3 GPU can support it
|
2014-11-01 19:17:08 +00:00
|
|
|
bool found_GL_ARB_buffer_storage = false;
|
2013-08-17 08:57:52 +00:00
|
|
|
bool found_GL_ARB_copy_image = false; // Not sure actually maybe GL3 GPU can do it
|
2013-06-16 16:33:08 +00:00
|
|
|
bool found_GL_ARB_gpu_shader5 = false;
|
2014-03-29 09:47:53 +00:00
|
|
|
bool found_GL_ARB_shader_image_load_store = false; // GLES3.1
|
2015-04-25 07:59:25 +00:00
|
|
|
bool found_GL_ARB_texture_barrier = false; // Well maybe supported by older hardware I don't know
|
2015-08-07 12:46:57 +00:00
|
|
|
// DX10 GPU limited driver
|
|
|
|
bool found_GL_ARB_draw_buffers_blend = false;
|
2014-09-07 15:27:49 +00:00
|
|
|
bool found_GL_ARB_clip_control = false;
|
|
|
|
bool found_GL_ARB_direct_state_access = false;
|
|
|
|
|
2013-08-03 08:29:01 +00:00
|
|
|
// Mandatory
|
|
|
|
bool found_GL_ARB_texture_storage = false;
|
2014-10-01 07:50:59 +00:00
|
|
|
bool found_GL_ARB_shading_language_420pack = false;
|
2013-08-03 08:29:01 +00:00
|
|
|
|
|
|
|
static bool status_and_override(bool& found, const std::string& name, bool mandatory = false)
|
|
|
|
{
|
2015-05-01 12:18:05 +00:00
|
|
|
if (mandatory) {
|
|
|
|
if (!found) {
|
2014-10-01 07:50:59 +00:00
|
|
|
fprintf(stderr, "ERROR: %s is NOT SUPPORTED\n", name.c_str());
|
|
|
|
}
|
2015-05-01 12:18:05 +00:00
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
fprintf(stderr, "INFO: %s is NOT SUPPORTED\n", name.c_str());
|
2014-02-01 11:11:14 +00:00
|
|
|
} else {
|
2014-09-07 15:27:49 +00:00
|
|
|
fprintf(stderr, "INFO: %s is available\n", name.c_str());
|
2013-08-03 08:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string opt("override_");
|
|
|
|
opt += name;
|
|
|
|
|
|
|
|
if (theApp.GetConfig(opt.c_str(), -1) != -1) {
|
|
|
|
found = !!theApp.GetConfig(opt.c_str(), -1);
|
|
|
|
fprintf(stderr, "Override %s detection (%s)\n", name.c_str(), found ? "Enabled" : "Disabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-05-19 12:42:55 +00:00
|
|
|
|
2015-07-13 10:35:55 +00:00
|
|
|
bool check_gl_version(int major, int minor) {
|
2013-05-19 12:42:55 +00:00
|
|
|
|
|
|
|
const GLubyte* s = glGetString(GL_VERSION);
|
2013-07-28 14:40:43 +00:00
|
|
|
if (s == NULL) {
|
|
|
|
fprintf(stderr, "Error: GLLoader failed to get GL version\n");
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-13 10:35:55 +00:00
|
|
|
GLuint v = 1;
|
|
|
|
while (s[v] != '\0' && s[v-1] != ' ') v++;
|
2013-05-19 12:42:55 +00:00
|
|
|
|
2013-06-11 11:14:26 +00:00
|
|
|
const char* vendor = (const char*)glGetString(GL_VENDOR);
|
2015-07-13 10:35:55 +00:00
|
|
|
fprintf(stderr, "OpenGL information. GPU: %s. Vendor: %s. Driver: %s\n", glGetString(GL_RENDERER), vendor, &s[v]);
|
2013-06-11 11:14:26 +00:00
|
|
|
|
2015-08-07 12:46:57 +00:00
|
|
|
// Name changed but driver is still bad!
|
2013-06-11 11:14:26 +00:00
|
|
|
if (strstr(vendor, "ATI") || strstr(vendor, "Advanced Micro Devices"))
|
2013-05-19 12:42:55 +00:00
|
|
|
fglrx_buggy_driver = true;
|
2013-07-11 17:08:42 +00:00
|
|
|
if (strstr(vendor, "NVIDIA Corporation"))
|
|
|
|
nvidia_buggy_driver = true;
|
2013-12-30 09:30:10 +00:00
|
|
|
if (strstr(vendor, "Intel"))
|
|
|
|
intel_buggy_driver = true;
|
2015-06-30 21:04:54 +00:00
|
|
|
if (strstr(vendor, "X.Org") || strstr(vendor, "nouveau")) // Note: it might actually catch nouveau too, but bugs are likely to be the same anyway
|
2014-03-29 09:47:53 +00:00
|
|
|
mesa_amd_buggy_driver = true;
|
2014-12-12 19:44:58 +00:00
|
|
|
if (strstr(vendor, "VMware")) // Assume worst case because I don't know the real status
|
|
|
|
mesa_amd_buggy_driver = intel_buggy_driver = true;
|
2013-01-14 09:15:39 +00:00
|
|
|
|
2015-06-16 16:32:23 +00:00
|
|
|
if (mesa_amd_buggy_driver) {
|
|
|
|
fprintf(stderr, "Buggy driver detected. Geometry shaders will be disabled\n");
|
|
|
|
found_geometry_shader = false;
|
|
|
|
}
|
2013-05-27 16:53:38 +00:00
|
|
|
if (theApp.GetConfig("override_geometry_shader", -1) != -1) {
|
|
|
|
found_geometry_shader = !!theApp.GetConfig("override_geometry_shader", -1);
|
2015-06-06 19:28:59 +00:00
|
|
|
fprintf(stderr, "Overriding geometry shaders detection\n");
|
2013-05-27 16:53:38 +00:00
|
|
|
}
|
2015-07-13 10:35:55 +00:00
|
|
|
|
|
|
|
GLint major_gl = 0;
|
|
|
|
GLint minor_gl = 0;
|
|
|
|
glGetIntegerv(GL_MAJOR_VERSION, &major_gl);
|
|
|
|
glGetIntegerv(GL_MINOR_VERSION, &minor_gl);
|
2013-01-14 09:15:39 +00:00
|
|
|
if ( (major_gl < major) || ( major_gl == major && minor_gl < minor ) ) {
|
2015-06-30 21:04:54 +00:00
|
|
|
fprintf(stderr, "OpenGL %d.%d is not supported. Only OpenGL %d.%d\n was found", major, minor, major_gl, minor_gl);
|
2013-01-14 09:15:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool check_gl_supported_extension() {
|
|
|
|
int max_ext = 0;
|
|
|
|
glGetIntegerv(GL_NUM_EXTENSIONS, &max_ext);
|
|
|
|
|
2013-05-19 09:19:20 +00:00
|
|
|
if (gl_GetStringi && max_ext) {
|
2013-01-14 09:15:39 +00:00
|
|
|
for (GLint i = 0; i < max_ext; i++) {
|
2013-05-19 09:19:20 +00:00
|
|
|
string ext((const char*)gl_GetStringi(GL_EXTENSIONS, i));
|
2015-05-02 08:53:19 +00:00
|
|
|
// Bonus
|
|
|
|
if (ext.compare("GL_EXT_texture_filter_anisotropic") == 0) found_GL_EXT_texture_filter_anisotropic = true;
|
2014-09-27 17:12:30 +00:00
|
|
|
// GL4.0
|
|
|
|
if (ext.compare("GL_ARB_gpu_shader5") == 0) found_GL_ARB_gpu_shader5 = true;
|
2015-05-29 16:38:19 +00:00
|
|
|
if (ext.compare("GL_ARB_draw_buffers_blend") == 0) found_GL_ARB_draw_buffers_blend = true;
|
2014-09-27 17:12:30 +00:00
|
|
|
// GL4.1
|
2013-01-14 09:15:39 +00:00
|
|
|
if (ext.compare("GL_ARB_separate_shader_objects") == 0) {
|
2014-08-23 15:09:38 +00:00
|
|
|
if (!fglrx_buggy_driver && !mesa_amd_buggy_driver && !intel_buggy_driver) found_GL_ARB_separate_shader_objects = true;
|
2013-06-01 09:29:57 +00:00
|
|
|
else fprintf(stderr, "Buggy driver detected, GL_ARB_separate_shader_objects will be disabled\n");
|
2013-01-14 09:15:39 +00:00
|
|
|
}
|
2014-09-27 17:12:30 +00:00
|
|
|
// GL4.2
|
|
|
|
if (ext.compare("GL_ARB_shading_language_420pack") == 0) found_GL_ARB_shading_language_420pack = true;
|
|
|
|
if (ext.compare("GL_ARB_texture_storage") == 0) found_GL_ARB_texture_storage = true;
|
2015-05-08 08:40:43 +00:00
|
|
|
if (ext.compare("GL_ARB_shader_image_load_store") == 0) found_GL_ARB_shader_image_load_store = true;
|
2014-09-27 17:12:30 +00:00
|
|
|
// GL4.3
|
|
|
|
if (ext.compare("GL_ARB_copy_image") == 0) found_GL_ARB_copy_image = true;
|
|
|
|
// GL4.4
|
|
|
|
if (ext.compare("GL_ARB_buffer_storage") == 0) found_GL_ARB_buffer_storage = true;
|
2015-05-15 18:58:14 +00:00
|
|
|
if (ext.compare("GL_ARB_clear_texture") == 0) found_GL_ARB_clear_texture = true;
|
2014-09-15 20:28:35 +00:00
|
|
|
// GL4.5
|
|
|
|
if (ext.compare("GL_ARB_direct_state_access") == 0) found_GL_ARB_direct_state_access = true;
|
|
|
|
if (ext.compare("GL_ARB_clip_control") == 0) found_GL_ARB_clip_control = true;
|
2015-04-25 07:59:25 +00:00
|
|
|
if (ext.compare("GL_ARB_texture_barrier") == 0) found_GL_ARB_texture_barrier = true;
|
2014-09-30 19:56:36 +00:00
|
|
|
|
|
|
|
//fprintf(stderr, "DEBUG ext: %s\n", ext.c_str());
|
2013-01-14 09:15:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-03 08:29:01 +00:00
|
|
|
bool status = true;
|
|
|
|
fprintf(stderr, "\n");
|
2013-01-14 09:15:39 +00:00
|
|
|
|
2015-05-02 08:53:19 +00:00
|
|
|
// Bonus
|
|
|
|
status &= status_and_override(found_GL_EXT_texture_filter_anisotropic, "GL_EXT_texture_filter_anisotropic");
|
2014-09-27 17:12:30 +00:00
|
|
|
// GL4.0
|
2015-05-02 08:53:19 +00:00
|
|
|
status &= status_and_override(found_GL_ARB_gpu_shader5, "GL_ARB_gpu_shader5");
|
2015-06-10 20:55:27 +00:00
|
|
|
status &= status_and_override(found_GL_ARB_draw_buffers_blend, "GL_ARB_draw_buffers_blend");
|
2014-09-27 17:12:30 +00:00
|
|
|
// GL4.1
|
2015-05-02 08:53:19 +00:00
|
|
|
status &= status_and_override(found_GL_ARB_separate_shader_objects, "GL_ARB_separate_shader_objects");
|
2014-09-27 17:12:30 +00:00
|
|
|
// GL4.2
|
2015-05-02 08:53:19 +00:00
|
|
|
status &= status_and_override(found_GL_ARB_shader_image_load_store, "GL_ARB_shader_image_load_store");
|
|
|
|
status &= status_and_override(found_GL_ARB_shading_language_420pack, "GL_ARB_shading_language_420pack", true);
|
2013-08-03 08:29:01 +00:00
|
|
|
status &= status_and_override(found_GL_ARB_texture_storage, "GL_ARB_texture_storage", true);
|
2014-09-27 17:12:30 +00:00
|
|
|
// GL4.3
|
|
|
|
status &= status_and_override(found_GL_ARB_copy_image, "GL_ARB_copy_image");
|
|
|
|
// GL4.4
|
|
|
|
status &= status_and_override(found_GL_ARB_buffer_storage,"GL_ARB_buffer_storage");
|
2015-05-15 18:58:14 +00:00
|
|
|
status &= status_and_override(found_GL_ARB_clear_texture,"GL_ARB_clear_texture");
|
2014-09-27 17:12:30 +00:00
|
|
|
// GL4.5
|
2014-09-07 15:27:49 +00:00
|
|
|
status &= status_and_override(found_GL_ARB_clip_control, "GL_ARB_clip_control");
|
2014-09-28 10:11:22 +00:00
|
|
|
status &= status_and_override(found_GL_ARB_direct_state_access, "GL_ARB_direct_state_access");
|
2015-04-25 07:59:25 +00:00
|
|
|
status &= status_and_override(found_GL_ARB_texture_barrier, "GL_ARB_texture_barrier");
|
2015-05-01 17:16:18 +00:00
|
|
|
|
2015-04-24 17:32:00 +00:00
|
|
|
if (!found_GL_ARB_direct_state_access) {
|
|
|
|
Emulate_DSA::Init();
|
|
|
|
}
|
2015-04-25 07:50:19 +00:00
|
|
|
if (gl_BindTextureUnit == NULL) {
|
|
|
|
fprintf(stderr, "FATAL ERROR !!!! Failed to setup DSA function pointer!!!\n");
|
|
|
|
status = false;
|
|
|
|
}
|
|
|
|
|
2015-05-09 16:33:28 +00:00
|
|
|
if (!found_GL_ARB_texture_barrier) {
|
2015-07-19 07:34:32 +00:00
|
|
|
fprintf(stderr, "Error GL_ARB_texture_barrier is not supported by your driver. You can't emulate correctly the GS blending unit! Sorry!\n");
|
|
|
|
theApp.SetConfig("accurate_blending_unit", 0);
|
2015-07-25 15:13:37 +00:00
|
|
|
theApp.SetConfig("accurate_date", 0);
|
2015-05-09 16:33:28 +00:00
|
|
|
}
|
|
|
|
|
2013-08-03 08:29:01 +00:00
|
|
|
fprintf(stderr, "\n");
|
2013-05-26 13:05:03 +00:00
|
|
|
|
2013-08-03 08:29:01 +00:00
|
|
|
return status;
|
2013-01-14 09:15:39 +00:00
|
|
|
}
|
|
|
|
}
|