- added some things from Raze to allow using the same code in both projects.

This commit is contained in:
Christoph Oelckers 2020-04-11 19:51:22 +02:00
parent 5fe22c70b5
commit 1e40b745d5
13 changed files with 189 additions and 41 deletions

View file

@ -1751,7 +1751,7 @@ void DAutomap::drawMline (mline_t *ml, const AMColor &color)
if (clipMline (ml, &fl))
{
twod->AddLine (f_x + fl.a.x, f_y + fl.a.y, f_x + fl.b.x, f_y + fl.b.y, -1, color.RGB);
twod->AddLine (f_x + fl.a.x, f_y + fl.a.y, f_x + fl.b.x, f_y + fl.b.y, -1, -1, INT_MAX, INT_MAX, color.RGB);
}
}
@ -3166,7 +3166,7 @@ void DAutomap::drawAuthorMarkers ()
void DAutomap::drawCrosshair (const AMColor &color)
{
twod->AddPixel(f_w/2, (f_h+1)/2, -1, color.RGB);
twod->AddPixel(f_w/2, (f_h+1)/2, color.RGB);
}
//=============================================================================

View file

@ -217,6 +217,15 @@ void F2DDrawer::AddIndices(int firstvert, int count, ...)
}
}
void F2DDrawer::AddIndices(int firstvert, TArray<int> &v)
{
int addr = mIndices.Reserve(v.Size());
for (unsigned i = 0; i < v.Size(); i++)
{
mIndices[addr + i] = firstvert + v[i];
}
}
//==========================================================================
//
// SetStyle
@ -423,7 +432,7 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms)
// Note that this only works for unflipped full textures.
if (parms.windowleft > 0 || parms.windowright < parms.texwidth)
{
double wi = MIN(parms.windowright, parms.texwidth);
double wi = std::min(parms.windowright, parms.texwidth);
x += parms.windowleft * xscale;
w -= (parms.texwidth - wi + parms.windowleft) * xscale;
@ -621,6 +630,53 @@ void F2DDrawer::AddPoly(FTexture *texture, FVector2 *points, int npoints,
//
//==========================================================================
void F2DDrawer::AddPoly(FTexture* img, FVector4* vt, size_t vtcount, unsigned int* ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2)
{
RenderCommand dg = {};
int method = 0;
dg.mType = DrawTypeTriangles;
if (clipx1 > 0 || clipy1 > 0 || clipx2 < GetWidth() - 1 || clipy2 < GetHeight() - 1)
{
dg.mScissor[0] = clipx1;
dg.mScissor[1] = clipy1;
dg.mScissor[2] = clipx2 + 1;
dg.mScissor[3] = clipy2 + 1;
dg.mFlags |= DTF_Scissor;
}
dg.mTexture = img;
dg.mTranslationId = translation;
dg.mColor1 = color;
dg.mVertCount = (int)vtcount;
dg.mVertIndex = (int)mVertices.Reserve(vtcount);
dg.mRenderStyle = LegacyRenderStyles[STYLE_Translucent];
dg.mIndexIndex = mIndices.Size();
dg.mFlags |= DTF_Wrap;
auto ptr = &mVertices[dg.mVertIndex];
for (size_t i=0;i<vtcount;i++)
{
ptr->Set(vt[i].X, vt[i].Y, 0.f, vt[i].Z, vt[i].W, color);
ptr++;
}
dg.mIndexIndex = mIndices.Size();
mIndices.Reserve(idxcount);
for (size_t i = 0; i < idxcount; i++)
{
mIndices[dg.mIndexIndex + i] = ind[i] + dg.mVertIndex;
}
dg.mIndexCount = (int)idxcount;
AddCommand(&dg);
}
//==========================================================================
//
//
//
//==========================================================================
void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FTexture *src, bool local_origin)
{
float fU1, fU2, fV1, fV2;
@ -688,19 +744,33 @@ void F2DDrawer::AddColorOnlyQuad(int x1, int y1, int w, int h, PalEntry color, F
AddCommand(&dg);
}
void F2DDrawer::ClearScreen(PalEntry color)
{
AddColorOnlyQuad(0, 0, GetWidth(), GetHeight(), color);
}
//==========================================================================
//
//
//
//==========================================================================
void F2DDrawer::AddLine(int x1, int y1, int x2, int y2, int palcolor, uint32_t color, uint8_t alpha)
void F2DDrawer::AddLine(float x1, float y1, float x2, float y2, int clipx1, int clipy1, int clipx2, int clipy2, uint32_t color, uint8_t alpha)
{
PalEntry p = color ? (PalEntry)color : GPalette.BaseColors[palcolor];
PalEntry p = (PalEntry)color;
p.a = alpha;
RenderCommand dg;
if (clipx1 > 0 || clipy1 > 0 || clipx2 < GetWidth()- 1 || clipy2 < GetHeight() - 1)
{
dg.mScissor[0] = clipx1;
dg.mScissor[1] = clipy1;
dg.mScissor[2] = clipx2 + 1;
dg.mScissor[3] = clipy2 + 1;
dg.mFlags |= DTF_Scissor;
}
dg.mType = DrawTypeLines;
dg.mRenderStyle = LegacyRenderStyles[STYLE_Translucent];
dg.mVertCount = 2;
@ -757,9 +827,9 @@ void F2DDrawer::AddThickLine(int x1, int y1, int x2, int y2, double thickness, u
//
//==========================================================================
void F2DDrawer::AddPixel(int x1, int y1, int palcolor, uint32_t color)
void F2DDrawer::AddPixel(int x1, int y1, uint32_t color)
{
PalEntry p = color ? (PalEntry)color : GPalette.BaseColors[palcolor];
PalEntry p = (PalEntry)color;
p.a = 255;
RenderCommand dg;

View file

@ -2,6 +2,7 @@
#define __2DDRAWER_H
#include "tarray.h"
#include "vectors.h"
#include "textures.h"
#include "renderstyle.h"
#include "dobject.h"
@ -52,6 +53,20 @@ public:
TArray<DVector2> mTransformedVertices;
};
struct F2DPolygons
{
TArray<FVector4> vertices;
TArray<int> indices;
unsigned AllocVertices(int num)
{
auto vindex = vertices.Reserve(num);
indices.Push(num);
return vindex;
}
};
class F2DDrawer
{
public:
@ -61,6 +76,7 @@ public:
DrawTypeTriangles,
DrawTypeLines,
DrawTypePoints,
DrawTypeRotateSprite,
};
enum ETextureFlags : uint8_t
@ -149,11 +165,11 @@ public:
public:
int fullscreenautoaspect = 0;
int cliptop = -1, clipleft = -1, clipwidth = -1, clipheight = -1;
private:
int AddCommand(const RenderCommand *data);
void AddIndices(int firstvert, int count, ...);
private:
void AddIndices(int firstvert, TArray<int> &v);
bool SetStyle(FTexture *tex, DrawParms &parms, PalEntry &color0, RenderCommand &quad);
void SetColorOverlay(PalEntry color, float alpha, PalEntry &vertexcolor, PalEntry &overlaycolor);
@ -163,17 +179,20 @@ public:
void AddPoly(FTexture *texture, FVector2 *points, int npoints,
double originx, double originy, double scalex, double scaley,
DAngle rotation, const FColormap &colormap, PalEntry flatcolor, double lightlevel, uint32_t *indices, size_t indexcount);
void AddPoly(FTexture* img, FVector4 *vt, size_t vtcount, unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2);
void FillPolygon(int* rx1, int* ry1, int* xb1, int32_t npoints, int picnum, int palette, int shade, int props, const FVector2& xtex, const FVector2& ytex, const FVector2& otex,
int clipx1, int clipy1, int clipx2, int clipy2);
void AddFlatFill(int left, int top, int right, int bottom, FTexture *src, bool local_origin = false);
void AddColorOnlyQuad(int left, int top, int width, int height, PalEntry color, FRenderStyle *style);
void AddColorOnlyQuad(int left, int top, int width, int height, PalEntry color, FRenderStyle *style = nullptr);
void ClearScreen(PalEntry color = 0xff000000);
void AddDim(PalEntry color, float damount, int x1, int y1, int w, int h);
void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color);
void AddLine(int x1, int y1, int x2, int y2, int palcolor, uint32_t color, uint8_t alpha = 255);
void AddLine(float x1, float y1, float x2, float y2, int cx, int cy, int cx2, int cy2, uint32_t color, uint8_t alpha = 255);
void AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color, uint8_t alpha = 255);
void AddPixel(int x1, int y1, int palcolor, uint32_t color);
void AddPixel(int x1, int y1, uint32_t color);
void Clear();
int GetWidth() const { return Width; }

View file

@ -1179,10 +1179,10 @@ void FillBorder (F2DDrawer *drawer, FTexture *img)
//
//==========================================================================
static void DrawLine(int x0, int y0, int x1, int y1, int palColor, uint32_t realcolor, int alpha)
static void DrawLine(int x0, int y0, int x1, int y1, uint32_t realcolor, int alpha)
{
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
twod->AddLine(x0, y0, x1, y1, palColor, realcolor, alpha);
twod->AddLine((float)x0, (float)y0, (float)x1, (float)y1, -1, -1, INT_MAX, INT_MAX, realcolor | MAKEARGB(255, 0, 0, 0), alpha);
}
DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine)
@ -1194,7 +1194,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine)
PARAM_INT(y1);
PARAM_INT(color);
PARAM_INT(alpha);
DrawLine(x0, y0, x1, y1, -1, color | MAKEARGB(255, 0, 0, 0), alpha);
DrawLine(x0, y0, x1, y1, color, alpha);
return 0;
}
@ -1359,3 +1359,26 @@ void DrawBorder (F2DDrawer *drawer, FTextureID picnum, int x1, int y1, int x2, i
}
}
//==========================================================================
//
// V_DrawFrame
//
// Draw a frame around the specified area using the view border
// frame graphics. The border is drawn outside the area, not in it.
//
//==========================================================================
void DrawFrame(F2DDrawer* twod, PalEntry color, int left, int top, int width, int height, int thickness)
{
// Sanity check for incomplete gameinfo
int offset = thickness == -1 ? twod->GetHeight() / 400 : thickness;
int right = left + width;
int bottom = top + height;
// Draw top and bottom sides.
twod->AddColorOnlyQuad(left, top - offset, width, offset, color);
twod->AddColorOnlyQuad(left - offset, top - offset, offset, height + 2 * offset, color);
twod->AddColorOnlyQuad(left, bottom, width, offset, color);
twod->AddColorOnlyQuad(right, top - offset, offset, height + 2 * offset, color);
}

