diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 35d56b9c..fa90151d 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -66,7 +66,7 @@ #include "v_palette.h" #include "v_font.h" -#include "gl/data/gl_data.h" +#include "gl/gl_functions.h" static FRandom pr_script("FScript"); diff --git a/src/gl/common/a_dynlight.cpp b/src/gl/common/a_dynlight.cpp index 0f871055..f899bb4e 100644 --- a/src/gl/common/a_dynlight.cpp +++ b/src/gl/common/a_dynlight.cpp @@ -48,6 +48,8 @@ #include "gl/common/glc_dynlight.h" #include "gl/common/glc_templates.h" +#include "gl/data/gl_data.h" + EXTERN_CVAR (Float, gl_lights_size); EXTERN_CVAR (Bool, gl_lights_additive); diff --git a/src/gl/common/glc_renderer.h b/src/gl/common/glc_renderer.h index 99c3f96e..107977ab 100644 --- a/src/gl/common/glc_renderer.h +++ b/src/gl/common/glc_renderer.h @@ -52,6 +52,11 @@ public: FDrawInfo *GlobalDrawInfo; int gl_spriteindex; + FTexture *glpart2; + FTexture *glpart; + FTexture *mirrortexture; + FTexture *gllight; + float mSky1Pos, mSky2Pos; FRotator mAngles; @@ -74,6 +79,7 @@ public: mVBO = NULL; gl_spriteindex = 0; GlobalDrawInfo = NULL; + glpart2 = glpart = gllight = mirrortexture = NULL; } ~FGLRenderer() ; @@ -132,7 +138,6 @@ public: }; // Global functions. Make them members of GLRenderer later? -FTextureID gl_GetSpriteFrame(unsigned sprite, int frame, int rot, angle_t angle, bool *mirror); void gl_RenderBSPNode (void *node); bool gl_CheckClip(side_t * sidedef, sector_t * frontsector, sector_t * backsector); void gl_CheckViewArea(vertex_t *v1, vertex_t *v2, sector_t *frontsector, sector_t *backsector); diff --git a/src/gl/data/gl_data.cpp b/src/gl/data/gl_data.cpp index 9d262902..c4c79efe 100644 --- a/src/gl/data/gl_data.cpp +++ b/src/gl/data/gl_data.cpp @@ -80,29 +80,6 @@ CUSTOM_CVAR(Bool, gl_nocoloredspritelighting, false, 0) void gl_CreateSections(); -FTexture *glpart2; -FTexture *glpart; -FTexture *mirrortexture; -FTexture *gllight; - -void gl_FreeSpecialTextures() -{ - if (glpart2) delete glpart2; - if (glpart) delete glpart; - if (mirrortexture) delete mirrortexture; - if (gllight) delete gllight; - - glpart = glpart2 = gllight = mirrortexture = NULL; -} - -void gl_InitSpecialTextures() -{ - glpart2 = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/glpart2.png"), FTexture::TEX_MiscPatch); - glpart = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/glpart.png"), FTexture::TEX_MiscPatch); - mirrortexture = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/mirror.png"), FTexture::TEX_MiscPatch); - gllight = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/gllight.png"), FTexture::TEX_MiscPatch); -} - //----------------------------------------------------------------------------- // // Adjust sprite offsets for GL rendering (IWAD resources only) diff --git a/src/gl/data/gl_data.h b/src/gl/data/gl_data.h index af08ae35..4739ba61 100644 --- a/src/gl/data/gl_data.h +++ b/src/gl/data/gl_data.h @@ -21,27 +21,7 @@ extern GLRenderSettings glset; #include "r_defs.h" -struct sector_t; -struct line_t; -class FTexture; - -void gl_FreeSpecialTextures(); -void gl_InitSpecialTextures(); void gl_RecalcVertexHeights(vertex_t * v); -void gl_PreprocessLevel(); -void gl_CleanLevelData(); FTextureID gl_GetSpriteFrame(unsigned sprite, int frame, int rot, angle_t ang, bool *mirror); -struct MapData; -void gl_CheckNodes(MapData * map); -bool gl_LoadGLNodes(MapData * map); - - -extern FTexture *glpart2; -extern FTexture *glpart; -extern FTexture *mirrortexture; -extern FTexture *gllight; - - - #endif diff --git a/src/gl/gl_functions.h b/src/gl/gl_functions.h index 670aa43e..c1a83535 100644 --- a/src/gl/gl_functions.h +++ b/src/gl/gl_functions.h @@ -1,96 +1,27 @@ #ifndef __GL_FUNCT #define __GL_FUNCT -#include "doomtype.h" -#include "templates.h" -#include "m_fixed.h" -#include "tables.h" -#include "textures/textures.h" -#include "gl/old_renderer/gl1_renderer.h" - -class FArchive; +#include "v_palette.h" class AActor; -class FTexture; -class FFont; -struct sector_t; -class player_s; -struct GL_IRECT; -class FCanvasTexture; -struct texcoord; struct MapData; -struct FColormap; -struct particle_t; -struct subsector_t; -struct vertex_t; -class DCanvas; -union FRenderStyle; -struct side_t; - - -// Light + color - -void gl_GetLightColor(int lightlevel, int rellight, const FColormap * cm, float * pred, float * pgreen, float * pblue, bool weapon=false); -void gl_SetColor(int light, int rellight, const FColormap * cm, float alpha, PalEntry ThingColor = 0xffffff, bool weapon=false); -void gl_SetColor(int light, int rellight, const FColormap * cm, float *red, float *green, float *blue, PalEntry ThingColor=0xffffff, bool weapon=false); - -void gl_GetSpriteLight(AActor *Self, fixed_t x, fixed_t y, fixed_t z, subsector_t * subsec, int desaturation, float * out); -void gl_SetSpriteLight(AActor * thing, int lightlevel, int rellight, FColormap * cm, float alpha, PalEntry ThingColor = 0xffffff, bool weapon=false); - -void gl_GetSpriteLight(AActor * thing, int lightlevel, int rellight, FColormap * cm, - float *red, float *green, float *blue, - PalEntry ThingColor, bool weapon); - -void gl_SetSpriteLighting(FRenderStyle style, AActor *thing, int lightlevel, int rellight, FColormap *cm, - PalEntry ThingColor, float alpha, bool fullbright, bool weapon); - - -void gl_SetSpriteLight(particle_t * thing, int lightlevel, int rellight, FColormap *cm, float alpha, PalEntry ThingColor = 0xffffff); - -void gl_InitFog(); -void gl_SetFog(int lightlevel, int rellight, const FColormap *cm, bool isadditive); - -inline bool gl_isBlack(PalEntry color) -{ - return color.r + color.g + color.b == 0; -} - -inline bool gl_isWhite(PalEntry color) -{ - return color.r + color.g + color.b == 3*0xff; -} - -inline bool gl_isFullbright(PalEntry color, int lightlevel) -{ - return gl_fixedcolormap || (gl_isWhite(color) && lightlevel==255); -} -// Scene +// External entry points for the GL renderer +void gl_PreprocessLevel(); +void gl_CleanLevelData(); void gl_LinkLights(); void gl_SetActorLights(AActor *); void gl_DeleteAllAttachedLights(); void gl_RecreateAllAttachedLights(); void gl_ParseDefs(); +void gl_SetFogParams(int _fogdensity, PalEntry _outsidefogcolor, int _outsidefogdensity, int _skyfog); +void gl_CheckNodes(MapData * map); +bool gl_LoadGLNodes(MapData * map); -inline float Dist2(float x1,float y1,float x2,float y2) -{ - return sqrtf((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); -} - -__forceinline void gl_Desaturate(int gray, int ired, int igreen, int iblue, BYTE & red, BYTE & green, BYTE & blue, int fac) -{ - red = (ired*(31-fac) + gray*fac)/31; - green = (igreen*(31-fac) + gray*fac)/31; - blue = (iblue*(31-fac) + gray*fac)/31; -} - -void gl_ModifyColor(BYTE & red, BYTE & green, BYTE & blue, int cm); - - extern int currentrenderer; #endif diff --git a/src/gl/gl_light.cpp b/src/gl/gl_light.cpp index 798dc4ce..56384724 100644 --- a/src/gl/gl_light.cpp +++ b/src/gl/gl_light.cpp @@ -362,8 +362,8 @@ bool gl_SetupLight(Plane & p, ADynamicLight * light, Vector & nearPt, Vector & u bool gl_SetupLightTexture() { - if (gllight == NULL) return false; - FMaterial * pat = FMaterial::ValidateTexture(gllight); + if (GLRenderer->gllight == NULL) return false; + FMaterial * pat = FMaterial::ValidateTexture(GLRenderer->gllight); pat->BindPatch(CM_DEFAULT, 0); return true; } diff --git a/src/gl/gl_lights.h b/src/gl/gl_lights.h index 5aba313c..9a2524c3 100644 --- a/src/gl/gl_lights.h +++ b/src/gl/gl_lights.h @@ -15,10 +15,76 @@ extern unsigned int frameStartMS; +class AActor; +class FTexture; +class FFont; +struct sector_t; +class player_s; +struct GL_IRECT; +class FCanvasTexture; +struct texcoord; +struct MapData; +struct FColormap; +struct particle_t; +struct subsector_t; +struct vertex_t; +class DCanvas; +union FRenderStyle; +struct side_t; + + +// Light + color + +void gl_GetLightColor(int lightlevel, int rellight, const FColormap * cm, float * pred, float * pgreen, float * pblue, bool weapon=false); +void gl_SetColor(int light, int rellight, const FColormap * cm, float alpha, PalEntry ThingColor = 0xffffff, bool weapon=false); +void gl_SetColor(int light, int rellight, const FColormap * cm, float *red, float *green, float *blue, PalEntry ThingColor=0xffffff, bool weapon=false); + +void gl_GetSpriteLight(AActor *Self, fixed_t x, fixed_t y, fixed_t z, subsector_t * subsec, int desaturation, float * out); +void gl_SetSpriteLight(AActor * thing, int lightlevel, int rellight, FColormap * cm, float alpha, PalEntry ThingColor = 0xffffff, bool weapon=false); + +void gl_GetSpriteLight(AActor * thing, int lightlevel, int rellight, FColormap * cm, + float *red, float *green, float *blue, + PalEntry ThingColor, bool weapon); + +void gl_SetSpriteLighting(FRenderStyle style, AActor *thing, int lightlevel, int rellight, FColormap *cm, + PalEntry ThingColor, float alpha, bool fullbright, bool weapon); + + +void gl_SetSpriteLight(particle_t * thing, int lightlevel, int rellight, FColormap *cm, float alpha, PalEntry ThingColor = 0xffffff); + +void gl_SetFog(int lightlevel, int rellight, const FColormap *cm, bool isadditive); + +inline bool gl_isBlack(PalEntry color) +{ + return color.r + color.g + color.b == 0; +} + +inline bool gl_isWhite(PalEntry color) +{ + return color.r + color.g + color.b == 3*0xff; +} + +extern DWORD gl_fixedcolormap; + +inline bool gl_isFullbright(PalEntry color, int lightlevel) +{ + return gl_fixedcolormap || (gl_isWhite(color) && lightlevel==255); +} + + bool gl_SetupLight(Plane & p, ADynamicLight * light, Vector & nearPt, Vector & up, Vector & right, float & scale, int desaturation, bool checkside=true, bool forceadditive=true); bool gl_SetupLightTexture(); void gl_GetLightForThing(AActor * thing, float upper, float lower, float & r, float & g, float & b); -extern bool i_useshaders; +__forceinline void gl_Desaturate(int gray, int ired, int igreen, int iblue, BYTE & red, BYTE & green, BYTE & blue, int fac) +{ + red = (ired*(31-fac) + gray*fac)/31; + green = (igreen*(31-fac) + gray*fac)/31; + blue = (iblue*(31-fac) + gray*fac)/31; +} + +void gl_ModifyColor(BYTE & red, BYTE & green, BYTE & blue, int cm); + + #endif diff --git a/src/gl/old_renderer/gl1_renderer.cpp b/src/gl/old_renderer/gl1_renderer.cpp index 71c6065e..5363e031 100644 --- a/src/gl/old_renderer/gl1_renderer.cpp +++ b/src/gl/old_renderer/gl1_renderer.cpp @@ -47,6 +47,7 @@ #include "r_main.h" #include "m_png.h" #include "m_crc32.h" +#include "w_wad.h" #include "gl/common/glc_templates.h" #include "gl/gl_struct.h" #include "gl/gl_intern.h" @@ -69,6 +70,7 @@ // Renderer interface // //=========================================================================== +void gl_InitFog(); EXTERN_CVAR(Bool, gl_render_segs) @@ -81,6 +83,11 @@ EXTERN_CVAR(Bool, gl_render_segs) void FGLRenderer::Initialize() { + glpart2 = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/glpart2.png"), FTexture::TEX_MiscPatch); + glpart = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/glpart.png"), FTexture::TEX_MiscPatch); + mirrortexture = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/mirror.png"), FTexture::TEX_MiscPatch); + gllight = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/gllight.png"), FTexture::TEX_MiscPatch); + mVBO = new FVertexBuffer; GlobalDrawInfo = new FDrawInfo; gl_InitShaders(); @@ -93,6 +100,10 @@ FGLRenderer::~FGLRenderer() gl_ClearShaders(); if (GlobalDrawInfo != NULL) delete GlobalDrawInfo; if (mVBO != NULL) delete mVBO; + if (glpart2) delete glpart2; + if (glpart) delete glpart; + if (mirrortexture) delete mirrortexture; + if (gllight) delete gllight; } //=========================================================================== diff --git a/src/gl/scene/gl_decal.cpp b/src/gl/scene/gl_decal.cpp index 42e38eb0..f7146672 100644 --- a/src/gl/scene/gl_decal.cpp +++ b/src/gl/scene/gl_decal.cpp @@ -40,7 +40,7 @@ #include "doomdata.h" #include "gl/gl_include.h" -#include "gl/gl_functions.h" +#include "gl/gl_lights.h" #include "gl/gl_intern.h" #include "a_sharedglobal.h" #include "gl/common/glc_clock.h" diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp index f583a755..2432b0f8 100644 --- a/src/gl/scene/gl_portal.cpp +++ b/src/gl/scene/gl_portal.cpp @@ -47,7 +47,7 @@ #include "gl/common/glc_clock.h" #include "gl/old_renderer/gl1_renderer.h" #include "gl/common/glc_glow.h" -#include "gl/gl_functions.h" +#include "gl/gl_lights.h" #include "gl/gl_intern.h" #include "gl/common/glc_templates.h" #include "gl/common/glc_geometric.h" diff --git a/src/gl/scene/gl_skydome.cpp b/src/gl/scene/gl_skydome.cpp index 3eb7fdb7..288b0197 100644 --- a/src/gl/scene/gl_skydome.cpp +++ b/src/gl/scene/gl_skydome.cpp @@ -41,7 +41,7 @@ #include "sc_man.h" #include "w_wad.h" #include "gl/old_renderer/gl1_renderer.h" -#include "gl/gl_functions.h" +#include "gl/gl_lights.h" #include "gl/gl_intern.h" #include "gl/old_renderer/gl1_shader.h" #include "gl/common/glc_convert.h" diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index b645baed..5a2afe7a 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -803,11 +803,11 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s FTexture *lump = NULL; if (gl_particles_style == 1) { - lump = glpart2; + lump = GLRenderer->glpart2; } else if (gl_particles_style == 2) { - lump = glpart; + lump = GLRenderer->glpart; } if (lump != NULL) diff --git a/src/gl/scene/gl_wall.h b/src/gl/scene/gl_wall.h index b92cf4d5..1687ad5b 100644 --- a/src/gl/scene/gl_wall.h +++ b/src/gl/scene/gl_wall.h @@ -326,4 +326,10 @@ public: double CalcIntersectionVertex(GLWall * w2); }; +inline float Dist2(float x1,float y1,float x2,float y2) +{ + return sqrtf((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); +} + + #endif diff --git a/src/gl/scene/gl_walls_draw.cpp b/src/gl/scene/gl_walls_draw.cpp index 60b4c9b2..bd99efe2 100644 --- a/src/gl/scene/gl_walls_draw.cpp +++ b/src/gl/scene/gl_walls_draw.cpp @@ -240,7 +240,7 @@ void GLWall::RenderFogBoundary() //========================================================================== void GLWall::RenderMirrorSurface() { - if (mirrortexture == NULL) return; + if (GLRenderer->mirrortexture == NULL) return; // Use sphere mapping for this gl.Enable(GL_TEXTURE_GEN_T); @@ -254,7 +254,7 @@ void GLWall::RenderMirrorSurface() gl.DepthFunc(GL_LEQUAL); gl_SetFog(lightlevel, extralight*gl_weaponlight, &Colormap, true); - FMaterial * pat=FMaterial::ValidateTexture(mirrortexture); + FMaterial * pat=FMaterial::ValidateTexture(GLRenderer->mirrortexture); pat->BindPatch(Colormap.colormap, 0); flags &= ~GLWF_GLOW; diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp index e781ac0d..483e7677 100644 --- a/src/gl/scene/gl_weapon.cpp +++ b/src/gl/scene/gl_weapon.cpp @@ -43,7 +43,7 @@ #include "v_video.h" #include "doomstat.h" #include "gl/gl_struct.h" -#include "gl/gl_functions.h" +#include "gl/gl_lights.h" #include "gl/gl_intern.h" #include "gl/old_renderer/gl1_renderer.h" diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 54f6267a..13b810fc 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -86,12 +86,10 @@ OpenGLFrameBuffer::OpenGLFrameBuffer(int width, int height, int bits, int refres InitializeState(); gl_GenerateGlobalBrightmapFromColormap(); - gl_InitSpecialTextures(); } OpenGLFrameBuffer::~OpenGLFrameBuffer() { - gl_FreeSpecialTextures(); delete GLRenderer; GLRenderer = NULL; } diff --git a/src/gl/textures/gl_bitmap.cpp b/src/gl/textures/gl_bitmap.cpp index fe125637..fbed4726 100644 --- a/src/gl/textures/gl_bitmap.cpp +++ b/src/gl/textures/gl_bitmap.cpp @@ -40,7 +40,7 @@ #include "r_translate.h" #include "v_palette.h" #include "templates.h" -#include "gl/gl_functions.h" +#include "gl/gl_lights.h" #include "gl/textures/gl_translate.h" #include "gl/textures/gl_bitmap.h" diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 104335ec..bc995fca 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -66,7 +66,7 @@ #include "md5.h" #include "compatibility.h" -#include "gl/data/gl_data.h" +#include "gl/gl_functions.h" #include "fragglescript/t_fs.h" diff --git a/src/r_main.cpp b/src/r_main.cpp index 79325b86..d1d0bcce 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -50,7 +50,7 @@ #include "r_bsp.h" #include "r_plane.h" #include "v_palette.h" -#include "gl/data/gl_data.h" +//#include "gl/data/gl_data.h" #include "gl/gl_functions.h" // MACROS ------------------------------------------------------------------ diff --git a/src/win32/win32gliface.cpp b/src/win32/win32gliface.cpp index 8b5044e7..c959d7de 100644 --- a/src/win32/win32gliface.cpp +++ b/src/win32/win32gliface.cpp @@ -5,7 +5,7 @@ #include "gl/common/glc_templates.h" #include "gl/gl_intern.h" #include "gl/gl_struct.h" -#include "gl/gl_functions.h" +#include "gl/common/glc_renderer.h" #include "gl/old_renderer/gl1_shader.h" #include "templates.h" #include "version.h"