- separation of software renderer from the rest of the code complete. All external access to the renderer is routed through the FRenderer interface class now, with two exceptions (2D texture drawing to a canvas and polymost testing code) that are handled by #defines.

SVN r3263 (trunk)
This commit is contained in:
Christoph Oelckers 2011-07-07 15:37:47 +00:00
parent 3e9ffc9ac9
commit 5bfcaab25c
37 changed files with 1677 additions and 1224 deletions

View File

@ -722,6 +722,8 @@ add_executable( zdoom WIN32
p_xlat.cpp
parsecontext.cpp
po_man.cpp
r_swrenderer.cpp
r_utility.cpp
r_3dfloors.cpp
r_bsp.cpp
r_draw.cpp

View File

@ -36,10 +36,10 @@
#include "r_data/r_translate.h"
#include "d_event.h"
#include "gi.h"
#include "r_bsp.h"
#include "p_setup.h"
#include "c_bind.h"
#include "farchive.h"
#include "r_renderer.h"
#include "m_cheat.h"
#include "i_system.h"
@ -1634,8 +1634,7 @@ void AM_drawSubsectors()
points[j].Y = f_y + (f_h - (pt.y - m_y) * scale / float(1 << 24));
}
// For lighting and texture determination
sector_t *sec = R_FakeFlat (subsectors[i].render_sector, &tempsec, &floorlight,
&ceilinglight, false);
sector_t *sec = Renderer->FakeFlat (subsectors[i].render_sector, &tempsec, &floorlight, &ceilinglight, false);
// Find texture origin.
mpoint_t originpt = { -sec->GetXOffset(sector_t::floor) >> FRACTOMAPBITS,
sec->GetYOffset(sector_t::floor) >> FRACTOMAPBITS };

View File

@ -73,7 +73,7 @@
#include "st_stuff.h"
#include "am_map.h"
#include "p_setup.h"
#include "r_local.h"
#include "r_utility.h"
#include "r_sky.h"
#include "d_main.h"
#include "d_dehacked.h"
@ -87,7 +87,6 @@
#include "gameconfigfile.h"
#include "sbar.h"
#include "decallib.h"
#include "r_polymost.h"
#include "version.h"
#include "v_text.h"
#include "st_start.h"
@ -106,7 +105,11 @@
#include "sc_man.h"
#include "po_man.h"
#include "resourcefiles/resourcefile.h"
#include "r_3dfloors.h"
#include "r_renderer.h"
#ifdef USE_POLYMOST
#include "r_polymost.h"
#endif
EXTERN_CVAR(Bool, hud_althud)
void DrawHUD();
@ -184,6 +187,9 @@ CUSTOM_CVAR (Int, fraglimit, 0, CVAR_SERVERINFO)
}
}
#ifdef USE_POLYMOST
CVAR(Bool, testpolymost, false, 0)
#endif
CVAR (Float, timelimit, 0.f, CVAR_SERVERINFO);
CVAR (Int, wipetype, 1, CVAR_ARCHIVE);
CVAR (Int, snd_drawoutput, 0, 0);
@ -276,8 +282,10 @@ void D_ProcessEvents (void)
continue; // console ate the event
if (M_Responder (ev))
continue; // menu ate the event
if (testpolymost)
Polymost_Responder (ev);
#ifdef USE_POLYMOST
if (testpolymost)
Polymost_Responder (ev);
#endif
G_Responder (ev);
}
}
@ -298,8 +306,11 @@ void D_PostEvent (const event_t *ev)
return;
}
events[eventhead] = *ev;
if (ev->type == EV_Mouse && !testpolymost && !paused && menuactive == MENU_Off &&
ConsoleState != c_down && ConsoleState != c_falling)
if (ev->type == EV_Mouse && !paused && menuactive == MENU_Off && ConsoleState != c_down && ConsoleState != c_falling
#ifdef USE_POLYMOST
&& !testpolymost
#endif
)
{
if (Button_Mlook.bDown || freelook)
{
@ -710,6 +721,7 @@ void D_Display ()
hw2d = false;
#ifdef USE_POLYMOST
if (testpolymost)
{
drawpolymosttest();
@ -717,6 +729,7 @@ void D_Display ()
M_Drawer();
}
else
#endif
{
unsigned int nowtime = I_FPSTime();
TexMan.UpdateAnimations(nowtime);
@ -744,14 +757,14 @@ void D_Display ()
screen->SetBlendingRect(viewwindowx, viewwindowy,
viewwindowx + viewwidth, viewwindowy + viewheight);
P_CheckPlayerSprites();
screen->RenderView(&players[consoleplayer]);
Renderer->RenderView(&players[consoleplayer]);
if ((hw2d = screen->Begin2D(viewactive)))
{
// Redraw everything every frame when using 2D accel
SB_state = screen->GetPageCount();
BorderNeedRefresh = screen->GetPageCount();
}
screen->DrawRemainingPlayerSprites();
Renderer->DrawRemainingPlayerSprites();
screen->DrawBlendingRect();
if (automapactive)
{
@ -915,15 +928,7 @@ void D_ErrorCleanup ()
menuactive = MENU_Off;
}
insave = false;
fakeActive = 0;
fake3D = 0;
while (CurrentSkybox)
{
R_3D_DeleteHeights();
R_3D_LeaveSkybox();
}
R_3D_ResetClip();
R_3D_DeleteHeights();
Renderer->ErrorCleanup();
}
//==========================================================================
@ -2109,6 +2114,7 @@ void D_DoomMain (void)
{
Printf ("I_Init: Setting up machine state.\n");
I_Init ();
I_CreateRenderer();
}
Printf ("V_Init: allocate screen.\n");

View File

@ -314,6 +314,9 @@ namespace GC
// is NULLed instead.
void Mark(DObject **obj);
// For cleanup
void DelSoftRootHead();
// Soft-roots an object.
void AddSoftRoot(DObject *obj);

View File

@ -529,6 +529,12 @@ void Barrier(DObject *pointing, DObject *pointed)
}
}
void DelSoftRootHead()
{
if (SoftRoots != NULL) delete SoftRoots;
SoftRoots = NULL;
}
//==========================================================================
//
// AddSoftRoot

