-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathVideoResolution.java
More file actions
109 lines (83 loc) · 3.36 KB
/
VideoResolution.java
File metadata and controls
109 lines (83 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package net.vulkanmod.config;
import com.mojang.blaze3d.platform.VideoMode;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWVidMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class VideoResolution {
private static VideoResolution[] videoResolutions;
int width;
int height;
int refreshRate;
private List<VideoMode> videoModes;
public VideoResolution(int width, int height) {
this.width = width;
this.height = height;
this.videoModes = new ArrayList<>(6);
}
public void addVideoMode(VideoMode videoMode) {
videoModes.add(videoMode);
}
public String toString() {
return this.width + " x " + this.height;
}
public VideoMode getVideoMode() {
VideoMode videoMode;
for(VideoResolution resolution : videoResolutions) {
if(this.width == resolution.width && this.height == resolution.height) return resolution.videoModes.get(0);
}
return null;
}
public int[] refreshRates() {
int[] arr = new int[videoModes.size()];
for(int i = 0; i < arr.length; ++i) {
arr[i] = videoModes.get(i).getRefreshRate();
}
return arr;
}
public static void init() {
RenderSystem.assertOnRenderThreadOrInit();
GLFW.glfwInit();
videoResolutions = populateVideoResolutions(GLFW.glfwGetPrimaryMonitor());
}
public static VideoResolution[] getVideoResolutions() {
return videoResolutions;
}
public static VideoResolution getFirstAvailable() {
if(videoResolutions != null) return videoResolutions[0];
else return new VideoResolution(-1, -1);
}
public static VideoResolution[] populateVideoResolutions(long monitor) {
GLFWVidMode.Buffer buffer = GLFW.glfwGetVideoModes(monitor);
// VideoMode[] videoModes = new VideoMode[buffer.limit()];
// for (int i = buffer.limit() - 1; i >= 0; --i) {
// buffer.position(i);
// VideoMode videoMode = new VideoMode(buffer);
// if (videoMode.getRedBits() < 8 || videoMode.getGreenBits() < 8 || videoMode.getBlueBits() < 8) continue;
// videoModes[i] = (videoMode);
// }
List<VideoResolution> videoResolutions = new ArrayList<>();
for (int i = buffer.limit() - 1; i >= 0; --i) {
buffer.position(i);
VideoMode videoMode = new VideoMode(buffer);
if (buffer.redBits() < 8 || buffer.greenBits() < 8 || buffer.blueBits() < 8) continue;
int width = buffer.width();
int height = buffer.height();
Optional<VideoResolution> resolution = videoResolutions.stream()
.filter(videoResolution -> videoResolution.width == width && videoResolution.height == height)
.findAny();
if(resolution.isEmpty()) {
VideoResolution newResoultion = new VideoResolution(width, height);
videoResolutions.add(newResoultion);
resolution = Optional.of(newResoultion);
}
resolution.get().addVideoMode(videoMode);
}
VideoResolution[] arr = new VideoResolution[videoResolutions.size()];
videoResolutions.toArray(arr);
return arr;
}
}