41package com.jogamp.nativewindow;
45import com.jogamp.common.util.PropertyAccess;
47import jogamp.nativewindow.Debug;
71 private static final boolean DEBUG;
74 Debug.initSingleton();
75 DEBUG = PropertyAccess.isPropertyDefined(
"nativewindow.debug.CapabilitiesChooser",
true);
78 private final static int NO_SCORE = -9999999;
79 private final static int COLOR_MISMATCH_PENALTY_SCALE = 36;
83 final List<? extends CapabilitiesImmutable> available,
84 final int windowSystemRecommendedChoice) {
86 System.err.println(
"Desired: " + desired);
87 for (
int i = 0; i < available.size(); i++) {
88 System.err.println(
"Available " + i +
": " + available.get(i));
90 System.err.println(
"Window system's recommended choice: " + windowSystemRecommendedChoice);
92 final int availnum = available.size();
94 if (windowSystemRecommendedChoice >= 0 &&
95 windowSystemRecommendedChoice < availnum &&
96 null != available.get(windowSystemRecommendedChoice)) {
98 System.err.println(
"Choosing window system's recommended choice of " + windowSystemRecommendedChoice);
99 System.err.println(available.get(windowSystemRecommendedChoice));
101 return windowSystemRecommendedChoice;
105 final int[] scores =
new int[availnum];
106 for (
int i = 0; i < availnum; i++) {
107 scores[i] = NO_SCORE;
110 for (
int i = 0; i < availnum; i++) {
121 score += (COLOR_MISMATCH_PENALTY_SCALE *
128 System.err.print(
"Scores: [");
129 for (
int i = 0; i < availnum; i++) {
131 System.err.print(
",");
133 System.err.print(
" " + scores[i]);
135 System.err.println(
" ]");
139 int scoreClosestToZero = NO_SCORE;
140 int chosenIndex = -1;
141 for (
int i = 0; i < availnum; i++) {
142 final int score = scores[i];
143 if (score == NO_SCORE) {
147 if ((scoreClosestToZero == NO_SCORE) ||
148 (Math.abs(score) < Math.abs(scoreClosestToZero) &&
149 ((sign(scoreClosestToZero) < 0) || (sign(score) > 0)))) {
150 scoreClosestToZero = score;
154 if (chosenIndex < 0) {
158 System.err.println(
"Chosen index: " + chosenIndex);
159 System.err.println(
"Chosen capabilities:");
160 System.err.println(available.get(chosenIndex));
166 private static int sign(
final int score) {
int chooseCapabilities(final CapabilitiesImmutable desired, final List<? extends CapabilitiesImmutable > available, final int windowSystemRecommendedChoice)
Chooses the index (0..available.length - 1) of the Capabilities most closely matching the desired one...
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Provides a mechanism by which applications can customize the window type selection for a given Capabi...
Specifies an immutable set of capabilities that a window's rendering context must support,...
int getAlphaBits()
Returns the number of bits for the color buffer's alpha component.
int getBlueBits()
Returns the number of bits for the color buffer's blue component.
int getRedBits()
Returns the number of bits for the color buffer's red component.
int getGreenBits()
Returns the number of bits for the color buffer's green component.
boolean isOnscreen()
Returns whether an on- or offscreen surface is requested, available or chosen.