do binding of VS inputs and FS outputs before linking shader programs, as per OpenGL standard.

should fix the rendering issues with strict drivers (AMD, Intel).
This commit is contained in:
Arisotura 2019-05-31 02:26:13 +02:00
parent 6f5e45ef2c
commit 06e08b053f
4 changed files with 37 additions and 15 deletions

View File

@ -148,9 +148,6 @@ bool BuildRenderShader(u32 flags, const char* vs, const char* fs)
GLuint prog = RenderShader[flags][2];
GLint uni_id = glGetUniformBlockIndex(prog, "uConfig");
glUniformBlockBinding(prog, uni_id, 0);
glBindAttribLocation(prog, 0, "vPosition");
glBindAttribLocation(prog, 1, "vColor");
glBindAttribLocation(prog, 2, "vTexcoord");
@ -158,6 +155,12 @@ bool BuildRenderShader(u32 flags, const char* vs, const char* fs)
glBindFragDataLocation(prog, 0, "oColor");
glBindFragDataLocation(prog, 1, "oAttr");
if (!OpenGL_LinkShaderProgram(RenderShader[flags]))
return false;
GLint uni_id = glGetUniformBlockIndex(prog, "uConfig");
glUniformBlockBinding(prog, uni_id, 0);
glUseProgram(prog);
uni_id = glGetUniformLocation(prog, "TexMem");
@ -202,6 +205,10 @@ bool Init()
glBindAttribLocation(ClearShaderPlain[2], 0, "vPosition");
glBindFragDataLocation(ClearShaderPlain[2], 0, "oColor");
glBindFragDataLocation(ClearShaderPlain[2], 1, "oAttr");
if (!OpenGL_LinkShaderProgram(ClearShaderPlain))
return false;
ClearUniformLoc[0] = glGetUniformLocation(ClearShaderPlain[2], "uColor");
ClearUniformLoc[1] = glGetUniformLocation(ClearShaderPlain[2], "uDepth");
ClearUniformLoc[2] = glGetUniformLocation(ClearShaderPlain[2], "uOpaquePolyID");
@ -226,12 +233,15 @@ bool Init()
if (!OpenGL_BuildShaderProgram(kFinalPassVS, kFinalPassFS, FinalPassShader, "FinalPassShader"))
return false;
uni_id = glGetUniformBlockIndex(FinalPassShader[2], "uConfig");
glUniformBlockBinding(FinalPassShader[2], uni_id, 0);
glBindAttribLocation(FinalPassShader[2], 0, "vPosition");
glBindFragDataLocation(FinalPassShader[2], 0, "oColor");
if (!OpenGL_LinkShaderProgram(FinalPassShader))
return false;
uni_id = glGetUniformBlockIndex(FinalPassShader[2], "uConfig");
glUniformBlockBinding(FinalPassShader[2], uni_id, 0);
glUseProgram(FinalPassShader[2]);
uni_id = glGetUniformLocation(FinalPassShader[2], "DepthBuffer");

View File

@ -85,6 +85,14 @@ bool OpenGL_BuildShaderProgram(const char* vs, const char* fs, GLuint* ids, cons
ids[2] = glCreateProgram();
glAttachShader(ids[2], ids[0]);
glAttachShader(ids[2], ids[1]);
return true;
}
bool OpenGL_LinkShaderProgram(GLuint* ids)
{
int res;
glLinkProgram(ids[2]);
glGetProgramiv(ids[2], GL_LINK_STATUS, &res);
@ -94,7 +102,7 @@ bool OpenGL_BuildShaderProgram(const char* vs, const char* fs, GLuint* ids, cons
if (res < 1) res = 1024;
char* log = new char[res+1];
glGetProgramInfoLog(ids[2], res+1, NULL, log);
printf("OpenGL: failed to link program %s: %s\n", name, log);
printf("OpenGL: failed to link shader program: %s\n", log);
delete[] log;
glDeleteShader(ids[0]);

View File

@ -49,7 +49,7 @@
#ifndef __WIN32__
#define DO_PROCLIST_1_3(func)
#define DO_PROCLIST_1_3(func)
#else
@ -131,6 +131,7 @@ DO_PROCLIST(DECLPROC_EXT);
bool OpenGL_Init();
bool OpenGL_BuildShaderProgram(const char* vs, const char* fs, GLuint* ids, const char* name);
bool OpenGL_LinkShaderProgram(GLuint* ids);
void OpenGL_DeleteShaderProgram(GLuint* ids);
void OpenGL_UseShaderProgram(GLuint* ids);

View File

@ -175,6 +175,13 @@ bool GLScreen_InitShader(GLuint* shader, const char* fs)
if (!OpenGL_BuildShaderProgram(kScreenVS, fs, shader, "ScreenShader"))
return false;
glBindAttribLocation(shader[2], 0, "vPosition");
glBindAttribLocation(shader[2], 1, "vTexcoord");
glBindFragDataLocation(shader[2], 0, "oColor");
if (!OpenGL_LinkShaderProgram(shader))
return false;
GLuint uni_id;
uni_id = glGetUniformBlockIndex(shader[2], "uConfig");
@ -186,10 +193,6 @@ bool GLScreen_InitShader(GLuint* shader, const char* fs)
uni_id = glGetUniformLocation(shader[2], "_3DTex");
glUniform1i(uni_id, 1);
glBindAttribLocation(shader[2], 0, "vPosition");
glBindAttribLocation(shader[2], 1, "vTexcoord");
glBindFragDataLocation(shader[2], 0, "oColor");
return true;
}
@ -198,7 +201,7 @@ bool GLScreen_Init()
// TODO: consider using epoxy?
if (!OpenGL_Init())
return false;
const GLubyte* renderer = glGetString(GL_RENDERER); // get renderer string
const GLubyte* version = glGetString(GL_VERSION); // version as a string
printf("OpenGL: renderer: %s\n", renderer);
@ -255,7 +258,7 @@ void GLScreen_DeInit()
void GLScreen_DrawScreen()
{
float scale = uiGLGetFramebufferScale(GLContext);
if (GL_ScreenSizeDirty)
{
GL_ScreenSizeDirty = false;
@ -2540,7 +2543,7 @@ int main(int argc, char** argv)
if (MicDevice) SDL_CloseAudioDevice(MicDevice);
if (MicWavBuffer) delete[] MicWavBuffer;
if (ScreenBitmap[0]) uiDrawFreeBitmap(ScreenBitmap[0]);
if (ScreenBitmap[1]) uiDrawFreeBitmap(ScreenBitmap[1]);