View File

@ -78,6 +78,7 @@
#include "p_acs.h"
#include "m_joy.h"
#include "farchive.h"
#include "r_renderer.h"
#include "r_data/colormaps.h"
#include <zlib.h>
@ -2034,7 +2035,7 @@ static void PutSavePic (FILE *file, int width, int height)
else
{
P_CheckPlayerSprites();
screen->WriteSavePic(&players[consoleplayer], file, width, height);
Renderer->WriteSavePic(&players[consoleplayer], file, width, height);
}
}

View File

@ -80,6 +80,7 @@
#include "a_strifeglobal.h"
#include "r_data/colormaps.h"
#include "farchive.h"
#include "r_renderer.h"
#include "gi.h"
@ -1349,7 +1350,7 @@ void G_SerializeLevel (FArchive &arc, bool hubLoad)
{
int i = level.totaltime;
screen->StartSerialize(arc);
Renderer->StartSerialize(arc);
arc << level.flags
<< level.flags2
@ -1468,7 +1469,7 @@ void G_SerializeLevel (FArchive &arc, bool hubLoad)
}
}
}
screen->EndSerialize(arc);
Renderer->EndSerialize(arc);
}
//==========================================================================

View File

@ -63,6 +63,7 @@
#include "gstrings.h"
#include "farchive.h"
#include "r_data/colormaps.h"
#include "r_renderer.h"
// MACROS ------------------------------------------------------------------
@ -523,7 +524,7 @@ bool AActor::SetState (FState *newstate, bool nofunction)
if (screen != NULL)
{
screen->StateChanged(this);
Renderer->StateChanged(this);
}
return true;
}
@ -3607,7 +3608,7 @@ AActor *AActor::StaticSpawn (const PClass *type, fixed_t ix, fixed_t iy, fixed_t
}
if (screen != NULL)
{
screen->StateChanged(actor);
Renderer->StateChanged(actor);
}
return actor;
}

View File

@ -53,6 +53,7 @@
#include "d_net.h"
#include "gstrings.h"
#include "farchive.h"
#include "r_renderer.h"
static FRandom pr_skullpop ("SkullPop");
@ -2196,11 +2197,11 @@ void P_PlayerThink (player_t *player)
player->mo->pitch -= look;
if (look > 0)
{ // look up
player->mo->pitch = MAX(player->mo->pitch, screen->GetMaxViewPitch(false));
player->mo->pitch = MAX(player->mo->pitch, Renderer->GetMaxViewPitch(false));
}
else
{ // look down
player->mo->pitch = MIN(player->mo->pitch, screen->GetMaxViewPitch(true));
player->mo->pitch = MIN(player->mo->pitch, Renderer->GetMaxViewPitch(true));
}
}
}

View File

