Merge remote-tracking branch 'gzdoom_upstream/master' into lightmath

This commit is contained in:
Magnus Norddahl 2016-09-12 22:30:46 +02:00
commit 0fc5ee1ffd
27 changed files with 382 additions and 217 deletions

View file

@ -281,6 +281,10 @@ if( NOT NO_FMOD )
if( FMOD_INCLUDE_DIR ) if( FMOD_INCLUDE_DIR )
message( STATUS "FMOD include files found at ${FMOD_INCLUDE_DIR}" ) message( STATUS "FMOD include files found at ${FMOD_INCLUDE_DIR}" )
include_directories( "${FMOD_INCLUDE_DIR}" ) include_directories( "${FMOD_INCLUDE_DIR}" )
if( EXISTS "${FMOD_INCLUDE_DIR}/fmod_common.h" )
set( FMOD_STUDIO YES )
endif()
else() else()
message( STATUS "Could not find FMOD include files" ) message( STATUS "Could not find FMOD include files" )
set( NO_FMOD ON ) set( NO_FMOD ON )
@ -1481,7 +1485,16 @@ endif()
if( MSVC ) if( MSVC )
option( ZDOOM_GENERATE_MAPFILE "Generate .map file for debugging." OFF ) option( ZDOOM_GENERATE_MAPFILE "Generate .map file for debugging." OFF )
set( LINKERSTUFF "/MANIFEST:NO /DELAYLOAD:\"fmodex${X64}.dll\"" ) set( LINKERSTUFF "/MANIFEST:NO" )
if( NOT NO_FMOD )
if( FMOD_STUDIO )
set( LINKERSTUFF "${LINKERSTUFF} /DELAYLOAD:\"fmod${X64}.dll\"" )
else()
set( LINKERSTUFF "${LINKERSTUFF} /DELAYLOAD:\"fmodex${X64}.dll\"" )
endif()
endif()
if( ZDOOM_GENERATE_MAPFILE ) if( ZDOOM_GENERATE_MAPFILE )
set( LINKERSTUFF "${LINKERSTUFF} /MAP" ) set( LINKERSTUFF "${LINKERSTUFF} /MAP" )
endif() endif()
@ -1521,17 +1534,23 @@ if( APPLE )
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/posix/osx/zdoom-info.plist" ) MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/posix/osx/zdoom-info.plist" )
if( NOT NO_FMOD ) if( NOT NO_FMOD )
if( FMOD_STUDIO )
set( FMOD_DYLIB libfmod.dylib )
else()
set( FMOD_DYLIB libfmodex.dylib )
endif()
# Fix fmod link so that it can be found in the app bundle. # Fix fmod link so that it can be found in the app bundle.
find_program( OTOOL otool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin" ) find_program( OTOOL otool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin" )
find_program( INSTALL_NAME_TOOL install_name_tool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin" ) find_program( INSTALL_NAME_TOOL install_name_tool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin" )
execute_process( COMMAND "${OTOOL}" -L "${FMOD_LIBRARY}" execute_process( COMMAND "${OTOOL}" -L "${FMOD_LIBRARY}"
COMMAND grep "libfmodex.dylib (compat" COMMAND grep "${FMOD_DYLIB} (compat"
COMMAND head -n1 COMMAND head -n1
COMMAND awk "{print $1}" COMMAND awk "{print $1}"
OUTPUT_VARIABLE FMOD_LINK OUTPUT_VARIABLE FMOD_LINK
OUTPUT_STRIP_TRAILING_WHITESPACE ) OUTPUT_STRIP_TRAILING_WHITESPACE )
add_custom_command( TARGET zdoom POST_BUILD add_custom_command( TARGET zdoom POST_BUILD
COMMAND "${INSTALL_NAME_TOOL}" -change "${FMOD_LINK}" @executable_path/../Frameworks/libfmodex.dylib "$<TARGET_FILE:zdoom>" COMMAND "${INSTALL_NAME_TOOL}" -change "${FMOD_LINK}" @executable_path/../Frameworks/${FMOD_DYLIB} "$<TARGET_FILE:zdoom>"
COMMENT "Relinking FMOD Ex" ) COMMENT "Relinking FMOD Ex" )
endif() endif()
endif() endif()

View file

@ -811,8 +811,8 @@ static void C_DrawNotifyText ()
DTA_KeepRatio, true, DTA_KeepRatio, true,
DTA_AlphaF, alpha, TAG_DONE); DTA_AlphaF, alpha, TAG_DONE);
else else
screen->DrawText (SmallFont, color, (screen->GetWidth() / active_con_scaletext() - screen->DrawText (SmallFont, color, (screen->GetWidth() -
SmallFont->StringWidth (NotifyStrings[i].Text))/ active_con_scaletext(), SmallFont->StringWidth (NotifyStrings[i].Text) * active_con_scaletext()) / 2 / active_con_scaletext(),
line, NotifyStrings[i].Text, line, NotifyStrings[i].Text,
DTA_VirtualWidth, screen->GetWidth() / active_con_scaletext(), DTA_VirtualWidth, screen->GetWidth() / active_con_scaletext(),
DTA_VirtualHeight, screen->GetHeight() / active_con_scaletext(), DTA_VirtualHeight, screen->GetHeight() / active_con_scaletext(),

View file

@ -1914,7 +1914,7 @@ class CommandAspectRatio : public SBarInfoCommandFlowControl
{ {
SBarInfoCommandFlowControl::Tick(block, statusBar, hudChanged); SBarInfoCommandFlowControl::Tick(block, statusBar, hudChanged);
SetTruth(ratioMap[CheckRatio(screen->GetWidth(), screen->GetHeight())] == ratio, block, statusBar); SetTruth(ratioMap[FindRatio()] == ratio, block, statusBar);
} }
protected: protected:
enum Ratio enum Ratio
@ -1931,6 +1931,37 @@ class CommandAspectRatio : public SBarInfoCommandFlowControl
static Ratio ratioMap[5]; static Ratio ratioMap[5];
Ratio ratio; Ratio ratio;
private:
int FindRatio()
{
float aspect = ActiveRatio(screen->GetWidth(), screen->GetHeight());
static std::pair<float, int> ratioTypes[] =
{
{ 21 / 9.0f , ASPECTRATIO_16_9 },
{ 16 / 9.0f , ASPECTRATIO_16_9 },
{ 17 / 10.0f , ASPECTRATIO_17_10 },
{ 16 / 10.0f , ASPECTRATIO_16_10 },
{ 4 / 3.0f , ASPECTRATIO_4_3 },
{ 5 / 4.0f , ASPECTRATIO_5_4 },
{ 0.0f, 0 }
};
int ratio = ratioTypes[0].second;
float distance = fabs(ratioTypes[0].first - aspect);
for (int i = 1; ratioTypes[i].first != 0.0f; i++)
{
float d = fabs(ratioTypes[i].first - aspect);
if (d < distance)
{
ratio = ratioTypes[i].second;
distance = d;
}
}
return ratio;
}
}; };
CommandAspectRatio::Ratio CommandAspectRatio::ratioMap[5] = {ASPECTRATIO_4_3,ASPECTRATIO_16_9,ASPECTRATIO_16_10,ASPECTRATIO_16_10,ASPECTRATIO_5_4}; CommandAspectRatio::Ratio CommandAspectRatio::ratioMap[5] = {ASPECTRATIO_4_3,ASPECTRATIO_16_9,ASPECTRATIO_16_10,ASPECTRATIO_16_10,ASPECTRATIO_5_4};

