41package com.jogamp.opengl;
43import com.jogamp.nativewindow.NativeWindowException;
47import com.jogamp.nativewindow.CapabilitiesImmutable;
49import com.jogamp.common.ExceptionUtils;
50import com.jogamp.common.util.PropertyAccess;
52import jogamp.opengl.Debug;
93 private static final boolean DEBUG;
96 Debug.initSingleton();
97 DEBUG = PropertyAccess.isPropertyDefined(
"jogl.debug.CapabilitiesChooser",
true);
100 private final static int NO_SCORE = -9999999;
101 private final static int DOUBLE_BUFFER_MISMATCH_PENALTY = 1000;
102 private final static int OPAQUE_MISMATCH_PENALTY = 750;
103 private final static int STENCIL_MISMATCH_PENALTY = 500;
104 private final static int MULTISAMPLE_MISMATCH_PENALTY = 500;
105 private final static int MULTISAMPLE_EXTENSION_MISMATCH_PENALTY = 250;
109 private final static int COLOR_MISMATCH_PENALTY_SCALE = 36;
110 private final static int DEPTH_MISMATCH_PENALTY_SCALE = 6;
111 private final static int ACCUM_MISMATCH_PENALTY_SCALE = 1;
112 private final static int STENCIL_MISMATCH_PENALTY_SCALE = 3;
113 private final static int MULTISAMPLE_MISMATCH_PENALTY_SCALE = 3;
117 final List<? extends CapabilitiesImmutable> available,
118 final int windowSystemRecommendedChoice) {
119 if (
null == desired ) {
122 if ( 0 == available.size() ) {
127 final int availnum = available.size();
130 ExceptionUtils.dumpStack(System.err);
131 System.err.println(
"Desired: " + gldes);
132 System.err.println(
"Available: " + availnum);
133 for (
int i = 0; i < available.size(); i++) {
134 System.err.println(i +
": " + available.get(i));
136 System.err.println(
"Window system's recommended choice: " + windowSystemRecommendedChoice);
139 if (windowSystemRecommendedChoice >= 0 &&
140 windowSystemRecommendedChoice < availnum &&
141 null != available.get(windowSystemRecommendedChoice)) {
143 System.err.println(
"Choosing window system's recommended choice of " + windowSystemRecommendedChoice);
144 System.err.println(available.get(windowSystemRecommendedChoice));
146 return windowSystemRecommendedChoice;
150 final int[] scores =
new int[availnum];
152 for (
int i = 0; i < scores.length; i++) {
153 scores[i] = NO_SCORE;
158 for (
int i = 0; i < availnum; i++) {
186 score += (COLOR_MISMATCH_PENALTY_SCALE *
190 score += (DEPTH_MISMATCH_PENALTY_SCALE * sign(score) *
193 score += (ACCUM_MISMATCH_PENALTY_SCALE * sign(score) *
199 score += MULTISAMPLE_MISMATCH_PENALTY_SCALE * sign(score) * (cur_samples - gldes_samples);
202 score += sign(score) * DOUBLE_BUFFER_MISMATCH_PENALTY;
206 score += sign(score) * OPAQUE_MISMATCH_PENALTY;
209 score += sign(score) * STENCIL_MISMATCH_PENALTY;
211 if (gldes_samples > 0) {
212 if (cur_samples == 0) {
213 score += sign(score) * MULTISAMPLE_MISMATCH_PENALTY;
216 score += sign(score) * MULTISAMPLE_EXTENSION_MISMATCH_PENALTY;
223 boolean gotHW =
false;
224 int maxAbsoluteHWScore = 0;
225 for (
int i = 0; i < availnum; i++) {
226 final int score = scores[i];
227 if (score == NO_SCORE) {
232 final int absScore = Math.abs(score);
234 (absScore > maxAbsoluteHWScore)) {
236 maxAbsoluteHWScore = absScore;
241 for (
int i = 0; i < availnum; i++) {
242 int score = scores[i];
243 if (score == NO_SCORE) {
249 score -= maxAbsoluteHWScore;
250 }
else if (score > 0) {
251 score += maxAbsoluteHWScore;
259 System.err.print(
"Scores: [");
260 for (
int i = 0; i < availnum; i++) {
262 System.err.print(
",");
264 System.err.print(
" " + i +
": " + scores[i]);
266 System.err.println(
" ]");
270 int scoreClosestToZero = NO_SCORE;
271 int chosenIndex = -1;
272 for (
int i = 0; i < availnum; i++) {
273 final int score = scores[i];
274 if (score == NO_SCORE) {
278 if ((scoreClosestToZero == NO_SCORE) ||
279 (Math.abs(score) < Math.abs(scoreClosestToZero) &&
280 ((sign(scoreClosestToZero) < 0) || (sign(score) > 0)))) {
281 scoreClosestToZero = score;
285 if (chosenIndex < 0) {
289 System.err.println(
"Chosen index: " + chosenIndex);
290 System.err.println(
"Chosen capabilities:");
291 System.err.println(available.get(chosenIndex));
297 private static int sign(
final int score) {
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
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...
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.
boolean isBitmap()
Returns whether bitmap offscreen mode is requested, available or chosen.
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.
boolean isBackgroundOpaque()
Returns whether an opaque or translucent surface is requested, supported or chosen.
Provides a mechanism by which applications can customize the window type selection for a given GLCapa...
Specifies an immutable set of OpenGL capabilities.
int getAccumGreenBits()
Returns the number of bits for the accumulation buffer's green component.
String getSampleExtension()
Returns the extension for full-scene antialiasing (FSAA).
int getNumSamples()
Returns the number of sample buffers to be allocated if sample buffers are enabled,...
boolean getHardwareAccelerated()
Returns whether hardware acceleration is requested, available or chosen.
int getDepthBits()
Returns the number of depth buffer bits.
boolean isPBuffer()
Returns whether pbuffer offscreen mode is requested, available or chosen.
int getAccumRedBits()
Returns the number of bits for the accumulation buffer's red component.
int getAccumAlphaBits()
Returns the number of bits for the accumulation buffer's alpha component.
boolean getDoubleBuffered()
Returns whether double-buffering is requested, available or chosen.
int getAccumBlueBits()
Returns the number of bits for the accumulation buffer's blue component.
int getStencilBits()
Returns the number of stencil buffer bits.
boolean getStereo()
Returns whether stereo is requested, available or chosen.