@ -52,6 +52,7 @@
#include "v_video.h"
#include "templates.h"
#include "r_utility.h"
#include "r_renderer.h"
static bool R_CheckForFixedLights(const BYTE *colormaps);
@ -205,7 +206,7 @@ FDynamicColormap *GetSpecialLights (PalEntry color, PalEntry fade, int desaturat
colormap->Desaturate = desaturate;
NormalLight.Next = colormap;
if (screen->UsesColormap())
if (Renderer->UsesColormap())
{
colormap->Maps = new BYTE[NUMCOLORMAPS*256];
colormap->BuildLights ();
@ -365,7 +366,7 @@ void FDynamicColormap::ChangeColorFade (PalEntry lightcolor, PalEntry fadecolor)
void FDynamicColormap::RebuildAllLights()
{
if (screen->UsesColormap())
if (Renderer->UsesColormap())
{
FDynamicColormap *cm;

View File

@ -6,7 +6,7 @@ void R_DeinitColormaps ();
DWORD R_ColormapNumForName(const char *name); // killough 4/4/98
void R_SetDefaultColormap (const char *name); // [RH] change normal fadetable
DWORD R_BlendForColormap (DWORD map); // [RH] return calculated blend for a colormap
DWORD R_BlendForColormap (DWORD map); // [RH] return calculated blend for a colormap
extern BYTE *realcolormaps; // [RH] make the colormaps externally visible
extern size_t numfakecmaps;

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,6 @@ typedef BYTE lighttable_t; // This could be wider for >8 bit display.
//
// POV related.
//
extern DCanvas *RenderTarget;
extern bool bRenderingToCanvas;
extern fixed_t viewcos;
extern fixed_t viewsin;
@ -106,7 +105,7 @@ extern float r_TiltVisibility;
extern fixed_t r_SpriteVisibility;
extern fixed_t r_SkyVisibility;
extern int extralight, r_actualextralight;
extern int r_actualextralight;
extern bool foggy;
extern int fixedlightlev;
extern lighttable_t* fixedcolormap;
@ -131,8 +130,6 @@ extern void (*hcolfunc_post2) (int hx, int sx, int yl, int yh);
extern void (STACK_ARGS *hcolfunc_post4) (int sx, int yl, int yh);
void R_SetFOV (float fov);
float R_GetFOV ();
void R_InitTextureMapping ();
void R_SetViewAngle ();
@ -147,14 +144,6 @@ void R_SetupBuffer ();
void R_RenderViewToCanvas (AActor *actor, DCanvas *canvas, int x, int y, int width, int height, bool dontmaplines = false);
// Called by startup code.
void R_Init (void);
void R_ExecuteSetViewSize (void);
// Called by M_Responder.
void R_SetViewSize (int blocks);
// [RH] Initialize multires stuff for renderer
void R_MultiresInit (void);

View File

@ -529,7 +529,6 @@ int PolyClipper::DoMost (float x0, float y0, float x1, float y1, pmostcallbackty
}
#include "d_event.h"
CVAR(Bool, testpolymost, false, 0)
static int pmx, pmy;
static int pt, px0, py0, px1, py1;
static struct polypt { float x, y; } polypts[80];

View File

@ -51,7 +51,5 @@ private:
};
EXTERN_CVAR(Bool, testpolymost)
extern void drawpolymosttest();
struct event_t; void Polymost_Responder (event_t *ev);

68
src/r_renderer.h Normal file
View File

@ -0,0 +1,68 @@
#ifndef __R_RENDERER_H
#define __R_RENDERER_H
#include <stdio.h>
struct FRenderer;
extern FRenderer *Renderer;
class FArchive;
class FTexture;
class AActor;
class player_t;
struct sector_t;
class FCanvasTexture;
struct FRenderer
{
FRenderer()
{
Renderer = this;
}
~FRenderer()
{
Renderer = NULL;
}
// Can be overridden so that the colormaps for sector color/fade won't be built.
virtual bool UsesColormap() const = 0;
// precache one texture
virtual void PrecacheTexture(FTexture *tex, int cache) = 0;
// render 3D view
virtual void RenderView(player_t *player) = 0;
// Remap voxel palette
virtual void RemapVoxels() {}
// renders view to a savegame picture
virtual void WriteSavePic (player_t *player, FILE *file, int width, int height) = 0;
// draws player sprites with hardware acceleration (only useful for software rendering)
virtual void DrawRemainingPlayerSprites() {}
// notifies the renderer that an actor has changed state.
virtual void StateChanged(AActor *actor) {}
// notify the renderer that serialization of the curent level is about to start/end
virtual void StartSerialize(FArchive &arc) {}
virtual void EndSerialize(FArchive &arc) {}
virtual int GetMaxViewPitch(bool down) = 0;
virtual void OnModeSet () {}
virtual void ErrorCleanup () {}
virtual void ClearBuffer(int color) = 0;
virtual void Init() = 0;
virtual void SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, int trueratio) {}
virtual void SetupFrame(player_t *player) {}
virtual void CopyStackedViewParameters() {}
virtual void RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov) = 0;
virtual sector_t *FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel, bool back) = 0;
};
#endif

View File

@ -54,7 +54,7 @@ CUSTOM_CVAR (Bool, r_stretchsky, true, CVAR_ARCHIVE)
R_InitSkyMap ();
}
extern fixed_t freelookviewheight;
fixed_t freelookviewheight;
//==========================================================================
//

View File

@ -33,6 +33,7 @@ extern fixed_t skytexturemid;
extern fixed_t skyiscale;
extern fixed_t skyscale;
extern bool skystretch;
extern fixed_t freelookviewheight;
#define SKYSTRETCH_HEIGHT 228

298
src/r_swrenderer.cpp Normal file
View File

