Skip to content

Commit

Permalink
do binding of VS inputs and FS outputs before linking shader programs…
Browse files Browse the repository at this point in the history
…, as per OpenGL standard.

should fix the rendering issues with strict drivers (AMD, Intel).
  • Loading branch information
Arisotura committed May 31, 2019
1 parent 6f5e45e commit 06e08b0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
22 changes: 16 additions & 6 deletions src/GPU3D_OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,19 @@ 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");
glBindAttribLocation(prog, 3, "vPolygonAttr");
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");
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
10 changes: 9 additions & 1 deletion src/OpenGLSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]);
Expand Down
3 changes: 2 additions & 1 deletion src/OpenGLSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

#ifndef __WIN32__

#define DO_PROCLIST_1_3(func)
#define DO_PROCLIST_1_3(func)

#else

Expand Down Expand Up @@ -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);

Expand Down
17 changes: 10 additions & 7 deletions src/libui_sdl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -255,7 +258,7 @@ void GLScreen_DeInit()
void GLScreen_DrawScreen()
{
float scale = uiGLGetFramebufferScale(GLContext);

if (GL_ScreenSizeDirty)
{
GL_ScreenSizeDirty = false;
Expand Down Expand Up @@ -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]);

Expand Down

0 comments on commit 06e08b0

Please sign in to comment.