View file

@ -220,6 +220,7 @@ void FillBorder(F2DDrawer *drawer, FTexture* img); // Fills the border around a
void DrawFrame(F2DDrawer* drawer, int left, int top, int width, int height);
void DrawBorder(F2DDrawer* drawer, FTextureID, int x1, int y1, int x2, int y2);
void DrawFrame(F2DDrawer* twod, PalEntry color, int left, int top, int width, int height, int thickness);
// Set an area to a specified color
void ClearRect(F2DDrawer* drawer, int left, int top, int right, int bottom, int palcolor, uint32_t color);
@ -229,3 +230,5 @@ void VirtualToRealCoords(F2DDrawer* drawer, double& x, double& y, double& w, dou
// Code that uses these (i.e. SBARINFO) should probably be evaluated for using doubles all around instead.
void VirtualToRealCoordsInt(F2DDrawer* drawer, int& x, int& y, int& w, int& h, int vwidth, int vheight, bool vbottom = false, bool handleaspect = true);
extern int CleanWidth, CleanHeight, CleanXfac, CleanYfac;
extern int CleanWidth_1, CleanHeight_1, CleanXfac_1, CleanYfac_1;

View file

@ -42,6 +42,7 @@
#include "v_draw.h"
#include "gstrings.h"
#include "vm.h"
#include "printf.h"
int ListGetInt(VMVa_List &tags);

View file

@ -33,7 +33,7 @@
*/
#include "stats.h"
#include "v_video.h"
#include "v_draw.h"
#include "v_text.h"
#include "v_font.h"
#include "c_console.h"

View file

@ -68,7 +68,7 @@
//
//==========================================================================
FFont::FFont (const char *name, const char *nametemplate, const char *filetemplate, int lfirst, int lcount, int start, int fdlump, int spacewidth, bool notranslate, bool iwadonly, bool doomtemplate)
FFont::FFont (const char *name, const char *nametemplate, const char *filetemplate, int lfirst, int lcount, int start, int fdlump, int spacewidth, bool notranslate, bool iwadonly, bool doomtemplate, GlyphSet *baseGlyphs)
{
int i;
FTextureID lump;
@ -185,6 +185,22 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
}
else
{
if (baseGlyphs)
{
// First insert everything from the given glyph set.
GlyphSet::Iterator it(*baseGlyphs);
GlyphSet::Pair* pair;
while (it.NextPair(pair))
{
if (pair->Value && pair->Value->GetTexelWidth() > 0 && pair->Value->GetTexelHeight() > 0)
{
auto position = pair->Key;
if (position < minchar) minchar = position;
if (position > maxchar) maxchar = position;
charMap.Insert(position, pair->Value);
}
}
}
if (nametemplate != nullptr)
{
if (!iwadonly)

View file

@ -1,3 +1,4 @@
#pragma once
/*
** v_font.h
**
@ -31,8 +32,6 @@
**
*/
#ifndef __V_FONT_H__
#define __V_FONT_H__
#include "filesystem.h"
#include "vectors.h"
@ -78,6 +77,7 @@ enum EColorRange : int
extern int NumTextColors;
using GlyphSet = TMap<int, FTexture*>;
class FFont
{
@ -94,7 +94,7 @@ public:
Custom
};
FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false, bool iwadonly = false, bool doomtemplate = false);
FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false, bool iwadonly = false, bool doomtemplate = false, GlyphSet *baseGlpyphs = nullptr);
virtual ~FFont ();
virtual FTexture *GetChar (int code, int translation, int *const width, bool *redirected = nullptr) const;
@ -194,4 +194,3 @@ void V_InitFontColors();
char* CleanseString(char* str);
#endif //__V_FONT_H__

View file

@ -88,6 +88,25 @@ TArray<uint8_t> FImageTexture::Get8BitPixels(bool alpha)
return mImage->GetPalettedPixels(alpha? alpha : bNoRemap0 ? FImageSource::noremap0 : FImageSource::normal);
}
//===========================================================================
//
// use the already known state of the underlying image to save time.
//
//===========================================================================
bool FImageTexture::DetermineTranslucency()
{
if (mImage->bTranslucent != -1)
{
bTranslucent = mImage->bTranslucent;
return !!bTranslucent;
}
else
{
return FTexture::DetermineTranslucency();
}
}
FTexture* CreateImageTexture(FImageSource* img, const char *name) noexcept
{

View file

@ -718,10 +718,8 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
//
//===========================================================================
bool FTexture::GetTranslucency()
bool FTexture::DetermineTranslucency()
{
if (bTranslucent == -1)
{
if (!bHasCanvas)
{
// This will calculate all we need, so just discard the result.
@ -731,7 +729,6 @@ bool FTexture::GetTranslucency()
{
bTranslucent = 0;
}
}
return !!bTranslucent;
}

View file

@ -423,7 +423,11 @@ protected:
public:
FTextureBuffer CreateTexBuffer(int translation, int flags = 0);
virtual bool GetTranslucency();
virtual bool DetermineTranslucency();
bool GetTranslucency()
{
return bTranslucent != -1 ? bTranslucent : DetermineTranslucency();
}
FMaterial* GetMaterial(int num)
{
return Material[num];
@ -515,6 +519,7 @@ public:
FImageSource* GetImage() const override { return mImage; }
FBitmap GetBgraBitmap(const PalEntry* p, int* trans) override;
bool DetermineTranslucency() override;
};

View file

@ -112,11 +112,6 @@ struct IntRect
};
extern int CleanWidth, CleanHeight, CleanXfac, CleanYfac;
extern int CleanWidth_1, CleanHeight_1, CleanXfac_1, CleanYfac_1;
extern int DisplayWidth, DisplayHeight;
void V_UpdateModeSize (int width, int height);
@ -386,6 +381,9 @@ struct FScriptPosition;
inline bool IsRatioWidescreen(int ratio) { return (ratio & 3) != 0; }
#include "v_draw.h"
class ScaleOverrider
{
int savedxfac, savedyfac, savedwidth, savedheight;
@ -421,6 +419,4 @@ public:
};
#include "v_draw.h"
#endif // __V_VIDEO_H__