@ -0,0 +1,298 @@
/*
** r_swrender.cpp
** Software renderer interface
**
**---------------------------------------------------------------------------
** Copyright 2011 Christoph Oelckers
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
*/
#include "r_local.h"
#include "v_palette.h"
#include "v_video.h"
#include "m_png.h"
#include "r_bsp.h"
#include "r_swrenderer.h"
#include "r_3dfloors.h"
#include "r_polymost.h"
#include "textures/textures.h"
#include "r_data/voxels.h"
class FArchive;
void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, int trueratio);
void R_SetupColormap(player_t *);
void R_SetupFreelook();
void R_SetupPolymost();
void R_InitRenderer();
extern float LastFOV;
//==========================================================================
//
// DCanvas :: Init
//
//==========================================================================
void FSoftwareRenderer::Init()
{
R_InitRenderer();
}
//==========================================================================
//
// DCanvas :: UsesColormap
//
//==========================================================================
bool FSoftwareRenderer::UsesColormap() const
{
return true;
}
//===========================================================================
//
// Texture precaching
//
//===========================================================================
void FSoftwareRenderer::PrecacheTexture(FTexture *tex, int cache)
{
if (tex != NULL)
{
if (cache & 1)
{
const FTexture::Span *spanp;
tex->GetColumn(0, &spanp);
}
else if (cache != 0)
{
tex->GetPixels ();
}
else
{
tex->Unload ();
}
}
}
//===========================================================================
//
// Render the view
//
//===========================================================================
void FSoftwareRenderer::RenderView(player_t *player)
{
R_RenderActorView (player->mo);
// [RH] Let cameras draw onto textures that were visible this frame.
FCanvasTextureInfo::UpdateAll ();
}
//==========================================================================
//
//
//
//==========================================================================
void FSoftwareRenderer::RemapVoxels()
{
for (unsigned i=0; i<Voxels.Size(); i++)
{
Voxels[i]->Remap();
}
}
//===========================================================================
//
// Render the view to a savegame picture
//
//===========================================================================
void FSoftwareRenderer::WriteSavePic (player_t *player, FILE *file, int width, int height)
{
DCanvas *pic = new DSimpleCanvas (width, height);
PalEntry palette[256];
// Take a snapshot of the player's view
pic->ObjectFlags |= OF_Fixed;
pic->Lock ();
R_RenderViewToCanvas (player->mo, pic, 0, 0, width, height);
screen->GetFlashedPalette (palette);
M_CreatePNG (file, pic->GetBuffer(), palette, SS_PAL, width, height, pic->GetPitch());
pic->Unlock ();
pic->Destroy();
pic->ObjectFlags |= OF_YesReallyDelete;
delete pic;
}
//===========================================================================
//
//
//
//===========================================================================
void FSoftwareRenderer::DrawRemainingPlayerSprites()
{
R_DrawRemainingPlayerSprites();
}
//===========================================================================
//
// Get max. view angle (renderer specific information so it goes here now)
//
//===========================================================================
#define MAX_DN_ANGLE 56 // Max looking down angle
#define MAX_UP_ANGLE 32 // Max looking up angle
int FSoftwareRenderer::GetMaxViewPitch(bool down)
{
return down? MAX_DN_ANGLE*ANGLE_1 : -MAX_UP_ANGLE*ANGLE_1;
}
//==========================================================================
//
// OnModeSet
//
// Called from V_SetResolution()
//
//==========================================================================
void FSoftwareRenderer::OnModeSet ()
{
R_MultiresInit ();
RenderTarget = screen;
screen->Lock (true);
R_SetupBuffer ();
screen->Unlock ();
}
//===========================================================================
//
//
//
//===========================================================================
void FSoftwareRenderer::ErrorCleanup ()
{
fakeActive = 0;
fake3D = 0;
while (CurrentSkybox)
{
R_3D_DeleteHeights();
R_3D_LeaveSkybox();
}
R_3D_ResetClip();
R_3D_DeleteHeights();
}
//===========================================================================
//
//
//
//===========================================================================
void FSoftwareRenderer::ClearBuffer(int color)
{
memset(RenderTarget->GetBuffer(), color, RenderTarget->GetPitch() * RenderTarget->GetHeight());
}
//===========================================================================
//
//
//
//===========================================================================
void FSoftwareRenderer::SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, int trueratio)
{
R_SWRSetWindow(windowSize, fullWidth, fullHeight, stHeight, trueratio);
}
//===========================================================================
//
//
//
//===========================================================================
void FSoftwareRenderer::SetupFrame(player_t *player)
{
R_SetupColormap(player);
R_SetupFreelook();
R_SetupPolymost();
}
//==========================================================================
//
// R_CopyStackedViewParameters
//
//==========================================================================
void FSoftwareRenderer::CopyStackedViewParameters()
{
R_CopyStackedViewParameters();
}
//==========================================================================
//
//
//
//==========================================================================
void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov)
{
BYTE *Pixels = const_cast<BYTE*>(tex->GetPixels());
DSimpleCanvas *Canvas = tex->GetCanvas();
float savedfov = LastFOV;
R_SetFOV ((float)fov);
R_RenderViewToCanvas (viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate);
R_SetFOV (savedfov);
if (Pixels == Canvas->GetBuffer())
{
FTexture::FlipSquareBlockRemap (Pixels, tex->GetWidth(), tex->GetHeight(), GPalette.Remap);
}
else
{
FTexture::FlipNonSquareBlockRemap (Pixels, Canvas->GetBuffer(), tex->GetWidth(), tex->GetHeight(), Canvas->GetPitch(), GPalette.Remap);
}
tex->SetUpdated();
}
//==========================================================================
//
//
//
//==========================================================================
sector_t *FSoftwareRenderer::FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel, bool back)
{
return R_FakeFlat(sec, tempsec, floorlightlevel, ceilinglightlevel, back);
}

