From 93599e483f3a3686617b40d4f64c1711342b3925 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 22 Oct 2018 23:40:44 +0200 Subject: [PATCH] - moved weapon drawing to hwrenderer. --- src/CMakeLists.txt | 1 - src/gl/scene/gl_drawinfo.cpp | 7 ++ src/gl/scene/gl_drawinfo.h | 10 +-- src/gl/scene/gl_scene.cpp | 6 +- src/gl/scene/gl_weapon.cpp | 107 ----------------------------- src/hwrenderer/scene/hw_drawinfo.h | 7 +- src/hwrenderer/scene/hw_weapon.cpp | 67 +++++++++++++++++- 7 files changed, 82 insertions(+), 123 deletions(-) delete mode 100644 src/gl/scene/gl_weapon.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b0f666e1e..d3cf31ef7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -822,7 +822,6 @@ set( FASTMATH_SOURCES textures/hires/xbr/xbrz_old.cpp gl/scene/gl_drawinfo.cpp gl/scene/gl_skydome.cpp - gl/scene/gl_weapon.cpp gl/scene/gl_scene.cpp gl/scene/gl_portal.cpp gl/scene/gl_walls_draw.cpp diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 1125208b5..f31d77855 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -305,6 +305,13 @@ void FDrawInfo::DrawModel(GLSprite *spr, FRenderState &state) renderer.RenderModel(spr->x, spr->y, spr->z, spr->modelframe, spr->actor, Viewpoint.TicFrac); } +void FDrawInfo::DrawHUDModel(HUDSprite *huds, FRenderState &state) +{ + FGLModelRenderer renderer(this, huds->lightindex); + renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my); +} + + void FDrawInfo::SetDepthMask(bool on) { glDepthMask(on); diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index dc306221c..213ae3052 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -30,7 +30,6 @@ enum DrawListType struct FDrawInfo : public HWDrawInfo { HWDrawList drawlists[GLDL_TYPES]; - TArray hudsprites; // These may just be stored by value. int vpIndex; void ApplyVPUniforms() override; @@ -40,7 +39,6 @@ struct FDrawInfo : public HWDrawInfo void AddPortal(GLWall *w, int portaltype) override; void AddFlat(GLFlat *flat, bool fog) override; void AddSprite(GLSprite *sprite, bool translucent) override; - void AddHUDSprite(HUDSprite *huds) override; std::pair AllocVertices(unsigned int count) override; int UploadLights(FDynLightData &data) override; @@ -48,6 +46,7 @@ struct FDrawInfo : public HWDrawInfo void Draw(EDrawType dt, FRenderState &state, int index, int count, bool apply = true) override; void DrawIndexed(EDrawType dt, FRenderState &state, int index, int count, bool apply = true) override; void DrawModel(GLSprite *spr, FRenderState &state) override; + void DrawHUDModel(HUDSprite *spr, FRenderState &state) override; void SetDepthMask(bool on) override; void SetDepthFunc(int func) override; @@ -55,9 +54,6 @@ struct FDrawInfo : public HWDrawInfo void StartScene(); - void DrawPSprite(HUDSprite *huds); - void DrawPlayerSprites(bool hudModelStep); - void DoDrawSorted(HWDrawList *dl, SortNode * head); void DrawSorted(int listindex); @@ -87,8 +83,4 @@ struct FDrawInfo : public HWDrawInfo } }; - - -void gl_SetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblending); - #endif diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 34319f8b1..556721b0d 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -166,7 +166,7 @@ void FDrawInfo::RenderScene(int recursion) // Part 1: solid geometry. This is set up so that there are no transparent parts glDepthFunc(GL_LESS); gl_RenderState.AlphaFunc(Alpha_GEqual, 0.f); - glDisable(GL_POLYGON_OFFSET_FILL); + gl_RenderState.ClearDepthBias(); gl_RenderState.EnableTexture(gl_texture); gl_RenderState.EnableBrightmap(true); @@ -306,7 +306,7 @@ void FDrawInfo::EndDrawScene(sector_t * viewsector) { // [BB] The HUD model should be drawn over everything else already drawn. glClear(GL_DEPTH_BUFFER_BIT); - DrawPlayerSprites(true); + DrawPlayerSprites(true, gl_RenderState); } glDisable(GL_STENCIL_TEST); @@ -332,7 +332,7 @@ void FDrawInfo::DrawEndScene2D(sector_t * viewsector) glDisable(GL_MULTISAMPLE); - DrawPlayerSprites(false); + DrawPlayerSprites(false, gl_RenderState); gl_RenderState.SetSoftLightLevel(-1); diff --git a/src/gl/scene/gl_weapon.cpp b/src/gl/scene/gl_weapon.cpp deleted file mode 100644 index ba4febce7..000000000 --- a/src/gl/scene/gl_weapon.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2000-2018 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// -/* -** gl_weapon.cpp -** Weapon sprite drawing -** -*/ - -#include "gl_load/gl_system.h" -#include "r_utility.h" -#include "v_video.h" - -#include "gl_load/gl_interface.h" -#include "hwrenderer/utility/hw_cvars.h" -#include "hwrenderer/scene/hw_weapon.h" -#include "gl/renderer/gl_renderer.h" -#include "gl/renderer/gl_renderstate.h" -#include "gl/data/gl_vertexbuffer.h" -#include "gl/scene/gl_drawinfo.h" -#include "gl/models/gl_models.h" -#include "gl/dynlights/gl_lightbuffer.h" - -//========================================================================== -// -// R_DrawPSprite -// -//========================================================================== - -void FDrawInfo::DrawPSprite (HUDSprite *huds) -{ - if (huds->RenderStyle.BlendOp == STYLEOP_Shadow) - { - gl_RenderState.SetColor(0.2f, 0.2f, 0.2f, 0.33f, huds->cm.Desaturation); - } - else - { - SetColor(huds->lightlevel, 0, huds->cm, huds->alpha, true); - } - gl_RenderState.SetRenderStyle(huds->RenderStyle); - gl_RenderState.SetTextureMode(huds->RenderStyle); - gl_RenderState.SetObjectColor(huds->ObjectColor); - gl_RenderState.SetDynLight(huds->dynrgb[0], huds->dynrgb[1], huds->dynrgb[2]); - gl_RenderState.EnableBrightmap(!(huds->RenderStyle.Flags & STYLEF_ColorIsFixed)); - - if (huds->mframe) - { - gl_RenderState.AlphaFunc(Alpha_GEqual, 0); - FGLModelRenderer renderer(this, huds->lightindex); - renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my); - } - else - { - float thresh = (huds->tex->tex->GetTranslucency() || huds->OverrideShader != -1) ? 0.f : gl_mask_sprite_threshold; - gl_RenderState.AlphaFunc(Alpha_GEqual, thresh); - gl_RenderState.ApplyMaterial(huds->tex, CLAMP_XY_NOMIP, 0, huds->OverrideShader); - gl_RenderState.Apply(); - GLRenderer->mVBO->RenderArray(GL_TRIANGLE_STRIP, huds->mx, 4); - } - - gl_RenderState.SetTextureMode(TM_NORMAL); - gl_RenderState.AlphaFunc(Alpha_GEqual, gl_mask_sprite_threshold); - gl_RenderState.SetObjectColor(0xffffffff); - gl_RenderState.SetDynLight(0, 0, 0); - gl_RenderState.EnableBrightmap(false); -} - -//========================================================================== -// -// R_DrawPlayerSprites -// -//========================================================================== - -void FDrawInfo::DrawPlayerSprites(bool hudModelStep) -{ - int oldlightmode = level.lightmode; - if (!hudModelStep && level.lightmode == 8) level.lightmode = 2; // Software lighting cannot handle 2D content so revert to lightmode 2 for that. - for(auto &hudsprite : hudsprites) - { - if ((!!hudsprite.mframe) == hudModelStep) - DrawPSprite(&hudsprite); - } - level.lightmode = oldlightmode; -} - -void FDrawInfo::AddHUDSprite(HUDSprite *huds) -{ - hudsprites.Push(*huds); -} diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 8e5ed90fd..3aa39dff2 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -6,6 +6,7 @@ #include "r_utility.h" #include "hw_viewpointuniforms.h" #include "v_video.h" +#include "hw_weapon.h" enum EDrawType { @@ -138,6 +139,7 @@ struct HWDrawInfo HWViewpointUniforms VPUniforms; // per-viewpoint uniform state TArray Portals; TArray Decals[2]; // the second slot is for mirrors which get rendered in a separate pass. + TArray hudsprites; // These may just be stored by value. TArray MissingUpperTextures; TArray MissingLowerTextures; @@ -191,6 +193,7 @@ private: void DoSubsector(subsector_t * sub); int SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &lightdata, const secplane_t *plane); int CreateOtherPlaneVertices(subsector_t *sub, const secplane_t *plane); + void DrawPSprite(HUDSprite *huds, FRenderState &state); public: gl_subsectorrendernode * GetOtherFloorPlanes(unsigned int sector) @@ -293,6 +296,7 @@ public: angle_t FrustumAngle(); void DrawDecals(FRenderState &state, TArray &decals); + void DrawPlayerSprites(bool hudModelStep, FRenderState &state); void ProcessLowerMinisegs(TArray &lowersegs); virtual void AddSubsectorToPortal(FSectorPortalGroup *portal, subsector_t *sub) = 0; @@ -302,18 +306,19 @@ public: virtual void AddMirrorSurface(GLWall *w) = 0; virtual void AddFlat(GLFlat *flat, bool fog) = 0; virtual void AddSprite(GLSprite *sprite, bool translucent) = 0; - virtual void AddHUDSprite(HUDSprite *huds) = 0; virtual int UploadLights(FDynLightData &data) = 0; virtual void ApplyVPUniforms() = 0; virtual bool SetDepthClamp(bool on) = 0; GLDecal *AddDecal(bool onmirror); + virtual std::pair AllocVertices(unsigned int count) = 0; virtual void Draw(EDrawType dt, FRenderState &state, int index, int count, bool apply = true) = 0; virtual void DrawIndexed(EDrawType dt, FRenderState &state, int index, int count, bool apply = true) = 0; virtual void DrawModel(GLSprite *spr, FRenderState &state) = 0; + virtual void DrawHUDModel(HUDSprite *spr, FRenderState &state) = 0; diff --git a/src/hwrenderer/scene/hw_weapon.cpp b/src/hwrenderer/scene/hw_weapon.cpp index 8e3650310..22bc482fe 100644 --- a/src/hwrenderer/scene/hw_weapon.cpp +++ b/src/hwrenderer/scene/hw_weapon.cpp @@ -41,6 +41,7 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/data/flatvertices.h" +#include "hw_renderstate.h" EXTERN_CVAR(Float, transsouls) EXTERN_CVAR(Int, gl_fuzztype) @@ -48,6 +49,67 @@ EXTERN_CVAR(Bool, r_drawplayersprites) EXTERN_CVAR(Bool, r_deathcamera) +//========================================================================== +// +// R_DrawPSprite +// +//========================================================================== + +void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state) +{ + if (huds->RenderStyle.BlendOp == STYLEOP_Shadow) + { + state.SetColor(0.2f, 0.2f, 0.2f, 0.33f, huds->cm.Desaturation); + } + else + { + state.SetColor(huds->lightlevel, 0, isFullbrightScene(), huds->cm, huds->alpha, true); + } + state.SetRenderStyle(huds->RenderStyle); + state.SetTextureMode(huds->RenderStyle); + state.SetObjectColor(huds->ObjectColor); + state.SetDynLight(huds->dynrgb[0], huds->dynrgb[1], huds->dynrgb[2]); + state.EnableBrightmap(!(huds->RenderStyle.Flags & STYLEF_ColorIsFixed)); + + if (huds->mframe) + { + state.AlphaFunc(Alpha_GEqual, 0); + DrawHUDModel(huds, state); + } + else + { + float thresh = (huds->tex->tex->GetTranslucency() || huds->OverrideShader != -1) ? 0.f : gl_mask_sprite_threshold; + state.AlphaFunc(Alpha_GEqual, thresh); + state.SetMaterial(huds->tex, CLAMP_XY_NOMIP, 0, huds->OverrideShader); + Draw(DT_TriangleStrip, state, huds->mx, 4); + } + + state.SetTextureMode(TM_NORMAL); + state.AlphaFunc(Alpha_GEqual, gl_mask_sprite_threshold); + state.SetObjectColor(0xffffffff); + state.SetDynLight(0, 0, 0); + state.EnableBrightmap(false); +} + +//========================================================================== +// +// R_DrawPlayerSprites +// +//========================================================================== + +void HWDrawInfo::DrawPlayerSprites(bool hudModelStep, FRenderState &state) +{ + int oldlightmode = level.lightmode; + if (!hudModelStep && level.lightmode == 8) level.lightmode = 2; // Software lighting cannot handle 2D content so revert to lightmode 2 for that. + for (auto &hudsprite : hudsprites) + { + if ((!!hudsprite.mframe) == hudModelStep) + DrawPSprite(&hudsprite, state); + } + level.lightmode = oldlightmode; +} + + //========================================================================== // // @@ -490,7 +552,7 @@ void HWDrawInfo::PreparePlayerSprites(sector_t * viewsector, area_t in_area) { if (!hudsprite.GetWeaponRect(this, psp, spos.X, spos.Y, player)) continue; } - AddHUDSprite(&hudsprite); + hudsprites.Push(hudsprite); } level.lightmode = oldlightmode; PrepareTargeterSprites(); @@ -537,8 +599,9 @@ void HWDrawInfo::PrepareTargeterSprites() hudsprite.weapon = psp; if (hudsprite.GetWeaponRect(this, psp, psp->x, psp->y, player)) { - AddHUDSprite(&hudsprite); + hudsprites.Push(hudsprite); } } } } +