- removed several unneeded GL headers from the software renderer's sources.

- consolidated the code to calculate a sprite's display angle for all 3 renderers.

As it turned out, they all differed in their feature support because they had always been updated independently by different people.
This commit is contained in:
Christoph Oelckers 2017-03-16 13:49:34 +01:00
parent 005e6871f9
commit b529b1e3a7
20 changed files with 100 additions and 103 deletions

View file

@ -1324,6 +1324,20 @@ public:
result.Roll = PrevAngles.Roll + deltaangle(PrevAngles.Roll, Angles.Roll) * ticFrac;
return result;
}
DAngle GetSpriteAngle(DAngle viewangle, double ticFrac)
{
if (flags7 & MF7_SPRITEANGLE)
{
return SpriteAngle;
}
else
{
DAngle thisang;
if (renderflags & RF_INTERPOLATEANGLES) thisang = PrevAngles.Yaw + deltaangle(PrevAngles.Yaw, Angles.Yaw) * ticFrac;
else thisang = Angles.Yaw;
return viewangle - (thisang + SpriteRotation);
}
}
DVector3 PosPlusZ(double zadd) const
{
return { X(), Y(), Z() + zadd };

View file

@ -72,16 +72,13 @@
#include "doomstat.h"
#include "serializer.h"
#include "g_levellocals.h"
#include "a_dynlight.h"
#include "actorinlines.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/data/gl_data.h"
#include "gl/dynlights/gl_dynlight.h"
#include "gl/utility/gl_convert.h"
#include "gl/utility/gl_templates.h"
#include "c_cvars.h"
#include "gl/system//gl_interface.h"
EXTERN_CVAR(Int, vid_renderer)
CUSTOM_CVAR (Bool, gl_lights, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
@ -168,7 +165,7 @@ void ADynamicLight::BeginPlay()
specialf1 = DAngle(double(SpawnAngle)).Normalized360().Degrees;
visibletoplayer = true;
if (gl.legacyMode && (flags4 & MF4_ATTENUATE))
if (vid_renderer == 1 && gl.legacyMode && (flags4 & MF4_ATTENUATE))
{
args[LIGHT_INTENSITY] = args[LIGHT_INTENSITY] * 2 / 3;
args[LIGHT_SECONDARY_INTENSITY] = args[LIGHT_SECONDARY_INTENSITY] * 2 / 3;
@ -793,7 +790,7 @@ CCMD(listlights)
if (dl->target)
{
FTextureID spr = gl_GetSpriteFrame(dl->target->sprite, dl->target->frame, 0, 0, NULL);
FTextureID spr = sprites[dl->target->sprite].GetSpriteFrame(dl->target->frame, 0, 0., nullptr);
Printf(", frame = %s ", TexMan[spr]->Name.GetChars());
}

View file

@ -333,42 +333,6 @@ CCMD(gl_resetmap)
}
//===========================================================================
//
// Gets the texture index for a sprite frame
//
//===========================================================================
FTextureID gl_GetSpriteFrame(unsigned sprite, int frame, int rot, angle_t ang, bool *mirror)
{
spritedef_t *sprdef = &sprites[sprite];
if (frame >= sprdef->numframes)
{
// If there are no frames at all for this sprite, don't draw it.
return FNullTextureID();
}
else
{
//picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0];
// choose a different rotation based on player view
spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + frame];
if (rot==-1)
{
if (sprframe->Texture[0] == sprframe->Texture[1])
{
rot = (ang + (angle_t)(ANGLE_90/4)*9) >> 28;
}
else
{
rot = (ang + (angle_t)(ANGLE_90/4)*9-(angle_t)(ANGLE_180/16)) >> 28;
}
}
if (mirror) *mirror = !!(sprframe->Flip&(1<<rot));
return sprframe->Texture[rot];
}
}
//==========================================================================
//
// Recalculate all heights affecting this vertex.

View file

@ -36,7 +36,6 @@ inline int getExtraLight()
}
void gl_RecalcVertexHeights(vertex_t * v);
FTextureID gl_GetSpriteFrame(unsigned sprite, int frame, int rot, angle_t ang, bool *mirror);
struct GLSectorStackPortal;

View file

@ -785,18 +785,22 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
patch = thing->picnum;
mirror = false;
}
else if (thing->flags7 & MF7_SPRITEANGLE)
{
patch = gl_GetSpriteFrame(spritenum, thing->frame, -1, (thing->SpriteAngle).BAMs(), &mirror);
}
else if (!(thing->renderflags & RF_FLATSPRITE))
{
patch = gl_GetSpriteFrame(spritenum, thing->frame, -1, (ang - (Angles.Yaw + thing->SpriteRotation)).BAMs(), &mirror);
}
else
{
// Flat sprites cannot rotate in a predictable manner.
patch = gl_GetSpriteFrame(spritenum, thing->frame, 0, 0, &mirror);
DAngle sprangle;
int rot;
if (!(thing->renderflags & RF_FLATSPRITE))
{
sprangle = thing->GetSpriteAngle(ang, r_viewpoint.TicFrac);
rot = -1;
}
else
{
// Flat sprites cannot rotate in a predictable manner.
sprangle = 0.;
rot = 0;
}
patch = sprites[spritenum].GetSpriteFrame(thing->frame, rot, sprangle, &mirror);
}
if (!patch.isValid()) return;