41
src/r_swrenderer.h Normal file
View File

@ -0,0 +1,41 @@
#ifndef __R_SWRENDERER_H
#define __R_SWRENDERER_H
#include "r_renderer.h"
struct FSoftwareRenderer : public FRenderer
{
// Can be overridden so that the colormaps for sector color/fade won't be built.
virtual bool UsesColormap() const;
// precache one texture
virtual void PrecacheTexture(FTexture *tex, int cache);
// render 3D view
virtual void RenderView(player_t *player);
// Remap voxel palette
virtual void RemapVoxels();
// renders view to a savegame picture
virtual void WriteSavePic (player_t *player, FILE *file, int width, int height);
// draws player sprites with hardware acceleration (only useful for software rendering)
virtual void DrawRemainingPlayerSprites();
virtual int GetMaxViewPitch(bool down);
void OnModeSet ();
void ErrorCleanup ();
void ClearBuffer(int color);
void Init();
void SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, int trueratio);
void SetupFrame(player_t *player);
void CopyStackedViewParameters();
void RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov);
sector_t *FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel, bool back);
};
#endif

1050
src/r_utility.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -9,8 +9,14 @@
// There a 0-31, i.e. 32 LUT in the COLORMAP lump.
#define NUMCOLORMAPS 32
extern DCanvas *RenderTarget;
extern fixed_t viewx;
extern fixed_t viewy;
extern fixed_t viewz;
extern int viewpitch;
extern int setblocks;
extern fixed_t viewtancos;
extern fixed_t viewtansin;
@ -26,6 +32,9 @@ extern int WidescreenRatio;
extern fixed_t r_TicFrac;
extern DWORD r_FrameTime;
extern int extralight;
extern unsigned int R_OldBlend;
//==========================================================================
//
@ -49,6 +58,18 @@ subsector_t *R_PointInSubsector (fixed_t x, fixed_t y);
fixed_t R_PointToDist2 (fixed_t dx, fixed_t dy);
void R_ResetViewInterpolation ();
void R_SetViewSize (int blocks);
void R_SetFOV (float fov);
float R_GetFOV ();
void R_SetupFrame (AActor * camera);
// Called by startup code.
void R_Init (void);
void R_ExecuteSetViewSize (void);
// Called by M_Responder.
void R_SetViewSize (int blocks);
void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight);
extern void R_FreePastViewers ();
extern void R_ClearPastViewer (AActor *actor);

View File

@ -80,6 +80,21 @@ void I_InitGraphics ()
Video->SetWindowedScale (vid_winscale);
}
static void I_DeleteRenderer()
{
if (Renderer != NULL) delete Renderer;
}
void I_CreateRenderer()
{
if (Renderer == NULL)
{
Renderer = new FSoftwareRenderer;
atterm(I_DeleteRenderer);
}
}
/** Remaining code is common to Win32 and Linux **/
// VIDEO WRAPPERS ---------------------------------------------------------

View File

@ -57,6 +57,7 @@ class IVideo
void I_InitGraphics ();
void I_ShutdownGraphics ();
void I_CreateRenderer();
extern IVideo *Video;

View File

@ -11,6 +11,7 @@
#include "stats.h"
#include "v_palette.h"
#include "sdlvideo.h"
#include "r_swrenderer.h"
#include <SDL.h>
@ -147,6 +148,7 @@ static MiniModeInfo WinModes[] =
{ 1600, 900 }, // 16:9
{ 1600, 1000 }, // 16:10
{ 1600, 1200 },
{ 1920, 1080 },
};
static cycle_t BlitCycles;

View File

