From c6f4c0b6f0c54bb27911f198a64a681da537d8c2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 9 Sep 2014 10:03:34 +0200 Subject: [PATCH] - fixed: FMaterial's tex pointer could be accessed before it was set. - allow more than two texture units in shaders. --- src/gl/shaders/gl_shader.cpp | 10 ++++++++-- src/gl/textures/gl_material.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index 26a1b3159..72815f2e2 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -227,8 +227,14 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * glUseProgram(hShader); - tempindex = glGetUniformLocation(hShader, "texture2"); - if (tempindex > 0) glUniform1i(tempindex, 1); + // set up other texture units (if needed by the shader) + for (int i = 2; i<16; i++) + { + char stringbuf[20]; + mysnprintf(stringbuf, 20, "texture%d", i); + tempindex = glGetUniformLocation(hShader, stringbuf); + if (tempindex > 0) glUniform1i(tempindex, i - 1); + } glUseProgram(0); return !!linked; diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index 05fcb992b..7995b572b 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -405,6 +405,7 @@ int FMaterial::mMaxBound; FMaterial::FMaterial(FTexture * tx, bool expanded) { mShaderIndex = 0; + tex = tx; // TODO: apply custom shader object here /* if (tx->CustomShaderDefinition) @@ -495,7 +496,6 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) mMaterials.Push(this); tx->gl_info.Material[expanded] = this; if (tx->bHasCanvas) tx->gl_info.mIsTransparent = 0; - tex = tx; mExpanded = expanded; }