View file

@ -82,7 +82,7 @@ void GLSceneDrawer::DrawPSprite (player_t * player,DPSprite *psp, float sx, floa
// decide which patch to use
bool mirror;
FTextureID lump = gl_GetSpriteFrame(psp->GetSprite(), psp->GetFrame(), 0, 0, &mirror);
FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., &mirror);
if (!lump.isValid()) return;
FMaterial * tex = FMaterial::ValidateTexture(lump, true, false);
@ -172,7 +172,7 @@ static bool isBright(DPSprite *psp)
if (psp != nullptr && psp->GetState() != nullptr)
{
bool disablefullbright = false;
FTextureID lump = gl_GetSpriteFrame(psp->GetSprite(), psp->GetFrame(), 0, 0, NULL);
FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., nullptr);
if (lump.isValid())
{
FMaterial * tex = FMaterial::ValidateTexture(lump, false, false);

View file

@ -376,6 +376,10 @@ FTexture *RenderPolySprite::GetSpriteTexture(AActor *thing, /*out*/ bool &flipX)
{
const auto &viewpoint = PolyRenderer::Instance()->Thread.Viewport->viewpoint;
flipX = false;
if (thing->renderflags & RF_FLATSPRITE)
return nullptr; // do not draw flat sprites.
if (thing->picnum.isValid())
{
FTexture *tex = TexMan(thing->picnum);
@ -422,21 +426,15 @@ FTexture *RenderPolySprite::GetSpriteTexture(AActor *thing, /*out*/ bool &flipX)
{
//picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0];
// choose a different rotation based on player view
spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame];
DVector3 pos = thing->InterpolatedPosition(viewpoint.TicFrac);
pos.Z += thing->GetBobOffset(viewpoint.TicFrac);
DAngle ang = (pos - viewpoint.Pos).Angle();
angle_t rot;
if (sprframe->Texture[0] == sprframe->Texture[1])
{
rot = (ang - thing->Angles.Yaw + 45.0 / 2 * 9).BAMs() >> 28;
}
else
{
rot = (ang - thing->Angles.Yaw + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28;
}
flipX = (sprframe->Flip & (1 << rot)) != 0;
return TexMan[sprframe->Texture[rot]]; // Do not animate the rotation
DAngle sprangle = thing->GetSpriteAngle((pos - viewpoint.Pos).Angle(), viewpoint.TicFrac);
FTextureID tex = sprdef->GetSpriteFrame(thing->frame, -1, sprangle, &flipX);
if (!tex.isValid()) return nullptr;
return TexMan[tex];
}
}
}

View file

@ -35,6 +35,39 @@ uint8_t OtherGameSkinRemap[256];
PalEntry OtherGameSkinPalette[256];
//===========================================================================
//
// Gets the texture index for a sprite frame
//
//===========================================================================
FTextureID spritedef_t::GetSpriteFrame(int frame, int rot, DAngle ang, bool *mirror)
{
if ((unsigned)frame >= numframes)
{
// If there are no frames at all for this sprite, don't draw it.
return FNullTextureID();
}
else
{
// choose a different rotation based on player view
spriteframe_t *sprframe = &SpriteFrames[spriteframes + frame];
if (rot == -1)
{
if (sprframe->Texture[0] == sprframe->Texture[1])
{
rot = (ang + 45.0 / 2 * 9).BAMs() >> 28;
}
else
{
rot = (ang + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28;
}
}
if (mirror) *mirror = !!(sprframe->Flip&(1 << rot));
return sprframe->Texture[rot];
}
}
//
// R_InstallSpriteLump

View file

@ -36,6 +36,8 @@ struct spritedef_t
};
uint8_t numframes;
uint16_t spriteframes;
FTextureID GetSpriteFrame(int frame, int rot, DAngle ang, bool *mirror);
};
extern TArray<spriteframe_t> SpriteFrames;

View file

@ -36,7 +36,7 @@
#include "v_palette.h"
#include "r_data/colormaps.h"
#include "r_draw_rgba.h"
#include "gl/data/gl_matrix.h"
//#include "gl/data/gl_matrix.h"
#include "swrenderer/viewport/r_viewport.h"
#include "swrenderer/scene/r_light.h"
#ifdef NO_SSE

View file

@ -28,7 +28,7 @@
#include "g_level.h"
#include "v_palette.h"
#include "r_data/colormaps.h"
#include "gl/dynlights/gl_dynlight.h"
#include "a_dynlight.h"
#include "swrenderer/drawers/r_draw_rgba.h"
#include "swrenderer/scene/r_opaque_pass.h"
#include "swrenderer/scene/r_3dfloors.h"

