From 704e3f2f0d8bb1b8ab4615754e8ed75a8a323fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Wed, 16 Jun 2021 01:40:52 +0200 Subject: [PATCH] Improved code for loading and linking shaders --- src/graphics/opengl/glutil.cpp | 11 +++++++---- src/graphics/opengl/glutil.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/graphics/opengl/glutil.cpp b/src/graphics/opengl/glutil.cpp index 97ccdd4c..3c812ed9 100644 --- a/src/graphics/opengl/glutil.cpp +++ b/src/graphics/opengl/glutil.cpp @@ -471,9 +471,12 @@ GLint LoadShader(GLint type, const char* filename) return 0; } - GLchar source[65536]; - GLchar *sources[] = { source }; - int length = PHYSFS_read(file, source, 1, 65536); + size_t len = PHYSFS_fileLength(file); + + std::vector source(len + 1); + + GLchar *sources[] = { source.data() }; + size_t length = PHYSFS_read(file, source.data(), 1, len); source[length] = '\0'; PHYSFS_close(file); @@ -503,7 +506,7 @@ GLint LoadShader(GLint type, const char* filename) return shader; } -GLint LinkProgram(int count, GLint shaders[]) +GLint LinkProgram(int count, const GLint* shaders) { GLint program = glCreateProgram(); diff --git a/src/graphics/opengl/glutil.h b/src/graphics/opengl/glutil.h index f92888a4..c205a0cc 100644 --- a/src/graphics/opengl/glutil.h +++ b/src/graphics/opengl/glutil.h @@ -99,7 +99,7 @@ std::string GetLastShaderError(); GLint LoadShader(GLint type, const char* filename); -GLint LinkProgram(int count, GLint shaders[]); +GLint LinkProgram(int count, const GLint* shaders); // TODO: Moved this here temporarily only to remove code duplication in CGLDeviceXX struct PreparedTextureData