- moved weapon drawing to hwrenderer.

This commit is contained in:
Christoph Oelckers 2018-10-22 23:40:44 +02:00
parent 08e1b49988
commit 93599e483f
7 changed files with 82 additions and 123 deletions

View file

@ -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

View file

@ -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);

View file

@ -30,7 +30,6 @@ enum DrawListType
struct FDrawInfo : public HWDrawInfo
{
HWDrawList drawlists[GLDL_TYPES];
TArray<HUDSprite> 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<FFlatVertex *, unsigned int> 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

View file

@ -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);

View file

@ -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);
}

View file

@ -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<IPortal *> Portals;
TArray<GLDecal *> Decals[2]; // the second slot is for mirrors which get rendered in a separate pass.
TArray<HUDSprite> hudsprites; // These may just be stored by value.
TArray<MissingTextureInfo> MissingUpperTextures;
TArray<MissingTextureInfo> 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<GLDecal *> &decals);
void DrawPlayerSprites(bool hudModelStep, FRenderState &state);
void ProcessLowerMinisegs(TArray<seg_t *> &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<FFlatVertex *, unsigned int> 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;

View file

@ -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);
}
}
}
}