From 887d35d559820d9ffac14f17e09b9c1557a2c09f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 11 May 2014 19:44:19 +0200 Subject: [PATCH] - remove colormap from texture generation parameters. The one remaining special case, alpha texture on old hardware is now handled by the currently set texture mode at the time of use. - use the cleaned up decal lighting code from the first GLEW branch. --- src/gl/renderer/gl_lightdata.cpp | 1 + src/gl/renderer/gl_renderer.cpp | 2 +- src/gl/renderer/gl_renderstate.h | 2 + src/gl/scene/gl_decal.cpp | 100 +++++------------------ src/gl/scene/gl_skydome.cpp | 2 - src/gl/system/gl_interface.cpp | 2 - src/gl/system/gl_interface.h | 5 ++ src/gl/system/gl_wipe.cpp | 22 ++--- src/gl/textures/gl_bitmap.cpp | 133 ++++--------------------------- src/gl/textures/gl_bitmap.h | 28 ++++--- src/gl/textures/gl_hwtexture.cpp | 49 ++++-------- src/gl/textures/gl_hwtexture.h | 21 +++-- src/gl/textures/gl_material.cpp | 43 +++++----- src/gl/textures/gl_material.h | 16 ++-- 14 files changed, 134 insertions(+), 292 deletions(-) diff --git a/src/gl/renderer/gl_lightdata.cpp b/src/gl/renderer/gl_lightdata.cpp index 102d1d43e..7d69ababd 100644 --- a/src/gl/renderer/gl_lightdata.cpp +++ b/src/gl/renderer/gl_lightdata.cpp @@ -170,6 +170,7 @@ void gl_GetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblend } else if (style.Flags & STYLEF_InvertSource) { + // The only place where InvertSource is used is for inverted sprites with the infrared powerup. texturemode = TM_INVERSE; } diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index 5120c00ea..d7d2466f0 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -246,7 +246,7 @@ unsigned char *FGLRenderer::GetTextureBuffer(FTexture *tex, int &w, int &h) FMaterial * gltex = FMaterial::ValidateTexture(tex); if (gltex) { - return gltex->CreateTexBuffer(CM_DEFAULT, 0, w, h); + return gltex->CreateTexBuffer(0, w, h); } return NULL; } diff --git a/src/gl/renderer/gl_renderstate.h b/src/gl/renderer/gl_renderstate.h index e037fb637..cd37705af 100644 --- a/src/gl/renderer/gl_renderstate.h +++ b/src/gl/renderer/gl_renderstate.h @@ -2,6 +2,7 @@ #define __GL_RENDERSTATE_H #include +#include "gl/system/gl_interface.h" #include "c_cvars.h" #include "r_defs.h" @@ -177,6 +178,7 @@ public: void SetTextureMode(int mode) { mTextureMode = mode; + gl.checkTextureMode(mode); } void EnableTexture(bool on) diff --git a/src/gl/scene/gl_decal.cpp b/src/gl/scene/gl_decal.cpp index 959641076..7c2dda05f 100644 --- a/src/gl/scene/gl_decal.cpp +++ b/src/gl/scene/gl_decal.cpp @@ -74,7 +74,7 @@ void GLWall::DrawDecal(DBaseDecal *decal) int light; int rel; float a; - bool flipx, flipy, loadAlpha; + bool flipx, flipy; DecalVertex dv[4]; FTextureID decalTile; @@ -179,9 +179,6 @@ void GLWall::DrawDecal(DBaseDecal *decal) rel = rellight + getExtraLight(); } - int r = RPART(decal->AlphaColor); - int g = GPART(decal->AlphaColor); - int b = BPART(decal->AlphaColor); FColormap p = Colormap; if (glset.nocoloredspritelighting) @@ -190,58 +187,6 @@ void GLWall::DrawDecal(DBaseDecal *decal) p.LightColor = PalEntry(p.colormap, v, v, v); } - float red, green, blue; - - if (decal->RenderStyle.Flags & STYLEF_RedIsAlpha) - { - loadAlpha = true; - p.colormap=CM_SHADE; - - if (glset.lightmode != 8) - { - gl_GetLightColor(light, rel, &p, &red, &green, &blue); - } - else - { - gl_GetLightColor(lightlevel, rellight, &p, &red, &green, &blue); - } - - if (gl_lights && GLRenderer->mLightCount && !gl_fixedcolormap && gl_light_sprites) - { - float result[3]; - fixed_t x, y; - decal->GetXY(seg->sidedef, x, y); - gl_GetSpriteLight(NULL, x, y, zpos, sub, Colormap.colormap-CM_DESAT0, result, line, side == line->sidedef[0]? 0:1); - if (glset.lightmode != 8) - { - red = clamp(result[0]+red, 0, 1.0f); - green = clamp(result[1]+green, 0, 1.0f); - blue = clamp(result[2]+blue, 0, 1.0f); - } - else - { - gl_RenderState.SetDynLight(result[0], result[1], result[2]); - } - } - - BYTE R = xs_RoundToInt(r * red); - BYTE G = xs_RoundToInt(g * green); - BYTE B = xs_RoundToInt(b * blue); - - gl_ModifyColor(R,G,B, Colormap.colormap); - - red = R/255.f; - green = G/255.f; - blue = B/255.f; - } - else - { - loadAlpha = false; - - red = 1.f; - green = 1.f; - blue = 1.f; - } a = FIXED2FLOAT(decal->Alpha); @@ -299,8 +244,6 @@ void GLWall::DrawDecal(DBaseDecal *decal) zpos+= FRACUNIT*(flipy? decalheight-decaltopo : decaltopo); - tex->BindPatch(p.colormap, decal->Translation); - dv[1].z=dv[2].z = FIXED2FLOAT(zpos); dv[0].z=dv[3].z = dv[1].z - decalheight; dv[1].v=dv[2].v = tex->GetVT(); @@ -359,32 +302,25 @@ void GLWall::DrawDecal(DBaseDecal *decal) float vb = tex->GetVB(); for(i=0;i<4;i++) dv[i].v=vb-dv[i].v; } - // fog is set once per wall in the calling function and not per decal! - if (loadAlpha) + // calculate dynamic light effect. + if (gl_lights && GLRenderer->mLightCount && !gl_fixedcolormap && gl_light_sprites) { - glColor4f(red, green, blue, a); - - if (glset.lightmode == 8) - { - if (gl_fixedcolormap) - glVertexAttrib1f(VATTR_LIGHTLEVEL, 1.0); - else - glVertexAttrib1f(VATTR_LIGHTLEVEL, gl_CalcLightLevel(light, rel, false) / 255.0); - } - } - else - { - if (glset.lightmode == 8) - { - gl_SetColor(light, rel, &p, a, !!extralight); // Korshun. - } - else - { - gl_SetColor(light, rel, &p, a); - } + // Note: This should be replaced with proper shader based lighting. + fixed_t x, y; + decal->GetXY(seg->sidedef, x, y); + gl_SetDynSpriteLight(NULL, x, y, zpos, sub); } + // alpha color only has an effect when using an alpha texture. + if (decal->RenderStyle.Flags & STYLEF_RedIsAlpha) + { + gl_RenderState.SetObjectColor(decal->AlphaColor); + } + + gl_SetColor(light, rel, &p, a); + + // for additively drawn decals we must temporarily set the fog color to black. PalEntry fc = gl_RenderState.GetFogColor(); if (decal->RenderStyle.BlendOp == STYLEOP_Add && decal->RenderStyle.DestAlpha == STYLEALPHA_One) { @@ -393,6 +329,8 @@ void GLWall::DrawDecal(DBaseDecal *decal) gl_SetRenderStyle(decal->RenderStyle, false, false); + tex->BindPatch(p.colormap, decal->Translation); + // If srcalpha is one it looks better with a higher alpha threshold if (decal->RenderStyle.SrcAlpha == STYLEALPHA_One) gl_RenderState.AlphaFunc(GL_GEQUAL, gl_mask_threshold); @@ -407,6 +345,8 @@ void GLWall::DrawDecal(DBaseDecal *decal) } glEnd(); rendered_decals++; + gl_RenderState.SetTextureMode(TM_MODULATE); + gl_RenderState.SetObjectColor(0xffffffff); gl_RenderState.SetFog(fc,-1); gl_RenderState.SetDynLight(0,0,0); } diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index 7dbf5e573..b5f3b1333 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -290,7 +290,6 @@ static void RenderDome(FTextureID texno, FMaterial * tex, float x_offset, float if (tex && !secondlayer) { PalEntry pe = tex->tex->GetSkyCapColor(false); - if (CM_Index!=CM_DEFAULT) ModifyPalette(&pe, &pe, CM_Index, 1); R=pe.r/255.0f; G=pe.g/255.0f; @@ -312,7 +311,6 @@ static void RenderDome(FTextureID texno, FMaterial * tex, float x_offset, float if (tex && !secondlayer) { PalEntry pe = tex->tex->GetSkyCapColor(true); - if (CM_Index!=CM_DEFAULT) ModifyPalette(&pe, &pe, CM_Index, 1); R=pe.r/255.0f; G=pe.g/255.0f; B=pe.b/255.0f; diff --git a/src/gl/system/gl_interface.cpp b/src/gl/system/gl_interface.cpp index 7615373c5..2299ddabb 100644 --- a/src/gl/system/gl_interface.cpp +++ b/src/gl/system/gl_interface.cpp @@ -194,7 +194,6 @@ void gl_PrintStartupLog() void gl_SetTextureMode(int type) { - gl.needAlphaTexture = false; if (type == TM_MASK) { glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); @@ -239,7 +238,6 @@ void gl_SetTextureMode(int type) else // if (type == TM_MODULATE) { glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - gl.needAlphaTexture = (type == TM_REDTOALPHA); } } diff --git a/src/gl/system/gl_interface.h b/src/gl/system/gl_interface.h index 13913f621..8618c246a 100644 --- a/src/gl/system/gl_interface.h +++ b/src/gl/system/gl_interface.h @@ -44,6 +44,11 @@ struct RenderContext { return glslversion >= 1.3f; } + + void checkTextureMode(int mode) + { + if (!hasGLSL()) needAlphaTexture = (mode == TM_REDTOALPHA); + } }; extern RenderContext gl; diff --git a/src/gl/system/gl_wipe.cpp b/src/gl/system/gl_wipe.cpp index c41a1fb24..b7751b7ec 100644 --- a/src/gl/system/gl_wipe.cpp +++ b/src/gl/system/gl_wipe.cpp @@ -145,9 +145,9 @@ bool OpenGLFrameBuffer::WipeStartScreen(int type) } wipestartscreen = new FHardwareTexture(Width, Height, false, false, false, true); - wipestartscreen->CreateTexture(NULL, Width, Height, false, 0, CM_DEFAULT); + wipestartscreen->CreateTexture(NULL, Width, Height, false, 0); glFinish(); - wipestartscreen->Bind(0, CM_DEFAULT); + wipestartscreen->Bind(0); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, Width, Height); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -168,9 +168,9 @@ bool OpenGLFrameBuffer::WipeStartScreen(int type) void OpenGLFrameBuffer::WipeEndScreen() { wipeendscreen = new FHardwareTexture(Width, Height, false, false, false, true); - wipeendscreen->CreateTexture(NULL, Width, Height, false, 0, CM_DEFAULT); + wipeendscreen->CreateTexture(NULL, Width, Height, false, 0); glFlush(); - wipeendscreen->Bind(0, CM_DEFAULT); + wipeendscreen->Bind(0); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, Width, Height); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -280,7 +280,7 @@ bool OpenGLFrameBuffer::Wiper_Crossfade::Run(int ticks, OpenGLFrameBuffer *fb) gl_RenderState.SetTextureMode(TM_OPAQUE); gl_RenderState.EnableAlphaTest(false); gl_RenderState.Apply(); - fb->wipestartscreen->Bind(0, CM_DEFAULT); + fb->wipestartscreen->Bind(0); glColor4f(1.f, 1.f, 1.f, 1.f); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, vb); @@ -293,7 +293,7 @@ bool OpenGLFrameBuffer::Wiper_Crossfade::Run(int ticks, OpenGLFrameBuffer *fb) glVertex2i(fb->Width, fb->Height); glEnd(); - fb->wipeendscreen->Bind(0, CM_DEFAULT); + fb->wipeendscreen->Bind(0); glColor4f(1.f, 1.f, 1.f, clamp(Clock/32.f, 0.f, 1.f)); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, vb); @@ -347,7 +347,7 @@ bool OpenGLFrameBuffer::Wiper_Melt::Run(int ticks, OpenGLFrameBuffer *fb) // Draw the new screen on the bottom. gl_RenderState.SetTextureMode(TM_OPAQUE); gl_RenderState.Apply(); - fb->wipeendscreen->Bind(0, CM_DEFAULT); + fb->wipeendscreen->Bind(0); glColor4f(1.f, 1.f, 1.f, 1.f); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, vb); @@ -363,7 +363,7 @@ bool OpenGLFrameBuffer::Wiper_Melt::Run(int ticks, OpenGLFrameBuffer *fb) int i, dy; bool done = false; - fb->wipestartscreen->Bind(0, CM_DEFAULT); + fb->wipestartscreen->Bind(0); // Copy the old screen in vertical strips on top of the new one. while (ticks--) { @@ -492,7 +492,7 @@ bool OpenGLFrameBuffer::Wiper_Burn::Run(int ticks, OpenGLFrameBuffer *fb) gl_RenderState.SetTextureMode(TM_OPAQUE); gl_RenderState.EnableAlphaTest(false); gl_RenderState.Apply(); - fb->wipestartscreen->Bind(0, CM_DEFAULT); + fb->wipestartscreen->Bind(0); glColor4f(1.f, 1.f, 1.f, 1.f); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, vb); @@ -523,10 +523,10 @@ bool OpenGLFrameBuffer::Wiper_Burn::Run(int ticks, OpenGLFrameBuffer *fb) // Burn the new screen on top of it. glColor4f(1.f, 1.f, 1.f, 1.f); - fb->wipeendscreen->Bind(1, CM_DEFAULT); + fb->wipeendscreen->Bind(1); //BurnTexture->Bind(0, CM_DEFAULT); - BurnTexture->CreateTexture(rgb_buffer, WIDTH, HEIGHT, false, 0, CM_DEFAULT); + BurnTexture->CreateTexture(rgb_buffer, WIDTH, HEIGHT, false, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); diff --git a/src/gl/textures/gl_bitmap.cpp b/src/gl/textures/gl_bitmap.cpp index d90fd36b7..51e03aa98 100644 --- a/src/gl/textures/gl_bitmap.cpp +++ b/src/gl/textures/gl_bitmap.cpp @@ -50,12 +50,11 @@ // //=========================================================================== template -void iCopyColors(unsigned char * pout, const unsigned char * pin, int cm, int count, int step) +void iCopyColors(unsigned char * pout, const unsigned char * pin, bool alphatex, int count, int step) { int i; - int fac; - if (cm == CM_DEFAULT) + if (!alphatex) { for(i=0;i= CM_FIRSTSPECIALCOLORMAP && cm < CM_FIRSTSPECIALCOLORMAP + int(SpecialColormaps.Size())) - { - for(i=0;i, @@ -147,57 +115,11 @@ void FGLBitmap::CopyPixelDataRGB(int originx, int originy, BYTE *buffer = GetPixels() + 4*originx + Pitch*originy; for (int y=0;y= CM_FIRSTSPECIALCOLORMAP && cm < CM_FIRSTSPECIALCOLORMAP + int(SpecialColormaps.Size())) - { - for(i=0;i> 8; - // This can be done in place so we cannot copy the color directly. - PalEntry pe = SpecialColormaps[cm - CM_FIRSTSPECIALCOLORMAP].GrayscaleToColor[gray]; - pout[i].r = pe.r; - pout[i].g = pe.g; - pout[i].b = pe.b; - pout[i].a = pin[i].a; - } - } - else if (cm<=CM_DESAT31) - { - // Desaturated light settings. - fac=cm-CM_DESAT0; - for(i=0;i>8; - gl_Desaturate(gray, pin[i].r, pin[i].g, pin[i].b, pout[i].r, pout[i].g, pout[i].b, fac); - pout[i].a = pin[i].a; - } - } - else if (pin!=pout) - { - memcpy(pout, pin, count * sizeof(PalEntry)); - } -} - - //=========================================================================== // // Paletted to True Color texture copy function @@ -215,7 +137,7 @@ void FGLBitmap::CopyPixelData(int originx, int originy, const BYTE * patch, int BYTE *buffer = GetPixels() + 4*originx + Pitch*originy; // CM_SHADE is an alpha map with 0==transparent and 1==opaque - if (cm == CM_SHADE) + if (alphatex) { for(int i=0;i<256;i++) { @@ -225,37 +147,21 @@ void FGLBitmap::CopyPixelData(int originx, int originy, const BYTE * patch, int penew[i]=PalEntry(0,255,255,255); // If the palette contains transparent colors keep them. } } - else + else if (translation > 0) { - // apply any translation. - // The ice and blood color translations are done directly - // because that yields better results. - switch(translation) + PalEntry *ptrans = GLTranslationPalette::GetPalette(translation); + if (ptrans) { - default: - { - PalEntry *ptrans = GLTranslationPalette::GetPalette(translation); - if (ptrans) + for (i = 0; i < 256; i++) { - for(i = 0; i < 256; i++) - { - penew[i] = (ptrans[i]&0xffffff) | (palette[i]&0xff000000); - } - break; + penew[i] = (ptrans[i] & 0xffffff) | (palette[i] & 0xff000000); } } - - case 0: - memcpy(penew, palette, 256*sizeof(PalEntry)); - break; - } - if (cm!=0) - { - // Apply color modifications like invulnerability, desaturation and Boom colormaps - ModifyPalette(penew, penew, cm, 256); - } } - // Now penew contains the actual palette that is to be used for creating the image. + else + { + memcpy(penew, palette, 256*sizeof(PalEntry)); + } // convert the image according to the translated palette. for (y=0;y(buffer[pos+3] + (( 255-buffer[pos+3]) * (255-penew[v].a))/255, 0, 255); - } - */ } } } diff --git a/src/gl/textures/gl_bitmap.h b/src/gl/textures/gl_bitmap.h index db3722a6e..98addb51d 100644 --- a/src/gl/textures/gl_bitmap.h +++ b/src/gl/textures/gl_bitmap.h @@ -5,24 +5,34 @@ #include "gl/textures/gl_material.h" -void ModifyPalette(PalEntry * pout, PalEntry * pin, int cm, int count); - class FGLBitmap : public FBitmap { - int cm; + bool alphatex; int translation; public: - FGLBitmap() { cm = CM_DEFAULT; translation = 0; } + FGLBitmap() + { + alphatex = false; + translation = 0; + } FGLBitmap(BYTE *buffer, int pitch, int width, int height) : FBitmap(buffer, pitch, width, height) - { cm = CM_DEFAULT; translation = 0; } - - void SetTranslationInfo(int _cm, int _trans=-1337) { - if (_cm != -1) cm = _cm; - if (_trans != -1337) translation = _trans; + alphatex = false; + translation = 0; + } + void SetTranslationInfo(int _trans) + { + if (_trans == -1) alphatex = true; + else if (_trans != -1337) translation = _trans; + + } + + void SetAlphaTex() + { + alphatex = true; } virtual void CopyPixelDataRGB(int originx, int originy, const BYTE *patch, int srcwidth, diff --git a/src/gl/textures/gl_hwtexture.cpp b/src/gl/textures/gl_hwtexture.cpp index 648bac770..7aa8b610c 100644 --- a/src/gl/textures/gl_hwtexture.cpp +++ b/src/gl/textures/gl_hwtexture.cpp @@ -277,9 +277,7 @@ FHardwareTexture::FHardwareTexture(int _width, int _height, bool _mipmap, bool w texwidth=_width; texheight=_height; - int cm_arraysize = CM_FIRSTSPECIALCOLORMAP + SpecialColormaps.Size(); - glTexID = new unsigned[cm_arraysize]; - memset(glTexID,0,sizeof(unsigned int)*cm_arraysize); + glDefTexID = 0; clampmode=0; glDepthID = 0; forcenofiltering = nofilter; @@ -317,21 +315,8 @@ void FHardwareTexture::Clean(bool all) if (all) { - for (int i=0;i= CM_MAXCOLORMAP) cm=CM_DEFAULT; - if (translation==0) { - return &glTexID[cm]; + return &glDefTexID; } // normally there aren't more than very few different // translations here so this isn't performance critical. for(unsigned int i=0;i= CM_MAXCOLORMAP) cm=CM_DEFAULT; - - unsigned int * pTexID=GetTexID(cm, translation); + if (alphatexture) translation = TRANS_Alpha; + unsigned int * pTexID=GetTexID(translation); if (texunit != 0) glActiveTexture(GL_TEXTURE0+texunit); - LoadImage(buffer, w, h, *pTexID, wrap? GL_REPEAT:GL_CLAMP, cm==CM_SHADE, texunit); + LoadImage(buffer, w, h, *pTexID, wrap? GL_REPEAT:GL_CLAMP, alphatexture, texunit); if (texunit != 0) glActiveTexture(GL_TEXTURE0); return *pTexID; } diff --git a/src/gl/textures/gl_hwtexture.h b/src/gl/textures/gl_hwtexture.h index 5b5e55ac5..fc962f3ea 100644 --- a/src/gl/textures/gl_hwtexture.h +++ b/src/gl/textures/gl_hwtexture.h @@ -10,6 +10,17 @@ class FCanvasTexture; class AActor; +// For error catching while changing parameters. +enum EInvalid +{ + Invalid = 0 +}; + +enum ETranslation +{ + TRANS_Alpha = INT_MAX +}; + enum { GLT_CLAMPX=1, @@ -27,7 +38,7 @@ class FHardwareTexture { unsigned int glTexID; int translation; - int cm; + //int cm; }; public: @@ -48,12 +59,12 @@ private: bool forcenofiltering; bool forcenocompression; - unsigned int * glTexID; + unsigned glDefTexID; TArray glTexID_Translated; unsigned int glDepthID; // only used by camera textures void LoadImage(unsigned char * buffer,int w, int h, unsigned int & glTexID,int wrapparam, bool alphatexture, int texunit); - unsigned * GetTexID(int cm, int translation); + unsigned * GetTexID(int translation); int GetDepthBuffer(); void DeleteTexture(unsigned int texid); @@ -68,8 +79,8 @@ public: void BindToFrameBuffer(); - unsigned int Bind(int texunit, int cm, int translation=0); - unsigned int CreateTexture(unsigned char * buffer, int w, int h,bool wrap, int texunit, int cm, int translation=0); + unsigned int Bind(int texunit, int translation=0, bool alphatexture = false); + unsigned int CreateTexture(unsigned char * buffer, int w, int h,bool wrap, int texunit, int translation=0, bool alphatexture = false); void Resize(int _width, int _height) ; void Clean(bool all); diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index 5d471fc81..8253c3262 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -109,7 +109,7 @@ FGLTexture::~FGLTexture() // Checks for the presence of a hires texture replacement and loads it // //========================================================================== -unsigned char *FGLTexture::LoadHiresTexture(FTexture *tex, int *width, int *height, int cm) +unsigned char *FGLTexture::LoadHiresTexture(FTexture *tex, int *width, int *height, bool alphatexture) { if (HiresLump==-1) { @@ -131,7 +131,7 @@ unsigned char *FGLTexture::LoadHiresTexture(FTexture *tex, int *width, int *heig memset(buffer, 0, w * (h+1) * 4); FGLBitmap bmp(buffer, w*4, w, h); - bmp.SetTranslationInfo(cm); + if (alphatexture) bmp.SetAlphaTex(); int trans = hirestexture->CopyTrueColorPixels(&bmp, 0, 0); @@ -271,7 +271,7 @@ BYTE *FGLTexture::WarpBuffer(BYTE *buffer, int Width, int Height, int warp) // //=========================================================================== -unsigned char * FGLTexture::CreateTexBuffer(int cm, int translation, int & w, int & h, bool expand, FTexture *hirescheck, int warp) +unsigned char * FGLTexture::CreateTexBuffer(int translation, int & w, int & h, bool expand, FTexture *hirescheck, int warp, bool alphatexture) { unsigned char * buffer; int W, H; @@ -281,7 +281,7 @@ unsigned char * FGLTexture::CreateTexBuffer(int cm, int translation, int & w, in // by hires textures if (gl_texture_usehires && hirescheck != NULL) { - buffer = LoadHiresTexture (hirescheck, &w, &h, cm); + buffer = LoadHiresTexture (hirescheck, &w, &h, alphatexture); if (buffer) { return buffer; @@ -296,7 +296,8 @@ unsigned char * FGLTexture::CreateTexBuffer(int cm, int translation, int & w, in memset(buffer, 0, W * (H+1) * 4); FGLBitmap bmp(buffer, W*4, W, H); - bmp.SetTranslationInfo(cm, translation); + bmp.SetTranslationInfo(translation); + if (alphatexture) bmp.SetAlphaTex(); if (tex->bComplex) { @@ -337,7 +338,7 @@ unsigned char * FGLTexture::CreateTexBuffer(int cm, int translation, int & w, in else //if (bIsTransparent != 1) { // [BB] Potentially upsample the buffer. - buffer = gl_CreateUpsampledTextureBuffer ( tex, buffer, W, H, w, h, bIsTransparent || cm == CM_SHADE ); + buffer = gl_CreateUpsampledTextureBuffer ( tex, buffer, W, H, w, h, bIsTransparent || alphatexture); } currentwarp = warp; currentwarptime = gl_frameMS; @@ -386,7 +387,7 @@ bool FGLTexture::CreatePatch() // //=========================================================================== -const FHardwareTexture *FGLTexture::Bind(int texunit, int cm, int clampmode, int translation, FTexture *hirescheck, int warp) +const FHardwareTexture *FGLTexture::Bind(int texunit, int clampmode, int translation, FTexture *hirescheck, int warp) { int usebright = false; @@ -400,7 +401,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int cm, int clampmode, int hwtex = gltexture[clampmode] = gltexture[4]; gltexture[4] = NULL; - if (hwtex->Bind(texunit, cm, translation)) + if (hwtex->Bind(texunit, translation)) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (clampmode & GLT_CLAMPX)? GL_CLAMP_TO_EDGE : GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (clampmode & GLT_CLAMPY)? GL_CLAMP_TO_EDGE : GL_REPEAT); @@ -428,7 +429,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int cm, int clampmode, int } // Bind it to the system. - if (!hwtex->Bind(texunit, cm, translation)) + if (!hwtex->Bind(texunit, translation)) { int w=0, h=0; @@ -438,10 +439,10 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int cm, int clampmode, int if (!tex->bHasCanvas) { - buffer = CreateTexBuffer(cm, translation, w, h, false, hirescheck, warp); + buffer = CreateTexBuffer(translation, w, h, false, hirescheck, warp); tex->ProcessData(buffer, w, h, false); } - if (!hwtex->CreateTexture(buffer, w, h, true, texunit, cm, translation)) + if (!hwtex->CreateTexture(buffer, w, h, true, texunit, translation)) { // could not create texture delete[] buffer; @@ -463,7 +464,7 @@ const FHardwareTexture *FGLTexture::Bind(int texunit, int cm, int clampmode, int // Binds a sprite to the renderer // //=========================================================================== -const FHardwareTexture * FGLTexture::BindPatch(int texunit, int cm, int translation, int warp) +const FHardwareTexture * FGLTexture::BindPatch(int texunit, int translation, int warp, bool alphatexture) { bool usebright = false; int transparm = translation; @@ -489,14 +490,14 @@ const FHardwareTexture * FGLTexture::BindPatch(int texunit, int cm, int translat // Bind it to the system. - if (!glpatch->Bind(texunit, cm, translation)) + if (!glpatch->Bind(texunit, translation, alphatexture)) { int w, h; // Create this texture - unsigned char * buffer = CreateTexBuffer(cm, translation, w, h, bExpand, NULL, warp); + unsigned char * buffer = CreateTexBuffer(translation, w, h, bExpand, NULL, warp, alphatexture); tex->ProcessData(buffer, w, h, true); - if (!glpatch->CreateTexture(buffer, w, h, false, texunit, cm, translation)) + if (!glpatch->CreateTexture(buffer, w, h, false, texunit, translation, alphatexture)) { // could not create texture delete[] buffer; @@ -755,7 +756,7 @@ bool FMaterial::TrimBorders(int *rect) int w; int h; - unsigned char *buffer = CreateTexBuffer(CM_DEFAULT, 0, w, h); + unsigned char *buffer = CreateTexBuffer(0, w, h); if (buffer == NULL) { @@ -847,7 +848,7 @@ void FMaterial::Bind(int cm, int clampmode, int translation, int overrideshader) else if (clampmode != -1) clampmode &= 3; else clampmode = 4; - const FHardwareTexture *gltexture = mBaseLayer->Bind(0, cm, clampmode, translation, allowhires? tex:NULL, softwarewarp); + const FHardwareTexture *gltexture = mBaseLayer->Bind(0, clampmode, translation, allowhires? tex:NULL, softwarewarp); if (gltexture != NULL && shaderindex > 0 && overrideshader == 0) { for(unsigned i=0;igl_info.SystemTexture->Bind(i+1, CM_DEFAULT, clampmode, 0, NULL, false); + layer->gl_info.SystemTexture->Bind(i+1, clampmode, 0, NULL, false); maxbound = i+1; } } @@ -890,11 +891,11 @@ void FMaterial::BindPatch(int cm, int translation, int overrideshader) int softwarewarp = gl_RenderState.SetupShader(tex->bHasCanvas, shaderindex, cm, tex->gl_info.shaderspeed); - const FHardwareTexture *glpatch = mBaseLayer->BindPatch(0, cm, translation, softwarewarp); + const FHardwareTexture *glpatch = mBaseLayer->BindPatch(0, translation, softwarewarp, gl.needAlphaTexture); // The only multitexture effect usable on sprites is the brightmap. if (glpatch != NULL && shaderindex == 3) { - mTextureLayers[0].texture->gl_info.SystemTexture->BindPatch(1, CM_DEFAULT, 0, 0); + mTextureLayers[0].texture->gl_info.SystemTexture->BindPatch(1, 0, 0, false); maxbound = 1; } // unbind everything from the last texture that's still active @@ -1012,7 +1013,7 @@ void FMaterial::BindToFrameBuffer() if (mBaseLayer->gltexture == NULL) { // must create the hardware texture first - mBaseLayer->Bind(0, CM_DEFAULT, 0, 0, NULL, 0); + mBaseLayer->Bind(0, 0, 0, NULL, 0); FHardwareTexture::Unbind(0); } mBaseLayer->gltexture[0]->BindToFrameBuffer(); diff --git a/src/gl/textures/gl_material.h b/src/gl/textures/gl_material.h index 3754e9337..16f1ed451 100644 --- a/src/gl/textures/gl_material.h +++ b/src/gl/textures/gl_material.h @@ -48,7 +48,7 @@ enum ETexUse }; -class FGLTexture //: protected WorldTextureInfo, protected PatchTextureInfo +class FGLTexture { friend class FMaterial; public: @@ -68,21 +68,21 @@ private: bool bExpand; float AlphaThreshold; - unsigned char * LoadHiresTexture(FTexture *hirescheck, int *width, int *height, int cm); + unsigned char * LoadHiresTexture(FTexture *hirescheck, int *width, int *height, bool alphatexture); BYTE *WarpBuffer(BYTE *buffer, int Width, int Height, int warp); FHardwareTexture *CreateTexture(int clampmode); //bool CreateTexture(); bool CreatePatch(); - const FHardwareTexture *Bind(int texunit, int cm, int clamp, int translation, FTexture *hirescheck, int warp); - const FHardwareTexture *BindPatch(int texunit, int cm, int translation, int warp); + const FHardwareTexture *Bind(int texunit, int clamp, int translation, FTexture *hirescheck, int warp); + const FHardwareTexture *BindPatch(int texunit, int translation, int warp, bool alphatexture); public: FGLTexture(FTexture * tx, bool expandpatches); ~FGLTexture(); - unsigned char * CreateTexBuffer(int cm, int translation, int & w, int & h, bool expand, FTexture *hirescheck, int warp); + unsigned char * CreateTexBuffer(int translation, int & w, int & h, bool expand, FTexture *hirescheck, int warp, bool alphatexture = false); void Clean(bool all); int Dump(int i); @@ -138,9 +138,9 @@ public: void Bind(int cm, int clamp = 0, int translation = 0, int overrideshader = 0); void BindPatch(int cm, int translation = 0, int overrideshader = 0); - unsigned char * CreateTexBuffer(int cm, int translation, int & w, int & h, bool expand = false, bool allowhires=true) const + unsigned char * CreateTexBuffer(int translation, int & w, int & h, bool expand = false, bool allowhires=true) const { - return mBaseLayer->CreateTexBuffer(cm, translation, w, h, expand, allowhires? tex:NULL, 0); + return mBaseLayer->CreateTexBuffer(translation, w, h, expand, allowhires? tex:NULL, 0); } void Clean(bool f) @@ -233,7 +233,7 @@ public: if (!mBaseLayer->tex->bHasCanvas) { int w, h; - unsigned char *buffer = CreateTexBuffer(CM_DEFAULT, 0, w, h); + unsigned char *buffer = CreateTexBuffer(0, w, h); delete [] buffer; } else