View file

@ -1108,13 +1108,13 @@ void DrawHUD()
} }
else else
{ {
if (WidescreenRatio == 4) if (CheckRatio(SCREENWIDTH, SCREENHEIGHT) == 4)
{ {
hudheight = hudwidth * 30 / BaseRatioSizes[WidescreenRatio][3]; // BaseRatioSizes is inverted for this mode hudheight = hudwidth * 30 / AspectMultiplier(WidescreenRatio); // BaseRatioSizes is inverted for this mode
} }
else else
{ {
hudheight = hudwidth * 30 / (48*48/BaseRatioSizes[WidescreenRatio][3]); hudheight = hudwidth * 30 / (48*48/AspectMultiplier(WidescreenRatio));
} }
} }
} }

View file

@ -299,14 +299,15 @@ void DBaseStatusBar::SetScaled (bool scale, bool force)
{ {
ST_X = 0; ST_X = 0;
ST_Y = VirticalResolution - RelTop; ST_Y = VirticalResolution - RelTop;
if (CheckRatio(SCREENWIDTH, SCREENHEIGHT) != 4) float aspect = ActiveRatio(SCREENWIDTH, SCREENHEIGHT);
if (aspect >= 1.3f)
{ // Normal resolution { // Normal resolution
::ST_Y = Scale (ST_Y, SCREENHEIGHT, VirticalResolution); ::ST_Y = Scale (ST_Y, SCREENHEIGHT, VirticalResolution);
} }
else else
{ // 5:4 resolution { // 5:4 resolution
::ST_Y = Scale(ST_Y - VirticalResolution/2, SCREENHEIGHT*3, Scale(VirticalResolution, BaseRatioSizes[4][1], 200)) + SCREENHEIGHT/2 ::ST_Y = Scale(ST_Y - VirticalResolution/2, SCREENHEIGHT*3, Scale(VirticalResolution, AspectBaseHeight(aspect), 200)) + SCREENHEIGHT/2
+ (SCREENHEIGHT - SCREENHEIGHT * BaseRatioSizes[4][3] / 48) / 2; + (SCREENHEIGHT - SCREENHEIGHT * AspectMultiplier(aspect) / 48) / 2;
} }
Displacement = 0; Displacement = 0;
} }
@ -1035,10 +1036,10 @@ void DBaseStatusBar::DrSmallNumberOuter (int val, int x, int y, bool center) con
void DBaseStatusBar::RefreshBackground () const void DBaseStatusBar::RefreshBackground () const
{ {
int x, x2, y, ratio; int x, x2, y;
ratio = CheckRatio (SCREENWIDTH, SCREENHEIGHT); float ratio = ActiveRatio (SCREENWIDTH, SCREENHEIGHT);
x = (!IsRatioWidescreen(ratio) || !Scaled) ? ST_X : SCREENWIDTH*(48-BaseRatioSizes[ratio][3])/(48*2); x = (ratio < 1.5f || !Scaled) ? ST_X : SCREENWIDTH*(48-AspectMultiplier(ratio))/(48*2);
y = x == ST_X && x > 0 ? ST_Y : ::ST_Y; y = x == ST_X && x > 0 ? ST_Y : ::ST_Y;
if(!CompleteBorder) if(!CompleteBorder)
@ -1058,8 +1059,8 @@ void DBaseStatusBar::RefreshBackground () const
{ {
if(!CompleteBorder) if(!CompleteBorder)
{ {
x2 = !IsRatioWidescreen(ratio) || !Scaled ? ST_X+HorizontalResolution : x2 = ratio < 1.5f || !Scaled ? ST_X+HorizontalResolution :
SCREENWIDTH - (SCREENWIDTH*(48-BaseRatioSizes[ratio][3])+48*2-1)/(48*2); SCREENWIDTH - (SCREENWIDTH*(48-AspectMultiplier(ratio))+48*2-1)/(48*2);
} }
else else
{ {

View file

@ -120,7 +120,7 @@ angle_t FGLRenderer::FrustumAngle()
// ok, this is a gross hack that barely works... // ok, this is a gross hack that barely works...
// but at least it doesn't overestimate too much... // but at least it doesn't overestimate too much...
double floatangle=2.0+(45.0+((tilt/1.9)))*mCurrentFoV*48.0/BaseRatioSizes[WidescreenRatio][3]/90.0; double floatangle=2.0+(45.0+((tilt/1.9)))*mCurrentFoV*48.0/AspectMultiplier(WidescreenRatio)/90.0;
angle_t a1 = DAngle(floatangle).BAMs(); angle_t a1 = DAngle(floatangle).BAMs();
if (a1>=ANGLE_180) return 0xffffffff; if (a1>=ANGLE_180) return 0xffffffff;
return a1; return a1;
@ -915,14 +915,10 @@ void FGLRenderer::RenderView (player_t* player)
NoInterpolateView = saved_niv; NoInterpolateView = saved_niv;
// I stopped using BaseRatioSizes here because the information there wasn't well presented.
// 4:3 16:9 16:10 17:10 5:4
static float ratios[]={1.333333f, 1.777777f, 1.6f, 1.7f, 1.25f, 1.7f, 2.333333f};
// now render the main view // now render the main view
float fovratio; float fovratio;
float ratio = ratios[WidescreenRatio]; float ratio = WidescreenRatio;
if (! Is54Aspect(WidescreenRatio)) if (WidescreenRatio >= 1.3f)
{ {
fovratio = 1.333333f; fovratio = 1.333333f;
} }

View file

@ -135,7 +135,6 @@ void GLSprite::CalculateVertices(FVector3 *v)
// [Nash] is a flat sprite // [Nash] is a flat sprite
const bool isFlatSprite = (actor != nullptr) && (spritetype == RF_WALLSPRITE || spritetype == RF_FLATSPRITE); const bool isFlatSprite = (actor != nullptr) && (spritetype == RF_WALLSPRITE || spritetype == RF_FLATSPRITE);
const bool dontFlip = (actor != nullptr) && (actor->renderflags & RF_DONTFLIP);
const bool useOffsets = (actor != nullptr) && !(actor->renderflags & RF_ROLLCENTER); const bool useOffsets = (actor != nullptr) && !(actor->renderflags & RF_ROLLCENTER);
// [Nash] check for special sprite drawing modes // [Nash] check for special sprite drawing modes
@ -176,37 +175,8 @@ void GLSprite::CalculateVertices(FVector3 *v)
yawvecY = actor->Angles.Yaw.Sin(); yawvecY = actor->Angles.Yaw.Sin();
} }
// [MC] This is the only thing that I changed in Nash's submission which
// was constantly applying roll to everything. That was wrong. Flat sprites
// with roll literally look like paper thing space ships trying to swerve.
// However, it does well with wall sprites.
// Also, renamed FLOORSPRITE to FLATSPRITE because that's technically incorrect.
// I plan on adding proper FLOORSPRITEs which can actually curve along sloped
// 3D floors later... if possible.
// Here we need some form of priority in order to work.
if (spritetype == RF_FLATSPRITE)
{
float pitchDegrees = -actor->Angles.Pitch.Degrees;
DVector3 apos = { x, y, z };
DVector3 diff = ViewPos - apos;
DAngle angto = diff.Angle();
angto = deltaangle(actor->Angles.Yaw, angto);
bool noFlipSprite = (!dontFlip || (fabs(angto) < 90.));
mat.Rotate(0, 1, 0, (noFlipSprite) ? 0 : 180);
mat.Rotate(-yawvecY, 0, yawvecX, (noFlipSprite) ? -pitchDegrees : pitchDegrees);
if (drawRollSpriteActor)
{
if (useOffsets) mat.Translate(xx, zz, yy);
mat.Rotate(yawvecX, 0, yawvecY, (noFlipSprite) ? -rollDegrees : rollDegrees);
if (useOffsets) mat.Translate(-xx, -zz, -yy);
}
}
// [fgsfds] Rotate the sprite about the sight vector (roll) // [fgsfds] Rotate the sprite about the sight vector (roll)
else if (spritetype == RF_WALLSPRITE) if (spritetype == RF_WALLSPRITE)
{ {
mat.Rotate(0, 1, 0, 0); mat.Rotate(0, 1, 0, 0);
if (drawRollSpriteActor) if (drawRollSpriteActor)
@ -405,7 +375,13 @@ void GLSprite::Draw(int pass)
gl_RenderState.Apply(); gl_RenderState.Apply();
FVector3 v[4]; FVector3 v[4];
if ((actor->renderflags & RF_SPRITETYPEMASK) == RF_FLATSPRITE)
{
}
else
{
CalculateVertices(v); CalculateVertices(v);
}
FQuadDrawer qd; FQuadDrawer qd;
@ -461,7 +437,7 @@ inline void GLSprite::PutSprite(bool translucent)
{ {
int list; int list;
// [BB] Allow models to be drawn in the GLDL_TRANSLUCENT pass. // [BB] Allow models to be drawn in the GLDL_TRANSLUCENT pass.
if (translucent || !modelframe) if (translucent || (!modelframe && (actor->renderflags & RF_SPRITETYPEMASK) != RF_WALLSPRITE))
{ {
list = GLDL_TRANSLUCENT; list = GLDL_TRANSLUCENT;
} }
@ -711,7 +687,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
x = thingpos.X; x = thingpos.X;
z = thingpos.Z; z = thingpos.Z;
y = thingpos.Y; y = thingpos.Y;
if (spritetype != RF_FLATSPRITE) z -= thing->Floorclip; if (spritetype == RF_FACESPRITE) z -= thing->Floorclip; // wall and flat sprites are to be considered level geometry so this may not apply.
// [RH] Make floatbobbing a renderer-only effect. // [RH] Make floatbobbing a renderer-only effect.
if (thing->flags2 & MF2_FLOATBOB) if (thing->flags2 & MF2_FLOATBOB)
@ -727,9 +703,19 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
DAngle ang = (thingpos - ViewPos).Angle(); DAngle ang = (thingpos - ViewPos).Angle();
FTextureID patch; FTextureID patch;
if (thing->flags7 & MF7_SPRITEANGLE) if (thing->flags7 & MF7_SPRITEANGLE)
{
patch = gl_GetSpriteFrame(spritenum, thing->frame, -1, (thing->SpriteAngle).BAMs(), &mirror); patch = gl_GetSpriteFrame(spritenum, thing->frame, -1, (thing->SpriteAngle).BAMs(), &mirror);
else }
else if (!(thing->renderflags & RF_FLATSPRITE))
{
patch = gl_GetSpriteFrame(spritenum, thing->frame, -1, (ang - (thing->Angles.Yaw + thing->SpriteRotation)).BAMs(), &mirror); patch = gl_GetSpriteFrame(spritenum, thing->frame, -1, (ang - (thing->Angles.Yaw + thing->SpriteRotation)).BAMs(), &mirror);
}
else
{
// Flat sprites cannot rotate in a predictable manner.
patch = gl_GetSpriteFrame(spritenum, thing->frame, 0, 0, &mirror);
}
if (!patch.isValid()) return; if (!patch.isValid()) return;
int type = thing->renderflags & RF_SPRITETYPEMASK; int type = thing->renderflags & RF_SPRITETYPEMASK;
gltexture = FMaterial::ValidateTexture(patch, (type == RF_FACESPRITE), false); gltexture = FMaterial::ValidateTexture(patch, (type == RF_FACESPRITE), false);
@ -781,6 +767,9 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
break; break;
case RF_FLATSPRITE: case RF_FLATSPRITE:
// needs careful rethinking
return;
case RF_WALLSPRITE: case RF_WALLSPRITE:
viewvecX = thing->Angles.Yaw.Cos(); viewvecX = thing->Angles.Yaw.Cos();
viewvecY = thing->Angles.Yaw.Sin(); viewvecY = thing->Angles.Yaw.Sin();
@ -910,8 +899,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal)
// This is a non-translucent sprite (i.e. STYLE_Normal or equivalent) // This is a non-translucent sprite (i.e. STYLE_Normal or equivalent)
trans=1.f; trans=1.f;
if (!gl_sprite_blend || modelframe || (thing->renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE)
if (!gl_sprite_blend || modelframe)
{ {
RenderStyle.SrcAlpha = STYLEALPHA_One; RenderStyle.SrcAlpha = STYLEALPHA_One;
RenderStyle.DestAlpha = STYLEALPHA_Zero; RenderStyle.DestAlpha = STYLEALPHA_Zero;

View file

@ -81,8 +81,6 @@ void FGLRenderer::DrawPSprite (player_t * player,DPSprite *psp, float sx, float
float scale; float scale;
float scalex; float scalex;
float ftexturemid; float ftexturemid;
// 4:3 16:9 16:10 17:10 5:4 17:10 21:9
static float xratio[] = {1.f, 3.f/4, 5.f/6, 40.f/51, 1.f, 40.f/51, 4.f/7};
// [BB] In the HUD model step we just render the model and break out. // [BB] In the HUD model step we just render the model and break out.
if ( hudModelStep ) if ( hudModelStep )
@ -108,7 +106,7 @@ void FGLRenderer::DrawPSprite (player_t * player,DPSprite *psp, float sx, float
tex->GetSpriteRect(&r); tex->GetSpriteRect(&r);
// calculate edges of the shape // calculate edges of the shape
scalex = xratio[WidescreenRatio] * vw / 320; scalex = (320.0f / (240.0f * WidescreenRatio)) * vw / 320;
tx = sx - (160 - r.left); tx = sx - (160 - r.left);
x1 = tx * scalex + vw/2; x1 = tx * scalex + vw/2;

View file

@ -45,17 +45,38 @@ QuadStereo::QuadStereo(double ipdMeters)
// Check whether quad-buffered stereo is supported in the current context // Check whether quad-buffered stereo is supported in the current context
// We are assuming the OpenGL context is already current at this point, // We are assuming the OpenGL context is already current at this point,
// i.e. this constructor is called "just in time". // i.e. this constructor is called "just in time".
// First initialize to mono-ish initial state
bQuadStereoSupported = leftEye.bQuadStereoSupported = rightEye.bQuadStereoSupported = false;
eye_ptrs.Push(&leftEye); // We ALWAYS want to show at least this one view...
// We will possibly advance to true stereo mode in the Setup() method...
}
// Sometimes the stereo render context is not ready immediately at start up
/* private */
void QuadStereo::checkInitialRenderContextState()
{
// Keep trying until we see at least one good OpenGL context to render to
static bool bDecentContextWasFound = false;
if (!bDecentContextWasFound) {
// I'm using a "random" OpenGL call (glGetFramebufferAttachmentParameteriv)
// that appears to correlate with whether the context is ready
GLint attachmentType = GL_NONE;
glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
if (attachmentType != GL_NONE) // Finally, a useful OpenGL context
{
// This block will be executed exactly ONCE during a game run
bDecentContextWasFound = true; // now we can stop checking every frame...
// Now check whether this context supports hardware stereo
GLboolean supportsStereo, supportsBuffered; GLboolean supportsStereo, supportsBuffered;
glGetBooleanv(GL_STEREO, &supportsStereo); glGetBooleanv(GL_STEREO, &supportsStereo);
glGetBooleanv(GL_DOUBLEBUFFER, &supportsBuffered); glGetBooleanv(GL_DOUBLEBUFFER, &supportsBuffered);
bQuadStereoSupported = supportsStereo && supportsBuffered; bQuadStereoSupported = supportsStereo && supportsBuffered;
leftEye.bQuadStereoSupported = bQuadStereoSupported; leftEye.bQuadStereoSupported = bQuadStereoSupported;
rightEye.bQuadStereoSupported = bQuadStereoSupported; rightEye.bQuadStereoSupported = bQuadStereoSupported;
if (bQuadStereoSupported)
eye_ptrs.Push(&leftEye); eye_ptrs.Push(&rightEye); // Use the other eye too, if we can do stereo
// If stereo is not supported, just draw scene once (left eye view only) }
if (bQuadStereoSupported) {
eye_ptrs.Push(&rightEye);
} }
} }
@ -81,11 +102,18 @@ void QuadStereo::Present() const
{ {
GLRenderer->mBuffers->BindOutputFB(); GLRenderer->mBuffers->BindOutputFB();
GLRenderer->ClearBorders(); GLRenderer->ClearBorders();
GLRenderer->mBuffers->BindEyeTexture(1, 0); GLRenderer->mBuffers->BindEyeTexture(0, 0);
GLRenderer->DrawPresentTexture(GLRenderer->mOutputLetterbox, true); GLRenderer->DrawPresentTexture(GLRenderer->mOutputLetterbox, true);
} }
} }
void QuadStereo::SetUp() const
{
Stereo3DMode::SetUp();
// Maybe advance to true stereo mode (ONCE), after the stereo context is finally ready
const_cast<QuadStereo*>(this)->checkInitialRenderContextState();
}
/* static */ /* static */
const QuadStereo& QuadStereo::getInstance(float ipd) const QuadStereo& QuadStereo::getInstance(float ipd)
{ {

View file

@ -69,11 +69,13 @@ class QuadStereo : public Stereo3DMode
public: public:
QuadStereo(double ipdMeters); QuadStereo(double ipdMeters);
void Present() const override; void Present() const override;
void SetUp() const override;
static const QuadStereo& getInstance(float ipd); static const QuadStereo& getInstance(float ipd);
private: private:
QuadStereoLeftPose leftEye; QuadStereoLeftPose leftEye;
QuadStereoRightPose rightEye; QuadStereoRightPose rightEye;
bool bQuadStereoSupported; bool bQuadStereoSupported;
void checkInitialRenderContextState();
}; };

View file

@ -192,12 +192,23 @@ void OpenGLFrameBuffer::Update()
DrawRateStuff(); DrawRateStuff();
GLRenderer->Flush(); GLRenderer->Flush();
GLRenderer->SetOutputViewport(nullptr);
Swap(); Swap();
swapped = false; swapped = false;
Unlock(); Unlock();
CheckBench(); CheckBench();
if (Windowed)
{
int clientWidth = GetClientWidth();
int clientHeight = GetClientHeight();
if (clientWidth > 0 && clientHeight > 0 && (Width != clientWidth || Height != clientHeight))
{
Resize(clientWidth, clientHeight);
V_OutputResized(Width, Height);
}
}
GLRenderer->SetOutputViewport(nullptr);
} }

View file

@ -309,6 +309,11 @@ void FUDMFKeys::Sort()
FUDMFKey *FUDMFKeys::Find(FName key) FUDMFKey *FUDMFKeys::Find(FName key)
{ {
if (!mSorted)
{
mSorted = true;
Sort();
}
int min = 0, max = Size()-1; int min = 0, max = Size()-1;
while (min <= max) while (min <= max)

View file

@ -483,7 +483,7 @@ NSOpenGLPixelFormat* CreatePixelFormat(const OpenGLProfile profile)
attributes[i++] = NSOpenGLPFAAllowOfflineRenderers; attributes[i++] = NSOpenGLPFAAllowOfflineRenderers;
} }
if (NSAppKitVersionNumber >= AppKit10_7 && OpenGLProfile::Core == profile) if (NSAppKitVersionNumber >= AppKit10_7 && OpenGLProfile::Core == profile && 1 == vid_renderer)
{ {
NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersion3_2Core; NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersion3_2Core;
const char* const glversion = Args->CheckValue("-glversion"); const char* const glversion = Args->CheckValue("-glversion");

View file

@ -245,6 +245,7 @@ struct FUDMFKey
class FUDMFKeys : public TArray<FUDMFKey> class FUDMFKeys : public TArray<FUDMFKey>
{ {
bool mSorted = false;
public: public:
void Sort(); void Sort();
FUDMFKey *Find(FName key); FUDMFKey *Find(FName key);

View file

@ -232,7 +232,7 @@ void R_SetVisibility(double vis)
else else
r_WallVisibility = r_BaseVisibility; r_WallVisibility = r_BaseVisibility;
r_WallVisibility = (InvZtoScale * SCREENWIDTH*BaseRatioSizes[WidescreenRatio][1] / r_WallVisibility = (InvZtoScale * SCREENWIDTH*AspectBaseHeight(WidescreenRatio) /
(viewwidth*SCREENHEIGHT*3)) * (r_WallVisibility * FocalTangent); (viewwidth*SCREENHEIGHT*3)) * (r_WallVisibility * FocalTangent);
// Prevent overflow on floors/ceilings. Note that the calculation of // Prevent overflow on floors/ceilings. Note that the calculation of
@ -295,7 +295,7 @@ CCMD (r_visibility)
// //
//========================================================================== //==========================================================================
void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, int trueratio) void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, float trueratio)
{ {
int virtheight, virtwidth, virtwidth2, virtheight2; int virtheight, virtwidth, virtwidth2, virtheight2;
@ -318,22 +318,22 @@ void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight,
virtwidth = virtwidth2 = fullWidth; virtwidth = virtwidth2 = fullWidth;
virtheight = virtheight2 = fullHeight; virtheight = virtheight2 = fullHeight;
if (Is54Aspect(trueratio)) if (trueratio < 1.3f)
{ {
virtheight2 = virtheight2 * BaseRatioSizes[trueratio][3] / 48; virtheight2 = virtheight2 * AspectMultiplier(trueratio) / 48;
} }
else else
{ {
virtwidth2 = virtwidth2 * BaseRatioSizes[trueratio][3] / 48; virtwidth2 = virtwidth2 * AspectMultiplier(trueratio) / 48;
} }
if (Is54Aspect(WidescreenRatio)) if (WidescreenRatio < 1.3f)
{ {
virtheight = virtheight * BaseRatioSizes[WidescreenRatio][3] / 48; virtheight = virtheight * AspectMultiplier(WidescreenRatio) / 48;
} }
else else
{ {
virtwidth = virtwidth * BaseRatioSizes[WidescreenRatio][3] / 48; virtwidth = virtwidth * AspectMultiplier(WidescreenRatio) / 48;
} }
BaseYaspectMul = 320.0 * virtheight2 / (r_Yaspect * virtwidth2); BaseYaspectMul = 320.0 * virtheight2 / (r_Yaspect * virtwidth2);
@ -678,7 +678,7 @@ void R_EnterPortal (PortalDrawseg* pds, int depth)
ViewPos.X = (x1 + r * dx)*2 - x; ViewPos.X = (x1 + r * dx)*2 - x;
ViewPos.Y = (y1 + r * dy)*2 - y; ViewPos.Y = (y1 + r * dy)*2 - y;
} }
ViewAngle = pds->src->Delta().Angle() - startang; ViewAngle = pds->src->Delta().Angle() * 2 - startang;
} }
else else
{ {

View file

@ -55,7 +55,7 @@ struct FRenderer
virtual void ErrorCleanup () {} virtual void ErrorCleanup () {}
virtual void ClearBuffer(int color) = 0; virtual void ClearBuffer(int color) = 0;
virtual void Init() = 0; virtual void Init() = 0;
virtual void SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, int trueratio) {} virtual void SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, float trueratio) {}
virtual void SetupFrame(player_t *player) {} virtual void SetupFrame(player_t *player) {}
virtual void CopyStackedViewParameters() {} virtual void CopyStackedViewParameters() {}
virtual void RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov) = 0; virtual void RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov) = 0;

View file

@ -45,7 +45,7 @@
class FArchive; class FArchive;
void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, int trueratio); void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight, float trueratio);
void R_SetupColormap(player_t *); void R_SetupColormap(player_t *);
void R_SetupFreelook(); void R_SetupFreelook();
void R_InitRenderer(); void R_InitRenderer();
@ -275,7 +275,7 @@ void FSoftwareRenderer::ClearBuffer(int color)
// //
//=========================================================================== //===========================================================================
void FSoftwareRenderer::SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, int trueratio) void FSoftwareRenderer::SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, float trueratio)
{ {
R_SWRSetWindow(windowSize, fullWidth, fullHeight, stHeight, trueratio); R_SWRSetWindow(windowSize, fullWidth, fullHeight, stHeight, trueratio);
} }

View file

@ -30,7 +30,7 @@ struct FSoftwareRenderer : public FRenderer
void ErrorCleanup (); void ErrorCleanup ();
void ClearBuffer(int color); void ClearBuffer(int color);
void Init(); void Init();
void SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, int trueratio); void SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight, float trueratio);
void SetupFrame(player_t *player); void SetupFrame(player_t *player);
void CopyStackedViewParameters(); void CopyStackedViewParameters();
void RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov); void RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov);

