mirror of https://github.com/adamdruppe/arsd.git
Implement hybrid ("int" up, "contain" down) scaling mode
This commit is contained in:
parent
92796f8e29
commit
7bd2675b1f
|
@ -156,7 +156,6 @@ import arsd.simpledisplay;
|
||||||
- Minimum window size
|
- Minimum window size
|
||||||
- or something similar
|
- or something similar
|
||||||
- to ensure `Scaling.integer` doesn’t break “unexpectedly”
|
- to ensure `Scaling.integer` doesn’t break “unexpectedly”
|
||||||
- Hybrid scaling mode: integer up, FP down
|
|
||||||
- Fix timing
|
- Fix timing
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -270,6 +269,12 @@ struct PixelBuffer {
|
||||||
|
|
||||||
@safe pure nothrow @nogc {
|
@safe pure nothrow @nogc {
|
||||||
|
|
||||||
|
// keep aspect ratio (contain)
|
||||||
|
bool karContainNeedsDownscaling(const Size drawing, const Size canvas) {
|
||||||
|
return (drawing.width > canvas.width)
|
||||||
|
|| (drawing.height > canvas.height);
|
||||||
|
}
|
||||||
|
|
||||||
// keep aspect ratio (contain)
|
// keep aspect ratio (contain)
|
||||||
int karContainScalingFactorInt(const Size drawing, const Size canvas) {
|
int karContainScalingFactorInt(const Size drawing, const Size canvas) {
|
||||||
const int w = canvas.width / drawing.width;
|
const int w = canvas.width / drawing.width;
|
||||||
|
@ -318,10 +323,11 @@ struct PixelBuffer {
|
||||||
$(SMALL_TABLE
|
$(SMALL_TABLE
|
||||||
Mode feature matrix
|
Mode feature matrix
|
||||||
Mode | Aspect Ratio | Pixel Ratio | Cropping | Border | Comment(s)
|
Mode | Aspect Ratio | Pixel Ratio | Cropping | Border | Comment(s)
|
||||||
`none` | preserved | preserved | yes | 4 |
|
`none` | preserved | preserved | yes | 4 | Crops if the `window.size < frame.size`.
|
||||||
`stretch` | no | no | no | none |
|
`stretch` | no | no | no | none |
|
||||||
`contain` | preserved | no | no | 4 | letterboxing/pillarboxing
|
`contain` | preserved | no | no | 2 | Letterboxing/Pillarboxing
|
||||||
`integer` | preserved | preserved | no | 2 | works only if `window.size >= frame.size`
|
`integer` | preserved | preserved | no | 4 | Works only if `window.size >= frame.size`.
|
||||||
|
`integerFP` | preserved | when up | no | 4 or 2 | Hybrid: int upscaling, floating-point downscaling
|
||||||
`cover` | preserved | no | yes | none |
|
`cover` | preserved | no | yes | none |
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -342,6 +348,7 @@ enum Scaling {
|
||||||
stretch, ///
|
stretch, ///
|
||||||
contain, ///
|
contain, ///
|
||||||
integer, ///
|
integer, ///
|
||||||
|
integerFP, ///
|
||||||
cover, ///
|
cover, ///
|
||||||
|
|
||||||
// aliases
|
// aliases
|
||||||
|
@ -629,6 +636,12 @@ final class OpenGL3PixelRenderer : PixelRenderer {
|
||||||
viewport = (_pro.config.renderer.resolution * scaleI);
|
viewport = (_pro.config.renderer.resolution * scaleI);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Scaling.integerFP:
|
||||||
|
if (karContainNeedsDownscaling(_pro.config.renderer.resolution, _pro.config.window.size)) {
|
||||||
|
goto case Scaling.contain;
|
||||||
|
}
|
||||||
|
goto case Scaling.integer;
|
||||||
|
|
||||||
case Scaling.cover:
|
case Scaling.cover:
|
||||||
const float fillF = karCoverScalingFactorF(_pro.config.renderer.resolution, _pro.config.window.size);
|
const float fillF = karCoverScalingFactorF(_pro.config.renderer.resolution, _pro.config.window.size);
|
||||||
viewport = Size(
|
viewport = Size(
|
||||||
|
|
Loading…
Reference in New Issue