@ -35,13 +35,10 @@
#include "doomtype.h"
#include "files.h"
#include "r_local.h"
#include "v_palette.h"
#include "v_video.h"
#include "textures/textures.h"
extern float LastFOV;
FCanvasTexture::FCanvasTexture (const char *name, int width, int height)
{
strncpy (Name, name, 8);
@ -62,6 +59,7 @@ FCanvasTexture::FCanvasTexture (const char *name, int width, int height)
bDidUpdate = false;
bHasCanvas = true;
bFirstUpdate = true;
bPixelsAllocated = false;
}
FCanvasTexture::~FCanvasTexture ()
@ -112,10 +110,12 @@ void FCanvasTexture::MakeTexture ()
if (Width != Height || Width != Canvas->GetPitch())
{
Pixels = new BYTE[Width*Height];
bPixelsAllocated = true;
}
else
{
Pixels = Canvas->GetBuffer();
bPixelsAllocated = false;
}
// Draw a special "unrendered" initial texture into the buffer.
memset (Pixels, 0, Width*Height/2);
@ -124,13 +124,15 @@ void FCanvasTexture::MakeTexture ()
void FCanvasTexture::Unload ()
{
if (bPixelsAllocated)
{
if (Pixels != NULL) delete [] Pixels;
bPixelsAllocated = false;
Pixels = NULL;
}
if (Canvas != NULL)
{
if (Pixels != NULL && Pixels != Canvas->GetBuffer())
{
delete[] Pixels;
}
Pixels = NULL;
GC::DelSoftRoot(Canvas);
Canvas->Destroy();
Canvas = NULL;
@ -147,26 +149,3 @@ bool FCanvasTexture::CheckModified ()
return false;
}
void FCanvasTexture::RenderView (AActor *viewpoint, int fov)
{
if (Canvas == NULL)
{
MakeTexture ();
}
float savedfov = LastFOV;
R_SetFOV ((float)fov);
R_RenderViewToCanvas (viewpoint, Canvas, 0, 0, Width, Height, bFirstUpdate);
R_SetFOV (savedfov);
if (Pixels == Canvas->GetBuffer())
{
FlipSquareBlockRemap (Pixels, Width, Height, GPalette.Remap);
}
else
{
FlipNonSquareBlockRemap (Pixels, Canvas->GetBuffer(), Width, Height, Canvas->GetPitch(), GPalette.Remap);
}
bNeedsUpdate = false;
bDidUpdate = true;
bFirstUpdate = false;
}

View File

@ -50,6 +50,7 @@
#include "m_fixed.h"
#include "farchive.h"
#include "v_video.h"
#include "r_renderer.h"
#include "textures/textures.h"
FTextureManager TexMan;
@ -1169,7 +1170,7 @@ void FTextureManager::PrecacheLevel (void)
screen->GetHitlist(hitlist);
for (int i = cnt - 1; i >= 0; i--)
{
screen->PrecacheTexture(ByIndex(i), hitlist[i]);
Renderer->PrecacheTexture(ByIndex(i), hitlist[i]);
}
delete[] hitlist;

View File

@ -295,6 +295,7 @@ protected:
Rotations = other->Rotations;
}
public:
static void FlipSquareBlock (BYTE *block, int x, int y);
static void FlipSquareBlockRemap (BYTE *block, int x, int y, const BYTE *remap);
static void FlipNonSquareBlock (BYTE *blockto, const BYTE *blockfrom, int x, int y, int srcpitch);
@ -522,18 +523,21 @@ public:
const BYTE *GetPixels ();
void Unload ();
bool CheckModified ();
void RenderView (AActor *viewpoint, int fov);
void NeedUpdate() { bNeedsUpdate=true; }
void SetUpdated() { bNeedsUpdate = false; bDidUpdate = true; bFirstUpdate = false; }
DSimpleCanvas *GetCanvas() { return Canvas; }
void MakeTexture ();
protected:
DSimpleCanvas *Canvas;
BYTE *Pixels;
Span DummySpans[2];
BYTE bNeedsUpdate:1;
BYTE bDidUpdate:1;
BYTE bFirstUpdate:1;
bool bNeedsUpdate;
bool bDidUpdate;
bool bPixelsAllocated;
public:
bool bFirstUpdate;
void MakeTexture ();
friend struct FCanvasTextureInfo;
};

View File

@ -32,6 +32,8 @@
**
*/
// #define NO_SWRENDER // set this if you want to exclude the software renderer. Without software renderer the base implementations of DrawTextureV and FillSimplePoly need to be disabled because they depend on it.
#include <stdio.h>
#include <stdarg.h>
@ -39,9 +41,11 @@
#include "v_video.h"
#include "m_swap.h"
#include "r_defs.h"
#ifndef NO_SWRENDER
#include "r_draw.h"
#include "r_main.h"
#include "r_things.h"
#endif
#include "r_data/r_translate.h"
#include "doomstat.h"
#include "v_palette.h"
@ -68,7 +72,6 @@ int CleanXfac_1, CleanYfac_1, CleanWidth_1, CleanHeight_1;
// FillSimplePoly uses this
extern "C" short spanend[MAXHEIGHT];
extern int setblocks;
CVAR (Bool, hud_scale, false, CVAR_ARCHIVE);
@ -110,6 +113,7 @@ void STACK_ARGS DCanvas::DrawTexture (FTexture *img, double x, double y, int tag
void STACK_ARGS DCanvas::DrawTextureV(FTexture *img, double x, double y, uint32 tag, va_list tags)
{
#ifndef NO_SWRENDER
FTexture::Span unmaskedSpan[2];
const FTexture::Span **spanptr, *spans;
static short bottomclipper[MAXWIDTH], topclipper[MAXWIDTH];
@ -318,6 +322,7 @@ void STACK_ARGS DCanvas::DrawTextureV(FTexture *img, double x, double y, uint32
{
NetUpdate();
}
#endif
}
bool DCanvas::ParseDrawTextureTags (FTexture *img, double x, double y, DWORD tag, va_list tags, DrawParms *parms, bool hw) const
@ -1119,6 +1124,7 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints,
double originx, double originy, double scalex, double scaley, angle_t rotation,
FDynamicColormap *colormap, int lightlevel)
{
#ifndef NO_SWRENDER
// Use an equation similar to player sprites to determine shade
fixed_t shade = LIGHT2SHADE(lightlevel) - 12*FRACUNIT;
float topy, boty, leftx, rightx;
@ -1263,6 +1269,7 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints,
pt1 = pt2;
pt2--; if (pt2 < 0) pt2 = npoints;
} while (pt1 != botpt);
#endif
}