View file

@ -1393,7 +1393,7 @@ void R_DrawPSprite(DPSprite *pspr, AActor *owner, float bobx, float boby, double
} }
if (pspr->GetID() < PSP_TARGETCENTER) if (pspr->GetID() < PSP_TARGETCENTER)
{ // Move the weapon down for 1280x1024. { // Move the weapon down for 1280x1024.
vis->texturemid -= BaseRatioSizes[WidescreenRatio][2]; vis->texturemid -= AspectPspriteOffset(WidescreenRatio);
} }
vis->x1 = x1 < 0 ? 0 : x1; vis->x1 = x1 < 0 ? 0 : x1;
vis->x2 = x2 >= viewwidth ? viewwidth : x2; vis->x2 = x2 >= viewwidth ? viewwidth : x2;

View file

@ -138,7 +138,7 @@ angle_t LocalViewAngle;
int LocalViewPitch; int LocalViewPitch;
bool LocalKeyboardTurner; bool LocalKeyboardTurner;
int WidescreenRatio; float WidescreenRatio;
int setblocks; int setblocks;
int extralight; int extralight;
bool setsizeneeded; bool setsizeneeded;
@ -200,7 +200,7 @@ void R_SetViewSize (int blocks)
void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight) void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight)
{ {
int trueratio; float trueratio;
if (windowSize >= 11) if (windowSize >= 11)
{ {
@ -220,8 +220,7 @@ void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight)
freelookviewheight = ((setblocks*fullHeight)/10)&~7; freelookviewheight = ((setblocks*fullHeight)/10)&~7;
} }
// If the screen is approximately 16:9 or 16:10, consider it widescreen. WidescreenRatio = ActiveRatio (fullWidth, fullHeight, &trueratio);
WidescreenRatio = CheckRatio (fullWidth, fullHeight, &trueratio);
DrawFSHUD = (windowSize == 11); DrawFSHUD = (windowSize == 11);
@ -230,13 +229,13 @@ void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight)
centery = viewheight/2; centery = viewheight/2;
centerx = viewwidth/2; centerx = viewwidth/2;
if (Is54Aspect(WidescreenRatio)) if (WidescreenRatio < 1.3f)
{ {
centerxwide = centerx; centerxwide = centerx;
} }
else else
{ {
centerxwide = centerx * BaseRatioSizes[WidescreenRatio][3] / 48; centerxwide = centerx * AspectMultiplier(WidescreenRatio) / 48;
} }

