diff options
-rw-r--r-- | src/GPU3D_OpenGL.cpp | 22 | ||||
-rw-r--r-- | src/OpenGLSupport.cpp | 10 | ||||
-rw-r--r-- | src/OpenGLSupport.h | 3 | ||||
-rw-r--r-- | src/libui_sdl/main.cpp | 17 |
4 files changed, 37 insertions, 15 deletions
diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index 95243d1..1fd266f 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -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"); diff --git a/src/OpenGLSupport.cpp b/src/OpenGLSupport.cpp index 11fd629..59424b4 100644 --- a/src/OpenGLSupport.cpp +++ b/src/OpenGLSupport.cpp @@ -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]); diff --git a/src/OpenGLSupport.h b/src/OpenGLSupport.h index 31a0dc0..a4d6124 100644 --- a/src/OpenGLSupport.h +++ b/src/OpenGLSupport.h @@ -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); diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 33a35d0..5408586 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -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]); |