View File

@ -28,7 +28,6 @@
#include "i_system.h"
#include "x86.h"
#include "i_video.h"
#include "r_local.h"
#include "r_state.h"
#include "doomdef.h"
@ -61,10 +60,14 @@
#include "colormatcher.h"
#include "v_palette.h"
#include "r_sky.h"
#include "r_utility.h"
#include "r_renderer.h"
#include "menu/menu.h"
#include "r_data/voxels.h"
FRenderer *Renderer;
IMPLEMENT_ABSTRACT_CLASS (DCanvas)
IMPLEMENT_ABSTRACT_CLASS (DFrameBuffer)
@ -373,17 +376,6 @@ void DCanvas::Dim (PalEntry color, float damount, int x1, int y1, int w, int h)
}
}
//==========================================================================
//
// DCanvas :: UsesColormap
//
//==========================================================================
bool DCanvas::UsesColormap() const
{
return true;
}
//==========================================================================
//
// DCanvas :: GetScreenshotBuffer
@ -1274,130 +1266,6 @@ void DFrameBuffer::GetHitlist(BYTE *hitlist)
}
}
//===========================================================================
//
// Texture precaching
//
//===========================================================================
void DFrameBuffer::PrecacheTexture(FTexture *tex, int cache)
{
if (tex != NULL)
{
if (cache & 1)
{
const FTexture::Span *spanp;
tex->GetColumn(0, &spanp);
}
else if (cache != 0)
{
tex->GetPixels ();
}
else
{
tex->Unload ();
}
}
}
//===========================================================================
//
// Render the view
//
//===========================================================================
void DFrameBuffer::RenderView(player_t *player)
{
R_RenderActorView (player->mo);
// [RH] Let cameras draw onto textures that were visible this frame.
FCanvasTextureInfo::UpdateAll ();
}
//==========================================================================
//
//
//
//==========================================================================
void DFrameBuffer::RemapVoxels()
{
for (unsigned i=0; i<Voxels.Size(); i++)
{
Voxels[i]->Remap();
}
}
//===========================================================================
//
// Render the view to a savegame picture
//
//===========================================================================
void DFrameBuffer::WriteSavePic (player_t *player, FILE *file, int width, int height)
{
DCanvas *pic = new DSimpleCanvas (width, height);
PalEntry palette[256];
// Take a snapshot of the player's view
pic->ObjectFlags |= OF_Fixed;
pic->Lock ();
R_RenderViewToCanvas (player->mo, pic, 0, 0, width, height);
GetFlashedPalette (palette);
M_CreatePNG (file, pic->GetBuffer(), palette, SS_PAL, width, height, pic->GetPitch());
pic->Unlock ();
pic->Destroy();
pic->ObjectFlags |= OF_YesReallyDelete;
delete pic;
}
//===========================================================================
//
//
//
//===========================================================================
void DFrameBuffer::DrawRemainingPlayerSprites()
{
R_DrawRemainingPlayerSprites();
}
//===========================================================================
//
// notify the renderer that an actor has changed state
//
//===========================================================================
void DFrameBuffer::StateChanged(AActor *actor)
{
}
//===========================================================================
//
// notify the renderer that serialization of the curent level is about to start/end
//
//===========================================================================
void DFrameBuffer::StartSerialize(FArchive &arc)
{
}
void DFrameBuffer::EndSerialize(FArchive &arc)
{
}
//===========================================================================
//
// Get max. view angle (renderer specific information so it goes here now)
//
//===========================================================================
#define MAX_DN_ANGLE 56 // Max looking down angle
#define MAX_UP_ANGLE 32 // Max looking up angle
int DFrameBuffer::GetMaxViewPitch(bool down)
{
return down? MAX_DN_ANGLE*ANGLE_1 : -MAX_UP_ANGLE*ANGLE_1;
}
//==========================================================================
//
// DFrameBuffer :: GameRestart
@ -1532,12 +1400,8 @@ bool V_DoModeSetup (int width, int height, int bits)
DisplayHeight = height;
DisplayBits = bits;
R_MultiresInit ();
RenderTarget = screen;
screen->Lock (true);
R_SetupBuffer ();
screen->Unlock ();
R_OldBlend = ~0;
Renderer->OnModeSet();
M_RefreshModesList ();
@ -1703,7 +1567,7 @@ void V_Init2()
Printf ("Resolution: %d x %d\n", SCREENWIDTH, SCREENHEIGHT);
screen->SetGamma (gamma);
screen->RemapVoxels();
Renderer->RemapVoxels();
FBaseCVar::ResetColors ();
C_NewModeAdjust();
M_InitVideoModesMenu();

View File

