diff --git a/framework/platform-dx/adapter.cpp b/framework/platform-dx/adapter.cpp index fe0e00c..bc9e242 100644 --- a/framework/platform-dx/adapter.cpp +++ b/framework/platform-dx/adapter.cpp @@ -167,7 +167,7 @@ namespace xna { for (size_t i = 0; i < modes->DisplayModes.size(); ++i) { auto& m = modes->DisplayModes[i]; - if (m->Format == surfaceFormat && m->Width == width && m->Height == height) { + if (m->Format() == surfaceFormat && m->Width() == width && m->Height() == height) { currentDisplayMode = m; } else if (i + 1 == modes->DisplayModes.size()) { @@ -197,27 +197,29 @@ namespace xna { uptr createDisplayModeCollection(std::vector const& source) { auto collection = unew(); - DisplayMode currentDisplayMode; + std::vector> displayList; sptr pDisplay = nullptr; for (size_t i = 0; i < source.size(); ++i) { auto& modedesc = source[i]; - DisplayModeDescription description; - description._refreshRate = modedesc.RefreshRate; - description._scaling = static_cast(modedesc.Scaling); - description._scanlineOrdering = static_cast(modedesc.ScanlineOrdering); + DisplayModeRate rate; + rate.RefreshRate.Denominator = modedesc.RefreshRate.Denominator; + rate.RefreshRate.Numerator = modedesc.RefreshRate.Numerator; + rate.Scaling = static_cast(modedesc.Scaling); + rate.ScanlineOrdering = static_cast(modedesc.ScanlineOrdering); - if (pDisplay && pDisplay->Width == modedesc.Width && pDisplay->Height == modedesc.Height && pDisplay->Format == DxHelpers::SurfaceFormatToXna(modedesc.Format)) { - pDisplay->impl->Descriptions.push_back(description); + if (pDisplay && pDisplay->Width() == modedesc.Width && pDisplay->Height() == modedesc.Height && pDisplay->Format() == DxHelpers::SurfaceFormatToXna(modedesc.Format)) { + pDisplay->Rates.push_back(rate); } else { - pDisplay = snew(); - pDisplay->Width = modedesc.Width; - pDisplay->Height = modedesc.Height; - pDisplay->Format = DxHelpers::SurfaceFormatToXna(modedesc.Format); - pDisplay->impl->Descriptions.push_back(description); + pDisplay = snew( + modedesc.Width, + modedesc.Height, + DxHelpers::SurfaceFormatToXna(modedesc.Format)); + + pDisplay->Rates.push_back(rate); displayList.push_back(pDisplay); } } diff --git a/framework/platform-dx/displaymode.cpp b/framework/platform-dx/displaymode.cpp index fbebf57..80a56c4 100644 --- a/framework/platform-dx/displaymode.cpp +++ b/framework/platform-dx/displaymode.cpp @@ -2,16 +2,12 @@ #include "xna/graphics/displaymode.hpp" namespace xna { - DisplayMode::DisplayMode() { - impl = unew(); - } - size_t DisplayModeCollection::SurfaceCount(SurfaceFormat format) const { size_t counter = 0; for (size_t i = 0; i < DisplayModes.size(); ++i) { - if (DisplayModes[i]->Format == format) { + if (DisplayModes[i]->Format() == format) { ++counter; } } @@ -27,7 +23,7 @@ namespace xna { std::vector> modes(count); for (size_t i = 0; i < DisplayModes.size(); ++i) { - if (DisplayModes[i]->Format == format) { + if (DisplayModes[i]->Format() == format) { modes[index] = DisplayModes[i]; ++index; } @@ -46,10 +42,10 @@ namespace xna { for (size_t i = 0; i < DisplayModes.size(); ++i) { const auto& mode = DisplayModes[i]; - if (mode->Format == format && mode->Width == width && mode->Height == height) { + if (mode->Format() == format && mode->Width() == width && mode->Height() == height) { return DisplayModes[i]; } - else if(mode->Format == format && mode->Width == width) { + else if(mode->Format() == format && mode->Width() == width) { matched = mode; } } diff --git a/inc/xna/common/numerics.hpp b/inc/xna/common/numerics.hpp index d637230..bd1d63f 100644 --- a/inc/xna/common/numerics.hpp +++ b/inc/xna/common/numerics.hpp @@ -6,6 +6,23 @@ #include namespace xna { + //Represents a rational number. + struct RationalNumber { + constexpr RationalNumber() = default; + + constexpr RationalNumber(Uint numerator, Uint denominator) + : Numerator(numerator), Denominator(denominator) {} + + constexpr bool operator==(const RationalNumber& other) const { + return Numerator == other.Numerator && Denominator == other.Denominator; + } + + //An unsigned integer value representing the top of the rational number. + Uint Numerator{ 0 }; + //An unsigned integer value representing the bottom of the rational number. + Uint Denominator{ 0 }; + }; + struct Point { Int X{ 0 }; Int Y{ 0 }; diff --git a/inc/xna/enumerations.hpp b/inc/xna/enumerations.hpp index 51bf886..bb007e0 100644 --- a/inc/xna/enumerations.hpp +++ b/inc/xna/enumerations.hpp @@ -193,19 +193,6 @@ namespace xna { Portrait = 4, }; - enum class DisplayModeScanlineOrder { - Unspecified = 0, - Progressive = 1, - UpperFieldFirst = 2, - LowerFieldFirst = 3 - }; - - enum class DisplayModeScaling { - Unspecified = 0, - Centered = 1, - Stretched = 2 - }; - enum class EffectParameterClass { Matrix, Object, diff --git a/inc/xna/graphics/displaymode.hpp b/inc/xna/graphics/displaymode.hpp index 8861a7f..6385008 100644 --- a/inc/xna/graphics/displaymode.hpp +++ b/inc/xna/graphics/displaymode.hpp @@ -2,40 +2,78 @@ #define XNA_GRAPHICS_DISPLAYMODE_HPP #include "../default.hpp" +#include "../common/numerics.hpp" namespace xna { - struct DisplayModeDescription; + //Flags indicating the method the raster uses to create an image on a surface + enum class DisplayModeScanlineOrder { + Unspecified = 0, + Progressive = 1, + UpperFieldFirst = 2, + LowerFieldFirst = 3 + }; + + //Flags indicating how an image is stretched to fit a given monitor's resolution + enum class DisplayModeScaling { + Unspecified = 0, + Centered = 1, + Stretched = 2 + }; + + struct DisplayModeRate { + constexpr DisplayModeRate() = default; + + constexpr DisplayModeRate(DisplayModeScanlineOrder scanlineOrdering, DisplayModeScaling scaling, RationalNumber refreshRate) : + ScanlineOrdering(scanlineOrdering), Scaling(scaling), RefreshRate(refreshRate){} + + constexpr bool operator==(const DisplayModeRate& other) const { + return ScanlineOrdering == other.ScanlineOrdering && Scaling == other.Scaling && RefreshRate == other.RefreshRate; + } + + //Gets the method the raster uses to create an image on a surface + DisplayModeScanlineOrder ScanlineOrdering{ DisplayModeScanlineOrder::Unspecified }; + //Gets how an image is stretched to fit a given monitor's resolution + DisplayModeScaling Scaling{ DisplayModeScaling::Unspecified }; + //Describing the refresh rate in hertz. + RationalNumber RefreshRate{}; + }; //Describes the display mode. class DisplayMode { public: - DisplayMode(); + constexpr DisplayMode(); + + constexpr DisplayMode(Int width, Int height, SurfaceFormat format): + width(width), height(height), format(format){} //Gets the aspect ratio used by the graphics device. constexpr float AspectRatio() const { - if (Height == 0 || Width == 0) + if (height == 0 || width == 0) return 0; - return static_cast(Width) / static_cast(Height); + return static_cast(width) / static_cast(height); } + //Gets a value indicating the screen width, in pixels. + constexpr Int Width() const { return width; } + //Gets a value indicating the screen height, in pixels. + constexpr Int Height() const { return height; } + //Gets a value indicating the surface format of the display mode. + constexpr SurfaceFormat Format() const { return format; } + constexpr bool operator==(const DisplayMode& other) const { - return Width == other.Width - && Height == other.Height - && Format == other.Format; + return width == other.width + && height == other.height + && format == other.format; } + private: + Int width{ 0 }; + Int height{ 0 }; + SurfaceFormat format{ SurfaceFormat::Color }; + public: - //Gets a value indicating the screen width, in pixels. - Int Width{ 0 }; - //Gets a value indicating the screen height, in pixels. - Int Height{ 0 }; - //Gets a value indicating the surface format of the display mode. - SurfaceFormat Format{ SurfaceFormat::Color }; - - public: - struct PlatformImplementation; - uptr impl; + std::vector Rates; }; //Manipulates a collection of DisplayMode structures. diff --git a/inc/xna/xna-dx.hpp b/inc/xna/xna-dx.hpp index 0226b17..959d3fb 100644 --- a/inc/xna/xna-dx.hpp +++ b/inc/xna/xna-dx.hpp @@ -622,40 +622,6 @@ namespace xna { D3D11_DEPTH_STENCIL_DESC dxDescription{}; }; - struct DisplayModeRefreshRate { - constexpr DisplayModeRefreshRate() = default; - - constexpr DisplayModeRefreshRate(DXGI_RATIONAL const& dxrational) { - Numerator = dxrational.Numerator; - Denominator = dxrational.Denominator; - } - constexpr DisplayModeRefreshRate(Uint numerator, Uint denominator) - : Numerator(numerator), Denominator(denominator) {} - - Uint Numerator{ 0 }; - Uint Denominator{ 0 }; - - constexpr bool operator==(const DisplayModeRefreshRate& other) const - { - return Numerator == other.Numerator && Denominator == other.Denominator; - } - }; - - struct DisplayModeDescription { - DisplayModeScanlineOrder _scanlineOrdering{ DisplayModeScanlineOrder::Unspecified }; - DisplayModeScaling _scaling{ DisplayModeScaling::Unspecified }; - DisplayModeRefreshRate _refreshRate{}; - - constexpr bool operator==(const DisplayModeDescription& other) const - { - return _scanlineOrdering == other._scanlineOrdering && _scaling == other._scaling && _refreshRate == other._refreshRate; - } - }; - - struct DisplayMode::PlatformImplementation { - std::vector Descriptions; - }; - struct GamePad::PlatformImplementation { uptr _dxGamePad = unew();