mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações em DisplayMode
This commit is contained in:
parent
6e10a3a669
commit
818e694da5
@ -167,7 +167,7 @@ namespace xna {
|
|||||||
for (size_t i = 0; i < modes->DisplayModes.size(); ++i) {
|
for (size_t i = 0; i < modes->DisplayModes.size(); ++i) {
|
||||||
auto& m = modes->DisplayModes[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;
|
currentDisplayMode = m;
|
||||||
}
|
}
|
||||||
else if (i + 1 == modes->DisplayModes.size()) {
|
else if (i + 1 == modes->DisplayModes.size()) {
|
||||||
@ -197,27 +197,29 @@ namespace xna {
|
|||||||
|
|
||||||
uptr<DisplayModeCollection> createDisplayModeCollection(std::vector<DXGI_MODE_DESC> const& source) {
|
uptr<DisplayModeCollection> createDisplayModeCollection(std::vector<DXGI_MODE_DESC> const& source) {
|
||||||
auto collection = unew<DisplayModeCollection>();
|
auto collection = unew<DisplayModeCollection>();
|
||||||
DisplayMode currentDisplayMode;
|
|
||||||
std::vector<sptr<DisplayMode>> displayList;
|
std::vector<sptr<DisplayMode>> displayList;
|
||||||
sptr<DisplayMode> pDisplay = nullptr;
|
sptr<DisplayMode> pDisplay = nullptr;
|
||||||
|
|
||||||
for (size_t i = 0; i < source.size(); ++i) {
|
for (size_t i = 0; i < source.size(); ++i) {
|
||||||
auto& modedesc = source[i];
|
auto& modedesc = source[i];
|
||||||
|
|
||||||
DisplayModeDescription description;
|
DisplayModeRate rate;
|
||||||
description._refreshRate = modedesc.RefreshRate;
|
rate.RefreshRate.Denominator = modedesc.RefreshRate.Denominator;
|
||||||
description._scaling = static_cast<DisplayModeScaling>(modedesc.Scaling);
|
rate.RefreshRate.Numerator = modedesc.RefreshRate.Numerator;
|
||||||
description._scanlineOrdering = static_cast<DisplayModeScanlineOrder>(modedesc.ScanlineOrdering);
|
rate.Scaling = static_cast<DisplayModeScaling>(modedesc.Scaling);
|
||||||
|
rate.ScanlineOrdering = static_cast<DisplayModeScanlineOrder>(modedesc.ScanlineOrdering);
|
||||||
|
|
||||||
if (pDisplay && pDisplay->Width == modedesc.Width && pDisplay->Height == modedesc.Height && pDisplay->Format == DxHelpers::SurfaceFormatToXna(modedesc.Format)) {
|
if (pDisplay && pDisplay->Width() == modedesc.Width && pDisplay->Height() == modedesc.Height && pDisplay->Format() == DxHelpers::SurfaceFormatToXna(modedesc.Format)) {
|
||||||
pDisplay->impl->Descriptions.push_back(description);
|
pDisplay->Rates.push_back(rate);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pDisplay = snew<DisplayMode>();
|
pDisplay = snew<DisplayMode>(
|
||||||
pDisplay->Width = modedesc.Width;
|
modedesc.Width,
|
||||||
pDisplay->Height = modedesc.Height;
|
modedesc.Height,
|
||||||
pDisplay->Format = DxHelpers::SurfaceFormatToXna(modedesc.Format);
|
DxHelpers::SurfaceFormatToXna(modedesc.Format));
|
||||||
pDisplay->impl->Descriptions.push_back(description);
|
|
||||||
|
pDisplay->Rates.push_back(rate);
|
||||||
displayList.push_back(pDisplay);
|
displayList.push_back(pDisplay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,12 @@
|
|||||||
#include "xna/graphics/displaymode.hpp"
|
#include "xna/graphics/displaymode.hpp"
|
||||||
|
|
||||||
namespace xna {
|
namespace xna {
|
||||||
DisplayMode::DisplayMode() {
|
|
||||||
impl = unew<PlatformImplementation>();
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t DisplayModeCollection::SurfaceCount(SurfaceFormat format) const
|
size_t DisplayModeCollection::SurfaceCount(SurfaceFormat format) const
|
||||||
{
|
{
|
||||||
size_t counter = 0;
|
size_t counter = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < DisplayModes.size(); ++i) {
|
for (size_t i = 0; i < DisplayModes.size(); ++i) {
|
||||||
if (DisplayModes[i]->Format == format) {
|
if (DisplayModes[i]->Format() == format) {
|
||||||
++counter;
|
++counter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -27,7 +23,7 @@ namespace xna {
|
|||||||
std::vector<sptr<DisplayMode>> modes(count);
|
std::vector<sptr<DisplayMode>> modes(count);
|
||||||
|
|
||||||
for (size_t i = 0; i < DisplayModes.size(); ++i) {
|
for (size_t i = 0; i < DisplayModes.size(); ++i) {
|
||||||
if (DisplayModes[i]->Format == format) {
|
if (DisplayModes[i]->Format() == format) {
|
||||||
modes[index] = DisplayModes[i];
|
modes[index] = DisplayModes[i];
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
@ -46,10 +42,10 @@ namespace xna {
|
|||||||
for (size_t i = 0; i < DisplayModes.size(); ++i) {
|
for (size_t i = 0; i < DisplayModes.size(); ++i) {
|
||||||
const auto& mode = DisplayModes[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];
|
return DisplayModes[i];
|
||||||
}
|
}
|
||||||
else if(mode->Format == format && mode->Width == width) {
|
else if(mode->Format() == format && mode->Width() == width) {
|
||||||
matched = mode;
|
matched = mode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,23 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace xna {
|
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 {
|
struct Point {
|
||||||
Int X{ 0 };
|
Int X{ 0 };
|
||||||
Int Y{ 0 };
|
Int Y{ 0 };
|
||||||
|
@ -193,19 +193,6 @@ namespace xna {
|
|||||||
Portrait = 4,
|
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 {
|
enum class EffectParameterClass {
|
||||||
Matrix,
|
Matrix,
|
||||||
Object,
|
Object,
|
||||||
|
@ -2,40 +2,78 @@
|
|||||||
#define XNA_GRAPHICS_DISPLAYMODE_HPP
|
#define XNA_GRAPHICS_DISPLAYMODE_HPP
|
||||||
|
|
||||||
#include "../default.hpp"
|
#include "../default.hpp"
|
||||||
|
#include "../common/numerics.hpp"
|
||||||
|
|
||||||
namespace xna {
|
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.
|
//Describes the display mode.
|
||||||
class DisplayMode {
|
class DisplayMode {
|
||||||
public:
|
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.
|
//Gets the aspect ratio used by the graphics device.
|
||||||
constexpr float AspectRatio() const {
|
constexpr float AspectRatio() const {
|
||||||
if (Height == 0 || Width == 0)
|
if (height == 0 || width == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return static_cast<float>(Width) / static_cast<float>(Height);
|
return static_cast<float>(width) / static_cast<float>(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 {
|
constexpr bool operator==(const DisplayMode& other) const {
|
||||||
return Width == other.Width
|
return width == other.width
|
||||||
&& Height == other.Height
|
&& height == other.height
|
||||||
&& Format == other.Format;
|
&& format == other.format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Int width{ 0 };
|
||||||
|
Int height{ 0 };
|
||||||
|
SurfaceFormat format{ SurfaceFormat::Color };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//Gets a value indicating the screen width, in pixels.
|
std::vector<DisplayModeRate> Rates;
|
||||||
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<PlatformImplementation> impl;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//Manipulates a collection of DisplayMode structures.
|
//Manipulates a collection of DisplayMode structures.
|
||||||
|
@ -622,40 +622,6 @@ namespace xna {
|
|||||||
D3D11_DEPTH_STENCIL_DESC dxDescription{};
|
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<DisplayModeDescription> Descriptions;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct GamePad::PlatformImplementation {
|
struct GamePad::PlatformImplementation {
|
||||||
uptr<DirectX::GamePad> _dxGamePad = unew<DirectX::GamePad>();
|
uptr<DirectX::GamePad> _dxGamePad = unew<DirectX::GamePad>();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user