@ -193,8 +193,6 @@ public:
// Calculate gamma table
void CalcGamma (float gamma, BYTE gammalookup[256]);
// Can be overridden so that the colormaps for sector color/fade won't be built.
virtual bool UsesColormap() const;
// Retrieves a buffer containing image data for a screenshot.
// Hint: Pitch can be negative for upside-down images, in which case buffer
@ -364,27 +362,6 @@ public:
// Set the rect defining the area affected by blending.
virtual void SetBlendingRect (int x1, int y1, int x2, int y2);
// Remap voxel palette
virtual void RemapVoxels();
// render 3D view
virtual void RenderView(player_t *player);
// renders view to a savegame picture
virtual void WriteSavePic (player_t *player, FILE *file, int width, int height);
// draws player sprites with hardware acceleration (only useful for software rendering)
virtual void DrawRemainingPlayerSprites();
// notifies the renderer that an actor has changed state.
virtual void StateChanged(AActor *actor);
// notify the renderer that serialization of the curent level is about to start/end
virtual void StartSerialize(FArchive &arc);
virtual void EndSerialize(FArchive &arc);
virtual int GetMaxViewPitch(bool down);
bool Accel2D; // If true, 2D drawing can be accelerated.
// Begin 2D drawing operations. This is like Update, but it doesn't end
@ -408,7 +385,6 @@ public:
// Precaches or unloads a texture
virtual void GetHitlist(BYTE *hitlist);
virtual void PrecacheTexture(FTexture *tex, int cache);
// Report a game restart
virtual void GameRestart();

View File

@ -46,6 +46,8 @@
#include "v_text.h"
#include "doomstat.h"
#include "m_argv.h"
#include "version.h"
#include "r_swrenderer.h"
EXTERN_CVAR (Bool, ticker)
EXTERN_CVAR (Bool, fullscreen)
@ -104,6 +106,20 @@ void I_InitGraphics ()
Video->SetWindowedScale (vid_winscale);
}
static void I_DeleteRenderer()
{
if (Renderer != NULL) delete Renderer;
}
void I_CreateRenderer()
{
if (Renderer == NULL)
{
Renderer = new FSoftwareRenderer;
atterm(I_DeleteRenderer);
}
}
/** Remaining code is common to Win32 and Linux **/
// VIDEO WRAPPERS ---------------------------------------------------------

View File

@ -57,6 +57,7 @@ class IVideo
void I_InitGraphics ();
void I_ShutdownGraphics ();
void I_CreateRenderer();
void I_SaveWindowedPos ();
void I_RestoreWindowedPos ();

View File

@ -263,6 +263,7 @@ static void FinalGC()
{
Args = NULL;
GC::FullGC();
GC::DelSoftRootHead(); // the soft root head will not be collected by a GC so we have to do it explicitly
}
//==========================================================================
@ -1300,7 +1301,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE nothing, LPSTR cmdline, int n
_CrtSetDbgFlag (_CrtSetDbgFlag(0) | _CRTDBG_LEAK_CHECK_DF);
// Use this to break at a specific allocation number.
//_crtBreakAlloc = 30055;
//_crtBreakAlloc = 77624;
#endif
DoMain (hInstance);

View File

@ -54,6 +54,7 @@ EXTERN_CVAR (Bool, vid_vsync)
class D3DTex;
class D3DPal;
struct FSoftwareRenderer;
class Win32Video : public IVideo
{

View File

@ -68,6 +68,7 @@
#include "m_argv.h"
#include "r_defs.h"
#include "v_text.h"
#include "r_swrenderer.h"
#include "win32iface.h"
@ -709,7 +710,6 @@ DFrameBuffer *Win32Video::CreateFrameBuffer (int width, int height, bool fullscr
retry = 0;
fb->SetFlash (flashColor, flashAmount);
return fb;
}

View File

@ -2344,7 +2344,7 @@
>
</File>
<File
RelativePath=".\src\r_sky.cpp"
RelativePath=".\src\r_swrenderer.cpp"
>
</File>
<File
@ -2363,10 +2363,6 @@
RelativePath=".\src\r_bsp.h"
>
</File>
<File
RelativePath=".\src\r_defs.h"
>
</File>
<File
RelativePath=".\src\r_draw.h"
>
@ -2392,21 +2388,13 @@
>
</File>
<File
RelativePath=".\src\r_sky.h"
>
</File>
<File
RelativePath=".\src\r_state.h"
RelativePath=".\src\r_swrenderer.h"
>
</File>
<File
RelativePath=".\src\r_things.h"
>
</File>
<File
RelativePath=".\src\r_utility.h"
>
</File>
</Filter>
</Filter>
<Filter
@ -6662,6 +6650,38 @@
</File>
</Filter>
</Filter>
<Filter
Name="Render Interface"
>
<File
RelativePath=".\src\r_defs.h"
>
</File>
<File
RelativePath=".\src\r_renderer.h"
>
</File>
<File
RelativePath=".\src\r_sky.cpp"
>
</File>
<File
RelativePath=".\src\r_sky.h"
>
</File>
<File
RelativePath=".\src\r_state.h"
>
</File>
<File
RelativePath=".\src\r_utility.cpp"
>
</File>
<File
RelativePath=".\src\r_utility.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>