View file

@ -33,7 +33,7 @@ extern int validcount;
extern angle_t LocalViewAngle; // [RH] Added to consoleplayer's angle extern angle_t LocalViewAngle; // [RH] Added to consoleplayer's angle
extern int LocalViewPitch; // [RH] Used directly instead of consoleplayer's pitch extern int LocalViewPitch; // [RH] Used directly instead of consoleplayer's pitch
extern bool LocalKeyboardTurner; // [RH] The local player used the keyboard to turn, so interpolate extern bool LocalKeyboardTurner; // [RH] The local player used the keyboard to turn, so interpolate
extern int WidescreenRatio; extern float WidescreenRatio;
extern double r_TicFracF; extern double r_TicFracF;
extern DWORD r_FrameTime; extern DWORD r_FrameTime;

View file

@ -971,6 +971,7 @@ bool FMODSoundRenderer::Init()
#if FMOD_STUDIO #if FMOD_STUDIO
FMOD_ADVANCEDSETTINGS advSettings = {}; FMOD_ADVANCEDSETTINGS advSettings = {};
advSettings.cbSize = sizeof advSettings;
advSettings.resamplerMethod = resampler; advSettings.resamplerMethod = resampler;
result = Sys->setAdvancedSettings(&advSettings); result = Sys->setAdvancedSettings(&advSettings);
if (result != FMOD_OK) if (result != FMOD_OK)
@ -1370,11 +1371,8 @@ void FMODSoundRenderer::PrintStatus()
{ {
FMOD_OUTPUTTYPE output; FMOD_OUTPUTTYPE output;
FMOD_SPEAKERMODE speakermode; FMOD_SPEAKERMODE speakermode;
FMOD_SOUND_FORMAT format;
FMOD_DSP_RESAMPLER resampler;
int driver; int driver;
int samplerate; int samplerate;
int numoutputchannels;
unsigned int bufferlength; unsigned int bufferlength;
int numbuffers; int numbuffers;
@ -1413,6 +1411,9 @@ void FMODSoundRenderer::PrintStatus()
#endif #endif
} }
#if !FMOD_STUDIO #if !FMOD_STUDIO
FMOD_SOUND_FORMAT format;
FMOD_DSP_RESAMPLER resampler;
int numoutputchannels;
if (FMOD_OK == Sys->getSoftwareFormat(&samplerate, &format, &numoutputchannels, NULL, &resampler, NULL)) if (FMOD_OK == Sys->getSoftwareFormat(&samplerate, &format, &numoutputchannels, NULL, &resampler, NULL))
{ {
Printf (TEXTCOLOR_LIGHTBLUE "Software mixer sample rate: " TEXTCOLOR_GREEN "%d\n", samplerate); Printf (TEXTCOLOR_LIGHTBLUE "Software mixer sample rate: " TEXTCOLOR_GREEN "%d\n", samplerate);
@ -2758,6 +2759,16 @@ std::pair<SoundHandle,bool> FMODSoundRenderer::LoadSoundRaw(BYTE *sfxdata, int l
exinfo.defaultfrequency = frequency; exinfo.defaultfrequency = frequency;
switch (bits) switch (bits)
{ {
#if FMOD_STUDIO
case -8:
// Need to convert sample data from signed to unsigned.
for (int i = 0; i < length; i++)
{
sfxdata[i] ^= 0x80;
}
case 8:
#else // !FMOD_STUDIO
case 8: case 8:
// Need to convert sample data from unsigned to signed. // Need to convert sample data from unsigned to signed.
for (int i = 0; i < length; ++i) for (int i = 0; i < length; ++i)
@ -2766,6 +2777,7 @@ std::pair<SoundHandle,bool> FMODSoundRenderer::LoadSoundRaw(BYTE *sfxdata, int l
} }
case -8: case -8:
#endif // FMOD_STUDIO
exinfo.format = FMOD_SOUND_FORMAT_PCM8; exinfo.format = FMOD_SOUND_FORMAT_PCM8;
numsamples = length; numsamples = length;
break; break;

View file

@ -863,37 +863,37 @@ bool DCanvas::ParseDrawTextureTags (FTexture *img, double x, double y, DWORD tag
void DCanvas::VirtualToRealCoords(double &x, double &y, double &w, double &h, void DCanvas::VirtualToRealCoords(double &x, double &y, double &w, double &h,
double vwidth, double vheight, bool vbottom, bool handleaspect) const double vwidth, double vheight, bool vbottom, bool handleaspect) const
{ {
int myratio = handleaspect ? CheckRatio (Width, Height) : 0; float myratio = handleaspect ? ActiveRatio (Width, Height) : (4.0f / 3.0f);
// if 21:9 AR, map to 16:9 for all callers. // if 21:9 AR, map to 16:9 for all callers.
// this allows for black bars and stops the stretching of fullscreen images // this allows for black bars and stops the stretching of fullscreen images
if (myratio == 6) { if (myratio > 1.7f) {
myratio = 2; myratio = 16.0f / 9.0f;
} }
double right = x + w; double right = x + w;
double bottom = y + h; double bottom = y + h;
if (myratio != 0 && myratio != 4) if (myratio > 1.4f)
{ // The target surface is either 16:9 or 16:10, so expand the { // The target surface is either 16:9 or 16:10, so expand the
// specified virtual size to avoid undesired stretching of the // specified virtual size to avoid undesired stretching of the
// image. Does not handle non-4:3 virtual sizes. I'll worry about // image. Does not handle non-4:3 virtual sizes. I'll worry about
// those if somebody expresses a desire to use them. // those if somebody expresses a desire to use them.
x = (x - vwidth * 0.5) * Width * 960 / (vwidth * BaseRatioSizes[myratio][0]) + Width * 0.5; x = (x - vwidth * 0.5) * Width * 960 / (vwidth * AspectBaseWidth(myratio)) + Width * 0.5;
w = (right - vwidth * 0.5) * Width * 960 / (vwidth * BaseRatioSizes[myratio][0]) + Width * 0.5 - x; w = (right - vwidth * 0.5) * Width * 960 / (vwidth * AspectBaseWidth(myratio)) + Width * 0.5 - x;
} }
else else
{ {
x = x * Width / vwidth; x = x * Width / vwidth;
w = right * Width / vwidth - x; w = right * Width / vwidth - x;
} }
if (myratio == 4) if (myratio < 1.3f)
{ // The target surface is 5:4 { // The target surface is 5:4
y = (y - vheight * 0.5) * Height * 600 / (vheight * BaseRatioSizes[myratio][1]) + Height * 0.5; y = (y - vheight * 0.5) * Height * 600 / (vheight * AspectBaseHeight(myratio)) + Height * 0.5;
h = (bottom - vheight * 0.5) * Height * 600 / (vheight * BaseRatioSizes[myratio][1]) + Height * 0.5 - y; h = (bottom - vheight * 0.5) * Height * 600 / (vheight * AspectBaseHeight(myratio)) + Height * 0.5 - y;
if (vbottom) if (vbottom)
{ {
y += (Height - Height * BaseRatioSizes[myratio][3] / 48.0) * 0.5; y += (Height - Height * AspectMultiplier(myratio) / 48.0) * 0.5;
} }
} }
else else
@ -937,30 +937,30 @@ void DCanvas::VirtualToRealCoordsInt(int &x, int &y, int &w, int &h,
void DCanvas::FillBorder (FTexture *img) void DCanvas::FillBorder (FTexture *img)
{ {
int myratio = CheckRatio (Width, Height); float myratio = ActiveRatio (Width, Height);
// if 21:9 AR, fill borders akin to 16:9, since all fullscreen // if 21:9 AR, fill borders akin to 16:9, since all fullscreen
// images are being drawn to that scale. // images are being drawn to that scale.
if (myratio == 6) { if (myratio > 1.7f) {
myratio = 2; myratio = 16 / 9.0f;
} }
if (myratio == 0) if (myratio >= 1.3f && myratio <= 1.4f)
{ // This is a 4:3 display, so no border to show { // This is a 4:3 display, so no border to show
return; return;
} }
int bordtop, bordbottom, bordleft, bordright, bord; int bordtop, bordbottom, bordleft, bordright, bord;
if (Is54Aspect(myratio)) if (myratio < 1.3f)
{ // Screen is taller than it is wide { // Screen is taller than it is wide
bordleft = bordright = 0; bordleft = bordright = 0;
bord = Height - Height * BaseRatioSizes[myratio][3] / 48; bord = Height - Height * AspectMultiplier(myratio) / 48;
bordtop = bord / 2; bordtop = bord / 2;
bordbottom = bord - bordtop; bordbottom = bord - bordtop;
} }
else else
{ // Screen is wider than it is tall { // Screen is wider than it is tall
bordtop = bordbottom = 0; bordtop = bordbottom = 0;
bord = Width - Width * BaseRatioSizes[myratio][3] / 48; bord = Width - Width * AspectMultiplier(myratio) / 48;
bordleft = bord / 2; bordleft = bord / 2;
bordright = bord - bordleft; bordright = bord - bordleft;
} }

View file

@ -725,6 +725,21 @@ void DCanvas::CalcGamma (float gamma, BYTE gammalookup[256])
DSimpleCanvas::DSimpleCanvas (int width, int height) DSimpleCanvas::DSimpleCanvas (int width, int height)
: DCanvas (width, height) : DCanvas (width, height)
{ {
MemBuffer = nullptr;
Resize(width, height);
}
void DSimpleCanvas::Resize(int width, int height)
{
Width = width;
Height = height;
if (MemBuffer != NULL)
{
delete[] MemBuffer;
MemBuffer = NULL;
}
// Making the pitch a power of 2 is very bad for performance // Making the pitch a power of 2 is very bad for performance
// Try to maximize the number of cache lines that can be filled // Try to maximize the number of cache lines that can be filled
// for each column drawing operation by making the pitch slightly // for each column drawing operation by making the pitch slightly
@ -1259,7 +1274,6 @@ CCMD(clean)
bool V_DoModeSetup (int width, int height, int bits) bool V_DoModeSetup (int width, int height, int bits)
{ {
DFrameBuffer *buff = I_SetMode (width, height, screen); DFrameBuffer *buff = I_SetMode (width, height, screen);
int cx1, cx2;
if (buff == NULL) if (buff == NULL)
{ {
@ -1274,6 +1288,17 @@ bool V_DoModeSetup (int width, int height, int bits)
// if D3DFB is being used for the display. // if D3DFB is being used for the display.
FFont::StaticPreloadFonts(); FFont::StaticPreloadFonts();
DisplayBits = bits;
V_UpdateModeSize(width, height);
M_RefreshModesList ();
return true;
}
void V_UpdateModeSize (int width, int height)
{
int cx1, cx2;
V_CalcCleanFacs(320, 200, width, height, &CleanXfac, &CleanYfac, &cx1, &cx2); V_CalcCleanFacs(320, 200, width, height, &CleanXfac, &CleanYfac, &cx1, &cx2);
CleanWidth = width / CleanXfac; CleanWidth = width / CleanXfac;
@ -1314,32 +1339,37 @@ bool V_DoModeSetup (int width, int height, int bits)
DisplayWidth = width; DisplayWidth = width;
DisplayHeight = height; DisplayHeight = height;
DisplayBits = bits;
R_OldBlend = ~0; R_OldBlend = ~0;
Renderer->OnModeSet(); Renderer->OnModeSet();
}
M_RefreshModesList (); void V_OutputResized (int width, int height)
{
return true; V_UpdateModeSize(width, height);
setsizeneeded = true;
if (StatusBar != NULL)
{
StatusBar->ScreenSizeChanged();
}
} }
void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *_cx1, int *_cx2) void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *_cx1, int *_cx2)
{ {
int ratio; float ratio;
int cwidth; int cwidth;
int cheight; int cheight;
int cx1, cy1, cx2, cy2; int cx1, cy1, cx2, cy2;
ratio = CheckRatio(realwidth, realheight); ratio = ActiveRatio(realwidth, realheight);
if (Is54Aspect(ratio)) if (ratio < 1.3f)
{ {
cwidth = realwidth; cwidth = realwidth;
cheight = realheight * BaseRatioSizes[ratio][3] / 48; cheight = realheight * AspectMultiplier(ratio) / 48;
} }
else else
{ {
cwidth = realwidth * BaseRatioSizes[ratio][3] / 48; cwidth = realwidth * AspectMultiplier(ratio) / 48;
cheight = realheight; cheight = realheight;
} }
// Use whichever pair of cwidth/cheight or width/height that produces less difference // Use whichever pair of cwidth/cheight or width/height that produces less difference
@ -1573,20 +1603,10 @@ CUSTOM_CVAR (Int, vid_aspect, 0, CVAR_GLOBALCONFIG|CVAR_ARCHIVE)
} }
} }
// Tries to guess the physical dimensions of the screen based on the // Helper for ActiveRatio and CheckRatio. Returns the forced ratio type, or -1 if none.
// screen's pixel dimensions. Can return: int ActiveFakeRatio(int width, int height)
// 0: 4:3
// 1: 16:9
// 2: 16:10
// 3: 17:10
// 4: 5:4
// 5: 17:10 (redundant)
// 6: 21:9
int CheckRatio (int width, int height, int *trueratio)
{ {
int fakeratio = -1; int fakeratio = -1;
int ratio;
if ((vid_aspect >= 1) && (vid_aspect <= 6)) if ((vid_aspect >= 1) && (vid_aspect <= 6))
{ {
// [SP] User wants to force aspect ratio; let them. // [SP] User wants to force aspect ratio; let them.
@ -1611,72 +1631,96 @@ int CheckRatio (int width, int height, int *trueratio)
fakeratio = (height * 5 / 4 == width) ? 4 : 0; fakeratio = (height * 5 / 4 == width) ? 4 : 0;
} }
} }
// If the size is approximately 16:9, consider it so. return fakeratio;
if (abs (height * 16/9 - width) < 10)
{
ratio = 1;
}
// Consider 17:10 as well.
else if (abs (height * 17/10 - width) < 10)
{
ratio = 3;
}
// 16:10 has more variance in the pixel dimensions. Grr.
else if (abs (height * 16/10 - width) < 60)
{
// 320x200 and 640x400 are always 4:3, not 16:10
if ((width == 320 && height == 200) || (width == 640 && height == 400))
{
ratio = 0;
}
else
{
ratio = 2;
}
}
// Unless vid_tft is set, 1280x1024 is 4:3, not 5:4.
else if (height * 5/4 == width && vid_tft)
{
ratio = 4;
}
// test for 21:9 (actually 64:27, 21:9 is a semi-accurate ratio used in marketing)
else if (abs (height * 64/27 - width) < 30)
{
ratio = 6;
}
// Assume anything else is 4:3. (Which is probably wrong these days...)
else
{
ratio = 0;
} }
if (trueratio != NULL) // Active screen ratio based on cvars and size
float ActiveRatio(int width, int height, float *trueratio)
{ {
*trueratio = ratio; static float forcedRatioTypes[] =
}
return (fakeratio >= 0) ? fakeratio : ratio;
}
// First column: Base width
// Second column: Base height (used for wall visibility multiplier)
// Third column: Psprite offset (needed for "tallscreen" modes)
// Fourth column: Width or height multiplier
// For widescreen aspect ratio x:y ...
// base_width = 240 * x / y
// multiplier = 320 / base_width
// base_height = 200 * multiplier
const int BaseRatioSizes[7][4] =
{ {
{ 960, 600, 0, 48 }, // 4:3 320, 200, multiplied by three 4 / 3.0f,
{ 1280, 450, 0, 48*3/4 }, // 16:9 426.6667, 150, multiplied by three 16 / 9.0f,
{ 1152, 500, 0, 48*5/6 }, // 16:10 386, 166.6667, multiplied by three 16 / 10.0f,
{ 1224, 471, 0, 48*40/51 }, // 17:10 408, 156.8627, multiplied by three 17 / 10.0f,
{ 960, 640, (int)(6.5*FRACUNIT), 48*15/16 }, // 5:4 320, 213.3333, multiplied by three 5 / 4.0f,
{ 1224, 471, 0, 48*40/51 }, // 17:10 408, 156.8627, multiplied by three (REDUNDANT) 17 / 10.0f,
{ 1707, 338, 0, 48*9/16 } // 21:9 568.8889, 337.5, multiplied by three 21 / 9.0f
}; };
float ratio = width / (float)height;
int fakeratio = ActiveFakeRatio(width, height);
if (trueratio)
*trueratio = ratio;
return (fakeratio != -1) ? forcedRatioTypes[fakeratio] : ratio;
}
// Tries to guess the physical dimensions of the screen based on the
// screen's pixel dimensions. Can return:
// 0: 4:3
// 1: 16:9
// 2: 16:10
// 3: 17:10
// 4: 5:4
// 5: 17:10 (redundant, never returned)
// 6: 21:9
int CheckRatio (int width, int height, int *trueratio)
{
float aspect = width / (float)height;
static std::pair<float, int> ratioTypes[] =
{
{ 21 / 9.0f , 6 },
{ 16 / 9.0f , 1 },
{ 17 / 10.0f , 3 },
{ 16 / 10.0f , 2 },
{ 4 / 3.0f , 0 },
{ 5 / 4.0f , 4 },
{ 0.0f, 0 }
};
int ratio = ratioTypes[0].second;
float distance = fabs(ratioTypes[0].first - aspect);
for (int i = 1; ratioTypes[i].first != 0.0f; i++)
{
float d = fabs(ratioTypes[i].first - aspect);
if (d < distance)
{
ratio = ratioTypes[i].second;
distance = d;
}
}
int fakeratio = ActiveFakeRatio(width, height);
if (fakeratio == -1)
fakeratio = ratio;
if (trueratio)
*trueratio = ratio;
return fakeratio;
}
int AspectBaseWidth(float aspect)
{
return (int)round(240.0f * aspect * 3.0f);
}
int AspectBaseHeight(float aspect)
{
return (int)round(200.0f * (320.0f / (240.0f * aspect)) * 3.0f);
}
int AspectPspriteOffset(float aspect)
{
return aspect < 1.3f ? (int)(6.5*FRACUNIT) : 0;
}
int AspectMultiplier(float aspect)
{
return (int)round(320.0f / (240.0f * aspect) * 48.0f);
}
void IVideo::DumpAdapters () void IVideo::DumpAdapters ()
{ {
Printf("Multi-monitor support unavailable.\n"); Printf("Multi-monitor support unavailable.\n");

View file

@ -47,6 +47,8 @@ extern int CleanWidth_1, CleanHeight_1, CleanXfac_1, CleanYfac_1;
extern int DisplayWidth, DisplayHeight, DisplayBits; extern int DisplayWidth, DisplayHeight, DisplayBits;
bool V_DoModeSetup (int width, int height, int bits); bool V_DoModeSetup (int width, int height, int bits);
void V_UpdateModeSize (int width, int height);
void V_OutputResized (int width, int height);
void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *cx1=NULL, int *cx2=NULL); void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *cx1=NULL, int *cx2=NULL);
class FTexture; class FTexture;
@ -300,6 +302,8 @@ public:
void Unlock (); void Unlock ();
protected: protected:
void Resize(int width, int height);
BYTE *MemBuffer; BYTE *MemBuffer;
DSimpleCanvas() {} DSimpleCanvas() {}
@ -512,15 +516,15 @@ extern "C" void ASM_PatchPitch (void);
int CheckRatio (int width, int height, int *trueratio=NULL); int CheckRatio (int width, int height, int *trueratio=NULL);
static inline int CheckRatio (double width, double height) { return CheckRatio(int(width), int(height)); } static inline int CheckRatio (double width, double height) { return CheckRatio(int(width), int(height)); }
extern const int BaseRatioSizes[7][4]; inline bool IsRatioWidescreen(int ratio) { return (ratio & 3) != 0; }
inline bool IsRatioWidescreen(int ratio) { float ActiveRatio (int width, int height, float *trueratio = NULL);
return (ratio & 3)!=0; static inline double ActiveRatio (double width, double height) { return ActiveRatio(int(width), int(height)); }
}
inline bool Is54Aspect(int ratio) { int AspectBaseWidth(float aspect);
return ratio == 4; int AspectBaseHeight(float aspect);
} int AspectPspriteOffset(float aspect);
int AspectMultiplier(float aspect);
EXTERN_CVAR(Int, uiscale); EXTERN_CVAR(Int, uiscale);

View file

@ -1220,6 +1220,24 @@ void D3DFB::Flip()
CurrRenderTexture ^= RenderTextureToggle; CurrRenderTexture ^= RenderTextureToggle;
TempRenderTexture = RenderTexture[CurrRenderTexture]; TempRenderTexture = RenderTexture[CurrRenderTexture];
} }
if (Windowed)
{
RECT box;
GetClientRect(Window, &box);
if (box.right > 0 && box.right > 0 && (Width != box.right || Height != box.bottom))
{
Resize(box.right, box.bottom);
TrueHeight = Height;
PixelDoubling = 0;
LBOffsetI = 0;
LBOffset = 0.0f;
Reset();
V_OutputResized(Width, Height);
}
}
} }
//========================================================================== //==========================================================================

View file

@ -537,10 +537,18 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (screen && !VidResizing) if (screen && !VidResizing)
{ {
LPMINMAXINFO mmi = (LPMINMAXINFO)lParam; LPMINMAXINFO mmi = (LPMINMAXINFO)lParam;
if (screen->IsFullscreen())
{
RECT rect = { 0, 0, screen->GetWidth(), screen->GetHeight() }; RECT rect = { 0, 0, screen->GetWidth(), screen->GetHeight() };
AdjustWindowRectEx(&rect, WS_VISIBLE | WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW); AdjustWindowRectEx(&rect, WS_VISIBLE | WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW);
mmi->ptMinTrackSize.x = rect.right - rect.left; mmi->ptMinTrackSize.x = rect.right - rect.left;
mmi->ptMinTrackSize.y = rect.bottom - rect.top; mmi->ptMinTrackSize.y = rect.bottom - rect.top;
}
else
{
mmi->ptMinTrackSize.x = 320;
mmi->ptMinTrackSize.y = 200;
}
return 0; return 0;
} }
break; break;