View file

@ -28,7 +28,7 @@
#include "r_walldraw.h"
#include "v_palette.h"
#include "r_data/colormaps.h"
#include "gl/dynlights/gl_dynlight.h"
#include "a_dynlight.h"
#include "swrenderer/drawers/r_draw.h"
#include "swrenderer/segments/r_drawsegment.h"
#include "swrenderer/scene/r_opaque_pass.h"

View file

@ -33,7 +33,7 @@
#include "v_palette.h"
#include "r_data/colormaps.h"
#include "swrenderer/drawers/r_draw_rgba.h"
#include "gl/dynlights/gl_dynlight.h"
#include "a_dynlight.h"
#include "swrenderer/segments/r_clipsegment.h"
#include "swrenderer/segments/r_drawsegment.h"
#include "swrenderer/scene/r_portal.h"

View file

@ -27,7 +27,7 @@
#include "cmdlib.h"
#include "d_net.h"
#include "g_level.h"
#include "gl/dynlights/gl_dynlight.h"
#include "a_dynlight.h"
#include "swrenderer/plane/r_visibleplane.h"
#include "swrenderer/plane/r_planerenderer.h"

View file

@ -32,7 +32,7 @@
#include "v_palette.h"
#include "r_data/colormaps.h"
#include "swrenderer/drawers/r_draw_rgba.h"
#include "gl/dynlights/gl_dynlight.h"
#include "a_dynlight.h"
#include "swrenderer/segments/r_clipsegment.h"
#include "swrenderer/segments/r_drawsegment.h"
#include "swrenderer/line/r_wallsetup.h"

View file

@ -33,7 +33,7 @@
#include "v_palette.h"
#include "r_data/colormaps.h"
#include "swrenderer/drawers/r_draw_rgba.h"
#include "gl/dynlights/gl_dynlight.h"
#include "a_dynlight.h"
#include "swrenderer/segments/r_clipsegment.h"
#include "swrenderer/segments/r_drawsegment.h"
#include "swrenderer/scene/r_portal.h"

View file

@ -27,7 +27,7 @@
#include "cmdlib.h"
#include "d_net.h"
#include "g_level.h"
#include "gl/dynlights/gl_dynlight.h"
#include "a_dynlight.h"
#include "swrenderer/r_memory.h"
#include "swrenderer/r_renderthread.h"
#include "swrenderer/scene/r_opaque_pass.h"

View file

@ -27,7 +27,7 @@
#include "cmdlib.h"
#include "d_net.h"
#include "g_level.h"
#include "gl/dynlights/gl_dynlight.h"
#include "a_dynlight.h"
#include "swrenderer/r_memory.h"
#include "swrenderer/scene/r_opaque_pass.h"
#include "swrenderer/scene/r_3dfloors.h"

View file

@ -997,34 +997,20 @@ namespace swrenderer
}
else
{
//picnum = SpriteFrames[sprdef->spriteframes + thing->frame].Texture[0];
// choose a different rotation based on player view
spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + thing->frame];
DAngle ang = (sprite.pos - Thread->Viewport->viewpoint.Pos).Angle();
angle_t rot;
if (sprframe->Texture[0] == sprframe->Texture[1])
{
if (thing->flags7 & MF7_SPRITEANGLE)
rot = (thing->SpriteAngle + 45.0 / 2 * 9).BAMs() >> 28;
else
rot = (ang - (thing->Angles.Yaw + thing->SpriteRotation) + 45.0 / 2 * 9).BAMs() >> 28;
}
else
{
if (thing->flags7 & MF7_SPRITEANGLE)
rot = (thing->SpriteAngle + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28;
else
rot = (ang - (thing->Angles.Yaw + thing->SpriteRotation) + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28;
}
sprite.picnum = sprframe->Texture[rot];
if (sprframe->Flip & (1 << rot))
auto &viewpoint = Thread->Viewport->viewpoint;
DAngle sprangle = thing->GetSpriteAngle((sprite.pos - viewpoint.Pos).Angle(), viewpoint.TicFrac);
bool flipX;
FTextureID tex = sprdef->GetSpriteFrame(thing->frame, -1, sprangle, &flipX);
if (!tex.isValid()) return false;
if (flipX)
{
sprite.renderflags ^= RF_XFLIP;
}
sprite.tex = TexMan[sprite.picnum]; // Do not animate the rotation
sprite.tex = TexMan[tex]; // Do not animate the rotation
if (r_drawvoxels)
{
sprite.voxel = sprframe->Voxel;
sprite.voxel = SpriteFrames[sprdef->spriteframes + thing->frame].Voxel;
}
}

View file

@ -56,7 +56,7 @@
#include "swrenderer/viewport/r_viewport.h"
#include "swrenderer/r_memory.h"
#include "swrenderer/r_renderthread.h"
#include "gl/dynlights/gl_dynlight.h"
#include "a_dynlight.h"
EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor)
EXTERN_CVAR(Bool, gl_light_sprites)