diff --git a/build.gradle b/build.gradle index f0774df..65963b8 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ if (org.gradle.internal.os.OperatingSystem.current() == org.gradle.internal.os.O } group 'valoeghese' -version '1.1.3' +version '1.1.4' switch (org.gradle.internal.os.OperatingSystem.current()) { case org.gradle.internal.os.OperatingSystem.LINUX: diff --git a/src/main/java/valoeghese/scalpel/Model.java b/src/main/java/valoeghese/scalpel/Model.java index 9de2b1d..1b63754 100644 --- a/src/main/java/valoeghese/scalpel/Model.java +++ b/src/main/java/valoeghese/scalpel/Model.java @@ -82,9 +82,12 @@ protected void generateBuffers() { public void destroy() { for (VertexArray array : this.vertexArrays) { glDeleteVertexArrays(array.vao); + glDeleteBuffers(array.ebo); + glDeleteBuffers(array.vbo); } this.vertexArrays = new ArrayList<>(); + this.vTempIndex = 0; } @@ -101,6 +104,33 @@ public final void render(Matrix4f transform) { unbind(); } + /** + * @return the {@linkplain VertexArray vertex array} objects containing the opengl object ids. + * @apiNote only use this if you KNOW WHAT YOU ARE DOING. This allows more direct access to precise OpenGL calls. + */ + public Iterable getOpenglHandles() { + return this.vertexArrays; + } + + /** + * @return the {@linkplain VertexArray vertex array} object containing the opengl object ids stored at this position in this model. + * @apiNote only use this if you KNOW WHAT YOU ARE DOING. This allows more direct access to precise OpenGL calls. + */ + public VertexArray getHandleAt(int index) throws ArrayIndexOutOfBoundsException { + return this.vertexArrays.get(index); + } + + /** + * Removes and destroys the {@linkplain VertexArray vertex array} object at this position. + * @apiNote only use this if you KNOW WHAT YOU ARE DOING. This allows more direct access to precise OpenGL calls. + */ + public void destroyHandleAt(int index) { + VertexArray array = this.vertexArrays.remove(index); + glDeleteVertexArrays(array.vao); + glDeleteBuffers(array.ebo); + glDeleteBuffers(array.vbo); + } + @Nullable public Shader getShader() { return this.shader; @@ -110,7 +140,10 @@ public static final void unbind() { glBindVertexArray(0); } - private static class VertexArray { + /** + * A container containing + */ + public static class VertexArray { private VertexArray(int vbo, int ebo, int vao, int elementCount) { this.vbo = vbo; this.ebo = ebo; @@ -122,5 +155,33 @@ private VertexArray(int vbo, int ebo, int vao, int elementCount) { private final int ebo; private final int vao; private final int elementCount; + + /** + * @return the vertex buffer object opengl handle. + */ + public int getVBOHandle() { + return this.vbo; + } + + /** + * @return the index buffer object opengl handle. + */ + public int getEBOHandle() { + return this.ebo; + } + + /** + * @return the array buffer object opengl handle. + */ + public int getVAOHandle() { + return this.vao; + } + + /** + * @return the length of the indices buffer object array. + */ + public int getElementCount() { + return this.elementCount; + } } } diff --git a/src/main/java/valoeghese/scalpel/audio/AudioSource.java b/src/main/java/valoeghese/scalpel/audio/AudioSource.java index 76dcfd3..d9c78dd 100644 --- a/src/main/java/valoeghese/scalpel/audio/AudioSource.java +++ b/src/main/java/valoeghese/scalpel/audio/AudioSource.java @@ -36,4 +36,8 @@ public void play() { public void destroy() { alDeleteSources(this.source); } + + public boolean isPlaying() { + return alGetSourcei(this.source, AL_SOURCE_STATE) == AL_PLAYING; + } } diff --git a/src/main/java/valoeghese/scalpel/util/ALUtils.java b/src/main/java/valoeghese/scalpel/util/ALUtils.java index 5a2b38c..c759886 100644 --- a/src/main/java/valoeghese/scalpel/util/ALUtils.java +++ b/src/main/java/valoeghese/scalpel/util/ALUtils.java @@ -68,7 +68,7 @@ public static AudioBuffer createBuffer(String fileName) throws IOException { // stb_vorbis_get_info(decoder, info); int channels = info.channels(); - pcm = MemoryUtil.memAllocShort(stb_vorbis_stream_length_in_samples(decoder) * 2); + pcm = MemoryUtil.memAllocShort(stb_vorbis_stream_length_in_samples(decoder) * channels); pcm.limit(stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm) * channels); stb_vorbis_close(decoder); } diff --git a/src/test/java/valoeghese/scalpel/test/TestAudio.java b/src/test/java/valoeghese/scalpel/test/TestAudio.java index 3db73f1..9c6d236 100644 --- a/src/test/java/valoeghese/scalpel/test/TestAudio.java +++ b/src/test/java/valoeghese/scalpel/test/TestAudio.java @@ -15,9 +15,11 @@ private TestAudio() { super(100 / 20); } - AudioBuffer audio; + AudioBuffer audioStereo; + AudioBuffer audioMono; AudioSource source; private Window window; + boolean playedMonoYet = false; @Override protected void preInit() { @@ -31,7 +33,8 @@ protected void preInit() { ALUtils.setListenerVelocity(0, 0, 0); try { - audio = ALUtils.createBuffer("assets/sound/Test_Sound.ogg"); + audioStereo = ALUtils.createBuffer("assets/sound/Test_Sound.ogg"); + audioMono = ALUtils.createBuffer("assets/sound/Test_Mono.ogg"); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -41,7 +44,7 @@ protected void preInit() { source.setPitch(1.0f); source.setPosition(0, 0, 0); source.setVelocity(0, 0, 0); - source.attachBufferData(audio); + source.attachBufferData(audioStereo); } @Override @@ -65,12 +68,15 @@ protected boolean shouldRun() { @Override protected void tick() { - } @Override protected void render() { - + if (!this.playedMonoYet && !this.source.isPlaying()) { + this.playedMonoYet = true; + this.source.attachBufferData(audioMono); + source.play(); + } } @Override diff --git a/src/test/resources/assets/sound/Test_Mono.ogg b/src/test/resources/assets/sound/Test_Mono.ogg new file mode 100644 index 0000000..9dde7db Binary files /dev/null and b/src/test/resources/assets/sound/Test_Mono.ogg differ