JOAL v2.6.0-rc-20250712
JOAL, OpenAL® API Binding for Java™ (public API).
ALVersion.java
Go to the documentation of this file.
1/**
2 * Copyright 2023 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.openal;
29
30import com.jogamp.common.os.Platform;
31import com.jogamp.common.util.VersionNumber;
32import com.jogamp.common.util.VersionNumberString;
33
34public class ALVersion {
35 private final String vendor;
36 private final String renderer;
37 private final VersionNumberString version;
38 private final VersionNumberString vendorVersion;
39
40 /**
41 * Returns the optional vendor version at the end of the
42 * <code>AL_VERSION</code> string if exists, otherwise the {@link VersionNumberString#zeroVersion zero version} instance.
43 * <pre>
44 * 1.1.0 (1.1 ALSOFT 1.23.1)
45 * </pre>
46 */
47 private static final VersionNumberString getVendorVersion(final VersionNumberString version) {
48 // Skip the 1st AL version
49 String str = version.getVersionString().substring(version.endOfStringMatch()).trim();
50 while ( str.length() > 0 ) {
51 final VersionNumberString vv = new VersionNumberString(str, VersionNumber.getDefaultVersionNumberPattern());
52 final int eosm = vv.endOfStringMatch();
53 if( 0 < eosm ) {
54 if( vv.hasMajor() && vv.hasMinor() ) { // Requires at least a defined major and minor version component!
55 return vv;
56 }
57 str = str.substring( eosm ).trim();
58 } else {
59 break; // no match
60 }
61 }
62 return VersionNumberString.zeroVersion;
63 }
64
65 /**
66 * ALVersion Ctor
67 * <p>
68 * The given {@link AL} is being used and assumed having a current {@link ALCcontext},
69 * w/o any resources being allocated.
70 * </p>
71 * @param al {@link AL} instance with a current {@link ALCcontext}.
72 */
73 public ALVersion(final AL al) {
75 renderer = al.alGetString(ALConstants.AL_RENDERER);
76 version = new VersionNumberString(al.alGetString(ALConstants.AL_VERSION));
77 vendorVersion = getVendorVersion(version);
78 }
79
80 /**
81 * ALVersion Ctor
82 * <p>
83 * The given {@link ALC} is being used and {@Link ALCdevice} and {@link ALCcontext} are allocated,
84 * made current and finally being released.
85 * </p>
86 * @param alc static {@link ALC} instance
87 */
88 public ALVersion(final ALC alc) {
89 final ALCdevice device = alc.alcOpenDevice(null);
90 final ALCcontext context = alc.alcCreateContext(device, null);
91 alc.alcMakeContextCurrent(context);
92 final AL al = ALFactory.getAL(); // valid after makeContextCurrent(..)
94 renderer = al.alGetString(ALConstants.AL_RENDERER);
95 version = new VersionNumberString(al.alGetString(ALConstants.AL_VERSION));
96 vendorVersion = getVendorVersion(version);
97 alc.alcMakeContextCurrent(null);
98 alc.alcDestroyContext(context);
99 alc.alcCloseDevice(device);
100 }
101
102 /**
103 * Return the AL context implementation vendor.
104 */
105 public String getVendor() { return vendor; }
106
107 /**
108 * Return the AL context implementation renderer.
109 */
110 public String getRenderer() { return renderer; }
111
112 /**
113 * Return the AL context implementation version.
114 */
115 public VersionNumberString getVersion() { return version; }
116
117 /**
118 * Returns the optional vendor version at the end of the
119 * <code>AL_VERSION</code> string if exists, otherwise the {@link VersionNumberString#zeroVersion zero version} instance.
120 * <pre>
121 * 1.1.0 (1.1 ALSOFT 1.23.1)
122 * </pre>
123 */
124 public VersionNumberString getVendorVersion() { return vendorVersion; }
125
126 @Override
127 public String toString() {
128 return toString(false, null).toString();
129 }
130
131 public StringBuilder toString(final boolean withNewline, StringBuilder sb) {
132 if( null == sb ) {
133 sb = new StringBuilder();
134 }
135 if( withNewline ) {
136 sb.append("AL_VENDOR ").append(getVendor());
137 sb.append(Platform.getNewline());
138 sb.append("AL_RENDERER ").append(getRenderer());
139 sb.append(Platform.getNewline());
140 sb.append("AL_VERSION ").append(getVersion());
141 sb.append(Platform.getNewline());
142 sb.append("AL_VENDOR_VERS ").append(getVendorVersion());
143 sb.append(Platform.getNewline());
144 } else {
145 sb.append("vendor ").append(getVendor());
146 sb.append(", renderer ").append(getRenderer());
147 sb.append(", version ").append(getVersion());
148 sb.append(", vendorVersion ").append(getVendorVersion());
149 }
150 return sb;
151 }
152}
This class provides factory methods for generating AL and ALC objects.
Definition: ALFactory.java:62
static AL getAL()
Get the default AL object.
Definition: ALFactory.java:122
VersionNumberString getVendorVersion()
Returns the optional vendor version at the end of the AL_VERSION string if exists,...
Definition: ALVersion.java:124
VersionNumberString getVersion()
Return the AL context implementation version.
Definition: ALVersion.java:115
StringBuilder toString(final boolean withNewline, StringBuilder sb)
Definition: ALVersion.java:131
ALVersion(final ALC alc)
ALVersion Ctor.
Definition: ALVersion.java:88
String getVendor()
Return the AL context implementation vendor.
Definition: ALVersion.java:105
ALVersion(final AL al)
ALVersion Ctor.
Definition: ALVersion.java:73
String getRenderer()
Return the AL context implementation renderer.
Definition: ALVersion.java:110
void alcDestroyContext(ALCcontext context)
Entry point (through function pointer) to C language function: void alcDestroyContext(ALCcontext * ...
boolean alcMakeContextCurrent(ALCcontext context)
Entry point (through function pointer) to C language function: ALCboolean alcMakeContextCurrent(ALC...
boolean alcCloseDevice(ALCdevice device)
Entry point (through function pointer) to C language function: ALCboolean alcCloseDevice(ALCdevice ...
ALCdevice alcOpenDevice(String devicename)
Entry point (through function pointer) to C language function: ALCdevice * alcOpenDevice(const ALCc...
ALCcontext alcCreateContext(ALCdevice device, IntBuffer attrlist)
Entry point (through function pointer) to C language function: ALCcontext * alcCreateContext(ALCdev...
static final int AL_VENDOR
Define "AL_VENDOR" with expression '0xB001', CType: int.
static final int AL_VERSION
Define "AL_VERSION" with expression '0xB002', CType: int.
static final int AL_RENDERER
Define "AL_RENDERER" with expression '0xB003', CType: int.
String alGetString(int param)
Entry point (through function pointer) to C language function: const ALchar * alGetString(ALenum pa...