diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index d551106a45..c7944f141c 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -376,8 +376,7 @@ struct FDefaultShader const char * gettexelfunc; }; -// Note: the FIRST_USER_SHADER constant in gl_shader.h needs -// to be updated whenever the size of this array is modified. +// Note: the ShaderIndex enum in gl_shader.h needs to be updated whenever this array is modified. static const FDefaultShader defaultshaders[]= { {"Default", "shaders/glsl/func_normal.fp"}, @@ -522,8 +521,8 @@ FShaderCollection::~FShaderCollection() void FShaderCollection::CompileShaders(EPassType passType) { - mTextureEffects.Clear(); - mTextureEffectsNAT.Clear(); + mMaterialShaders.Clear(); + mMaterialShadersNAT.Clear(); for (int i = 0; i < MAX_EFFECTS; i++) { mEffectShaders[i] = NULL; @@ -532,11 +531,11 @@ void FShaderCollection::CompileShaders(EPassType passType) for(int i=0;defaultshaders[i].ShaderName != NULL;i++) { FShader *shc = Compile(defaultshaders[i].ShaderName, defaultshaders[i].gettexelfunc, true, passType); - mTextureEffects.Push(shc); - if (i <= 3) + mMaterialShaders.Push(shc); + if (i <= SHADER_Brightmap) { FShader *shc = Compile(defaultshaders[i].ShaderName, defaultshaders[i].gettexelfunc, false, passType); - mTextureEffectsNAT.Push(shc); + mMaterialShadersNAT.Push(shc); } } @@ -546,7 +545,7 @@ void FShaderCollection::CompileShaders(EPassType passType) FName sfn = name; FShader *shc = Compile(sfn, usershaders[i], true, passType); - mTextureEffects.Push(shc); + mMaterialShaders.Push(shc); } for(int i=0;imName == sfn) + if (mMaterialShaders[i]->mName == sfn) { return i; } @@ -636,19 +635,19 @@ void FShaderCollection::ApplyMatrices(VSMatrix *proj, VSMatrix *view) VSMatrix norm; norm.computeNormalMatrix(*view); - for (int i = 0; i < 4; i++) + for (int i = 0; i < SHADER_NoTexture; i++) { - mTextureEffects[i]->ApplyMatrices(proj, view, &norm); - mTextureEffectsNAT[i]->ApplyMatrices(proj, view, &norm); + mMaterialShaders[i]->ApplyMatrices(proj, view, &norm); + mMaterialShadersNAT[i]->ApplyMatrices(proj, view, &norm); } - mTextureEffects[4]->ApplyMatrices(proj, view, &norm); + mMaterialShaders[SHADER_NoTexture]->ApplyMatrices(proj, view, &norm); if (gl_fuzztype != 0) { - mTextureEffects[4 + gl_fuzztype]->ApplyMatrices(proj, view, &norm); + mMaterialShaders[SHADER_NoTexture + gl_fuzztype]->ApplyMatrices(proj, view, &norm); } - for (unsigned i = 12; i < mTextureEffects.Size(); i++) + for (unsigned i = FIRST_USER_SHADER; i < mMaterialShaders.Size(); i++) { - mTextureEffects[i]->ApplyMatrices(proj, view, &norm); + mMaterialShaders[i]->ApplyMatrices(proj, view, &norm); } for (int i = 0; i < MAX_EFFECTS; i++) { diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index f41f7467bc..6995c7b286 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -355,8 +355,8 @@ private: class FShaderCollection { - TArray mTextureEffects; - TArray mTextureEffectsNAT; + TArray mMaterialShaders; + TArray mMaterialShadersNAT; FShader *mEffectShaders[MAX_EFFECTS]; void Clean(); @@ -372,13 +372,13 @@ public: void ResetFixedColormap() { - for (unsigned i = 0; i < mTextureEffects.Size(); i++) + for (unsigned i = 0; i < mMaterialShaders.Size(); i++) { - mTextureEffects[i]->currentfixedcolormap = -1; + mMaterialShaders[i]->currentfixedcolormap = -1; } - for (unsigned i = 0; i < mTextureEffectsNAT.Size(); i++) + for (unsigned i = 0; i < mMaterialShadersNAT.Size(); i++) { - mTextureEffectsNAT[i]->currentfixedcolormap = -1; + mMaterialShadersNAT[i]->currentfixedcolormap = -1; } } @@ -387,17 +387,32 @@ public: // indices 0-2 match the warping modes, 3 is brightmap, 4 no texture, the following are custom if (!alphateston && eff <= 3) { - return mTextureEffectsNAT[eff]; // Non-alphatest shaders are only created for default, warp1+2 and brightmap. The rest won't get used anyway + return mMaterialShadersNAT[eff]; // Non-alphatest shaders are only created for default, warp1+2 and brightmap. The rest won't get used anyway } - if (eff < mTextureEffects.Size()) + if (eff < mMaterialShaders.Size()) { - return mTextureEffects[eff]; + return mMaterialShaders[eff]; } return NULL; } }; -#define FIRST_USER_SHADER 12 +enum MaterialShaderIndex +{ + SHADER_Default = 0, + SHADER_Warp1 = 1, + SHADER_Warp2 = 2, + SHADER_Brightmap = 3, + SHADER_NoTexture = 4, + SHADER_BasicFuzz = 5, + SHADER_SmoothFuzz = 6, + SHADER_SwirlyFuzz = 7, + SHADER_TranslucentFuzz = 8, + SHADER_JaggedFuzz = 9, + SHADER_NoiseFuzz = 10, + SHADER_SmoothNoiseFuzz = 11, + FIRST_USER_SHADER = 12 +}; enum { diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index 53d22f8573..c716f57174 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -438,7 +438,7 @@ int FMaterial::mMaxBound; FMaterial::FMaterial(FTexture * tx, bool expanded) { - mShaderIndex = 0; + mShaderIndex = SHADER_Default; tex = tx; // TODO: apply custom shader object here @@ -449,7 +449,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) */ if (tx->bWarped) { - mShaderIndex = tx->bWarped; + mShaderIndex = tx->bWarped; // This picks SHADER_Warp1 or SHADER_Warp2 tx->gl_info.shaderspeed = static_cast(tx)->GetSpeed(); } else if (tx->bHasCanvas) @@ -474,7 +474,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) ValidateSysTexture(tx->gl_info.Brightmap, expanded); FTextureLayer layer = {tx->gl_info.Brightmap, false}; mTextureLayers.Push(layer); - mShaderIndex = 3; + mShaderIndex = SHADER_Brightmap; } } } @@ -804,7 +804,7 @@ void FMaterial::GetTexCoordInfo(FTexCoordInfo *tci, float x, float y) const int FMaterial::GetAreas(FloatRect **pAreas) const { - if (mShaderIndex == 0) // texture splitting can only be done if there's no attached effects + if (mShaderIndex == SHADER_Default) // texture splitting can only be done if there's no attached effects { FTexture *tex = mBaseLayer->tex; *pAreas = tex->gl_info.areas;